Open maresmar opened 3 years ago
Overlays don't have the ability to cause arbitrary commands to be run, but you could use modify the systemd service you refer to make it conditional on something in /proc/device-tree created by the overlay, or that /sys/class/rtc is not empty - something like:
[Unit]
Description=sync system clock with default rtc
After=sysinit.target
ConditionDirectoryNotEmpty=/sys/class/rtc
[Service]
Type=oneshot
ExecStart=/sbin/hwclock --hctosys
[Install]
WantedBy=basic.target
If that works then we could add it to the standard images.
It works great for me. I modified my service file and it still works as I would expect. Please note I had that service already enabled (using systemctl enable my-hwclock-service
). I don't know how it would behave out of the box.
Sorry for the delay. I didn't find a time to try it earlier.
I guess it would work correctly if fake-hwclock
did not override it. Try to purge it: apt purge fake-hwclock
Usually it is not required to install a custom service as systemd applies the RTC time automatically, at least it actively sets a mask for hwclock.service
, even on Debian Bullseye where systemd-timesyncd
has become an own package. fake-hwclock
likely overrides it, as it does not have any conditionals:
# systemctl cat fake-hwclock
# /lib/systemd/system/fake-hwclock.service
[Unit]
Description=Restore / save the current clock
Documentation=man:fake-hwclock(8)
DefaultDependencies=no
Before=sysinit.target shutdown.target
Conflicts=shutdown.target
[Service]
EnvironmentFile=-/etc/default/fake-hwclock
ExecStart=/sbin/fake-hwclock load $FORCE
ExecStop=/sbin/fake-hwclock save
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=sysinit.target
If you want it as fallback, you'd need to add a conditional, e.g.:
mkdir -p /etc/systemd/system/fake-hwclock.service.d
echo -e '[Unit]\nConditionDirectoryNotEmpty=!/sys/class/rtc'
But probably my assumption is wrong when the RTC is loaded as kernel module and becomes ready a bit later, or if because of this the timing of systemd/udev/whatever does not work out.
Ah lol, what a coincidence: https://github.com/raspberrypi/linux/commit/f877159aeda241935e07833ba9b7234836c99ed7 Probably that was the reason for the missing automatic sync and this issue is therefore solved by that commit?
Exactly - the sync should now be automatic in both directions.
Is this the right place for my bug report? I hope so :-) The
dtoverlay=i2c-rtc
overlay is located in this repository. But I don't have a clue how does it work inside...Describe the bug The overlay correctly enables RTC support but doesn't use RTC as a system time source.
To reproduce
dtoverlay=i2c-rtc,ds3231
to/boot/config.txt
sudo hwclock -w
sudo timedatectl set-ntp false
Expected behaviour The system should use the correct time from RTC.
Actual behaviour The system uses the wrong time from the last shutdown (using
fake-hwclock
).Some solutions The most of tutorials solve it by commenting a few lines in
/lib/udev/hwclock-set
(these changes enablehwclock --hctosys
call in systemd environment). This is a bad solution as that file is overridden with standard package updates.There is already an (old) bug report in Debian with a nice analysis of the problem. One of later comment recommend nice solutions using systemd service:
This works fine for me. Could override include / enable this service for everyone?
System
vcgencmd version
)?Logs
Additional context