diff options
Diffstat (limited to 'recipes-support/ntp')
-rw-r--r-- | recipes-support/ntp/files/logtime.patch | 79 | ||||
-rw-r--r-- | recipes-support/ntp/files/ntp.conf.patch | 55 | ||||
-rw-r--r-- | recipes-support/ntp/files/ntpd-default | 35 | ||||
-rw-r--r-- | recipes-support/ntp/files/ntpd-init.patch | 96 | ||||
-rw-r--r-- | recipes-support/ntp/ntp_4.2.6p5.bbappend | 33 |
5 files changed, 298 insertions, 0 deletions
diff --git a/recipes-support/ntp/files/logtime.patch b/recipes-support/ntp/files/logtime.patch new file mode 100644 index 0000000..6b104ce --- /dev/null +++ b/recipes-support/ntp/files/logtime.patch @@ -0,0 +1,79 @@ + Create a test to log time since boot MONOTONIC_RAW or uptime + and the REALTIME clock (UTC) + Not real sure how the build should work. To build logtime + do bitbake -c devshell ntp + Then cd clockstuff, and to: + make logtime +============================================================== +diff -Naur old/clockstuff/logtime.c new/clockstuff/logtime.c +--- old/clockstuff/logtime.c 1969-12-31 18:00:00.000000000 -0600 ++++ new/clockstuff/logtime.c 2017-01-27 16:55:46.420307603 -0600 +@@ -0,0 +1,44 @@ ++#include <time.h> ++#include <stdio.h> ++#include <unistd.h> ++#include <stdarg.h> ++#include <syslog.h> ++/* ++ * Generate a log messages 4 times per second ++ * to verify leap second. The CLOCK_MONOTONIC_RAW ++ * is the time since boot unaffected by adjustments. ++ * ++ * CLOCK_REALTIME is the UTC clock, which is affected ++ * by leap seconds. ++ * ++ * Program does not exit. ++ * ++ */ ++main() ++{ ++ openlog("CTST",0,LOG_LOCAL2); ++ while(1) { ++ struct timespec ts,unused,ep; ++ if (clock_gettime(CLOCK_MONOTONIC,&ts) == 0) { ++ ++ if(ts.tv_nsec < 750000000) ++ ts.tv_nsec += 250000000; ++ else { ++ ts.tv_nsec -= 750000000; ++ ts.tv_sec += 1; ++ } ++ clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&ts,&unused); ++ clock_gettime(CLOCK_MONOTONIC_RAW,&ts); ++ ts.tv_nsec /= 1000000; ++ clock_gettime(CLOCK_REALTIME,&ep); ++ ep.tv_nsec /= 1000000; ++ syslog(LOG_NOTICE,"epoch: %lu.%3.3ld boot: %lu.%3.3ld", ++ ep.tv_sec,ep.tv_nsec, ++ ts.tv_sec,ts.tv_nsec); ++ ++ } ++ ++ ++ } ++ ++} +diff -Naur old/clockstuff/Makefile.am new/clockstuff/Makefile.am +--- old/clockstuff/Makefile.am 2017-01-27 16:50:58.929973639 -0600 ++++ new/clockstuff/Makefile.am 2017-01-27 16:53:22.625139584 -0600 +@@ -1,7 +1,7 @@ + #AUTOMAKE_OPTIONS = ../ansi2knr no-dependencies + AUTOMAKE_OPTIONS = +-noinst_PROGRAMS = @PROPDELAY@ @CHUTEST@ @CLKTEST@ +-EXTRA_PROGRAMS = propdelay chutest clktest ++noinst_PROGRAMS = @PROPDELAY@ @CHUTEST@ @CLKTEST@ @LOGTIME@ ++EXTRA_PROGRAMS = propdelay chutest clktest logtime + + INCLUDES = -I$(top_srcdir)/include + # We need -lm (and perhaps $(COMPAT) for propdelay, -lntp for {chu,clk}test +diff -Naur old/configure.ac new/configure.ac +--- old/configure.ac 2017-01-27 17:59:46.940532782 -0600 ++++ new/configure.ac 2017-01-27 17:55:26.626841232 -0600 +@@ -4115,6 +4115,7 @@ + AC_SUBST([PROPDELAY]) dnl Set to "propdelay" + AC_SUBST([CHUTEST]) dnl Set to "chutest" + AC_SUBST([CLKTEST]) dnl Set to "clktest" ++AC_SUBST([LOGTIME]) dnl Set to "logtime" + + AC_SUBST([MAKE_ADJTIMED]) + AC_MSG_CHECKING([if we want HP-UX adjtimed support]) diff --git a/recipes-support/ntp/files/ntp.conf.patch b/recipes-support/ntp/files/ntp.conf.patch new file mode 100644 index 0000000..bb1dcfe --- /dev/null +++ b/recipes-support/ntp/files/ntp.conf.patch @@ -0,0 +1,55 @@ +diff -Naur old/ntp.conf new/ntp.conf +--- old/ntp.conf 2017-02-02 19:09:54.524791189 -0600 ++++ new/ntp.conf 2017-02-02 19:06:41.744669788 -0600 +@@ -1,16 +1,47 @@ +-# This is the most basic ntp configuration file + # The driftfile must remain in a place specific to this + # machine - it records the machine specific clock error +-driftfile /etc/ntp.drift ++# Driftfile must be in a directory owned by ntp ++driftfile /var/lib/ntp/ntp.drift ++ ++# The following code is for evaluating the timeserver. ++# Remove the # to activate the statistics ++# statsdir must start in column 1 for the initscript to ++# create the directory, in case it is volatile. ++# ++# statistics loopstats ++# statistics peerstats ++# statsdir /var/log/ntpstats ++# filegen peerstats file peerstats type day link enable ++# filegen loopstats file loopstats type day link enable ++ ++# This is the US timeserver pool. You should use a pool ++# close to your location. ++#pool us.pool.ntp.org iburst ++ + # This should be a server that is close (in IP terms) + # to the machine. Add other servers as required. +-# Unless you un-comment the line below ntpd will sync +-# only against the local system clock. + # + # server time.server.example.com + # ++ ++restrict default kod nomodify notrap nopeer noquery ++restrict -6 default kod nomodify notrap nopeer noquery ++restrict 127.0.0.1 mask 255.255.255.0 ++restrict -6 ::1 ++ ++# GPS Serial data reference (NTP0) ++# This sets the GPS 50 milliseconds slower than the PPS. ++server 127.127.28.0 true ++fudge 127.127.28.0 time1 0.050 refid GPS ++ ++# GPS PPS reference (NTP2) ++server 127.127.28.2 prefer true ++fudge 127.127.28.2 time1 0.000 refid PPS ++ + # Using local hardware clock as fallback + # Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself ++# The stratum should be a high value so this does not get chosen ++# except in dire circumstances. + server 127.127.1.0 + fudge 127.127.1.0 stratum 14 + # Defining a default security setting diff --git a/recipes-support/ntp/files/ntpd-default b/recipes-support/ntp/files/ntpd-default new file mode 100644 index 0000000..ed7a6ec --- /dev/null +++ b/recipes-support/ntp/files/ntpd-default @@ -0,0 +1,35 @@ +ENABLED="yes" + +CONFIGFILE=/etc/ntp.conf + +# The GPSD_* parameters in this file are ignored +# if the uBlox GPS is not present. + +# Require a GPS lock/fix before starting NTP +# This is needed if we are not using NTP servers. +# NTP will not work with the GPS if the GPS is not +# locked before starting. +# See /etc/default/gpsd for the states required. +GPSD_REQUIRED=1 + +# Number of seconds between testing for a GPS +# lock prior to calling ntpd. +GPSD_WAIT_TIME=120 + +# Since the HW Clock could be off by a second or +# so, our GPS might get marked as a false ticker +# if we do not set the system clock to the GPS +# first. The current correct way to do this +# according to the ntp doc is ntpd -gq -c conffile +# which must be done before ntpd is started. +# conffile should exclude the local clock, so it is +# ignored while doing the initial sync. +# ntpd -gq apparently does not work with the GPS +# when tested with the clock more than one day off +# and no ntpd. The gps shared memory is never polled. +# +# If there is a uBlox GPS present, the time is +# read from the GPS to initialize the system time +# before NTP is started. +SET_SYSTEM_CLOCK=1 + diff --git a/recipes-support/ntp/files/ntpd-init.patch b/recipes-support/ntp/files/ntpd-init.patch new file mode 100644 index 0000000..2ef7e0b --- /dev/null +++ b/recipes-support/ntp/files/ntpd-init.patch @@ -0,0 +1,96 @@ +diff -Naur old/ntpd new/ntpd +--- old/ntpd 2017-02-06 09:21:52.607908299 -0600 ++++ new/ntpd 2017-02-06 09:22:52.417169090 -0600 +@@ -1,6 +1,8 @@ +-#! /bin/sh ++#! /bin/bash + # ++. /etc/default/ntpd + PATH=/sbin:/bin:/usr/bin:/usr/sbin ++GNSSRST=/sys/devices/platform/mts-io/gnss-reset + + # ntpd init.d script for ntpdc from ntp.isc.org + test -x /usr/sbin/ntpd -a -r /etc/ntp.conf || exit 0 +@@ -18,13 +20,29 @@ + } + } + startdaemon(){ +- # The -g option allows ntpd to step the time to correct it just +- # once. The daemon will exit if the clock drifts too much after +- # this. If ntpd seems to disappear after a while assume TICKADJ +- # above is set to a totally incorrect value. +- echo -n "Starting ntpd: " +- start-stop-daemon --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" +- echo "done" ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd --test -- -u ntp:ntp -p /var/run/ntp.pid "$@" \ ++ || return 1 ++ if [[ -x /usr/sbin/gpsd_ubx_settime ]] && ((GPSD_REQUIRED == 1)) && [[ -L /dev/gps0 ]] && [[ -f "${GNSSRST}" ]]; then ++ . /etc/default/gpsd ++ if ((SET_SYSTEM_CLOCK == 1)) && /usr/sbin/gpsd_ubx_settime ; then ++ # We just set the system time by the GPS. Should be within 2 seconds. ++ # Now that we are close to the correct system time, we ++ # use the ntpd one shot option to get to less than ++ # 250mS error so that we don't waste time adjusting the clock. ++ /usr/sbin/ntpd -gq ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" ++ else ++ # Need a GPS fix before startint ntp. Try again later. ++ /usr/sbin/start-stop-daemon -b -n z1e9d3qb -N -20 --start -x /bin/bash -- -c "sleep $GPSD_WAIT_TIME;/etc/init.d/ntpd start" ++ fi ++ else ++ if ((SET_SYSTEM_CLOCK == 1)) ; then ++ # Sets the clock and exits. ++ ntpd -gq ++ shift ++ fi ++ /usr/sbin/start-stop-daemon -N -20 --start -x /usr/sbin/ntpd -- -u ntp:ntp -p /var/run/ntp.pid "$@" ++ fi + } + stopdaemon(){ + echo -n "Stopping ntpd: " +@@ -34,24 +52,38 @@ + + case "$1" in + start) +- settick +- startdaemon -g ++ if ! [[ $ENABLED =~ ^[yY][eE][sS]$ ]] ; then ++ exit 0 ++ fi ++ if [[ -n "$CONFIGFILE" ]] ; then ++ CONFIGOPT="-c ${CONFIGFILE}" ++ STATSDIR=$(grep "^statsdir" ${CONFIGFILE} | sed -r 's/[^[:space:]]+[[:space:]]//') ++ if ((${#STATSDIR} > 0)) && ! [[ -d ${STATSDIR} ]] ; then ++ echo Make ${STATSDIR} ++ mkdir -m 0755 -p ${STATSDIR} ++ fi ++ if [[ -d ${STATSDIR} ]] ; then ++ chown ntp:ntp ${STATSDIR} >/dev/null 2>&1 ++ fi ++ fi ++ settick ++ startdaemon -g $CONFIGOPT + ;; + stop) +- stopdaemon ++ stopdaemon + ;; + force-reload) +- stopdaemon +- settick ++ stopdaemon ++ settick + startdaemon -g + ;; + restart) +- # Don't reset the tick here ++ # Don't reset the tick here + stopdaemon + startdaemon -g + ;; + reload) +- # Must do this by hand, but don't do -g ++ # Must do this by hand, but don't do -g + stopdaemon + startdaemon + ;; diff --git a/recipes-support/ntp/ntp_4.2.6p5.bbappend b/recipes-support/ntp/ntp_4.2.6p5.bbappend new file mode 100644 index 0000000..8460fda --- /dev/null +++ b/recipes-support/ntp/ntp_4.2.6p5.bbappend @@ -0,0 +1,33 @@ +PR .= ".mlinux2" + +SRC_URI += " file://ntpd-init.patch;patchdir=.. \ + file://ntp.conf.patch;patchdir=.. \ + file://ntpd-default \ + file://logtime.patch \ + " +FILESEXTRAPATHS_prepend := "${THISDIR}/files" + +python do_patch_prepend () { + import os +} + +do_install_append() { + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/ntpd-default ${D}${sysconfdir}/default/ntpd.default + + drdir=${D}${localstatedir}/lib/ntp + install -d -m 0755 -p ${drdir} + drfile="${drdir}/ntp.drift" + touch ${drfile} + chmod 664 ${drfile} + chown -R ntp:ntp ${drdir} +} +pkg_postinst_${PN}_append() { + update-alternatives --install ${sysconfdir}/default/ntpd ntpd-defaults ${sysconfdir}/default/ntpd.default 10 +} + +pkg_postrm_${PN}_append() { + update-alternatives --remove ntpd-defaults ${sysconfdir}/default/ntpd.default +} +FILES_${PN} += "${sysconfdir}/default/ntpd.default ${localstatedir}/lib/*" +CONFFILES_${PN} += "${sysconfdir}/default/ntpd.default" |