From 5d43882dd6b9099012540f9cdf7d91613a0ccf0f Mon Sep 17 00:00:00 2001 From: KemoNine Date: Fri, 12 Apr 2019 00:47:16 +0100 Subject: [PATCH] Updates and improvements on adding rtc boards --- hardware/rtc.md | 81 +++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/hardware/rtc.md b/hardware/rtc.md index 3b9e902..e6ba2a4 100644 --- a/hardware/rtc.md +++ b/hardware/rtc.md @@ -35,15 +35,17 @@ armbian-config # enable i2c busses systemctl reboot # reboot to enable bus(es) apt install i2c-tools # install tools i2cdetect -l # check to ensure busses are present -i2cdetect -y 0 # 0 for orange pi zero ; 1 for recent pi's +i2cdetect -y 1 # 0 for orange pi zero ; 1 for recent pi's modprobe rtc-pcf8523 # load the proper rtc module (adafruit cheap model) -echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-0/new_device # setup device so it's seen +echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device # setup device so it's seen dmesg | grep rtc # verify the kernel sees the rtc ls /dev/rtc* # should have rtc1 +hwclock -r -f /dev/rtc1 # See if anything is on the rtc hwclock -f /dev/rtc1 --systohc -D --noadjfile --utc # set / init the rtc hwclock -r -f /dev/rtc1 # read the value from the rtc hwclock -w -f /dev/rtc1 # write the current time to the rtc apt remove --purge fake-hwclock # purge the fake hwclock as we have a real one now +systemctl disable fake-hwclock # Disable any dangling services ``` @@ -58,50 +60,6 @@ EOF ``` -## Internal RTC Adjustments - -A systemd service to ensure the internal RTC is 'close' to the real time w/o battery. - -``` bash - -# Set the internal RTC on shutdown to match ntpified time -cat > /etc/systemd/system/rtc0-shutdown-fix.service < /etc/systemd/system/rtc0-online.service < /etc/systemd/system/rtc1-online.service < /sys/class/i2c-adapter/i2c-0/new_device \ +ExecStart=/bin/sh -c '/sbin/modprobe rtc-pcf8523 \ +&& echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device \ && /sbin/hwclock -s -f /dev/rtc1' [Install] WantedBy=time-sync.target -After=rtc0-online EOF systemctl daemon-reload @@ -131,6 +87,31 @@ systemctl enable rtc1-online ``` +## Set RTC on shutdown + +A systemd unit that sets the current time to the rtc on shutdown to minimize clock drift during next boot + +``` bash + +cat > /etc/systemd/system/rtc1-shutdown-fix.service <