Repository navigation
cv6xx: parse composite image headers dynamically - #130
Conversation
PR Summary by QodoParse CV6xx composite image layouts dynamically
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
694ff5c to
3431b8d
Compare
widgetii
left a comment
There was a problem hiding this comment.
Thanks. This fixes a real bug, I checked it against every published image in the family and ran it on a CV608 board, and it's good to merge. I've rebased the branch onto master, which resolves the conflict with #165.
Parser. I compared the old and new parsers on every published boot image of this family:
| Image | Result |
|---|---|
boot-hi3516cv608-nor.bin and the five boot-hi3516cv610-{00s,10b,20g,20s}-nor.bin |
byte-identical GSL (22528 B), DDR table (14336 B) and U-Boot (168448 B) |
boot-hi3519dv500-dmebpro-nor.bin |
master: Invalid GSL magic: expected 0x4BB4D22D, got 0xAAAAAAAA. This PR: GSL 56320 B, DDR 13312 B, U-Boot 216064 B |
So nothing changes for images that already worked, and master really can't use the published dv500 dmebpro image today. (dmeb isn't published, so I couldn't check it.) The validation is sound: headers must be aligned, the scans are bounded, a board mapping that points at a missing table is rejected, and two valid layouts in one file is an error rather than a guess.
GSL load address 0x04021A00, on hardware. I ran defib burn -c hi3516cv608 --power-cycle twice from RAM on a Hi3516CV608 (DDR2 64 MB), through a vectis UART bridge. Both runs printed DDR size: 0x00000040 and reached the U-Boot console from the upload. Neither showed the flash-fallback lines (The table is incorrect / System startup), so the uploaded U-Boot ran, not the one in flash. I haven't tested a CV610 or a dv500 board.
Rebase. The only conflict was in tests/test_protocol_cv6xx.py: #165 appended a test class, and this PR appended the GSL_LOAD_ADDR assertion to test_send_firmware. I kept both. On the rebased branch: pytest 1097 passed / 3 skipped, fuzz 16 passed, ruff and mypy clean, node --test 95 passed.
Nits, not blocking, fine as follow-ups:
build_ddr_table()reads the DDR header'sstructure_lengthfromfile_dataagain after the parser has already validated it. Carrying the first table's offset inCV6xxBootPartswould keep the two from drifting.MAX_GSL_HEADER_OFFSET,MAX_SECTION_GAPandMAX_DDR_TABLESare reasonable bounds. A short comment saying where each comes from would help whoever meets the next image-tool generation.
… come from (#166) Follow-up to #130, covering the two nits from its review. ## Changes - **`CV6xxBootParts.first_table_offset` replaces `offset_32`.** `build_ddr_table()` used to read the DDR header's `structure_length` from `file_data` again to rebuild where table 0 starts, even though `parse_cv6xx_boot()` had already validated that. The parser now keeps the validated offset, so the two can't drift. `offset_32` had no other users; the browser parser already kept `tableOffset`. - **The parser's bounds are documented** with the layouts they were set against, measured on the published images: | Image | GSL header | GSL → DDR header | Board map | |---|---|---|---| | `boot-hi3516cv608-nor.bin`, `boot-hi3516cv610-*-nor.bin` | `0x800` | `0x400` | 8 bytes, 1 table | | `boot-hi3519dv500-dmebpro-nor.bin` | `0x1200` | `0x100` | 8 bytes, 1 table | `MAX_GSL_HEADER_OFFSET` (64 KiB) and `MAX_SECTION_GAP` (4 KiB) leave room past both layouts. `MAX_DDR_TABLES` = 8 because the board map has 8 entries, so a ninth table could never be selected. The browser constants point at the Python comment. ## Verified - **No behaviour change:** GSL, U-Boot and `build_ddr_table()` output are byte-identical to master for all six published images and board IDs 0–9. - `pytest tests/ --ignore=tests/fuzz`: 1097 passed, 3 skipped. Fuzz: 16 passed. - ruff and mypy are clean; `node --test`: 95 passed.
Summary
0x800offset0x800and0x1200layoutsCP_STEP1_ADDR(0x04021A00)Some HI3519DV500 image-tool output places the valid GSL header at
0x1200; the previous fixed-offset parser read padding at0x800and failed withexpected magic ... got 0xAAAAAAAA. Candidate scanning is bounded and requires aligned headers, valid structure and payload lengths, a bounded DDR table count and board map, in-range table data, and a valid U-Boot image immediately after the declared tables.Validation
uv run pytest tests/ -x -q --ignore=tests/fuzz: 731 passed, 2 skippeduv run pytest tests/fuzz/ -x -q --hypothesis-seed=0: 16 passeduv run ruff check src/ tests/uv run mypy src/defib/ --ignore-missing-imports0x800HI3516CV610 and0x1200HI3519DV500 composite images without embedding either image in the test suite