Repository navigation
rtc: hibvt: do not set the clock to 1970 from a counter that lost power - #79
Merged
openipc-ai merged 1 commit intoOct 20, 2026
Conversation
This was referenced Oct 13, 2026
Author
|
/review |
Code Review by Qodo
1.
|
openipc-ai
force-pushed
the
rtc/hibvt-low-voltage-hisilicon-hi3516ev200
branch
from
October 13, 2026 11:19
181be2a to
b2c076e
Compare
Author
|
/review |
|
Code review by qodo was updated up to the latest commit b2c076e |
When the backup cell of a hi3516ev300 board is flat, every power cut restarts the RTC counter from zero, and hctosys then sets the system clock to 1970-01-01 (seen as "setting system clock to 1970-01-01 00:00:06 UTC"). - read_time() returns -EINVAL for a counter before 2000-01-01, so hctosys leaves the clock alone instead of applying it. set_time() refuses the same range, so every time it accepts can be read back. - Clear the low-voltage flag (RTC_INT_RAW bit 1) with LV_INT_MASK. The driver wrote 1 to RTC_INT_CLR, which is the alarm bit, so the flag never cleared and a pending alarm interrupt was acknowledged instead. The low-voltage flag cannot tell whether the time is good. On that board it stays set, and returns about 0.5 s after each clear, both with the flat CR927 and with a fresh one that keeps the time through a 5-minute power cut. That is why the vendor's commented-out "date/time is not reliable" message stays out, and why validity is judged by the counter.
openipc-ai
force-pushed
the
rtc/hibvt-low-voltage-hisilicon-hi3516ev200
branch
from
October 20, 2026 11:15
b2c076e to
f3fe950
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a hi3516ev300 camera whose CR927 backup cell had gone flat, a power cut of about 5 minutes brought the clock back at 1970:
The counter restarts from zero when it loses every supply. The driver returns it as a real time, and hctosys applies it. A warm
rebootkeeps the time, so nothing in U-Boot or the driver resets the RTC.Change
read_time()returns-EINVALfor a counter before 2000-01-01, so hctosys leaves the clock alone.set_time()refuses the same range, so every time it accepts can be read back (Qodo's review point).RTC_INT_RAWbit 1) is cleared withLV_INT_MASK. The driver wrote1toRTC_INT_CLR, which isAIE_INT_MASK, so the flag never cleared and a pending alarm interrupt was acknowledged instead.The low-voltage flag is not used to judge the time, or reported. The first revision of this PR printed a "backup supply low" warning from it. The flag turned out not to mean that. On this board it stays set, and returns about 0.5 s after each clear, both with the flat cell and with a fresh CR927 that keeps the time through a 5-minute power cut. So the vendor's commented-out
date/time is not reliablemessage stays out, and the counter decides.OpenIPC's
fake-hwclockalready handles an unreadable RTC: it restores its checkpoint, and NTP corrects the clock.Ports: #80 (hisilicon-hi3516cv500, same code) and #81 (hisilicon-hi3536dv100, which still had the vendor's return
-EINVALon the flag).Verification
Board: hi3516ev300,
hi3516ev300_ultimate_rostelecom-ipc8232swc-we, USB powered through a switchable relay. I built the kernel with this driver from the same build tree as the camera's shipped fitImage, with onlyrtc-hibvt.cchanged; the DTB is identical. U-Boot loaded it through an extrabootcmdstep, so the shipped kernel was never touched. The camera is back on its own kernel andbootcmd.Fresh cell, warm reboot. The time is applied, with no message about the flag:
Fresh cell, 60 s power cut. The cut started at 11:12:37 and the camera stopped answering ping during it. Power returned at 11:13:39:
Counter that lost its time. I zeroed the counter through the RTC load registers and ran
reboot -f, so no shutdown script could write the time back. The counter is refused, and the clock is not stepped to 1970:The same boot path with the flat cell, on the first revision of this change, gave
hctosys: unable to read the hardware clockafter a real ~1-minute power cut, where the shipped kernel had givensetting system clock to 1970-01-01 00:00:06 UTC.set_time()andread_time()agree:With the shipped driver and the fresh cell, a 5-minute power cut booted with
setting system clock to 2026-10-20 11:05:41 UTC, about 7 s after power returned. The cell was the cause of the 1970 clock, and this change keeps that working.