1

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.

Ostpanaka
  • 75
  • 8
  • 2
    The error code means that the time read from the hardware is invalid. As this happens mostly for months that have fewer than 31 days, I'd say your hardware treats all months as having 31 days and software is complaining about seeing things like 31st June. So... crappy hardware clock implementation? –  Jan 22 '21 at 09:08
  • Yes, it seems the hwclock always think every month has more dates than they actually have. I added some prints when we read the hwclock, and I put the date to 2020-04-30 23:59:55 and wait 6 seconds it gives me this : Year 120 mon 3 mday 31 hour 0 min 0 sec 1 – Ostpanaka Jan 26 '21 at 07:54

0 Answers0