aboutsummaryrefslogtreecommitdiff
path: root/tools/update_usb.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/update_usb.sh')
-rwxr-xr-xtools/update_usb.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/tools/update_usb.sh b/tools/update_usb.sh
new file mode 100755
index 0000000..6d49e87
--- /dev/null
+++ b/tools/update_usb.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Replace the OpenWrt initramfs ITB on the CKB01 boot USB stick (FreeBSD host).
+#
+# su -c 'sh /ROM/Projects/ckb01/tools/update_usb.sh'
+#
+# The stick must be the 7.5G "General UDisk" with
+# da1s1: MBR fat32lba 512M (CKB01BOOT)
+# da1s2: MBR linux-data 1.5G (ckb01-rootfs)
+set -eu
+
+IMG=/ROM/Projects/ckb01/out/ckb01-nss-wifi-hb-initramfs.itb
+DEV=/dev/da1s1
+DISK=/dev/da1
+MNT=/mnt/usb
+
+if [ "$(id -u)" != 0 ]; then
+ echo "root required: su -c 'sh $0'" >&2
+ exit 1
+fi
+[ -f "$IMG" ] || { echo "missing $IMG" >&2; exit 1; }
+[ -c "$DEV" ] || { echo "missing $DEV (USB not plugged in?)" >&2; exit 1; }
+
+# --- safety: make sure da1 really is the CKB01 stick -----------------------
+geom=$(gpart show da1 2>/dev/null || true)
+case "$geom" in
+*fat32lba*) ;;
+*) echo "da1 does not look like the CKB01 stick:" >&2; echo "$geom" >&2; exit 1 ;;
+esac
+size=$(diskinfo "$DISK" | awk '{print $3}')
+if [ "$size" != "8053063680" ]; then
+ echo "da1 size is $size, expected 8053063680 (7.5G General UDisk)" >&2
+ exit 1
+fi
+
+# --- replace the ITB -------------------------------------------------------
+mkdir -p "$MNT"
+mount -t msdosfs "$DEV" "$MNT"
+trap 'umount "$MNT" 2>/dev/null || true' EXIT
+
+echo "=== before ==="
+ls -l "$MNT"
+
+cp "$IMG" "$MNT/uImage-initramfs.itb"
+sync
+
+echo "=== after ==="
+ls -l "$MNT"
+echo "--- sha256 (USB) ---"
+sha256 "$MNT/uImage-initramfs.itb"
+echo "--- sha256 (source) ---"
+sha256 "$IMG"
+
+umount "$MNT"
+trap - EXIT
+echo "done: USB updated"