#!/bin/sh
# Boot salmanoff-image with eth0 bridged onto the host lab LAN (10.42.0.0/24).
#
# Prerequisites on the host:
#   1. A Linux bridge (default: br-smo) whose ports include the NIC on 10.42.0.0/24.
#   2. /etc/qemu/bridge.conf containing:  allow br-smo
#   3. qemu-oe-bridge-helper allowed (setuid or root via sudo policy).
#
# Usage (from build/ after sourcing init-build-env):
#   ../layers/meta-salmanoff/scripts/runqemu-salmanoff-bridge
#   ../layers/meta-salmanoff/scripts/runqemu-salmanoff-bridge br-lab
#   ../layers/meta-salmanoff/scripts/runqemu-salmanoff-bridge br-smo 4096
#
# Guest eth0 is configured statically as 10.42.0.16/24 via init-ifupdown.
# Default RAM is 2G: Mesa Rusticl/llvmpipe (clinfo, Salmanoff OpenCL) OOMs at 256M.

set -eu

BRIDGE="${1:-br-smo}"
MEM="${2:-2048}"

if [ ! -f /etc/qemu/bridge.conf ] || ! grep -q "allow ${BRIDGE}" /etc/qemu/bridge.conf 2>/dev/null; then
	echo "Host bridge helper is not configured for '${BRIDGE}'." >&2
	echo "Create /etc/qemu/bridge.conf with a line:  allow ${BRIDGE}" >&2
	echo "See: https://docs.yoctoproject.org/dev-manual/qemu.html" >&2
	exit 1
fi

exec runqemu salmanoff-image snapshot "bridge=${BRIDGE}" nographic "qemuparams=-m ${MEM}"
