Saving time with Hardware Clock: Difference between revisions

From Alpine Linux
m (Categorized: Hardware, System Administration)
(use cat and path template)
 
(2 intermediate revisions by 2 users not shown)
Line 6: Line 6:
Add the modules from the kernel
Add the modules from the kernel


== /etc/modules/ ==
== /etc/modules ==
Add these modules so they're loaded on boot. You can modprobe each one individually if you don't want to reboot.
Add these modules so they're loaded on boot. You can modprobe each one individually if you don't want to reboot.


<pre>i2c_dev
{{Cat|/etc/modules|i2c_dev
i2c_bcm2708
i2c_bcm2708
i2c:mcp7941x</pre>
i2c:mcp7941x
}}


== /media/mmcblk0p1/config.txt ==
== /media/mmcblk0p1/config.txt ==
Line 20: Line 21:
Add these two parameters to the bottom
Add these two parameters to the bottom


<pre>dtparam=i2c1=on
{{Cat|/media/mmcblk0p1/config.txt|dtparam{{=}}i2c1{{=}}on
dtparam=i2c_arm=on</pre>
dtparam{{=}}i2c_arm{{=}}on
}}


{{cmd|mount -o remount,ro /media/mmcblk0p1}}
{{cmd|mount -o remount,ro /media/mmcblk0p1}}
Line 29: Line 31:
== Binding the hardware clock device ==
== Binding the hardware clock device ==


You will want to make sure the device is created when hwclock starts, if it isn't already created. To the bottom of /etc/conf.d/hwclock add this:
You will want to make sure the device is created when hwclock starts, if it isn't already created. To the bottom of {{Path|/etc/conf.d/hwclock}} add this:


<pre>start_pre() {
{{Cat|/etc/conf.d/hwclock|...
start_pre() {
     if [ -d "/sys/class/i2c-adapter/i2c-1/i2c-dev/i2c-1" ]; then
     if [ -d "/sys/class/i2c-adapter/i2c-1/i2c-dev/i2c-1" ]; then
         einfo "Creating RTC device";
         einfo "Creating RTC device";
         echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-1/new_device
         echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-1/new_device
     fi
     fi
}</pre>
}
}}


For the time being this is necessary but in the future when [https://github.com/raspberrypi/linux/issues/1032 issue 1032] you should be able to just add
For the time being this is necessary but in the future when [https://github.com/raspberrypi/linux/issues/1032 issue 1032] you should be able to just add


<pre>dtparam=i2c-rtc,mcp7941x</pre>
{{Cat|/media/mmcblk0p1/config.txt|...
dtparam{{=}}i2c-rtc,mcp7941x
}}


to /media/mmcblk0p1/config.txt
to {{Path|/media/mmcblk0p1/config.txt}}
 
== Starting hwclock on boot ==
The hwclock service needs to be started for the hardware clock device to actually do anything. Check if hwclock has been started by running this command:
 
{{cmd|rc-status {{!}} grep hwclock}}
 
If it outputs
 
<pre> hwclock                                                          [  started  ]</pre>
 
hwclock has already started. Otherwise start it manually and add it to the default init.d runlevel, so that it starts at boot time:
 
{{cmd|rc-service hwclock start}}
{{cmd|rc-update add hwclock default}}
 
If you are running Alpine Linux in the diskless mode (non-persistent root filesystem), save the configuration by:
 
{{cmd|lbu commit -d}}


[[Category:Hardware]]
[[Category:Hardware]]
[[Category:System Administration]]
[[Category:System Administration]]
[[Category:Raspberry]]

Latest revision as of 13:53, 25 August 2023

Install Hardware

I used a PiFace Real Time Clock. After installing the CR1220 battery and correctly mounting on the board, see manual for that.

Install Software

Add the modules from the kernel

/etc/modules

Add these modules so they're loaded on boot. You can modprobe each one individually if you don't want to reboot.

Contents of /etc/modules

i2c_dev i2c_bcm2708 i2c:mcp7941x

/media/mmcblk0p1/config.txt

You will need to mount this as read-write

mount -o remount,rw /media/mmcblk0p1

Add these two parameters to the bottom

Contents of /media/mmcblk0p1/config.txt

dtparam=i2c1=on dtparam=i2c_arm=on

mount -o remount,ro /media/mmcblk0p1

Then you will need to reboot.

Binding the hardware clock device

You will want to make sure the device is created when hwclock starts, if it isn't already created. To the bottom of /etc/conf.d/hwclock add this:

Contents of /etc/conf.d/hwclock

... start_pre() { if [ -d "/sys/class/i2c-adapter/i2c-1/i2c-dev/i2c-1" ]; then einfo "Creating RTC device"; echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-1/new_device fi }

For the time being this is necessary but in the future when issue 1032 you should be able to just add

Contents of /media/mmcblk0p1/config.txt

... dtparam=i2c-rtc,mcp7941x

to /media/mmcblk0p1/config.txt

Starting hwclock on boot

The hwclock service needs to be started for the hardware clock device to actually do anything. Check if hwclock has been started by running this command:

rc-status | grep hwclock

If it outputs

 hwclock                                                           [  started  ]

hwclock has already started. Otherwise start it manually and add it to the default init.d runlevel, so that it starts at boot time:

rc-service hwclock start

rc-update add hwclock default

If you are running Alpine Linux in the diskless mode (non-persistent root filesystem), save the configuration by:

lbu commit -d