我正试图使用CM4 IO板的实时时钟(RTC(来保持docker容器中的日期时间更改,因此每当设备重新启动时,它都会记住新设置的日期时间。(默认情况下,它通过chrony进行同步。(我可以使用date --set="<datetime string>"
更新系统的日期时间,但在重新启动时,它会重新同步并覆盖以前设置的日期时间。
要启用OI板的RTC,您需要根据IO板的数据表设置BALENA_HOST_CONFIG_dtparam="i2c_vc=on"
:我已经完成了这项工作(添加了整个车队的配置(,之后我还将i2c-tools
添加到我想要在其中使用的容器中,这允许使用i2cdetect
命令。它可以使用以下命令检测RTC(电池插入偏离路线(:i2cdetect -y 10
(RTC在i2c-10上(,该命令显示数据表所述地址0x51上的RTC设备:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- 0c -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2f
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
虽然对我来说,这看起来像是在1x51上,所以可能有问题?然而,地址似乎是正确的,因为我在运行i2cget -y 10 0x51
:0x00
时得到了以下结果。而当我运行i2cget -y 10 1x51
时,我得到:Error: Chip address is not a number!
。为了完整起见,这是我运行时得到的(其他i2c地址正在使用,不知道是为了什么(:
i2cget -y 10 0x0c
:0x5f
i2cget -y 10 0x2f
:0x00
这是运行i2cdetect -l
:时得到的结果
i2c-10 i2c i2c-22-mux (chan_id 1) I2C adapter
i2c-0 i2c i2c-22-mux (chan_id 0) I2C adapter
i2c-22 i2c bcm2835 (i2c@7e205000) I2C adapter
这也反映在运行ls -hal /dev/i2c*
时(容器内部和主机操作系统上的结果相同(:
crw-rw---- 1 root i2c 89, 0 Apr 5 12:49 /dev/i2c-0
crw-rw---- 1 root i2c 89, 10 Apr 5 12:49 /dev/i2c-10
crw-rw---- 1 root i2c 89, 22 Apr 5 12:49 /dev/i2c-22
这是我运行dmesg | grep -E '(i2c|rtc)' | head -50
时的输出(容器内和主机操作系统上的结果相同(:
[ 6.492981] i2c i2c-22: Added multiplexed i2c bus 0
[ 6.493115] i2c i2c-22: Added multiplexed i2c bus 10
[ 9.378968] i2c /dev entries driver
到目前为止似乎还不错。
根据Raspberry Pi论坛上的这篇帖子,你还需要:
echo pcf85063 0x51 >/sys/class/i2c-adapter/i2c-10/new_device
modprobe rtc-pcf85063
我已经将这两件事都添加到了我的docker设置中(并尝试了同一篇文章中列出的一些变体(,但我认为我甚至不需要这个,因为我可以在设置_dtparam
后立即检测到它。做与不做似乎没有什么区别。
通常,当一切正常工作时,您应该能够设置、更新。。。RTC使用hwclock
命令,但每当我运行该命令时,我都会收到以下消息:
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --verbose option to see the details of our search for an access method.
这是我运行hwclock --verbose
:时的输出
hwclock from util-linux 2.36.1
System Time: 1649177573.560553
Trying to open: /dev/rtc0
Trying to open: /dev/rtc
Trying to open: /dev/misc/rtc
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.
当我在主机操作系统上运行timedatectl
时,我得到:
Local time: Tue 2022-04-05 17:04:37 UTC
Universal time: Tue 2022-04-05 17:04:37 UTC
RTC time: n/a
Time zone: n/a (UTC, +0000)
System clock synchronized: yes
NTP service: n/a
RTC in local TZ: no
这似乎表明RTC不工作。
当在容器内部运行这个命令时,我得到:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
我在这里错过了什么或做错了什么?这是权限/用户组问题吗(因为我试图在容器内执行此操作(?是什么错误的配置吗?我是不是错过了一些额外的设置?
我也在balena论坛上发布了同样的问题,我只需将BALENA_HOST_CONFIG_dtoverlay
设置为"i2c-rtc,pcf85063a,i2c_csi_dsi,addr=0x51"
。
额外信息:在CM4 IO板数据表中(第2.13节(,它表明您只需要将BALENA_HOST_CONFIG_dtparam
设置为"i2c_vc=on"
,但在从上面设置dtoverlay
时不需要这样做。我测试过有没有这个,没有发现任何区别。