Skip to content

RTC probe adopts a chip whose status-register read failed, then writes time into it #23

Open

Description

@ptr727

Found while reviewing the hw CLI (#1, #16). This is pre-existing code from upstream dev that neither PR changes.

Problem

rtc_time_unreliable() in zephcore/adapters/clock/ZephyrRTCDiscover.c returns true when the status-register read fails ("can't confirm => don't trust it"). rtc_probe() accepts a candidate whose time block is valid BCD or for which rtc_time_unreliable() returns true. So a chip that answers the 7-byte time read with non-BCD data, and then fails the status read, is accepted as an RTC. The first such chip becomes the write-back target (s_active). Every later time sync then calls zephcore_rtc_save(), which writes seven bytes at that chip's time register and read-modify-writes its status register.

The acceptance-on-power-loss rule exists for a good reason: a battery-depleted RTC holds garbage time with its power-loss flag latched, and it must still be adopted so a sync can re-initialise it. But a failed status read is not that flag. It is the absence of evidence, and it is treated as proof the chip is an RTC.

When it matters

Only on a board that declares an RTC candidate at an address shared with a non-RTC part, where that part answers the time read but not the status read. The RAK4631 used to declare the DS3231 at 0x68, an IMU address; #1 now declares only the RV3028 there (see #4). Other boards that include all of rtc-i2c.dtsi are the ones to check.

Suggested direction

Accept on a power-loss flag that was actually read as set. On a failed status read, skip the candidate (or leave it unprobed) rather than adopting it. That would change upstream behaviour, so it would go to liquidraver/ZephCore as its own PR, with the maintainer's go-ahead.

Activity

  1. added 2 commits that reference this issue on Oct 2, 2026
    581fe6c
    0212c7a
  2. ptr727 commented on Oct 2, 2026

    @ptr727
    OwnerAuthor

    Fixed on the iteration branches at the maintainer's direction: 581fe6c on #1 and 0212c7a on #16. A power-loss flag now counts only when it was read as set, so a chip with invalid time and an unreadable status is skipped, not adopted. Left open until the change reaches dev through upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions