diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-04-22 16:09:23 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-04-22 16:09:23 +0200 |
| commit | fe7e74d567537d39020c22fad573b77aed2aa017 (patch) | |
| tree | 8275137e874563eac691498ad5e7d9ede14d03d8 /bin/run-riscv-qemu.sh | |
| parent | eb147aa3c7f3bbbd3fba3f256d3366253d5b627f (diff) | |
| download | dotfiles-fe7e74d567537d39020c22fad573b77aed2aa017.tar.gz dotfiles-fe7e74d567537d39020c22fad573b77aed2aa017.zip | |
bin: Force a busybox path when running QEMU
When running QEMU/RISC-V, force the user to provide the `BUSYBOX_SRC`
environment variable. This variable points to the path where busybox has
been built. This way the path to the initramfs is not hardcoded.
Moreover, this allows us to rebuilt the initramfs every time the
`run-riscv-qemu.sh` is called, which in turn brings some consistency to
the process. Plus, this opens the door for allowing files to be passed
into a new `/home` directory for the current user. This way, someone can
just statically compile a binary via cross compilation, and then run it
in isolation with QEMU/RISC-V.
Last but not least, also update the .bashrc file with a value for
`BUSYBOX_SRC` on my system.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'bin/run-riscv-qemu.sh')
| -rwxr-xr-x | bin/run-riscv-qemu.sh | 28 |
1 files changed, 23 insertions, 5 deletions
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 \ |
