From d9fe082ef07b6e5c599585d6911dbad2bbe4c787 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 2 Aug 2026 02:16:40 +0200 Subject: v0.5.5: fix real-hardware boot crash — shadow back in heap as first allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User's machine: boot reached 'rsnix: boot done — shell' then panicked 'len is 0, index 0' at the first cell write — CELLS (the vt grid) was valid at vt::init and empty at the first shell paint, i.e. something stomped the heap between vt::init and the shell banner. The only change in that window vs the working v0.5.3 was the v0.5.4 move of the 1.9 MB display shadow from the heap to the fb-aware page allocator: on this machine's memory layout the page-allocator shadow's fill loop (480K words) clobbered the heap's vt vectors. - Shadow is again the *first* heap allocation, in gop::init before vt::init builds its grids (the v0.5.3 layout that provably boots on the user's hardware) — nothing else in the heap can collide with it. - init_heap now splits the free list at the GOP framebuffer hole instead of subtracting its size from one block that still *spanned* the hole — no heap allocation of any size can land on the display. - Kept the panic-proof try_reserve + fb-overlap rejection + no-shadow warning band; dropped the late init_shadow() call in main.rs. - Verified on QEMU: shadow @ 0x1980020 origin=heap, allocated before vt::init, fb clean at 0x80000000; all 5 suites PASS; 0 warnings. --- scripts/build-image-release.sh | 99 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/build-image-release.sh (limited to 'scripts/build-image-release.sh') diff --git a/scripts/build-image-release.sh b/scripts/build-image-release.sh new file mode 100755 index 0000000..32f8f91 --- /dev/null +++ b/scripts/build-image-release.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# +# scripts/build-image.sh — assemble a bootable rs-dos disk image (UEFI/GPT) +# +# Layout: +# Partition 1: ESP (FAT32) — rsboot bootloader + kernel +# +# Output: +# rs-dos.img (or custom path) — bootable raw disk image for UEFI +# +# Usage: +# ./scripts/build-image.sh [output.img] +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" + +cd "$PROJECT_DIR" + +BUILD_DIR="$PROJECT_DIR/build" +ESP_DIR="$PROJECT_DIR/esp" + +IMAGE="${1:-$PROJECT_DIR/rs-dos.img}" +TARGET=x86_64-unknown-uefi +PROFILE=release +OUT_DIR="target/${TARGET}/${PROFILE}" + +BOOTLOADER="$BUILD_DIR/bootloader/BOOTX64.EFI" +KERNEL="$OUT_DIR/rsdos.efi" +BZIMAGE="$ESP_DIR/bzImage" +INITRD="$ESP_DIR/initramfs.cpio.gz" +BOOT_EFI="$ESP_DIR/EFI/BOOT/BOOTX64.EFI" + +ESP_START=2048 # 1 MiB offset (standard alignment) +ESP_SIZE_MB=64 + +IMAGE_SIZE_MB=$((ESP_SIZE_MB + 2)) # ESP + GPT gap + backup + +# ---- checks ---- +for cmd in sfdisk mkfs.vfat mcopy truncate dd; do + if ! command -v "$cmd" &>/dev/null; then + echo "Error: $cmd not found" + exit 1 + fi +done + +# ---- build kernel ---- +echo "[1/4] Building kernel..." +cargo build --release --package rsdos --target x86_64-unknown-uefi ${CARGO_FLAGS:-} + +# ---- build bootloader ---- +echo "[2/4] Building bootloader..." +if [ ! -f "$BOOTLOADER" ]; then + "$SCRIPT_DIR/build-bootloader.sh" +fi + +# ---- assemble ESP ---- +echo "[3/4] Assembling ESP..." +mkdir -p "$ESP_DIR/EFI/BOOT" +cp "$KERNEL" "$BZIMAGE" +cp "$BOOTLOADER" "$BOOT_EFI" +if [ ! -f "$INITRD" ]; then + printf '' | gzip >"$INITRD" +fi + +# ---- create disk image ---- +echo "[4/4] Writing disk image..." +rm -f "$IMAGE" +truncate -s "${IMAGE_SIZE_MB}M" "$IMAGE" + +# GPT partition table: single EFI System partition +sfdisk --quiet "$IMAGE" </dev/null 2>&1 + +# Copy files into FAT +mmd -i "$ESP_IMG" ::/EFI 2>/dev/null || true +mmd -i "$ESP_IMG" ::/EFI/BOOT 2>/dev/null || true +mcopy -i "$ESP_IMG" "$BOOT_EFI" ::/EFI/BOOT/BOOTX64.EFI +mcopy -i "$ESP_IMG" "$BZIMAGE" ::/bzImage 2>/dev/null || true +mcopy -i "$ESP_IMG" "$INITRD" ::/initramfs.cpio.gz 2>/dev/null || true + +# Inject FAT into image at partition offset +dd if="$ESP_IMG" of="$IMAGE" bs=512 seek="$ESP_START" conv=notrunc 2>/dev/null +rm -f "$ESP_IMG" + +echo "" +echo "=== Done: $IMAGE ===" +ls -lh "$IMAGE" +echo "" +echo "Boot with: ./scripts/boot-image.sh" +echo "USB: sudo dd if=$IMAGE of=/dev/sdX bs=4M status=progress" -- cgit v1.2.3