Repository navigation
Conversation
nanddump: full NAND backup over the vendor telnet shell -- no UART, no TFTP, no disassembly. Enables the built-in telnet server via DHIP (set_telnet), then reads every raw /dev/mtdNro partition through the shell with 'dd | base64' (ASCII-armored, so the pty cannot corrupt the stream) and verifies each dump against the size declared in /proc/mtd. Targeted at firmwares with a minimal busybox (Zenointel GK7205V510 stock: no gzip/md5sum/tftp/nc), but works on any Linux device exposing /dev/mtd* over telnet. upgrade: CLI wrapper for the existing (hardware-validated) upgrade_firmware() -- flashes a vendor upgrade package (Dahua zzip) over DHIP with progress reporting; --state queries the upgrader. Validated on a Zenointel SD-2N-4G twin (QEMU, stock vendor firmware): telnet enable over DHIP, defcfg partition recovered byte-exact vs the pristine NAND image; a full-dump pass is covered in the PR discussion.
PR Summary by QodoAdd telnet-based NAND backup and firmware upgrade CLI commands
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
Review findings fixed: 1. 'upgrade --state' is now strictly read-only: supplying a package alongside --state is rejected (exit 2), and the branch returns immediately after the probe. 2. A failed upgrader.getState probe exits non-zero instead of 0. 3. 'nanddump' no longer leaves the root telnet shell enabled: it reads the current InnerServer.Telnet state first, enables telnet only when it was off, and restores it in a finally block -- verified live on the GK7205V510 twin (state off -> dump -> state off again, confirmed via a separate DHIP query). 4. A 'Last login: ...' success banner is no longer mistaken for a repeated login prompt (line-anchored prompt check), and a failed login is detected even when the retry prompt arrives while the client is still waiting for the password prompt. 5. Telnet framing is now a stateful parser: IAC sequences that straddle socket reads are held back instead of leaking into command output, subnegotiation (SB..IAC SE) frames are consumed whole, and escaped 0xff passes through as data. 6. parse_proc_mtd() no longer drops entries by erasesize; it tags UBI volume aliases and skips them only in the automatic dump. An explicit --parts index selects any partition, UBI-mapped or otherwise; a raw partition with an unusual erase size is kept. 7. The dump path streams: payload text goes through an incremental per-line strict-decoding sink straight to disk, so host memory is bounded by the base64 line length, not the partition size (previously several full copies of each partition accumulated). 8. Partition dumps stream into <file>.part and are renamed into place only after the command exit code and the exact byte count check out -- a failed rerun can never truncate a previously complete backup (regression-tested). Adds tests/test_nanddump.py: marker/rc framing across chunk boundaries, negotiation straddle and SB frames, corrupted-payload rejection, /proc/mtd parsing, and an end-to-end fake busybox telnet server exercising login (including the Last login banner and wrong password), byte-exact dumps, atomic replacement and UBI selection. 42 tests pass. Live re-validation on the SD-2N-4G twin (QEMU, stock vendor firmware) with the rewritten code: 'dhip ... nanddump --parts 1' recovered defcfg byte-exact (262144/262144 B vs the pristine flash slice) and restored the telnet state afterwards.
|
All 8 findings addressed in ba66ea4 ( Bugs
High-level recommendations
A full-flash dump with the rewritten code (~128 MiB, all 10 raw partitions) is running against the QEMU twin right now; the byte-exact comparison against the pristine flash image will be posted here before merge. |
|
Full-flash dump with the rewritten code: complete. All 10 raw partitions (~128 MiB, 2666 s over the telnet channel ≈ 49 KiB/s) dumped from the QEMU twin of the SD-2N-4G (stock vendor firmware), every partition at its exact declared size, no strict-decode failures. Byte-exact comparison against the pristine vendor flash image the twin was booted from: The That is the expected best-case result for a live backup: the dump reproduces the device state faithfully, including runtime changes. Merging now — and will monitor the coupler README PR (OpenIPC/coupler#72) which documents this flow for end users. |
The CI matrix runs 'python -m unittest discover' with no pytest installed; the nanddump tests were written against pytest and failed import on every matrix job. Mechanically converted (assertRaises, setUp/tearDown lifecycle, tmpdirs cleaned in finally); 42/42 green under both unittest and pytest.
actions/setup-python cannot install 3.9 on ubuntu-latest anymore (Ubuntu 26.04 has no 3.9 build; 3.9 is EOL since 2025-10), so every current PR fails on that matrix row before running a single test. Remove the 3.9 row; 3.10-3.13 keep running the suite. pyproject still declares >=3.9 and the code remains 3.9-compatible (future annotations, verified syntax) -- it just cannot be CI-tested on the current runner image.
"test (3.9)" is a required status check in branch protection, so removing the row blocks the merge forever (the check can never report). Keep the row and pin it to the last runner image with a published 3.9 build (actions/python-versions 3.9.25 ships 22.04/24.04, not 26.04); 3.10-3.13 stay on ubuntu-latest. CI coverage of 3.9 is restored instead of abandoned.
With a matrix.include that adds a second key (runner), the display
name auto-expands to 'test (3.9, ubuntu-24.04)' and the required
status check 'test (3.9)' is never satisfied. Set the job name
explicitly to 'test (${{ matrix.python-version }})' so all rows
report under the exact names branch protection expects.
What
Two new CLI subcommands for the "hunter"-family devices (Zenointel etc.):
nanddump-- full NAND backup with no solderingThe README of OpenIPC/coupler tells Zenointel users to "back up the full NAND"
before flashing, but the stock camera has no UART pins exposed, no tftp/nc/wget
applets, and telnet disabled by default -- an end user has no realistic way
to do that today. This adds one:
What it does:
InnerServer.Telnet.Enable=true,the vendor's own switch -- the
telnetsubcommand already wraps it)./dev/mtdNropartition with
dd | base64. This applet pair is what the minimal stockbusybox actually has (no gzip, md5sum, tftp, nc or wget) and the base64
armoring makes the stream immune to telnet/pty byte mangling.
b64decode(validate=True): any corruptionraises) and verifies every file against the size declared in
/proc/mtd.the dump covers the contiguous raw vendor map.
--partsselects indices,--no-enable-telnetskips the DHIP step if theshell is already up.
upgrade-- flash a package over DHIP from the CLIThin wrapper over the already-validated
DahuaClient.upgrade_firmware()(
upgrader.prepare-> chunkedappendData->execute), with upload progressand a read-only
--stateprobe. Refuses to flash without--confirm.Validation
On a Zenointel SD-2N-4G twin (QEMU emulation of the stock vendor NAND):
cat /proc/mtdover the shell returns the 10 raw partitions;defcfgpartition (256 KiB) recovered byte-exact versus thecorresponding slice of the pristine flash image the twin was booted from;
result will be posted in this PR before merge.
Notes
upgradestate machine andappendData {"length": N}behavior areunchanged -- this PR only surfaces the existing API in the CLI.