Last active
July 9, 2022 14:37
-
-
Save h0tw1r3/11191428 to your computer and use it in GitHub Desktop.
Initializing I2C RTC (DS3231) on Raspberry PI bootup with Systemd without recompiling the kernel or devicetree support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/conf.d/rtc-i2c | |
# | |
# My chip is actually a ds3231n, but ds1307 driver works fine (ds3232 does not!) | |
# | |
CHIP="ds1307" | |
ADDRESS="0x68" | |
BUS="1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/modules-load.d/rtc-i2c.conf | |
i2c-dev | |
i2c_bcm2708 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/udev/rules.d/rtc-i2c.rules | |
# | |
# I would prefer to put SUBSYSTEMS="i2c", | |
# but for some reason it's not working on my system. | |
# | |
ACTION=="add", SUBSYSTEM="rtc", ATTRS{hctosys}=="0", RUN+="/usr/bin/hwclock -s --utc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/systemd/system/rtc-i2c.service | |
[Unit] | |
Description=Initialize i2c hardware RTC device driver | |
DefaultDependencies=no | |
Requires=systemd-modules-load.service | |
After=systemd-modules-load.service | |
Before=sysvinit.target | |
ConditionPathExists=/sys/class/i2c-adapter | |
Conflicts=shutdown.target | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
EnvironmentFile=/etc/conf.d/rtc-i2c | |
ExecStart=/bin/sh -c "echo ${CHIP} ${ADDRESS} > /sys/class/i2c-adapter/i2c-${BUS}/new_device" | |
[Install] | |
WantedBy=sysinit.target |
I link to my setup/fork. Here is what is working for me: https://gist.github.com/Lahorde/2bc5e4a3b69fc6ca5797#gistcomment-2825294
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
With such dependencies in .service :
You can have rtc udev rules run, whereas i2c module not yet fully loaded as you can see in logs :
After investigating, I found very useful TAG attribute of udev rules http://www.freedesktop.org/software/systemd/man/systemd.device.html
And finally got it working :
https://gist.github.com/Lahorde/2bc5e4a3b69fc6ca5797