Toolkit: split and reassemble flash images from a dump

split.sh carves a dump into partitions using a layout file, build-image.sh
reassembles them (reproduces the stock dump byte-for-byte), repack-fs.sh
rebuilds squashfs/jffs2 partitions, extract-src.sh unpacks the stock
APP/rootfs from the user's own dump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 22:01:43 +01:00
co-authored by Claude Opus 5.5
parent 497c0758cc
commit e8cc206d23
5 changed files with 80 additions and 0 deletions

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
# Usage: build-image.sh [parts_dir] [out_image]
# Assembles an 8 MiB image from the parts in parts_dir (default parts/stock).
set -e
HERE="$(cd "$(dirname "$0")" && pwd)"
PARTS=${1:-$HERE/parts/stock}
OUT=${2:-$HERE/out/camera_flash.bin}
LAYOUT="${LAYOUT:-$HERE/layout.conf}"
FLASH=$((8*1024*1024))
mkdir -p "$(dirname "$OUT")"
# start from a fully-erased (0xFF) 8 MiB image
tr '\0' '\377' < /dev/zero | dd of="$OUT" bs=1 count=$FLASH status=none
echo "assembling -> $OUT (8 MiB, pre-erased 0xFF)"
grep -vE '^\s*#|^\s*$' "$LAYOUT" | while read name off size kind file; do
o=$((off)); s=$((size)); src="$PARTS/$file"
[ -f "$src" ] || { echo " !! missing part: $src"; exit 1; }
fsz=$(stat -c %s "$src")
if [ "$fsz" -gt "$s" ]; then
echo " !! $name too big: $fsz > slot $s ($((s/1024))K)"; exit 1
fi
dd if="$src" of="$OUT" bs=4096 seek=$((o/4096)) conv=notrunc status=none
printf " %-8s @ %#09x %6dK slot %6dK used <- %s\n" "$name" "$o" "$((s/1024))" "$((fsz/1024))" "$file"
done
echo "md5: $(md5sum "$OUT" | cut -d' ' -f1)"
echo "done: $OUT"