#!/bin/sh # test-osboot.sh -- take the LANCE over, then hand it back with `osboot`. # # sudo ./test-osboot.sh [iface] [host] # # The point of this script is that it contains no sleep. The payload # broadcasts an announce frame (ethertype 0x88B6, opcode 0xFF, magic "LANC") # as soon as its RX ring is armed, so the host starts listening first and acts # the moment the payload is really up. Loading the COFF over rdebug is slow # (thousands of word pokes), and a fixed sleep either wastes seconds or is too # short -- waiting for the announce is exact. # # Steps: # 1. listen for the announce (background) # 2. load dwt/loader/hostload.py, which pokes and jumps into the payload # 3. when the announce arrives, read stats and send `osboot` # 4. wait for the terminal's rdebug port to come back # # `osboot` jumps to the OS cold start at 0x3F5788C0, which STOPs the LANCE and # re-programs the board window before restarting the OS. Measured: 40 s twice. IFACE=${1:-vt1200} HOST=${2:-100.103.100.103} HERE=$(cd "$(dirname "$0")" && pwd) ROOT=$(cd "$HERE/../.." && pwd) LOG=${LOG:-/tmp/vt1200-osboot.log} if [ "$(id -u)" != "0" ]; then echo "run as root: raw sockets and rdebug need it" >&2 exit 2 fi echo "[*] listening for the announce on $IFACE" python3 "$HERE/vtcmd.py" wait --iface "$IFACE" --wait-timeout 240 & LISTENER=$! echo "[*] loading $(basename "$HERE")/build/lance_cmd.coff onto $HOST" python3 "$ROOT/dwt/loader/hostload.py" --host "$HOST" \ --coff "$HERE/build/lance_cmd.coff" --real --no-screenshot \ > "$LOG" 2>&1 & if ! wait "$LISTENER"; then echo "[!] no announce: the payload did not start (see $LOG)" >&2 exit 1 fi echo "[*] payload is up, stats:" python3 "$HERE/vtcmd.py" stats --iface "$IFACE" || true echo "[*] handing back with osboot" python3 "$HERE/vtcmd.py" osboot --iface "$IFACE" || exit 1 echo "[*] waiting for rdebug :771 on $HOST" T0=$(date +%s) i=0 while [ $i -lt 36 ]; do sleep 5 i=$((i + 1)) if timeout 2 sh -c "/dev/null; then echo "[+] back after $(( $(date +%s) - T0 ))s" exit 0 fi done echo "[!] did not come back within 180 s" >&2 exit 1