From 76103215711d268b4b02f62e900f2be3032cf295 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 02:18:30 +0200 Subject: Initial commit: raisernics toy kernel - Bare-metal x86_64 UEFI kernel (PE32+, no libc) - GOP framebuffer + 8x16 bitmap font - PS/2 keyboard (polling, scancode set 1) - UART 16550 serial driver (COM1, 115200 8N1) - Bump allocator as #[global_allocator] (alloc::String, Vec, format!) - UEFI memory map capture (static buffer, ADR 0001) - Shell with 7 commands (help, echo, clear, hello, info, mem, halt) - Dual output: GOP framebuffer + serial console - Makefile: run, run-gui, debug, release, image targets - tools/: qemu.sh, boot-image.sh, debug-kernel.py --- tools/boot-image.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 tools/boot-image.sh (limited to 'tools/boot-image.sh') diff --git a/tools/boot-image.sh b/tools/boot-image.sh new file mode 100755 index 0000000..2592afa --- /dev/null +++ b/tools/boot-image.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# ============================================================================= +# tools/boot-image.sh — Create a bootable disk image from the ESP directory +# +# Produces a raw disk image (bootable via UEFI) for dd-ing to a USB stick +# or attaching to QEMU as a hard disk. +# +# Usage: +# ./tools/boot-image.sh [output.img] +# +# Default output: raisernics.img +# ============================================================================= +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +cd "$SCRIPT_DIR" + +OUTPUT="${1:-raisernics.img}" +ESP_DIR="${ESP_DIR:-esp}" +MBR_SZ=1 # 1 MB reserved at start for GPT/pmbr +SECTOR_SZ=512 + +# Rebuild ESP if stale +make all + +if [ ! -d "$ESP_DIR" ]; then + echo "ERROR: ESP directory '$ESP_DIR' not found. Run 'make all' first." + exit 1 +fi + +# Calculate required size: ESP contents + MBR gap + some slack +ESP_SIZE_MB=$(du -sm "$ESP_DIR" 2>/dev/null | cut -f1 || echo 1) +TOTAL_MB=$((ESP_SIZE_MB + MBR_SZ + 1)) # +1 MB slack + +echo "Creating ${TOTAL_MB} MB disk image: ${OUTPUT}" + +# Create empty image with MBR gap +dd if=/dev/zero of="$OUTPUT" bs=1M count="$TOTAL_MB" status=none 2>/dev/null + +# Partition table: single GPT partition, type EFI System (C12A7328-F81F-11D2-BA4B-00A0C93EC93B) +sgdisk --clear \ + --new=1:${MBR_SZ}M:0 \ + --typecode=1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \ + --change-name=1:"raisernics" \ + "$OUTPUT" >/dev/null + +# Find partition offset +PART_START=$(sgdisk --info=1 "$OUTPUT" 2>/dev/null | grep "Partition start sector" | awk '{print $NF}') +if [ -z "$PART_START" ]; then + PART_START=$((MBR_SZ * 1024 * 1024 / SECTOR_SZ)) +fi + +# Format as FAT32 +mformat -i "$OUTPUT"@$((PART_START * SECTOR_SZ)) -h 32 -s 32 -t "$((TOTAL_MB * 2))" >/dev/null 2>&1 || true + +# Copy the ESP contents onto the partition +mcopy -i "$OUTPUT"@$((PART_START * SECTOR_SZ)) -s "$ESP_DIR"/* ::/ 2>/dev/null + +echo " -> ${OUTPUT} ($(ls -lh "$OUTPUT" | awk '{print $5}'))" +echo "" +echo "To write to USB: sudo dd if=${OUTPUT} of=/dev/sdX bs=4M status=progress" +echo "To test with QEMU: qemu-system-x86_64 -bios -drive file=${OUTPUT},format=raw" -- cgit v1.2.3