Skip to content

xm: name the V1 sensor from the factory HWID when the bus gives nothing - #278

Merged
widgetii merged 2 commits into
masterfrom
xm-hwid-sensor
Nov 11, 2026
Merged

widgetii merged 2 commits into
masterfrom
xm-hwid-sensor

Conversation

@widgetii

Copy link
Copy Markdown
Member

Problem

On an XM N51813L (Hi3518CV100, Sofia firmware built 2016-09-28), ipctool -s printed "No sensor detected". Every read through /dev/hi_i2c returns 0, including a sweep of every address at reg 0x3000.

What the vendor firmware does

I decompiled Sofia and libdvr.so: the firmware never probes the sensor.

  • libdvr save_dvrHWInfo() / foo() parse the U-Boot HWID (16 hex digits → strtoull → little-endian u64) into g_hwinfo.
  • get_hwinfo(0) = byte0 & 0x1f, the product (25 = "N51813").
  • get_hwinfo(5), "forward video chip" in libdvr's SYSTEM INFO dump, = byte2 >> 4, the sensor: 0 OV9712, 1 External Signal, 2 IMX138, 3 IMX104, 4 IMX122, 5 IMX136, 6 MT9P006, 7 AR0130, 8 AR0140, 9 H22, 10 AR0141, 11 BF3116, 12 PS1210k.
  • get_hwinfo(6) = byte3 & 0xf, the DSP (2 = "HI3518C").
  • Sofia then runs the AR0130 init table built into it, via /dev/hi_i2c CMD_I2C_WRITE to dev 0x20, 16/16-bit.

Change

  • uboot_getenv() loads the U-Boot env on demand. -s never walks the flash, so it had no env.
  • xm_hwid_sensor() decodes the HWID. It is gated on is_xm_board() and HISI_V1, the only libdvr generation checked.
  • When the bus probe comes back empty, -s prints <model>_<control>. The report's sensors: entry gets source: xm-hwid, so it is not taken for a read of the part.

The libipchw path (getsensorid()) is unchanged.

Tested

Tested on an N51813L, built with the hi3516cv100 toolchain and packed with UPX 4.2.3. HWID=8043420002748439:

$ ipctool -s
AR0130_i2c
$ ipctool | sed -n '/^sensors:/,/^clocks:/p'
sensors:
- vendor: ON Semiconductor
  model: AR0130
  control:
    type: i2c
  source: xm-hwid

The native unit tests pass.

Xiongmai's Hi3518/Hi3516C V1 Sofia firmware never probes its sensor.
libdvr's save_dvrHWInfo() unpacks the U-Boot HWID (16 hex digits, one
little-endian u64) into g_hwinfo; get_hwinfo(5), "forward video chip" in
libdvr's SYSTEM INFO dump, is the high nibble of byte 2, and Sofia brings
up the sensor its build carries.

On an N51813L (Hi3518CV100, HWID=8043420002748439) every read through
/dev/hi_i2c comes back 0, so `ipctool -s` said "No sensor detected". With
the probe empty on an XM V1 board, decode the HWID instead: `-s` prints
AR0130_i2c, and the report's sensors entry carries `source: xm-hwid` so
it is not mistaken for a read of the part.

uboot_getenv() loads the environment on demand, for callers such as -s
that never walk the flash. Only V1 is decoded; later libdvr generations
were not checked.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Identify XM V1 sensors from HWID when bus probing fails

🐞 Bug fix ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Identify XM V1 sensors from factory HWID when the sensor bus yields no result.
• Load U-Boot environment on demand so -s can access HWID.
• Mark HWID-derived report entries to distinguish them from sensors detected on the bus.
Diagram

graph TD
  Entry["CLI or report"] --> Probe["Bus probe"] --> Found{"Sensor found?"}
  Found -->|yes| Output["Sensor output"]
  Found -->|no| Decode["XM V1 fallback"] --> Env["U-Boot HWID"] --> Output
  Decode -->|ineligible| Missing["No sensor"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Put HWID fallback in getsensorid
  • ➕ All sensor consumers would share one detection path.
  • ➖ Would change libipchw behavior and risk presenting an HWID-derived identity as a sensor read.

Recommendation: Keep the fallback at the CLI and report boundaries. It preserves bus-probe precedence and libipchw behavior while letting reports explicitly identify the inferred source.

Files changed (5) +101 / -1

Enhancement (4) +70 / -0
xm.cDecode XM V1 sensor identity from factory HWID +50/-0

Decode XM V1 sensor identity from factory HWID

• Adds a vendor sensor mapping and decodes the HWID sensor field only for XM boards with HiSilicon V1 chips. Missing, invalid, unsupported, and External Signal values produce no fallback identity.

src/boards/xm.c

xm.hExpose XM HWID sensor lookup +2/-0

Expose XM HWID sensor lookup

• Declares the board-specific lookup for the CLI and report paths.

src/boards/xm.h

uboot.cLoad U-Boot environment on demand +17/-0

Load U-Boot environment on demand

• Adds a load operation to the existing MTD environment scan. 'uboot_getenv()' invokes it when no environment has been copied yet, enabling callers that do not scan flash first.

src/uboot.c

uboot.hDeclare on-demand U-Boot lookup +1/-0

Declare on-demand U-Boot lookup

• Exports 'uboot_getenv()' for the XM HWID lookup.

src/uboot.h

Bug fix (1) +31 / -1
main.cUse HWID identity after unsuccessful sensor probes +31/-1

Use HWID identity after unsuccessful sensor probes

• Adds an HWID fallback to '-s' and report generation without replacing successful bus results. HWID-derived report entries carry 'source: xm-hwid'.

src/main.c

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

qodo-free-for-open-source-projects Bot commented Nov 11, 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


Remediation recommended

1. Invalid factory IDs name the wrong sensor ✓ Resolved
Description
xm_hwid_sensor() accepts any fully parsed hexadecimal value instead of requiring the documented
16-digit HWID. On an XM V1 board with no probe result, an environment value such as HWID=0 selects
index zero and reports OV9712 as though the factory ID identified it.

Grey Divider

Tip of the day
💡 Did you know, you can import rules and skills only from the repositories your team follows

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

HWID=0 or any short hand-set value parsed fine and decoded as sensor 0,
the OV9712. save_dvrHWInfo() always writes 16 hex digits; require them.
@widgetii

Copy link
Copy Markdown
Member Author

Fixed in ee41089: xm_hwid_sensor() now accepts only the full 16-hex-digit form save_dvrHWInfo() writes. HWID=0 and other short values fall through to the existing no-sensor path. Re-checked on the N51813L: -s still prints AR0130_i2c.

@widgetii
widgetii merged commit 2adc991 into master Nov 11, 2026
5 checks passed
@widgetii
widgetii deleted the xm-hwid-sensor branch November 11, 2026 13:20
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.

1 participant