nixos-riscv/boot.sh

83 lines
2.6 KiB
Bash
Raw Normal View History

2024-01-17 18:22:30 +01:00
#!/usr/bin/env bash
2023-11-09 12:09:05 +01:00
set -ex
2023-11-09 12:09:05 +01:00
2024-01-17 18:22:30 +01:00
#export PATH=/nix/store/c5xwy0rllg4lcw61mh20glairjz7ibv4-qemu-8.0.4/bin/:$PATH
2023-11-29 10:48:59 +01:00
CDIR=$(readlink -f "$PWD")
2023-11-09 12:09:05 +01:00
NIX_DISK_IMAGE=$(readlink -f "${NIX_DISK_IMAGE:-./visionfive-nix.qcow2}")
if ! test -e "$NIX_DISK_IMAGE"; then
2023-11-29 10:48:59 +01:00
qemu-img create -f qcow2 "$NIX_DISK_IMAGE" 1024M
2023-11-09 12:09:05 +01:00
fi
2023-11-29 10:48:59 +01:00
echo "NIX_DISK_IMAGE = $NIX_DISK_IMAGE"
2023-11-09 12:09:05 +01:00
# Create a directory for storing temporary data of the running VM.
if [ -z "$TMPDIR" ] || [ -z "$USE_TMPDIR" ]; then
TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
fi
# Create a directory for exchanging data with the VM.
mkdir -p "$TMPDIR/xchg"
2024-01-18 14:14:11 +01:00
system="$NIXOS_SYSTEM_TOPLEVEL"
echo "Booting $system"
2023-11-09 12:09:05 +01:00
cd "$TMPDIR"
2023-11-29 10:48:59 +01:00
#QEMU_KERNEL_PARAMS="boot.debug1devices"
#QEMU_KERNEL_PARAMS="boot.trace boot.debug1"
# Trap the CPU on compressed instructions?
2024-01-18 14:14:11 +01:00
#TRAP_COMPRESSED="-cpu rv64,c=false"
2024-01-18 14:14:11 +01:00
#CUSTOM_BIOS="-bios $OPENSBI/share/opensbi/lp64/generic/firmware/fw_payload.bin"
#CUSTOM_BIOS="-bios $CDIR/bios-nc.bin"
2024-01-17 18:22:30 +01:00
#CUSTOM_BIOS="-bios $CDIR/bios.bin"
#CUSTOM_BIOS="-bios opensbi-1.4-rv-bin/share/opensbi/lp64/generic/firmware/fw_payload.bin"
#DEBUG_GDB="-s -S"
DEBUG_CPU="-d cpu_reset"
#DEBUG_CPU="-d in_asm,cpu,cpu_reset"
2023-11-09 12:09:05 +01:00
2024-01-18 14:14:11 +01:00
2023-11-09 12:09:05 +01:00
# Start QEMU.
2023-11-29 10:48:59 +01:00
exec qemu-system-riscv64 \
$DEBUG_GDB \
$DEBUG_CPU \
2023-11-09 12:09:05 +01:00
-name visionfive-nix \
-m 1024 \
-smp 1 \
-nographic \
-machine virt \
-device virtio-rng-pci \
$TRAP_COMPRESSED \
$CUSTOM_BIOS \
2023-11-29 10:48:59 +01:00
-netdev user,id=net0,hostfwd=tcp::60022-:22 -device virtio-net-device,netdev=net0 \
2023-11-09 12:09:05 +01:00
-virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store \
-virtfs local,path="${SHARED_DIR:-$TMPDIR/xchg}",security_model=none,mount_tag=shared \
-virtfs local,path="$TMPDIR"/xchg,security_model=none,mount_tag=xchg \
-device virtio-keyboard \
2023-11-29 10:48:59 +01:00
-drive "file=$NIX_DISK_IMAGE,if=none,id=hd0" \
-device virtio-blk-device,drive=hd0 \
2024-01-18 14:14:11 +01:00
-kernel $system/kernel \
-initrd $system/initrd \
-append "$(cat $system/kernel-params) init=$system/init regInfo=/nix/store/x3zpwfbk2wkiisxhgi7zwsfwbdfxk0w1-closure-info-riscv64-unknown-linux-gnu/registration console=ttyS0,115200n8 loglevel=7 $QEMU_KERNEL_PARAMS"
2023-11-09 12:09:05 +01:00
$QEMU_OPTS \
"$@"
2023-11-29 10:48:59 +01:00
# -drive "file=$NIX_DISK_IMAGE,if=virtio,id=hd0" \
# -hda "$NIX_DISK_IMAGE" \
#-net nic,model=virtio,macaddr=16:da:11:b4:44:c9 -net user \
# -net nic,netdev=user.0,model=virtio -netdev user,id=user.0,"$QEMU_NET_OPTS" \
2023-11-09 12:09:05 +01:00
#console=tty0
#console=ttyS0,115200n8
#
# -fsdev local,id=fsdev1,path=/nix/store,security_model=none \
# -device virtio-9p-pci,fsdev=fsdev1,mount_tag=store,bus=pcie.1 \
#
# -drive cache=writeback,file="$NIX_DISK_IMAGE",id=drive1,if=none,index=1,werror=report -device virtio-blk-pci,drive=drive1 \