#!/usr/bin/env bash # Build the current gateware over N nextpnr seeds and flash the best result. # # The capture domain (54 MHz) is routing-dominated and only closes on a minority # of seeds, so a sweep is mandatory — see CLAUDE.md. synth.py ranks the seeds by # capture_clk fmax and reports the winner; this flashes that one. # # ./scripts/build-flash.sh # 8 seeds (default), build + flash # ./scripts/build-flash.sh 12 # 12 seeds # ./scripts/build-flash.sh 8 --no-flash # build only, don't touch the board # # The socket-3 UDP bring-up test identity is set from these env vars (override # to match your LAN before running): # UDP_SRC_IP UDP_SUBNET UDP_GATEWAY UDP_DST_IP UDP_SRC_PORT UDP_DST_PORT UDP_SOCKET set -euo pipefail cd "$(dirname "$0")/.." SEEDS="${1:-8}" NOFLASH="${2:-}" export UDP_SRC_IP="${UDP_SRC_IP:-192.168.2.99}" export UDP_SUBNET="${UDP_SUBNET:-255.255.255.0}" export UDP_GATEWAY="${UDP_GATEWAY:-192.168.2.1}" export UDP_DST_IP="${UDP_DST_IP:-192.168.2.112}" export UDP_SRC_PORT="${UDP_SRC_PORT:-40000}" export UDP_DST_PORT="${UDP_DST_PORT:-6464}" export UDP_SOCKET="${UDP_SOCKET:-3}" LOG="$(mktemp -t bbabuild.XXXXXX.log)" echo "==> building $SEEDS seeds (log: $LOG)" echo " UDP: ${UDP_SRC_IP}:${UDP_SRC_PORT} -> ${UDP_DST_IP}:${UDP_DST_PORT} (socket ${UDP_SOCKET})" python -m exi_bba.synth --seeds "$SEEDS" 2>&1 | tee "$LOG" # synth.py prints: "Bitstream for best seed: build/seedN/top.bin" BIN="$(grep -aoE 'build/seed[0-9]+/top\.bin' "$LOG" | tail -1 || true)" if [ -z "$BIN" ] || [ ! -f "$BIN" ]; then echo "!! no best-seed bitstream found — check the log above" >&2 exit 1 fi grep -aE 'Best seed' "$LOG" | tail -1 || true if [ "$NOFLASH" = "--no-flash" ]; then echo "==> built $BIN (not flashing, --no-flash given)" exit 0 fi echo "==> flashing $BIN" iceprog "$BIN" 2>&1 | grep -aE 'VERIFY|cdone|Error|error|Bye' || true echo "==> done"