Fix restore: write boot partition last, use mtdparts offsets#58
Merged
Fix restore: write boot partition last, use mtdparts offsets#58
Conversation
During restore, setenv commands (mtdparts, ipaddr, serverip) cause U-Boot to save env to NAND within the boot area at offset 0x40000, corrupting the boot partition. Fix: write boot partition last so the final nand write overwrites any env corruption. Also fix partition offset calculation: use pre-computed offsets from the original sequential partition order instead of accumulating from data sizes (which breaks when partitions are reordered or UBI images are smaller than their NAND partitions). Tested end-to-end on hi3516av200: full 7-partition NAND restore including 5 UBI volumes. Cold boot succeeds, all UBIFS volumes mount cleanly, vendor firmware runs (Sony IMX385 sensor, RTSP, cloud). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
Two bugs in
defib restorefor NAND:Boot partition corruption:
setenvcommands during restore (mtdparts, ipaddr, serverip) cause U-Boot to save env to NAND at offset 0x40000 within the boot area, corrupting mtd0. Fix: write boot partition last so the finalnand writeoverwrites any env corruption.Wrong partition offsets: offsets were accumulated from image data sizes, which breaks when partitions are reordered or UBI images are smaller than their NAND partitions. Fix: pre-compute offsets from the original sequential partition order.
End-to-end test result
Full 7-partition NAND restore on hi3516av200 (128MB SPI NAND):
Cold boot: all UBIFS volumes mount, vendor firmware runs (Sony IMX385 sensor, RTSP server, cloud login). Zero errors.
Test plan
🤖 Generated with Claude Code