aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bashrc4
-rwxr-xr-xbin/run-riscv-qemu.sh28
2 files changed, 27 insertions, 5 deletions
diff --git a/.bashrc b/.bashrc
index 76ff96a..3c75c5e 100644
--- a/.bashrc
+++ b/.bashrc
@@ -168,6 +168,10 @@ if [ "$(uname -m)" != "riscv64" ]; then
export CROSS_COMPILE=riscv64-suse-linux-
fi
+# I have built a local busybox so I can generate an initramfs for various
+# hacking thingies, let's reference it into an environment variable.
+export BUSYBOX_SRC="$HOME/src/busybox/1.36.1"
+
##
# Lastly I had some problems with the GPG agent recently. So I copied a solution
# from https://github.com/jessfraz/dotfiles
diff --git a/bin/run-riscv-qemu.sh b/bin/run-riscv-qemu.sh
index 6b9aaa9..94310c5 100755
--- a/bin/run-riscv-qemu.sh
+++ b/bin/run-riscv-qemu.sh
@@ -1,12 +1,20 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
set -e
+# Enfore the BUSYBOX_SRC path.
+if [ -z "$BUSYBOX_SRC" ]; then
+ echo "run-qemu (error): you need to define BUSYBOX_SRC."
+ exit 1
+fi
+
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}
+
+# Cleanup older environments.
+rm -rf "$BUSYBOX_SRC/initramfs/home"
while [[ $# -gt 0 ]]; do
case $1 in
@@ -23,7 +31,8 @@ while [[ $# -gt 0 ]]; do
exit 1
;;
*)
- echo "run-qemu (warning): argument '$1' will be ignored."
+ mkdir -p "$BUSYBOX_SRC/initramfs/home/$(whoami)"
+ cp "$1" "$BUSYBOX_SRC/initramfs/home/$(whoami)/"
shift # past argument
;;
esac
@@ -43,17 +52,26 @@ 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
+##
+# Generate the initramfs.
+
+pushd "$BUSYBOX_SRC/initramfs"
+find . -print0 | cpio --null -o --format=newc | gzip -9 >../initramfs.cpio.gz
+popd
+
+##
+# Actual run.
+
qemu-system-riscv64 -machine virt -nographic \
-smp "$CORES" \
-kernel "$KERNEL" \
- -initrd "$INITRD" \
+ -initrd "$BUSYBOX_SRC/initramfs.cpio.gz" \
-append "root=/dev/ram" \
-append nokaslr \
-append ftrace_dump_on_oops \