Skip to content

hi3516cv300: give hwclock the SoC RTC as /dev/rtc0 - #2643

Merged
openipc-ai merged 1 commit into
masterfrom
hi3516cv300/rtc-class
Oct 20, 2026
Merged

openipc-ai merged 1 commit into
masterfrom
hi3516cv300/rtc-class

Conversation

@openipc-ai

@openipc-ai openipc-ai commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #191.

Problem

On hi3516cv300, hwclock cannot use the SoC's RTC. Lab hi3516cv300 on hi3516cv300_lite, master+6f03cc4:

hwclock: can't open '/dev/misc/rtc': No such file or directory
hwclock: can't open '/dev/rtc0': No such file or directory
ls: /sys/class/rtc: No such file or directory

The kernel config has # CONFIG_RTC_CLASS is not set, so there is no /dev/rtc0. hctosys never runs, and fake-hwclock has no RTC to keep.

The image ships the SDK's hi3516cv300_rtc.ko, which nothing loads. It can't stand in for a real driver: it is a character device with private HI_RTC_* ioctls, so hwclock's RTC_RD_TIME on it fails with Operation not permitted, exactly as reported in #191.

The RTC itself works. With no driver loaded, its counter reads day 14, 01:08, which matches the board's 14 days of uptime: it ticks from power-on.

Change

hi3516cv300.generic.config turns on:

  • RTC_CLASS, with hctosys and systohc;
  • the dev, sysfs and proc interfaces;
  • RTC_DRV_HIBVT.

Depends on OpenIPC/linux#125. The cv300 device tree names the RTC "hisilicon,hi_rtc", which rtc-hibvt doesn't match, and #125 fixes that. #125 also brings in the driver fixes from OpenIPC/linux#81: no 1970 from a counter that lost power, and no read failure from the low-voltage flag. Until #125 is merged, this change costs about 8 KB of kernel and changes nothing else: the driver is built but never binds.

Left alone:

  • hi3516ev100.generic.config. It shares the kernel family, but there is no ev100 board to test it on, so it is not part of this change (Qodo's review point).
  • hi3516cv300.neo.config. It is a minimal config that never mentions the RTC.

Kernel size: the same tree, toolchain and global patches, built both ways. zImage grows from 1,680,160 to 1,688,608 bytes (+8,448), and the DTB by +4. That makes the uImage about 1667 KB of the 2048 KB cap.

Hardware tested on

hi3516cv300, lab board hi3516cv300-imx291 (hi3516cv300_lite), no backup battery.

I built the kernel with Buildroot from this branch, with OpenIPC/linux#125's two commits applied to its source. U-Boot loaded it over TFTP. The NOR kernel was never written, and afterwards the board went back to its own kernel and its original environment.

The kernel was rebuilt and re-run on this board after OpenIPC/linux#125's set_time() fix: setting the time returns 0, 1999 is refused, and the time reads back.

Evidence

Before (shipped kernel):

hwclock: can't open '/dev/misc/rtc': No such file or directory
hwclock: can't open '/dev/rtc0': No such file or directory

After. First boot from power-on: the counter restarted with no battery, so it is refused, and userspace restores the time:

[    2.059490] hibvt_rtc 12090000.rtc: rtc core: registered 12090000.rtc as rtc0
[    2.066670] hibvt_rtc 12090000.rtc: RTC driver for hibvt enabled
[    2.688849] hibvt_rtc 12090000.rtc: hctosys: unable to read the hardware clock
fake-hwclock: clock restored to 2026-10-20 13:02:15 UTC

hwclock and sysfs work once the time is set:

crw-rw----    1 root     root      254,   0 Jan  1  1970 /dev/rtc0
hwclock: Tue Oct 20 13:06:28 2026  0.000000 seconds
since_epoch: 1792501588

Warm reboot. The RTC kept counting, and hctosys applies it:

[    2.748957] hibvt_rtc 12090000.rtc: setting system clock to 2026-10-20 13:07:54 UTC (1792501674)

30 s PoE cut, with no battery. The counter restarts, and it is refused rather than set to 1970:

[    2.689031] hibvt_rtc 12090000.rtc: hctosys: unable to read the hardware clock
python3 .github/scripts/ci-matrix.py --self-test
ci-matrix: self-test ok (107 boards, 156 packages, 75 cases)
git diff --name-only origin/master | python3 .github/scripts/ci-matrix.py --stdin
matrix={"include":[{"platform":"hi3516cv300_lite"},{"platform":"hi3516cv300_neo"},{"platform":"hi3516cv300_ultimate"},{"platform":"hi3516ev100_lite"}]}

Scope

  • No kernel patches under general/package/all-patches/linux/ (those go to OpenIPC/linux)
  • No files specific to a single retail camera model (those go to OpenIPC/builder)
  • No probing or bring-up tooling (that goes to OpenIPC/ipctool)
  • Nothing under general/overlay/ or in a shared load_<vendor> script hardcodes a value specific to my board
  • Package sources come from an OpenIPC repository, and any version bump keeps at least the specificity of the pin it replaces (a new package should pin a full 40-character SHA)
  • No LD_PRELOAD, and no binaries that cannot be rebuilt from source
  • New code is selected by a defconfig, so CI actually builds it

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Enable the SoC RTC for hi3516cv300 and hi3516ev100

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Enable the kernel RTC class and SoC driver so hwclock can use /dev/rtc0.
• Enable clock synchronization and RTC interfaces for both generic kernel configurations.
• RTC binding depends on the device-tree fix in OpenIPC/linux#125.
Diagram

graph TD
  CFG["Generic configs"] --> DRV["rtc-hibvt driver"] --> CORE["RTC class"] --> DEV["/dev/rtc0"] --> USER["hwclock and hctosys"]
  DT["Device-tree match"] --> DRV
  DRV --> SOC["SoC RTC"]
Loading
High-Level Assessment

Enabling the existing Linux RTC class and driver is preferable to adapting hwclock to the SDK module’s private ioctls. Confirm the OpenIPC/linux#125 device-tree and driver changes are available before expecting either configuration to bind the RTC.

Files changed (2) +22 / -2

Bug fix (2) +22 / -2
hi3516cv300.generic.configEnable standard SoC RTC support for hi3516cv300 +11/-1

Enable standard SoC RTC support for hi3516cv300

• Enables the RTC class, rtc-hibvt, clock synchronization, and dev, sysfs, and proc interfaces. This allows the generic cv300 kernel to expose the SoC clock as rtc0 once the device-tree match is fixed.

br-ext-chip-hisilicon/board/hi3516cv300/hi3516cv300.generic.config

hi3516ev100.generic.configEnable standard SoC RTC support for hi3516ev100 +11/-1

Enable standard SoC RTC support for hi3516ev100

• Applies the same RTC driver, synchronization, and interface settings to the ev100 generic kernel configuration. Hardware behavior on ev100 was not tested in this PR.

br-ext-chip-hisilicon/board/hi3516cv300/hi3516ev100.generic.config

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. The ev100 image lacks hardware proof ✓ Resolved
Description
hi3516ev100.generic.config enables the RTC class and HiSilicon RTC driver without a hardware test
on an hi3516ev100 camera. The description explicitly says hi3516ev100 was not run on hardware, so
this firmware behavior remains unverified for an affected image.
Code

br-ext-chip-hisilicon/board/hi3516cv300/hi3516ev100.generic.config[R1777-1784]

+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_SYSTOHC=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+CONFIG_RTC_INTF_SYSFS=y
+CONFIG_RTC_INTF_PROC=y
+CONFIG_RTC_INTF_DEV=y
+CONFIG_RTC_DRV_HIBVT=y
Evidence
The compliance rule requires hardware evidence for any change that can alter firmware behavior on a
camera. The PR description provides hardware evidence only for hi3516cv300 and explicitly states
that hi3516ev100 was not run on hardware, while this diff enables the RTC driver in the hi3516ev100
image.

Rule 3: Hardware evidence is present and honest
br-ext-chip-hisilicon/board/hi3516cv300/hi3516ev100.generic.config[1777-1784]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The change enables RTC behavior for hi3516ev100, but the PR provides no hardware evidence for that affected image.
## Fix Focus Areas
- br-ext-chip-hisilicon/board/hi3516cv300/hi3516ev100.generic.config[1777-1784]
## Recommended Fix
Run the built image on a real hi3516ev100 camera and add before/after evidence showing RTC device availability, `hwclock` behavior, and boot-time clock restoration, or remove the unverified ev100 configuration change.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can open the rule or relationship behind a finding in one click

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread br-ext-chip-hisilicon/board/hi3516cv300/hi3516ev100.generic.config Outdated
The cv300 kernel was built without the RTC class, so the board had no
/dev/rtc0: hwclock failed with "can't open '/dev/misc/rtc'", hctosys
never ran, and fake-hwclock had no RTC to keep. The SDK's
hi3516cv300_rtc.ko, which the image ships but nothing loads, cannot
stand in: it offers only private HI_RTC_* ioctls, so hwclock's
RTC_RD_TIME on it fails with EPERM (#191).

Turn on the RTC class with hctosys, systohc, the dev, sysfs and proc
interfaces, and rtc-hibvt. It binds once the device tree names the RTC
"hisilicon,hi35xx-rtc" (OpenIPC/linux#125); until then this costs
about 8 KB of kernel and changes nothing else.

hi3516ev100 shares the kernel family but is left as it is: there is
no ev100 board to run it on.
@openipc-ai
openipc-ai force-pushed the hi3516cv300/rtc-class branch from e7b3bca to c607f54 Compare October 20, 2026 14:16
@openipc-ai

Copy link
Copy Markdown
Collaborator Author

/review

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit c607f54

@openipc-ai
openipc-ai merged commit ff3282e into master Oct 20, 2026
35 of 36 checks passed
@openipc-ai
openipc-ai deleted the hi3516cv300/rtc-class branch October 20, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hwclock не работает со встроенным RTC на HI3516cv300

1 participant