Welcome! Log In Create A New Profile

Advanced

[How To] Use U-Boot SNTP

Posted by bodhi 
[How To] Use U-Boot SNTP
May 05, 2014 10:34PM
As requested by a forum member, here is the instruction how to setup SNTP using the new U-Boot.

The envs can be setup either in u-boot console or in Linux . In this example, my router local IP is 192.168.0.1, and the NTP server is montpelier.caltech.edu.

1. Setup network variables
setenv dnsip 192.168.0.1
setenv gatewayip 192.168.0.1
setenv netmask 255.255.255.0

2. Test the internet connection using Google IP address:
ping 8.8.8.8
Using egiga0 device
host 8.8.8.8 is alive

3. Lookup Caltech IP. If you already know other NTP server IP address to use then use that IP.
dns montpelier.caltech.edu
192.12.19.20

4. Get date time from Caltech
sntp 192.12.19.20
Date: 2014-02-09 Time: 7:37:35


The boot time is automatically stored in the RTC. Also, it can then be stored in u-boot env variable and used in Linux with fw_printenv. Or it could also be passed to Linux kernel with a custom param:
usb_set_bootargs=setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype $mtdparts $usb_custom_params

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 2 time(s). Last edit at 02/03/2019 09:10PM by bodhi.
Re: [How To] Use U-Boot SNTP
May 06, 2014 11:15PM
I was the forum member in question, and I'd like to share what I've done here in case it helps others avoid the pitfall(s) I've encountered. It assumes that a) you have installed the latest uboot with SNTP support, and b) that your device's RTC is set to UTC (i.e. you are setting a proper timezone offset in Linux).

Boot into Linux on your ubootable device, become root, and do the following (choose the correct process for your particular network setup and leave out the comments!):

Fully static IP addressing

fw_setenv ipaddr 192.168.0.100 # Replace with correct IP for your ubooted device
fw_setenv dnsip 192.168.0.1 # Replace with correct IP for your DNS server
fw_setenv gatewayip 192.168.0.1 # Replace with correct IP for your network gateway
fw_setenv netmask 255.255.255.0 # Replace with the correct netmask for your network
fw_setenv bootcmd "dns pool.ntp.org ntpserverip; sntp; `fw_printenv bootcmd | sed 's/^bootcmd=//'`"

(Static) DHCP IP addressing (i.e. standard DHCP or "static" DHCP/forced IP based on MAC)

fw_setenv autoload no # This is *VERY* important, otherwise it will attempt to TFTP boot after getting an IP and bootloop forever, and the ONLY way out will be a serial cable, netconsole WILL NOT work!
fw_setenv bootcmd "dhcp; dns pool.ntp.org ntpserverip; sntp; `fw_printenv bootcmd | sed 's/^bootcmd=//'`"

Check your work, disable any daemons you are currently using to force initial time (fakeclock, et al), install, configure and enable a timeslewing daemon of your choice (ntpd, chrony, et al) to keep the time correct long-term (if you haven't already), and reboot. Voila! The RTC will be set on uboot before the kernel is even loaded and all timestamps will be correct (assuming your network is up and the Internet is reachable at the time of boot).

If anyone has any questions/comments/suggestions, please reply - there *may* be a better approach to this, but I've tried to make it as platform/user/network/locale agnostic as I could.

Good luck and enjoy proper timekeeping from boot! ;) Thanks VERY much to bodhi for making it possible!

Rodney



Edited 3 time(s). Last edit at 05/07/2014 06:30AM by rhester72.
Re: [How To] Use U-Boot SNTP
May 07, 2014 02:21AM
Nicely done Rodney! thanks for sharing.

One possible correction:
fw_setenv bootcmd "dhcp; dns pool.ntp.org ntpserverip; sntp; `fw_printcmd bootcmd | sed 's/^bootcmd=//'`"
should it be?
fw_setenv bootcmd "dhcp; dns pool.ntp.org ntpserverip; sntp; `fw_printenv bootcmd | sed 's/^bootcmd=//'`"

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: [How To] Use U-Boot SNTP
May 07, 2014 06:31AM
Yes, indeed - the perils of midnight hacking. :) Corrected in original post, thanks for the catch!

Rodney
jcromero
Re: [How To] Use U-Boot SNTP
April 11, 2021 04:00AM
Is this working?

GoFlexNet> setenv dnsip 8.8.8.8
setenv dnsip 8.8.8.8
GoFlexNet> dns pool.ntp.org ntpserverip
dns pool.ntp.org ntpserverip
182.176.15.141
GoFlexNet> date
date
Date: 2000-01-01 (Sunday)    Time:  0:00:00
GoFlexNet> sntp
sntp
GoFlexNet> date
date
Date: 2000-01-01 (Sunday)    Time:  0:00:00
Re: [How To] Use U-Boot SNTP
April 11, 2021 04:37PM
jcromero,

> Is this working?

It should work for boxes that have RTC such as the GoFlex Home, and other Kirkwood boxes. It was a long time ago, but I recalled making it work for boxes that have no RTC, too (I could be remember it wrong, though).

When I have some time, I'll reboot my GoFex Net to investigate this.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
jcromero
Re: [How To] Use U-Boot SNTP
April 12, 2021 01:42AM
> When I have some time, I'll reboot my GoFex Net to investigate this.

Thank you very much for this.

I have a Goflex Net, and a Pogo E02. I have flashed the last U-Boot (2017-07-tld-1) in both of them, but none is working.

-- jcromero
jcromero
Re: [How To] Use U-Boot SNTP
April 20, 2021 03:48PM
Some news about this?

Thanks in advance

-- jcromero
Re: [How To] Use U-Boot SNTP
April 20, 2021 03:57PM
jcromero,

It does not look like the box without RTC like Goflex Net and Pogo E02 will work with SNTP. It's the normal behavior.

I thought I did patch something in this area, but apparently I did not.

You could use fake-hwclock to keep the system time closer to current to help with the clock sync.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
jcromero
Re: [How To] Use U-Boot SNTP
April 21, 2021 09:15AM
I didn't know the fake-hwclock package. Thanks for the info.

-- jcromero
Re: [How To] Use U-Boot SNTP
June 30, 2021 07:51PM
I am able to get SNTP to work with the 2014 U-Boot, but not with 2016 or 2017.

I've got:

Pogov4> version
version

U-Boot 2017.07-tld-1 (Sep 05 2017 - 00:34:01 -0700)
Pogoplug V4
gcc (Debian 6.3.0-18) 6.3.0 20170516
GNU ld (GNU Binutils for Debian) 2.28
Pogov4>

dnsip=8.8.8.8
ethact=egiga0
gatewayip=10.A.B.1
ipaddr=10.A.B.205
netmask=255.255.255.0
ntpserverip=X.Y.226.86

Pogov4> ping $dnsip
ping $dnsip
Using egiga0 device
host 8.8.8.8 is alive
Pogov4> ping $ntpserverip
ping $ntpserverip
Using egiga0 device
host X.Y.226.86 is alive
Pogov4> sntp
sntp
Pogov4> date
date
Date: 2000-01-01 (Sunday) Time: 0:00:00


It chimes happily when running a 2014 U-Boot. I've tried it on both Pogoplug Mobiles and Pogoplugs V4 and neither
works with later U-Boot versions.

Am I missing something?

Thanks,
Jim
Re: [How To] Use U-Boot SNTP
June 30, 2021 08:51PM
Jim,

I recalled I did some tweak to the code to make it work back then (2014). The boxes that has no RTC like this Pogo V4 and Pogo E02 are not supposed to have SNTP (SNTP writes to the real-time clock).

But apparently in the 2017.07 version, we've lost that. Probably because mainline code change (that I did not notice), now it only works on boxes with RTC like the GoFlex Home.

I will have to revisit that area in the future to see what I did and then retrofit in the latest u-boot. ATM, I'm rebasing to 2021.04 or 2021.07.

In the mean time, you can use Debian fake-hwclock to get the clock saved whenever you shutdown and then it will set to that at start up again.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: