Add UBI-aware NAND writes for install and restore#62
Merged
Conversation
Raw UBI images written via `nand write` corrupt UBIFS because bad block skipping shifts data, breaking UBI's physical-to-logical block mapping. This adds a UBI image parser (`defib.ubi`) that extracts UBIFS volume data from raw UBI images (UBI# magic), then writes via `ubi part` / `ubi create` / `ubi write` which lets U-Boot's UBI subsystem handle bad block mapping. Changes: - New `src/defib/ubi.py`: parse UBI EC/VID headers, extract UBIFS by volume ID - `defib install --nand`: detect raw UBI rootfs, extract UBIFS, write via `ubi write` instead of `nand write`; detect download command mode (XHEAD/XCMD) so install works on chips with CONFIG_START_MAGIC (e.g. hi3516av200); page-align NAND write sizes to 2KB - `defib restore`: auto-detect raw UBI images in partition files and convert to UBIFS before UBI-aware write; create UBI volumes with full partition space (not just image size) so UBIFS has room for runtime writes - 8 new tests for UBI extraction Tested on hi3516av200 (128MB SPI NAND, MX35LF1GE4AB): - UBI attaches cleanly: 944 PEBs, 0 bad, 0 corrupted - UBIFS mounts without errors: 111 MiB usable (vs 10 MiB before) - Linux boots fully, services start, no "space left" errors Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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
rootfs.ubi) written vianand writecorrupt UBIFS because bad block skipping shifts data, breaking UBI's physical-to-logical block mappingdefib.ubimodule extracts UBIFS volume data from raw UBI images, then writes viaubi part/ubi create/ubi writewhich handles bad blocks correctlydefib install --nandnow detects download command mode (XHEAD/XCMD) for chips with CONFIG_START_MAGIC (hi3516av200), page-aligns NAND writes, and uses UBI-aware rootfs writesdefib restoreauto-converts raw UBI images to UBIFS and creates UBI volumes with full partition space (not just image size)Test plan
Before (raw
nand write):After (
ubi write):🤖 Generated with Claude Code