From eb79d8fcf0632582dfcc0dea01cdf6f89a664926 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 3 Oct 2025 16:20:14 +0200 Subject: run-riscv-qemu.sh: Add '-k/--kernel' and '-d/--disk' parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows this script to be more specific on the kernel being used, less hiden (as it was on an environment variable), and it easies up the route for a disk already containing a Linux system. Signed-off-by: Miquel Sabaté Solà --- bin/run-riscv-qemu.sh | 130 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 47 deletions(-) diff --git a/bin/run-riscv-qemu.sh b/bin/run-riscv-qemu.sh index 5098beb..77bf808 100755 --- a/bin/run-riscv-qemu.sh +++ b/bin/run-riscv-qemu.sh @@ -1,40 +1,21 @@ #!/usr/bin/env bash -set -e +set -ex -# Enfore BUSYBOX_SRC and QEMU_KERNEL. -if [ -z "$BUSYBOX_SRC" ]; then - 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 - 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." +EXTRA="" +KERNEL="" +DISK="" +while [[ $# -gt 0 ]]; do + case $1 in + -d | --disk) + if [ -z "$2" ]; then + echo "run-riscv-qemu (error): you have to provide a value for -d/--disk" 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. -QEMU_CPU=${QEMU_CPU:-max} -QEMU_SMP=${QEMU_SMP:-4} -EXTRA=${EXTRA:-} - -# Cleanup older environments. -rm -rf "$BUSYBOX_SRC/initramfs/home" - -while [[ $# -gt 0 ]]; do - case $1 in + DISK="$2" + shift 2 + ;; -g | --gdb) EXTRA="-s -S" shift @@ -43,14 +24,26 @@ while [[ $# -gt 0 ]]; do SHOW_HELP=1 shift ;; + -k | --kernel) + if [ -z "$2" ]; then + echo "run-riscv-qemu (error): you have to provide a value for -k/--kernel" + exit 1 + fi + + KERNEL="$2" + shift 2 + ;; -*) echo "run-riscv-qemu (error): unknown option '$1'." exit 1 ;; *) - mkdir -p "$BUSYBOX_SRC/initramfs/home/$(whoami)" - cp "$1" "$BUSYBOX_SRC/initramfs/home/$(whoami)/" - shift # past argument + if [ ! -z "$BUSYBOX_SRC" ]; then + mkdir -p "$BUSYBOX_SRC/initramfs/home/$(whoami)" + cp "$1" "$BUSYBOX_SRC/initramfs/home/$(whoami)/" + fi + + shift ;; esac done @@ -58,24 +51,67 @@ done # Print the show message if needed. if [ -n "$SHOW_HELP" ]; then cat <../initramfs.cpio.gz @@ -87,10 +123,10 @@ popd set -x qemu-system-riscv64 -machine virt -nographic \ - -cpu "$QEMU_CPU" \ - -m 8G \ - -smp "$QEMU_SMP" \ - -kernel "$QEMU_KERNEL" \ + -cpu max -m 8G -smp 4 \ + -device virtio-net-device,netdev=usernet \ + -netdev user,id=usernet,hostfwd=tcp::22222-:22 \ + -kernel "$KERNEL" \ -initrd "$BUSYBOX_SRC/initramfs.cpio.gz" \ -append "root=/dev/ram" \ -append nokaslr \ -- cgit v1.2.3