Files
xteink-web-emulator/scripts/mksd.sh
T
2026-07-19 19:23:51 -04:00

25 lines
859 B
Bash
Executable File

#!/usr/bin/env bash
# Build a FAT32 SD-card image from a local directory — the local-disk backing
# for the emulated SD. QEMU's block layer is the interface: this same image is
# swapped for a browser-supplied blockdev (File/OPFS) in the WASM build.
#
# scripts/mksd.sh [src-dir] [out-img] (SIZE_MB env overrides size)
set -euo pipefail
SRC="${1:-../crosspoint-reader-lua/sdcard}"
OUT="${2:-sd.img}"
SIZE_MB="${SIZE_MB:-64}"
[ -d "$SRC" ] || { echo "no such dir: $SRC" >&2; exit 1; }
OUT_ABS="$(realpath -m "$OUT")"
rm -f "$OUT_ABS"
truncate -s "${SIZE_MB}M" "$OUT_ABS"
mkfs.vfat -F 32 -n XTEINK "$OUT_ABS" >/dev/null
# mcopy the tree in (recursive, no per-file prompts).
( cd "$SRC" && for e in *; do [ -e "$e" ] && mcopy -i "$OUT_ABS" -s -Q -o "$e" ::; done )
echo "wrote $OUT (${SIZE_MB}M FAT32) from $SRC"
mdir -i "$OUT_ABS" :: | sed 's/^/ /'