'hwclock' and 'timedatectl' behaviour on the system with removed RTC battery

268 Views Asked by At

I have embedded Linux running on device with the following setup:

  • RTC battery is removed,

  • No NTP server configured,

  • With the following related defconfig:

    CONFIG_RTC_HCTOSYS=y

    CONFIG_RTC_SYSTOHC=y

After system boots up, I issue the commands:

$hwclock

hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument


$timedatectl
Failed to query server: Failed to read RTC: Invalid argument

$date
Wed Mar 24 11:26:45 CET 2021

All commands return errors, except 'date' which returns some old date/time.

But after I sync hwclock with the system time:

$hwclock -w

all three commands start to work without errors and show the same date/time as'date' showed above,

before 'hwclock -w' sync.

Could you please clarify the following moments about this test:

  1. From what source does 'date' take that old date/time value?

  2. How does 'hwclock -w' sync help to resolve the errors returned by the commands?

    I initially thought that 'hwclock -w' should sync with the value returned by 'timedatectl'.

    But since 'timedatectl' is in error condition, it looks like 'hwclock -w' takes time from the some other source,

    probably the same as 'date'.

  3. Is there a way to configure 'timedatectl' to behave like 'date' when RTC battery is removed

    (i.e. to return some date/time value instead of an error) without the need to make 'hwclock -w' sync for it?

0

There are 0 best solutions below