Skip to content

Commit

Permalink
Add SNTP support
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrisan committed Sep 29, 2019
1 parent bbc2127 commit 09a2cf3
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 21 deletions.
36 changes: 29 additions & 7 deletions board/common/overlay/etc/init.d/S50date
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

PROG_DATE="/bin/date"
PROG_NTPD="/usr/sbin/ntpd"
PROG_SNTP="/usr/bin/sntp"
LOG_SNTP="/var/log/sntp.log"

SYS_CONF="/etc/date.conf"
BOOT_CONF="/boot/date.conf"
Expand Down Expand Up @@ -55,8 +57,22 @@ set_current_date_ntp() {
fi
}

set_current_date_sntp() {
sntp_args="-t ${DATE_TIMEOUT} -K /var/lib/ntp/kod -Ss"
server=$(cat ${NTP_CONF} | grep server | head -n 1 | cut -d ' ' -f 2)
${PROG_SNTP} ${sntp_args} ${server} &>${LOG_SNTP}
if [[ $? == 0 ]]; then
logger -t date "current system date/time set to $(date) via SNTP"
return 0
else
logger -t date "failed to set current system date/time via SNTP"
return 1
fi
}


start_http() {
msg_begin "Setting current date using http"
msg_begin "Setting current date using HTTP"
if set_current_date_http; then
sleep_interval=${DATE_INTERVAL}
msg_done "$(${PROG_DATE})"
Expand All @@ -79,6 +95,7 @@ start_http() {

start_ntp() {
mkdir -p /var/lib/ntp
touch /var/lib/ntp/kod

cat ${NTP_CONF} | grep -v iburst > ${NTP_CONF}.tmp

Expand All @@ -91,9 +108,15 @@ start_ntp() {
cat ${NTP_CONF}.tmp >> ${NTP_CONF}
rm ${NTP_CONF}.tmp

msg_begin "Setting current date using ntp"
set_current_date_ntp || set_current_date_ntp
test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
if [[ "${DATE_METHOD}" == "sntp" ]]; then
msg_begin "Setting current date using SNTP"
set_current_date_sntp
test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
else # assuming ntp
msg_begin "Setting current date using NTP"
set_current_date_ntp || set_current_date_ntp
test $? == 0 && msg_done "$(${PROG_DATE})" || msg_fail
fi

msg_begin "Starting ntpd"
${PROG_NTPD} -g -c ${NTP_CONF}
Expand All @@ -115,7 +138,7 @@ stop_ntp() {
start() {
if [[ "${DATE_METHOD}" == "http" ]]; then
start_http
else
else # ntp or sntp
start_ntp
fi

Expand All @@ -125,7 +148,7 @@ start() {
stop() {
if [[ "${DATE_METHOD}" == "http" ]]; then
stop_http
else
else # ntp or sntp
stop_ntp
fi
}
Expand All @@ -150,4 +173,3 @@ case "$1" in
esac

exit $?

2 changes: 1 addition & 1 deletion configs/bananapim1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/nanopineo2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/nanopineo_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/odroidc1_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/odroidc2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/odroidxu4_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/orangepione_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/orangepizero_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/pine64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/raspberrypi2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/raspberrypi3_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/raspberrypi4_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/raspberrypi_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down
2 changes: 1 addition & 1 deletion configs/tinkerboard_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BR2_PACKAGE_IW=y
BR2_PACKAGE_NETCAT=y
BR2_PACKAGE_NET_TOOLS=y
BR2_PACKAGE_NTP=y
BR2_PACKAGE_NTP_NTPDATE=y
BR2_PACKAGE_NTP_SNTP=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_WIRELESS_TOOLS=y
Expand Down

0 comments on commit 09a2cf3

Please sign in to comment.