Discussion:
[Linuxptp-devel] [PATCH 2/4] Remove conflicting netinet/ether.h
Petr Kulhavy
2017-05-15 08:17:52 UTC
Permalink
On some platforms like br-arm-cortex-a9-musl struct ethhdr was defined twice
due to including of both linux/if_ether.h and netinet/ether.h. Which lead
to a compilation error.

Remove netinet/ether.h as the official header for struct ethhdr is
linux/if_ether.h

Signed-off-by: Petr Kulhavy <***@jikos.cz>
---
raw.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/raw.c b/raw.c
index f51c829..73e45b4 100644
--- a/raw.c
+++ b/raw.c
@@ -20,7 +20,6 @@
#include <fcntl.h>
#include <linux/filter.h>
#include <linux/if_ether.h>
-#include <net/ethernet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netpacket/packet.h>
--
2.7.4
Petr Kulhavy
2017-05-15 08:17:53 UTC
Permalink
On some platforms clock_adjtime is defined in timex.h instead of time.h
Due to this fact the detection in incdefs.h was failing.
Add timex.h into the list of searched files.

Signed-off-by: Petr Kulhavy <***@jikos.cz>
---
incdefs.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/incdefs.sh b/incdefs.sh
index 34e227f..8232b5c 100755
--- a/incdefs.sh
+++ b/incdefs.sh
@@ -31,7 +31,7 @@ user_flags()

# Look for clock_adjtime().
for d in $dirs; do
- files=$(find $d -type f -name time.h)
+ files=$(find $d -type f -name time.h -o -name timex.h)
for f in $files; do
if grep -q clock_adjtime $f; then
printf " -DHAVE_CLOCK_ADJTIME"
--
2.7.4
Richard Cochran
2017-05-15 21:25:26 UTC
Permalink
Post by Petr Kulhavy
On some platforms clock_adjtime is defined in timex.h instead of time.h
Due to this fact the detection in incdefs.h was failing.
Add timex.h into the list of searched files.
Applied.

Thanks,
Richard
Petr Kulhavy
2017-05-15 08:17:54 UTC
Permalink
On some platforms compilation issues due to clock_nanosleep were occuring. The
simple test for __uClinux__ was not sufficient.

Implement full detection of clock_nanosleep in incdefs.h by compiling a short C
file. incdefs.sh now sets a new HAVE_CLOCK_NANOSLEEP literal. missing.h is
changed accordingly.

For cross-compilation purposes CFLAGS in makefile is not set but += is used.
Also the CC variable is passed to the incdefs.sh script.

Signed-off-by: Petr Kulhavy <***@jikos.cz>
---
incdefs.sh | 14 ++++++++++++++
makefile | 4 ++--
missing.h | 15 +++++++++------
3 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/incdefs.sh b/incdefs.sh
index 8232b5c..9a870ac 100755
--- a/incdefs.sh
+++ b/incdefs.sh
@@ -40,6 +40,20 @@ user_flags()
done
done

+ # Look for clock_nanosleep().
+ echo '
+#include <time.h>
+
+void test(void)
+{
+ clock_nanosleep(CLOCK_REALTIME, 0, NULL, NULL);
+}
+ ' > .incdefs-test.c
+ if ${CC} -c -Werror .incdefs-test.c 2> /dev/null ; then
+ printf " -DHAVE_CLOCK_NANOSLEEP"
+ fi
+ rm -f .incdefs-test.c .incdefs-test.o
+
# Look for posix_spawn().
for d in $dirs; do
files=$(find $d -type f -name spawn.h)
diff --git a/makefile b/makefile
index f898336..a54ee00 100644
--- a/makefile
+++ b/makefile
@@ -20,7 +20,7 @@ KBUILD_OUTPUT =
DEBUG =
CC = $(CROSS_COMPILE)gcc
VER = -DVER=$(version)
-CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
+CFLAGS += -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS)
LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
PRG = ptp4l pmc phc2sys hwstamp_ctl phc_ctl timemaster
OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o fault.o \
@@ -33,7 +33,7 @@ OBJECTS = $(OBJ) hwstamp_ctl.o phc2sys.o phc_ctl.o pmc.o pmc_common.o \
SRC = $(OBJECTS:.o=.c)
DEPEND = $(OBJECTS:.o=.d)
srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
-incdefs := $(shell $(srcdir)/incdefs.sh)
+incdefs := $(shell CC="$(CC)" $(srcdir)/incdefs.sh)
version := $(shell $(srcdir)/version.sh $(srcdir))
VPATH = $(srcdir)

diff --git a/missing.h b/missing.h
index f7efd92..7279ece 100644
--- a/missing.h
+++ b/missing.h
@@ -69,18 +69,21 @@ static inline int clock_adjtime(clockid_t id, struct timex *tx)
}
#endif

-#ifndef __uClinux__
-
-#include <sys/timerfd.h>
-
-#else
-
+#if !defined ( HAVE_CLOCK_NANOSLEEP ) || defined ( __uClinux__ )
static inline int clock_nanosleep(clockid_t clock_id, int flags,
const struct timespec *request,
struct timespec *remain)
{
return syscall(__NR_clock_nanosleep, clock_id, flags, request, remain);
}
+#endif
+
+
+#ifndef __uClinux__
+
+#include <sys/timerfd.h>
+
+#else

static inline int timerfd_create(int clockid, int flags)
{
--
2.7.4
Richard Cochran
2017-05-15 21:29:41 UTC
Permalink
Post by Petr Kulhavy
On some platforms compilation issues due to clock_nanosleep were occuring. The
simple test for __uClinux__ was not sufficient.
Implement full detection of clock_nanosleep in incdefs.h by compiling a short C
file. incdefs.sh now sets a new HAVE_CLOCK_NANOSLEEP literal. missing.h is
changed accordingly.
No, no, no.

We are not going to start compiling fragments like autotools. That
way is obsolete madness. There has got to be a better way.

What problem are you trying to solve? Your uClinux actually does
offer clock_nanosleep?

Thanks,
Richard
Petr Kulhavy
2017-05-15 21:37:05 UTC
Permalink
I'm afraid this is the only way. I originally tried the same grep
approach as for the clock_adjtime, etc.
However it is too weak. On some targets clock_nanosleep is defined
conditionally in #if preprocessor directives.
There is no way to detect that with grep.

I'm trying to get linuxptp into Buildroot so that it compiles on all 49
targets.

Regards
Petr
Post by Richard Cochran
Post by Petr Kulhavy
On some platforms compilation issues due to clock_nanosleep were occuring. The
simple test for __uClinux__ was not sufficient.
Implement full detection of clock_nanosleep in incdefs.h by compiling a short C
file. incdefs.sh now sets a new HAVE_CLOCK_NANOSLEEP literal. missing.h is
changed accordingly.
No, no, no.
We are not going to start compiling fragments like autotools. That
way is obsolete madness. There has got to be a better way.
What problem are you trying to solve? Your uClinux actually does
offer clock_nanosleep?
Thanks,
Richard
Richard Cochran
2017-05-21 19:10:09 UTC
Permalink
Post by Petr Kulhavy
However it is too weak. On some targets clock_nanosleep is defined
conditionally in #if preprocessor directives.
There is no way to detect that with grep.
Is this a configuration option for uClibc? If so, then correct
solution is to enable that option in the library.

Or is clock_nanosleep always available starting with a particular
uClibc version? In that case, a version check in linuxptp would be
acceptable.
Post by Petr Kulhavy
I'm trying to get linuxptp into Buildroot so that it compiles on all 49
targets.
Post by Richard Cochran
We are not going to start compiling fragments like autotools.
Thanks,
Richard
Petr Kulhavy
2017-05-21 22:09:06 UTC
Permalink
Hi Richard,

the clock_nanosleep test fails in 6 of 49 built targets of Buildroot:
br-arm-full-nothread, br-bfin-full, br-m68k-68040-full,
br-microblazeel-full, br-openrisc-uclibc, br-sparc-uclibc.
They all use uclibc.

I'm not a uclibc expert, so I can't answer under what conditions
clock_nanosleep is defined. TYou would need to ask the uclibc authors.
But I don't see any configuration options for uclibc in Buildroot, the
existence of clock_nanosleep seems to be rather uclibc version and
platform dependent.

This is the error why it fails in all 6 cases:

/tmp/br-testpkg1/br-arm-full-nothread/host/usr/bin/arm-linux-gcc -Wall
-DVER=1.8 -D_GNU_SOURCE -DHAVE_CLOCK_ADJTIME -DHAVE_POSIX_SPAWN
-DHAVE_ONESTEP_SYNC -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64 -Os -c -o phc_ctl.o phc_ctl.c
phc2sys.c: In function ‘do_loop’:
phc2sys.c:618:3: warning: implicit declaration of function
‘clock_nanosleep’ [-Wimplicit-function-declaration]
clock_nanosleep(CLOCK_MONOTONIC, 0, &interval, NULL);
^

phc2sys.o: In function `do_loop':
phc2sys.c:(.text+0xdb0): undefined reference to `clock_nanosleep'


On some targets clock_nanosleep doesn't exist in time.h at all, on some
it's defined there but is conditioned by either:


# ifdef __USE_POSIX199309


or


# if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
# ifdef __UCLIBC_HAS_THREADS_NATIVE__



I neither understand or share your aversion to the autoconf approach. It
is a standard and well working solution. In my view it is the best
possible approach when running on a potentially unknown system.
I've just brought my two cents in the form of a pragmatic and working
proposal. If you have a better idea, feel free to implement it.
Currently linuxptp seems to rather fail with uclibc.

Regards
Petr
Post by Richard Cochran
Post by Petr Kulhavy
However it is too weak. On some targets clock_nanosleep is defined
conditionally in #if preprocessor directives.
There is no way to detect that with grep.
Is this a configuration option for uClibc? If so, then correct
solution is to enable that option in the library.
Or is clock_nanosleep always available starting with a particular
uClibc version? In that case, a version check in linuxptp would be
acceptable.
Post by Petr Kulhavy
I'm trying to get linuxptp into Buildroot so that it compiles on all 49
targets.
Post by Richard Cochran
We are not going to start compiling fragments like autotools.
Thanks,
Richard
Richard Cochran
2017-05-22 04:51:24 UTC
Permalink
Post by Petr Kulhavy
I'm not a uclibc expert, so I can't answer under what conditions
clock_nanosleep is defined. TYou would need to ask the uclibc authors.
And just who might they be?

If you want this to work on uClibc, then *you* could ask them!
Post by Petr Kulhavy
But I don't see any configuration options for uclibc in Buildroot,
But what about in uClibs itself?
Post by Petr Kulhavy
the
existence of clock_nanosleep seems to be rather uclibc version and platform
dependent.
That sounds like a promising lead...
Post by Petr Kulhavy
# ifdef __USE_POSIX199309
or
# if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
# ifdef __UCLIBC_HAS_THREADS_NATIVE__
If you find the right combination of feature test macros, then this
would be acceptable for our missing.h.
Post by Petr Kulhavy
I neither understand or share your aversion to the autoconf approach. It is
a standard and well working solution. In my view it is the best possible
approach when running on a potentially unknown system.
That is your view. Mine is more like this:

https://varnish-cache.org/docs/4.0/phk/autocrap.html
Post by Petr Kulhavy
I've just brought my two cents in the form of a pragmatic and working
proposal. If you have a better idea, feel free to implement it. Currently
linuxptp seems to rather fail with uclibc.
And it is going to stay that way unless you can find a reasonable
solution that does not involve autotools or compiling test programs.

Sorry,
Richard
Petr Kulhavy
2017-05-22 21:05:39 UTC
Permalink
Hi Richard,

It is not my primary objective to make your project run under uclibc.
I'm working on a project that uses Linuxptp on an embedded system, so I
needed to integrate it into Buildroot.
Since it was failing the integration test, I had to patch it. And I
contributed my patches because I find it good that the community can
profit from it.

I can't find any rational argument against test-compiling a piece of
code in that negatively loaded emotional outburst you referred to. So I
still don't see anything conceptually wrong on my patch.
If you don't like it, please take my email just as a bugreport: linuxptp
fails to build with uclibc, details in my previous emails.
I don't have the time and resources to investigate this deeper.

Regards
Petr
Post by Richard Cochran
Post by Petr Kulhavy
I'm not a uclibc expert, so I can't answer under what conditions
clock_nanosleep is defined. TYou would need to ask the uclibc authors.
And just who might they be?
If you want this to work on uClibc, then *you* could ask them!
Post by Petr Kulhavy
But I don't see any configuration options for uclibc in Buildroot,
But what about in uClibs itself?
Post by Petr Kulhavy
the
existence of clock_nanosleep seems to be rather uclibc version and platform
dependent.
That sounds like a promising lead...
Post by Petr Kulhavy
# ifdef __USE_POSIX199309
or
# if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
# ifdef __UCLIBC_HAS_THREADS_NATIVE__
If you find the right combination of feature test macros, then this
would be acceptable for our missing.h.
Post by Petr Kulhavy
I neither understand or share your aversion to the autoconf approach. It is
a standard and well working solution. In my view it is the best possible
approach when running on a potentially unknown system.
https://varnish-cache.org/docs/4.0/phk/autocrap.html
Post by Petr Kulhavy
I've just brought my two cents in the form of a pragmatic and working
proposal. If you have a better idea, feel free to implement it. Currently
linuxptp seems to rather fail with uclibc.
And it is going to stay that way unless you can find a reasonable
solution that does not involve autotools or compiling test programs.
Sorry,
Richard
Richard Cochran
2017-05-23 04:42:40 UTC
Permalink
Post by Petr Kulhavy
If you don't like it, please take my email just as a bugreport: linuxptp
fails to build with uclibc, details in my previous emails.
Let me fix that for you:

bugreport: Improperly configured uClibc lacks clock_nanosleep.
Post by Petr Kulhavy
I don't have the time and resources to investigate this deeper.
Then nothing will get done, but I really don't care.

Thanks,
Richard
Petr Kulhavy
2017-05-23 08:34:19 UTC
Permalink
That is misleading. Some earlier versions of uclibc completely lack
clock_nanosleep().

Petr
Post by Richard Cochran
Post by Petr Kulhavy
If you don't like it, please take my email just as a bugreport: linuxptp
fails to build with uclibc, details in my previous emails.
bugreport: Improperly configured uClibc lacks clock_nanosleep.
Post by Petr Kulhavy
I don't have the time and resources to investigate this deeper.
Then nothing will get done, but I really don't care.
Thanks,
Richard
Richard Cochran
2017-05-23 05:07:44 UTC
Permalink
I can't find any rational argument against test-compiling a piece of code in
that negatively loaded emotional outburst you referred to.
you still have to do the hard work and figure out the right way to
explain to the autocrap tools what you are trying to do and how to do
it

Compiling a test program is a lazy work around that fails to address
real issues. In this case, the problem is that sometimes uClibc omits
clock_nanosleep.

The real solution is to figure out why, and fix that in uClibc. A
second, less optimal solution would be to figure out how uClibc's
feature test macros advertise presence of clock_nanosleep (if indeed
they do that) and use those macros in missing.h.
I don't have the time and resources to investigate this deeper.
Right, and that is the point. It is "hard work" to find a proper
solution. Blindly slapping on autotools or similar is a cop-out.

Thanks,
Richard
Petr Kulhavy
2017-05-23 09:43:57 UTC
Permalink
Hi Richard,

I'm not sure that you fully understand the problem. It seems there are
currently four scenarios possible.
1) Some earlier versions of uclibc don't have clock_nanosleep() at all.
In some versions it is configurable as you correctly mentioned, so we
have case 2) is present and selected, 3) is present and not selected.
4) On some architectures it might not be present at all even with the
newer version of the library. Quoting the uclibc documentation of the
HAS_ADVANCED_REALTIME option:
"These functions are part of the Timers option and need not be available
on all implementations."

That is the current situation.

In software engineering you rely on well defined APIs or standards like
POSIX or C11. Not on internals or particular implementation of other
libraries - that would be a bad programming practice.
The __UCLIBC_HAS_ADVANCED_REALTIME__ is part of uclibc internals and
does not even guarantee the presence of clock_nanosleep().

Now the question is how to handle this less than optimal situation of
uclibc.
One option is to clearly define the boundaries where your software runs,
i.e. put the required libraries or features into prerequisites.
The other option (which linuxptp follows) is to detect the features and
adapt or workaround the missing features (missing.h).

Modifying the uclibc doesn't solve the problem for the past uclibc
versions until now.
Unless you want to be compatible only from some future version of uclibc
on, it is not an option.

Relying on internals of uclibc is not reliable (see the above quote),
not clean and will work only until someone from uclibc decides to change
the name of the config option.

Since the library doesn't provide a clear API or indication whether the
required feature is present and since this is C and not Java, there is
no clean way how to detect it.
That said, the test compilation is still the best working, forward
compatible, portable and clean approach (the only well defined API is
the header) for the current situation.

Regards
Petr
Post by Richard Cochran
I can't find any rational argument against test-compiling a piece of code in
that negatively loaded emotional outburst you referred to.
you still have to do the hard work and figure out the right way to
explain to the autocrap tools what you are trying to do and how to do
it
Compiling a test program is a lazy work around that fails to address
real issues. In this case, the problem is that sometimes uClibc omits
clock_nanosleep.
The real solution is to figure out why, and fix that in uClibc. A
second, less optimal solution would be to figure out how uClibc's
feature test macros advertise presence of clock_nanosleep (if indeed
they do that) and use those macros in missing.h.
I don't have the time and resources to investigate this deeper.
Right, and that is the point. It is "hard work" to find a proper
solution. Blindly slapping on autotools or similar is a cop-out.
Thanks,
Richard
Richard Cochran
2017-05-30 06:36:32 UTC
Permalink
Post by Petr Kulhavy
I'm not sure that you fully understand the problem. It seems there are
currently four scenarios possible.
Yeah, I get that. Your task then would have been to address the four
possibilities.
Post by Petr Kulhavy
Now the question is how to handle this less than optimal situation of
uclibc.
Post by Richard Cochran
The real solution is to figure out why, and fix that in uClibc. A
second, less optimal solution would be to figure out how uClibc's
feature test macros advertise presence of clock_nanosleep (if indeed
they do that) and use those macros in missing.h.
Since the library doesn't provide a clear API or indication whether the
required feature is present and since this is C and not Java, there is no
clean way how to detect it.
On the contrary, there is a clean way. One can use the feature test
macros. Patch follows.
Post by Petr Kulhavy
That said, the test compilation is still the best working, forward
compatible, portable and clean approach (the only well defined API is the
header) for the current situation.
Repeating this assertion over and over again doesn't make it any more
true.

You did come close to finding the simple solution to building against
uClibc, but instead of taking that last step, you slapped on an
autoconf-like workaround. The whole point of phk's "rant" article is
that we really should strive for proper solutions when it comes to
portability. Many times, this requires the hard work of analyzing the
problem in order to find the best solution.

Thanks,
Richard
Richard Cochran
2017-05-30 06:37:39 UTC
Permalink
Passes all 49 of buildroot's build tests with support/scripts/test-pk.
Append below is a buildroot patch for exercising the build. This
patch was adapted from:

http://lists.busybox.net/pipermail/buildroot/2017-May/192051.html

I changed the source to use git directly and removed

- the DEVELOPERS hunk (which no longer applies, fix is trivial)
- the patches for linuxptp, no longer necessary
- the broken LINUXPTP_INSTALL_INIT_SYSV macro


Richard Cochran (1):
Fix build when using uClinux.

missing.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

---8<---

diff --git a/package/Config.in b/package/Config.in
index d57813c5c..200ae009d 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1597,6 +1597,7 @@ menu "Networking applications"
source "package/links/Config.in"
source "package/linphone/Config.in"
source "package/linux-zigbee/Config.in"
+ source "package/linuxptp/Config.in"
source "package/lldpd/Config.in"
source "package/lrzsz/Config.in"
source "package/macchanger/Config.in"
diff --git a/package/linuxptp/Config.in b/package/linuxptp/Config.in
new file mode 100644
index 000000000..a5604ed24
--- /dev/null
+++ b/package/linuxptp/Config.in
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_LINUXPTP
+ bool "linuxptp"
+ help
+ The Linux PTP Project is the Precision Time Protocol
+ implementation according to IEEE standard 1588 for Linux.
+
+ The dual design goals are to provide a robust implementation
+ of the standard and to use the most relevant and modern
+ Application Programming Interfaces (API) offered by the Linux
+ kernel. Supporting legacy APIs and other platforms is not a
+ goal.
+
+ http://linuxptp.sourceforge.net/
diff --git a/package/linuxptp/S65linuxptp b/package/linuxptp/S65linuxptp
new file mode 100755
index 000000000..46b8921fd
--- /dev/null
+++ b/package/linuxptp/S65linuxptp
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Start linuxptp
+#
+
+start() {
+ printf "Starting linuxptp daemon: "
+ start-stop-daemon -S -b -q -p /var/run/linuxptp-ptp4l.pid \
+ -x /usr/sbin/ptp4l -- -f /etc/linuxptp.cfg
+ [ $? = 0 ] && echo "OK" || echo "FAIL"
+
+ printf "Starting linuxptp system clock synchronization: "
+ start-stop-daemon -S -b -q -p /var/run/linuxptp-phc2sys.pid \
+ -x /usr/sbin/phc2sys -- -s eth0 -c CLOCK_REALTIME -w -S 1.0
+ [ $? = 0 ] && echo "OK" || echo "FAIL"
+}
+
+stop() {
+ printf "Stopping linuxptp system clock synchronization: "
+ start-stop-daemon -K -q -p /var/run/linuxptp-phc2sys.pid \
+ -x /usr/sbin/phc2sys
+ echo "OK"
+
+ printf "Stopping linuxptp daemon: "
+ start-stop-daemon -K -q -p /var/run/linuxptp-ptp4l.pid \
+ -x /usr/sbin/ptp4l
+ echo "OK"
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart|reload)
+ stop
+ start
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+esac
+
+exit $?
diff --git a/package/linuxptp/linuxptp-system-clock.service b/package/linuxptp/linuxptp-system-clock.service
new file mode 100644
index 000000000..73272542c
--- /dev/null
+++ b/package/linuxptp/linuxptp-system-clock.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Precision Time Protocol system clock synchronization
+After=syslog.target network.target
+
+[Service]
+ExecStart=/usr/sbin/phc2sys -s /dev/ptp0 -c CLOCK_REALTIME -w -S 1.0
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
+WantedBy=linuxptp.service
diff --git a/package/linuxptp/linuxptp.cfg b/package/linuxptp/linuxptp.cfg
new file mode 100644
index 000000000..f9d02e8d9
--- /dev/null
+++ b/package/linuxptp/linuxptp.cfg
@@ -0,0 +1,19 @@
+# LinuxPTP configuration file for synchronizing the system clock to
+# a remote PTP master in slave-only mode.
+#
+# By default synchronize time in slave-only mode using UDP and hardware time
+# stamps on eth0. If the difference to master is >1.0 second correct by
+# stepping the clock instead of adjusting the frequency.
+#
+# If you change the configuration don't forget to update the phc2sys
+# parameters accordingly in linuxptp-system-clock.service (systemd)
+# or the linuxptp SysV init script.
+
+[global]
+slaveOnly 1
+delay_mechanism Auto
+network_transport UDPv4
+time_stamping hardware
+step_threshold 1.0
+
+[eth0]
diff --git a/package/linuxptp/linuxptp.hash b/package/linuxptp/linuxptp.hash
new file mode 100644
index 000000000..1ac94434d
--- /dev/null
+++ b/package/linuxptp/linuxptp.hash
@@ -0,0 +1,2 @@
+# Locally computed:
+sha256 fa8e00f6ec73cefa7bb313dce7f60dfe5eb9e2bde3353594e9ac18edc93e5165 linuxptp-1.8.tgz
diff --git a/package/linuxptp/linuxptp.mk b/package/linuxptp/linuxptp.mk
new file mode 100644
index 000000000..44f56f98d
--- /dev/null
+++ b/package/linuxptp/linuxptp.mk
@@ -0,0 +1,39 @@
+################################################################################
+#
+# Linux PTP
+#
+################################################################################
+
+LINUXPTP_SITE = git://git.code.sf.net/p/linuxptp/code
+LINUXPTP_SITE_METHOD = git
+LINUXPTP_VERSION = 8d024ed8bf198bd31ae86d21a58f4e270b6d5469
+
+LINUXPTP_LICENSE = GPL-2.0+
+LINUXPTP_LICENSE_FILES = COPYING
+
+define LINUXPTP_BUILD_CMDS
+ $(TARGET_MAKE_ENV) $(MAKE) KBUILD_OUTPUT=$(TARGET_DIR) \
+ EXTRA_CFLAGS="$(TARGET_CFLAGS)" EXTRA_LDFLAGS="$(TARGET_LDFLAGS)" \
+ CC="$(TARGET_CC)" \
+ -C $(@D) all
+endef
+
+define LINUXPTP_INSTALL_TARGET_CMDS
+ $(TARGET_MAKE_ENV) $(MAKE) prefix=/usr DESTDIR=$(TARGET_DIR) \
+ $(TARGET_CONFIGURE_OPTS) -C $(@D) install
+
+ $(INSTALL) -D -m 644 $(LINUXPTP_PKGDIR)/linuxptp.cfg \
+ $(TARGET_DIR)/etc/linuxptp.cfg
+endef
+
+define LINUXPTP_INSTALL_INIT_SYSTEMD
+ $(INSTALL) -D -m 644 $(LINUXPTP_PKGDIR)/linuxptp.service \
+ $(TARGET_DIR)/usr/lib/systemd/system/linuxptp.service
+ $(INSTALL) -D -m 644 $(LINUXPTP_PKGDIR)/linuxptp-system-clock.service \
+ $(TARGET_DIR)/usr/lib/systemd/system/linuxptp-system-clock.service
+ mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+ ln -sf ../../../../usr/lib/systemd/system/linuxptp.service \
+ $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/linuxptp.service
+endef
+
+$(eval $(generic-package))
diff --git a/package/linuxptp/linuxptp.service b/package/linuxptp/linuxptp.service
new file mode 100644
index 000000000..f69043063
--- /dev/null
+++ b/package/linuxptp/linuxptp.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Precision Time Protocol daemon
+After=syslog.target network.target
+Wants=linuxptp-system-clock.service
+
+[Service]
+ExecStart=/usr/sbin/ptp4l -f /etc/linuxptp.cfg
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
--
2.11.0
Richard Cochran
2017-05-30 06:51:48 UTC
Permalink
Post by Richard Cochran
diff --git a/package/linuxptp/linuxptp.mk b/package/linuxptp/linuxptp.mk
new file mode 100644
index 000000000..44f56f98d
--- /dev/null
+++ b/package/linuxptp/linuxptp.mk
@@ -0,0 +1,39 @@
+################################################################################
+#
+# Linux PTP
+#
+################################################################################
+
+LINUXPTP_SITE = git://git.code.sf.net/p/linuxptp/code
+LINUXPTP_SITE_METHOD = git
+LINUXPTP_VERSION = 8d024ed8bf198bd31ae86d21a58f4e270b6d5469
FYI, I messed up the author info on that commit. The corrected author
info is in 97c351cafd7327fd28047580c9e2528a6f7e742b , and that is the
one I will merge into master, if all goes well.

Thanks,
Richard
Petr Kulhavy
2017-06-07 17:50:49 UTC
Permalink
I'm going to use that version to create a new patch for Buildroot.
FYI there are still the "may be used uninitialised" warnings in
phc2sys.c I mentioned earlier. See the logfile when running the BR test
script.

Regards
Petr
Post by Richard Cochran
Post by Richard Cochran
diff --git a/package/linuxptp/linuxptp.mk b/package/linuxptp/linuxptp.mk
new file mode 100644
index 000000000..44f56f98d
--- /dev/null
+++ b/package/linuxptp/linuxptp.mk
@@ -0,0 +1,39 @@
+################################################################################
+#
+# Linux PTP
+#
+################################################################################
+
+LINUXPTP_SITE = git://git.code.sf.net/p/linuxptp/code
+LINUXPTP_SITE_METHOD = git
+LINUXPTP_VERSION = 8d024ed8bf198bd31ae86d21a58f4e270b6d5469
FYI, I messed up the author info on that commit. The corrected author
info is in 97c351cafd7327fd28047580c9e2528a6f7e742b , and that is the
one I will merge into master, if all goes well.
Thanks,
Richard
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
Richard Cochran
2017-05-30 06:37:40 UTC
Permalink
From: Richard Cochran <***@linutronix.de>

Unfortunately uClinux is rather inconsistent with respect to
clock_nanosleep(). Older versions of uclibc lack that function, while
newer versions may include the declaration but still lack the
definition, depending on whether pthreads are selected in the
configuration.

This patch works around uClinux shortcomings by using the library call
when available at compile time, otherwise falling back to syscall().

Signed-off-by: Richard Cochran <***@gmail.com>
---
missing.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/missing.h b/missing.h
index f7efd92..7bc1776 100644
--- a/missing.h
+++ b/missing.h
@@ -69,7 +69,10 @@ static inline int clock_adjtime(clockid_t id, struct timex *tx)
}
#endif

-#ifndef __uClinux__
+#ifdef __UCLIBC__
+
+#if (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L) && \
+ defined __UCLIBC_HAS_THREADS_NATIVE__

#include <sys/timerfd.h>

@@ -93,6 +96,11 @@ static inline int timerfd_settime(int fd, int flags,
{
return syscall(__NR_timerfd_settime, fd, flags, new_value, old_value);
}
+#endif
+
+#else /*__UCLIBC__*/
+
+#include <sys/timerfd.h>

#endif
--
2.1.4
Richard Cochran
2017-05-30 06:00:24 UTC
Permalink
Post by Petr Kulhavy
I'm trying to get linuxptp into Buildroot so that it compiles on all 49
targets.
FYI, your buildroot patch

http://lists.busybox.net/pipermail/buildroot/2017-May/192051.html

has another issue. If you build beaglebone_defconfig and then add
Post by Petr Kulhavy
linuxptp 1.8 Installing to target
PATH="/scratch/richard/buildroot/output/host/bin:/scratch/richard/buildroot/output/host/sbin:/scratch/richard/buildroot/output/host/usr/bin:/scratch/richard/buildroot/output/host/usr/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" /usr/bin/make -j32 prefix=/usr DESTDIR=/scratch/richard/buildroot/output/target PATH="/scratch/richard/buildroot/output/host/bin:/scratch/richard/buildroot/output/host/sbin:/scratch/richard/buildroot/output/host/usr/bin:/scratch/richard/buildroot/output/host/usr/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" AR="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ar" AS="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-as" LD="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ld" NM="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-nm" CC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gcc" GCC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gcc" CPP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-cpp" CXX="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-g++" FC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gfortran" F77="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gfortran" RANLIB="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ranlib" READELF="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-readelf" STRIP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-strip" OBJCOPY="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-objcopy" OBJDUMP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-objdump" AR_FOR_BUILD="/usr/bin/ar" AS_FOR_BUILD="/usr/bin/as" CC_FOR_BUILD="/usr/bin/gcc" GCC_FOR_BUILD="/usr/bin/gcc" CXX_FOR_BUILD="/usr/bin/g++" LD_FOR_BUILD="/usr/bin/ld" CPPFLAGS_FOR_BUILD="-I/scratch/richard/buildroot/output/host/usr/include" CFLAGS_FOR_BUILD="-O2 -I/scratch/richard/buildroot/output/host/usr/include" CXXFLAGS_FOR_BUILD="-O2 -I/scratch/richard/buildroot/output/host/usr/include" LDFLAGS_FOR_BUILD="-L/scratch/richard/buildroot/output/host/lib -L/scratch/richard/buildroot/output/host/usr/lib -Wl,-rpath,/scratch/richard/buildroot/output/host/usr/lib" FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-as" DEFAULT_LINKER="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ld" CPPFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os " CXXFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os " LDFLAGS="" FCFLAGS=" -Os " FFLAGS=" -Os " PKG_CONFIG="/scratch/richard/buildroot/output/host/usr/bin/pkg-config" STAGING_DIR="/scratch/richard/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabihf/sysroot" INTLTOOL_PERL=/usr/bin/perl CXX=false -C /scratch/richard/buildroot/output/build/linuxptp-1.8 install
make[1]: Entering directory '/scratch/richard/buildroot/output/build/linuxptp-1.8'
install -p -m 755 -d /scratch/richard/buildroot/output/target/usr/sbin /scratch/richard/buildroot/output/target/usr/man/man8
install ptp4l pmc phc2sys hwstamp_ctl phc_ctl timemaster /scratch/richard/buildroot/output/target/usr/sbin
install -p -m 644 -t /scratch/richard/buildroot/output/target/usr/man/man8 ptp4l.8 pmc.8 phc2sys.8 hwstamp_ctl.8 phc_ctl.8 timemaster.8
make[1]: Leaving directory '/scratch/richard/buildroot/output/build/linuxptp-1.8'
/usr/bin/install -D -m 644 package/linuxptp//linuxptp.cfg /scratch/richard/buildroot/output/target/etc/linuxptp.cfg
/usr/bin/install -m 755 -D /scratch/richard/buildroot/output/build/linuxptp-1.8/package/linuxptp/S65linuxptp /scratch/richard/buildroot/output/target/etc/init.d/S65linuxptp
/usr/bin/install: cannot stat '/scratch/richard/buildroot/output/build/linuxptp-1.8/package/linuxptp/S65linuxptp': No such file or directory
package/pkg-generic.mk:308: recipe for target '/scratch/richard/buildroot/output/build/linuxptp-1.8/.stamp_target_installed' failed
make: *** [/scratch/richard/buildroot/output/build/linuxptp-1.8/.stamp_target_installed] Error 1

Thanks,
Richard
Petr Kulhavy
2017-05-31 09:16:44 UTC
Permalink
Thanks, Richard. That's a good catch. I'm going to fix that.

Regards
Petrr
Post by Richard Cochran
Post by Petr Kulhavy
I'm trying to get linuxptp into Buildroot so that it compiles on all 49
targets.
FYI, your buildroot patch
http://lists.busybox.net/pipermail/buildroot/2017-May/192051.html
has another issue. If you build beaglebone_defconfig and then add
Post by Petr Kulhavy
linuxptp 1.8 Installing to target
PATH="/scratch/richard/buildroot/output/host/bin:/scratch/richard/buildroot/output/host/sbin:/scratch/richard/buildroot/output/host/usr/bin:/scratch/richard/buildroot/output/host/usr/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" /usr/bin/make -j32 prefix=/usr DESTDIR=/scratch/richard/buildroot/output/target PATH="/scratch/richard/buildroot/output/host/bin:/scratch/richard/buildroot/output/host/sbin:/scratch/richard/buildroot/output/host/usr/bin:/scratch/richard/buildroot/output/host/usr/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" AR="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ar" AS="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-as" LD="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ld" NM="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-nm" CC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gcc" GCC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gcc" CPP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-cpp" CXX="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-g++" FC="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gfortran" F77="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-gfortran" RANLIB="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ranlib" READELF="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-readelf" STRIP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-strip" OBJCOPY="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-objcopy" OBJDUMP="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-objdump" AR_FOR_BUILD="/usr/bin/ar" AS_FOR_BUILD="/usr/bin/as" CC_FOR_BUILD="/usr/bin/gcc" GCC_FOR_BUILD="/usr/bin/gcc" CXX_FOR_BUILD="/usr/bin/g++" LD_FOR_BUILD="/usr/bin/ld" CPPFLAGS_FOR_BUILD="-I/scratch/richard/buildroot/output/host/usr/include" CFLAGS_FOR_BUILD="-O2 -I/scratch/richard/buildroot/output/host/usr/include" CXXFLAGS_FOR_BUILD="-O2 -I/scratch/richard/buildroot/output/host/usr/include" LDFLAGS_FOR_BUILD="-L/scratch/richard/buildroot/output/host/lib -L/scratch/richard/buildroot/output/host/usr/lib -Wl,-rpath,/scratch/richard/buildroot/output/host/usr/lib" FCFLAGS_FOR_BUILD="" DEFAULT_ASSEMBLER="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-as" DEFAULT_LINKER="/scratch/richard/buildroot/output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-ld" CPPFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os " CXXFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os " LDFLAGS="" FCFLAGS=" -Os " FFLAGS=" -Os " PKG_CONFIG="/scratch/richard/buildroot/output/host/usr/bin/pkg-config" STAGING_DIR="/scratch/richard/buildroot/output/host/usr/arm-buildroot-linux-uclibcgnueabihf/sysroot" INTLTOOL_PERL=/usr/bin/perl CXX=false -C /scratch/richard/buildroot/output/build/linuxptp-1.8 install
make[1]: Entering directory '/scratch/richard/buildroot/output/build/linuxptp-1.8'
install -p -m 755 -d /scratch/richard/buildroot/output/target/usr/sbin /scratch/richard/buildroot/output/target/usr/man/man8
install ptp4l pmc phc2sys hwstamp_ctl phc_ctl timemaster /scratch/richard/buildroot/output/target/usr/sbin
install -p -m 644 -t /scratch/richard/buildroot/output/target/usr/man/man8 ptp4l.8 pmc.8 phc2sys.8 hwstamp_ctl.8 phc_ctl.8 timemaster.8
make[1]: Leaving directory '/scratch/richard/buildroot/output/build/linuxptp-1.8'
/usr/bin/install -D -m 644 package/linuxptp//linuxptp.cfg /scratch/richard/buildroot/output/target/etc/linuxptp.cfg
/usr/bin/install -m 755 -D /scratch/richard/buildroot/output/build/linuxptp-1.8/package/linuxptp/S65linuxptp /scratch/richard/buildroot/output/target/etc/init.d/S65linuxptp
/usr/bin/install: cannot stat '/scratch/richard/buildroot/output/build/linuxptp-1.8/package/linuxptp/S65linuxptp': No such file or directory
package/pkg-generic.mk:308: recipe for target '/scratch/richard/buildroot/output/build/linuxptp-1.8/.stamp_target_installed' failed
make: *** [/scratch/richard/buildroot/output/build/linuxptp-1.8/.stamp_target_installed] Error 1
Thanks,
Richard
Richard Cochran
2017-05-15 21:24:18 UTC
Permalink
On some targets the time_t structure was missing and the compilation was failing.
---
util.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/util.h b/util.h
index e912f19..3efde5c 100644
--- a/util.h
+++ b/util.h
@@ -22,6 +22,7 @@
#include "ddt.h"
#include "ether.h"
+#include <time.h>
This patch is no longer needed, since Stephen Walker fixed the same
issue just the other day.

[ BTW, We put the standard includes <> first, then the local includes "" ]

Thanks,
Richard
Richard Cochran
2017-05-15 21:24:58 UTC
Permalink
Post by Petr Kulhavy
On some platforms like br-arm-cortex-a9-musl struct ethhdr was defined twice
due to including of both linux/if_ether.h and netinet/ether.h. Which lead
to a compilation error.
Remove netinet/ether.h as the official header for struct ethhdr is
linux/if_ether.h
Applied.

Thanks,
Richard
Loading...