[scripts][do-qemuarm] general cleanup of script style and fix potential bugs

Mostly suggestions from shellcheck
This commit is contained in:
Travis Geiselbrecht
2025-09-16 13:36:20 -07:00
parent 457355fa3c
commit 5c1bc61e11

View File

@@ -2,23 +2,25 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# TODO: try to merge this with other architecture's do-qemu scripts if possible
# host operating system # host operating system
readonly HOST_OS=$(uname -s) HOST_OS=$(uname -s)
# host architecture # host architecture
HOST_OS_ARCH=$(uname -m) HOST_OS_ARCH=$(uname -m)
case $HOST_OS_ARCH in case $HOST_OS_ARCH in
aarch64*|arm64) aarch64*|arm64)
# flatten either aarch64 or arm64 to arm64 to keep it simple # flatten either aarch64 or arm64 to arm64 to keep it simple
readonly HOST_ARCH="arm64" HOST_OS_ARCH="arm64"
;;
*)
readonly HOST_ARCH
;; ;;
*) ;;
esac esac
readonly HOST_OS
readonly HOST_OS_ARCH
#echo HOST_OS = $HOST_OS # echo HOST_OS = "$HOST_OS"
#echo HOST_OS_ARCH = $HOST_OS_ARCH # echo HOST_OS_ARCH = "$HOST_OS_ARCH"
function HELP { function HELP {
echo "help:" echo "help:"
@@ -100,28 +102,29 @@ elif [ "$PAGE_SIZE" == "64k" ]; then
fi fi
# pick the appropriate qemu and project # pick the appropriate qemu and project
if [ $DO_64BIT == 1 ]; then if (( DO_64BIT )); then
QEMU="qemu-system-aarch64" QEMU="qemu-system-aarch64"
CPU="cortex-a76" CPU="cortex-a76" # default to something recent that modern qemu supports
MACHINE="virt" MACHINE="virt"
if [ $DO_KVM == 1 ]; then # if using KVM/HVF, switch to a host cpu and enable acceleration
if (( DO_KVM )); then
CPU="host" CPU="host"
if [ $HOST_OS == "Darwin" ]; then if [ "$HOST_OS" == "Darwin" ]; then
MACHINE+=",gic_version=2,accel=hvf" MACHINE+=",gic_version=2,accel=hvf"
elif [ $HOST_OS == "Linux" ]; then elif [ "$HOST_OS" == "Linux" ]; then
MACHINE+=",gic_version=host,accel=kvm" MACHINE+=",gic_version=host,accel=kvm"
fi fi
elif [ $DO_VIRT == 1 ]; then elif [ $DO_VIRT == 1 ]; then
MACHINE+=",virtualization=on" MACHINE+=",virtualization=on"
fi fi
if [ $PAGE_SIZE == 65536 ]; then if [ "$PAGE_SIZE" == 65536 ]; then
_PROJECT="qemu-virt-arm64-64k-test" _PROJECT="qemu-virt-arm64-64k-test"
elif [ $PAGE_SIZE == 16384 ]; then elif [ "$PAGE_SIZE" == 16384 ]; then
_PROJECT="qemu-virt-arm64-16k-test" _PROJECT="qemu-virt-arm64-16k-test"
else else
_PROJECT="qemu-virt-arm64-test" _PROJECT="qemu-virt-arm64-test"
fi fi
elif [ $DO_CORTEX_M3 == 1 ]; then elif (( DO_CORTEX_M3 )); then
QEMU="qemu-system-arm" QEMU="qemu-system-arm"
CPU="cortex-m3" CPU="cortex-m3"
MACHINE="lm3s6965evb" MACHINE="lm3s6965evb"
@@ -135,21 +138,22 @@ else
fi fi
# allow overriding the project from the environment # allow overriding the project from the environment
if [ "$PROJECT" == "" ]; then if [ -z "$PROJECT" ]; then
PROJECT=$_PROJECT PROJECT=$_PROJECT
fi fi
# TODO: move ARGS to an array to avoid issues with spaces in paths
ARGS=" -cpu $CPU -m $MEMSIZE -smp $SMP -machine $MACHINE -kernel build-${PROJECT}/lk.elf" ARGS=" -cpu $CPU -m $MEMSIZE -smp $SMP -machine $MACHINE -kernel build-${PROJECT}/lk.elf"
if (( $DO_DISK )); then if (( DO_DISK )); then
ARGS+=" -drive if=none,file=${DISK_IMAGE},id=blk,format=raw" ARGS+=" -drive if=none,file=${DISK_IMAGE},id=blk,format=raw"
ARGS+=" -device virtio-blk-device,drive=blk" ARGS+=" -device virtio-blk-device,drive=blk"
fi fi
if (( $DO_NET )); then if (( DO_NET )); then
ARGS+=" -netdev user,id=vmnic,hostname=qemu " ARGS+=" -netdev user,id=vmnic,hostname=qemu "
ARGS+=" -device virtio-net-device,netdev=vmnic" ARGS+=" -device virtio-net-device,netdev=vmnic"
elif (( $DO_NET_TAP )); then elif (( DO_NET_TAP )); then
# quick note to enable tap interface # quick note to enable tap interface
# IFNAME=qemu0 # IFNAME=qemu0
# BRIDGE=bridge0 # BRIDGE=bridge0
@@ -164,7 +168,7 @@ else
ARGS+=$NO_NET_ARGS ARGS+=$NO_NET_ARGS
fi fi
if (( $DO_DISPLAY )); then if (( DO_DISPLAY )); then
ARGS+=" -device virtio-gpu-device -serial stdio" ARGS+=" -device virtio-gpu-device -serial stdio"
ARGS+=" -device virtio-keyboard-device" ARGS+=" -device virtio-keyboard-device"
ARGS+=" -device virtio-mouse-device" ARGS+=" -device virtio-mouse-device"
@@ -172,19 +176,20 @@ else
ARGS+=" -nographic" ARGS+=" -nographic"
fi fi
if (( $DO_V9P )); then if (( DO_V9P )); then
ARGS+=" -fsdev local,path=$DO_V9P_DIR,security_model=mapped,id=v9p0" ARGS+=" -fsdev local,path=$DO_V9P_DIR,security_model=mapped,id=v9p0"
ARGS+=" -device virtio-9p-device,fsdev=v9p0,mount_tag=V9P0" ARGS+=" -device virtio-9p-device,fsdev=v9p0,mount_tag=V9P0"
fi fi
MAKE_VARS="" MAKE_VARS=""
if (( $DO_CMPCTMALLOC )); then if (( DO_CMPCTMALLOC )); then
MAKE_VARS=LK_HEAP_IMPLEMENTATION=cmpctmalloc MAKE_VARS="LK_HEAP_IMPLEMENTATION=cmpctmalloc"
elif (( $DO_MINIHEAP )); then elif (( DO_MINIHEAP )); then
MAKE_VARS=LK_HEAP_IMPLEMENTATION=miniheap MAKE_VARS="LK_HEAP_IMPLEMENTATION=miniheap"
fi fi
$DIR/make-parallel $MAKE_VARS $PROJECT && set -e
echo $SUDO $QEMU $ARGS $@ && "$DIR"/make-parallel $MAKE_VARS PROJECT="$PROJECT"
$SUDO $QEMU $ARGS $@ echo "$SUDO" $QEMU $ARGS "$@"
$SUDO $QEMU $ARGS "$@"