aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-10-11 21:39:25 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-10-11 21:39:25 +0200
commitf7a74ab248d3a033f795275fd4b9eda3e0b90834 (patch)
tree7a4a7dcdb9e5a150e0224fe0d32ed557198f35fc
parentd88a036686497275931ea72626756e3f5414d7de (diff)
downloaddotfiles-f7a74ab248d3a033f795275fd4b9eda3e0b90834.tar.gz
dotfiles-f7a74ab248d3a033f795275fd4b9eda3e0b90834.zip
bin: Add helpers for gdb and qemu for RISC-V
There are now two scripts that can be used in order to quickly test a locally built Linux kernel which has been cross compiled for the RISC-V architecture. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rwxr-xr-xbin/run-riscv-gdb.sh54
-rwxr-xr-xbin/run-riscv-qemu.sh61
2 files changed, 115 insertions, 0 deletions
diff --git a/bin/run-riscv-gdb.sh b/bin/run-riscv-gdb.sh
new file mode 100755
index 0000000..6efad17
--- /dev/null
+++ b/bin/run-riscv-gdb.sh
@@ -0,0 +1,54 @@
+#!/usr/bin/env sh
+
+set -e
+
+TUI=""
+BASE=${BASE:-~/src/git.kernel.org/linux/kernel}
+PROFILE=${PROFILE:-riscv}
+REPO=${REPO:-riscv}
+VMLINUX=${VMLINUX:-$BASE/$REPO/vmlinux}
+
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ -t | --tui)
+ TUI="-tui"
+ shift
+ ;;
+ -h | --help)
+ SHOW_HELP=1
+ shift
+ ;;
+ -*)
+ echo "run-gdb (error): unknown option '$1'."
+ exit 1
+ ;;
+ *)
+ echo "run-gdb (warning): argument '$1' will be ignored."
+ shift # past argument
+ ;;
+ esac
+done
+
+# Print the show message if needed.
+if [ -n "$SHOW_HELP" ]; then
+ cat <<HERE
+usage: run-gdb.sh [OPTIONS]
+
+Start a connection to a running QEMU/KVM machine.
+
+ -h, --help Show this message.
+ -t, --tui Enable TUI mode.
+
+Environment variables that can be used the further configure GDB:
+
+ - BASE: the base kernel location. That is, the directory where kernel trees live. Default: "$BASE".
+ - PROFILE: the GDB profile from the default base kernel location. Default: "riscv".
+ - REPO: the Linux repository to be used. Default: "riscv".
+ - VMLINUX: path to 'vmlinux' so to load symbols. Default: "$VMLINUX".
+HERE
+ exit 0
+fi
+
+gdb $TUI \
+ --command $BASE/$PROFILE.gdb \
+ $VMLINUX
diff --git a/bin/run-riscv-qemu.sh b/bin/run-riscv-qemu.sh
new file mode 100755
index 0000000..6b9aaa9
--- /dev/null
+++ b/bin/run-riscv-qemu.sh
@@ -0,0 +1,61 @@
+#!/usr/bin/env sh
+
+set -e
+
+CORES=${CORES:-4}
+EXTRA=${EXTRA:-}
+REPO=${REPO:-riscv}
+KERNEL=${KERNEL:-~/src/git.kernel.org/linux/kernel/$REPO/arch/riscv/boot/Image}
+INITRD=${INITRD:-~/src/busybox/1.36.1/initramfs.cpio.gz}
+
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ -g | --gdb)
+ EXTRA="-s -S"
+ shift
+ ;;
+ -h | --help)
+ SHOW_HELP=1
+ shift
+ ;;
+ -*)
+ echo "run-qemu (error): unknown option '$1'."
+ exit 1
+ ;;
+ *)
+ echo "run-qemu (warning): argument '$1' will be ignored."
+ shift # past argument
+ ;;
+ esac
+done
+
+# Print the show message if needed.
+if [ -n "$SHOW_HELP" ]; then
+ cat <<HERE
+usage: run-riscv-qemu.sh [OPTIONS]
+
+Run QEMU/KVM tailored to my needs for testing the Linux Kernel.
+
+ -g, --gdb Wait for a GDB connection.
+ -h, --help Show this message.
+
+Environment variables that can be used the further configure the run:
+
+ - CORES: number of cores (i.e. argument for '-smp'). Default: 4.
+ - EXTRA: extra arguments to pass. Default: (empty).
+ - INITRD: the initial ramdisk for the run (e.g. argument for '-initrd'). Default: "$INITRD".
+ - KERNEL: the kernel to be passed (i.e. argument for '-kernel'). Default: "$KERNEL".
+ - REPO: the Linux repository to be used. Default: "riscv".
+HERE
+ exit 0
+fi
+
+qemu-system-riscv64 -machine virt -nographic \
+ -smp "$CORES" \
+ -kernel "$KERNEL" \
+ -initrd "$INITRD" \
+ -append "root=/dev/ram" \
+ -append nokaslr \
+ -append ftrace_dump_on_oops \
+ -append sysctl.kernel.panic_on_rcu_stall=1 \
+ $EXTRA