Balenaos使用Raspberry Pi Compute模块4 IO板的实时时钟在容器中

发布于 2025-01-19 04:59:22 字数 3876 浏览 2 评论 0原文

我正在尝试使用CM4 IO板的实时时钟(RTC)来持久从Docker容器内部进行DateTime更改,因此,每当设备重新启动时,它都会记住新设置的DateTime。 (默认情况下,它通过 chrony 。系统的日期时间使用date -set =“< dateTime String>“,但是重新启动后,它重新启动并覆盖先前设置的DateTime。

要启用OI板的RTC,您需要设置balena_host_config_dtparam =“ i2c_vc = on”根据IO板的数据表: 我已经做到了(添加了机队的配置),之后,我还将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 0x510x00时,我会得到以下结果。当我运行i2cget -y 10 1x51时,我得到:错误:芯片地址不是数字!。 只是要完成,这就是我运行时得到的(使用的其他I2C地址,不知道是什么):

  • i2cget -y 10 0x0c0x5f
  • <代码> i2cget -y 10 0x2f :0x00

这是我在运行i2cdetect -l <​​/code>>:

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*(在容器内和主机OS中相同的结果):

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(在容器内和主机OS中相同的结果):

[    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

到目前为止,看起来还不错。

根据 this 在Raspberry Pi的论坛上帖子,您还需要:

  1. <代码: <代码> echo pcf85063 0x51&gt;/sys/class/class/i2c-adapter/i2c-10/i2c-10/new_device
  2. modprobe rtc-pcf85063

我已经在我的docker设置中添加了这两个东西在同一帖子中列出了一些变体),但是我认为我什至不需要这个,因为我可以在设置_DTPARAM后立即检测到它。这样做或不这样做似乎没有任何区别。

通常,当一切正常工作时,您应该能够设置,更新,...使用hwclock命令的RTC,但是每当我运行该命令时,我会收到以下消息:

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.

当我在主机OS上运行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

我在这里想念或做错了什么?这是一个权限/用户组问题(因为我试图从容器内部执行此操作)?是否有一些错误的配置?我错过了一些额外的设置吗?

I'm trying to use the CM4 IO board's Real-Time Clock (RTC) to persist datetime changes from within a docker container, so whenever the device reboots, it remembers the newly set datetime. (By default it syncs via chrony.) I can update the system's datetime using the date --set="<datetime string>", but upon reboot it re-syncs and overrides the previously set datetime.

To enable the OI board's RTC, you need to set BALENA_HOST_CONFIG_dtparam="i2c_vc=on" according to the IO board's datasheet:

I've done that (added fleet-wide configuration), after that I've also added i2c-tools to the container I want to use it in, which allows the usage of the i2cdetect command.
It can detect the RTC (with battery inserted off course) using the following command: i2cdetect -y 10 (RTC is on i2c-10) which shows the RTC device on address 0x51 as stated by the datasheet:

     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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Although to me this looks like it's on 1x51, so maybe there's an issue there?
However, the address does seem to be correct, since I get the following result when running i2cget -y 10 0x51: 0x00. Whereas when I run i2cget -y 10 1x51, I get: Error: Chip address is not a number!.
Just to be complete, this is what I get when I run (other i2c addresses in use, don't know what for):

  • i2cget -y 10 0x0c: 0x5f
  • i2cget -y 10 0x2f: 0x00

This is what I get when running 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

This is also reflected when running ls -hal /dev/i2c* (same result inside container and on host OS):

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

This is the output when I run dmesg | grep -E '(i2c|rtc)' | head -50 (same result inside container and on host OS):

[    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

So far so good, it seems.

According to this post on Raspberry Pi's forum, you also need to:

  1. echo pcf85063 0x51 >/sys/class/i2c-adapter/i2c-10/new_device
  2. modprobe rtc-pcf85063

I've added both these things to my docker setup (and also tried a few variations listed in that same post), however I don't think I even need this, since I can detect it right away after setting the _dtparam. Having done this or not doesn't seem to make any difference.

Normally, when everything is working correctly, you should be able to set, update, ... the RTC using the hwclock commands, but whenever I run that, I get the following message:

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.

This is the output when I run 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.

When I run timedatectl on the host OS I get:

               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

This seems to indicate the RTC is not working.

When running this command inside the container itself, I get:

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

What am I missing or doing wrong here? Is this a permission/usergroup issue (since I'm trying to do this from inside a container)? Is it some wrong configuration? Am I missing some extra setup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个ˇ局外人 2025-01-26 04:59:22

我还在 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。我测试过有和没有这个,没有发现任何区别。

I'd also posted the same question on the balena forum and what I had to do was simply set BALENA_HOST_CONFIG_dtoverlay to "i2c-rtc,pcf85063a,i2c_csi_dsi,addr=0x51".

Extra info: in the CM4 IO board datasheet (Section 2.13) it indicates you only need to set BALENA_HOST_CONFIG_dtparam to "i2c_vc=on", but this is not needed when setting the dtoverlay from above. I've tested with and without this and have found no difference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文