diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 217 |
1 files changed, 67 insertions, 150 deletions
| @@ -1,176 +1,93 @@ | |||
| 1 | # shellcheck shell=sh disable=SC2046,SC2091,SC2086,SC2155 | 1 | # Thin wrapper over scripts/ — all real logic lives in scripts/*.sh, with |
| 2 | # shared config and helpers in scripts/lib.sh. `make help` lists targets. | ||
| 3 | # | ||
| 2 | # NOTE: $(VAR) in this file is MAKE syntax, not shell substitution. | 4 | # NOTE: $(VAR) in this file is MAKE syntax, not shell substitution. |
| 3 | export TARGET=x86_64-unknown-uefi | 5 | |
| 4 | export PROFILE=release | 6 | SYSTEM_IMG ?= /tmp/system.img |
| 5 | export OUT_DIR=target/$(TARGET)/$(PROFILE) | 7 | |
| 6 | export ESP_DIR=esp | 8 | .PHONY: all build run run-headless debug system system-fresh inspect \ |
| 7 | export KERNEL=$(OUT_DIR)/rsdos.efi | 9 | test test-disk test-fault test-gfx test-mouse test-msg fmt clean help |
| 8 | export BZIMAGE=$(ESP_DIR)/bzImage | 10 | |
| 9 | export INITRD=$(ESP_DIR)/initramfs.cpio.gz | 11 | # ---- build ---------------------------------------------------------------- |
| 10 | export BOOTLOADER=rsboot/rsboot.efi | 12 | |
| 11 | export OVMF=/usr/share/edk2/x64/OVMF.4m.fd | 13 | all: build |
| 12 | export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI | 14 | |
| 13 | # Attach the single dd-able system image as the SATA drive (ide.0). | 15 | build: |
| 14 | # Create/re-create with: make system-fresh (or: ./scripts/mksystem.sh --force) | 16 | ./scripts/build.sh |
| 15 | export SYSTEM_IMG ?= /tmp/system.img | 17 | |
| 16 | 18 | # ---- boot ----------------------------------------------------------------- | |
| 17 | 19 | ||
| 18 | # ---- Build --------------------------------------------------------------- | 20 | # Build + stage the image + boot QEMU (window + serial on stdio). |
| 19 | 21 | run: | |
| 20 | .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 | 22 | ./scripts/run.sh |
| 21 | 23 | ||
| 22 | release: PROFILE=release | 24 | # Serial console only, no window. |
| 23 | release: export PROFILE=release | 25 | run-headless: |
| 24 | release: export OUT_DIR=target/$(TARGET)/release | 26 | ./scripts/run.sh --headless |
| 25 | release: CARGO_FLAGS=--release | 27 | |
| 26 | release: all | 28 | # GDB stub on :1234, CPU paused (attach: gdb -x scripts/debug-kernel.py). |
| 27 | 29 | debug: | |
| 28 | # CARGO_FLAGS set by PROFILE above | 30 | ./scripts/run.sh --debug |
| 29 | CARGO_FLAGS=--release | 31 | |
| 30 | 32 | # ---- system image --------------------------------------------------------- | |
| 31 | $(OUT_DIR)/rsdos.efi: $(shell find rsnix shell rsdos -name '*.rs') Cargo.toml rsnix/Cargo.toml shell/Cargo.toml rsdos/Cargo.toml | 33 | |
| 32 | cargo build --package rsdos --target $(TARGET) $(CARGO_FLAGS) | 34 | # Stage the image if it is stale (runtime files survive). |
| 33 | |||
| 34 | $(BZIMAGE): $(KERNEL) | $(ESP_DIR) | ||
| 35 | cp "$<" "$@" | ||
| 36 | |||
| 37 | $(ESP_DIR): | ||
| 38 | mkdir -p $(ESP_DIR) | ||
| 39 | |||
| 40 | $(INITRD): | $(ESP_DIR) | ||
| 41 | printf '' | gzip > "$@" | ||
| 42 | |||
| 43 | # ---- QEMU runners -------------------------------------------------------- | ||
| 44 | |||
| 45 | run: all system | ||
| 46 | qemu-system-x86_64 \ | ||
| 47 | -bios $(OVMF) \ | ||
| 48 | -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ | ||
| 49 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 50 | -serial stdio \ | ||
| 51 | -m 256M \ | ||
| 52 | -machine q35 \ | ||
| 53 | -cpu qemu64 \ | ||
| 54 | -no-reboot \ | ||
| 55 | -display none | ||
| 56 | |||
| 57 | run-gui: all system | ||
| 58 | qemu-system-x86_64 \ | ||
| 59 | -bios $(OVMF) \ | ||
| 60 | -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ | ||
| 61 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 62 | -serial stdio \ | ||
| 63 | -m 256M \ | ||
| 64 | -machine q35 \ | ||
| 65 | -cpu qemu64 \ | ||
| 66 | -no-reboot \ | ||
| 67 | -vga std | ||
| 68 | |||
| 69 | # GDB stub on :1234 | ||
| 70 | debug: all system | ||
| 71 | qemu-system-x86_64 \ | ||
| 72 | -bios $(OVMF) \ | ||
| 73 | -drive file=$(SYSTEM_IMG),format=raw,if=none,id=disk \ | ||
| 74 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 75 | -serial stdio \ | ||
| 76 | -m 256M \ | ||
| 77 | -machine q35 \ | ||
| 78 | -cpu qemu64 \ | ||
| 79 | -no-reboot \ | ||
| 80 | -display none \ | ||
| 81 | -s -S | ||
| 82 | |||
| 83 | # Boot from a raw disk image (delegates to boot-image.sh which builds the | ||
| 84 | # full chain if the image doesn't exist yet) | ||
| 85 | run-image: all | ||
| 86 | |||
| 87 | # ---- System image -------------------------------------------------------- | ||
| 88 | |||
| 89 | # One dd-able FAT32 image: kernel + ESP + /etc + /bin + seed data. | ||
| 90 | # Stamp rule: rebuilt only when the kernel or this script changes — an | ||
| 91 | # up-to-date image is NEVER touched, so files written at runtime survive. | ||
| 92 | system: | 35 | system: |
| 93 | @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 \ | 36 | ./scripts/mksystem.sh |
| 94 | ./scripts/mksystem.sh --force "$(SYSTEM_IMG)"; \ | ||
| 95 | else \ | ||
| 96 | echo "system image up to date: $(SYSTEM_IMG)"; \ | ||
| 97 | fi | ||
| 98 | 37 | ||
| 99 | # Re-create the system image from scratch (wipes runtime data). | 38 | # Re-create the image from scratch (wipes runtime data). |
| 100 | system-fresh: | 39 | system-fresh: |
| 101 | ./scripts/mksystem.sh --force "$(SYSTEM_IMG)" | 40 | ./scripts/mksystem.sh --force |
| 102 | 41 | ||
| 103 | # List the system image contents with mtools (requires mtools). | 42 | # List the image contents (needs mtools: sudo apt install mtools). |
| 104 | inspect: | 43 | inspect: |
| 105 | @command -v mdir >/dev/null 2>&1 || (echo "inspect needs mtools: sudo apt install mtools"; exit 1) | ||
| 106 | @mdir -i "$(SYSTEM_IMG)" :: | 44 | @mdir -i "$(SYSTEM_IMG)" :: |
| 107 | 45 | ||
| 108 | # Full automated round trip: build -> boot -> shell commands -> poweroff | 46 | # ---- tests ---------------------------------------------------------------- |
| 109 | # -> fsck + mtools verification. | ||
| 110 | test-disk: | ||
| 111 | ./scripts/test-disk.sh | ||
| 112 | 47 | ||
| 113 | # Automated PS/2 mouse round trip: boot -> inject mouse_move/mouse_button | 48 | test: test-disk test-gfx test-mouse test-msg test-fault |
| 114 | # via the monitor -> verify /dev/mouse + the `mouse` stream -> poweroff. | ||
| 115 | test-mouse: | ||
| 116 | ./scripts/test-mouse.sh | ||
| 117 | 49 | ||
| 118 | test-gfx: | 50 | test-disk: |
| 119 | ./scripts/test-gfx.sh | 51 | ./scripts/tests/test-disk.sh |
| 120 | 52 | ||
| 121 | # Fault-diagnostics round trip: boot -> `fault` (deliberate page fault) -> | ||
| 122 | # verify the full dump (vec/err/rip/cr2/task) hits serial + screen -> halt. | ||
| 123 | test-fault: | 53 | test-fault: |
| 124 | ./scripts/test-fault.sh | 54 | ./scripts/tests/test-fault.sh |
| 125 | |||
| 126 | # Automated scheduler message-queue round trip: msgrecv/send, real-input | ||
| 127 | # routing into a task's queue, queue-full boundary. | ||
| 128 | test-msg: | ||
| 129 | ./scripts/test-msg.sh | ||
| 130 | |||
| 131 | # ---- Full boot chain ----------------------------------------------------- | ||
| 132 | 55 | ||
| 133 | # Build bootloader only (rsboot submodule) | 56 | test-gfx: |
| 134 | bootloader: | 57 | ./scripts/tests/test-gfx.sh |
| 135 | ./scripts/build-bootloader.sh | ||
| 136 | 58 | ||
| 137 | # Build the full boot chain disk image (kernel + bootloader) | 59 | test-mouse: |
| 138 | image: all | 60 | ./scripts/tests/test-mouse.sh |
| 139 | ./scripts/mksystem.sh --chain rs-dos.img | ||
| 140 | 61 | ||
| 141 | # Boot the full chain disk image (builds it first if needed) | 62 | test-msg: |
| 142 | boot-image: all | 63 | ./scripts/tests/test-msg.sh |
| 143 | ./scripts/boot-image.sh rs-dos.img | ||
| 144 | 64 | ||
| 145 | # ---- Utilities ----------------------------------------------------------- | 65 | # ---- utilities ------------------------------------------------------------ |
| 146 | 66 | ||
| 147 | fmt: | 67 | fmt: |
| 148 | cargo fmt | 68 | cargo fmt |
| 149 | 69 | ||
| 150 | clean: | 70 | clean: |
| 151 | cargo clean | 71 | cargo clean |
| 152 | rm -rf $(ESP_DIR) | ||
| 153 | 72 | ||
| 154 | help: | 73 | help: |
| 155 | @echo "rs-dos — Make targets" | 74 | @echo "raisernics — make targets" |
| 156 | @echo "" | 75 | @echo "" |
| 157 | @echo " make build kernel + ESP (default)" | 76 | @echo " make build kernel + /bin binaries (release)" |
| 158 | @echo " make release build with --release (smaller binary)" | 77 | @echo " make run build + stage image + boot QEMU (window)" |
| 159 | @echo " make bootloader build rsboot from source" | 78 | @echo " make run-headless same, serial console only" |
| 160 | @echo " make image build full chain disk image (bootloader + kernel)" | 79 | @echo " make debug same, GDB stub on :1234 (CPU paused)" |
| 161 | @echo " make boot-image build + boot full chain via QEMU" | 80 | @echo " make system stage the system image if stale" |
| 162 | @echo " make run QEMU serial console (direct boot, no bootloader)" | 81 | @echo " make system-fresh re-create the system image (wipes data)" |
| 163 | @echo " make system create the system image if stale/missing (/tmp/system.img)" | 82 | @echo " make inspect list image contents (mtools)" |
| 164 | @echo " make system-fresh re-create the system image (wipes runtime data)" | 83 | @echo " make test run every automated test" |
| 165 | @echo " make inspect list system image contents (mtools)" | 84 | @echo " make test-disk disk round trip (build -> boot -> fsck)" |
| 166 | @echo " make test-disk automated disk round trip (build->boot->fsck)" | 85 | @echo " make test-gfx graphics self-test" |
| 167 | @echo " make clean remove build artifacts" | 86 | @echo " make test-mouse PS/2 mouse + cursor tracking" |
| 87 | @echo " make test-msg scheduler message queues" | ||
| 88 | @echo " make test-fault fault dump (screen + serial)" | ||
| 168 | @echo " make fmt format Rust source" | 89 | @echo " make fmt format Rust source" |
| 169 | @echo " ./scripts/mksystem.sh build the dd-able system image" | 90 | @echo " make clean remove build artifacts" |
| 170 | @echo " ./scripts/boot.sh quick direct boot (dev loop)" | 91 | @echo "" |
| 171 | @echo " ./scripts/test-disk.sh automated disk round trip" | 92 | @echo "Two-command flow: ./scripts/build.sh && ./scripts/run.sh" |
| 172 | @echo " ./scripts/sendkeys.py type into QEMU via the monitor" | 93 | @echo "Scripts: build.sh run.sh mksystem.sh lib.sh tests/" |
| 173 | @echo " ./scripts/boot-image.sh boot full chain (builds if needed)" | ||
| 174 | @echo " ./scripts/build-bootloader.sh build rsboot from source" | ||
| 175 | @echo " ./scripts/qemu.sh flexible QEMU launcher" | ||
| 176 | @echo " ./scripts/debug-kernel.py GDB plugin (attach after 'make debug')" | ||
