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:
No files matched your search
Executable
+25
@@ -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"
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# (Re)create src/app and src/rootfs = the stock APP / ROOTFS squashfs from YOUR dump
|
||||||
|
# (parts/stock, made by ./split.sh). They are inputs to the variants, never committed.
|
||||||
|
set -e
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
[ -f "$HERE/parts/stock/app.bin" ] || { echo "no parts/stock: run ./split.sh <your_dump.bin> first"; exit 1; }
|
||||||
|
for p in app rootfs; do
|
||||||
|
if [ ! -d "$HERE/src/$p" ] || [ "$1" = -f ]; then
|
||||||
|
rm -rf "$HERE/src/$p"
|
||||||
|
unsquashfs -q -d "$HERE/src/$p" "$HERE/parts/stock/$p.bin" >/dev/null
|
||||||
|
echo "[extract-src] src/$p from parts/stock/$p.bin"
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Anyka AK3918AV130 — 8 MiB SPI-NOR map (from stock U-Boot mtdparts)
|
||||||
|
# Chip: ZB25VQ64, 8 MiB, 4 KiB erase. NOTE: stock mtdparts claims APP=13312K,
|
||||||
|
# but the chip is only 8 MiB, so APP is physically clamped to 5120K (end of flash).
|
||||||
|
# name offset size kind file
|
||||||
|
UBOOT 0x000000 0x032000 raw uboot.bin
|
||||||
|
ENV 0x032000 0x001000 raw env.bin
|
||||||
|
ENVBK 0x033000 0x001000 raw envbk.bin
|
||||||
|
DTB 0x034000 0x010000 raw dtb.bin
|
||||||
|
KERNEL 0x044000 0x180000 raw kernel.bin
|
||||||
|
ROOTFS 0x1c4000 0x0fc000 fs rootfs.bin
|
||||||
|
CONFIG 0x2c0000 0x040000 fs config.bin
|
||||||
|
APP 0x300000 0x500000 fs app.bin
|
||||||
Executable
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Usage: repack-fs.sh <src_tree_dir> <out_part_file> <slot_bytes> [squashfs|jffs2]
|
||||||
|
set -e
|
||||||
|
SRC=${1:?src tree}; OUT=${2:?out file}; SLOT=${3:?slot bytes}; FS=${4:-squashfs}
|
||||||
|
case "$FS" in
|
||||||
|
squashfs)
|
||||||
|
mksquashfs "$SRC" "$OUT" -comp xz -b 131072 -all-root -noappend -no-progress >/dev/null ;;
|
||||||
|
jffs2)
|
||||||
|
mkfs.jffs2 -r "$SRC" -e 0x1000 -l -p --squash-uids -o "$OUT" ;;
|
||||||
|
*) echo "unknown fs: $FS"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
sz=$(stat -c %s "$OUT")
|
||||||
|
printf "%s: %s -> %d bytes (%dK) / slot %dK %s\n" "$FS" "$SRC" "$sz" "$((sz/1024))" "$((SLOT/1024))" \
|
||||||
|
"$( [ "$sz" -le "$SLOT" ] && echo OK || echo 'TOO_BIG!!' )"
|
||||||
|
[ "$sz" -le "$SLOT" ]
|
||||||
Executable
+15
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Usage: split.sh <full_image.bin> [dest_parts_dir]
|
||||||
|
set -e
|
||||||
|
IMG=${1:?need a full flash image}
|
||||||
|
DEST=${2:-$(dirname "$0")/parts/stock}
|
||||||
|
LAYOUT="$(dirname "$0")/layout.conf"
|
||||||
|
mkdir -p "$DEST"
|
||||||
|
sz=$(stat -c %s "$IMG")
|
||||||
|
echo "splitting $IMG ($sz bytes) -> $DEST"
|
||||||
|
grep -vE '^\s*#|^\s*$' "$LAYOUT" | while read name off size kind file; do
|
||||||
|
o=$((off)); s=$((size))
|
||||||
|
dd if="$IMG" of="$DEST/$file" bs=4096 skip=$((o/4096)) count=$((s/4096)) status=none
|
||||||
|
printf " %-8s @ %#09x %6dK -> %s\n" "$name" "$o" "$((s/1024))" "$file"
|
||||||
|
done
|
||||||
|
echo "done."
|
||||||
Reference in New Issue
Block a user