siemens / meta-iot2050

SIMATIC IOT2050 Isar/Debian Board Support Package
MIT License
129 stars 76 forks source link

add commandline tool to check rtc battery status #438

Open nhahnetsrot opened 1 year ago

nhahnetsrot commented 1 year ago

The patch adds the readrtcbattery commandline tool that prints the current status of the rtc battery (1 == faulty, 0 == ok).

jan-kiszka commented 1 year ago

Commit message should always contain a reason WHY we want this change.

We may also think about who to make this tool discoverable to our users.

Another improvement could be calling this tool from a systemd timer once a week or so and log a system error if a low battery is detected.

nhahnetsrot commented 1 year ago

Commit message should always contain a reason WHY we want this change.

Ok, i added this

We may also think about who to make this tool discoverable to our users.

What do you mean with that ?

Another improvement could be calling this tool from a systemd timer once a week or so and log a system error if a low battery is detected.

Yes, sounds like a good idea ... shall i do that (ask Volker about that)? My information was, that somehow this tool is intended to be called from some orcla module and then the battery-warning may show up in some high-level tool / health-gui.

jan-kiszka commented 1 year ago

General remark: Please fold changes to the patches into the existing ones (interactive rebase), rather than patching on top.

jan-kiszka commented 1 year ago

We may also think about who to make this tool discoverable to our users.

What do you mean with that ?

Having it mentioned in the README e.g.

Another improvement could be calling this tool from a systemd timer once a week or so and log a system error if a low battery is detected.

Yes, sounds like a good idea ... shall i do that (ask Volker about that)? My information was, that somehow this tool is intended to be called from some orcla module and then the battery-warning may show up in some high-level tool / health-gui.

We don't have those tools included here. This layer is supposed to be free-standing first of all, providing guidance / examples / re-usable bits how to make use of the hardware.

AsuraZeng commented 1 year ago

hi

If no battery or voltage is low, using the existing tool hwclock also can show the status.

hwclock 
[  107.495137] rtc-pcf8563 2-0051: low voltage detected, date/time is not reliable.
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument
jan-kiszka commented 1 year ago

hi

If no battery or voltage is low, using the existing tool hwclock also can show the status.

hwclock 
[  107.495137] rtc-pcf8563 2-0051: low voltage detected, date/time is not reliable.
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

hwclock is apparently not using RTC_VL_READ while only that IOCTL is triggering the readout of the RTC status bit we need.

jan-kiszka commented 1 year ago

A customer analyzed a problem with the current implementation of RTC_VL_READ in our RTC driver: Every write clears the INVALID bit, and that prevents checking the state after, e.g., a write-back done on NTP adjustment during boot. Unfortunately, he didn't report his findings to the upstream kernel.

So I'm trying to resolve that there, see https://lore.kernel.org/lkml/da84b6b1-a9d8-ce46-16a9-e1a2d495240c@siemens.com/T/#u. A simple python script to read the ioctl proved it's working on our hardware.

jan-kiszka commented 9 months ago

Seems the hardware does not permit proper read-out, and the kernel does not allow working around that limitation. I'm not sure if it still makes sense to follow this path, given that Linux has no framework to report the battery state via some userspace service. Users could still evaluate the system boot log for warnings about the battery state.