From 29523170630804b6083c6d46ac54d65e06bde176 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 23 Sep 2025 16:41:59 +0200 Subject: bin: Guess the QEMU_KERNEL to be used based on cwd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- .bashrc | 1 - bin/run-riscv-qemu.sh | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.bashrc b/.bashrc index c844f04..8358e1c 100644 --- a/.bashrc +++ b/.bashrc @@ -130,7 +130,6 @@ fi # Local builds for busybox and the Linux kernel. Needed by scripts like # `bin/run-riscv-qemu.sh`. export BUSYBOX_SRC="$HOME/src/busybox/1.36.1" -export QEMU_KERNEL="$HOME/src/git.kernel.org/linux/kernel/riscv/arch/riscv/boot/Image" ## # Misc. diff --git a/bin/run-riscv-qemu.sh b/bin/run-riscv-qemu.sh index c96cafb..2e926cf 100755 --- a/bin/run-riscv-qemu.sh +++ b/bin/run-riscv-qemu.sh @@ -4,12 +4,25 @@ set -e # Enfore BUSYBOX_SRC and QEMU_KERNEL. if [ -z "$BUSYBOX_SRC" ]; then - echo "run-qemu (error): you need to define BUSYBOX_SRC." + echo "run-riscv-qemu (error): you need to define BUSYBOX_SRC." exit 1 fi + +# If the $QEMU_KERNEL environment variable is not explicitely set, then guess +# one based on the current working directory. if [ -z "$QEMU_KERNEL" ]; then - echo "run-qemu (error): you need to define QEMU_KERNEL with the Image to be used." - exit 1 + if [ ! -z "$ARCH" ]; then + if [ -f "arch/$ARCH/boot/Image" ]; then + QEMU_KERNEL=$(realpath "arch/$ARCH/boot/Image") + else + echo "run-riscv-qemu (error): you need to define QEMU_KERNEL with the Image to be used." + exit 1 + fi + echo "run-riscv-qemu (info): using '$QEMU_KERNEL' as the Linux kernel Image." + else + echo "run-riscv-qemu (error): you need to define QEMU_KERNEL with the Image to be used." + exit 1 + fi fi # Configurable variables. @@ -31,7 +44,7 @@ while [[ $# -gt 0 ]]; do shift ;; -*) - echo "run-qemu (error): unknown option '$1'." + echo "run-riscv-qemu (error): unknown option '$1'." exit 1 ;; *) -- cgit v1.2.3