Updates and improvements on adding rtc boards
This commit is contained in:
parent
fde8fb3287
commit
5d43882dd6
|
@ -35,15 +35,17 @@ armbian-config # enable i2c busses
|
||||||
systemctl reboot # reboot to enable bus(es)
|
systemctl reboot # reboot to enable bus(es)
|
||||||
apt install i2c-tools # install tools
|
apt install i2c-tools # install tools
|
||||||
i2cdetect -l # check to ensure busses are present
|
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)
|
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
|
dmesg | grep rtc # verify the kernel sees the rtc
|
||||||
ls /dev/rtc* # should have rtc1
|
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 -f /dev/rtc1 --systohc -D --noadjfile --utc # set / init the rtc
|
||||||
hwclock -r -f /dev/rtc1 # read the value from 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
|
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
|
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 <<EOF
|
|
||||||
[Unit]
|
|
||||||
Description=Set sunxi internal RTC on shutdown
|
|
||||||
DefaultDependencies=no
|
|
||||||
Before=shutdown.target reboot.target halt.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/sbin/hwclock --systohc -D --noadjfile --utc -f /dev/rtc0
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=halt.target reboot.target shutdown.target
|
|
||||||
EOF
|
|
||||||
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable rtc0-shutdown-fix
|
|
||||||
|
|
||||||
# Trick for getting the early boot time 'close'
|
|
||||||
cat > /etc/systemd/system/rtc0-online.service <<EOF
|
|
||||||
[Unit]
|
|
||||||
Description=Set system clock to rtc0
|
|
||||||
DefaultDependencies=no
|
|
||||||
Before=time-sync.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/sbin/hwclock -s -f /dev/rtc0
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=time-sync.target
|
|
||||||
EOF
|
|
||||||
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable rtc0-online
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## External RTC On Boot
|
## External RTC On Boot
|
||||||
|
|
||||||
A systemd unit that brings the external RTC online during boot
|
A systemd unit that brings the external RTC online during boot
|
||||||
|
@ -113,17 +71,15 @@ cat > /etc/systemd/system/rtc1-online.service <<EOF
|
||||||
Description=Setup rtc1 as primary clock
|
Description=Setup rtc1 as primary clock
|
||||||
DefaultDependencies=no
|
DefaultDependencies=no
|
||||||
Before=time-sync.target
|
Before=time-sync.target
|
||||||
After=rtc0-online.service
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/bin/sh -c '/sbin/modprobe rtc_pcf8523 \
|
ExecStart=/bin/sh -c '/sbin/modprobe rtc-pcf8523 \
|
||||||
&& echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-0/new_device \
|
&& echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device \
|
||||||
&& /sbin/hwclock -s -f /dev/rtc1'
|
&& /sbin/hwclock -s -f /dev/rtc1'
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=time-sync.target
|
WantedBy=time-sync.target
|
||||||
After=rtc0-online
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
systemctl daemon-reload
|
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 <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Set rtc1 on shutdown
|
||||||
|
DefaultDependencies=no
|
||||||
|
Before=shutdown.target reboot.target halt.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/sbin/hwclock --systohc -D --noadjfile --utc -f /dev/rtc1
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=halt.target reboot.target shutdown.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable rtc1-shutdown-fix
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Misc Notes
|
## Misc Notes
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
|
Reference in New Issue