docs: capture sensor-side WDR via /mnt/mtd/Config/wdrmode.dat on Sofia#156
Merged
docs: capture sensor-side WDR via /mnt/mtd/Config/wdrmode.dat on Sofia#156
Conversation
Documents what's actually needed to capture sensor-mode reconfiguration on a XiongMai Sofia build, after we walked through the false leads: * Sofia's runtime DVR-IP `BroadTrends.AutoGain` knob does NOT reconfigure the sensor. The path is `Public_LinearWDR_Switch` -> `LibXmCap_System_switchWdrMode` -> `XmCap_IspVi_switchWdrMode`, which calls `HI_MPI_ISP_GetPubAttr`, optionally does a VI unbind/rebind, and persists the new mode to `/mnt/mtd/Config/wdrmode.dat` via `libdvr.so`'s `SetWdrMode` (a thin `fopen + fwrite`). It does not call `HI_MPI_ISP_SetWDRMode` and does not invoke any sensor-driver code. Confirmed empirically on two boards: zero `0x100` (SmartSens) / `0x3000` (Sony) cycles after `AutoGain` toggle. * The actual sensor-side mode dispatch happens at Sofia startup: Sofia reads wdrmode.dat (4-byte LE int) and calls `cmos_set_image_mode(mode)` inside the per-sensor driver. For Sony IMX29x the case-set is 0=linear, 2=line-WDR (DOL), 3=half-frame WDR, 4=full-frame WDR. * Procedure: write the desired mode to wdrmode.dat with `printf '\x02\x00\x00\x00' > ...`, kill Sofia, restart under the bind-mount trace wrapper. Sofia at startup picks up the new mode and the trace captures the alternative init register sequence. * Worked example: Hi3516CV300 + IMX291 + Sofia. Mode 0 (linear) produced 70 writes; mode 2 (line-WDR) produced 140 writes with 17 WDR-only register values (`0x3007=0x00`, `0x3009=0x02`, `0x3018=0x6D`, `0x3046=0xE1`, etc. - matching Sony's IMX29x DOL configuration). `trace_segment.py`'s existing `find_mode_switches` heuristic catches the two-pass init as `init` + `mode_switch_1` with no changes; `trace_to_driver.py` emits the WDR body as `<sensor>_set_mode_1`. * Diagnostic: which sensors in your Sofia binary have WDR firmware vs being linear-only? Grep the binary for `_init ` debug markers and `LINE Init OK` banners. A sensor with both has multi-mode drivers; one with only `_init` is linear-only and `wdrmode.dat` changes are no-ops at the sensor level (the file still gets persisted, but no sensor-driver code path responds). Also generalises the existing "Segmenter heuristic" note from the hardcoded SmartSens `0x100` pair to "the stream-control register pair the matched `init_pattern` used", with explicit Sony IMX and SOI/JX examples - reflects the actual code in `trace_segment.py` post-#152. No tooling changes; CI `test-extraction-pipeline` passes unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Documents the procedure for capturing sensor-side WDR mode init from a XiongMai Sofia build, after the multi-step investigation that turned up several false leads.
TL;DR of the new section
Sofia's runtime DVR-IP
BroadTrends.AutoGainknob does not reconfigure the sensor — it lands inPublic_LinearWDR_Switch→LibXmCap_System_switchWdrMode→XmCap_IspVi_switchWdrModewhich only reads the ISP attr (the misleadingHI_MPI_ISP_SetWDRMode failederror string is a copy-paste relic from a refactor) and persists the new mode to/mnt/mtd/Config/wdrmode.datvialibdvr.so'sSetWdrMode(a thinfopen + fwriteof a 4-byte LE int). The sensor-side mode dispatch happens at the next Sofia startup: Sofia readswdrmode.datand callscmos_set_image_mode(mode)inside the per-sensor driver, which then runs the alternative init register table.So the actual procedure is:
Then verify the right mode fired by grep'ing Sofia's stdout for the per-mode banner (
linear mode/2to1 line WDR .../LINE Init OK).Worked example: IMX291 + CV300 + Sofia
linear mode2to1 half frame WDR mode+60fps LINE Init OKinit(106)init(106) +mode_switch_1(114)WDR-only registers:
0x3007=0x00,0x3009=0x02,0x3018=0x6D,0x3046=0xE1,0x300A=0xF0,0x3014=0x20,0x3020/0x3021— Sony's IMX29x DOL configuration block.Tooling unchanged
trace_segment.py's existingfind_mode_switchesheuristic (added in #149, generalised in #152) catches Sofia's two-pass init asinit+mode_switch_1with no code changes — works because Sofia'scmos_set_image_modeper-mode init wraps each register table between a standby-assert/release pair on the family's stream-control register, which is exactly what the heuristic looks for.trace_to_driver.pyemits the WDR body as<sensor>_set_mode_1next to<sensor>_linear_init, allgcc -Wall -Wextraclean.Diagnostic added
The new section ends with a recipe for answering "does my sensor have WDR firmware in this Sofia build?":
A sensor with only
~~~_init~~~markers is linear-only on that build;wdrmode.datwrites still get persisted but produce no sensor-side effect.Also generalises the Segmenter heuristic note
The existing paragraph said
find_mode_switcheswatches for0x100=0 → 0x100=1. That was true only for SmartSens; #152 made the function take whichever(reg, init_val, stream_val)tuplefind_init_boundsmatched on. The note now reads "the same stream-control register pair that the matchedinit_patternused", with explicit examples for SmartSens / Sony IMX / SOI/JX.Test plan
tools/test_pipeline.sh(CI smoke test) — passes🤖 Generated with Claude Code