diff --git a/toolkit/build-image.sh b/toolkit/build-image.sh new file mode 100755 index 0000000..e6c1d9e --- /dev/null +++ b/toolkit/build-image.sh @@ -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" diff --git a/toolkit/extract-src.sh b/toolkit/extract-src.sh new file mode 100755 index 0000000..dbc8bd1 --- /dev/null +++ b/toolkit/extract-src.sh @@ -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 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 diff --git a/toolkit/layout.conf b/toolkit/layout.conf new file mode 100644 index 0000000..d871f4a --- /dev/null +++ b/toolkit/layout.conf @@ -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 diff --git a/toolkit/repack-fs.sh b/toolkit/repack-fs.sh new file mode 100755 index 0000000..a473878 --- /dev/null +++ b/toolkit/repack-fs.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Usage: repack-fs.sh [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" ] diff --git a/toolkit/split.sh b/toolkit/split.sh new file mode 100755 index 0000000..7232004 --- /dev/null +++ b/toolkit/split.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Usage: split.sh [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."