Note: This Howto \ Guide has only been tested on Raspberry Pi OS but may work with Ubuntu or other flavors of Debian Linux
When you first run the following command to check the RTC... you'll probably get the following output:
sudo hwclock -r
hwclock: Cannot access the Hardware Clock via any known method. hwclock: Use the --verbose option to see the details of our search for an access method.
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclock
dtparam=i2c_vc=on
reboot
sudo apt install i2c-tools sudo i2cdetect -y 10
> 0 1 2 3 4 5 6 7 8 9 a b c d e f >00: -- -- -- -- 0c -- -- -- >10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f >30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- >60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- >70: -- -- -- -- -- -- -- --
"To set the clock from /dev/rtc0 on a CM4 the rtc-pcf85063 module needs to be in the pi-kernel initrd... since there are issues with calling hctosys from the kernel at module load time there probably also needs to be a udev rule like:"
sudo nano /etc/udev/rules.d/60-rtc.rules
cat /etc/udev/rules.d/60-rtc.rules
ACTION=="add", SUBSYSTEM=="rtc", ATTRS{hctosys}=="0", RUN+="/usr/sbin/hwclock -s --utc"
sudo nano /boot/config.txt
cat /boot/config.txt
... # Additional overlays and parameters are documented /boot/overlays/README dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi ...
i2c-dev rtc-pcf85063
sudo update-initramfs -c -k uname -r
ls -l /boot/initrd*
-rwxr-xr-x 1 root root 14003079 Dec 24 10:04 /boot/initrd.img-5.4.79-v7l+
sudo nano /boot/config.txt
cat /boot/config.txt | tail -n 3
[all] dtoverlay=dwc2,dr_mode=host initramfs initrd.img-5.15.56-v8+
reboot
sudo hwclock -r
2022-09-23 23:37:14.345612+10:00
- https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time
- https://forums.raspberrypi.com/viewtopic.php?f=98&t=293632
- https://forums.raspberrypi.com/viewtopic.php?t=314445
- canonical/core-initrd#17
Please feel free to leave any helpful comments or suggestions