RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / scripts / run-qemu.sh
1793 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# Boot the Foundry OS image interactively on the pinned Rustbelt kernel:
# a QEMU window (or add NOGRAPHIC=1 for serial only).
#   CONTRACT=v2 (default via make): only our image; init starts rbsh on the
#     console and on hvc0. Writes go to a temporary overlay (snapshot) and
#     are thrown away at exit; set KEEP=1 to write to the image for real.
#   CONTRACT=v1: our image as disk 0 (B:), the kernel's test disks as C:,
#     D:, E:, like the kernel's `cargo run`.
# The hvc0 console is on the unix socket OUT/hvc0.sock:
#   socat - UNIX-CONNECT:out/hvc0.sock     (v1: then `getty /dev/hvc0 &` in Foundry)
#
# Usage: scripts/run-qemu.sh IMAGE KERNEL_BOOTIMAGE KERNEL_TARGET OUT_DIR
set -euo pipefail
cd "$(dirname "$0")/.."
IMAGE=$1 IMG=$2 KT=$3 OUT=$4
display=()
snap=,snapshot=on
[ -n "${KEEP:-}" ] && snap=
if [ "${CONTRACT:-v1}" = v2 ]; then
    disks=(-drive file="$IMAGE",format=raw,if=virtio$snap)
else
    disks=(-drive file="$IMAGE",format=raw,if=virtio,snapshot=on)
    for d in ext2 exfat btrfs; do disks+=(-drive file="$KT/$d.img",format=raw,if=virtio,snapshot=on); done
fi
[ -n "${NOGRAPHIC:-}" ] && display=(-display none)
exec qemu-system-x86_64 -smp 4 -cpu "${QEMU_CPU:-max}" \
    -pidfile "$OUT/qemu-run.pid" \
    -drive format=raw,file="$IMG",snapshot=on \
    "${disks[@]}" \
    -netdev "user,id=net0,guestfwd=tcp:10.0.2.100:80-cmd:sh scripts/http-reply.sh,guestfwd=tcp:10.0.2.100:7-cmd:cat,hostfwd=tcp:127.0.0.1:5580-:80" \
    -device virtio-net-pci,netdev=net0 \
    -vga none -device virtio-vga -device virtio-rng-pci \
    -device virtio-serial-pci -device virtconsole,chardev=hvc \
    -chardev "socket,id=hvc,path=$OUT/hvc0.sock,server=on,wait=off" \
    -device isa-debug-exit,iobase=0xf4,iosize=0x04 \
    -serial stdio "${display[@]}"