RTC and "date" command

Denys Vlasenko vda.linux at googlemail.com
Sat Jun 21 06:01:23 UTC 2008


On Saturday 21 June 2008 07:11, Midhun A wrote:
> I am working on Freescale's i.MX21 RTC. I have a driver which does the
> basic initialization of the RTC and sets and reads time from the RTC.
> The RTC is working perfectly fine. When I use the "date" command of
> busybox, it seems that busybox picks up the date and time from
> somewhere else.

date command (busybox or not) does not read RTC. It uses kernel's idea
of current time. Linux kernel does not use RTC directly as time source,
it keeps its own counter.

> The time shown by busybox is slower than the RTC time. 
> Also all C programs to retrieve system time return the busybox time
> and not the RTC time.
> 
> Does busybox maintain a separate counter by itself ? How do I make
> busybox pick time from the kernel (the one in the RTC) ?

You need to set kernel's time from RTC's time.
This program is designed to do exactly that:

# hwclock --help
BusyBox v1.10.0 (2008-03-22 15:35:10 CET) multi-call binary

Usage: hwclock [-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc] [-f FILE]

Query and set hardware clock (RTC)

Options:
        -r      Show time from hardware clock
        -s      Set system time from hardware clock  <======== THIS ONE
        -w      Set hardware clock to system time
        -u      Hardware clock is in UTC
        -l      Hardware clock is in local time
        -f FILE Use specified device (e.g. /dev/rtc2)

--
vda



More information about the busybox mailing list