Why can't linux read hwclock some month shift?

214 views Asked by At

We have a linux system that we are building with yocto. We can read our hardware clock after reboots, change both system time and hardware time without any error (most of the time). However; after some new month, every year that we have tried we are running in to this error. "hwclock: RTC_RD_TIME: Invalid argument". Example 1:

root@:~# date
Thu Apr 30 23:59:50 UTC 2020
root@:~# hwclock
Thu Apr 30 23:59:52 2020 0.000000 seconds
root@:~# 
root@:~# 
root@:~# date 
Fri May 1 00:00:10 UTC 2020
root@:~# hwclock
hwclock: RTC_TD_TIME: Invalid argument
root@:~#

This is not happening every new month, if I do the same test in January linux can read the hwclock without any issues. It does also not matter if the unit is powered or not. If I set the hwclock to first of May 00:00:00 it can keep track of the time.

The same error occurs on the following month shift:

  • Feb (it does not matter if it is leap year or not) -> Mar
  • Apr -> May
  • Jun -> Jul
  • Sep -> Oct
  • Nov -> Dec
  • Dec (Not sure because of new year or new month) -> Jan

In my understanding, this is happening because rtc-lib.c cannot verify the time correctly.

I have tried on multiple different hardware

Does anyone have any idea what might cause this?

Solution: The fault was not in rtc-lib.c. The cause of the error was a faulty RTC implementation. The RTC month value is 1-indexed, but the kernel assumes it is 0-indexed. Added a patch for this to rtc-[my_rtc_model].c and now it seems to be working.

0

There are 0 answers