Skip to content

Add UBI/UBIFS-aware backup and restore for NAND cameras#142

Merged
widgetii merged 3 commits intomasterfrom
ubi-aware-backup
Apr 22, 2026
Merged

Add UBI/UBIFS-aware backup and restore for NAND cameras#142
widgetii merged 3 commits intomasterfrom
ubi-aware-backup

Conversation

@widgetii
Copy link
Copy Markdown
Member

Summary

Closes #141

  • Detect UBI devices attached to MTD partitions via /sys/class/ubi/ sysfs
  • Backup UBI volumes (/dev/ubiN_V) instead of raw MTD for UBI-managed partitions, storing actual volume data (no UBI headers)
  • Add dump_type, ubi_device, and ubi_volumes array to YAML output with per-volume vol_id, vol_name, data_bytes, and sha1
  • Restore UBI partitions using kernel ioctls (UBI_IOCDET, UBI_IOCATT, UBI_IOCMKVOL, UBI_IOCVOLUP) — no dependency on userspace UBI tools
  • Unmount UBIFS filesystems during restore
  • Backward compatible: non-UBI partitions (NOR, raw NAND) are handled identically to before

YAML output example (HI3516AV200)

partitions:
  - name: boot
    size: 0x100000
    sha1: ddc7f851
  - name: rootfs
    size: 0x800000
    dump_type: ubifs
    ubi_device: 0
    ubi_volumes:
      - vol_id: 0
        vol_name: rootfs
        data_bytes: 0x4f7000
        sha1: 932ea10b

Test plan

  • Cross-compiled for ARM (static, arm-linux-gnueabihf-gcc)
  • Tested on HI3516AV200 with 128MB SPI NAND, 5 UBI devices (ubi0, ubi3-6)
  • YAML output correctly shows dump_type: ubifs and ubi_volumes for all UBI partitions
  • Raw partitions (boot, kernel) unchanged in output
  • Backup produces correct file: 7 data blocks, all sizes match YAML, SHA1 verified
  • Backup file fully consumed (115MB, no truncation/padding)
  • Restore path not yet tested on hardware (requires expendable device)

🤖 Generated with Claude Code

widgetii and others added 3 commits April 22, 2026 09:47
On NAND cameras with UBI/UBIFS, raw MTD dumps include physical block
mappings that are chip-specific and cannot be safely restored. This adds
UBI volume-level backup and restore using kernel sysfs and ioctls.

Detection: scan /sys/class/ubi/ to find UBI devices attached to MTD
partitions and enumerate their volumes with data_bytes and names.

Backup: read UBI volumes from /dev/ubiN_V instead of raw /dev/mtdblockN
for UBI-managed partitions. Each volume becomes a separate data block.

YAML output: add dump_type, ubi_device, and ubi_volumes array with
per-volume vol_id, vol_name, data_bytes, and sha1.

Restore: UBI-aware path using ioctls (UBI_IOCDET, UBI_IOCATT,
UBI_IOCMKVOL, UBI_IOCVOLUP) to detach, erase, reattach, create
volumes, and write data. Raw MTD partitions use existing path.

Tested on HI3516AV200 with 128MB SPI NAND and 5 UBI volumes.

Closes #141

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cross-compile for both ARM and MIPS targets on PRs to catch build
errors before merge. Uses the same OpenIPC toolchains as the release
workflows but skips packaging, uploads, and notifications.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The OpenIPC ARM musl toolchain has a broken <mtd/ubi-user.h> where
__packed is not defined, causing build failures. Replace the include
with minimal inlined struct and ioctl definitions guarded by
ifndef UBI_IOC_MAGIC.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii widgetii merged commit 573918c into master Apr 22, 2026
2 checks passed
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.

Add UBI/UBIFS-aware backup for NAND cameras

1 participant