3

I have a Raspberry Pi 4 and Installed Ubuntu 20.04 on it. Unfortunately, it will not be connected to the internet all the time meaning the date will be set back to the build time after each reboot. I have added an external RTC module (DS3231 working on the IIC bus) and can read the time with hwclock --show.

After adding dtoverlay=i2c-rtc,ds3231 to /boot/firmware/usercfg.txt, the module rtc_ds1307 is now loaded at boot time. The only problem is that it seems Ubuntu is trying to set the system time from the RTC before the module is loaded (see the dmesg output below). Once booted, I can manually set the time to what is on the RTC by running sudo hwclock --hctosys.

Any suggestions for getting around this problem? Is there any way to get the module to load sooner?

I have tried adding this to the superuser/root crontab:

@reboot sleep 10; hwclock --hctosys

but it does not seem to work.

Output from dmesg | grep rtc:

[    0.000000] Kernel command line:  coherent_pool=1M 8250.nr_uarts=1 bcm2708_fb.fbwidth=0 bcm2708_fb.fbheight=0 bcm2708_fb.fbswap=1 smsc95xx.macaddr=DC:A6:32:43:2B:86 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc quiet splash
[    1.726560] hctosys: unable to open rtc device (rtc0)
[    2.470632] rtc-ds1307 1-0068: registered as rtc0
Melebius
  • 11,121
  • 8
  • 50
  • 77
  • Don't use a cronjob for this. Learn how to use systemd's boot dependencies, monitor during which systemd boot target the clock becomes available, and set the clock after that. There's a learning curve involved, but I found it worth investing the time to learn -- comes in handy all over the place. – user535733 Jul 19 '20 at 19:15
  • 1
    One thing to note, is that there is a script in `/lib/udev/hwclock-set` that kinda of handles this, but I admit I'm not sure when or how it runs, or if it's effective as the first check seems to be to skip it if systemd is used. – Michael Graff Jul 24 '20 at 22:42

1 Answers1

0

I'm working on the same thing and rather new to this.

See if this helps, https://wiki.52pi.com/index.php/DS1307_RTC_Module_with_BAT_for_Raspberry_Pi_SKU:_EP-0059#Compatibility_List

I think you need to edit the script file "/lib/udev/hwclock-set" as Michael said to look like below.

#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.

dev=$1
# COMMENT OUT NEXT THREE LINES
#if [ -e /run/systemd/system ] ; then
#    exit 0
#fi

if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi

if [ -f /etc/default/rcS ] ; then
    . /etc/default/rcS
fi

# These defaults are user-overridable in /etc/default/hwclock
BADYEAR=no

My clock hasn't arrived yet so I haven't tried it yet. Let me know if it works for you.