diff options
Diffstat (limited to 'scripts/boot.sh')
| -rwxr-xr-x | scripts/boot.sh | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/scripts/boot.sh b/scripts/boot.sh index 5b8e6fa..9c60dc9 100755 --- a/scripts/boot.sh +++ b/scripts/boot.sh | |||
| @@ -2,8 +2,8 @@ | |||
| 2 | # | 2 | # |
| 3 | # scripts/boot.sh — quick direct boot in QEMU (dev loop) | 3 | # scripts/boot.sh — quick direct boot in QEMU (dev loop) |
| 4 | # | 4 | # |
| 5 | # Fastest iteration: boots the kernel directly as BOOTX64.EFI via QEMU's | 5 | # Builds the kernel, stages the system image, and boots directly as |
| 6 | # FAT driver, skipping the bootloader entirely. | 6 | # BOOTX64.EFI via QEMU's FAT driver. One image = one drive. |
| 7 | # | 7 | # |
| 8 | # Usage: | 8 | # Usage: |
| 9 | # ./scripts/boot.sh [--gui] [--debug] [--release] [--mem 512M] [--smp 2] | 9 | # ./scripts/boot.sh [--gui] [--debug] [--release] [--mem 512M] [--smp 2] |
| @@ -19,26 +19,19 @@ | |||
| 19 | # OVMF path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) | 19 | # OVMF path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) |
| 20 | # MEM memory size (default: 256M) | 20 | # MEM memory size (default: 256M) |
| 21 | # SMP CPU count (default: 1) | 21 | # SMP CPU count (default: 1) |
| 22 | # DISK_IMG raw disk image attached as the SATA data disk (default: /tmp/disk.img) | 22 | # SYSTEM_IMG system image path (default: /tmp/system.img) |
| 23 | # | ||
| 24 | # The data disk is pinned to AHCI port 0 (ide.0) and the ESP to port 1 | ||
| 25 | # (ide.1); the implicit `-drive file=fat:rw:esp` would otherwise grab | ||
| 26 | # port 0 and the kernel would find the ESP where it expects a FAT32 disk. | ||
| 27 | # | 23 | # |
| 28 | set -euo pipefail | 24 | set -euo pipefail |
| 29 | 25 | ||
| 30 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | 26 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 31 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | 27 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 32 | |||
| 33 | cd "$PROJECT_DIR" | 28 | cd "$PROJECT_DIR" |
| 34 | 29 | ||
| 35 | ESP_DIR="$PROJECT_DIR/esp" | ||
| 36 | |||
| 37 | # ---- config ---- | 30 | # ---- config ---- |
| 38 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | 31 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" |
| 39 | MEM="${MEM:-256M}" | 32 | MEM="${MEM:-256M}" |
| 40 | SMP="${SMP:-1}" | 33 | SMP="${SMP:-1}" |
| 41 | DISK_IMG="${DISK_IMG:-/tmp/disk.img}" | 34 | SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}" |
| 42 | PROFILE="debug" | 35 | PROFILE="debug" |
| 43 | CARGO_FLAGS="" | 36 | CARGO_FLAGS="" |
| 44 | GUI="" | 37 | GUI="" |
| @@ -46,7 +39,6 @@ DEBUG="" | |||
| 46 | 39 | ||
| 47 | # ---- args ---- | 40 | # ---- args ---- |
| 48 | source "$SCRIPT_DIR/lib-boot-args.sh" | 41 | source "$SCRIPT_DIR/lib-boot-args.sh" |
| 49 | # boot.sh-specific flags live here; everything else is shared. | ||
| 50 | handle_arg() { | 42 | handle_arg() { |
| 51 | case "$1" in | 43 | case "$1" in |
| 52 | --release | -r) | 44 | --release | -r) |
| @@ -62,46 +54,29 @@ handle_arg() { | |||
| 62 | parse_boot_args "$@" | 54 | parse_boot_args "$@" |
| 63 | 55 | ||
| 64 | OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" | 56 | OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" |
| 65 | KERNEL="$OUT_DIR/rsdos.efi" | ||
| 66 | 57 | ||
| 67 | # ---- build ---- | 58 | # ---- build ---- |
| 68 | echo "=== Building kernel ($PROFILE) ===" | 59 | echo "=== Building kernel ($PROFILE) ===" |
| 69 | cargo build --package rsdos --target x86_64-unknown-uefi $CARGO_FLAGS | 60 | cargo build --package rsdos --target x86_64-unknown-uefi $CARGO_FLAGS |
| 70 | 61 | ||
| 71 | # ---- deploy ---- | 62 | # ---- stage system image ---- |
| 72 | mkdir -p "$ESP_DIR/EFI/BOOT" | 63 | echo "=== Staging system image ===" |
| 73 | cp "$KERNEL" "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | 64 | "$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG" |
| 74 | echo " kernel: $(ls -lh "$KERNEL" | awk '{print $5}')" | 65 | echo " system image: $SYSTEM_IMG" |
| 75 | 66 | ||
| 76 | # ---- boot ---- | 67 | # ---- boot ---- |
| 77 | echo "" | 68 | echo "" |
| 78 | echo "=== Booting (direct: firmware → rsnix) ===" | 69 | echo "=== Booting (direct: firmware → rsnix) ===" |
| 79 | echo " ovmf: $OVMF" | 70 | echo " ovmf: $OVMF" |
| 80 | echo " mem: $MEM smp: $SMP" | 71 | echo " mem: $MEM smp: $SMP" |
| 81 | echo " disk: $([ -f "$DISK_IMG" ] && echo "$DISK_IMG" || echo "none ($DISK_IMG missing)")" | ||
| 82 | echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" | 72 | echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" |
| 83 | echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" | 73 | echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" |
| 84 | echo "" | 74 | echo "" |
| 85 | 75 | ||
| 86 | if [ ! -f "$DISK_IMG" ]; then | ||
| 87 | echo " (creating missing disk image: $DISK_IMG)" | ||
| 88 | "$SCRIPT_DIR/mkdisk.sh" "$DISK_IMG" | ||
| 89 | fi | ||
| 90 | |||
| 91 | if [ -f "$DISK_IMG" ]; then | ||
| 92 | DISK_ARGS=( | ||
| 93 | -drive "file=$DISK_IMG,format=raw,if=none,id=disk" | ||
| 94 | -device ide-hd,drive=disk,bus=ide.0 | ||
| 95 | ) | ||
| 96 | else | ||
| 97 | DISK_ARGS=() | ||
| 98 | fi | ||
| 99 | |||
| 100 | exec qemu-system-x86_64 \ | 76 | exec qemu-system-x86_64 \ |
| 101 | -bios "$OVMF" \ | 77 | -bios "$OVMF" \ |
| 102 | "${DISK_ARGS[@]}" \ | 78 | -drive "file=$SYSTEM_IMG,format=raw,if=none,id=disk" \ |
| 103 | -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ | 79 | -device ide-hd,drive=disk,bus=ide.0 \ |
| 104 | -device ide-hd,drive=esp,bus=ide.1 \ | ||
| 105 | -serial stdio \ | 80 | -serial stdio \ |
| 106 | -m "$MEM" \ | 81 | -m "$MEM" \ |
| 107 | -machine q35 \ | 82 | -machine q35 \ |
