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



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
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
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
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
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: