Mailing List Archive

Getting network time early in boot
Hi all,

I've got a board with no RTC so there are some problems during boot.
Currently there's a hack in the udev init script to get the time from the
network (via ntp or rdate), but I'm wondering if somebody else has solved
this in a better way. Any ideas?

Thanks,
Joe
Re: Getting network time early in boot [ In reply to ]
On Tue, Mar 29, 2011 at 10:06 PM, Joe Sapp wrote:
> I've got a board with no RTC so there are some problems during boot.
> Currently there's a hack in the udev init script to get the time from the
> network (via ntp or rdate), but I'm wondering if somebody else has solved
> this in a better way.  Any ideas?

add your own init.d script, mark it "before udev', and add it to boot runlevel ?
-mike
Re: Getting network time early in boot [ In reply to ]
Dear Joe Sapp,

In message <4D92902B.5000300@gentoo.org> you wrote:
>
> I've got a board with no RTC so there are some problems during boot.
> Currently there's a hack in the udev init script to get the time from the
> network (via ntp or rdate), but I'm wondering if somebody else has solved
> this in a better way. Any ideas?

If your board uses U-Boot as boot loader, you can enable SNTP support
in U-Boot and get and set the time already there, before you even boot
into Linux.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
"Faith: not *wanting* to know what is true." - Friedrich Nietzsche
Re: Getting network time early in boot [ In reply to ]
On 30/03/2011 05:47, Mike Frysinger wrote:
> On Tue, Mar 29, 2011 at 10:06 PM, Joe Sapp wrote:
>> I've got a board with no RTC so there are some problems during boot.
>> Currently there's a hack in the udev init script to get the time from the
>> network (via ntp or rdate), but I'm wondering if somebody else has solved
>> this in a better way. Any ideas?
>
> add your own init.d script, mark it "before udev', and add it to boot runlevel ?

You would still have the problem that you can't run it until at least
after you start network of course?

Some people might not know of /etc/init.d/swclock. It writes the time
at shutdown and restores *that* old time on bootup. For some scenarios
that might get you a time close to reality... (eg if you just want to
check stuff like "has this file changed" and avoid "clock moved
backwards" kind of issues)

Good luck

Ed W
Re: Getting network time early in boot [ In reply to ]
On Wed, Mar 30, 2011 at 9:59 AM, Ed W wrote:
> On 30/03/2011 05:47, Mike Frysinger wrote:
>> On Tue, Mar 29, 2011 at 10:06 PM, Joe Sapp wrote:
>>> I've got a board with no RTC so there are some problems during boot.
>>> Currently there's a hack in the udev init script to get the time from the
>>> network (via ntp or rdate), but I'm wondering if somebody else has solved
>>> this in a better way.  Any ideas?
>>
>> add your own init.d script, mark it "before udev', and add it to boot runlevel ?
>
> You would still have the problem that you can't run it until at least
> after you start network of course?

that depends on how the board comes up. if the boot loader provides
network settings to the kernel (autoconfig), it might be up. or if
people have an initramfs that brings things up.

> Some people might not know of /etc/init.d/swclock.  It writes the time
> at shutdown and restores *that* old time on bootup.  For some scenarios
> that might get you a time close to reality... (eg if you just want to
> check stuff like "has this file changed" and avoid "clock moved
> backwards" kind of issues)

that can be useful depending on the system needs. i tend to forget about it ;).
-mike
Re: Getting network time early in boot [ In reply to ]
On 03/30/2011 04:59 AM, Wolfgang Denk wrote:
> Dear Joe Sapp,
>
> In message <4D92902B.5000300@gentoo.org> you wrote:
>>
>> I've got a board with no RTC so there are some problems during boot.
>> Currently there's a hack in the udev init script to get the time from the
>> network (via ntp or rdate), but I'm wondering if somebody else has solved
>> this in a better way. Any ideas?
>
> If your board uses U-Boot as boot loader, you can enable SNTP support
> in U-Boot and get and set the time already there, before you even boot
> into Linux.

It does use U-Boot, so maybe a combination of this and swclock (from
sys-apps/openrc) is the most reliable way to set the time for my application.

Thanks all for the ideas.

Joe