Files
thebearsandClaude Opus 5.5 07da135257 Add the vendor firmware: stock flash dump, update file, both unpacked
vendor/ holds the camera's 16 MB NOR dump (backup-ssc377d-nor16m.bin), the
vendor update V3.6.1.3, and their unpacked trees, which the RE tools and
notes read. verify.py now defaults to vendor/flash_dump_ssc377d, and the
docs point at vendor/ instead of folders beside the checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EfVNki7giKruPunvux6dDA
2026-10-29 14:23:37 -04:00

52 KiB
Raw Permalink Blame History

Porting the AnjoyVision MC-L18D to OpenIPC: everything learned, and where it came from

This guide is for learning. It covers how the vendor firmware was taken apart, where each hardware fact came from, every file I added or changed and why, how each piece was tested, and the mistakes I made and corrected along the way.

Two companion files go deeper on single topics:

  • MCL18D-PORT.md: the short port notes.
  • AF-BOARD-PROTOCOL.md: the lens-board protocol, byte by byte.

Status: sections 1–19 were written before the camera was on the bench. Every claim in them is backed by one of these:

  • the vendor binaries;
  • OpenIPC's sources;
  • a build that succeeded;
  • a test against a simulation.

Section 20 is what the camera then showed, 2026-10-28/29, and where it corrected the earlier sections they have been updated. Section 14 lists what was still to be checked then.


Contents

  1. What you started with
  2. How OpenIPC builds an image (the mental model)
  3. Taking the vendor firmware apart
  4. Hardware facts and their sources
  5. Kernel: the device tree
  6. The GC5603 sensor driver
  7. Registering the board in the OpenIPC tree
  8. The board package anjvision-mcl18d
  9. PTZ over ONVIF
  10. The lens board (zoom / focus) protocol
  11. Manual focus, iris and mcl18d-af
  12. Building
  13. Testing: what was tested and how
  14. Not verified on hardware: first-boot checklist
  15. Upstreaming: what OpenIPC would and would not accept
  16. Every file changed, by repository
  17. Mistakes made and corrected
  18. Loose ends in the folder
  19. Techniques worth reusing
  20. On the hardware: bring-up, 2026-10-28/29

1. What you started with

Item What it is
backup-ssc377d-nor16m.bin Full 16 MB SPI NOR dump of your camera: boot, kernel, rootfs and settings. Everything authoritative comes from this.
r1885__firmware_MCL18D_V0-A-H5_V3.6.1.3_20260917092033.bin The vendor's update file. It has a newer app build than your dump, but the same kernel and sensor driver.
MC-L18D-spec-sheet-EN.pdf, MC-L18D-wiring-diagram-EN.pdf Connector pinouts (D1, D5, D6, D7) and the feature list.

The hardware:

  • SoC: SigmaStar SSC377D, the "Infinity6C" family.
  • Sensor: GalaxyCore GC5603.
  • Flash: 16 MB NOR.
  • Board layout: a copy of SigmaStar's SSC027A-S01A reference design.

Optional external boards hang off connector D7:

  • an autofocus/zoom lens board;
  • a Pelco-D pan/tilt head.

2. How OpenIPC builds an image (the mental model)

You need this picture before any of the changes make sense.

  • OpenIPC firmware is a Buildroot "external tree".

    • make BOARD=x picks br-ext-chip-<vendor>/configs/x_defconfig.
    • That defconfig is merged with general/openipc.fragment.
    • Buildroot then builds the toolchain, kernel, packages and root filesystem.
  • The kernel is not in the firmware repo.

    • It is downloaded as a tarball from OpenIPC/linux, branch sigmastar-infinity6c for this chip.
    • The kernel config file lives in the firmware repo, under br-ext-chip-sigmastar/board/infinity6c/.
  • SigmaStar's device tree is chosen by a kernel config option, CONFIG_SS_DTB_NAME, not by U-Boot.

    • A new board therefore needs a new .dts plus a kernel config copy pointing at it.
  • Sensor drivers are separate kernel modules (sensor_<name>_mipi.ko).

    • They are built from OpenIPC/sensors by the sigmastar-osdrv-sensors package.
    • At boot, load_sigmastar (from the sigmastar-osdrv-infinity6c package) insmods the driver named in the U-Boot variable sensor.
    • The defconfig's BR2_OPENIPC_SNS_MODEL sets that default.
  • The ISP needs an IQ (image tuning) file per sensor: /etc/sensors/<sensor>.bin.

  • majestic is the closed-source streamer (RTSP, web UI, night mode, ONVIF). It reads /etc/majestic.yaml. You change that with the cli tool: cli -s .key value / cli -g .key.

  • Per-board settings go through sanctioned hooks, not shared files. S30customizer runs these on first boot:

    • /usr/share/openipc/customizer.sh
    • /usr/share/openipc/muxes.sh

    firstboot (a factory reset) makes them run again.

  • Shipped shell scripts are comment-stripped at build time (general/scripts/strip-shell-comments.awk). They run under busybox ash, not bash.

  • CI rule: every defconfig and package must be either built by CI or listed in .github/scripts/ci-matrix.py with a reason. ci-matrix.py --self-test enforces this.

Source: openipc/firmware/CLAUDE.md, Makefile, general/, and reading the build as it ran.


3. Taking the vendor firmware apart

3.1 The update file → firmware_MCL18D_V3.6.1.3/

binwalk and xxd showed three parts:

Offset Size Content
0 1556 Vendor header: magic ANJOY888, model MCL18D_V0-A-H5_V3.6.1.3, date 2026-09-17
1556 1,899,640 uImage kernel
1,901,196 8,897,236 xz SquashFS root filesystem
after that 3372 Zero padding
dd if=update.bin of=kernel.uImage bs=1 skip=1556 count=$((1899576+64))
dd if=kernel.uImage of=kernel.xz bs=64 skip=1      # strip the 64-byte uImage header
xz -dc kernel.xz > kernel.img                        # header says lzma; it's really xz
dd if=update.bin of=rootfs.squashfs bs=1 skip=1901196 count=8897236
unsquashfs -d rootfs rootfs.squashfs

Lesson: the uImage header claims LZMA but the payload is xz. Trust magic bytes (FD 37 7A 58 5A), not headers.

The device tree inside the kernel.

  1. I searched kernel.img for the DTB magic D0 0D FE ED. There were five candidates.
  2. I read each candidate's totalsize field and kept the real one, at offset 3,638,064.
  3. I carved it out and decompiled it:
dd if=kernel.img of=board.dtb bs=1 skip=3638064
dtc -I dtb -O dts -o board.dts board.dtb

3.2 The full flash dump → flash_dump_ssc377d/

The partition boundaries come from the U-Boot environment in the dump (strings | grep mtdparts), which reads mtdparts=nor0:0x30000(BOOT),0x200000(kernel),0xCD0000(rootfs),0x100000(DATA):

Partition Offset Size Content
BOOT 0x000000 192 KB IPL + U-Boot + environment
kernel 0x030000 2 MB uImage, Linux 5.10.61
rootfs 0x230000 0xCD0000 SquashFS, app V3.4.5.2, built 2025-11-06
DATA 0xF00000 1 MB jffs2: runtime settings (config.xml)
dd if=dump.bin of=kernel.uImage bs=64K skip=3 count=32
dd if=dump.bin of=rootfs.squashfs bs=64K skip=35 count=205
dd if=dump.bin of=data.jffs2 bs=64K skip=240 count=16
jefferson -f -d data data.jffs2        # pip install jefferson

Findings:

  • The kernel is byte-identical to the update file's.
  • The sensor driver gc5603_MIPI_1125.ko is identical.
  • The app build is older.
  • Your MAC address, from the U-Boot environment, is F0:00:06:14:73:FF. Keep this dump. It is your only way back.
  • config.xml in DATA gives the live settings:
    • AfConfig enable="1" type="1"
    • PTZConfig PELCO_D ComPort=1 BaudRate=2400
    • Dzoom max 10

3.3 Where the vendor's logic lives

File Role
opt/ch/libtools.so Board tables, including the GPIO table per device type
opt/ch/media_server Video, ISP, IR-cut and lamps, and the AF data sender
opt/ch/comm_server Serial port: PTZ, lens board, upgrade
opt/ch/mainctrl, record_server Misc GPIO (SD power, LEDs)
config/modules/…/gc5603_MIPI_1125.ko Sensor driver
config/iqfile/gc4023_day.bin / gc4023_night.bin IQ files. There is no GC5603 one.
opt/ch/*.flag Feature switches, e.g. af.flag = lens board fitted

Tools used:

  • strings, objdump, radare2 for disassembly;
  • unicorn (Python) to run ARM code;
  • pyelftools;
  • dtc, jefferson.

I did not install a decompiler.


4. Hardware facts and their sources

GPIO numbers are Linux sysfs numbers. On Infinity6C these equal the pad index, and OpenIPC's kernel uses the same numbering. I checked this by comparing both kernels' pad tables.

Function Pin Where it came from
Speaker amp enable GPIO 12 (PAD_SPI0_DO) libtools.so table g_io_mcl12d2, type code 4
Reset button GPIO 60 (PAD_SR_IO00) same table, type 3
Alarm out / red-blue light GPIO 10 (PAD_SPI0_CK), driven 1 at boot same table, type 2, init 1
Alarm in GPIO 44 (PAD_FUART_CTS) same table, type 1
Warning light, active low GPIO 61 (PAD_SR_IO01), driven 1 (off) at boot same table, type 12; mainctrl's GetLedBrGpioPort pulls it low on alarm
IR-cut A (night) GPIO 11 (PAD_SPI0_DI) the vendor kernel's built-in /dev/irled driver table
IR-cut B (day) GPIO 80 (PAD_SAR_GPIO1) same driver
Light board's day/night output (CDSIN): 1 day, 0 night GPIO 23 (PAD_PM_IRIN) same driver ("IRDET"); media_server reads it as a level in "Passive" mode
SD power GPIO 45 (PAD_FUART_RTS) device tree, irled driver, record_server
SD card detect pad 22 (PAD_PM_SD_CDZ) device tree
White lamp PWM0 on PAD_PWM0 (pad 13) device tree padmux
IR lamp PWM4 on PAD_SPI0_CZ (pad 9); OpenIPC drives it as GPIO 9 padmux; the wiring sheet calls it "PWM1"
Ethernet LED PAD_PWM1 (pad 14) padmux mode LED1
Lens/PTZ UART FUART RX/TX (pads 42/43) = /dev/ttyS2 padmux, plus comm_server opening /dev/ttyS2
Core voltage select GPIO 30 (PAD_PM_GPIO4) media_server holds it low; OpenIPC's reference DTS switches it by CPU frequency
Sensor I2C I2C1 (pads 58/59), address 0x62 device tree, sensor driver

How the table was found.

  • The app doesn't store pin numbers as strings.
  • gpio_init_by_array is called with a per-board array, chosen by device type. This board is type 0x681.
  • I found the caller and decoded the array, then decoded the type codes from the getter functions in libtools.so. For example, the reset getter looks for type 3.

IR-cut direction took two sources:

  1. The vendor's day-mode function writes 1 to /dev/irled, which pulses GPIO 80. Night mode writes 0, which pulses GPIO 11. Found by disassembling media_server.
  2. In majestic, irCutPin1 is the "opens" coil and irCutPin2 the "closes" coil. Found in majestic-webui's ircut-scan.js: irCutPin1: opensWhenHigh, irCutPin2: closesWhenHigh. The filter opens at night.

So irCutPin1=11 and irCutPin2=80.

Wiring sheet connectors:

Connector Pins
D5 (lighting) CDS in, IR PWM, white PWM
D6 IR-cut coil
D7 TX/RX (ttyS2), SPKEN, red/blue IO
D1 pin 7 = reset, pin 8 = network LED

The full map is in vendor/firmware_MCL18D_V3.6.1.3/gpio_map.md.


5. Kernel: the device tree

Method.

  1. Compiled OpenIPC's own infinity6c-ssc027a-s01a.dts.
    • This needed a fake autoconf.h, generated from the kernel config, because the DTS includes generated headers.
  2. Decompiled both DTBs with dtc -s (sorted).
  3. Diffed them node by node.
  4. Decoded the padmux "schematic" entries, which are pad / mode / purpose triples, into the kernel's macro names.

Differences found (everything else matched):

Item Vendor OpenIPC reference
PAD_PWM0 PWM0 (white lamp) I2C0
PAD_SPI0_CZ PWM4 mode 2 (IR lamp) unused / SPI
PAD_PWM1 Ethernet LED (LED1 mode 2) I2C0
PAD_FUART_RX/TX 2-wire FUART —
SD card 20 MHz, drive strength 0 48 MHz, drive 1

The change is a thin overlay DTS. It #includes the reference DTS and overrides only padmux and sdmmc, so upstream fixes to the reference still flow in:

linux-infinity6c/arch/arm/boot/dts/infinity6c-ssc027a-s01a-mcl18d.dts

It is carried into the build as a kernel patch. The board kernel config infinity6c-ssc027a-mcl18d.config is a copy of infinity6c-ssc027a.config with one line changed:

CONFIG_SS_DTB_NAME="infinity6c-ssc027a-s01a-mcl18d"

Verified:

  • The kernel's own SigmaStar checks passed during the build: "The configuration of GPIO & PADMUX is correct!" and "PUSE check PASS!".
  • The DTB extracted from the built uImage has the new padmux and SD settings.
  • The compiled padmux table matches the vendor's entry for entry.

Deliberately not ported:

  • The vendor's /dev/irled driver. majestic drives the IR-cut pins and reads the light sensor itself.
  • The core-voltage behaviour on GPIO 30. OpenIPC's reference design switches it by CPU frequency; I left that alone.

6. The GC5603 sensor driver

Why it had to be rewritten

  • OpenIPC/sensors has no GC5603 driver for Infinity6C.
  • The vendor's .ko can't simply be copied in. Its ms_cus_sensor struct differs from OpenIPC's in two places. The vendor module would read and write the wrong fields.
    • SPI: the vendor struct has no SPI fields. OpenIPC's has app_spi_cfg spi_cfg (12 bytes, packed) and spi_handle_t *spi_bus (4 bytes) right after i2c_bus. Every field from sensor_if_api on sits 16 bytes later in OpenIPC.
    • Frame sync: after sat_mingain, the vendor has one 4-byte field and OpenIPC has three: nPixelSize, CurTotalVertLine and bChangeVTS (a u8 padded to 4). So every callback pointer (pCus_sensor_poweron onward) sits 24 bytes later.
    • How this was measured: OpenIPC's offsets were computed with offsetof and the ARM toolchain. The vendor's were read from its code: ldr r6, [r0, #0x40] in pCus_poweron loads sensor_if_api, and cus_camsensor_init_handle stores each callback at a fixed offset.

How it was rebuilt

  1. Disassembled gc5603_MIPI_1125.ko with relocations, so calls and table references resolve to names.
  2. Dumped its read-only data as register/value tables. The C tables were generated from the binary, not hand-copied:
    • init (2960x1666@30)
    • gain
    • exposure
    • VTS (frame length)
    • mirror/flip
  3. Recovered the constants from the code:
Constant Value
Bayer order BG
Bit depth 10-bit
MIPI lanes 2
MCLK 27 MHz
I2C address 0x62, 16-bit register / 8-bit data
Line period 19047 ns
VTS at 30 fps 1750
Gain table 26 entries, max 128x
  1. Kept the vendor's temperature-dependent black-level logic:
    • it reads level registers 0x0410/0x0414 on gain changes;
    • it writes 0x0451/0x0452/0x0455/0x0456.
  2. Wrote it in OpenIPC's sensor-driver template style: sensors/sigmastar/infinity6c/sensor_gc5603_mipi.c, about 950 lines.

One deliberate difference: orientation.

  • The vendor maps "no mirror/flip" to register 0x022c=3, then its app inverts mirror and flip for this board. Net effect: native readout.
  • Here, "no mirror/flip" is native readout, so majestic's image.mirror/image.flip mean what they say.

How it was verified without the camera: a differential test

openipc/gc5603-difftest/ runs both modules in an ARM emulator (unicorn):

  • the vendor .ko;
  • my driver, built with the OpenIPC toolchain.

emu_ko.py:

  • loads a kernel module;
  • applies its relocations;
  • stubs the kernel symbols it calls;
  • connects it to a fake sensor that records every I2C transaction.

difftest.py drives both modules through the same operations and compares every register write:

  • init and sensor ID;
  • gain and exposure sweeps;
  • FPS;
  • orientation;
  • temperature levels.

Results:

  • 76,011 checks, 0 mismatches. The .ko actually shipped in the image also passes.
  • The test was tested. Four deliberately planted bugs were each caught, with 82 to 928 mismatches each.
  • The first two planted bugs were not caught, which exposed that the test wasn't reaching the temperature code. I fixed the test before trusting it; see section 17.

The IQ (tuning) file

  • The flash dump has no GC5603 IQ file.
  • media_server hard-codes /config/iqfile/gc4023_day.bin and gc4023_night.bin for this board. That is what your camera really runs with the GC5603.
  • So the image ships the vendor's gc4023_day.bin as /etc/sensors/gc5603.bin.
  • That is a vendor binary blob. It works for your build but can't go upstream (section 15).

Wiring it into the build

  • general/package/sigmastar-osdrv-sensors/0001-sigmastar-infinity6c-add-gc5603-driver.patch adds the driver source to the sensors package. It was generated from the openipc/sensors branch gc5603-infinity6c.
  • general/package/sigmastar-osdrv-infinity6c/files/script/load_sigmastar gets a new gc5603) case arm: insmod sensor_gc5603_mipi.ko chmap=1. It is additive; the family default is untouched, as OpenIPC's rules require.
  • general/package/sigmastar-osdrv-infinity6c/files/sensor/configs/gc5603.bin is the IQ file.

7. Registering the board in the OpenIPC tree

br-ext-chip-sigmastar/configs/ssc377d_mcl18d_defconfig is a copy of ssc377d_lite_defconfig with these differences:

-BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=".../infinity6c-ssc027a.config"
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=".../infinity6c-ssc027a-mcl18d.config"
+BR2_LINUX_KERNEL_PATCH=".../board/infinity6c/mcl18d/linux"
-BR2_OPENIPC_FLASH_SIZE="8"
+BR2_OPENIPC_FLASH_SIZE="16"          # 16 MB NOR: 2 MB kernel + 8 MB rootfs slots
+BR2_OPENIPC_SNS_MODEL="gc5603"       # default `sensor` env → which driver loads
+BR2_PACKAGE_ANJVISION_MCL18D=y       # the board package (section 8)
+BR2_PACKAGE_ONVIF_SIMPLE_SERVER=y    # ONVIF with PTZ (section 9)

Other registration edits:

  • general/package/Config.in: one source line for the new package.
  • .github/scripts/ci-matrix.py:
    • ssc377d_mcl18d goes in UNBUILT_BOARDS, with the reason "single retail device".
    • anjvision-mcl18d goes in NOT_BUILT.
    • --self-test passes (107 boards, 158 packages).

OpenIPC's own rules send single retail devices to OpenIPC/builder, so this is kept as a local port.


8. The board package anjvision-mcl18d

Location: firmware/general/package/anjvision-mcl18d/.

  • SITE_METHOD = local: it builds from its own src/.
  • The .mk installs each file to its path below.
File Installed as What it does
Config.in — Kconfig entry; selects onvif-simple-server
anjvision-mcl18d.mk — Builds pelco-ptz, installs everything
files/customizer.sh /usr/share/openipc/customizer.sh First boot. See below.
files/muxes.sh /usr/share/openipc/muxes.sh Drives GPIO 10 and 61 to 1 every boot, as the vendor does
files/S94mcl18d /etc/init.d/S94mcl18d Starts mcl18d-io, pelco-ptz keepalive (without it the lens board and head ignore every command, section 20), and wsd_simple_server (ONVIF discovery, once the interface has an IP)
files/mcl18d-io /usr/sbin/mcl18d-io Polls every 100 ms. Reset button GPIO 60 held 5 s → firstboot. Alarm GPIO 44 changes → syslog + /etc/mcl18d/alarm-in active|idle
files/onvif.conf /etc/onvif.conf.mcl18d ONVIF config: port 85, two profiles, PTZ hooks calling pelco-ptz
files/onvif-passwd /usr/sbin/onvif-passwd Sets the ONVIF password
files/pelco-ptz.conf /etc/pelco-ptz.conf Port, baud (57600), address, mounting, presets
files/mcl18d-af /usr/sbin/mcl18d-af One-shot autofocus (section 11)
src/ /usr/sbin/pelco-ptz C tool for Pelco-D (sections 9 and 11), plus tests

customizer.sh, step by step:

  1. Writes majestic's pin map:

    • nightMode.irCutPin1 11, irCutPin2 80
    • lightSensorPin 23, lightMonitor true
    • backlightPin 9
    • irLightPwmChannel 4, whiteLightPwmChannel 0
    • irCut, backlight and whiteLight set to auto
    • audio.speakerPin 12

    The key names came from majestic's strings and the web UI. They exist in the infinity6c majestic build.

    lightMonitor and backlightPin came from the camera (section 20). Without lightMonitor true majestic never reads the light sensor, so night mode never runs. This majestic brings up no PWM lamp on infinity6c, so backlightPin 9 drives the IR lamp's pad as a plain GPIO, high at night.

  2. Turns off majestic's own ONVIF (.onvif.enabled false), so NVRs find only the PTZ-capable server.

  3. Sets the streams:

    • video0.size 2560x1440 (main);
    • video1.enabled true, video1.size 640x360 (sub).

    These match the ONVIF profiles and the vendor: your camera's saved config.xml streams 2560X1440, and the spec sheet lists 2560×1440 as the 30 fps main stream. The sensor outputs 2960×1666, so full size is possible in principle but untested.

  4. Copies /etc/onvif.conf.mcl18d to /etc/onvif.conf with a random password, so the camera never answers ONVIF with a password anyone else knows.

Why customizer.sh and muxes.sh: they are OpenIPC's sanctioned per-device seams. Shared files like general/overlay/ must not carry board-specific GPIO numbers.

Why the reset button and alarm are a shell loop: majestic doesn't handle them on this chip. The script uses only busybox applets that are in the image, which I checked.


9. PTZ over ONVIF

Why majestic can't do it here

  • OpenIPC's PTZ plugin is majestic-af, which already speaks Pelco-D. majestic loads it only when its "Motorized lens" settings enable it. Those settings are seeded from U-Boot variables ptz_control, ptz_port, ptz_speed.
  • I compared majestic's strings for two chip families:
    • the infinity6e build has that settings section;
    • the infinity6c build (this chip) does not.
  • majestic is closed source, so it can't be added.
  • I tried enabling majestic-af, confirmed it could never load, and reverted it.

The route taken: onvif-simple-server + pelco-ptz

onvif-simple-server is an open-source ONVIF server already packaged in OpenIPC. It runs as a CGI on port 85, and its PTZ requests run shell commands from onvif.conf. All of them point at pelco-ptz.

pelco-ptz (C, in src/) runs one command per invocation:

pelco-ptz move left|right|up|down|in|out [SPEED]   continuous, speed 0..1
pelco-ptz focus near|far | iris open|close         until stop
pelco-ptz stop
pelco-ptz abs X Y Z     /  rel DX DY DZ             ("nan" leaves an axis alone)
pelco-ptz position      /  moving
pelco-ptz home | sethome | preset list|set NAME|goto N|remove N

Design choices:

  • Code split: pelco.c holds pure functions (frames and coordinate maths) with no I/O, so tests can pin every byte. main.c does the serial port, locking, state and presets.
  • Coordinates:
    • pan −1..1 = −180..180°;
    • tilt −1..1 = −90..90°, up positive (Pelco counts tilt down-positive, so it's converted);
    • zoom 0..1 = 0..65535.
  • Absolute and relative moves:
    • Absolute uses Pelco-D's extended "set position" commands 0x4B / 0x4D / 0x4F.
    • Relative asks the head where it is (queries 0x51 / 0x53 / 0x55, replies 0x59 / 0x5B / 0x5D), adds the offset, then moves absolutely.
    • A head that doesn't answer gets the last position pelco-ptz commanded.
  • Diagonals:
    • Pelco-D sets the whole motion in one frame, but ONVIF clients send pan and tilt as separate calls.
    • Axes set within 300 ms of each other are combined into one frame. Older ones are dropped, as ONVIF's "new velocity replaces the old" requires.
  • Presets:
    • 2..32 are stored in /etc/pelco-ptz.presets as N=name,x,y,z.
    • Preset 1 is home.
  • Locking: an exclusive flock stops two requests interleaving frames. Motion state is kept in /tmp/pelco-ptz.state.

Bugs fixed in onvif-simple-server

general/package/onvif-simple-server/03-ptz-absolute-relative-zoom-fixes.patch fixes these upstream bugs, found while testing:

  • A pan/tilt AbsoluteMove passed 0 for the missing zoom, so it drove the lens fully wide every time. It now passes NAN, meaning "leave it".
  • Zoom-only Absolute/RelativeMove ran an uninitialised command buffer through system().
  • An empty RelativeMove was accepted.
  • strcmp was called on a Zoom space that could be NULL, which is a crash.
  • SetPreset sscanf'd %s into an int, which is memory corruption.
  • The FOV-space relative move was rescaled to the configured ranges.

The upstream package is pinned at roleoroleo/onvif_simple_server 7c8672f. My working copy is openipc/onvif_simple_server, branch ptz-fixes.

Wiring note: D7 is a 3.3 V UART. A typical RS-485 Pelco head needs a TTL-to-RS-485 adapter.


10. The lens board (zoom / focus) protocol

Full spec: AF-BOARD-PROTOCOL.md. Reproduction scripts: af-board-re/.

How it was decoded

  • Static disassembly of comm_server and media_server. Along the way:
    • r2 mislabels this binary's library calls by one PLT entry, so af-board-re/plt.py rebuilds the map.
    • comm_server loads addresses with movw/movt pairs.
    • media_server uses literal pools.
    • od.py resolves both.
  • Emulation: the vendor's own functions were run in unicorn (af-board-re/emu.py).
    • libc is stubbed.
    • write() to the UART is recorded.
    • The PTZ dispatcher HandleYuntai was driven with each command name, and the exact bytes it sends were captured.
    • The same was done for the six AF data senders and the upgrade routine.
  • af-board-re/verify.py re-derives every frame in the doc from the binaries: 40 checks, all pass.

What it is

Topic Finding
Link /dev/ttyS2 at 57600 8N1 whenever /opt/ch/af.flag exists, as it does on your camera. This overrides the configured 2400.
Why 57600 The vendor code sets it when af.flag is present. The likely reason is bandwidth: an 18-byte AF frame 30 times a second is about 5400 bit/s, which 2400 baud cannot carry. That reason is my inference.
Commands Plain Pelco-D, address 1. Focus near FF 01 01 00 30 30 62, far FF 01 00 80 30 30 E1, iris open/close …02 00 30 30 63 / …04 00 30 30 65, zoom FF 01 00 20/40 ss ss.
AF data media_server reads the ISP's AF statistics every frame and sends two focus values: whole picture and centre window. Gain, day/night, IR-cut and lamp levels go with them. Your config: CAfV2, 18 bytes, header 51 01 04 78 01 11. Factory default: CAfV3, 16 bytes. The board runs autofocus from this stream.
Boot Version query: END+sum ×8, then VER+sum. The reply holds a lens code and a date. (This board never answered it on OpenIPC, awake or asleep.)
Keep-alive Found on the camera, not in the binaries: the board, and the pan/tilt behind it, ignore every command unless AF frames keep arriving. The vendor never notices because it streams them from boot. pelco-ptz keepalive sends one every 100 ms. See section 20.
Upgrade START+size; the board pulls 128-byte blocks by address; OK ends. Emulated end to end; risky on a real board.

11. Manual focus, iris and mcl18d-af

Focus and iris in pelco-ptz

  • Frames: the motion frame gained focus bits (command-1 bit 0 near, command-2 bit 7 far) and iris bits (command-1 bits 1/2).
  • Speed bytes: frames that move only the lens carry a speed in both data bytes, as the vendor sends them:
    • the zoom speed, or 0x30 for focus/iris (PELCO_LENS_SPEED);
    • a normal Pelco head ignores those bytes when not panning or tilting.
  • State: the motion state is now an array per axis (pan, tilt, zoom, focus, iris), each with its own timestamp for the 300 ms combine rule.
  • Config: /etc/pelco-ptz.conf and the compiled default are now 57600. A pan/tilt head sharing D7 must be set to 57600 too.

Why not the board's own autofocus

It needs the per-frame ISP AF statistics. majestic is closed source and doesn't export them on this chip, so nothing on OpenIPC can produce real AF data frames. pelco-ptz keepalive sends frames with constant values purely to keep the board awake; they give its autofocus nothing to climb.

What mcl18d-af does instead

A shell script run on the camera. Contrast autofocus from the camera side:

  • Sharpness measure: the byte size of a JPEG snapshot.
    • At a fixed JPEG quality, a sharper picture has more fine detail and compresses less. On the camera a sharp snapshot of the bench was about 338 KB and a blurred one about 126 KB, against 0.1–0.6% between two snapshots of a still scene.
    • It asks for the middle third with ?crop=XxYxWxH (the syntax came from majestic's strings: "crop must be XxYxWxH"). majestic for this chip refuses it: HTTP 501, "snapshot parameters are not supported on this platform". The script then judges the whole frame.
  • The lens it has to work with:
    • the motor reports no position, so positions are motor run time;
    • it is slow: focus lay up to 19 s of motor time away, and the sharp band is about 1.5 s wide;
    • so a short step from a blurred start changes the picture less than the noise.
  • Sweep: run the motor without stopping and take snapshots as fast as they come, timing each from /proc/uptime.
    • It stops once the picture has risen 5% above where it began and then fallen 3% back from its best twice running: focus has just been passed. It notes when the best snapshot was taken.
    • It goes far first. If the picture gets clearly worse over the first 1.5 s, it turns round; if a whole sweep (-t, 45 s) finds nothing, it sweeps the other way.
    • The second sweep never turns. A snapshot shows the lens a little after the fact, so just after a reversal the picture goes on getting worse for a moment.
  • Approach: back off past the best snapshot by how far the motor ran after it plus a margin (-b, 1 s), then step back the way the sweep went in -s (150 ms) steps, measuring after each, and stop on the first step that is worse.
    • It never reverses near focus, so gear backlash cannot leave it short. The lens rests one step past the sharpest point.
    • If the very first change is for the worse, the margin was too small: it backs off again, up to 3 times (AF_LOST).
  • On the camera: from either side of focus, 12–27 s, ending at 99.4–99.6% of the best snapshot seen.
  • Login: user/password from /etc/onvif.conf (onvif-passwd sets them to root's), or -u.
  • Options:
    • -s approach step, -b back-off, -t longest sweep;
    • -n snapshots averaged per approach step, -w settle time;
    • -g threshold in thousandths, default 0.5%;
    • -c crop, -a URL.
  • Logs: to syslog with tags AF_START, AF_SWEEP, AF_BACK, AF_STEP, AF_DONE, AF_CROP_REFUSED, AF_SNAPSHOT_FAILED, AF_NO_DETAIL, AF_LOST.
  • Fallbacks: a refused crop falls back to the full frame; a scene with no detail ends with AF_NO_DETAIL. It always stops the motor on exit.

12. Building

F=openipc/firmware; O=~/.cache/openipc-mcl18d
docker run --rm --user $(id -u):$(id -g) -e HOME=$O/home -e BR2_DL_DIR=$O/dl -e PWD=$F \
  -v $F:$F -v $O:$O -w $F openipc-builder:24.04 make BOARD=ssc377d_mcl18d TARGET=$O/output

Gotchas hit:

  • Arch can't build it natively. Buildroot 2024.02's host tar fails on this Arch toolchain, so I made an Ubuntu 24.04 image, openipc-builder:24.04. It has build-essential, bc, bison, flex, cpio, rsync, unzip, wget, python3, cmake, u-boot-tools and bsdextrautils.
  • PWD must be passed into the container. The Makefile reads $PWD from the environment, and docker doesn't set it.
  • hexdump is needed. It comes from bsdextrautils, and the kernel's padmux check (dtx_diff) uses it. Without it the build died with a confusing dtc "Unable to parse input tree" error.
  • Build outside the synced folder. /tmp is RAM, and Seafile would sync gigabytes, so the build lives in ~/.cache/openipc-mcl18d.
  • Rebuilding one package: make … br-anjvision-mcl18d-dirclean, then make … again (incremental, about 40 s).

Result:

  • uImage 1991 / 2048 KB.
  • rootfs 5264 / 8192 KB.
  • Images are copied to openipc/images/:
    • openipc.ssc377d-nor-lite.tgz
    • uImage.ssc377d
    • rootfs.squashfs.ssc377d

13. Testing: what was tested and how

Test What it proves Result
GC5603 differential test (gc5603-difftest/) My driver writes the same registers as the vendor's for every operation 76,011 checks, 0 mismatches; 4/4 planted bugs caught
Kernel build checks Padmux and pin-use table are consistent PASS
make test (src/tests/pelco_test.c) Every Pelco-D frame byte for byte, including the vendor's focus/iris frames; coordinate maths; reply parsing; combine rule all pass
make e2e (src/tests/pelco_e2e.py) The real pelco-ptz binary against a simulated head on a pseudo-terminal, including focus/iris all pass
tests/onvif_e2e.py Real ONVIF SOAP requests → patched server → pelco-ptz → simulated head 23/23 pass; the unpatched server fails 7
make af BUSYBOX=… (src/tests/af_sim.py) mcl18d-af, comment-stripped as it ships, under a host build of the tree's own busybox ash, against a simulated lens with backlash, noise, end stops and, in one case, late snapshots 14 checks, all pass
af-board-re/verify.py Every lens-protocol frame in the doc, re-derived from the vendor binaries 40/40
ci-matrix.py --self-test, test_shell_parse.sh, test_strip_shell_comments.sh Tree rules; every shipped script parses before and after stripping pass

The mcl18d-af simulation covers:

  • starting on either side of focus;
  • starting at focus;
  • starting far out;
  • snapshots that show the lens 150 ms late;
  • a refused crop;
  • a wrong login;
  • a featureless scene.

Why a host busybox: the camera's ash isn't bash. I built busybox from the tree's own source and .config with the host compiler, so the script is tested under the same shell it ships with.


14. Not verified on hardware: first-boot checklist

Written before the camera was available. Most of it has since been checked; section 20 has the results.

Before flashing:

  • Flashing needs OpenIPC's U-Boot for SSC377D and a serial console.
  • Keep backup-ssc377d-nor16m.bin.

Video and board I/O:

  1. dmesg shows sensor_gc5603_mipi loading, and fw_printenv sensor says gc5603.
  2. The picture is upright. If not, set image.mirror / image.flip.
  3. Day/night switches the right way. If not, set nightMode.lightSensorInvert.
  4. The IR-cut clicks the right way.
  5. GPIO 10 = 1 leaves the red/blue light off, and GPIO 61 = 1 is right for the light board.
  6. SD card, microphone, speaker (audio.speakerPinInvert if silent), reset button, alarm input.

PTZ:

  • From the shell: pelco-ptz move left 0.5, then pelco-ptz stop.
  • Then an ONVIF client on port 85, after running onvif-passwd with root's password.

Lens board:

  • pelco-ptz focus far, then pelco-ptz stop.
  • Check that the board holds focus with no AF data frames arriving. The protocol doesn't say what it does then.
  • Check that /image.jpg?crop= works.
  • Check how much a still scene's JPEG size varies between shots. If it varies more than 0.5%, raise mcl18d-af -g.
  • Tune -s and -m to the motor's real speed.

15. Upstreaming: what OpenIPC would and would not accept

From openipc/firmware/CLAUDE.md and its best_practices.md:

Where each part belongs:

  • driver → OpenIPC/sensors;
  • device tree → OpenIPC/linux;
  • single-device board files → OpenIPC/builder (devices/<board>/).

Not acceptable as is:

  • Register tables copied from a vendor driver ("a register table copied out of a camera vendor's driver is the same problem written in C").
  • gc5603.bin, a binary lifted from a factory image.

Fine:

  • The additive load_sigmastar case arm.
  • The onvif-simple-server fixes, as a pull request to roleoroleo/onvif_simple_server.

Never accept majestic's EULA on someone's behalf. It's accepted by the owner at first claim.


16. Every file changed, by repository

Nothing is committed. All changes are on local branches.

openipc/firmware (tag latest = 7d213e9, branch mcl18d-port)

Status Path
new br-ext-chip-sigmastar/configs/ssc377d_mcl18d_defconfig
new br-ext-chip-sigmastar/board/infinity6c/infinity6c-ssc027a-mcl18d.config
new br-ext-chip-sigmastar/board/infinity6c/mcl18d/linux/0001-arm-dts-infinity6c-add-anjvision-mc-l18d.patch
new general/package/sigmastar-osdrv-sensors/0001-sigmastar-infinity6c-add-gc5603-driver.patch
new general/package/sigmastar-osdrv-infinity6c/files/sensor/configs/gc5603.bin
modified general/package/sigmastar-osdrv-infinity6c/files/script/load_sigmastar (gc5603) arm)
new general/package/onvif-simple-server/03-ptz-absolute-relative-zoom-fixes.patch
new general/package/anjvision-mcl18d/: Config.in, .mk, files/, src/ (section 8)
modified general/package/Config.in (source line)
modified .github/scripts/ci-matrix.py (UNBUILT_BOARDS, NOT_BUILT)

openipc/sensors (branch gc5603-infinity6c)

Status Path
new sigmastar/infinity6c/sensor_gc5603_mipi.c

openipc/linux-infinity6c (branch mcl18d)

Status Path
new arch/arm/boot/dts/infinity6c-ssc027a-s01a-mcl18d.dts

openipc/onvif_simple_server (branch ptz-fixes)

The source of the onvif patch.

Other folders in openipc/

Folder Contents
ipctool/ Reference only; it already detects GC5603
majestic-af/ Reference; pinned 67a9631
gc5603-difftest/ The differential sensor test
af-board-re/ Lens-protocol emulator and checks
images/ The built firmware
vendor/ The stock flash dump and the vendor update file, as received
vendor/firmware_MCL18D_V3.6.1.3/ The unpacked update file, plus gpio_map.md and board.dts
vendor/flash_dump_ssc377d/ The unpacked flash dump
MCL18D-PORT.md, AF-BOARD-PROTOCOL.md, this file Notes

Outside openipc/

Item Contents
~/.cache/openipc-mcl18d/ Build tree, download cache, logs

17. Mistakes made and corrected

These are worth reading. Each one is a trap you'll meet in this kind of work.

  1. "The lens board talks FC 01 at 115200." I first said this from a partial read.
    • The FC frames and the 115200 channel exist in comm_server, but only for other customers' builds (af_protocol_5_flag, _MY on /dev/ttyS4).
    • Tracing the af.flag path showed 57600 and plain Pelco-D for this camera.
    • Lesson: a byte pattern in a binary tells you it exists, not that your configuration uses it. Follow the flags.
  2. A test that couldn't fail. The first sensor difftest reported 0 mismatches, but two planted bugs in the temperature code weren't caught either.
    • The test never reached that code.
    • I extended it until all planted bugs were caught.
    • Lesson: always prove a test can fail.
  3. Emulator stubs out of branch range. ARM BL reaches ±16 MB. My stub area was 256 MB away, so calls landed in the wrong function. I moved the stubs inside the code mapping.
  4. r2 PLT names off by one. radare2 and objdump labelled this binary's imported calls with the neighbouring entry's name. plt.py reads each PLT stub's own instructions and follows it to its JUMP_SLOT relocation instead.
  5. Stray files. An earlier r2 command with redirects left junk files in flash_dump_ssc377d/rootfs/opt/ch/. I deleted them.
  6. Docker build "finished" instantly. The Makefile needs $PWD, and the wrapper's exit code hid make's failure. Lesson: read the log, not the exit code.
  7. Missing hexdump in the container produced a misleading dtc error deep in the kernel build.
  8. mcl18d-af -h printed nothing on the camera. It read its help from its own header comments, and the build strips comments. I rewrote it as real text, and the test now runs the stripped copy.
  9. Autofocus overshoot logic. After overshooting, my first version turned back toward the side it already knew was worse, and landed short. The simulator showed it. The fix: after an overshoot, keep the direction and halve the step.
  10. Zoom frames. My first pelco-ptz sent zoom with zero data bytes. The vendor puts a speed there for the lens board, so I now match the vendor.
  11. A patch exported with git diff picked up a generated file. The kernel build rewrites ms_version.h. The first DTS patch carried that rewrite alongside the DTS, and I found it when cross-checking each patch against its source branch. It was harmless only because the kernel regenerates the file on every build. Lesson: export a patch by naming the paths, and read the diff --git lines before shipping it.
  12. "The camera never reads the port." I wrote that in AF-BOARD-PROTOCOL.md from comm_server alone. media_server opens the same port and reads the board's frames. Lesson: a port can have more than one owner; search every binary for the device name.
  13. Plain Pelco-D is enough. I matched the vendor's command frames byte for byte and assumed that was the whole interface. The board also needed the AF stream to be awake, which no amount of reading comm_server would show, because the vendor never lets it sleep. Lesson: reproduce everything the vendor puts on the wire, not just the part you think matters.
  14. A rising TX counter is not a transmission. /proc/tty/driver counts bytes when the DMA driver copies them into its ring buffer, not when they leave the pin. Timing a write at 2400 baud proved they did leave.
  15. Reading the FUART's registers crashed the camera. A devmem read of the UART block hit a register-bus timeout, and the SigmaStar kernel treats that as fatal (MDrv_RIU_TIMEOUT_interrupt, then SW Reset). The pad-mux and clock banks read safely. Lesson: on SigmaStar, probe one bank before scripting a whole dump.
  16. Two dead ends on the colour flares, and one wrong conclusion. First I suspected UART traffic, then the sensor's black-level writes. The flares carried on with the port silent, and in that gain band the black level never changes. Then I wrote that heat was the cause, because refitting the heat sink cut them from every 5–15 s to about one a minute. They did not stop, and the cause is still open (section 20). Lessons: rule out the hardware's state (temperature, supply) before reading driver code, and "rarer" is not "gone".
  17. pkill -f killed my own shell twice, because the pattern also matched the command line that ran it. Write the pattern so it can't match itself ([s]erd\.py).
  18. Hill-climbing a slow motor. The first mcl18d-af stepped the motor a few hundred ms at a time, judged each step, and reversed when it got worse. From a blurred start a step changed the picture less than the noise, and every reversal near focus lost travel to backlash, so it ended short of focus. The simulator had a lens that travelled 1.5 s end to end; the real one needed up to 19 s. Lesson: measure the actuator before tuning a search for it.
  19. A snapshot is late. The sweep's second leg once gave up the moment it started, because the picture was still getting worse from the first leg. The fix was to let only the first sweep turn round, and the simulator now has a case with late snapshots.
  20. "GPIO 61 enables the light board." I named it from where it sits in the vendor's IO table, among the lamps. Following its type code (12) to the code that uses it, mainctrl's GetLedBrGpioPort, showed an active-low warning light that goes low on alarm. Lesson: name a pin by what its consumer does with it.
  21. Night mode configured but never running. The pin map had the light sensor, but majestic's lightMonitor was off, so it never read the pin. Lesson: check the running state (night_mode_source in /metrics), not just the config.

18. Loose ends in the folder

  • Two files I didn't make: firmware_MCL18D_V3.6.1.3/passwd_sys.orig.bak and rootfs.new.squashfs, created Oct 27 at 23:15.
    • They don't appear in anything I ran in these sessions.
    • The name suggests someone edited passwd_sys and repacked the rootfs.
    • Check them before using that folder as a clean reference.
  • ms_version.h in linux-infinity6c: the kernel's build regenerates it, and that edit was swept into the first export of the device-tree patch. The kernel regenerates the file on every build, so it never changed the image. It is now reverted, and the patch holds only the DTS (section 17).
  • The scratchpad under /tmp/claude-1000/… holds intermediate files: listings, the host busybox, the native onvif build. It isn't needed for anything shipped and disappears on reboot.

19. Techniques worth reusing

  • Diff device trees after normalising them. Compile both, decompile with dtc -s, and compare. Raw sources differ in includes and macros.
  • Find tables by their callers, not by searching for numbers. Find the function that consumes the table (here gpio_init_by_array), then follow its argument.
  • Emulate instead of reading branchy code. Load the binary in unicorn, stub libc, capture output syscalls, and drive the real function with real inputs. It is often faster and more trustworthy than static reading.
  • Differential testing for rewrites. Run old and new against the same fake hardware, compare every transaction, and then prove the comparison catches planted bugs.
  • Generate tables from binaries, never hand-copy them.
  • Test shell scripts under the shell they ship with, after the build's own transformations (comment stripping).
  • Keep board specifics in the sanctioned seams: customizer.sh, muxes.sh, the board package. Shared files reach every camera.

20. On the hardware: bring-up, 2026-10-28/29

What happened once the camera was on the bench, in the order it was learned.

The bench

  • Power: a Tasmota plug (http://192.168.1.41/cm?cmnd=Power%20On|Off, Status%2010 reads watts). Power-cycling plus the console is enough to drive U-Boot unattended.
  • Console: an FT232R on the camera's UART0 at 115200. These boards often have a 5 V / 3.3 V jumper; it must be on 3.3 V.
  • Images: served over TFTP from the PC's existing uftpd (/srv/ftp/openipc-mcl18d/).

Getting into U-Boot

  • The vendor's U-Boot (the stock image) ignores Ctrl-C. Its key is bootdelaykey, which is unset, so the default is Enter (\r). With bootdelay=0 it looks for the key only twice, so the Enter has to be in the UART buffer already: send it continuously from power-on.
  • OpenIPC's U-Boot sets rootmtd (5120k or 8192k) on every sf probe, from the size of the squashfs already in flash. fw_setenv rootmtd is therefore overwritten at boot. Writing the larger rootfs from U-Boot is what moves the camera to the 8192k layout.
  • Flash safely: load to RAM, check the image's crc32 against the PC's, write everything except the boot area first, write the boot area last in one command line, read back and compare.

The first claim

The camera ships unclaimed. Root's password is set at the first login, and that same step accepts the Majestic EULA, which only the owner may do. An AI must not type "I agree" (firmware/CLAUDE.md).

The heat sink

  • Symptoms: resets every few minutes, also idle at the U-Boot prompt; the boot ROM's memory test failing (BIST0_0001-FAIL); a kernel oops on memory holding 0xdead4ead (the spinlock debug marker) in path lookup, hitting majestic and dropbear at the same moment; frames turning to coloured noise every 5-15 s.
  • The boot ROM prints the reset's cause. Every one was HW Reset, not WDT Reset (watchdog) or SW Reset (a panic or reboot). That ruled out software.
  • Temperature: majestic's /metrics reports it (node_hwmon_temp_celsius): 76 C. With the heat sink refitted, 63 C steady, no more resets or oopses, and flares only at start-up and about one a minute. They did not go away; see below.
  • What a flare is: one frame where the dark areas fill with coloured noise below a random row, faded out over the next frames by the noise filter. A random start row means an event at a random moment, not a register write at frame start.

Why nothing on D7 moved

  1. The camera side was right. The pad mux (PADTOP 0x6e = 0x1000, FUART_2W_MODE_1), the clock and the vendor's settings all matched. Writing 64 bytes at 2400 baud took as long as sending them, so they left the UART.
  2. Nothing ever came back: rx stayed 0, at every baud from 2400 to 115200, Pelco-D at address 0 and 1, and Pelco-P.
  3. Copying the rest of the vendor's traffic woke it. A few CAfV2 AF frames, then a zoom: the picture zoomed, and the board sent its first bytes ever (51 01 04 78 01 0a …).
  4. Measured: five frames wake it, one does not; it still obeys 3 s later and has gone back to sleep by 40 s; one frame every 100 ms keeps it awake. Pan and tilt sleep and wake with it.
  5. The fix: pelco-ptz keepalive, started by S94mcl18d.

Absolute positions

The head ignores Pelco-D set-position (0x4B/0x4D/0x4F), even after "set zero" (0x49), and never answers position queries. Presets work: set one, move away, go to it, and it is back. So presets are its only absolute positions, and onvif.conf no longer offers AbsoluteMove or RelativeMove, which would have been acknowledged and done nothing.

How a picture became the measuring instrument

With no feedback from the head, every test compared snapshots: the mean pixel difference for "did it move", phase correlation for pan/tilt shift, a scale search for zoom, and Laplacian variance for focus. Blurry or low-contrast scenes defeat the shift estimate, so the frames themselves were checked by eye whenever the numbers disagreed.

Autofocus on the real lens

The first mcl18d-af was tuned on a simulated lens and did not survive the real one (section 17, mistakes 18 and 19). What the camera showed:

  • the snapshot size is a strong signal: about 338 KB in focus against 126 KB blurred, with 0.1–0.6% noise;
  • the motor is slow: focus was up to 19 s of motor time away, and the sharp band about 1.5 s wide;
  • ?crop= returns 501, so it judges the whole frame.

So it now sweeps first and finishes with a one-way approach (section 11). From either side of focus it takes 12–27 s and ends at 99.4–99.6% of the best snapshot it saw.

Night mode, the IR lamp and the light sensor

  • What the vendor does, from media_server and the /dev/irled driver:
    • this unit's saved IR-cut mode is 2, "Passive": day and night come from GPIO 23 alone;
    • in that mode the light board lights its own IR LEDs from its own photoresistor and reports the result on GPIO 23 (IRDET), 1 by day and 0 at night;
    • the SAR ADC light reading in media_server is for other customers' builds (_KO);
    • in its other modes the vendor holds PWM4, the IR lamp, at 100% at night;
    • /dev/irled only pulses the IR-cut (GPIO 11 for night, GPIO 80 for day, 250 ms) and reads GPIO 23.
  • What OpenIPC needed:
    • lightMonitor true, without which majestic never reads the sensor. Then /metrics shows night_mode_source 1;
    • backlightPin 9, because this majestic brings up no PWM lamp on infinity6c. It drives the IR lamp's pad as a GPIO instead, high at night.
  • Checked: forcing night by inverting the sensor for a moment, majestic opened the IR-cut, went grey and drove GPIO 9 high.
  • Not seen: GPIO 23 read 1 with the room lights on and off, and nothing lit the scene with PWM4 at 0% or 100% or GPIO 9 high. Either the board waits for real darkness at its own photoresistor, which a dark room may not give it, or it has no power. Next: cover the photoresistor in a dark room and watch GPIO 23 and the LEDs (a phone camera sees IR), and check the light board's supply on D5.

The colour flares that remain

  • What they look like: below a random row, the frame is random coloured noise. They come mostly within seconds of a large change in lighting, such as the room lights going on or off.
  • Ruled out:
    • UART traffic;
    • the driver's black-level writes, also forced during exposure changes;
    • the motors;
    • writes of the frame length, the gain index or the analog gain page in the middle of a frame;
    • VIF rewinds and FIFO errors.
  • Same as the vendor: the vendor driver writes its exposure registers at the same point as this one (CUS_FRAME_ACTIVE, status 1).
  • Open. The next test is the stock firmware on the same board, in the same scene: if it flares too, the cause is the hardware.

Loose ends from the bench

  • majestic logs set_gpio(12, 0) error, about the speaker-enable pin, at every start. Not looked into.
  • A majestic restart once left a zombie process with stuck threads; a reboot cleared it.
  • Time-based pan moves are not a way back to a position: in one trial, 1 s right then 1 s left at half speed left the picture differing from the start by a mean pixel difference of 36, against 50 for the move itself. Use presets for positions.