From 7958276c9f0d230053520ba20f2a00f5ecda18e4 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 1 Nov 2026 15:53:29 +0100 Subject: scripts: rebuild the dev loop around build.sh/run.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `make` did not parse at all (missing separator at line 139), so every make target was dead. The folder also carried three overlapping launchers (boot.sh, qemu.sh, boot-image.sh) plus a fourth partial one in the Makefile, `cargo build --package rsdos` copy-pasted eight times, the QEMU invocation copy-pasted per script, and the test helpers (fail/wait_log/wait_qemu_exit/qemu_hmp) duplicated in five tests. New layout: - scripts/lib.sh: single config (image, OVMF, mem/smp), the one cargo invocation (build_all), the one QEMU shape (qemu_args), and the test harness (test_boot, wait_log, wait_qemu_exit, qemu_hmp, sendkeys) - scripts/build.sh: kernel + every bins/* in one pass - scripts/mksystem.sh: freshness-aware image build that now stages every bins/*.efi into /bin/cli|gui (they were never copied before) - scripts/run.sh: build + stage + boot in one command; --headless, --debug (GDB stub), --monitor (HMP socket), --fresh, --mem/--smp/ --bios/--image; on Wayland it auto-selects XWayland plus grab-on-hover so the mouse can be captured (Ctrl+Alt+G toggles) - scripts/tests/: the five automated tests on the shared harness - deleted: boot.sh, qemu.sh, boot-image.sh, lib-boot-args.sh, build-image-release.sh, build-bootloader.sh (rsboot chain dropped) The Makefile is now a thin wrapper: make run, make test, make system, make inspect, make help. Two-command flow: ./scripts/build.sh then ./scripts/run.sh (run.sh alone also works). Stale test assumptions fixed so the suite is green again: test-gfx waited for "gfx: check" while the shell prints "gfx check: PASS"; test-mouse/test-msg hardcoded msgrecv = task 3 (wm-input took slot 3 — ids are parsed from the log now); the queue-full probe targeted task 0, whose exec pump drains its own queue as completion codes (moved to the cursor task, which never recvs). Verified in QEMU: make test -> test-disk, test-gfx, test-mouse, test-msg, test-fault all PASS. --- Makefile | 217 ++++++++++++++++++++------------------------------------------- 1 file changed, 67 insertions(+), 150 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d18a78a..ee9755f 100644 --- a/Makefile +++ b/Makefile @@ -1,176 +1,93 @@ -# shellcheck shell=sh disable=SC2046,SC2091,SC2086,SC2155 +# Thin wrapper over scripts/ — all real logic lives in scripts/*.sh, with +# shared config and helpers in scripts/lib.sh. `make help` lists targets. +# # NOTE: $(VAR) in this file is MAKE syntax, not shell substitution. -export TARGET=x86_64-unknown-uefi -export PROFILE=release -export OUT_DIR=target/$(TARGET)/$(PROFILE) -export ESP_DIR=esp -export KERNEL=$(OUT_DIR)/rsdos.efi -export BZIMAGE=$(ESP_DIR)/bzImage -export INITRD=$(ESP_DIR)/initramfs.cpio.gz -export BOOTLOADER=rsboot/rsboot.efi -export OVMF=/usr/share/edk2/x64/OVMF.4m.fd -export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI -# Attach the single dd-able system image as the SATA drive (ide.0). -# Create/re-create with: make system-fresh (or: ./scripts/mksystem.sh --force) -export SYSTEM_IMG ?= /tmp/system.img - - -# ---- Build --------------------------------------------------------------- - -.PHONY: all run run-gui clean image debug release fmt bootloader boot-image system system-fresh inspect test-disk test-mouse test-gfx test-fault test-msg - -release: PROFILE=release -release: export PROFILE=release -release: export OUT_DIR=target/$(TARGET)/release -release: CARGO_FLAGS=--release -release: all - -# CARGO_FLAGS set by PROFILE above -CARGO_FLAGS=--release - -$(OUT_DIR)/rsdos.efi: $(shell find rsnix shell rsdos -name '*.rs') Cargo.toml rsnix/Cargo.toml shell/Cargo.toml rsdos/Cargo.toml - cargo build --package rsdos --target $(TARGET) $(CARGO_FLAGS) - -$(BZIMAGE): $(KERNEL) | $(ESP_DIR) - cp "$<" "$@" - -$(ESP_DIR): - mkdir -p $(ESP_DIR) - -$(INITRD): | $(ESP_DIR) - printf '' | gzip > "$@" - -# ---- QEMU runners -------------------------------------------------------- - -run: all system - qemu-system-x86_64 \ - -bios $(OVMF) \ - -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ - -device ide-hd,drive=disk,bus=ide.0 \ - -serial stdio \ - -m 256M \ - -machine q35 \ - -cpu qemu64 \ - -no-reboot \ - -display none - -run-gui: all system - qemu-system-x86_64 \ - -bios $(OVMF) \ - -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ - -device ide-hd,drive=disk,bus=ide.0 \ - -serial stdio \ - -m 256M \ - -machine q35 \ - -cpu qemu64 \ - -no-reboot \ - -vga std - -# GDB stub on :1234 -debug: all system - qemu-system-x86_64 \ - -bios $(OVMF) \ - -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ - -device ide-hd,drive=disk,bus=ide.0 \ - -serial stdio \ - -m 256M \ - -machine q35 \ - -cpu qemu64 \ - -no-reboot \ - -display none \ - -s -S - -# Boot from a raw disk image (delegates to boot-image.sh which builds the -# full chain if the image doesn't exist yet) -run-image: all - -# ---- System image -------------------------------------------------------- - -# One dd-able FAT32 image: kernel + ESP + /etc + /bin + seed data. -# Stamp rule: rebuilt only when the kernel or this script changes — an -# up-to-date image is NEVER touched, so files written at runtime survive. + +SYSTEM_IMG ?= /tmp/system.img + +.PHONY: all build run run-headless debug system system-fresh inspect \ + test test-disk test-fault test-gfx test-mouse test-msg fmt clean help + +# ---- build ---------------------------------------------------------------- + +all: build + +build: + ./scripts/build.sh + +# ---- boot ----------------------------------------------------------------- + +# Build + stage the image + boot QEMU (window + serial on stdio). +run: + ./scripts/run.sh + +# Serial console only, no window. +run-headless: + ./scripts/run.sh --headless + +# GDB stub on :1234, CPU paused (attach: gdb -x scripts/debug-kernel.py). +debug: + ./scripts/run.sh --debug + +# ---- system image --------------------------------------------------------- + +# Stage the image if it is stale (runtime files survive). system: - @if [ ! -f "$(SYSTEM_IMG)" ] || [ "$$(stat -c %Y $(BZIMAGE) 2>/dev/null || echo 0)" -gt "$$(stat -c %Y $(SYSTEM_IMG) 2>/dev/null || echo 0)" ]; then \ - ./scripts/mksystem.sh --force "$(SYSTEM_IMG)"; \ - else \ - echo "system image up to date: $(SYSTEM_IMG)"; \ - fi + ./scripts/mksystem.sh -# Re-create the system image from scratch (wipes runtime data). +# Re-create the image from scratch (wipes runtime data). system-fresh: - ./scripts/mksystem.sh --force "$(SYSTEM_IMG)" + ./scripts/mksystem.sh --force -# List the system image contents with mtools (requires mtools). +# List the image contents (needs mtools: sudo apt install mtools). inspect: - @command -v mdir >/dev/null 2>&1 || (echo "inspect needs mtools: sudo apt install mtools"; exit 1) @mdir -i "$(SYSTEM_IMG)" :: -# Full automated round trip: build -> boot -> shell commands -> poweroff -# -> fsck + mtools verification. -test-disk: - ./scripts/test-disk.sh +# ---- tests ---------------------------------------------------------------- -# Automated PS/2 mouse round trip: boot -> inject mouse_move/mouse_button -# via the monitor -> verify /dev/mouse + the `mouse` stream -> poweroff. -test-mouse: - ./scripts/test-mouse.sh +test: test-disk test-gfx test-mouse test-msg test-fault -test-gfx: - ./scripts/test-gfx.sh +test-disk: + ./scripts/tests/test-disk.sh -# Fault-diagnostics round trip: boot -> `fault` (deliberate page fault) -> -# verify the full dump (vec/err/rip/cr2/task) hits serial + screen -> halt. test-fault: - ./scripts/test-fault.sh - -# Automated scheduler message-queue round trip: msgrecv/send, real-input -# routing into a task's queue, queue-full boundary. -test-msg: - ./scripts/test-msg.sh - -# ---- Full boot chain ----------------------------------------------------- + ./scripts/tests/test-fault.sh -# Build bootloader only (rsboot submodule) -bootloader: - ./scripts/build-bootloader.sh +test-gfx: + ./scripts/tests/test-gfx.sh -# Build the full boot chain disk image (kernel + bootloader) -image: all -./scripts/mksystem.sh --chain rs-dos.img +test-mouse: + ./scripts/tests/test-mouse.sh -# Boot the full chain disk image (builds it first if needed) -boot-image: all - ./scripts/boot-image.sh rs-dos.img +test-msg: + ./scripts/tests/test-msg.sh -# ---- Utilities ----------------------------------------------------------- +# ---- utilities ------------------------------------------------------------ fmt: cargo fmt clean: cargo clean - rm -rf $(ESP_DIR) help: - @echo "rs-dos — Make targets" + @echo "raisernics — make targets" @echo "" - @echo " make build kernel + ESP (default)" - @echo " make release build with --release (smaller binary)" - @echo " make bootloader build rsboot from source" - @echo " make image build full chain disk image (bootloader + kernel)" - @echo " make boot-image build + boot full chain via QEMU" - @echo " make run QEMU serial console (direct boot, no bootloader)" - @echo " make system create the system image if stale/missing (/tmp/system.img)" - @echo " make system-fresh re-create the system image (wipes runtime data)" - @echo " make inspect list system image contents (mtools)" - @echo " make test-disk automated disk round trip (build->boot->fsck)" - @echo " make clean remove build artifacts" + @echo " make build kernel + /bin binaries (release)" + @echo " make run build + stage image + boot QEMU (window)" + @echo " make run-headless same, serial console only" + @echo " make debug same, GDB stub on :1234 (CPU paused)" + @echo " make system stage the system image if stale" + @echo " make system-fresh re-create the system image (wipes data)" + @echo " make inspect list image contents (mtools)" + @echo " make test run every automated test" + @echo " make test-disk disk round trip (build -> boot -> fsck)" + @echo " make test-gfx graphics self-test" + @echo " make test-mouse PS/2 mouse + cursor tracking" + @echo " make test-msg scheduler message queues" + @echo " make test-fault fault dump (screen + serial)" @echo " make fmt format Rust source" - @echo " ./scripts/mksystem.sh build the dd-able system image" - @echo " ./scripts/boot.sh quick direct boot (dev loop)" - @echo " ./scripts/test-disk.sh automated disk round trip" - @echo " ./scripts/sendkeys.py type into QEMU via the monitor" - @echo " ./scripts/boot-image.sh boot full chain (builds if needed)" - @echo " ./scripts/build-bootloader.sh build rsboot from source" - @echo " ./scripts/qemu.sh flexible QEMU launcher" - @echo " ./scripts/debug-kernel.py GDB plugin (attach after 'make debug')" + @echo " make clean remove build artifacts" + @echo "" + @echo "Two-command flow: ./scripts/build.sh && ./scripts/run.sh" + @echo "Scripts: build.sh run.sh mksystem.sh lib.sh tests/" -- cgit v1.2.3