Skip to content

Pad U-Boot to boot-partition size on install (#73)#74

Merged
widgetii merged 1 commit intomasterfrom
uboot-pad-on-write
May 6, 2026
Merged

Pad U-Boot to boot-partition size on install (#73)#74
widgetii merged 1 commit intomasterfrom
uboot-pad-on-write

Conversation

@widgetii
Copy link
Copy Markdown
Member

@widgetii widgetii commented May 5, 2026

Summary

  • OpenIPC removed the historical 1 MiB padding from published U-Boot assets (issue Pad u-boot-{hi3516av200,hi3519v101}-universal.bin to flash erase-block size before writing #73). For example u-boot-hi3516av200-universal.bin went from 1,048,576 B (1 MiB padded) → 199,276 B (raw).
  • Add pad_to_size() in firmware.py and call it at the install read site so the U-Boot region is written with 0xFF trailing bytes — matches the historical 1 MiB on NAND and 256 KiB on NOR (clean partition boundaries either way).
  • Agent flash path (LZMA SPL boundary detection) is unaffected. Restore path doesn't write U-Boot to flash, only loads it to RAM via the bootrom — neither needs to change.

Closes #73

Test plan

  • uv run pytest tests/test_firmware.py -x -v — 16/16 pass (5 new TestPadToSize cases)
  • uv run pytest tests/ -x -q --ignore=tests/fuzz — 407 passed, 2 skipped
  • uv run ruff check src/defib/firmware.py src/defib/cli/app.py tests/test_firmware.py — clean
  • uv run mypy src/defib/firmware.py src/defib/cli/app.py --ignore-missing-imports — clean
  • make -C agent test HOST_CC=gcc — 5406/5406
  • After OpenIPC ships unpadded asset: re-run defib install -c hi3516av200 … on av200 hardware and confirm the boot partition still flashes clean.

🤖 Generated with Claude Code

OpenIPC dropped the historical 1 MiB padding from published U-Boot
assets — for example u-boot-hi3516av200-universal.bin went from
1,048,576 B (1 MiB padded) to 199,276 B (raw). Consumers that flash
to a fixed-size partition need to pad locally so trailing flash bytes
are erased (0xFF) instead of left at whatever was previously written.

Add pad_to_size() in firmware.py and call it at the install read
site. Padding to the boot partition size matches the historical 1 MiB
on NAND and gives 256 KiB on NOR — both clean partition boundaries.

The agent flash path (LZMA SPL boundary detection) is unaffected,
and the restore path doesn't write U-Boot to flash, only loads it
into RAM via the bootrom — so neither needs to change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@widgetii
Copy link
Copy Markdown
Member Author

widgetii commented May 6, 2026

Hardware verification — av200 board (hi3516av200, NAND)

Tested with the cached u-boot truncated to 199,276 B to simulate the new (unpadded) OpenIPC producer asset:

$ ls -l ~/.cache/defib/firmware/u-boot-hi3516av200-universal.bin
-rw-r--r-- 1 root root 199276 ...

defib burn (full bootrom upload pipeline, smallest input):

SPL boundary detected (LZMA) at 0x6800 (26624 bytes); profile default was 0x4F00 (20224 bytes)
  Sending DDR step  100%
  Sending SPL       100%   ~2s
  Sending U-Boot    100%  ~18s
Done! (27927ms)

defib agent upload (uses same truncated u-boot as SPL):

Agent: agent-hi3519v101.bin (15812 bytes)
SPL: full U-Boot (199276 bytes — boundary auto-detected)
  Boot mode entered → DDR step → SPL → Agent → READY
Agent ready!
  RAM: 0x80000000
  Flash: 131072KB

defib agent info:

JEDEC ID:    00c212    (Macronix MX35LF1GE4AB SPI NAND)
Flash size:  131072 KB
RAM base:    0x80000000
Sector size: 128 KB
Agent ver:   2
Capabilities: flash_stream, sector_bitmap, page_skip, set_baud, reboot, selfupdate, scan

The bootrom upload + agent stages handle the new (smaller) producer asset cleanly. pad_to_size itself is unit-tested; only the tftp_and_flash step in install exercises it on hardware, but that step writes a fixed-size buffer to a fixed-size partition — the only behavioral difference vs. the old producer is 0xFF vs. 0x00 trailing bytes, and 0xFF is the natural NAND erased state, so it's actually more correct than before.

@widgetii widgetii merged commit c58f01a into master May 6, 2026
13 checks passed
@widgetii widgetii deleted the uboot-pad-on-write branch May 6, 2026 06:46
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.

Pad u-boot-{hi3516av200,hi3519v101}-universal.bin to flash erase-block size before writing

1 participant