boot-build-p1.sh (1387B)
1 #!/bin/sh 2 ## boot-build-p1.sh — in-container .P1/.M1 -> ELF. 3 ## 4 ## Pure transformation. Caller (the Makefile) ensures every fixed-path 5 ## input below already exists. Only the variable per-call inputs (source, 6 ## output binary) come in as args. 7 ## 8 ## Pipeline: 9 ## cat <P1/P1-$ARCH.M1> <src> -> /tmp/combined.M1 10 ## M0 /tmp/combined.M1 -> /tmp/prog.hex2 11 ## catm /tmp/elf.hex2 /tmp/prog.hex2 -> /tmp/linked.hex2 12 ## hex2-0 /tmp/linked.hex2 -> $OUT 13 ## 14 ## Stages through /tmp because the stage0 tools do one syscall per byte; 15 ## virtiofs round-trips would dominate otherwise. 16 ## 17 ## Env: ARCH=aarch64|amd64|riscv64 18 ## Usage: boot-build-p1.sh <src> <out> 19 20 set -eu 21 22 : "${ARCH:?ARCH must be set}" 23 [ "$#" -eq 2 ] || { echo "usage: ARCH=<arch> $0 <src> <out>" >&2; exit 2; } 24 25 SRC=$1 26 OUT=$2 27 28 TABLE=P1/P1-$ARCH.M1 29 ELF_HDR=vendor/seed/$ARCH/ELF.hex2 30 TOOLS=build/$ARCH/tools 31 NAME=$(basename "$SRC" | sed 's/\.[^.]*$//') 32 WORK=build/$ARCH/.work/$NAME 33 mkdir -p "$WORK" "$(dirname "$OUT")" 34 35 cat "$TABLE" "$SRC" > /tmp/combined.M1 36 "$TOOLS/M0" /tmp/combined.M1 /tmp/prog.hex2 37 38 cp "$ELF_HDR" /tmp/elf.hex2 39 "$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 40 "$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin 41 42 cp /tmp/combined.M1 "$WORK/combined.M1" 43 cp /tmp/prog.hex2 "$WORK/prog.hex2" 44 cp /tmp/linked.hex2 "$WORK/linked.hex2" 45 cp /tmp/prog.bin "$OUT" 46 chmod 0700 "$OUT"