From 3997ec4d2d7d6f69b08d0c04ce8de0df03c52a45 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 21:29:49 +0200 Subject: ahci: scan all ports; fat: mount first valid FAT32 disk The kernel previously started only AHCI port 0, so any launch where the firmware/QEMU put something else on port 0 (e.g. the ESP from an implicit -drive file=fat:rw:esp) left the real disk unnoticed: 'unsupported sector size 0' and no mount. - ahci.rs: enumerate CAP.NP/PI ports, start every port that links up (empty ports settle at DET=0 and are skipped quickly), keep up to 8 disks, and expose disk_count()/select() for the filesystem - fat.rs: try each disk in port order and mount the first valid FAT32 volume; non-FAT disks are logged and skipped - scripts/boot.sh: attach the data disk on ide.0 and the ESP on ide.1 (DISK_IMG env var, default /tmp/disk.img), matching the Makefile - Verified with the disk on port 0 (Makefile style), port 5 (old-style command line), and with the ESP on port 0; fsck.fat stays clean --- scripts/boot.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'scripts/boot.sh') diff --git a/scripts/boot.sh b/scripts/boot.sh index 1e3f739..26064f9 100755 --- a/scripts/boot.sh +++ b/scripts/boot.sh @@ -19,6 +19,11 @@ # OVMF path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) # MEM memory size (default: 256M) # SMP CPU count (default: 1) +# DISK_IMG raw disk image attached as the SATA data disk (default: /tmp/disk.img) +# +# The data disk is pinned to AHCI port 0 (ide.0) and the ESP to port 1 +# (ide.1); the implicit `-drive file=fat:rw:esp` would otherwise grab +# port 0 and the kernel would find the ESP where it expects a FAT32 disk. # set -euo pipefail @@ -33,6 +38,7 @@ ESP_DIR="$PROJECT_DIR/esp" OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" MEM="${MEM:-256M}" SMP="${SMP:-1}" +DISK_IMG="${DISK_IMG:-/tmp/disk.img}" PROFILE="debug" CARGO_FLAGS="" GUI="" @@ -84,13 +90,25 @@ echo "" echo "=== Booting (direct: firmware → rsnix) ===" echo " ovmf: $OVMF" echo " mem: $MEM smp: $SMP" +echo " disk: $([ -f "$DISK_IMG" ] && echo "$DISK_IMG" || echo "none ($DISK_IMG missing)")" echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" echo "" +if [ -f "$DISK_IMG" ]; then + DISK_ARGS=( + -drive "file=$DISK_IMG,format=raw,if=none,id=disk" + -device ide-hd,drive=disk,bus=ide.0 + ) +else + DISK_ARGS=() +fi + exec qemu-system-x86_64 \ -bios "$OVMF" \ - -drive file=fat:rw:"$ESP_DIR",format=raw \ + "${DISK_ARGS[@]}" \ + -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ + -device ide-hd,drive=esp,bus=ide.1 \ -serial stdio \ -m "$MEM" \ -machine q35 \ -- cgit v1.2.3