From: Florian Fainelli Date: Wed, 27 Dec 2006 19:21:05 +0000 (+0000) Subject: Add ntpd (#1065) X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fsvn-archive%2Farchive.git;a=commitdiff_plain;h=71e771af94c634b51d8af9b4a8f3131a0daa9b51;hp=a3d10bd2aef003ffa02500596b16970e0f1bdb09 Add ntpd (#1065) SVN-Revision: 5908 --- diff --git a/net/ntpd/Makefile b/net/ntpd/Makefile new file mode 100644 index 0000000000..2acd6a7207 --- /dev/null +++ b/net/ntpd/Makefile @@ -0,0 +1,68 @@ +# +# Copyright (C) 2006 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +# $Id: Makefile 5624 2006-11-23 00:29:07Z nbd $ + +include $(TOPDIR)/rules.mk + +PKG_NAME:=ntp +PKG_VERSION:=4.2.2p4 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ +PKG_MD5SUM:=916fe57525f8327f340b203f129088fa +PKG_CAT:=zcat + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk + +define Package/ntpd + SECTION:=net + CATEGORY:=Network + TITLE:=full featured NTP server + DEPENDS:=+libreadline + DESCRIPTION:=\ + The full featured original ntpd + URL:=http://www.ntp.org/ +endef + +define Package/ntpd/conffiles +/etc/ntp.conf +endef + +define Build/Configure + $(call Build/Configure/Default, \ + --disable-all-clocks \ + --disable-parse-clocks \ + --enable-NMEA \ + --enable-LOCAL-CLOCK \ + --enable-SHM \ + --enable-linuxcaps \ + ) +endef + +define Build/Compile + $(MAKE) -C $(PKG_BUILD_DIR) \ + CFLAGS="$(TARGET_CFLAGS)" +endef + +define Package/ntpd/install + $(INSTALL_DIR) $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpd/ntpd $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpdate/ntpdate $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpdc/ntpdc $(1)/usr/sbin/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpq/ntpq $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/etc + $(INSTALL_DATA) ./files/ntp.conf $(1)/etc/ + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_DATA) ./files/ntpd.init $(1)/etc/init.d/ntpd + $(INSTALL_DIR) $(1)/etc/hotplug.d/iface + $(INSTALL_DATA) ./files/ntpd.hotplug $(1)/etc/hotplug.d/iface/20-ntpd +endef + +$(eval $(call BuildPackage,ntpd)) diff --git a/net/ntpd/files/ntp.conf b/net/ntpd/files/ntp.conf new file mode 100644 index 0000000000..9b4211270b --- /dev/null +++ b/net/ntpd/files/ntp.conf @@ -0,0 +1,23 @@ +# use a random selection of 8 public stratum 2 servers +# see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers + +restrict default nomodify notrap noquery + +restrict 127.0.0.1 +restrict 192.168.1.253 + +driftfile /etc/ntp.drift + +server 127.127.1.0 +fudge 127.127.1.0 stratum 10 + +# GPS(NMEA)+PPS +#server 127.127.20.0 minpoll 4 prefer +#fudge 127.127.20.0 flag3 1 flag2 0 + +# SMA PPS +#server 127.127.28.0 minpoll 4 prefer +#fudge 127.127.28.0 refid PPS flag3 1 + +#server 192.168.1.253 + diff --git a/net/ntpd/files/ntpd.hotplug b/net/ntpd/files/ntpd.hotplug new file mode 100644 index 0000000000..992628f6cf --- /dev/null +++ b/net/ntpd/files/ntpd.hotplug @@ -0,0 +1,10 @@ +NAME=ntpd +CONFIG=/etc/ntp.conf +COMMAND=/usr/sbin/$NAME + +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && { + [ -x $COMMAND ] && [ -r $CONFIG ] && { + killall ntpd + /etc/init.d/ntpd start + } & +} diff --git a/net/ntpd/files/ntpd.init b/net/ntpd/files/ntpd.init new file mode 100644 index 0000000000..fbcd746ef2 --- /dev/null +++ b/net/ntpd/files/ntpd.init @@ -0,0 +1,13 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=60 +start() { +# ln -sf /dev/ttyS0 /dev/gps0 +# /usr/sbin/setgarmin -d /dev/gps -c /etc/setgarmin.conf + /usr/sbin/ntpd -g +} + +stop() { + killall ntpd +} diff --git a/net/ntpd/patches/100-ntpd-nmea.patch b/net/ntpd/patches/100-ntpd-nmea.patch new file mode 100644 index 0000000000..38c8fba3e8 --- /dev/null +++ b/net/ntpd/patches/100-ntpd-nmea.patch @@ -0,0 +1,105 @@ +diff -Naurp ntp-4.2.2p4.orig/ntpd/refclock_nmea.c ntp-4.2.2p4.mash/ntpd/refclock_nmea.c +--- ntp-4.2.2p4.orig/ntpd/refclock_nmea.c 2006-06-06 22:16:53.000000000 +0200 ++++ ntp-4.2.2p4.mash/ntpd/refclock_nmea.c 2006-12-13 16:22:26.000000000 +0100 +@@ -16,6 +16,7 @@ + + #include + #include ++#include + + #include "ntpd.h" + #include "ntp_io.h" +@@ -72,6 +72,7 @@ + #define RANGEGATE 500000 /* range gate (ns) */ + + #define LENNMEA 75 /* min timecode length */ ++#define LENPPS LINUXPPS_MAX_NAME_LEN + + /* + * Tables to compute the ddd of year form icky dd/mm timecode. Viva la +@@ -92,6 +93,7 @@ struct nmeaunit { + pps_params_t pps_params; /* pps parameters */ + pps_info_t pps_info; /* last pps data */ + pps_handle_t handle; /* pps handlebars */ ++ int handle_created; /* pps handle created flag */ + #endif /* HAVE_PPSAPI */ + }; + +@@ -140,7 +142,12 @@ nmea_start( + register struct nmeaunit *up; + struct refclockproc *pp; + int fd; ++#ifdef PPS_HAVE_FINDPATH ++ char id[LENPPS] = "", ++ path[LENPPS]; ++#endif /* PPS_HAVE_FINDPATH */ + char device[20]; ++ uint bits, mask=~0, outb=0; + + /* + * Open serial port. Use CLK line discipline, if available. +@@ -225,18 +232,42 @@ nmea_start( + memcpy((char *)&pp->refid, REFID, 4); + up->pollcnt = 2; + gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer); ++ gps_send(pp->io.fd,"$PGRMO,,2\r\n", peer); ++ gps_send(pp->io.fd,"$PGRMO,GPRMC,1\r\n", peer); ++ gps_send(pp->io.fd,"$PGRMO,,,,,,,,,,,,2\r\n", peer); ++ ++ mask &= ~TIOCM_RTS; ++ mask &= ~TIOCM_DTR; ++ outb |= TIOCM_RTS; ++ ioctl(fd, TIOCMGET, &bits); ++ bits &= mask; ++ bits |= outb; ++ ioctl(fd, TIOCMSET, &bits); + + #ifdef HAVE_PPSAPI + /* + * Start the PPSAPI interface if it is there. Default to use + * the assert edge and do not enable the kernel hardpps. + */ ++#ifdef PPS_HAVE_FINDPATH ++ /* Get the PPS source's real name */ ++ time_pps_readlink(device, LENPPS, path, LENPPS); ++ ++ /* Try to find the source */ ++ fd = time_pps_findpath(path, LENPPS, id, LENPPS); ++ if (fd < 0) { ++ msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path); ++ return (0); ++ } ++ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id); ++#endif /* PPS_HAVE_FINDPATH */ + if (time_pps_create(fd, &up->handle) < 0) { +- up->handle = 0; ++ up->handle_created = 0; + msyslog(LOG_ERR, + "refclock_nmea: time_pps_create failed: %m"); + return (1); + } ++ up->handle_created = ~0; + return(nmea_ppsapi(peer, 0, 0)); + #else + return (1); +@@ -258,8 +289,10 @@ nmea_shutdown( + pp = peer->procptr; + up = (struct nmeaunit *)pp->unitptr; + #ifdef HAVE_PPSAPI +- if (up->handle != 0) ++ if (up->handle_created) { + time_pps_destroy(up->handle); ++ up->handle_created = 0; ++ } + #endif /* HAVE_PPSAPI */ + io_closeclock(&pp->io); + free(up); +@@ -367,7 +400,7 @@ nmea_pps( + /* + * Convert the timespec nanoseconds field to ntp l_fp units. + */ +- if (up->handle == 0) ++ if (!up->handle_created) + return (0); + timeout.tv_sec = 0; + timeout.tv_nsec = 0;