openbsd-riscv64-vm.md - www.codemadness.org - www.codemadness.org saait content files
 (HTM) git clone git://git.codemadness.org/www.codemadness.org
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       openbsd-riscv64-vm.md (2101B)
       ---
            1 This describes how to setup an OpenBSD RISCV64 VM in QEMU.
            2 
            3 The shellscript below does the following:
            4 
            5 * Set up the disk image (raw format).
            6 * Patch the disk image with the OpenBSD miniroot file for the installation.
            7 * Downloads the opensbi and u-boot firmware files for qemu.
            8 * Run the VM with the supported settings.
            9 
           10 The script is tested on the host GNU/Void Linux and OpenBSD-current.
           11 
           12 **IMPORTANT!: The signature and checksum for the miniroot, u-boot and opensbi
           13 files are not verified. If the host is OpenBSD make sure to instead install the
           14 packages (pkg_add u-boot-riscv64 opensbi) and adjust the firmware path for the
           15 qemu -bios and -kernel options. **
           16 
           17 
           18 ## Shellscript
           19 
           20         #!/bin/sh
           21         # mirror list: https://www.openbsd.org/ftp.html
           22         mirror="https://ftp.bit.nl/pub/OpenBSD/"
           23         release="7.0"
           24         minirootname="miniroot70.img"
           25         
           26         miniroot() {
           27                 test -f "${minirootname}" && return # download once
           28         
           29                 url="${mirror}/${release}/riscv64/${minirootname}"
           30                 curl -o "${minirootname}" "${url}"
           31         }
           32         
           33         createrootdisk() {
           34                 test -f disk.raw && return # create once
           35                 qemu-img create disk.raw 10G # create 10 GB disk
           36                 dd conv=notrunc if=${minirootname} of=disk.raw # write miniroot to disk
           37         }
           38         
           39         opensbi() {
           40                 f="opensbi.tgz"
           41                 test -f "${f}" && return # download and extract once.
           42         
           43                 url="${mirror}/${release}/packages/amd64/opensbi-0.9p0.tgz"
           44                 curl -o "${f}" "${url}"
           45         
           46                 tar -xzf "${f}" share/opensbi/generic/fw_jump.bin
           47         }
           48         
           49         uboot() {
           50                 f="uboot.tgz"
           51                 test -f "${f}" && return # download and extract once.
           52         
           53                 url="${mirror}/${release}/packages/amd64/u-boot-riscv64-2021.07p0.tgz"
           54                 curl -o "${f}" "${url}"
           55         
           56                 tar -xzf "${f}" share/u-boot/qemu-riscv64_smode/u-boot.bin
           57         }
           58         
           59         setup() {
           60                 miniroot
           61                 createrootdisk
           62                 opensbi
           63                 uboot
           64         }
           65         
           66         run() {
           67                 qemu-system-riscv64 \
           68                         -machine virt \
           69                         -nographic \
           70                         -m 2048M \
           71                         -smp 2 \
           72                         -bios share/opensbi/generic/fw_jump.bin \
           73                         -kernel share/u-boot/qemu-riscv64_smode/u-boot.bin \
           74                         -drive file=disk.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
           75                         -netdev user,id=net0,ipv6=off -device virtio-net-device,netdev=net0
           76         }
           77         
           78         setup
           79         run