Repository navigation
Expand file tree
/
Copy pathdeploy-kernel.sh
More file actions
57 lines (51 loc) · 2.35 KB
/
Copy pathdeploy-kernel.sh
File metadata and controls
57 lines (51 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# deploy-kernel.sh — push a freshly built RV2 kernel to the running board and
# boot it once via nextboot (auto-fallback to /boot/kernel on any failure).
#
# Runs from the Windows side (Git Bash). Routes through Windows because only the
# Windows key "claude-buildvm" is authorized on both the build VM and the board.
#
# The board's if_smte RX path currently wedges under sustained load (~3 MB), so
# the kernel is gzip'd and split into 1 MB chunks, each pushed with md5 retry;
# a wedge costs only a single chunk, which reconnects and retries. The full
# image is reassembled and md5-verified on the board before it is staged.
#
# Usage: deploy-kernel.sh [board-ip] (default 192.168.1.161)
set -e
BOARD_IP="${1:-192.168.1.161}"
VM=root@172.23.160.242
BOARD="root@${BOARD_IP}"
KEY=/c/FreeBSD-VM/ssh/buildvm_ed25519
SSHO="-i $KEY -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=15"
OBJ=/usr/obj/usr/src/riscv.riscv64/sys/RV2/kernel
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
echo "[1/5] pull kernel from VM"
scp $SSHO "$VM:$OBJ" "$WORK/kernel" >/dev/null
WMD5=$(md5sum "$WORK/kernel" | cut -d' ' -f1)
echo " md5 $WMD5 size $(stat -c%s "$WORK/kernel")"
echo "[2/5] compress + chunk"
gzip -9 -c "$WORK/kernel" > "$WORK/k.gz"
( cd "$WORK" && split -b 1000000 k.gz part_ )
ssh $SSHO $BOARD 'rm -f /tmp/k.gz.part_* /tmp/kernel.gz /tmp/kernel; mkdir -p /boot/kernel.test'
echo "[3/5] push chunks (retry each until md5 matches)"
for p in "$WORK"/part_*; do
n=$(basename "$p"); want=$(md5sum "$p" | cut -d' ' -f1)
for try in 1 2 3 4 5 6 7 8; do
scp $SSHO "$p" "$BOARD:/tmp/k.gz.$n" >/dev/null 2>&1 || true
got=$(ssh $SSHO $BOARD "md5 -q /tmp/k.gz.$n 2>/dev/null" 2>/dev/null | tr -d '\r\n ')
[ "$got" = "$want" ] && break
[ "$try" = 8 ] && { echo " FAILED on $n"; exit 1; }
done
echo " $n ok"
done
echo "[4/5] reassemble + verify on board"
ssh $SSHO $BOARD "
cat /tmp/k.gz.part_* > /tmp/kernel.gz && gunzip -f /tmp/kernel.gz
[ \"\$(md5 -q /tmp/kernel)\" = \"$WMD5\" ] || { echo MD5_MISMATCH; exit 1; }
cp /tmp/kernel /boot/kernel.test/kernel && rm -f /tmp/k.gz.part_* /tmp/kernel
echo STAGED"
echo "[5/5] nextboot + reboot (one-shot; falls back to /boot/kernel on failure)"
ssh $SSHO $BOARD 'nextboot -k kernel.test'
ssh $SSHO $BOARD 'reboot' >/dev/null 2>&1 &
echo "done — watch serial console for boot result"