Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/physics-mv/blob/main/m3/build.sh # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `physics-mv / m3 / build.sh` 117 lines ยท 4167 bytes Raw Blame History 1 #!/bin/sh 2 # m3/build.sh -- Python-free build system for PHYSICS M3 image and qualification tools. 3 # 4 # Outputs under m3/build/ (gitignored). Never touches repo-root M2 files. 5 # sha256_clean.c is compiled from repo root (audited source, not forked). 6 # Deterministic: no timestamps, --build-id=none, prefix mapped to "." 7 set -eu 8 9 M3=$(cd "$(dirname "$0")" && pwd -P) 10 ROOT=$(cd "$M3/.." && pwd -P) 11 OUT=$M3/build 12 13 CROSS=${CROSS:-aarch64-linux-gnu-} 14 CC=${CC:-${CROSS}gcc} 15 AS=${AS:-${CROSS}as} 16 LD=${LD:-${CROSS}ld} 17 OBJCOPY=${OBJCOPY:-${CROSS}objcopy} 18 NM=${NM:-${CROSS}nm} 19 SIZE=${SIZE:-${CROSS}size} 20 HOSTCC=${HOSTCC:-gcc} 21 QEMU=${QEMU:-qemu-system-aarch64} 22 23 PREFIX_MAP="-ffile-prefix-map=$ROOT=." 24 CFLAGS_TARGET="-O2 -mstrict-align -mgeneral-regs-only -ffreestanding -nostdlib \ 25 -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-stack-protector $PREFIX_MAP" 26 ASFLAGS="" 27 LDFLAGS="-nostdlib --build-id=none -z noexecstack" 28 HOSTCFLAGS="-O2 -std=c11 -Wall -Wextra -Werror $PREFIX_MAP" 29 30 M3_KERNEL_SRCS="sha256_be.s capability.s receipt_ledger.s replay_cache.s memory_alloc.s vector_table.s effect_broker.s physics.s" 31 M3_TEST_SRCS="tests/test_m3_authority.s tests/sha256_kat.s tests/kat_stub.s" 32 33 mkdir -p "$OUT/obj" 34 cd "$ROOT" 35 36 toolver() { "$@" 2>&1 | head -n 1; } 37 { 38 echo "cc: $(toolver "$CC" --version)" 39 echo "as: $(toolver "$AS" --version)" 40 echo "ld: $(toolver "$LD" --version)" 41 echo "objcopy: $(toolver "$OBJCOPY" --version)" 42 echo "hostcc: $(toolver "$HOSTCC" --version)" 43 echo "qemu: $(toolver "$QEMU" --version)" 44 } > "$OUT/toolchain.txt" 45 46 # 1. Audited SHA-256, compiled from repo root 47 "$CC" $CFLAGS_TARGET -c sha256_clean.c -o "$OUT/obj/sha256_clean.o" 48 undef=$("$NM" -u "$OUT/obj/sha256_clean.o") 49 if [ -n "$undef" ]; then 50 echo "build.sh: sha256_clean.o has undefined symbols:" >&2 51 echo "$undef" >&2; exit 1 52 fi 53 54 # 2. Build host tool m3tool 55 "$HOSTCC" $HOSTCFLAGS -o "$OUT/m3tool" m3/tools/m3tool.c sha256_clean.c 56 57 # 3. Assemble all M3 kernel and test sources 58 for s in $M3_KERNEL_SRCS $M3_TEST_SRCS; do 59 o=$OUT/obj/$(basename "$s" .s).o 60 "$AS" $ASFLAGS "m3/$s" -o "$o" 61 done 62 "$AS" $ASFLAGS --defsym KAT_FAULT_PROBE=1 m3/tests/sha256_kat.s -o "$OUT/obj/sha256_kat_fault.o" 63 64 # 4. Link KAT tests (standalone SHA-256 verification) 65 link_kat() { 66 "$LD" $LDFLAGS -T m3/tests/kat.ld -o "$OUT/$2.elf" \ 67 "$1" "$OUT/obj/sha256_be.o" "$OUT/obj/sha256_clean.o" 68 "$OBJCOPY" -O binary "$OUT/$2.elf" "$OUT/$2.bin" 69 } 70 link_kat "$OUT/obj/sha256_kat.o" kat 71 link_kat "$OUT/obj/sha256_kat_fault.o" kat_fault 72 "$LD" $LDFLAGS -Ttext=0 -e _start -o "$OUT/kat_stub.elf" "$OUT/obj/kat_stub.o" 73 "$OBJCOPY" -O binary "$OUT/kat_stub.elf" "$OUT/kat_stub.bin" 74 75 # 5. Link Canonical M3 Physics Kernel: physics.elf and physics.bin 76 KERNEL_OBJS="$OUT/obj/physics.o \ 77 $OUT/obj/vector_table.o \ 78 $OUT/obj/capability.o \ 79 $OUT/obj/receipt_ledger.o \ 80 $OUT/obj/replay_cache.o \ 81 $OUT/obj/memory_alloc.o \ 82 $OUT/obj/effect_broker.o \ 83 $OUT/obj/test_m3_authority.o \ 84 $OUT/obj/sha256_be.o \ 85 $OUT/obj/sha256_clean.o" 86 87 "$LD" $LDFLAGS -T m3/physics.ld $KERNEL_OBJS -o "$OUT/physics.elf" 88 "$OBJCOPY" -O binary "$OUT/physics.elf" "$OUT/physics.bin" 89 90 # Check binary size 91 PHYS_SIZE=$(wc -c < "$OUT/physics.bin") 92 if [ "$PHYS_SIZE" -ne 18432 ]; then 93 echo "build.sh: physics.bin size is $PHYS_SIZE (expected 18432 bytes)" >&2 94 exit 1 95 fi 96 97 # 6. Generate pinned digest include for Atlas 98 "$OUT/m3tool" pin-inc "$OUT/physics.bin" "$OUT/m3_physics_pin.inc" 99 100 # 7. Assemble and link Atlas M3 bootstrap seed: atlas_m3.bin 101 "$AS" $ASFLAGS -I"$OUT" m3/atlas_m3.s -o "$OUT/obj/atlas_m3.o" 102 "$LD" $LDFLAGS -Ttext=0x00000000 "$OUT/obj/atlas_m3.o" "$OUT/obj/sha256_clean.o" -o "$OUT/atlas_m3.elf" 103 "$OBJCOPY" -O binary "$OUT/atlas_m3.elf" "$OUT/atlas_m3.bin" 104 105 # 8. Produce size and accounting report 106 { 107 echo "=== M3 OBJECT SIZES ===" 108 ( cd "$OUT/obj" && "$SIZE" -A *.o ) 109 echo "" 110 echo "=== M3 ELF IMAGES ===" 111 ( cd "$OUT" && "$SIZE" physics.elf atlas_m3.elf kat.elf ) 112 echo "" 113 echo "=== M3 BINARY SIZES ===" 114 ls -l "$OUT/physics.bin" "$OUT/atlas_m3.bin" "$OUT/kat.bin" 115 } > "$OUT/sizes.txt" 116 117 echo "build.sh: OK -> $OUT (physics.bin: $PHYS_SIZE bytes, atlas_m3.bin: $(wc -c < "$OUT/atlas_m3.bin") bytes)"