boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

boot6.sh (3148B)


      1 #!/bin/sh
      2 ## boot6.sh — build the seed-kernel ELF/Image with boot4's tcc3.
      3 ##
      4 ## Drives tcc3 to compile + link the seed kernel directly: no `ld -T
      5 ## kernel.lds`, no objcopy. aarch64 emits the flat Image QEMU expects;
      6 ## amd64/riscv64 emit the ELF consumed by QEMU's -kernel path.
      7 ##
      8 ## ─── Inputs (sources, from canonical tree) ───────────────────────────
      9 ##   build/$ARCH/src/src/kernel/arch/$ARCH/{kernel.S, mmu.c, arch.h}
     10 ##   build/$ARCH/src/src/kernel/kernel.c
     11 ##   build/$ARCH/src/src/tcc/cc/mem.c
     12 ##
     13 ## ─── Inputs (binaries from prior stages) ──────────────────────────────
     14 ##   build/$ARCH/$DRIVER/boot4/tcc3
     15 ##   build/$ARCH/$DRIVER/boot2/scheme1
     16 ##
     17 ## ─── Tools ────────────────────────────────────────────────────────────
     18 ##   scheme1 evaluates the prep-time run.scm at
     19 ##   build/$ARCH/src/run/boot6.scm (generated by
     20 ##   bootprep/boot6-gen-runscm.sh) against the flat staging root.
     21 ##
     22 ## ─── Outputs ─────────────────────────────────────────────────────────
     23 ##   build/$ARCH/$DRIVER/boot6/$KERNEL_NAME
     24 ##     aarch64: Image — flat boot Image, byte-format identical to the gcc
     25 ##              Makefile's `objcopy -O binary` output. QEMU's `-kernel`
     26 ##              detects `ARM\x64` magic at file offset 0x38 and follows
     27 ##              the arm64 boot protocol, putting DTB phys in x0 before
     28 ##              jumping to _start.
     29 ##     amd64/riscv64: kernel.elf — ELF consumed via QEMU's -kernel path.
     30 ##
     31 ## Usage: boot/boot6.sh <arch>
     32 ##   <arch> ∈ {aarch64, amd64, riscv64} for either DRIVER (default podman).
     33 
     34 set -eu
     35 
     36 . boot/lib-arch.sh
     37 bootlib_init boot6 "${1:-}"
     38 driver_init empty
     39 require_src
     40 
     41 BOOT2=build/$ARCH/$DRIVER/boot2
     42 BOOT4=build/$ARCH/$DRIVER/boot4
     43 SRC=build/$ARCH/src
     44 
     45 # ── prerequisites ─────────────────────────────────────────────────────
     46 require_prev "$BOOT4" tcc3
     47 require_prev "$BOOT2" scheme1
     48 for f in kernel/arch/$ARCH/kernel.S kernel/arch/$ARCH/mmu.c kernel/arch/$ARCH/arch.h kernel/kernel.c tcc/cc/mem.c; do
     49     require_file "$SRC/src/$f"
     50 done
     51 
     52 # ── stage inputs and run scheme1 + run.scm under $DRIVER ──────────────
     53 . boot/lib-runscm.sh
     54 runscm_init "$STAGE" "$OUT"
     55 runscm_runscm "$SRC/run/boot6.scm"
     56 
     57 runscm_scheme1 "$BOOT2/scheme1"
     58 runscm_prelude "$SRC/src/scheme1/prelude.scm"
     59 
     60 runscm_input tcc3       "$BOOT4/tcc3"
     61 runscm_input_from_src "kernel/arch/$ARCH/kernel.S"
     62 runscm_input_from_src kernel/kernel.c
     63 runscm_input_from_src "kernel/arch/$ARCH/arch.h"
     64 runscm_input_from_src "kernel/arch/$ARCH/mmu.c"
     65 runscm_input_from_src tcc/cc/mem.c
     66 
     67 runscm_export "$KERNEL_NAME"
     68 runscm_run "${BOOT6_TIMEOUT:-1200}"
     69 
     70 echo "[$BOOT_TAG] OK -> $OUT/$KERNEL_NAME ($(wc -c <"$OUT/$KERNEL_NAME") bytes)"