Add i2c clock

This commit is contained in:
Przemek Grondek 2021-01-25 19:50:37 +01:00
parent e6060ff9bc
commit 607a9374db
7 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1 @@
rtc-ds1307

View File

@ -0,0 +1,20 @@
[Unit]
ConditionCapability=CAP_SYS_TIME
ConditionVirtualization=!container
DefaultDependencies=no
Wants=dev-rtc_i2c.device
After=dev-rtc_i2c.device
Before=systemd-timesyncd.service ntpd.service chrony.service
[Service]
Type=oneshot
CapabilityBoundingSet=CAP_SYS_TIME
PrivateTmp=yes
ProtectSystem=full
ProtectHome=yes
DeviceAllow=/dev/rtc_i2c rw
DevicePolicy=closed
ExecStart=/usr/bin/echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device && /sbin/hwclock --s
[Install]
WantedBy=time-sync.target

View File

@ -0,0 +1,6 @@
#/lib/udev/rules.d/50-udev-default.rules:SUBSYSTEM=="rtc", ATTR{hctosys}=="1", SYMLINK+="rtc"
#/lib/udev/rules.d/50-udev-default.rules:SUBSYSTEM=="rtc", KERNEL=="rtc0", SYMLINK+="rtc", OPTIONS+="link_priority=-100"
# I2C RTC, when added and not the source of the sys clock (kernel), is used ;
# separate name to ensure rtc-i2c.service will not be run on anything else
ACTION=="add", SUBSYSTEMS=="i2c", SUBSYSTEM=="rtc", KERNEL=="rtc0", ATTR{hctosys}=="0", SYMLINK+="rtc_i2c", TAG+="systemd"

View File

@ -0,0 +1,25 @@
---
- become: yes
block:
- name: install i2c-tools
become: yes
apt:
update_cache: yes
pkg:
- i2c-tools
- name: enable automatic module load
copy:
src: etc/modules-load.d/rtc-ds1307.conf
dest: /etc/modules-load.d/rtc-ds1307.conf
- name: add systemd service
copy:
src: etc/systemd/system/rtc-i2c.service
dest: /etc/systemd/system/rtc-i2c.service
- name: enable systemd service
systemd:
name: rtc-i2c.service
enabled: yes
state: started

View File

@ -0,0 +1,6 @@
---
- import_tasks: install.yml
- import_tasks: set-time.yml
- import_tasks: remove-fake-clock.yml

View File

@ -0,0 +1,8 @@
---
- name: uninstall fakehw
become: yes
apt:
update_cache: yes
state: absent
pkg:
- fake-hwclock

View File

@ -0,0 +1,16 @@
---
- become: yes
block:
- name: load hwclock
shell:
cmd: |
modprobe rtc-ds1307
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
- name: update time
shell:
cmd: |
hwclock -w
- name: read time
shell:
cmd: |
hwclock -r