[LE11][RPi4] - RTC/HWCLOCK not working

  • These days,while checking various logs i noticed that all the logs from before the network time sync are wrong (that's normal,RPi doesn't have RTC) so i remembered that i still have a DS3231 module around the house and decided to hook it to my RPi4.

    So after adding dtoverlay=i2c-rtc,ds3231 and rebooting LibreELEC i proceed with the hwclock .using hwclock -w and rebooted ,this time with no network cable attached,but unfortunately the time and date were completely wrong.

    Code
    LibreELEC:~ # journalctl | grep hwclock
    Mar 11 09:33:35 LibreELEC systemd-udevd[336]: rtc0: Process '/sbin/hwclock --hctosys --utc --rtc=/dev/rtc0' failed with exit code 1.
    Code
    LibreELEC:~ # hwclock --hctosys --utc --rtc=/dev/rtc0
    hwclock: settimeofday: Invalid argument

    And this is the hwclock -r  output.notice that RTC time is UTC

    Quote

    LibreELEC:~ # hwclock -r

    Sun Mar 27 12:18:34 2022 0.000000 seconds

    To make sure that everything is fine with the hw,i tested the module on Raspbian OS (bullseye) and there everything worked as intended (see image),after rebooting the OS without network ,RTC time (UTC) was used and adjusted according to my TZ.

    Note: I also tested on LE 10.2 and it's not working either.

  • Ok,after more testing i managed to gather more informations.

    1) It seems that LibreELEC it's using busybox's hwclock

    2) Libreelec use /usr/lib/udev/rules.d/80-clock.rules but current hwclock can't handle that command

    Code
    ACTION=="add", SUBSYSTEM=="rtc", RUN+="/sbin/hwclock --hctosys --utc --rtc=/dev/%k"
    ACTION=="add", ENV{MAJOR}=="10", ENV{MINOR}=="135", RUN+="/sbin/hwclock --hctosys --utc --rtc=/dev/%k"

    3) I disabled hwclock in busybox target configuration and enabled it in sys-utils

    4) With the new hwclock binary the command works just fine

    5) However the 80-clock.rules still fails so i had to use systemd as a workaround.

    Code
    LibreELEC:~ # journalctl -b -o short-precise | grep hwclock
    Mar 11 09:33:35.753542 LibreELEC systemd-udevd[339]: rtc0: Process '/sbin/hwclock --hctosys --utc --rtc=/dev/rtc0' failed with exit code 1.
    Mar 11 09:33:45.004166 LibreELEC systemd[1]: Starting hwclock-start to read rtc and write to system clock...
    Mar 27 20:42:27.001309 LibreELEC systemd[1]: hwclock-start.service: Deactivated successfully.
    Mar 27 20:42:27.001775 LibreELEC systemd[1]: Finished hwclock-start to read rtc and write to system clock.

    6) Initially i used After= sysinit.target but again,hwclock failed and i managed to get it working only after using After= kodi.target

    Code
    [Unit]
    Description=hwclock-start to read rtc and write to system clock
    After= kodi.target
    
    [Service]
    Type=oneshot
    ExecStart=/sbin/hwclock --hctosys --utc --rtc=/dev/rtc0
    
    [Install]
    WantedBy=basic.target

    This workaround was just for testing and it work indeed,but it would be much better if we managed to fix the udev rule.

  • Can you give this build a try?

    https://www.horus.com/~hias/tmp/libreelec/LibreELEC-RPi4.arm-11.0-devel-20220327210704-a78ef86.tar

    I noticed RPi kernels didn't have CONFIG_RTC_HCTOSYS enabled, since kernel 5.10 that should also work with RTC drivers built as a module and thus system time should be automagically set after module load if it's not been set up yet - so the (broken) udev rule should no longer be needed.

    Would be great if you could give that a try, I don't have any RTCs for RPi4 here.

    BTW: source code is here: https://github.com/HiassofT/LibreELEC.tv/tree/le11-test

    so long,

    Hias

  • Yes, i will test it tomorrow and will return with feedback.

    BTW, while i was testing the RTC thing, i noticed these 3 lines during shutdown :

    Code
    systemd-shutdown[1]:Failed to set timeout to 10min:Invalid argument
    
    failed to unmount /flash:Device or resource busy
    
    systemd-shutdown[1]:Failed to finalize file systems, loop devices, ignoring.
  • The last two lines are normal (and harmless) and you can safely ignore them, the first one (10min invalid argument) is odd though and should not be there.

    Not sure where that should come from, 10 minutes sounds like a ridiculously long timeout. Did you add some systemd services and set it there?

    so long,

    Hias

  • Nope, no changes from me, those lines are there even after a clean install of LE11.

    I don't remember if those were there prior to the systemd bump.

    Another strange thing is that manually updating takes a lot longer than older LE11 builds and i'm using a SSD here. After "Update Kernel 100%" it seems to get stuck there for minutes.

    Let me know if there's a way to debug the update process and will check.

  • Easiest way to debug such things is with a serial console. Remove "quiet" from cmdline.txt and add "systemd.debug_shell ignore_loglevel" - for initramfs debugging adding "debugging" and "progress" may also help.

    I'm not using a USB/SSD here and rarely do updates on SD card, most of the time I netboot my dev systems and update the boot partition with a simple script using the files in the tar

    so long,

    Hias

  • Would be great if you could give that a try, I don't have any RTCs for RPi4 here.

    Currently using the DS3231, your build addresses the problem, clipped from 'dmesg':

    [ 5.774298] rtc-ds1307 1-0068: registered as rtc0

    [ 5.774481] rtc-ds1307 1-0068: setting system clock to 2022-03-27T20:33:32 UTC (1648413212)

    Yesterdays build only showed that the device was registered.

  • Perfect, thanks!

    The "slow update" issue is new, on older LE11 builds update was very quick.

    That kernel bug was fixed so it will be easy to check if that's the cause.

    If it's still there, i will enable the cmdline debug. And i have several USB - SATA adapters to test.

    Hopefully i will be able to find as many bugs i can with LE11, which probably will enter a "feature freeze" at some point! xD

  • Just finished testing on LE10,it's all good with your RTC fix.

    Code
    LibreELEC (HiassofT): devel-20220328220759-4d9d4e2 (RPi4.arm)
    LibreELEC:~ # journalctl | grep rtc-ds1307
    Mar 29 00:02:39 LibreELEC kernel: rtc-ds1307 1-0068: registered as rtc0
    Mar 29 00:02:39 LibreELEC kernel: rtc-ds1307 1-0068: setting system clock to 2022-03-28T21:02:39 UTC (1648501359)
  • HiassofT just did a quick test with a LE11 build from 18/03/2022 (commit 5591832ae999f003bc53e3f7c15dc81c06c32413 ) ,which is the last commit before the RPi kernel bump and with this build the system update no longer stalls ,so this really seems a kernel issue .

  • I can confirm that using latest 5.15.y kernel (a51218097a20b10e4696fa19bef8bebf3833020) addresses the slow system update issue.(and i kind of hijacked my own thread :D )

  • Hey, sorry to raise this 4-month old thread, I am having the same errors OP has shown in post #1, builds from posts #3 and #12 are both giving me 404, and it seems the package from the website does not include a fix for this yet. Can someone re-upload them please? Thank you.