diff options
Diffstat (limited to '')
| -rw-r--r-- | CONTEXT.md | 21 | ||||
| -rw-r--r-- | Makefile | 38 | ||||
| -rw-r--r-- | rsnix/src/ahci.rs | 5 | ||||
| -rwxr-xr-x | scripts/boot.sh | 5 | ||||
| -rwxr-xr-x | scripts/mkdisk.sh | 85 | ||||
| -rwxr-xr-x | scripts/sendkeys.py | 103 | ||||
| -rwxr-xr-x | scripts/test-disk.sh | 111 | ||||
| -rw-r--r-- | seed/lines.txt | 6 | ||||
| -rw-r--r-- | seed/motd.txt | 11 |
9 files changed, 377 insertions, 8 deletions
| @@ -186,8 +186,25 @@ Single Rust crate (`x86_64-unknown-uefi` target). Module breakdown: | |||
| 186 | `-device ide-hd,drive=disk,bus=ide.0` puts the data disk on AHCI port | 186 | `-device ide-hd,drive=disk,bus=ide.0` puts the data disk on AHCI port |
| 187 | 0; the ESP gets `bus=ide.1`. (The implicit `-drive file=fat:rw:esp` | 187 | 0; the ESP gets `bus=ide.1`. (The implicit `-drive file=fat:rw:esp` |
| 188 | otherwise grabs port 0.) Make targets (`run`, `run-gui`, `debug`) | 188 | otherwise grabs port 0.) Make targets (`run`, `run-gui`, `debug`) |
| 189 | attach `$(DISK_IMG)` (default `/tmp/disk.img`). OVMF writes its | 189 | attach `$(DISK_IMG)` (default `/tmp/disk.img`) and auto-create it when |
| 190 | `NvVars` varstore file onto the first FAT volume — harmless. | 190 | missing. OVMF writes its `NvVars` varstore file onto the first FAT |
| 191 | volume — harmless. | ||
| 192 | |||
| 193 | The whole disk workflow is scripted (no manual mkfs/mcopy): | ||
| 194 | |||
| 195 | - `make disk` / `./scripts/mkdisk.sh` — create the FAT32 image with | ||
| 196 | `mkfs.fat -C` (the flag that actually creates the file; plain | ||
| 197 | `mkfs.fat` needs an existing file), label `RSDOS`, seed from | ||
| 198 | `seed/` via mtools; `--fresh` re-formats, `--size 128M` sizes it | ||
| 199 | - `make inspect` — `mdir -i` listing of the image (mtools) | ||
| 200 | - `make test-disk` / `./scripts/test-disk.sh` — full automated round | ||
| 201 | trip: build → deploy → ensure image → boot QEMU headless → drive | ||
| 202 | the shell via `sendkey` through the monitor (`ls /disk`, `mkdir`, | ||
| 203 | `echo >`, `cat`, `poweroff`) → fsck-clean check → `mtype` verifies | ||
| 204 | the written file survived poweroff | ||
| 205 | - `./scripts/sendkeys.py` — types lines into the guest via the QEMU | ||
| 206 | monitor (`--sock`, US layout, named keys for punctuation; bare | ||
| 207 | `-`/`.`/`/` are not valid sendkey names) | ||
| 191 | 208 | ||
| 192 | ## Known issues / perf notes | 209 | ## Known issues / perf notes |
| 193 | 210 | ||
| @@ -11,10 +11,10 @@ export BOOTLOADER=rsboot/rsboot.efi | |||
| 11 | export OVMF=/usr/share/edk2/x64/OVMF.4m.fd | 11 | export OVMF=/usr/share/edk2/x64/OVMF.4m.fd |
| 12 | export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI | 12 | export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI |
| 13 | # Attach a raw disk image as the SATA drive (disk.img -> ide.0, ESP -> ide.1). | 13 | # Attach a raw disk image as the SATA drive (disk.img -> ide.0, ESP -> ide.1). |
| 14 | # Create one with: mkfs.fat -F 32 -n RSDOS disk.img && mcopy -i disk.img files :: | 14 | # Create one with: make disk (or: ./scripts/mkdisk.sh) |
| 15 | export DISK_IMG ?= /tmp/disk.img | 15 | export DISK_IMG ?= /tmp/disk.img |
| 16 | 16 | ||
| 17 | .PHONY: all run run-gui clean image debug release fmt bootloader boot-image | 17 | .PHONY: all run run-gui clean image debug release fmt bootloader boot-image disk disk-fresh inspect test-disk |
| 18 | 18 | ||
| 19 | # ---- Build --------------------------------------------------------------- | 19 | # ---- Build --------------------------------------------------------------- |
| 20 | 20 | ||
| @@ -43,7 +43,7 @@ $(INITRD): | $(ESP_DIR) | |||
| 43 | 43 | ||
| 44 | # ---- QEMU runners -------------------------------------------------------- | 44 | # ---- QEMU runners -------------------------------------------------------- |
| 45 | 45 | ||
| 46 | run: all | 46 | run: all disk |
| 47 | qemu-system-x86_64 \ | 47 | qemu-system-x86_64 \ |
| 48 | -bios $(OVMF) \ | 48 | -bios $(OVMF) \ |
| 49 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ | 49 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ |
| @@ -57,7 +57,7 @@ run: all | |||
| 57 | -no-reboot \ | 57 | -no-reboot \ |
| 58 | -display none | 58 | -display none |
| 59 | 59 | ||
| 60 | run-gui: all | 60 | run-gui: all disk |
| 61 | qemu-system-x86_64 \ | 61 | qemu-system-x86_64 \ |
| 62 | -bios $(OVMF) \ | 62 | -bios $(OVMF) \ |
| 63 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ | 63 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ |
| @@ -72,7 +72,7 @@ run-gui: all | |||
| 72 | -vga std | 72 | -vga std |
| 73 | 73 | ||
| 74 | # GDB stub on :1234 | 74 | # GDB stub on :1234 |
| 75 | debug: all | 75 | debug: all disk |
| 76 | qemu-system-x86_64 \ | 76 | qemu-system-x86_64 \ |
| 77 | -bios $(OVMF) \ | 77 | -bios $(OVMF) \ |
| 78 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ | 78 | -drive file=$(DISK_IMG),format=raw,if=none,id=disk \ |
| @@ -92,6 +92,27 @@ debug: all | |||
| 92 | run-image: all | 92 | run-image: all |
| 93 | ./scripts/boot-image.sh rs-dos.img | 93 | ./scripts/boot-image.sh rs-dos.img |
| 94 | 94 | ||
| 95 | # ---- Data disk ----------------------------------------------------------- | ||
| 96 | |||
| 97 | # Create the FAT32 data disk if it doesn't exist. Uses mkfs.fat -C (the | ||
| 98 | # flag that actually creates the file) and seeds it from seed/. | ||
| 99 | disk: | ||
| 100 | ./scripts/mkdisk.sh "$(DISK_IMG)" | ||
| 101 | |||
| 102 | # Re-format the data disk from scratch (wipes it, then re-seeds). | ||
| 103 | disk-fresh: | ||
| 104 | ./scripts/mkdisk.sh --fresh "$(DISK_IMG)" | ||
| 105 | |||
| 106 | # List the data disk contents with mtools (requires mtools). | ||
| 107 | inspect: | ||
| 108 | @command -v mdir >/dev/null 2>&1 || (echo "inspect needs mtools: sudo apt install mtools"; exit 1) | ||
| 109 | @mdir -i "$(DISK_IMG)" | ||
| 110 | |||
| 111 | # Full automated round trip: build -> boot -> shell commands -> poweroff | ||
| 112 | # -> fsck + mtools verification. | ||
| 113 | test-disk: | ||
| 114 | ./scripts/test-disk.sh | ||
| 115 | |||
| 95 | # ---- Full boot chain ----------------------------------------------------- | 116 | # ---- Full boot chain ----------------------------------------------------- |
| 96 | 117 | ||
| 97 | # Build bootloader only (rsboot submodule) | 118 | # Build bootloader only (rsboot submodule) |
| @@ -126,11 +147,18 @@ help: | |||
| 126 | @echo " make run QEMU serial console (direct boot, no bootloader)" | 147 | @echo " make run QEMU serial console (direct boot, no bootloader)" |
| 127 | @echo " make run-gui QEMU with graphical window (GOP/PS2)" | 148 | @echo " make run-gui QEMU with graphical window (GOP/PS2)" |
| 128 | @echo " make debug QEMU + GDB stub on :1234" | 149 | @echo " make debug QEMU + GDB stub on :1234" |
| 150 | @echo " make disk create the data disk if missing (default /tmp/disk.img)" | ||
| 151 | @echo " make disk-fresh re-format the data disk (wipes it)" | ||
| 152 | @echo " make inspect list data disk contents (mtools)" | ||
| 153 | @echo " make test-disk automated disk round trip (build->boot->fsck)" | ||
| 129 | @echo " make clean remove build artifacts" | 154 | @echo " make clean remove build artifacts" |
| 130 | @echo " make fmt format Rust source" | 155 | @echo " make fmt format Rust source" |
| 131 | @echo "" | 156 | @echo "" |
| 132 | @echo "Scripts:" | 157 | @echo "Scripts:" |
| 133 | @echo " ./scripts/boot.sh quick direct boot (dev loop)" | 158 | @echo " ./scripts/boot.sh quick direct boot (dev loop)" |
| 159 | @echo " ./scripts/mkdisk.sh create/re-format the data disk" | ||
| 160 | @echo " ./scripts/test-disk.sh automated disk round trip" | ||
| 161 | @echo " ./scripts/sendkeys.py type into QEMU via the monitor" | ||
| 134 | @echo " ./scripts/boot-image.sh boot full chain (builds if needed)" | 162 | @echo " ./scripts/boot-image.sh boot full chain (builds if needed)" |
| 135 | @echo " ./scripts/build-image.sh build full chain disk image" | 163 | @echo " ./scripts/build-image.sh build full chain disk image" |
| 136 | @echo " ./scripts/build-bootloader.sh build rsboot from source" | 164 | @echo " ./scripts/build-bootloader.sh build rsboot from source" |
diff --git a/rsnix/src/ahci.rs b/rsnix/src/ahci.rs index 2efe3b4..427345d 100644 --- a/rsnix/src/ahci.rs +++ b/rsnix/src/ahci.rs | |||
| @@ -182,7 +182,10 @@ fn start_port(abar: usize, port_idx: u32) -> Option<Disk> { | |||
| 182 | }; | 182 | }; |
| 183 | // IDENTIFY DEVICE as a sanity check + to learn the capacity. | 183 | // IDENTIFY DEVICE as a sanity check + to learn the capacity. |
| 184 | if issue(&d, ATA_IDENTIFY, 0, 1, false).is_err() { | 184 | if issue(&d, ATA_IDENTIFY, 0, 1, false).is_err() { |
| 185 | crate::serial_println!("ahci: IDENTIFY failed on port {} (not an ATA disk?)", port_idx); | 185 | crate::serial_println!( |
| 186 | "ahci: IDENTIFY failed on port {} (not an ATA disk?)", | ||
| 187 | port_idx | ||
| 188 | ); | ||
| 186 | return None; | 189 | return None; |
| 187 | } | 190 | } |
| 188 | let id = unsafe { core::slice::from_raw_parts(d.buf as *const u16, 256) }; | 191 | let id = unsafe { core::slice::from_raw_parts(d.buf as *const u16, 256) }; |
diff --git a/scripts/boot.sh b/scripts/boot.sh index 26064f9..99fd103 100755 --- a/scripts/boot.sh +++ b/scripts/boot.sh | |||
| @@ -95,6 +95,11 @@ echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" | |||
| 95 | echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" | 95 | echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" |
| 96 | echo "" | 96 | echo "" |
| 97 | 97 | ||
| 98 | if [ ! -f "$DISK_IMG" ]; then | ||
| 99 | echo " (creating missing disk image: $DISK_IMG)" | ||
| 100 | "$SCRIPT_DIR/mkdisk.sh" "$DISK_IMG" | ||
| 101 | fi | ||
| 102 | |||
| 98 | if [ -f "$DISK_IMG" ]; then | 103 | if [ -f "$DISK_IMG" ]; then |
| 99 | DISK_ARGS=( | 104 | DISK_ARGS=( |
| 100 | -drive "file=$DISK_IMG,format=raw,if=none,id=disk" | 105 | -drive "file=$DISK_IMG,format=raw,if=none,id=disk" |
diff --git a/scripts/mkdisk.sh b/scripts/mkdisk.sh new file mode 100755 index 0000000..f9a8c09 --- /dev/null +++ b/scripts/mkdisk.sh | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/mkdisk.sh — create (or re-create) the FAT32 data disk that the | ||
| 4 | # kernel mounts at /disk. | ||
| 5 | # | ||
| 6 | # Usage: | ||
| 7 | # ./scripts/mkdisk.sh # create /tmp/disk.img (64M) if missing | ||
| 8 | # ./scripts/mkdisk.sh --fresh # re-format (wipes the image!) | ||
| 9 | # ./scripts/mkdisk.sh --size 128M # different size (default 64M) | ||
| 10 | # ./scripts/mkdisk.sh /path/img # custom image path | ||
| 11 | # ./scripts/mkdisk.sh --no-seed # skip the seed/ directory | ||
| 12 | # | ||
| 13 | # The image is created with `mkfs.fat -C`, which is the option that | ||
| 14 | # actually creates the file — plain `mkfs.fat` only writes into an | ||
| 15 | # existing one. Files from seed/ (if present) are copied in with mtools. | ||
| 16 | # | ||
| 17 | set -euo pipefail | ||
| 18 | |||
| 19 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| 20 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | ||
| 21 | |||
| 22 | IMG="/tmp/disk.img" | ||
| 23 | SIZE="64M" | ||
| 24 | FRESH=0 | ||
| 25 | SEED_DIR="$PROJECT_DIR/seed" | ||
| 26 | |||
| 27 | while [ $# -gt 0 ]; do | ||
| 28 | case "$1" in | ||
| 29 | --fresh) FRESH=1 ;; | ||
| 30 | --size) | ||
| 31 | shift | ||
| 32 | SIZE="$1" | ||
| 33 | ;; | ||
| 34 | --no-seed) SEED_DIR="" ;; | ||
| 35 | --help | -h) | ||
| 36 | head -20 "$0" | grep "^#" | sed 's/^# \?//' | ||
| 37 | exit 0 | ||
| 38 | ;; | ||
| 39 | *) | ||
| 40 | IMG="$1" | ||
| 41 | ;; | ||
| 42 | esac | ||
| 43 | shift | ||
| 44 | done | ||
| 45 | |||
| 46 | if [ -f "$IMG" ] && [ "$FRESH" -eq 0 ]; then | ||
| 47 | echo "mkdisk: $IMG already exists (use --fresh to re-format)" | ||
| 48 | exit 0 | ||
| 49 | fi | ||
| 50 | |||
| 51 | if ! command -v mkfs.fat >/dev/null 2>&1; then | ||
| 52 | echo "mkdisk: mkfs.fat not found — install dosfstools (sudo apt install dosfstools)" >&2 | ||
| 53 | exit 1 | ||
| 54 | fi | ||
| 55 | |||
| 56 | # mkfs.fat sizes are 1024-byte blocks; accept M/G/K suffixes too. | ||
| 57 | case "$SIZE" in | ||
| 58 | *G) SIZE_BLOCKS=$(( ${SIZE%G} * 1024 * 1024 )) ;; | ||
| 59 | *M) SIZE_BLOCKS=$(( ${SIZE%M} * 1024 )) ;; | ||
| 60 | *K) SIZE_BLOCKS=$(( ${SIZE%K} )) ;; | ||
| 61 | *) SIZE_BLOCKS="$SIZE" ;; | ||
| 62 | esac | ||
| 63 | if [ -z "$SIZE_BLOCKS" ] || [ "$SIZE_BLOCKS" -le 0 ] 2>/dev/null; then | ||
| 64 | echo "mkdisk: bad size '$SIZE' (use e.g. 64M or 65536)" >&2 | ||
| 65 | exit 1 | ||
| 66 | fi | ||
| 67 | |||
| 68 | echo "mkdisk: creating $IMG ($SIZE FAT32, label RSDOS)" | ||
| 69 | rm -f "$IMG" | ||
| 70 | mkfs.fat -C -F 32 -n RSDOS "$IMG" "$SIZE_BLOCKS" | ||
| 71 | |||
| 72 | if [ -n "$SEED_DIR" ] && [ -d "$SEED_DIR" ]; then | ||
| 73 | if ! command -v mcopy >/dev/null 2>&1; then | ||
| 74 | echo "mkdisk: warning: mcopy not found — skipping seed files (install mtools)" >&2 | ||
| 75 | else | ||
| 76 | echo "mkdisk: seeding from $SEED_DIR/" | ||
| 77 | for f in "$SEED_DIR"/*; do | ||
| 78 | [ -f "$f" ] || continue | ||
| 79 | mcopy -i "$IMG" "$f" "::/$(basename "$f")" | ||
| 80 | echo " -> $(basename "$f")" | ||
| 81 | done | ||
| 82 | fi | ||
| 83 | fi | ||
| 84 | |||
| 85 | echo "mkdisk: done — boot with: make run (or: ./scripts/boot.sh)" | ||
diff --git a/scripts/sendkeys.py b/scripts/sendkeys.py new file mode 100755 index 0000000..5d1692c --- /dev/null +++ b/scripts/sendkeys.py | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | """Type lines into a QEMU guest via the monitor's `sendkey` command. | ||
| 3 | |||
| 4 | Each positional argument is one line: it is typed character by character | ||
| 5 | (US layout) followed by Enter. Use it to drive the rs-dos shell from a | ||
| 6 | test script without a display. | ||
| 7 | |||
| 8 | Usage: | ||
| 9 | sendkeys.py "ls /disk" "echo hi > /disk/a.txt" "poweroff" | ||
| 10 | sendkeys.py --sock /tmp/qmon.sock "date" | ||
| 11 | |||
| 12 | Environment: QMON_SOCK (default: /tmp/qmon.sock) | ||
| 13 | """ | ||
| 14 | import os | ||
| 15 | import socket | ||
| 16 | import sys | ||
| 17 | import time | ||
| 18 | |||
| 19 | SOCK = os.environ.get("QMON_SOCK", "/tmp/qmon.sock") | ||
| 20 | |||
| 21 | # Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are | ||
| 22 | # not valid sendkey names (and '-' is the modifier separator). | ||
| 23 | BASE = { | ||
| 24 | "-": "minus", "=": "equal", "[": "bracketleft", "]": "bracketright", | ||
| 25 | "\\": "backslash", ";": "semicolon", "'": "apostrophe", | ||
| 26 | ",": "comma", ".": "dot", "/": "slash", "`": "grave", | ||
| 27 | } | ||
| 28 | |||
| 29 | # Characters that need a shift key on US layout, and the key QEMU's | ||
| 30 | # `sendkey` understands for them. | ||
| 31 | SHIFT = { | ||
| 32 | "~": "grave", "!": "1", "@": "2", "#": "3", "$": "4", "%": "5", | ||
| 33 | "^": "6", "&": "7", "*": "8", "(": "9", ")": "0", | ||
| 34 | "_": "minus", "+": "equal", "{": "bracketleft", "}": "bracketright", | ||
| 35 | "|": "backslash", ":": "semicolon", '"': "apostrophe", | ||
| 36 | "<": "comma", ">": "dot", "?": "slash", | ||
| 37 | } | ||
| 38 | |||
| 39 | ALNUM = set("abcdefghijklmnopqrstuvwxyz0123456789") | ||
| 40 | |||
| 41 | |||
| 42 | def connect(path, timeout=60): | ||
| 43 | """Connect to the monitor socket, retrying until QEMU is up.""" | ||
| 44 | deadline = time.time() + timeout | ||
| 45 | while True: | ||
| 46 | try: | ||
| 47 | s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 48 | s.connect(path) | ||
| 49 | return s | ||
| 50 | except OSError: | ||
| 51 | if time.time() > deadline: | ||
| 52 | raise | ||
| 53 | time.sleep(0.2) | ||
| 54 | |||
| 55 | |||
| 56 | def sendkey(sock, keys): | ||
| 57 | sock.sendall(("sendkey %s\n" % keys).encode()) | ||
| 58 | |||
| 59 | |||
| 60 | def type_line(sock, line): | ||
| 61 | for ch in line: | ||
| 62 | if ch == " ": | ||
| 63 | sendkey(sock, "spc") | ||
| 64 | elif ch in BASE: | ||
| 65 | sendkey(sock, BASE[ch]) | ||
| 66 | elif ch in SHIFT: | ||
| 67 | sendkey(sock, "shift-" + SHIFT[ch]) | ||
| 68 | elif ch.isupper(): | ||
| 69 | sendkey(sock, "shift-" + ch.lower()) | ||
| 70 | elif ch in ALNUM: | ||
| 71 | sendkey(sock, ch) | ||
| 72 | else: | ||
| 73 | sys.stderr.write("warning: no sendkey mapping for %r\n" % ch) | ||
| 74 | continue | ||
| 75 | time.sleep(0.05) | ||
| 76 | sendkey(sock, "ret") | ||
| 77 | time.sleep(0.7) | ||
| 78 | |||
| 79 | |||
| 80 | def main(): | ||
| 81 | args = [a for a in sys.argv[1:] if a != "--sock"] | ||
| 82 | sock_path = SOCK | ||
| 83 | if "--sock" in sys.argv: | ||
| 84 | i = sys.argv.index("--sock") | ||
| 85 | sock_path = sys.argv[i + 1] | ||
| 86 | args = sys.argv[i + 2:] | ||
| 87 | if not args: | ||
| 88 | sys.stderr.write(__doc__ or "") | ||
| 89 | return 1 | ||
| 90 | sock = connect(sock_path) | ||
| 91 | # Let the monitor drain any startup banner before typing. | ||
| 92 | time.sleep(0.5) | ||
| 93 | for line in args: | ||
| 94 | try: | ||
| 95 | type_line(sock, line) | ||
| 96 | except OSError: | ||
| 97 | # Guest powered off (last line was usually "poweroff"). | ||
| 98 | break | ||
| 99 | return 0 | ||
| 100 | |||
| 101 | |||
| 102 | if __name__ == "__main__": | ||
| 103 | sys.exit(main()) | ||
diff --git a/scripts/test-disk.sh b/scripts/test-disk.sh new file mode 100755 index 0000000..f7be7c6 --- /dev/null +++ b/scripts/test-disk.sh | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/test-disk.sh — full automated data-disk round trip. | ||
| 4 | # | ||
| 5 | # Builds the kernel, ensures the FAT32 image exists (with --fresh it is | ||
| 6 | # re-formatted and re-seeded), boots QEMU headless, drives the shell via | ||
| 7 | # the monitor, then verifies the results with mtools and fsck. | ||
| 8 | # | ||
| 9 | # Usage: | ||
| 10 | # ./scripts/test-disk.sh # reuse existing image | ||
| 11 | # ./scripts/test-disk.sh --fresh # re-format the image first | ||
| 12 | # | ||
| 13 | # Environment: | ||
| 14 | # DISK_IMG data disk path (default: /tmp/disk.img) | ||
| 15 | # OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) | ||
| 16 | # QEMU qemu binary (default: qemu-system-x86_64) | ||
| 17 | # | ||
| 18 | set -euo pipefail | ||
| 19 | |||
| 20 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| 21 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | ||
| 22 | cd "$PROJECT_DIR" | ||
| 23 | |||
| 24 | FRESH=0 | ||
| 25 | [ "${1:-}" = "--fresh" ] && FRESH=1 | ||
| 26 | |||
| 27 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | ||
| 28 | QEMU="${QEMU:-qemu-system-x86_64}" | ||
| 29 | IMG="${DISK_IMG:-/tmp/disk.img}" | ||
| 30 | ESP_DIR="$PROJECT_DIR/esp" | ||
| 31 | QPID=/tmp/rsdos-test-qpid | ||
| 32 | SOCK=/tmp/rsdos-test-qmon.sock | ||
| 33 | LOG=/tmp/rsdos-test-serial.log | ||
| 34 | STAMP="$(date +%s)" | ||
| 35 | |||
| 36 | fail() { | ||
| 37 | echo "FAIL: $1" | ||
| 38 | [ -f "$LOG" ] && tail -20 "$LOG" | ||
| 39 | exit 1 | ||
| 40 | } | ||
| 41 | |||
| 42 | # wait_log FILE PATTERN TIMEOUT-SECONDS — poll a file for a regex. | ||
| 43 | wait_log() { | ||
| 44 | local i=0 | ||
| 45 | while [ "$i" -lt $(( ${3:-60} * 10 )) ]; do | ||
| 46 | grep -q "$2" "$1" 2>/dev/null && return 0 | ||
| 47 | sleep 0.1 | ||
| 48 | i=$((i + 1)) | ||
| 49 | done | ||
| 50 | return 1 | ||
| 51 | } | ||
| 52 | |||
| 53 | # wait_qemu_exit TIMEOUT-SECONDS — poll until the pid is gone. | ||
| 54 | wait_qemu_exit() { | ||
| 55 | local i=0 | ||
| 56 | while [ "$i" -lt $(( ${1:-30} * 10 )) ]; do | ||
| 57 | kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 | ||
| 58 | sleep 0.1 | ||
| 59 | i=$((i + 1)) | ||
| 60 | done | ||
| 61 | return 1 | ||
| 62 | } | ||
| 63 | |||
| 64 | echo "==> 1/6 build kernel (debug)" | ||
| 65 | cargo build --package rsdos --target x86_64-unknown-uefi | ||
| 66 | |||
| 67 | echo "==> 2/6 deploy to ESP + ensure disk image" | ||
| 68 | mkdir -p "$ESP_DIR/EFI/BOOT" | ||
| 69 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | ||
| 70 | "$SCRIPT_DIR/mkdisk.sh" $([ "$FRESH" -eq 1 ] && echo --fresh) "$IMG" | ||
| 71 | |||
| 72 | echo "==> 3/6 boot QEMU (headless)" | ||
| 73 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | ||
| 74 | sleep 1 | ||
| 75 | rm -f "$SOCK" "$LOG" | ||
| 76 | "$QEMU" -bios "$OVMF" \ | ||
| 77 | -drive file="$IMG",format=raw,if=none,id=disk \ | ||
| 78 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 79 | -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ | ||
| 80 | -device ide-hd,drive=esp,bus=ide.1 \ | ||
| 81 | -serial file:"$LOG" \ | ||
| 82 | -monitor unix:"$SOCK",server,nowait \ | ||
| 83 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none & | ||
| 84 | echo $! > "$QPID" | ||
| 85 | |||
| 86 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | ||
| 87 | sleep 1 | ||
| 88 | |||
| 89 | echo "==> 4/6 drive the shell (ls / mkdir / echo > / cat / poweroff)" | ||
| 90 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 91 | "ls /disk" \ | ||
| 92 | "mkdir /disk/sub" \ | ||
| 93 | "echo disk-test-$STAMP > /disk/sub/hello.txt" \ | ||
| 94 | "cat /disk/sub/hello.txt" \ | ||
| 95 | "poweroff" | ||
| 96 | |||
| 97 | echo "==> 5/6 wait for shutdown" | ||
| 98 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 99 | |||
| 100 | echo "==> 6/6 verify" | ||
| 101 | grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log" | ||
| 102 | if ! fsck.fat -n "$IMG" >/tmp/rsdos-fsck.out 2>&1; then | ||
| 103 | fail "fsck.fat reports problems: $(cat /tmp/rsdos-fsck.out | tail -3)" | ||
| 104 | fi | ||
| 105 | MT="$(mtype -i "$IMG" "::/sub/hello.txt" 2>/dev/null || true)" | ||
| 106 | [ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'" | ||
| 107 | |||
| 108 | echo "" | ||
| 109 | echo "PASS — disk round trip OK (fsck clean, file survived poweroff)" | ||
| 110 | echo " image: $IMG" | ||
| 111 | echo " written: /disk/sub/hello.txt = \"disk-test-$STAMP\"" | ||
diff --git a/seed/lines.txt b/seed/lines.txt new file mode 100644 index 0000000..719197f --- /dev/null +++ b/seed/lines.txt | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | the quick brown fox jumps over the lazy dog | ||
| 2 | the quick brown fox jumps over the lazy dog | ||
| 3 | the quick brown fox jumps over the lazy dog | ||
| 4 | line 4: a slightly longer line to exercise multi-cluster reads | ||
| 5 | line 5: rs-dos persistence test — power off and back on | ||
| 6 | line 6: hello from the disk | ||
diff --git a/seed/motd.txt b/seed/motd.txt new file mode 100644 index 0000000..ac960fa --- /dev/null +++ b/seed/motd.txt | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | Welcome to rs-dos! | ||
| 2 | |||
| 3 | This file lives on the FAT32 data disk (the one mounted at /disk). | ||
| 4 | The kernel mounts the first valid FAT32 volume it finds — create or | ||
| 5 | re-seed this image with: | ||
| 6 | |||
| 7 | make disk # create if missing (default /tmp/disk.img) | ||
| 8 | make disk-fresh # re-format + re-seed from seed/ | ||
| 9 | |||
| 10 | Everything written from the shell survives reboots: it's a real disk, | ||
| 11 | not RAM. | ||
