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/aienux/blob/main/native/kernel/Makefile # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. 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 `aienux / native / kernel / Makefile` 3530 lines ยท 222784 bytes Raw Blame History 1 # AIENOS C kernel core (Lane 18): UEFI entry stub + kernel core as one 2 # AArch64 PE32+ image, plus host unit tests. Toolchain: gcc, binutils, make. 3 # 4 # make core-only image $(OUT)/BOOTAA64.EFI (stages print 5 # "not linked"; the M1 gate boots this one) 6 # make full full image with the boot stages (devices, security, 7 # Store) from stage.mk: $(OUT)/full/BOOTAA64.EFI, 8 # NVMe DMA SMMU-confined, refused without an SMMU 9 # make full CK_QEMU_UNSAFE_DMA=1 10 # TEST-ONLY QEMU image with the unconfined NVMe DMA bypass: 11 # $(OUT)/full-qemu-unsafe-dma/BOOTAA64.EFI (only 12 # scripts/qemu_ck_store_test.sh sets this; refused 13 # together with CK_HARDWARE_STAGING=1) 14 # make full CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS= CK_MACHINE_ID= 15 # hardware staging image $(OUT)/full-hardware-staging/: 16 # no TEST Store keys/uuid/machine id (refused without 17 # both files; tools/ck_owner_gen.c checks them); its 18 # Store stage refuses (production key source is 19 # BLOCKED_OPERATOR). scripts/ck_owner_keys_check.sh 20 # make full CK_SERVICE=1 CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS= CK_MACHINE_ID= CK_INFER_LIB= 21 # the production service image with resident inference, 22 # model from the boot disk only (MODEL.MAP, no fw_cfg code): 23 # $(OUT)/full-service-hardware-staging/. Staged by 24 # scripts/stage_one_time_boot_ck_service.sh; proof 25 # scripts/qemu_ck_service_disk_test.sh (aienos#34, gate N3) 26 # make full CK_TEST_XHCI_MUTATION=bm-left-on|no-revoke|grant-no-smmu|no-sweep 27 # TEST-ONLY image that breaks one xHCI DMA fence row on 28 # purpose: $(OUT)/full-test-xhci-/ (only 29 # scripts/qemu_ck_keyboard_test.sh --mutation; refused 30 # with CK_HARDWARE_STAGING=1 or CK_QEMU_UNSAFE_DMA=1) 31 # make full CK_CONSOLE_SESSION=1 [CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit] 32 # TEST-ONLY QEMU image with the final "console" boot stage 33 # (serial + USB keyboard input until "exit", no time limit): 34 # $(OUT)/full-console-session/ (the mutation image: 35 # full-test-console-mutation/, bus master left on after the 36 # exit); only scripts/qemu_ck_console_test.sh; refused with 37 # CK_HARDWARE_STAGING=1 or CK_QEMU_UNSAFE_DMA=1 38 # make full CK_TEST_STORE_CRASH=1 [CK_TEST_STORE_CRASH_MUTANT=] 39 # TEST-ONLY Store crash hook image 40 # $(OUT)/full-test-store-crash[-mutant-]/ for 41 # scripts/qemu_ck_store_crash_test.sh (M4_STORE_CRASH); 42 # refused with CK_HARDWARE_STAGING / CK_QEMU_UNSAFE_DMA 43 # make owner-gen host tool $(OUT)/host/ck_owner_gen 44 # make [full] CK_TEST_FWCFG_ARTIFACTS=1 45 # TEST-ONLY: loader takes candidates from the QEMU fw_cfg 46 # side channel instead of the boot disk Store; own OUT 47 # (target/native-kernel-test-fwcfg); announces itself and 48 # never counts toward a PASS. Default images are checked 49 # to contain no fw_cfg artifact code. 50 # make CK_TEST_ROLLBACK=bad-magic|cpu-fault|hang 51 # TEST-ONLY M0_ROLLBACK candidates (bad handoff magic, CPU 52 # fault after "kernel: alive", hang with interrupts masked); 53 # own OUT (target/native-kernel-test-rollback-); only 54 # scripts/qemu_ck_rollback_test.sh; refused with CK_HARDWARE_STAGING 55 # make uefi-vars host tool $(OUT)/host/ck_uefi_vars: reads BootOrder, BootNext 56 # and Boot#### from an edk2 vars.fd (read-only, M0_ROLLBACK) 57 # make [full] CK_B7B_PROBE=1 [CK_B7B_PROBE_TEST_SEGMENT0=1] 58 # B7b preparation probe image (aienos#286): confine the 59 # GB10 requester once, read SMMU_IDR0/IDR1, unconfine; 60 # own OUT (target/native-kernel-b7b-probe); the segment-0 61 # variant is TEST-ONLY (QEMU positive path). Gate: 62 # scripts/qemu_ck_b7b_probe_test.sh 63 # make CK_TEST_SMP_SKIP_CPU=1 64 # TEST-ONLY SMP mutation: CPU_ON skipped for one secondary 65 # core (core/smp.c); own OUT (target/native-kernel-test-smp-skip); 66 # the SMP gate must FAIL on it (scripts/qemu_ck_smp_test.sh 67 # --mutation); refused with CK_HARDWARE_STAGING 68 # make store-image host tool $(OUT)/host/ck_store_image: signed artifacts 69 # into the sealed Store inside the AIENOS GPT partition 70 # of an NVMe disk image 71 # make gpt-image host tool $(OUT)/host/ck_gpt_image: GPT boot-disk images 72 # (AIENOS partition between two sentinels, hostile variants) 73 # for the QEMU gates; "find" runs the kernel GPT parser 74 # make full CK_TEST_DISK_XLATE_BYPASS=1 75 # TEST-ONLY mutation image for the DISK_LAYOUT gate: the 76 # LBA translation layer (dev/disk_part.c) adds no partition 77 # offset; $(OUT)/full-test-xlate-bypass/ (refused with 78 # CK_HARDWARE_STAGING; never counted toward a PASS) 79 # make test host unit tests -> CK_CORE_HOST: PASS 80 # (also builds the handoff_check reserved0 mutant 81 # and requires test_handoff to FAIL against it) 82 # make sanitize same under ASan + UBSan -> CK_CORE_HOST: PASS 83 # make continuity-mutants 84 # TEST-only -D mutants of svc/continuity_codec.c must 85 # each fail test_continuity_codec -> CK_CONTINUITY_CODEC_MUTANTS: PASS 86 # make continuity-resolve-mutants 87 # TEST-only -D mutants of svc/continuity_resolve.c must each fail 88 # test_continuity_resolve -> CK_CONTINUITY_RESOLVE_MUTANTS: PASS 89 # make continuity-commit-mutants 90 # TEST-only -D mutants of svc/continuity_commit.c (and MC-11 of the codec) must 91 # each fail test_continuity_commit -> CK_CONTINUITY_COMMIT_MUTANTS: PASS 92 # make continuity-recovery-mutants 93 # TEST-only -D mutants of svc/continuity_recovery.c (MR-1, MR-5, MR-6, MR-7, MR-9) must 94 # each fail test_continuity_recovery -> CK_CONTINUITY_RECOVERY_MUTANTS: PASS 95 # make stage-test | stage-sanitize | stage-free stage host tests (stage.mk) 96 # make print-kcflags flags stage code must be built with 97 # make udp-echo host UDP echo helper for scripts/qemu_ck_net_test.sh: 98 # $(OUT)/host/ck_udp_echo (hosted, test tooling only) 99 # make slot-loader CK_SLOT_KEYS= | CK_TEST_SLOT_KEY=1 100 # SLOTLDR.EFI, the signed A/B slot loader in front of the 101 # unchanged image (native/boot/slot_loader.c, P11 cut 2a): 102 # $(OUT)/SLOTLDR.EFI; owner keys baked in from CK_SLOT_KEYS, 103 # or the TEST-ONLY RFC 8032 TEST 1 key; the TEST key is 104 # refused with CK_HARDWARE_STAGING. Gate: 105 # scripts/qemu_ck_slot_loader_test.sh 106 # make slot-loader-check build checks + refusals -> SLOT_LOADER_BUILD: PASS 107 # 108 # CK_EXTRA_CFLAGS=... extra kernel flags for one-off checks, e.g. 109 # -DCK_SELFTEST_EL2_FAULT (brk at EL2: the EL2 fatal path) 110 # The stages are weak references in ck.h (the core defines no defaults): 111 # with none linked the kernel prints "stage : not linked". 112 # 113 # Output goes to /target/native-kernel (ignored by git) unless OUT is set. 114 # Builds natively on an aarch64 host, else with the aarch64-linux-gnu- prefix. 115 # QEMU is not hardware: nothing built here is physically qualified. 116 117 KDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) 118 NATIVE := $(abspath $(KDIR)/..) 119 REPO := $(abspath $(NATIVE)/..) 120 BOOT := $(NATIVE)/boot 121 122 HOST_ARCH := $(shell uname -m) 123 ifeq ($(HOST_ARCH),aarch64) 124 CROSS ?= 125 else 126 CROSS ?= aarch64-linux-gnu- 127 endif 128 KCC := $(CROSS)gcc 129 KLD := $(CROSS)ld 130 KOBJCOPY := $(CROSS)objcopy 131 KNM := $(CROSS)nm 132 KREADELF := $(CROSS)readelf 133 HOSTCC ?= cc 134 135 # Raspberry Pi 5 board image (CK_PI5=1, "make pi5"): the core image plus 136 # core/pi5.c (PM watchdog, microSD bring-up, console log written to the 137 # card), core/klog*.c, dev/pi5_wdt.c, the PIO SD driver (native/disk) and the 138 # UEFI stub's KLOG.MAP reader (native/boot/efi_klog.c). Own OUT, so it never 139 # replaces a default image. Not for the Spark or QEMU: pi5_wdt.c and pi5.c 140 # touch BCM2712-only addresses and refuse to build without CK_PI5. 141 CK_PI5_STORE ?= 142 ifneq ($(strip $(CK_PI5_STORE)),) 143 ifneq ($(strip $(CK_PI5_STORE)),1) 144 $(error CK_PI5_STORE must be empty or 1) 145 endif 146 ifneq ($(strip $(CK_SERVICE)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_HARDWARE_STAGING)),) 147 $(error CK_PI5_STORE is the TEST-key qualification tier (SEED-0B-PI5): it cannot be combined with CK_SERVICE, CK_TEST_STORE_CRASH, CK_TEST_CONTINUITY or CK_HARDWARE_STAGING) 148 endif 149 CK_PI5 := 1 150 OUT ?= $(REPO)/target/native-kernel-pi5-store 151 CK_EXTRA_CFLAGS += -DCK_PI5_STORE=1 152 endif 153 # Pi 5 inference image (CK_PI5_INFER=1, "make pi5-infer", PI5-6 cut 2): the plain Pi image plus 154 # the Rust inference unit (CK_INFER_LIB) and core/infer.c as the one-shot boot-disk probe. Model 155 # source is MODEL.MAP only (-DCK_INFER_DISK_ONLY=1): no fw_cfg code, and with no map the kernel 156 # refuses. No Store stage, no service, no resident session. Own OUT; plain pi5 / pi5-store unchanged. 157 CK_PI5_INFER ?= 158 ifneq ($(strip $(CK_PI5_INFER)),) 159 ifneq ($(strip $(CK_PI5_INFER)),1) 160 $(error CK_PI5_INFER must be empty or 1) 161 endif 162 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_UNLOCK)$(CK_PI5_AGENT)$(CK_SERVICE)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_RUST_LIBS)),) 163 $(error CK_PI5_INFER is the one-shot Pi inference image: it cannot be combined with CK_PI5_STORE, CK_PI5_UNLOCK, CK_PI5_AGENT, CK_SERVICE, CK_HARDWARE_STAGING, CK_TEST_FWCFG_ARTIFACTS or CK_RUST_LIBS) 164 endif 165 ifeq ($(strip $(CK_INFER_LIB)),) 166 $(error CK_PI5_INFER needs CK_INFER_LIB= (use "make pi5-infer", which builds it)) 167 endif 168 CK_PI5 := 1 169 OUT ?= $(REPO)/target/native-kernel-pi5-infer 170 CK_EXTRA_CFLAGS += -DCK_PI5_INFER=1 -DCK_INFER_DISK_ONLY=1 171 endif 172 # Pi 5 PCIe/RP1 enumerator image (CK_PI5_PCIE=1, "make pi5-pcie", AIENOS-PI5 network lane step 1): the plain Pi 173 # image plus dev/pi5_pcie.c (read-only look at the BCM2712 PCIe2 root complex, RP1's config space and BARs, and 174 # the inbound DMA window judged against the ADR 0020 bounce region) and dev/dma_window.c. Own OUT; the plain 175 # pi5, pi5-store and pi5-infer images and the default image carry none of this code. 176 CK_PI5_PCIE ?= 177 ifneq ($(strip $(CK_PI5_PCIE)),) 178 ifneq ($(strip $(CK_PI5_PCIE)),1) 179 $(error CK_PI5_PCIE must be empty or 1) 180 endif 181 ifneq ($(strip $(CK_PI5_NET)$(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_UNLOCK)$(CK_PI5_AGENT)$(CK_SERVICE)$(CK_HARDWARE_STAGING)),) 182 $(error CK_PI5_PCIE is the Pi PCIe/RP1 enumerator image: it cannot be combined with CK_PI5_NET, CK_PI5_STORE, CK_PI5_INFER, CK_PI5_UNLOCK, CK_PI5_AGENT, CK_SERVICE or CK_HARDWARE_STAGING) 183 endif 184 CK_PI5 := 1 185 OUT ?= $(REPO)/target/native-kernel-pi5-pcie 186 CK_EXTRA_CFLAGS += -DCK_PI5_PCIE=1 187 endif 188 189 # Pi 5 network bring-up image (CK_PI5_NET=1, "make pi5-net", AIENOS-PI5 network lane cut 2): the plain Pi image plus 190 # dev/pi5_net.c (narrows the BCM2712 PCIe2 inbound DMA window to the ADR 0020 bounce region, then brings RP1's 191 # Ethernet up to the PHY and reads the PHY ID; no frames). Own OUT; no other image carries this code. 192 CK_PI5_NET ?= 193 ifneq ($(strip $(CK_PI5_NET)),) 194 ifneq ($(strip $(CK_PI5_NET)),1) 195 $(error CK_PI5_NET must be empty or 1) 196 endif 197 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_UNLOCK)$(CK_PI5_AGENT)$(CK_PI5_FACT)$(CK_PI5_PCIE)$(CK_SERVICE)$(CK_HARDWARE_STAGING)),) 198 $(error CK_PI5_NET is the Pi network bring-up image: it cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_UNLOCK, CK_PI5_AGENT, CK_PI5_FACT, CK_PI5_PCIE, CK_SERVICE or CK_HARDWARE_STAGING) 199 endif 200 CK_PI5 := 1 201 OUT ?= $(REPO)/target/native-kernel-pi5-net 202 CK_EXTRA_CFLAGS += -DCK_PI5_NET=1 203 endif 204 205 # Pi unlock image (CK_PI5_UNLOCK=1, "make pi5-unlock", PI5-4 cut 1): the same Store stage, but the Store opens 206 # ONLY through the ADR 0017 Slot 1 recovery-secret path (ck_store_unlock_boot, PRODUCTION-class keys). 207 # ck_store_test_keys and ck_store_test_uuid are not compiled, so no TEST key or TEST uuid can reach it. 208 # It is a separate image from CK_PI5_STORE (TEST keys) and cannot be combined with any other tier flag. 209 # PI5-4 cut 2: CK_PI5_UNLOCK_CARD=1 (QUALIFICATION ONLY, "make pi5-unlock-card") adds one secret source to the 210 # unlock image: a THROWAWAY recovery secret from \EFI\AIENOS\UNLOCK.REQ on the card (core/unlock_req.h). It 211 # needs CK_PI5_UNLOCK=1 and is a separate image with its own OUT. CK_PI5_PRODUCTION is reserved for a future 212 # production Pi image; it is not implemented and can never be combined with the card request source. 213 CK_PI5_UNLOCK_CARD ?= 214 CK_PI5_PRODUCTION ?= 215 ifneq ($(strip $(CK_PI5_PRODUCTION)),) 216 $(error CK_PI5_PRODUCTION is reserved and not implemented: there is no production Pi image yet) 217 endif 218 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) 219 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),1) 220 $(error CK_PI5_UNLOCK_CARD must be empty or 1) 221 endif 222 ifeq ($(strip $(CK_PI5_UNLOCK)),) 223 $(error CK_PI5_UNLOCK_CARD (card request file, throwaway secret, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1) 224 endif 225 endif 226 CK_PI5_UNLOCK ?= 227 ifneq ($(strip $(CK_PI5_UNLOCK)),) 228 ifneq ($(strip $(CK_PI5_UNLOCK)),1) 229 $(error CK_PI5_UNLOCK must be empty or 1) 230 endif 231 ifneq ($(strip $(CK_PI5_STORE)),) 232 $(error CK_PI5_UNLOCK (production-class keys from the recovery secret) cannot be combined with CK_PI5_STORE (public TEST keys)) 233 endif 234 ifneq ($(strip $(CK_SERVICE)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_HARDWARE_STAGING)$(CK_SERVICE_TEST_KEYS)),) 235 $(error CK_PI5_UNLOCK cannot be combined with CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_TEST_STORE_CRASH, CK_TEST_CONTINUITY or CK_HARDWARE_STAGING) 236 endif 237 CK_PI5 := 1 238 OUT ?= $(REPO)/target/native-kernel-pi5-unlock$(if $(strip $(CK_PI5_UNLOCK_CARD)),-card)$(if $(strip $(CK_PI5_FACT)),-fact)$(if $(strip $(CK_PI5_AGENT)),-agent)$(if $(strip $(CK_PI5_LIFECYCLE)),-lifecycle) 239 CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK=1 240 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) 241 CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK_CARD=1 242 endif 243 endif 244 245 # Pi Cortex fact image (CK_PI5_FACT=1, "make pi5-fact", PI5-5): the Pi unlock-card image (production-class Store 246 # opened by the Slot 1 recovery secret from the card request file) plus the Cortex fact stage (svc/pi5_fact.c): a 247 # fact from \EFI\AIENOS\FACT.REQ (QUALIFICATION ONLY, core/fact_req.h) is appended to the Cortex journal of the 248 # sealed Store, and a boot without that file recalls it. It needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1, refuses 249 # every other tier flag and has its own OUT. 250 CK_PI5_FACT ?= 251 ifneq ($(strip $(CK_PI5_FACT)),) 252 ifneq ($(strip $(CK_PI5_FACT)),1) 253 $(error CK_PI5_FACT must be empty or 1) 254 endif 255 ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) 256 $(error CK_PI5_FACT (Cortex fact stage, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) 257 endif 258 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_AGENT)$(CK_PI5_LIFECYCLE)),) 259 $(error CK_PI5_FACT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_AGENT or CK_PI5_LIFECYCLE) 260 endif 261 CK_EXTRA_CFLAGS += -DCK_PI5_FACT=1 262 endif 263 264 # Pi agent image (CK_PI5_AGENT=1, "make pi5-agent", PI5-6 final cut, QUALIFICATION ONLY while the secret comes from the card request 265 # file): the Pi unlock-card image (production-class Store opened by the Slot 1 recovery secret) plus the resident inference unit 266 # (CK_INFER_LIB, model from MODEL.MAP only) plus the agent stage (svc/pi5_agent.c): after the Store opened it recovers the persisted 267 # reply, or (no reply yet) generates a bounded reply and commits it as a sealed R1 object. It needs CK_PI5_UNLOCK=1, CK_PI5_UNLOCK_CARD=1 268 # and CK_INFER_LIB, refuses every other tier flag (CK_PI5_INFER and CK_PI5_FACT included) and has its own OUT. 269 CK_PI5_AGENT ?= 270 ifneq ($(strip $(CK_PI5_AGENT)),) 271 ifneq ($(strip $(CK_PI5_AGENT)),1) 272 $(error CK_PI5_AGENT must be empty or 1) 273 endif 274 ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) 275 $(error CK_PI5_AGENT (Store plus inference, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) 276 endif 277 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_FACT)$(CK_PI5_LIFECYCLE)$(CK_SERVICE)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)),) 278 $(error CK_PI5_AGENT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_FACT, CK_PI5_LIFECYCLE, CK_SERVICE, CK_HARDWARE_STAGING or CK_TEST_FWCFG_ARTIFACTS) 279 endif 280 ifeq ($(strip $(CK_INFER_LIB)),) 281 $(error CK_PI5_AGENT needs CK_INFER_LIB= (use "make pi5-agent", which builds it)) 282 endif 283 CK_EXTRA_CFLAGS += -DCK_PI5_AGENT=1 -DCK_INFER_DISK_ONLY=1 -DCK_INFER_RESIDENT=1 284 endif 285 286 # Pi resident-lifecycle image (CK_PI5_LIFECYCLE=1, "make pi5-lifecycle", PI5-7 cut 2, QUALIFICATION ONLY while the secret comes from the 287 # card request file): the Pi unlock-card image (production-class Store opened by the Slot 1 recovery secret) plus the resident 288 # production lifecycle (core/lifecycle.c: remember, prefer, update, recall, approve, status, help, N3 context assembly) plus the resident 289 # inference unit (CK_INFER_LIB, model from MODEL.MAP only). Nothing reads the Pi's serial port, so the lifecycle takes its lines from the 290 # card command script \EFI\AIENOS\AGENT.CMD (core/agent_cmd.h) instead of the console and then runs its stop order. The lifecycle sources 291 # are the CK_SERVICE ones (-DCK_SERVICE=1 reaches only the stage sources, see the service block below); the secret still comes from the 292 # card (unlock and rotate are not script verbs). Needs CK_PI5_UNLOCK=1, CK_PI5_UNLOCK_CARD=1 and CK_INFER_LIB, refuses every other tier 293 # flag and has its own OUT. 294 CK_PI5_LIFECYCLE ?= 295 ifneq ($(strip $(CK_PI5_LIFECYCLE)),) 296 ifneq ($(strip $(CK_PI5_LIFECYCLE)),1) 297 $(error CK_PI5_LIFECYCLE must be empty or 1) 298 endif 299 ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) 300 $(error CK_PI5_LIFECYCLE (resident lifecycle, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) 301 endif 302 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_FACT)$(CK_PI5_AGENT)$(CK_SERVICE)$(CK_SERVICE_TEST_KEYS)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)),) 303 $(error CK_PI5_LIFECYCLE cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_FACT, CK_PI5_AGENT, CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_HARDWARE_STAGING or CK_TEST_FWCFG_ARTIFACTS) 304 endif 305 ifeq ($(strip $(CK_INFER_LIB)),) 306 $(error CK_PI5_LIFECYCLE needs CK_INFER_LIB= (use "make pi5-lifecycle", which builds it)) 307 endif 308 CK_EXTRA_CFLAGS += -DCK_PI5_LIFECYCLE=1 -DCK_INFER_DISK_ONLY=1 -DCK_INFER_RESIDENT=1 309 endif 310 # EL0 artifact qualification image (CK_ARTIFACT_CARD=1, "make pi5-artifact" for the Pi, PI5-7 cut 3, QUALIFICATION ONLY, TEST keys only): 311 # the plain core image (no Store stage, no NVMe) whose signed artifact candidates come from ONE card file, \EFI\AIENOS\ARTIFACT.BND 312 # (core/artifact_card.h, read by native/boot/efi_artifact.c), and which trusts the RFC 8032 TEST 1 public key only 313 # (CK_SEED0B_TEST_ANCHOR=1, forced by CK_PI5_ARTIFACT=1; the image prints "artifact_trust: ... TEST ONLY"). CK_PI5_ARTIFACT=1 is the Pi 314 # image (CK_PI5=1); CK_ARTIFACT_CARD=1 CK_SEED0B_TEST_ANCHOR=1 alone is its QEMU twin (scripts/qemu_ck_artifact_card_test.sh). Both 315 # refuse every other tier flag (so the other images refuse it too) and the "full" image (its Store stage owns the same hook), and each 316 # has its own OUT. No other image changes: the code is behind -DCK_ARTIFACT_CARD. 317 CK_ARTIFACT_CARD ?= 318 CK_PI5_ARTIFACT ?= 319 ifneq ($(strip $(CK_PI5_ARTIFACT)),) 320 ifneq ($(strip $(CK_PI5_ARTIFACT)),1) 321 $(error CK_PI5_ARTIFACT must be empty or 1) 322 endif 323 CK_ARTIFACT_CARD := 1 324 CK_PI5 := 1 325 CK_SEED0B_TEST_ANCHOR := 1 326 OUT ?= $(REPO)/target/native-kernel-pi5-artifact 327 endif 328 ifneq ($(strip $(CK_ARTIFACT_CARD)),) 329 ifneq ($(strip $(CK_ARTIFACT_CARD)),1) 330 $(error CK_ARTIFACT_CARD must be empty or 1) 331 endif 332 ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 333 $(error CK_ARTIFACT_CARD (card artifact bundle, QUALIFICATION ONLY) needs CK_SEED0B_TEST_ANCHOR=1: it only ever trusts the public TEST key) 334 endif 335 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_UNLOCK)$(CK_PI5_UNLOCK_CARD)$(CK_PI5_FACT)$(CK_PI5_AGENT)$(CK_PI5_LIFECYCLE)$(CK_SERVICE)$(CK_SERVICE_TEST_KEYS)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_INFER_LIB)),) 336 $(error CK_ARTIFACT_CARD / CK_PI5_ARTIFACT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_UNLOCK, CK_PI5_UNLOCK_CARD, CK_PI5_FACT, CK_PI5_AGENT, CK_PI5_LIFECYCLE, CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_HARDWARE_STAGING, CK_TEST_FWCFG_ARTIFACTS or CK_INFER_LIB) 337 endif 338 ifneq ($(filter full,$(MAKECMDGOALS)),) 339 $(error CK_ARTIFACT_CARD / CK_PI5_ARTIFACT build the core image only: the "full" image's Store stage owns the artifact hook) 340 endif 341 OUT ?= $(REPO)/target/native-kernel-artifact-card 342 CK_EXTRA_CFLAGS += -DCK_ARTIFACT_CARD=1 343 endif 344 # Pi 5 ALLEN exam image (CK_PI5_ALLEN=1, "make pi5-allen", PI5-8 cut K, QUALIFICATION ONLY): the plain Pi image plus the 345 # ALLEN exam stage (CK_ALLEN below). Own OUT; every other image carries none of this code. 346 CK_PI5_ALLEN ?= 347 ifneq ($(strip $(CK_PI5_ALLEN)),) 348 ifneq ($(strip $(CK_PI5_ALLEN)),1) 349 $(error CK_PI5_ALLEN must be empty or 1) 350 endif 351 CK_ALLEN := 1 352 CK_PI5 := 1 353 OUT ?= $(REPO)/target/native-kernel-pi5-allen 354 endif 355 # ALLEN exam stage (CK_ALLEN=1, PI5-8 cut K): links the ALLEN REFLEX decision core (CK_ALLEN_LIB=, 356 # crates/allen-reflex-kernel) and compiles core/allen.c, core/allen_gate.c (+ the card command parser and the lifecycle 357 # state machine it judges with) and the UEFI stub's exam file reader (native/boot/efi_allen.c). The core image only: no 358 # Store stage, no service, nothing written. Without CK_PI5 it is the QEMU twin (scripts/qemu_ck_allen_reflex_test.sh). 359 # CK_ALLEN_HEAP_KIB sets the Rust heap region (default 32768 KiB = 32 MiB; the QEMU twin also builds a small one to prove 360 # that exhaustion stops the run). Not combinable with another Rust staticlib (CK_INFER_LIB, CK_RUST_LIBS: two Rust 361 # staticlibs duplicate compiler_builtins) or with any other tier. 362 CK_ALLEN ?= 363 CK_ALLEN_HEAP_KIB ?= 32768 364 ifneq ($(strip $(CK_ALLEN)),) 365 ifneq ($(strip $(CK_ALLEN)),1) 366 $(error CK_ALLEN must be empty or 1) 367 endif 368 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_UNLOCK)$(CK_PI5_UNLOCK_CARD)$(CK_PI5_FACT)$(CK_PI5_AGENT)$(CK_PI5_LIFECYCLE)$(CK_PI5_ARTIFACT)$(CK_ARTIFACT_CARD)$(CK_SERVICE)$(CK_SERVICE_TEST_KEYS)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_INFER_LIB)$(CK_RUST_LIBS)),) 369 $(error CK_ALLEN / CK_PI5_ALLEN cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_UNLOCK, CK_PI5_UNLOCK_CARD, CK_PI5_FACT, CK_PI5_AGENT, CK_PI5_LIFECYCLE, CK_PI5_ARTIFACT, CK_ARTIFACT_CARD, CK_SERVICE, CK_SERVICE_TEST_KEYS, CK_HARDWARE_STAGING, CK_TEST_FWCFG_ARTIFACTS, CK_INFER_LIB or CK_RUST_LIBS) 370 endif 371 ifeq ($(strip $(CK_ALLEN_LIB)),) 372 $(error CK_ALLEN needs CK_ALLEN_LIB= (use "make pi5-allen", which builds it)) 373 endif 374 ifneq ($(filter full,$(MAKECMDGOALS)),) 375 $(error CK_ALLEN / CK_PI5_ALLEN build the core image only: no Store stage) 376 endif 377 ifeq ($(shell echo '$(CK_ALLEN_HEAP_KIB)' | grep -xE '[1-9][0-9]{0,6}'),) 378 $(error CK_ALLEN_HEAP_KIB must be a whole number of KiB, 1..`9999999`) 379 endif 380 OUT ?= $(REPO)/target/native-kernel-allen 381 CK_EXTRA_CFLAGS += -DCK_ALLEN=1 -DCK_ALLEN_HEAP_KIB=$(CK_ALLEN_HEAP_KIB) 382 endif 383 CK_PI5 ?= 384 ifneq ($(strip $(CK_PI5)),) 385 ifneq ($(strip $(CK_PI5)),1) 386 $(error CK_PI5 must be empty or 1) 387 endif 388 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 389 $(error CK_PI5 cannot be combined with CK_HARDWARE_STAGING) 390 endif 391 OUT ?= $(REPO)/target/native-kernel-pi5 392 CK_EXTRA_CFLAGS += -DCK_PI5=1 -DCK_KLOG=1 393 endif 394 395 # Storage-free attended Spark input image. Compose the existing device stage, 396 # never NVMe/Store/Allen. The bounded boot shell is used; the sustained 397 # CK_CONSOLE_SESSION image remains QEMU-only. 398 CK_SPARK_INPUT ?= 399 ifneq ($(strip $(CK_SPARK_INPUT)),) 400 ifneq ($(strip $(CK_SPARK_INPUT)),1) 401 $(error CK_SPARK_INPUT must be empty or 1) 402 endif 403 ifneq ($(strip $(CK_PI5)$(CK_SERVICE)$(CK_CONSOLE_SESSION)$(CK_B7B_PROBE)$(CK_INFER_LIB)$(CK_RUST_LIBS)$(CK_QEMU_UNSAFE_DMA)$(CK_TEST_XHCI_MUTATION)$(CK_TEST_CONSOLE_MUTATION)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_ARTIFACT_CARD)),) 404 $(error CK_SPARK_INPUT is storage-free and cannot be combined with another image variant) 405 endif 406 CK_RTL8127 := 1 407 OUT ?= $(REPO)/target/native-kernel-spark-input 408 CK_EXTRA_CFLAGS += -DCK_SPARK_INPUT=1 409 endif 410 411 # Spark attended boot #2 (L198): `make full CK_RTL8127=1` ($(OUT)/full/BOOTAA64.EFI) 412 # binds the Realtek RTL8127 10 GbE (dev/rtl8127_bind.c) in the devices stage and sends the console log as UDP 413 # broadcasts (tag AIENUX-SPARK-REPORT, port 47031). Empty (default) in every 414 # QEMU gate: the binding is compiled but never called. 415 ifneq ($(strip $(CK_RTL8127)),) 416 ifneq ($(strip $(CK_RTL8127)),1) 417 $(error CK_RTL8127 must be empty or 1) 418 endif 419 ifneq ($(strip $(CK_PI5)),) 420 $(error CK_RTL8127 cannot be combined with CK_PI5) 421 endif 422 CK_EXTRA_CFLAGS += -DCK_RTL8127=1 -DCK_KLOG=1 423 endif 424 425 # TEST-ONLY artifact source: CK_TEST_FWCFG_ARTIFACTS=1 compiles the QEMU fw_cfg 426 # side channel (opt/aienos/artifacts) into the loader instead of the boot disk 427 # Store. Every image built without it is checked to contain no fw_cfg artifact 428 # code. Such an image announces itself on the console and never counts toward 429 # a PASS. Its default OUT is separate so it never replaces a default image. 430 CK_TEST_FWCFG_ARTIFACTS ?= 431 ifneq ($(strip $(CK_TEST_FWCFG_ARTIFACTS)),) 432 ifneq ($(strip $(CK_TEST_FWCFG_ARTIFACTS)),1) 433 $(error CK_TEST_FWCFG_ARTIFACTS must be empty or 1) 434 endif 435 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 436 $(error CK_TEST_FWCFG_ARTIFACTS (QEMU fw_cfg test source) cannot be combined with CK_HARDWARE_STAGING) 437 endif 438 OUT ?= $(REPO)/target/native-kernel-test-fwcfg 439 endif 440 441 # TEST-ONLY SMP mutation: CK_TEST_SMP_SKIP_CPU=1 builds a kernel that never 442 # calls PSCI CPU_ON for one secondary core (core/smp.c) but still waits for 443 # it, so the SMP gate must FAIL on it (scripts/qemu_ck_smp_test.sh 444 # --mutation). Own OUT; announces itself; refused with CK_HARDWARE_STAGING 445 # and with the fw_cfg test source. Default images are checked to carry no 446 # trace of it (smp_check). 447 CK_TEST_SMP_SKIP_CPU ?= 448 ifneq ($(strip $(CK_TEST_SMP_SKIP_CPU)),) 449 ifneq ($(strip $(CK_TEST_SMP_SKIP_CPU)),1) 450 $(error CK_TEST_SMP_SKIP_CPU must be empty or 1) 451 endif 452 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 453 $(error CK_TEST_SMP_SKIP_CPU (TEST-only SMP mutation) cannot be combined with CK_HARDWARE_STAGING) 454 endif 455 ifneq ($(strip $(CK_TEST_FWCFG_ARTIFACTS)),) 456 $(error CK_TEST_SMP_SKIP_CPU cannot be combined with CK_TEST_FWCFG_ARTIFACTS) 457 endif 458 OUT ?= $(REPO)/target/native-kernel-test-smp-skip 459 SMP_TEST_FLAGS := -DCK_TEST_SMP_SKIP_CPU=1 460 else 461 SMP_TEST_FLAGS := 462 endif 463 CK_B7B_PROBE ?= 464 CK_B7B_EVENT_READOUT ?= 465 ifneq ($(strip $(CK_B7B_EVENT_READOUT)),) 466 ifneq ($(strip $(CK_B7B_EVENT_READOUT)),1) 467 $(error CK_B7B_EVENT_READOUT must be empty or 1) 468 endif 469 ifneq ($(strip $(CK_B7B_PROBE)),1) 470 $(error CK_B7B_EVENT_READOUT requires CK_B7B_PROBE=1) 471 endif 472 OUT ?= $(REPO)/target/native-kernel-b7b-events 473 SMP_TEST_FLAGS += -DCK_B7B_EVENT_READOUT=1 474 endif 475 # B7b preparation probe (aienos#286, core/smmu_svc.c): CK_B7B_PROBE=1 builds an 476 # image that confines PCI segment 15 requester 0x100 (the Spark's GB10) once on 477 # a one-page window, prints the route and SMMU_IDR0/IDR1, and unconfines. Own 478 # OUT; allowed with CK_HARDWARE_STAGING (it is meant for the attended B7b 479 # window); refused with CK_QEMU_UNSAFE_DMA. CK_B7B_PROBE_TEST_SEGMENT0=1 480 # (TEST-ONLY, needs CK_B7B_PROBE=1) probes segment 0 for the QEMU positive path 481 # and is refused with CK_HARDWARE_STAGING. Default images are checked to carry 482 # no probe (b7b_check). Gate: scripts/qemu_ck_b7b_probe_test.sh. 483 CK_B7B_PROBE_TEST_SEGMENT0 ?= 484 ifneq ($(strip $(CK_B7B_PROBE_TEST_SEGMENT0)),) 485 ifneq ($(strip $(CK_B7B_PROBE_TEST_SEGMENT0)),1) 486 $(error CK_B7B_PROBE_TEST_SEGMENT0 must be empty or 1) 487 endif 488 ifneq ($(strip $(CK_B7B_PROBE)),1) 489 $(error CK_B7B_PROBE_TEST_SEGMENT0 needs CK_B7B_PROBE=1) 490 endif 491 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 492 $(error CK_B7B_PROBE_TEST_SEGMENT0 (TEST-only QEMU positive path) cannot be combined with CK_HARDWARE_STAGING) 493 endif 494 OUT ?= $(REPO)/target/native-kernel-test-b7b-seg0 495 SMP_TEST_FLAGS += -DCK_B7B_PROBE_TEST_SEGMENT0=1 496 endif 497 ifneq ($(strip $(CK_B7B_PROBE)),) 498 ifneq ($(strip $(CK_B7B_PROBE)),1) 499 $(error CK_B7B_PROBE must be empty or 1) 500 endif 501 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 502 $(error CK_B7B_PROBE cannot be combined with CK_QEMU_UNSAFE_DMA) 503 endif 504 OUT ?= $(REPO)/target/native-kernel-b7b-probe 505 SMP_TEST_FLAGS += -DCK_B7B_PROBE=1 506 endif 507 # TEST-ONLY stale handoff (AIENOS_CK_SCREEN negative control, 508 # scripts/qemu_ck_screen_test.sh): the stub hands the kernel a CHANDOF2 magic; 509 # the kernel must refuse it ("panic: handoff: unsupported version 2 ..."). 510 # Own OUT; announces itself; refused with CK_HARDWARE_STAGING. The default 511 # image is checked to carry no trace of it ($(ELF) rule). 512 CK_TEST_STALE_HANDOFF ?= 513 ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),) 514 ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),2) 515 $(error CK_TEST_STALE_HANDOFF must be empty or 2) 516 endif 517 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 518 $(error CK_TEST_STALE_HANDOFF (TEST-only stale handoff) cannot be combined with CK_HARDWARE_STAGING) 519 endif 520 OUT ?= $(REPO)/target/native-kernel-test-stale-handoff 521 SMP_TEST_FLAGS += -DCK_TEST_STALE_HANDOFF=2 522 endif 523 # TEST-ONLY rollback candidates (CK gate M0_ROLLBACK, 524 # scripts/qemu_ck_rollback_test.sh; docs/BOOT_HANDOFF_CONTRACT.md 7.1 rows 43-44): 525 # bad-magic the stub flips one bit of the handoff magic after 526 # ExitBootServices; the kernel must panic "handoff: bad magic" 527 # cpu-fault after "kernel: alive" the kernel executes BRK at EL1; the 528 # fault report must print and the kernel must reset 529 # hang after "kernel: alive" the kernel prints one marker and spins 530 # with interrupts masked; only an outside reset ends it 531 # Own OUT; announces itself; refused with CK_HARDWARE_STAGING. The default 532 # image is checked to carry no trace of it (rollback_check). 533 CK_TEST_ROLLBACK ?= 534 ifneq ($(strip $(CK_TEST_ROLLBACK)),) 535 ifeq ($(filter $(strip $(CK_TEST_ROLLBACK)),bad-magic cpu-fault hang),) 536 $(error CK_TEST_ROLLBACK must be empty or one of bad-magic cpu-fault hang) 537 endif 538 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 539 $(error CK_TEST_ROLLBACK (TEST-only rollback candidate) cannot be combined with CK_HARDWARE_STAGING) 540 endif 541 ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),) 542 $(error CK_TEST_ROLLBACK cannot be combined with CK_TEST_STALE_HANDOFF) 543 endif 544 OUT ?= $(REPO)/target/native-kernel-test-rollback-$(strip $(CK_TEST_ROLLBACK)) 545 SMP_TEST_FLAGS += -DCK_TEST_ROLLBACK_$(subst -,_,$(shell echo '$(strip $(CK_TEST_ROLLBACK))' | tr a-z A-Z))=1 546 endif 547 # AIENOS-NATIVE-PIPE-1 (aienos-mv#428): CK_PIPE_TEST=1 adds the TEST-ONLY pipe self-test (core/pipe_test.c, gate 548 # scripts/qemu_ck_pipe_test.sh): after "kernel: alive" it drives the pipe primitive (core/pipe.c) with a producer and a 549 # consumer task through the scheduler and prints pipe_check lines. Own OUT; announces itself; refused with 550 # CK_HARDWARE_STAGING and CK_SERVICE. Default images are checked to carry no trace of it (pipe_check). 551 CK_PIPE_TEST ?= 552 ifneq ($(strip $(CK_PIPE_TEST)),) 553 ifneq ($(strip $(CK_PIPE_TEST)),1) 554 $(error CK_PIPE_TEST must be empty or 1) 555 endif 556 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 557 $(error CK_PIPE_TEST (TEST-only pipe self-test) cannot be combined with CK_HARDWARE_STAGING) 558 endif 559 OUT ?= $(REPO)/target/native-kernel-test-pipe 560 SMP_TEST_FLAGS += -DCK_PIPE_TEST=1 561 endif 562 # SLOTLDR.EFI trusted keys (native v1 plan P11 cut 2a; native/boot/slot_loader.c, 563 # make slot-loader): 564 # CK_SLOT_KEYS= owner public keys, "owner_root_`ed25519` <64 hex>" lines 565 # (tools/ck_owner_gen.c format; ck_slot_tool keys-c refuses 566 # every known TEST key) 567 # CK_TEST_SLOT_KEY=1 TEST-ONLY: RFC 8032 TEST 1; the loader prints 568 # "slot_loader: TEST-ONLY key ..."; refused with 569 # CK_HARDWARE_STAGING and together with CK_SLOT_KEYS. 570 # Checked here, before the hardware staging owner-file checks, so the refusal 571 # names the TEST key itself. 572 CK_SLOT_KEYS ?= 573 CK_TEST_SLOT_KEY ?= 574 ifneq ($(strip $(CK_TEST_SLOT_KEY)),) 575 ifneq ($(strip $(CK_TEST_SLOT_KEY)),1) 576 $(error CK_TEST_SLOT_KEY must be empty or 1) 577 endif 578 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 579 $(error CK_TEST_SLOT_KEY (TEST-ONLY slot loader key) cannot be combined with CK_HARDWARE_STAGING) 580 endif 581 ifneq ($(strip $(CK_SLOT_KEYS)),) 582 $(error CK_TEST_SLOT_KEY and CK_SLOT_KEYS are exclusive: one trusted key source per slot loader) 583 endif 584 endif 585 586 OUT ?= $(REPO)/target/native-kernel 587 # Pi builds only (CK_PI5=1: "make pi5" and anything built on it): when a tracked 588 # file differs from HEAD the stamp ends in "-dirty", so the kernel's report 589 # ("aienos_commit: ") and the EFI itself say the image is not the bare 590 # commit. Pi hardware runs are cited as evidence; a bare hash on an image built 591 # from an edited tree would name a commit that does not contain its source. 592 # Untracked files are ignored (build output lives in untracked target/). 593 # Non-Pi builds are untouched: the suffix stays empty and git status is not run 594 # (the QEMU gates compare "aienos_commit: "). An AIENOS_COMMIT given on 595 # the command line or in the environment is used as is, with no suffix. 596 AIENOS_COMMIT_SUFFIX := 597 ifeq ($(strip $(CK_PI5)),1) 598 ifneq ($(strip $(shell GIT_OPTIONAL_LOCKS=0 git -C $(REPO) status --porcelain --untracked-files=no 2>/dev/null)),) 599 AIENOS_COMMIT_SUFFIX := -dirty 600 endif 601 endif 602 AIENOS_COMMIT ?= $(shell git -C $(REPO) rev-parse HEAD 2>/dev/null || echo unknown)$(AIENOS_COMMIT_SUFFIX) 603 604 CK_EXTRA_CFLAGS ?= 605 # Build-time DMA policy for the full image (see dev/nvme_bind.c): 606 # default SMMU-confined or refuse; 1 = TEST-ONLY QEMU unconfined bypass when 607 # no SMMU exists. Never with hardware staging. 608 CK_QEMU_UNSAFE_DMA ?= 609 CK_HARDWARE_STAGING ?= 610 611 # FP/SIMD probe (aienos#34 lane 0): CK_RUST_LIBS= 612 # links that Rust no_std staticlib into the image and compiles core/fpu.c's 613 # probe (-DCK_FPU_PROBE=1). The C compile flags stay -mgeneral-regs-only; only 614 # the Rust unit uses FP/SIMD. Empty (default) = no Rust, no FP code. QEMU 615 # gate only: never combined with hardware staging. 616 CK_RUST_LIBS ?= 617 ifneq ($(strip $(CK_RUST_LIBS)),) 618 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 619 $(error CK_RUST_LIBS (FP probe, QEMU gate only) cannot be combined with CK_HARDWARE_STAGING) 620 endif 621 CK_EXTRA_CFLAGS += -DCK_FPU_PROBE=1 622 endif 623 624 # Inference ingest probe (aienos#34 lane 4): CK_INFER_LIB= links that Rust no_std staticlib (aienos-infer + 626 # bump allocator) and compiles core/infer.c (-DCK_INFER_PROBE=1): the kernel 627 # ingests a GGUF from the boot disk (MODEL.MAP, read by the UEFI stub) or, in 628 # the QEMU images only, from fw_cfg, and calls the Rust unit. C flags stay 629 # -mgeneral-regs-only. Not combinable with CK_RUST_LIBS (two Rust staticlibs 630 # would duplicate compiler_builtins). 631 # The same image then runs the bounded session API (native v1 P06: 632 # open/prompt/step/cancel/close in crates/aienos-infer-kernel/src/session.rs). 633 # 634 # Hardware staging (native v1 P06 / gate N3, aienos#34): exactly one inference 635 # image may be built with CK_HARDWARE_STAGING, the resident production service 636 # image 637 # make full CK_SERVICE=1 CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS= 638 # CK_MACHINE_ID= CK_INFER_LIB= 639 # It gets -DCK_INFER_DISK_ONLY=1: the QEMU fw_cfg ingest is compiled out (the 640 # fwcfg_check below requires no fw_cfg code or string in the image), and with 641 # no MODEL.MAP the kernel refuses instead of looking anywhere else. The 642 # one-shot probe image (no CK_SERVICE) stays QEMU only. 643 CK_INFER_LIB ?= 644 ifneq ($(strip $(CK_INFER_LIB)),) 645 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 646 ifneq ($(strip $(CK_SERVICE)),1) 647 $(error CK_INFER_LIB with CK_HARDWARE_STAGING needs CK_SERVICE=1: only the resident service image (boot-disk model, MODEL.MAP) is a hardware inference image; the one-shot probe stays QEMU only) 648 endif 649 CK_EXTRA_CFLAGS += -DCK_INFER_DISK_ONLY=1 650 endif 651 ifneq ($(strip $(CK_RUST_LIBS)),) 652 $(error CK_INFER_LIB and CK_RUST_LIBS cannot be combined: two Rust staticlibs duplicate compiler_builtins) 653 endif 654 CK_EXTRA_CFLAGS += -DCK_INFER_PROBE=1 655 # native v1 P06 cut 2: in a service image the model and one bounded session 656 # stay resident for the lifecycle's `prompt` verb (core/lifecycle.c) instead 657 # of running the one-shot probe. Model source: the boot disk (MODEL.MAP); the 658 # QEMU test images also keep the TEST-ONLY fw_cfg fallback. 659 ifeq ($(strip $(CK_SERVICE)),1) 660 CK_EXTRA_CFLAGS += -DCK_INFER_RESIDENT=1 661 endif 662 endif 663 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 664 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 665 $(error CK_QEMU_UNSAFE_DMA (unconfined DMA, QEMU debug only) cannot be combined with CK_HARDWARE_STAGING: no SMMU confinement means no DMA) 666 endif 667 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),1) 668 $(error CK_QEMU_UNSAFE_DMA must be empty or 1) 669 endif 670 endif 671 672 # TEST-ONLY xHCI DMA fence mutations (dev/xhci_fence.h), for the self-test of 673 # scripts/qemu_ck_keyboard_test.sh --mutation only: each one breaks one 674 # keyboard DMA-safety row on purpose. Own FULL_NAME, never a hardware image. 675 CK_TEST_XHCI_MUTATION ?= 676 ifneq ($(strip $(CK_TEST_XHCI_MUTATION)),) 677 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 678 $(error CK_TEST_XHCI_MUTATION (TEST-ONLY xHCI DMA fence mutation) cannot be combined with CK_HARDWARE_STAGING) 679 endif 680 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 681 $(error CK_TEST_XHCI_MUTATION cannot be combined with CK_QEMU_UNSAFE_DMA) 682 endif 683 XHCI_MUT_NUM := $(if $(filter bm-left-on,$(CK_TEST_XHCI_MUTATION)),1,$(if $(filter no-revoke,$(CK_TEST_XHCI_MUTATION)),2,$(if $(filter grant-no-smmu,$(CK_TEST_XHCI_MUTATION)),3,$(if $(filter no-sweep,$(CK_TEST_XHCI_MUTATION)),4,)))) 684 ifeq ($(XHCI_MUT_NUM),) 685 $(error CK_TEST_XHCI_MUTATION must be one of bm-left-on no-revoke grant-no-smmu no-sweep) 686 endif 687 endif 688 689 # TEST-ONLY console session (C3-1a, dev/devices.c ck_stage_console_session): 690 # CK_CONSOLE_SESSION=1 adds a final boot stage that keeps taking serial and USB 691 # keyboard input until the shell's "exit". QEMU test image only: own FULL_NAME, 692 # refused with CK_HARDWARE_STAGING and CK_QEMU_UNSAFE_DMA. The default image 693 # carries none of it. CK_TEST_CONSOLE_MUTATION=bm-left-on-after-exit (needs 694 # CK_CONSOLE_SESSION=1) leaves the xHCI bus master on after the session exit, 695 # for the CONSOLE gate's red-before-green self-test. 696 CK_CONSOLE_SESSION ?= 697 CK_TEST_CONSOLE_MUTATION ?= 698 ifneq ($(strip $(CK_CONSOLE_SESSION)),) 699 ifneq ($(strip $(CK_CONSOLE_SESSION)),1) 700 $(error CK_CONSOLE_SESSION must be empty or 1) 701 endif 702 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 703 $(error CK_CONSOLE_SESSION (QEMU test console session) cannot be combined with CK_HARDWARE_STAGING) 704 endif 705 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 706 $(error CK_CONSOLE_SESSION cannot be combined with CK_QEMU_UNSAFE_DMA) 707 endif 708 ifneq ($(strip $(CK_TEST_XHCI_MUTATION)),) 709 $(error CK_CONSOLE_SESSION cannot be combined with CK_TEST_XHCI_MUTATION) 710 endif 711 endif 712 ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),) 713 ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),bm-left-on-after-exit) 714 $(error CK_TEST_CONSOLE_MUTATION must be bm-left-on-after-exit) 715 endif 716 ifneq ($(strip $(CK_CONSOLE_SESSION)),1) 717 $(error CK_TEST_CONSOLE_MUTATION needs CK_CONSOLE_SESSION=1) 718 endif 719 endif 720 721 # CK_SERVICE=1 builds the resident production lifecycle image (core/lifecycle.c, 722 # native v1 plan P03): after every boot stage the kernel serves bounded operator 723 # requests on the serial console until "shutdown" (Store closed, NVMe released, 724 # then reset), instead of resetting at once. Own OUT subdirectory full-service/. 725 # Allowed with CK_HARDWARE_STAGING (it is the production entry); refused with 726 # every TEST-only flag. The production key source refuses today, so this image 727 # stays LOCKED. CK_SERVICE_TEST_KEYS=1 (TEST-ONLY, full-service-testkeys/, only 728 # scripts/qemu_ck_lifecycle_test.sh) opens the Store with the TEST keys so the 729 # ready/serve/commit paths run in QEMU; refused with CK_HARDWARE_STAGING. 730 CK_SERVICE ?= 731 CK_SERVICE_TEST_KEYS ?= 732 ifneq ($(strip $(CK_SERVICE)),) 733 ifneq ($(strip $(CK_SERVICE)),1) 734 $(error CK_SERVICE must be empty or 1) 735 endif 736 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 737 $(error CK_SERVICE cannot be combined with CK_QEMU_UNSAFE_DMA) 738 endif 739 ifneq ($(strip $(CK_CONSOLE_SESSION)),) 740 $(error CK_SERVICE cannot be combined with CK_CONSOLE_SESSION) 741 endif 742 ifneq ($(strip $(CK_TEST_XHCI_MUTATION)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_TEST_FWCFG_ARTIFACTS)$(CK_TEST_SMP_SKIP_CPU)$(CK_TEST_ROLLBACK)$(CK_TEST_STALE_HANDOFF)$(CK_TEST_DISK_XLATE_BYPASS)$(CK_PIPE_TEST)),) 743 $(error CK_SERVICE cannot be combined with a CK_TEST_* flag) 744 endif 745 endif 746 ifneq ($(strip $(CK_SERVICE_TEST_KEYS)),) 747 ifneq ($(strip $(CK_SERVICE_TEST_KEYS)),1) 748 $(error CK_SERVICE_TEST_KEYS must be empty or 1) 749 endif 750 ifneq ($(strip $(CK_SERVICE)),1) 751 $(error CK_SERVICE_TEST_KEYS needs CK_SERVICE=1) 752 endif 753 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 754 $(error CK_SERVICE_TEST_KEYS (TEST keys) cannot be combined with CK_HARDWARE_STAGING) 755 endif 756 endif 757 758 # TEST-ONLY Store crash hook (svc/store_crash.h; only 759 # scripts/qemu_ck_store_crash_test.sh sets it): the Store stage reads a crash 760 # plan from the scratch unit, runs on a volatile write cache and halts at the 761 # planned checkpoint. Own OUT subdirectory; announces itself; never counts 762 # toward a PASS of M4_STORE; refused with CK_HARDWARE_STAGING and 763 # CK_QEMU_UNSAFE_DMA. CK_TEST_STORE_CRASH_MUTANT (only with it) builds a 764 # deliberately broken Store the crash gate must catch: 765 # skip_root_flush no flush between the commit record and the root write 766 # accept_bad_root_crc superblock CRC never checked 767 CK_TEST_STORE_CRASH ?= 768 CK_TEST_STORE_CRASH_MUTANT ?= 769 ifneq ($(strip $(CK_TEST_STORE_CRASH)),) 770 ifneq ($(strip $(CK_TEST_STORE_CRASH)),1) 771 $(error CK_TEST_STORE_CRASH must be empty or 1) 772 endif 773 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 774 $(error CK_TEST_STORE_CRASH (TEST-ONLY Store crash hook) cannot be combined with CK_HARDWARE_STAGING) 775 endif 776 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 777 $(error CK_TEST_STORE_CRASH (TEST-ONLY Store crash hook) cannot be combined with CK_QEMU_UNSAFE_DMA) 778 endif 779 endif 780 ifneq ($(strip $(CK_TEST_STORE_CRASH_MUTANT)),) 781 ifneq ($(strip $(CK_TEST_STORE_CRASH)),1) 782 $(error CK_TEST_STORE_CRASH_MUTANT needs CK_TEST_STORE_CRASH=1 (TEST-ONLY)) 783 endif 784 ifeq ($(strip $(CK_TEST_STORE_CRASH_MUTANT)),skip_root_flush) 785 STORE_MUTANT_FLAGS := -DCK_TEST_STORE_MUTANT_SKIP_ROOT_FLUSH=1 786 else ifeq ($(strip $(CK_TEST_STORE_CRASH_MUTANT)),accept_bad_root_crc) 787 STORE_MUTANT_FLAGS := -DCK_TEST_STORE_MUTANT_ACCEPT_BAD_ROOT_CRC=1 788 else 789 $(error CK_TEST_STORE_CRASH_MUTANT must be skip_root_flush or accept_bad_root_crc) 790 endif 791 endif 792 793 794 # TEST-ONLY continuity / Recovery Core mode selection (svc/continuity_boot.h, 795 # contract K-7; only scripts/qemu_ck_continuity_test.sh and 796 # scripts/qemu_ck_recovery_test.sh set it): the Store stage reads a mode plan 797 # from the scratch unit and runs the continuity or Recovery Core wiring instead 798 # of the boot-record commit. Own OUT subdirectory; announces itself; refused 799 # with CK_HARDWARE_STAGING, CK_QEMU_UNSAFE_DMA and CK_TEST_STORE_CRASH. 800 # CK_TEST_CONTINUITY_MUTANT (only with it) builds a deliberately broken 801 # continuity layer the gates must catch: 802 # resume_no_commit resume does not commit the new incarnation 803 # resume_provisions resume mints an identity on an unprovisioned Store 804 # degraded_is_unprovisioned a degraded mount reads as unprovisioned (MR-5) 805 # compare_16 operator response compared on 16 of 32 bytes 806 # bare_sha256 operator response is a bare SHA-256, not an HMAC 807 # subject_restore_mints restore mints an ALLEN subject when it finds none (OS-0018) 808 # subject_accept_foreign restore accepts a subject bound to another agent (MS-1) 809 CK_TEST_CONTINUITY ?= 810 CK_TEST_CONTINUITY_MUTANT ?= 811 ifneq ($(strip $(CK_TEST_CONTINUITY)),) 812 ifneq ($(strip $(CK_TEST_CONTINUITY)),1) 813 $(error CK_TEST_CONTINUITY must be empty or 1) 814 endif 815 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 816 $(error CK_TEST_CONTINUITY (TEST-ONLY continuity mode selection) cannot be combined with CK_HARDWARE_STAGING) 817 endif 818 ifneq ($(strip $(CK_QEMU_UNSAFE_DMA)),) 819 $(error CK_TEST_CONTINUITY (TEST-ONLY continuity mode selection) cannot be combined with CK_QEMU_UNSAFE_DMA) 820 endif 821 ifneq ($(strip $(CK_TEST_STORE_CRASH)),) 822 $(error CK_TEST_CONTINUITY (TEST-ONLY continuity mode selection) cannot be combined with CK_TEST_STORE_CRASH) 823 endif 824 endif 825 ifneq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),) 826 ifneq ($(strip $(CK_TEST_CONTINUITY)),1) 827 $(error CK_TEST_CONTINUITY_MUTANT needs CK_TEST_CONTINUITY=1 (TEST-ONLY)) 828 endif 829 ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),resume_no_commit) 830 CONT_MUTANT_FLAGS := -DCM_MUTANT_RESUME_NO_COMMIT=1 831 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),resume_provisions) 832 CONT_MUTANT_FLAGS := -DCM_MUTANT_RESUME_PROVISIONS=1 833 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),degraded_is_unprovisioned) 834 CONT_MUTANT_FLAGS := -DRC_MUTANT_DEGRADED_IS_UNPROVISIONED=1 835 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),compare_16) 836 CONT_MUTANT_FLAGS := -DCR_MUTANT_COMPARE_16=1 837 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),bare_sha256) 838 CONT_MUTANT_FLAGS := -DCR_MUTANT_BARE_SHA256=1 839 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),subject_restore_mints) 840 CONT_MUTANT_FLAGS := -DCS_MUTANT_RESTORE_MINTS=1 841 else ifeq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),subject_accept_foreign) 842 CONT_MUTANT_FLAGS := -DCS_MUTANT_ACCEPT_FOREIGN=1 843 else 844 $(error CK_TEST_CONTINUITY_MUTANT must be resume_no_commit, resume_provisions, degraded_is_unprovisioned, compare_16, bare_sha256, subject_restore_mints or subject_accept_foreign) 845 endif 846 endif 847 848 # Owner provisioning. The hardware staging image never embeds the TEST Store 849 # keys, the TEST store uuid or the TEST machine id: it needs owner PUBLIC 850 # material and the machine identity as files (format: tools/ck_owner_gen.c; 851 # relative paths are relative to native/kernel), checked and turned into a 852 # generated header that refuses every known TEST value. Nothing secret is 853 # read: the production Store key source stays BLOCKED_OPERATOR 854 # (svc/store_boot.c ck_store_production_keys, TRUST-1 key ceremony). 855 CK_OWNER_PUBKEYS ?= 856 CK_MACHINE_ID ?= 857 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 858 ifneq ($(strip $(CK_HARDWARE_STAGING)),1) 859 $(error CK_HARDWARE_STAGING must be empty or 1) 860 endif 861 ifeq ($(strip $(CK_OWNER_PUBKEYS)),) 862 $(error CK_HARDWARE_STAGING refuses the TEST Store keys and TEST machine id: give CK_OWNER_PUBKEYS= and CK_MACHINE_ID= (native/kernel/README.md, Owner provisioning)) 863 endif 864 ifeq ($(strip $(CK_MACHINE_ID)),) 865 $(error CK_HARDWARE_STAGING refuses the TEST Store keys and TEST machine id: give CK_OWNER_PUBKEYS= and CK_MACHINE_ID= (native/kernel/README.md, Owner provisioning)) 866 endif 867 OWNER_PUBKEYS_FILE := $(abspath $(CK_OWNER_PUBKEYS)) 868 OWNER_MACHINE_FILE := $(abspath $(CK_MACHINE_ID)) 869 ifeq ($(wildcard $(OWNER_PUBKEYS_FILE)),) 870 $(error CK_OWNER_PUBKEYS file not found: $(OWNER_PUBKEYS_FILE)) 871 endif 872 ifeq ($(wildcard $(OWNER_MACHINE_FILE)),) 873 $(error CK_MACHINE_ID file not found: $(OWNER_MACHINE_FILE)) 874 endif 875 else 876 ifneq ($(strip $(CK_OWNER_PUBKEYS)$(CK_MACHINE_ID)),) 877 $(error CK_OWNER_PUBKEYS and CK_MACHINE_ID are only used with CK_HARDWARE_STAGING=1 (the default QEMU build keeps the labelled TEST keys)) 878 endif 879 endif 880 881 # TEST-ONLY DISK_LAYOUT mutation (dev/disk_part.h): the partition translation 882 # layer is bypassed. Its own FULL_NAME; never with hardware staging. 883 CK_TEST_DISK_XLATE_BYPASS ?= 884 ifneq ($(strip $(CK_TEST_DISK_XLATE_BYPASS)),) 885 ifneq ($(strip $(CK_TEST_DISK_XLATE_BYPASS)),1) 886 $(error CK_TEST_DISK_XLATE_BYPASS must be empty or 1) 887 endif 888 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 889 $(error CK_TEST_DISK_XLATE_BYPASS (TEST-ONLY translation bypass mutation) cannot be combined with CK_HARDWARE_STAGING) 890 endif 891 endif 892 893 # SEED-0B qualification build: trusts the RFC 8032 TEST 1 public key only. 894 # TEST ONLY; never combined with hardware staging. Use its own OUT. 895 CK_SEED0B_TEST_ANCHOR ?= 896 ifneq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 897 ifneq ($(strip $(CK_SEED0B_TEST_ANCHOR)),1) 898 $(error CK_SEED0B_TEST_ANCHOR must be empty or 1) 899 endif 900 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 901 $(error CK_SEED0B_TEST_ANCHOR (TEST key trust) cannot be combined with CK_HARDWARE_STAGING) 902 endif 903 ART_TRUST_FLAGS := -DCK_SEED0B_TEST_ANCHOR=1 904 else 905 ART_TRUST_FLAGS := 906 endif 907 ifeq ($(strip $(CK_TEST_FWCFG_ARTIFACTS)),1) 908 ART_TRUST_FLAGS += -DCK_TEST_FWCFG_ARTIFACTS=1 909 endif 910 # C3-3a: the launch self-test (core/osc_admit.c) runs scripted launches of the admitted units. TEST ONLY. 911 CK_OSC_LAUNCH_TEST ?= 912 ifeq ($(strip $(CK_OSC_LAUNCH_TEST)),1) 913 ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 914 $(error CK_OSC_LAUNCH_TEST needs CK_SEED0B_TEST_ANCHOR=1 (it launches TEST-signed units)) 915 endif 916 ART_TRUST_FLAGS += -DCK_OSC_LAUNCH_TEST=1 917 endif 918 # aienos#383: the receipt self-test variant of the launch self-test (CK_OSC_LAUNCH_TEST=1 CK_OSC_RECEIPT_TEST=1) runs 919 # a fixed script of launches with valid, missing and refused realization receipts instead of the C3-3a script. 920 # TEST ONLY, QEMU only. 921 # The post-admission code byte flip (variant 3, ck_osc_receipt_test_code_flip in 922 # core/osc_admit.c) is compiled only here, and only with its own opt-in 923 # -DCK_OSC_RECEIPT_CODE_FLIP=1. Empty by default. -DCK_SEED0B_TEST_ANCHOR does 924 # not enable it. Refused in a release build (no CK_SEED0B_TEST_ANCHOR), with 925 # CK_HARDWARE_STAGING and with CK_SERVICE. core/osc_admit.c #errors on the same 926 # combinations, and also when the receipt-test define arrives without the opt-in. 927 CK_OSC_RECEIPT_TEST ?= 928 ifeq ($(strip $(CK_OSC_RECEIPT_TEST)),1) 929 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 930 $(error CK_OSC_RECEIPT_TEST (TEST-ONLY post-admission code byte flip) cannot be combined with CK_HARDWARE_STAGING) 931 endif 932 ifneq ($(strip $(CK_SERVICE)),) 933 $(error CK_OSC_RECEIPT_TEST (TEST-ONLY post-admission code byte flip) cannot be combined with CK_SERVICE) 934 endif 935 ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 936 $(error CK_OSC_RECEIPT_TEST (TEST-ONLY post-admission code byte flip) cannot be compiled into a release build) 937 endif 938 ifneq ($(strip $(CK_OSC_LAUNCH_TEST)),1) 939 $(error CK_OSC_RECEIPT_TEST needs CK_OSC_LAUNCH_TEST=1) 940 endif 941 ART_TRUST_FLAGS += -DCK_OSC_RECEIPT_TEST=1 -DCK_OSC_RECEIPT_CODE_FLIP=1 942 endif 943 # OSH-AIENOS-0: the shell-core self-test (core/osh_test.c) runs the three osh units over embedded fixture scripts and 944 # prints the step trace. TEST ONLY, QEMU only; not combined with the launch self-test. 945 CK_OSH_TEST ?= 946 OSH_TEST_C := 947 ifeq ($(strip $(CK_OSH_TEST)),1) 948 ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 949 $(error CK_OSH_TEST needs CK_SEED0B_TEST_ANCHOR=1 (it launches TEST-signed units)) 950 endif 951 ifeq ($(strip $(CK_OSC_LAUNCH_TEST)),1) 952 $(error CK_OSH_TEST and CK_OSC_LAUNCH_TEST are exclusive) 953 endif 954 ART_TRUST_FLAGS += -DCK_OSH_TEST=1 955 OSH_TEST_C := $(KDIR)/core/osh_test.c 956 # OSH-AIENOS-OP: instead of the fixture traces, drive a real capability-authorized operation (core/osh_op.c) through the same shell units. 957 CK_OSH_OP_TEST ?= 958 ifeq ($(strip $(CK_OSH_OP_TEST)),1) 959 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 960 $(error CK_OSH_OP_TEST (test-only OSH adapter with injection hooks) cannot be combined with CK_HARDWARE_STAGING) 961 endif 962 ART_TRUST_FLAGS += -DCK_OSH_OP_TEST=1 963 OSH_TEST_C += $(KDIR)/core/osh_op.c 964 endif 965 endif 966 967 # Screen hold before reset (core/console.c ck_console_fb_hold): seconds the 968 # GOP framebuffer console keeps the last report on screen before the PSCI 969 # reset, so an operator can read or photograph it. 0 (default) in every QEMU 970 # gate; scripts/stage_one_time_boot_ck.sh builds the hardware image with 120. 971 # CK_BOOT_SHOW=1: the image plays the boot sequence (ui/boot_show.c: the night, the two black holes, 972 # the chirp) on its screen after the devices stage: the VM screen (virtio-gpu) and speakers (virtio-sound) 973 # when present, else the GOP framebuffer. Compiled into every image; on for the images people use (the 974 # aienos-run VM, PC and Spark images), off by default so the QEMU gates keep their timing. 975 CK_BOOT_SHOW ?= 0 976 ifeq ($(filter 0 1,$(CK_BOOT_SHOW)),) 977 $(error CK_BOOT_SHOW must be 0 or 1) 978 endif 979 CK_FB_HOLD_S ?= 0 980 ifeq ($(shell echo '$(CK_FB_HOLD_S)' | grep -Ex '[0-9]{1,4}'),) 981 $(error CK_FB_HOLD_S must be 0..9999 seconds) 982 endif 983 984 KINC := -I$(KDIR)/include -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/arch -I$(BOOT) 985 MODULE_INC := -I$(NATIVE)/disk -I$(NATIVE)/store -I$(NATIVE)/m5 -I$(NATIVE)/crypto \ 986 -I$(NATIVE)/capability -I$(NATIVE)/argus -I$(NATIVE)/net 987 KCFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin \ 988 -fno-stack-protector -fno-tree-loop-distribute-patterns -mstrict-align \ 989 -mgeneral-regs-only -mno-outline-atomics -fno-asynchronous-unwind-tables -fpie \ 990 -fvisibility=hidden -fno-plt $(KINC) $(SMP_TEST_FLAGS) -DCK_FB_HOLD_S=$(CK_FB_HOLD_S) -DCK_BOOT_SHOW=$(CK_BOOT_SHOW) $(CK_EXTRA_CFLAGS) 991 # After CK_EXTRA_CFLAGS. gcc keeps the last -D/-U, so a -U in extra cflags 992 # cannot drop this. Set on every build that is not the qualification anchor. 993 # Nothing else reads it. osc_admit.c #errors if the code flip is combined with it. 994 ifeq ($(strip $(CK_SEED0B_TEST_ANCHOR)),) 995 KCFLAGS += -DCK_RELEASE_IMAGE=1 996 endif 997 KLDFLAGS := -nostdlib -pie --no-dynamic-linker -z norelro -z noexecstack -z max-page-size=4096 --no-warn-rwx-segments \ 998 -T $(BOOT)/image.ld 999 1000 CORE_C := $(BOOT)/efi_main.c $(BOOT)/efi_model.c $(BOOT)/efi_gop.c \ 1001 $(KDIR)/arch/exception.c $(KDIR)/arch/gic.c $(KDIR)/arch/timer.c \ 1002 $(KDIR)/core/acpi.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/acpi_platform.c $(KDIR)/core/console.c $(KDIR)/core/fbcon.c $(KDIR)/core/fmt.c \ 1003 $(KDIR)/core/kmain.c $(KDIR)/core/handoff_check.c $(KDIR)/core/libc_min.c $(KDIR)/core/report.c \ 1004 $(KDIR)/core/smmu.c $(KDIR)/core/smmu_svc.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c \ 1005 $(KDIR)/core/fpu.c $(KDIR)/core/cpufeat.c $(KDIR)/core/infer.c $(KDIR)/core/allen.c $(KDIR)/core/m3.c $(KDIR)/core/entropy.c $(KDIR)/arch/rndr.c $(KDIR)/core/smp.c \ 1006 $(KDIR)/mm/frames.c $(KDIR)/mm/heap.c $(KDIR)/mm/mmu.c $(KDIR)/mm/pt.c 1007 ifeq ($(strip $(CK_PI5)),1) 1008 CORE_C += $(BOOT)/efi_klog.c $(KDIR)/core/pi5.c $(KDIR)/core/pi5_marker.c $(KDIR)/dev/disk_part.c $(KDIR)/core/klog.c $(KDIR)/core/klog_slot.c \ 1009 $(KDIR)/dev/pi5_wdt.c $(KDIR)/dev/pi5_rng.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_sdhci.c 1010 endif 1011 ifeq ($(strip $(CK_RTL8127)),1) 1012 CORE_C += $(KDIR)/core/klog.c 1013 endif 1014 ifeq ($(strip $(CK_PI5_PCIE)),1) 1015 CORE_C += $(KDIR)/dev/pi5_pcie.c $(KDIR)/dev/dma_window.c 1016 endif 1017 ifeq ($(strip $(CK_PI5_NET)),1) 1018 CORE_C += $(KDIR)/dev/pi5_pcie.c $(KDIR)/dev/dma_window.c $(KDIR)/dev/pi5_net.c $(KDIR)/dev/pi5_gem.c 1019 endif 1020 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) 1021 CORE_C += $(BOOT)/efi_unlock.c $(KDIR)/core/unlock_req.c 1022 endif 1023 ifneq ($(strip $(CK_PI5_FACT)),) 1024 CORE_C += $(BOOT)/efi_fact.c $(KDIR)/core/fact_req.c 1025 endif 1026 ifneq ($(strip $(CK_PI5_LIFECYCLE)),) 1027 CORE_C += $(BOOT)/efi_agentcmd.c $(KDIR)/core/agent_cmd.c 1028 endif 1029 ifneq ($(strip $(CK_ALLEN)),) 1030 CORE_C += $(BOOT)/efi_allen.c $(KDIR)/core/allen_gate.c $(KDIR)/core/agent_cmd.c $(KDIR)/core/lifecycle_fsm.c 1031 endif 1032 # P2 sealed-artifact loader: format/admission/receipt (artifact/), SHA-256 1033 # (argus), Ed25519/SHA-512 (sig). Built into the core so every image carries 1034 # the loader; the TEST-anchor qualification build is CK_SEED0B_TEST_ANCHOR=1. 1035 ART_C := $(KDIR)/core/artifact_loader.c $(KDIR)/core/osc_admit.c $(KDIR)/core/osc_task.c $(KDIR)/artifact/osc_launch.c $(KDIR)/artifact/format.c $(KDIR)/artifact/admission.c \ 1036 $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(KDIR)/artifact/osc_receipt.c $(NATIVE)/argus/sha256.c $(NATIVE)/sig/sha512.c \ 1037 $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/ct.c 1038 ART_INC := -I$(KDIR)/svc/compat -I$(KDIR)/artifact -I$(NATIVE)/sig -I$(NATIVE)/argus 1039 ART_C += $(OSH_TEST_C) 1040 ifneq ($(strip $(CK_ARTIFACT_CARD)),) 1041 ART_C += $(KDIR)/core/artifact_card.c $(KDIR)/core/artifact_card_stage.c 1042 CORE_C += $(BOOT)/efi_artifact.c 1043 endif 1044 CORE_C += $(ART_C) 1045 ifeq ($(strip $(CK_PIPE_TEST)),1) 1046 CORE_C += $(KDIR)/core/pipe.c $(KDIR)/core/pipe_test.c 1047 endif 1048 CORE_S := $(BOOT)/efi_entry.S $(KDIR)/arch/vectors.S $(KDIR)/arch/m3.S $(KDIR)/arch/smp_entry.S 1049 HDRS := $(wildcard $(KDIR)/include/*.h $(KDIR)/*/*.h $(BOOT)/*.h) 1050 1051 KOBJ := $(OUT)/obj 1052 CORE_OBJS := $(patsubst $(NATIVE)/%.c,$(KOBJ)/%.o,$(CORE_C)) \ 1053 $(patsubst $(NATIVE)/%.S,$(KOBJ)/%.o,$(CORE_S)) 1054 1055 .DEFAULT_GOAL := all 1056 1057 # ---- boot stages (stage.mk: STAGE_SRCS, STAGE_CFLAGS, stage-* host targets) ---- 1058 include $(KDIR)/stage.mk 1059 ifeq ($(strip $(CK_QEMU_UNSAFE_DMA)),1) 1060 FULL_NAME := full-qemu-unsafe-dma 1061 STAGE_DMA_FLAGS := -DCK_QEMU_UNSAFE_DMA=1 1062 else 1063 FULL_NAME := full 1064 STAGE_DMA_FLAGS := 1065 endif 1066 ifneq ($(strip $(CK_TEST_XHCI_MUTATION)),) 1067 FULL_NAME := full-test-xhci-$(strip $(CK_TEST_XHCI_MUTATION)) 1068 STAGE_DMA_FLAGS += -DCK_TEST_XHCI_MUTATION=$(XHCI_MUT_NUM) 1069 endif 1070 ifeq ($(strip $(CK_CONSOLE_SESSION)),1) 1071 FULL_NAME := full-console-session 1072 STAGE_DMA_FLAGS += -DCK_CONSOLE_SESSION=1 1073 ifneq ($(strip $(CK_TEST_CONSOLE_MUTATION)),) 1074 FULL_NAME := full-test-console-mutation 1075 STAGE_DMA_FLAGS += -DCK_TEST_CONSOLE_MUTATION=1 1076 endif 1077 endif 1078 ifneq ($(strip $(CK_HARDWARE_STAGING)),) 1079 # Own OUT subdirectory: stage objects built with these flags never mix with 1080 # the default full image's objects. 1081 FULL_NAME := full-hardware-staging 1082 OWNER_HDR := $(OUT)/gen-$(FULL_NAME)/ck_owner_prov.h 1083 STAGE_DMA_FLAGS += -DCK_HARDWARE_STAGING=1 -I$(dir $(OWNER_HDR)) 1084 else 1085 OWNER_HDR := 1086 endif 1087 ifeq ($(strip $(CK_TEST_STORE_CRASH)),1) 1088 # Own OUT subdirectory: TEST hook objects never mix with a default image. 1089 ifneq ($(strip $(CK_TEST_STORE_CRASH_MUTANT)),) 1090 FULL_NAME := full-test-store-crash-mutant-$(strip $(CK_TEST_STORE_CRASH_MUTANT)) 1091 else 1092 FULL_NAME := full-test-store-crash 1093 endif 1094 STAGE_DMA_FLAGS += -DCK_TEST_STORE_CRASH=1 $(STORE_MUTANT_FLAGS) 1095 endif 1096 ifeq ($(strip $(CK_TEST_CONTINUITY)),1) 1097 # Own OUT subdirectory: TEST objects never mix with a default image. The 1098 # continuity layer is linked only here (default images carry none of it). 1099 ifneq ($(strip $(CK_TEST_CONTINUITY_MUTANT)),) 1100 FULL_NAME := full-test-continuity-mutant-$(strip $(CK_TEST_CONTINUITY_MUTANT)) 1101 else 1102 FULL_NAME := full-test-continuity 1103 endif 1104 STAGE_DMA_FLAGS += -DCK_TEST_CONTINUITY=1 $(CONT_MUTANT_FLAGS) -I$(KDIR)/core 1105 STAGE_SRCS += $(KDIR)/svc/continuity_codec.c $(KDIR)/svc/continuity_resolve.c \ 1106 $(KDIR)/svc/continuity_resolve_sealed.c $(KDIR)/svc/continuity_commit.c $(KDIR)/svc/continuity_recovery.c \ 1107 $(KDIR)/svc/continuity_boot.c $(KDIR)/svc/continuity_subject.c $(KDIR)/svc/continuity_subject_provision.c 1108 endif 1109 ifneq ($(strip $(CK_SERVICE)$(CK_PI5_LIFECYCLE)),) 1110 SVC_STAGE_BASE := $(STAGE_SRCS) 1111 # Own OUT subdirectory: service objects never mix with a diagnostic image. 1112 ifeq ($(strip $(CK_SERVICE_TEST_KEYS)),1) 1113 FULL_NAME := full-service-testkeys 1114 STAGE_DMA_FLAGS += -DCK_SERVICE=1 -DCK_SERVICE_TEST_KEYS=1 1115 else 1116 FULL_NAME := full-service$(if $(strip $(CK_HARDWARE_STAGING)),-hardware-staging,) 1117 STAGE_DMA_FLAGS += -DCK_SERVICE=1 1118 endif 1119 STAGE_SRCS += $(KDIR)/core/lifecycle.c $(KDIR)/core/lifecycle_fsm.c $(KDIR)/core/line_rx.c 1120 # N3 (aienos#329): context assembly and the exact approval binding (pure C, host-tested by test_context). 1121 STAGE_SRCS += $(KDIR)/core/context.c $(KDIR)/core/context_proposal.c 1122 # P06 cut 3: the canonical Omega Cortex store over the sealed Store (svc/cortex_journal.c). 1123 STAGE_SRCS += $(STAGE_CORTEX_SRCS) 1124 # P05 cut 1: production continuity on the service lifecycle (svc/continuity_service.c): 1125 # the continuity layer without its TEST-ONLY mode selection (continuity_boot.c) 1126 # and without the Recovery Core (continuity_recovery.c, TEST operator key). 1127 STAGE_DMA_FLAGS += -I$(KDIR)/core 1128 STAGE_SRCS += $(KDIR)/svc/continuity_codec.c $(KDIR)/svc/continuity_resolve.c \ 1129 $(KDIR)/svc/continuity_resolve_sealed.c $(KDIR)/svc/continuity_commit.c \ 1130 $(KDIR)/svc/continuity_subject.c $(KDIR)/svc/continuity_subject_provision.c $(KDIR)/svc/continuity_service.c 1131 # P11 cut 2b: kernel-side slot promotion / abandon (svc/slot_service.c) over the shared 1132 # slot decision rules and control-commit routine of SLOTLDR.EFI (native/boot). 1133 STAGE_SRCS += $(KDIR)/svc/slot_service.c $(BOOT)/slot_select.c $(BOOT)/slot_control.c 1134 # P11 cut 3: the inactive-slot updater (svc/slot_service.c verb `update`, native/boot/slot_update.c) 1135 # verifies the inbox image against the key table SLOTLDR.EFI is built with (ck_slot_tool keys-c): 1136 # RFC 8032 TEST 1 in the TEST-keys image, the Owner Root (CK_OWNER_PUBKEYS) under CK_HARDWARE_STAGING. 1137 # The plain service image gets no table and refuses every update. 1138 STAGE_SRCS += $(BOOT)/slot_update.c 1139 SVC_SLOT_KEY_SRC := $(if $(strip $(CK_SERVICE_TEST_KEYS)),--test-key,$(if $(strip $(CK_HARDWARE_STAGING)),--keys $(OWNER_PUBKEYS_FILE),)) 1140 ifneq ($(SVC_SLOT_KEY_SRC),) 1141 SVC_SLOT_KEYS_C := $(OUT)/gen-$(FULL_NAME)/svc_slot_keys.c 1142 STAGE_SRCS += $(SVC_SLOT_KEYS_C) 1143 STAGE_DMA_FLAGS += -DCK_SLOT_UPDATE_KEYS=1 1144 endif 1145 # The sources this block added: the Pi block below restarts STAGE_SRCS, the lifecycle image takes them over. 1146 SVC_STAGE_ADDED := $(filter-out $(SVC_STAGE_BASE),$(STAGE_SRCS)) 1147 endif 1148 ifeq ($(strip $(CK_TEST_DISK_XLATE_BYPASS)),1) 1149 FULL_NAME := $(FULL_NAME)-test-xlate-bypass 1150 STAGE_DMA_FLAGS += -DCK_TEST_DISK_XLATE_BYPASS=1 1151 endif 1152 # AIENOS-PI5 step 3b: the sealed Store stage on the Pi card, in the TEST-key qualification tier 1153 # (SEED-0B-PI5, the Pi counterpart of the QEMU full image). Only the Store stage and what it needs 1154 # are linked: no PCI, NVMe, USB, virtio, SMMU or security stage (none of that hardware is on the 1155 # Pi path). core/pi5.c supplies ck_dev_boot_disk and ck_dev_nvme_release over the SD partition view. 1156 FULL_STAGE_SYMS := ck_stage_devices ck_stage_security ck_stage_store ck_stage_quiesce ck_stage_disk_artifacts 1157 ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_UNLOCK)),) 1158 FULL_NAME := $(if $(strip $(CK_PI5_UNLOCK)),full-pi5-unlock$(if $(strip $(CK_PI5_UNLOCK_CARD)),-card)$(if $(strip $(CK_PI5_FACT)),-fact)$(if $(strip $(CK_PI5_AGENT)),-agent)$(if $(strip $(CK_PI5_LIFECYCLE)),-lifecycle),full-pi5-store) 1159 FULL_STAGE_SYMS := ck_stage_store ck_stage_disk_artifacts 1160 STAGE_SRCS := $(KDIR)/svc/store_boot.c $(KDIR)/svc/artifact_store.c $(KDIR)/svc/store_crash.c $(KDIR)/svc/ck_compat.c \ 1161 $(foreach m,store/store_v1 store/store_engine store/store_disk store/store_sealed store/torn_slot m5/m5_keys m5/m5_envelope m5/m5_state crypto/aes crypto/polyval crypto/gcm_siv crypto/hmac crypto/ct argus/sha256,$(NATIVE)/$(m).c) 1162 ifneq ($(strip $(CK_PI5_FACT)),) 1163 STAGE_SRCS += $(KDIR)/svc/pi5_fact.c $(STAGE_CORTEX_SRCS) 1164 endif 1165 ifneq ($(strip $(CK_PI5_AGENT)),) 1166 STAGE_SRCS += $(KDIR)/svc/pi5_agent.c 1167 endif 1168 ifneq ($(strip $(CK_PI5_LIFECYCLE)),) 1169 # The NVMe image-slot service is not part of the Pi image: its four hooks are answered by svc/slot_service_pi5.c. 1170 STAGE_SRCS += $(filter-out $(KDIR)/svc/slot_service.c $(BOOT)/slot_select.c $(BOOT)/slot_control.c $(BOOT)/slot_update.c,$(SVC_STAGE_ADDED)) $(KDIR)/svc/slot_service_pi5.c 1171 endif 1172 endif 1173 # CK_BOOT_SHOW=1 images get their own image directory and stage objects; the one core object 1174 # that differs, kmain.o, is rebuilt through $(OUT)/boot_show.stamp (below). 1175 ifeq ($(strip $(CK_BOOT_SHOW)),1) 1176 FULL_NAME := $(FULL_NAME)-boot-show 1177 endif 1178 # The boot sequence runner (core/boot_screen.c) needs the devices stage: full images only. 1179 STAGE_SRCS += $(KDIR)/core/boot_screen.c 1180 ifeq ($(strip $(CK_SPARK_INPUT)),1) 1181 FULL_NAME := spark-input$(if $(strip $(CK_HARDWARE_STAGING)),-hardware-staging,) 1182 FULL_STAGE_SYMS := ck_stage_devices ck_stage_quiesce 1183 STAGE_SRCS := $(foreach m,pci devices xhci_fence usb_hid usb_kbd rtl8127_bind,$(KDIR)/dev/$(m).c) \ 1184 $(NATIVE)/net/aienos_rtl8127.c $(NATIVE)/net/aienos_report.c $(NATIVE)/net/aienos_net.c 1185 endif 1186 FULL_OUT := $(OUT)/$(FULL_NAME) 1187 STAGE_KOBJ := $(OUT)/obj/stage-$(FULL_NAME) 1188 STAGE_HDRS := $(HDRS) $(wildcard $(NATIVE)/*/*.h $(NATIVE)/argus/bridge/*.h $(KDIR)/svc/compat/*.h) 1189 STAGE_BUILT := $(foreach s,$(STAGE_SRCS),$(STAGE_KOBJ)/$(subst /,_,$(patsubst $(REPO)/%,%,$(abspath $(s)))).o) 1190 # STAGE_CFLAGS first: svc/compat must shadow the hosted headers. No fortify. 1191 STAGE_KCFLAGS := $(STAGE_CFLAGS) $(KCFLAGS) $(MODULE_INC) -U_FORTIFY_SOURCE $(STAGE_DMA_FLAGS) 1192 # The core already links argus/sha256.c (artifact loader); link it once. 1193 STAGE_LINK := $(filter-out %/native_argus_sha256.c.o,$(STAGE_BUILT)) 1194 1195 ELF := $(OUT)/aienos-ck.elf 1196 EFI := $(OUT)/BOOTAA64.EFI 1197 FULL_ELF := $(FULL_OUT)/aienos-ck.elf 1198 FULL_EFI := $(FULL_OUT)/BOOTAA64.EFI 1199 1200 all: $(EFI) 1201 full: $(FULL_EFI) 1202 1203 print-kcflags: 1204 @echo $(KCFLAGS) $(MODULE_INC) 1205 1206 $(OUT)/commit.stamp: FORCE 1207 @mkdir -p $(OUT) 1208 @echo '$(AIENOS_COMMIT)' | cmp -s - $@ || echo '$(AIENOS_COMMIT)' > $@ 1209 1210 $(KOBJ)/%.o: $(NATIVE)/%.c $(HDRS) 1211 @mkdir -p $(dir $@) 1212 $(KCC) $(KCFLAGS) -c -o $@ $< 1213 1214 $(KOBJ)/kernel/core/report.o: $(KDIR)/core/report.c $(HDRS) $(OUT)/commit.stamp 1215 @mkdir -p $(dir $@) 1216 $(KCC) $(KCFLAGS) -DAIENOS_COMMIT='"$(AIENOS_COMMIT)"' -c -o $@ $< 1217 1218 # kmain.o is shared by the full and full-boot-show images (one $(KOBJ)) but compiles 1219 # differently under CK_BOOT_SHOW, so it is rebuilt whenever the value changes; without the 1220 # stamp a warm OUT linked the other image's kmain.o (a boot-show image with no show, or the reverse). 1221 $(KOBJ)/kernel/core/kmain.o: $(OUT)/boot_show.stamp 1222 $(OUT)/boot_show.stamp: FORCE 1223 @mkdir -p $(OUT) 1224 @echo '$(CK_BOOT_SHOW)' | cmp -s - $@ || echo '$(CK_BOOT_SHOW)' > $@ 1225 1226 # Artifact loader objects: compat headers for , TEST-anchor flag. 1227 ART_OBJS := $(patsubst $(NATIVE)/%.c,$(KOBJ)/%.o,$(ART_C)) 1228 ART_HDRS := $(wildcard $(NATIVE)/sig/*.h $(NATIVE)/argus/sha256.h $(KDIR)/svc/compat/*.h) 1229 $(ART_OBJS): KCFLAGS += $(ART_INC) 1230 $(ART_OBJS): $(ART_HDRS) 1231 1232 # core/pi5.c drives the SD card through native/disk. 1233 $(KOBJ)/kernel/core/pi5.o: KCFLAGS += -I$(NATIVE)/disk 1234 $(KOBJ)/kernel/core/pi5_marker.o: KCFLAGS += -I$(NATIVE)/disk 1235 $(KOBJ)/kernel/arch/rndr.o: KCFLAGS += -I$(KDIR)/dev 1236 $(KOBJ)/kernel/dev/disk_part.o: KCFLAGS += -I$(NATIVE)/disk 1237 1238 # core/infer.c uses the in-core SHA-256 (argus) to prove the ingested bytes. 1239 $(KOBJ)/kernel/core/infer.o: KCFLAGS += -I$(NATIVE)/argus 1240 # core/allen.c prints the SHA-256 of the exam file it read. 1241 $(KOBJ)/kernel/core/allen.o: KCFLAGS += -I$(NATIVE)/argus 1242 1243 $(OUT)/trust.stamp: FORCE 1244 @mkdir -p $(OUT) 1245 @echo '$(ART_TRUST_FLAGS)' | cmp -s - $@ || echo '$(ART_TRUST_FLAGS)' > $@ 1246 1247 $(KOBJ)/kernel/core/artifact_loader.o: $(KDIR)/core/artifact_loader.c $(HDRS) $(ART_HDRS) \ 1248 $(OUT)/commit.stamp $(OUT)/trust.stamp 1249 @mkdir -p $(dir $@) 1250 $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -DAIENOS_COMMIT='"$(AIENOS_COMMIT)"' -c -o $@ $< 1251 1252 $(KOBJ)/kernel/core/osc_admit.o: $(KDIR)/core/osc_admit.c $(HDRS) $(ART_HDRS) $(OUT)/trust.stamp 1253 @mkdir -p $(dir $@) 1254 $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) $(if $(strip $(CK_HARDWARE_STAGING)),-DCK_HARDWARE_STAGING=1,) $(if $(filter 1,$(strip $(CK_SERVICE))),-DCK_SERVICE=1,) $(if $(filter 1,$(strip $(CK_SEED0B_TEST_ANCHOR))),,-DCK_RELEASE_IMAGE=1) -c -o $@ $< 1255 1256 # core/osh_op.c refuses to build without CK_OSH_OP_TEST (and with CK_HARDWARE_STAGING): it takes the trust flags too. 1257 $(KOBJ)/kernel/core/osh_op.o: $(KDIR)/core/osh_op.c $(KDIR)/core/osh_op.h $(HDRS) $(OUT)/trust.stamp 1258 @mkdir -p $(dir $@) 1259 $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -c -o $@ $< 1260 1261 # core/osh_test.c reads CK_OSH_OP_TEST, so it takes the trust flags too (and is rebuilt when they change). 1262 $(KOBJ)/kernel/core/osh_test.o: $(KDIR)/core/osh_test.c $(HDRS) $(ART_HDRS) $(OUT)/trust.stamp 1263 @mkdir -p $(dir $@) 1264 $(KCC) $(KCFLAGS) $(ART_TRUST_FLAGS) -c -o $@ $< 1265 1266 $(KOBJ)/%.o: $(NATIVE)/%.S 1267 @mkdir -p $(dir $@) 1268 $(KCC) $(KCFLAGS) -c -o $@ $< 1269 1270 define stage_rule 1271 $(STAGE_KOBJ)/$(subst /,_,$(patsubst $(REPO)/%,%,$(abspath $(1)))).o: $(1) $(STAGE_HDRS) $(OWNER_HDR) 1272 @mkdir -p $$(dir $$@) 1273 $(KCC) $(STAGE_KCFLAGS) -c -o $$@ $(1) 1274 endef 1275 $(foreach s,$(STAGE_SRCS),$(eval $(call stage_rule,$(s)))) 1276 1277 # fwcfg_check(elf): a default image (no CK_TEST_FWCFG_ARTIFACTS) must carry no 1278 # fw_cfg artifact code or strings; a test image must carry its announcement. 1279 # The QEMU inference images (CK_INFER_LIB without hardware staging, aienos#34 1280 # lane 4) read their model over fw_cfg when no MODEL.MAP is found: they must 1281 # carry their own TEST-ONLY announcement instead. The hardware service image 1282 # with inference (CK_INFER_LIB + CK_HARDWARE_STAGING, boot-disk only) must 1283 # carry the boot-disk source line, the resident session, and no fw_cfg code. 1284 define fwcfg_check 1285 @if [ -n "$(strip $(CK_INFER_LIB))" ] && [ -z "$(strip $(CK_HARDWARE_STAGING))" ] && [ -z "$(strip $(CK_PI5_INFER))" ] && [ -z "$(strip $(CK_PI5_AGENT))" ] && [ -z "$(strip $(CK_PI5_LIFECYCLE))" ]; then \ 1286 grep -aqF "TEST-ONLY QEMU fw_cfg model ingest" $(1) || { echo "inference probe image lacks its TEST-ONLY fw_cfg announcement"; rm -f $(1); exit 1; }; \ 1287 elif [ "$(strip $(CK_TEST_FWCFG_ARTIFACTS))" = 1 ]; then \ 1288 grep -aqF "TEST-ONLY QEMU fw_cfg side channel" $(1) || { echo "test fw_cfg image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1289 else \ 1290 s=$$(grep -aoE "opt/aienos/artifacts|opt/aienos/model|fw_cfg|QEMU0002" $(1) | sort -u | tr "\n" " "); \ 1291 y=$$($(KNM) $(1) | grep -E " (fw_select|fw_read|fw_skip|fw_find|fw_dma_read|fwcfg_from_dsdt|fwcfg_source|fwcfg)$$" | tr "\n" " "); \ 1292 if [ -n "$$s$$y" ]; then echo "default image carries fw_cfg artifact code: $$s$$y"; rm -f $(1); exit 1; fi; \ 1293 if [ -n "$(strip $(CK_INFER_LIB))" ]; then \ 1294 grep -aqF "infer_source_mode: boot-disk model" $(1) || { echo "hardware inference image lacks the boot-disk model source"; rm -f $(1); exit 1; }; \ 1295 if [ -z "$(strip $(CK_PI5_INFER))" ]; then grep -aqF "infer: resident open" $(1) || { echo "hardware inference image lacks the resident session"; rm -f $(1); exit 1; }; fi; \ 1296 echo "hardware inference image: boot-disk model source only, no fw_cfg code in $(1)"; \ 1297 fi; \ 1298 echo "no fw_cfg artifact code in $(1)"; \ 1299 fi 1300 endef 1301 1302 # console_check(elf): only a CK_CONSOLE_SESSION image may carry the console 1303 # session code; only a CK_TEST_CONSOLE_MUTATION image its mutation banner. 1304 define console_check 1305 @if [ "$(strip $(CK_CONSOLE_SESSION))" = 1 ]; then \ 1306 grep -aqF "console_session: begin" $(1) || { echo "console session image lacks its stage"; rm -f $(1); exit 1; }; \ 1307 else \ 1308 if grep -aqF "console_session:" $(1); then echo "default image carries the console session"; rm -f $(1); exit 1; fi; \ 1309 echo "no console session code in $(1)"; \ 1310 fi 1311 @if [ -n "$(strip $(CK_TEST_CONSOLE_MUTATION))" ]; then \ 1312 grep -aqF "TEST-ONLY console session MUTATION BUILD" $(1) || { echo "console mutation image lacks its TEST-ONLY banner"; rm -f $(1); exit 1; }; \ 1313 else \ 1314 if grep -aqF "TEST-ONLY console session MUTATION" $(1); then echo "image carries the console mutation without asking"; rm -f $(1); exit 1; fi; \ 1315 fi 1316 endef 1317 1318 # service_check(elf): only a CK_SERVICE image may carry the resident lifecycle; 1319 # only a CK_SERVICE_TEST_KEYS image its TEST-ONLY banner. 1320 define service_check 1321 @if [ "$(strip $(CK_SERVICE))" = 1 ] || [ -n "$(strip $(CK_PI5_LIFECYCLE))" ]; then \ 1322 grep -aqF "lifecycle: ready" $(1) || { echo "service image lacks the resident lifecycle"; rm -f $(1); exit 1; }; \ 1323 else \ 1324 if grep -aqF "lifecycle: ready" $(1); then echo "diagnostic image carries the resident lifecycle"; rm -f $(1); exit 1; fi; \ 1325 echo "no resident lifecycle in $(1)"; \ 1326 fi 1327 @if [ "$(strip $(CK_SERVICE_TEST_KEYS))" = 1 ]; then \ 1328 grep -aqF "TEST-ONLY service image" $(1) || { echo "service test-keys image lacks its TEST-ONLY banner"; rm -f $(1); exit 1; }; \ 1329 else \ 1330 if grep -aqF "TEST-ONLY service image" $(1); then echo "image carries TEST Store keys without asking"; rm -f $(1); exit 1; fi; \ 1331 fi 1332 endef 1333 1334 # xhci_mut_check(elf): only a CK_TEST_XHCI_MUTATION image may carry the 1335 # TEST-ONLY xHCI mutation banner (and it must carry it). 1336 define xhci_mut_check 1337 @if [ -n "$(strip $(CK_TEST_XHCI_MUTATION))" ]; then \ 1338 grep -aqF "TEST-ONLY xHCI MUTATION BUILD" $(1) || { echo "xHCI mutation image lacks its TEST-ONLY banner"; rm -f $(1); exit 1; }; \ 1339 else \ 1340 if grep -aqF "TEST-ONLY xHCI MUTATION" $(1); then echo "default image carries the TEST-ONLY xHCI mutation"; rm -f $(1); exit 1; fi; \ 1341 echo "no xHCI mutation code in $(1)"; \ 1342 fi 1343 endef 1344 1345 # owner_check(elf): a hardware staging image must carry no TEST Store label, 1346 # TEST store uuid, TEST Store print lines or TEST key symbols. 1347 define owner_check 1348 @if [ "$(strip $(CK_HARDWARE_STAGING))" = 1 ]; then \ 1349 s=$$(grep -aoE "AIENOS-LANE18-TEST-KVOL-NOT-SECRET|AIEN-TEST-BOOT01|TEST identity, TEST keys|formatted TEST store|TEST machine id 0xA1" $(1) | sort -u | tr "\n" " "); \ 1350 y=$$($(KNM) $(1) | grep -E " (ck_store_test_keys|ck_store_test_uuid)$$" | tr "\n" " "); \ 1351 if [ -n "$$s$$y" ]; then echo "hardware staging image carries the TEST Store identity: $$s$$y"; rm -f $(1); exit 1; fi; \ 1352 echo "no TEST Store label, uuid or key code in $(1)"; \ 1353 fi 1354 endef 1355 1356 # rollback_check(elf): only a CK_TEST_ROLLBACK image may carry a TEST-only 1357 # rollback candidate, and it must announce itself. 1358 define rollback_check 1359 @if [ -n "$(strip $(CK_TEST_ROLLBACK))" ]; then \ 1360 grep -aqF "TEST-ONLY rollback candidate ($(strip $(CK_TEST_ROLLBACK)))" $(1) || { echo "rollback test image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1361 else \ 1362 if grep -aqF "TEST-ONLY rollback candidate" $(1); then echo "default image carries a TEST-ONLY rollback candidate"; rm -f $(1); exit 1; fi; \ 1363 fi 1364 endef 1365 1366 # pipe_check(elf): only a CK_PIPE_TEST image may carry the TEST-only pipe self-test, and it must announce itself. 1367 define pipe_check 1368 @if [ "$(strip $(CK_PIPE_TEST))" = 1 ]; then \ 1369 grep -aqF "TEST-ONLY pipe self-test" $(1) || { echo "pipe test image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1370 else \ 1371 if grep -aqF "TEST-ONLY pipe self-test" $(1); then echo "default image carries the TEST-ONLY pipe self-test"; rm -f $(1); exit 1; fi; \ 1372 fi 1373 endef 1374 1375 # smp_check(elf): only a CK_TEST_SMP_SKIP_CPU image may carry the SMP mutation 1376 # announcement, and such an image must carry it. 1377 define smp_check 1378 @if [ "$(strip $(CK_TEST_SMP_SKIP_CPU))" = 1 ]; then \ 1379 grep -aqF "TEST-ONLY SMP mutation" $(1) || { echo "SMP mutation image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1380 else \ 1381 if grep -aqF "TEST-ONLY SMP mutation" $(1); then echo "default image carries the TEST-ONLY SMP mutation"; rm -f $(1); exit 1; fi; \ 1382 fi 1383 endef 1384 1385 # b7b_check(elf): only a CK_B7B_PROBE image may carry the B7b probe, and such an 1386 # image must; only a CK_B7B_PROBE_TEST_SEGMENT0 image may carry the TEST-ONLY 1387 # segment-0 announcement, and such an image must. 1388 define b7b_check 1389 @if [ "$(strip $(CK_B7B_PROBE))" = 1 ]; then \ 1390 grep -aqF "b7b_probe: start segment=" $(1) || { echo "B7b probe image lacks the probe"; rm -f $(1); exit 1; }; \ 1391 else \ 1392 if grep -aqF "b7b_probe:" $(1); then echo "default image carries the B7b probe"; rm -f $(1); exit 1; fi; \ 1393 fi 1394 @if [ "$(strip $(CK_B7B_PROBE_TEST_SEGMENT0))" = 1 ]; then \ 1395 grep -aqF "TEST-ONLY B7b probe on PCI segment 0" $(1) || { echo "segment-0 probe image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1396 else \ 1397 if grep -aqF "TEST-ONLY B7b probe" $(1); then echo "image carries the TEST-ONLY segment-0 probe"; rm -f $(1); exit 1; fi; \ 1398 fi 1399 @if [ "$(strip $(CK_B7B_EVENT_READOUT))" = 1 ]; then \ 1400 grep -aqF "b7b_events: final begin all_sids=yes" $(1) || { echo "B7b image lacks event readout"; rm -f $(1); exit 1; }; \ 1401 else \ 1402 if grep -aqF "b7b_events:" $(1); then echo "image carries unrequested event readout"; rm -f $(1); exit 1; fi; \ 1403 fi 1404 endef 1405 1406 # crash_check(elf): a full image built without CK_TEST_STORE_CRASH must carry 1407 # no Store crash hook code or strings; a TEST crash image must announce itself. 1408 # The bare "TEST-ONLY MUTANT" phrase is refused here except in the TEST 1409 # continuity image, whose own mutants print it (cont_check refuses it in every 1410 # image built without CK_TEST_CONTINUITY; crash-hook mutants are still caught 1411 # by their "store_crash:" prefix). 1412 define crash_check 1413 @if [ "$(strip $(CK_TEST_STORE_CRASH))" = 1 ]; then \ 1414 grep -aqF "TEST-ONLY Store crash hook image" $(1) || { echo "TEST crash image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1415 else \ 1416 m="|TEST-ONLY MUTANT"; [ "$(strip $(CK_TEST_CONTINUITY))" = 1 ] && m=""; \ 1417 s=$$(grep -aoE "store_crash:|AIENCRSH$$m" $(1) | sort -u | tr "\n" " "); \ 1418 y=$$($(KNM) $(1) | grep -E " ck_store_crash_[a-z_]+$$" | tr "\n" " "); \ 1419 if [ -n "$$s$$y" ]; then echo "default image carries the TEST Store crash hook: $$s$$y"; rm -f $(1); exit 1; fi; \ 1420 echo "no Store crash hook code in $(1)"; \ 1421 fi 1422 endef 1423 1424 # cont_check(elf): a full image built without CK_TEST_CONTINUITY must carry no 1425 # TEST continuity wiring code or strings; a TEST continuity image must announce 1426 # itself. A CK_SERVICE image carries the production continuity layer (P05 cut 1: 1427 # cr_provision/cr_resume through svc/continuity_service.c) and must still carry 1428 # neither the TEST mode selection (ck_cont_boot_stage, AIENCONT plan line) nor 1429 # the Recovery Core (rc_inspect, the TEST operator key). 1430 define cont_check 1431 @if [ "$(strip $(CK_TEST_CONTINUITY))" = 1 ]; then \ 1432 grep -aqF "TEST-ONLY continuity mode selection image" $(1) || { echo "TEST continuity image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ 1433 else \ 1434 m="|TEST-ONLY MUTANT"; [ "$(strip $(CK_TEST_STORE_CRASH))" = 1 ] && m=""; \ 1435 if [ "$(strip $(CK_SERVICE))" = 1 ] || [ -n "$(strip $(CK_PI5_LIFECYCLE))" ]; then \ 1436 s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: $$m" $(1) | sort -u | tr "\n" " "); \ 1437 y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|rc_inspect)$$" | tr "\n" " "); \ 1438 grep -aqF "continuity: REFUSED" $(1) || { echo "service image lacks the production continuity wiring"; rm -f $(1); exit 1; }; \ 1439 else \ 1440 s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: |continuity: REFUSED$$m" $(1) | sort -u | tr "\n" " "); \ 1441 y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|cr_resume|cr_provision|rc_inspect|ck_cont_service_start)$$" | tr "\n" " "); \ 1442 fi; \ 1443 if [ -n "$$s$$y" ]; then echo "image carries the TEST continuity wiring: $$s$$y"; rm -f $(1); exit 1; fi; \ 1444 echo "no TEST continuity wiring in $(1)"; \ 1445 fi 1446 endef 1447 1448 # allen_check(elf): only a CK_ALLEN image carries the ALLEN unit (aienos_allen_* entry points) and its exam stage; it must carry 1449 # both, plus the gate. Every other core image must carry none of it. 1450 define allen_check 1451 @a=$$($(KNM) $(1) | grep -cE " [Tt] (aienos_allen_decide|aienos_allen_train|ck_allen_gate_judge)$$" || true); \ 1452 if [ -n "$(strip $(CK_ALLEN))" ]; then \ 1453 [ "$$a" = 3 ] && grep -aqF "AIENOS_CK_ALLEN: " $(1) || { echo "ALLEN image lacks the ALLEN unit, gate or exam stage"; rm -f $(1); exit 1; }; \ 1454 echo "ALLEN exam image: ALLEN unit + gate + exam stage in $(1)"; \ 1455 elif [ "$$a" != 0 ] || grep -aqF "AIENOS_CK_ALLEN: " $(1); then echo "image without CK_ALLEN carries ALLEN code"; rm -f $(1); exit 1; fi 1456 endef 1457 1458 # osc_rehash_check(elf): the post-admission code byte flip is part of a 1459 # CK_OSC_RECEIPT_TEST image only, and that image must carry the banner and 1460 # ck_osc_receipt_test_code_flip. Every other image must carry neither. 1461 define osc_rehash_check 1462 @if [ "$(strip $(CK_OSC_RECEIPT_TEST))" = 1 ]; then \ 1463 grep -aqF "TEST-ONLY post-admission code byte flip" $(1) || { echo "receipt test image lacks the TEST-ONLY code byte flip"; rm -f $(1); exit 1; }; \ 1464 $(KNM) $(1) | grep -q ' ck_osc_receipt_test_code_flip$$' || { echo "receipt test image lacks ck_osc_receipt_test_code_flip"; rm -f $(1); exit 1; }; \ 1465 else \ 1466 s=""; $(KNM) $(1) | grep -q ' ck_osc_receipt_test_code_flip$$' && s="ck_osc_receipt_test_code_flip "; \ 1467 grep -aqF "TEST-ONLY post-admission code byte flip" $(1) && s="$${s}banner"; \ 1468 if [ -n "$$s" ]; then echo "image carries the TEST-ONLY post-admission code byte flip: $$s"; rm -f $(1); exit 1; fi; \ 1469 echo "no post-admission code byte flip in $(1)"; \ 1470 fi 1471 endef 1472 1473 # link_image(output elf, objects): refuses undefined symbols (weak stage 1474 # references excepted) and any relocation other than R_AARCH64_RELATIVE. 1475 define link_image 1476 @mkdir -p $(dir $(1)) 1477 $(KLD) $(KLDFLAGS) -o $(1) $(2) 1478 @u=$$($(KNM) -u $(1) | grep -v ' w ' || true); \ 1479 if [ -n "$$u" ]; then echo "image has undefined symbols: $$u"; rm -f $(1); exit 1; fi 1480 @bad=$$($(KREADELF) -rW $(1) | grep -E '^[0-9a-f]+ ' | grep -v R_AARCH64_RELATIVE || true); \ 1481 if [ -n "$$bad" ]; then echo "image has non-RELATIVE relocations:"; echo "$$bad"; rm -f $(1); exit 1; fi 1482 endef 1483 define pe_image 1484 $(KOBJCOPY) -O binary $(1) $(2) 1485 @sz=$$(stat -c %s $(2)); pad=$$(( (4096 - sz % 4096) % 4096 )); \ 1486 if [ $$pad -gt 0 ]; then head -c $$pad /dev/zero >> $(2); fi 1487 @[ "$$(head -c 2 $(2))" = "MZ" ] || { echo "not a PE image"; rm -f $(2); exit 1; } 1488 @echo "built $(2) (commit $(AIENOS_COMMIT))" 1489 endef 1490 1491 $(ELF): $(CORE_OBJS) $(BOOT)/image.ld 1492 $(call link_image,$@,$(CORE_OBJS) $(CK_RUST_LIBS) $(CK_INFER_LIB) $(CK_ALLEN_LIB)) 1493 $(call allen_check,$@) 1494 @if [ -z "$(strip $(CK_TEST_STALE_HANDOFF))" ] && grep -aqF "TEST-ONLY stale handoff" $@; then \ 1495 echo "default image carries the TEST-only stale handoff"; rm -f $@; exit 1; fi 1496 $(call rollback_check,$@) 1497 $(call pipe_check,$@) 1498 @s=$$($(KNM) $@ | grep -E ' [TtDdBbWwVv] ck_stage_(devices|security|store|quiesce)$$' || true); \ 1499 if [ -n "$$s" ]; then echo "core image defines stage symbols: $$s"; rm -f $@; exit 1; fi 1500 $(call fwcfg_check,$@) 1501 $(call smp_check,$@) 1502 $(call b7b_check,$@) 1503 $(call osc_rehash_check,$@) 1504 1505 $(FULL_ELF): $(CORE_OBJS) $(STAGE_BUILT) $(BOOT)/image.ld 1506 $(call link_image,$@,$(CORE_OBJS) $(STAGE_LINK) $(CK_RUST_LIBS) $(CK_INFER_LIB) $(CK_ALLEN_LIB)) 1507 $(call rollback_check,$@) 1508 $(call pipe_check,$@) 1509 @for s in $(FULL_STAGE_SYMS); do \ 1510 $(KNM) $@ | grep -qE " [TW] $$s$$" || { echo "full image lacks $$s"; rm -f $@; exit 1; }; done 1511 $(call fwcfg_check,$@) 1512 $(call owner_check,$@) 1513 $(call xhci_mut_check,$@) 1514 $(call console_check,$@) 1515 $(call service_check,$@) 1516 $(call smp_check,$@) 1517 $(call crash_check,$@) 1518 $(call b7b_check,$@) 1519 $(call cont_check,$@) 1520 $(call osc_rehash_check,$@) 1521 1522 $(EFI): $(ELF) 1523 $(call pe_image,$<,$@) 1524 1525 $(FULL_EFI): $(FULL_ELF) 1526 $(call pe_image,$<,$@) 1527 1528 # ---- host unit tests ---- 1529 HOST_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/mm/frames.c \ 1530 $(KDIR)/mm/pt.c $(KDIR)/mm/heap.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c $(KDIR)/core/entropy.c \ 1531 $(KDIR)/core/handoff_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/lifecycle_fsm.c \ 1532 $(KDIR)/core/line_rx.c $(KDIR)/core/klog.c $(KDIR)/core/klog_slot.c $(KDIR)/core/cpufeat.c $(KDIR)/core/unlock_req.c $(KDIR)/core/agent_cmd.c $(KDIR)/core/artifact_card.c $(KDIR)/core/allen_gate.c 1533 TESTS := test_fmt test_frames test_pt test_acpi test_dmar test_acpi_dev test_heap test_smmu test_sched test_ipc test_artifact test_osc_unit test_osc_launch test_osc_admit test_osc_receipt test_entropy test_handoff test_fbcon test_osh_op \ 1534 test_continuity_codec test_continuity_resolve test_continuity_commit test_continuity_recovery test_continuity_geometry \ 1535 test_continuity_subject test_continuity_subject_provision test_lifecycle test_console_rx test_klog test_klog_slot test_pi5 test_pi5_marker test_pi5_rng test_cpufeat test_dma_window test_pi5_pcie test_pi5_net test_pi5_gem test_unlock_req test_context test_agent_cmd test_artifact_card test_pipe test_allen_gate \ 1536 test_netboot_text test_gb10_gsp_boot 1537 TESTS += test_gpu_sim test_gsp_mmio 1538 TESTS += test_smmu_svc 1539 TESTS += test_spinlock test_pipe_irq 1540 HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) 1541 SANFLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer 1542 1543 $(OUT)/host/%: $(KDIR)/tests/%.c $(HOST_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1544 @mkdir -p $(dir $@) 1545 $(HOSTCC) $(HCFLAGS) -o $@ $< $(HOST_SRCS) 1546 1547 $(OUT)/host-san/%: $(KDIR)/tests/%.c $(HOST_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1548 @mkdir -p $(dir $@) 1549 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -o $@ $< $(HOST_SRCS) 1550 1551 # DMAR is a standalone byte parser; unrelated host tests need not link it. 1552 DMAR_TEST_SRCS := $(KDIR)/tests/test_dmar.c $(KDIR)/core/dmar.c 1553 $(OUT)/host/test_dmar: $(DMAR_TEST_SRCS) $(KDIR)/core/dmar.h $(KDIR)/tests/ck_test.h 1554 @mkdir -p $(dir $@) 1555 $(HOSTCC) $(HCFLAGS) -o $@ $(DMAR_TEST_SRCS) 1556 $(OUT)/host-san/test_dmar: $(DMAR_TEST_SRCS) $(KDIR)/core/dmar.h $(KDIR)/tests/ck_test.h 1557 @mkdir -p $(dir $@) 1558 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -o $@ $(DMAR_TEST_SRCS) 1559 1560 # OSH adapter operation layer (core/osh_op.c, aien-architecture#158): pure logic over ipc.c capabilities, SHA-256 for the 1561 # request digest. Its own rule because it needs the argus SHA-256 source. 1562 OSH_OP_SRCS := $(KDIR)/core/osh_op.c $(KDIR)/core/ipc.c $(KDIR)/core/fmt.c $(NATIVE)/argus/sha256.c 1563 $(OUT)/host/test_osh_op: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1564 @mkdir -p $(dir $@) 1565 $(HOSTCC) $(HCFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -o $@ $< $(OSH_OP_SRCS) 1566 1567 $(OUT)/host-san/test_osh_op: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1568 @mkdir -p $(dir $@) 1569 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -o $@ $< $(OSH_OP_SRCS) 1570 1571 # TEST-ONLY mutant of core/osh_op.c: the permission check always says OK. test_osh_op must FAIL against it (red before 1572 # green); "make test" fails if the test stops catching it. Host only (osh_op.c refuses the flag freestanding). 1573 $(OUT)/host/test_osh_op_mutant: $(KDIR)/tests/test_osh_op.c $(OSH_OP_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1574 @mkdir -p $(dir $@) 1575 $(HOSTCC) $(HCFLAGS) -DCK_OSH_OP_TEST -I$(NATIVE)/argus -DCK_OSH_OP_MUTANT_SKIP_PERM -o $@ $< $(OSH_OP_SRCS) 1576 1577 osh-op-mutant: $(OUT)/host/test_osh_op_mutant 1578 @if $< > $<.log 2>&1; then cat $<.log; echo "test_osh_op mutant (permission check always OK): PASSED, test does not catch it"; exit 1; \ 1579 else grep -F "test_osh_op: FAIL" $<.log && echo "test_osh_op mutant (permission check always OK): FAILS as required"; fi 1580 1581 # Native pipe primitive (core/pipe.c, aienos-mv#428): pure logic over ipc.c capability tables, driven through sched.c by 1582 # core/pipe_drive.h. Own rule: the test reads the fixture corpus in tests/fixtures/pipe/. 1583 PIPE_SRCS := $(KDIR)/core/pipe.c $(KDIR)/core/ipc.c $(KDIR)/core/sched.c 1584 PIPE_DEPS := $(KDIR)/tests/test_pipe.c $(PIPE_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) $(wildcard $(KDIR)/tests/fixtures/pipe/*) 1585 PIPE_DEF := -DPIPE_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures/pipe)"' 1586 # core/ is not a -I ahead of the system headers: must stay POSIX for the 1587 # pthread host test. Quoted includes still find core/ headers (the sources live there, 1588 # and -idirafter covers the test file). 1589 PIPE_HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) -idirafter $(KDIR)/core -pthread 1590 $(OUT)/host/test_pipe: $(PIPE_DEPS) 1591 @mkdir -p $(dir $@) 1592 $(HOSTCC) $(PIPE_HCFLAGS) $(PIPE_DEF) -o $@ $< $(PIPE_SRCS) 1593 1594 $(OUT)/host-san/test_pipe: $(PIPE_DEPS) 1595 @mkdir -p $(dir $@) 1596 $(HOSTCC) $(PIPE_HCFLAGS) $(SANFLAGS) $(PIPE_DEF) -o $@ $< $(PIPE_SRCS) 1597 1598 # DRA-556: core/spinlock.h, the one kernel spinlock (fair ticket lock, masks interrupts while held). test_spinlock: 1599 # mutual exclusion, FIFO order, counter wrap, interrupt deferral. test_pipe_irq: race test, a pipe op from an 1600 # interrupt (host: SIGUSR1) on the thread that holds the pool lock; before DRA-556 it deadlocks. Both must FAIL 1601 # against the TEST-ONLY mutant -DCK_SPIN_TEST_NO_IRQ_MASK (interrupts left open). Host only. 1602 SPIN_DEPS := $(KDIR)/core/spinlock.h 1603 $(OUT)/host/test_spinlock: $(KDIR)/tests/test_spinlock.c $(SPIN_DEPS) 1604 @mkdir -p $(dir $@) 1605 $(HOSTCC) $(PIPE_HCFLAGS) -o $@ $< 1606 1607 $(OUT)/host-san/test_spinlock: $(KDIR)/tests/test_spinlock.c $(SPIN_DEPS) 1608 @mkdir -p $(dir $@) 1609 $(HOSTCC) $(PIPE_HCFLAGS) $(SANFLAGS) -o $@ $< 1610 1611 PIPE_IRQ_SRCS := $(KDIR)/core/pipe.c $(KDIR)/core/ipc.c 1612 PIPE_IRQ_DEPS := $(KDIR)/tests/test_pipe_irq.c $(PIPE_IRQ_SRCS) $(SPIN_DEPS) $(HDRS) 1613 $(OUT)/host/test_pipe_irq: $(PIPE_IRQ_DEPS) 1614 @mkdir -p $(dir $@) 1615 $(HOSTCC) $(PIPE_HCFLAGS) -o $@ $< $(PIPE_IRQ_SRCS) 1616 1617 $(OUT)/host-san/test_pipe_irq: $(PIPE_IRQ_DEPS) 1618 @mkdir -p $(dir $@) 1619 $(HOSTCC) $(PIPE_HCFLAGS) $(SANFLAGS) -o $@ $< $(PIPE_IRQ_SRCS) 1620 1621 SPIN_MUTANTS := NO_IRQ_MASK TICKET_BEFORE_MASK RESTORE_BEFORE_RELEASE 1622 $(OUT)/host/test_spinlock_mutant_%: $(KDIR)/tests/test_spinlock.c $(SPIN_DEPS) 1623 @mkdir -p $(dir $@) 1624 $(HOSTCC) $(PIPE_HCFLAGS) -DCK_SPIN_TEST_$* -o $@ $< 1625 1626 $(OUT)/host/test_pipe_irq_mutant: $(PIPE_IRQ_DEPS) 1627 @mkdir -p $(dir $@) 1628 $(HOSTCC) $(PIPE_HCFLAGS) -DCK_SPIN_TEST_NO_IRQ_MASK -o $@ $< $(PIPE_IRQ_SRCS) 1629 1630 spinlock-mutant: $(addprefix $(OUT)/host/test_spinlock_mutant_,$(SPIN_MUTANTS)) $(OUT)/host/test_pipe_irq_mutant 1631 @for m in $(SPIN_MUTANTS); do b=$(OUT)/host/test_spinlock_mutant_$$m; \ 1632 if $$b > $$b.log 2>&1; then cat $$b.log; echo "test_spinlock mutant $$m: PASSED, test does not catch it"; exit 1; \ 1633 else grep -F "test_spinlock: FAIL" $$b.log && echo "test_spinlock mutant $$m: FAILS as required"; fi || exit 1; done 1634 @for mp in TICKET_BEFORE_MASK:irq-step-acquire RESTORE_BEFORE_RELEASE:irq-step-release; do m=$${mp%%:*}; ph=$${mp##*:}; \ 1635 b=$(OUT)/host/test_spinlock_mutant_$$m; \ 1636 if TEST_SPINLOCK_ONLY=$$ph $$b > $$b.$$ph.log 2>&1; then cat $$b.$$ph.log; echo "test_spinlock mutant $$m, phase $$ph alone: PASSED, phase does not catch it"; exit 1; \ 1637 else grep -F "test_spinlock: FAIL deadlock (no progress for 5 s) in phase $$ph" $$b.$$ph.log && echo "test_spinlock mutant $$m: phase $$ph alone FAILS as required"; fi || exit 1; done 1638 @if $(OUT)/host/test_pipe_irq_mutant > $(OUT)/host/test_pipe_irq_mutant.log 2>&1; then cat $(OUT)/host/test_pipe_irq_mutant.log; \ 1639 echo "test_pipe_irq mutant (interrupts not masked): PASSED, test does not catch it"; exit 1; \ 1640 else grep -F "test_pipe_irq: FAIL" $(OUT)/host/test_pipe_irq_mutant.log && echo "test_pipe_irq mutant (interrupts not masked): FAILS as required"; fi 1641 1642 # DRA-556: the freestanding instruction order of core/spinlock.h, aarch64 (KCC, KCFLAGS) and x86-64 (X86CFLAGS): 1643 # the interrupt mask comes before the first atomic of the acquire, and the restore after the releasing store. 1644 # Needs the cross compilers and objdump; not part of "make test". tools/ck_spinlock_asm_check.sh reads the dumps; its 1645 # --selftest mutates them (mask removed, order swapped, release store to another symbol) and requires each to FAIL. 1646 spinlock-asm-check: $(KDIR)/tests/spinlock_tu.c $(SPIN_DEPS) 1647 @mkdir -p $(OUT)/spinlock-asm 1648 $(KCC) $(KCFLAGS) -c -o $(OUT)/spinlock-asm/a64.o $< 1649 $(X86CC) $(X86CFLAGS) -c -o $(OUT)/spinlock-asm/x86.o $< 1650 $(CROSS)objdump -dr $(OUT)/spinlock-asm/a64.o > $(OUT)/spinlock-asm/a64.dis 1651 $(X86_CROSS)objdump -dr $(OUT)/spinlock-asm/x86.o > $(OUT)/spinlock-asm/x86.dis 1652 @bash $(REPO)/tools/ck_spinlock_asm_check.sh $(OUT)/spinlock-asm/a64.dis $(OUT)/spinlock-asm/x86.dis 1653 @bash $(REPO)/tools/ck_spinlock_asm_check.sh --selftest $(OUT)/spinlock-asm/a64.dis $(OUT)/spinlock-asm/x86.dis 1654 1655 # DRA-556: Lean 4 proof of the ticket arithmetic in core/spinlock.h (mutual exclusion, FIFO, wrap). Core Lean only, 1656 # toolchain pinned in proofs/lean-toolchain. Not part of "make test" (Lean is not a build dependency): prints NOT_RUN 1657 # without lean, FAIL on any error or "sorry". 1658 ticketlock-proof: 1659 @command -v lean >/dev/null || { echo "CK_TICKETLOCK_PROOF: NOT_RUN (lean not installed)"; exit 3; } 1660 @if grep -n "sorry" $(KDIR)/proofs/TicketLock.lean; then echo "CK_TICKETLOCK_PROOF: FAIL (sorry)"; exit 1; fi 1661 @cd $(KDIR)/proofs && lean TicketLock.lean && echo "CK_TICKETLOCK_PROOF: PASS" 1662 1663 # TEST-ONLY mutant of core/pipe.c: a write does not check the WRITE right or the end. test_pipe must FAIL against it 1664 # (red before green); "make test" fails if the test stops catching it. Host only. 1665 $(OUT)/host/test_pipe_mutant: $(PIPE_DEPS) 1666 @mkdir -p $(dir $@) 1667 $(HOSTCC) $(PIPE_HCFLAGS) $(PIPE_DEF) -DCK_PIPE_MUTANT_SKIP_RIGHTS -o $@ $< $(PIPE_SRCS) 1668 1669 pipe-mutant: $(OUT)/host/test_pipe_mutant 1670 @if $< > $<.log 2>&1; then cat $<.log; echo "test_pipe mutant (write right not checked): PASSED, test does not catch it"; exit 1; \ 1671 else grep -F "test_pipe: FAIL" $<.log && echo "test_pipe mutant (write right not checked): FAILS as required"; fi 1672 1673 # TEST-ONLY mutant: ck_pipe_dispatch does not reject a slice outside [user_lo, user_hi). test_pipe must FAIL. 1674 $(OUT)/host/test_pipe_slice_mutant: $(PIPE_DEPS) 1675 @mkdir -p $(dir $@) 1676 $(HOSTCC) $(PIPE_HCFLAGS) $(PIPE_DEF) -DCK_PIPE_MUTANT_SKIP_SLICE -o $@ $< $(PIPE_SRCS) 1677 1678 pipe-slice-mutant: $(OUT)/host/test_pipe_slice_mutant 1679 @if $< > $<.log 2>&1; then cat $<.log; echo "test_pipe mutant (user slice not checked): PASSED, test does not catch it"; exit 1; \ 1680 else grep -F "test_pipe: FAIL" $<.log && echo "test_pipe mutant (user slice not checked): FAILS as required"; fi 1681 1682 # TEST-ONLY mutants for #494. pipe-bounce-mutant: ck_pipe_dispatch hands the caller's slice to the ring copy, which 1683 # touches it under the pool lock. pipe-top-mutant: a window ending above CK_PIPE_USER_TOP is accepted. test_pipe must 1684 # FAIL against each. 1685 $(OUT)/host/test_pipe_bounce_mutant: $(PIPE_DEPS) 1686 @mkdir -p $(dir $@) 1687 $(HOSTCC) $(PIPE_HCFLAGS) $(PIPE_DEF) -DCK_PIPE_MUTANT_NO_BOUNCE -o $@ $< $(PIPE_SRCS) 1688 1689 pipe-bounce-mutant: $(OUT)/host/test_pipe_bounce_mutant 1690 @if $< > $<.log 2>&1; then cat $<.log; echo "test_pipe mutant (slice copied under the lock): PASSED, test does not catch it"; exit 1; \ 1691 else grep -F "test_pipe: FAIL" $<.log && echo "test_pipe mutant (slice copied under the lock): FAILS as required"; fi 1692 1693 $(OUT)/host/test_pipe_top_mutant: $(PIPE_DEPS) 1694 @mkdir -p $(dir $@) 1695 $(HOSTCC) $(PIPE_HCFLAGS) $(PIPE_DEF) -DCK_PIPE_MUTANT_NO_USER_TOP -o $@ $< $(PIPE_SRCS) 1696 1697 pipe-top-mutant: $(OUT)/host/test_pipe_top_mutant 1698 @if $< > $<.log 2>&1; then cat $<.log; echo "test_pipe mutant (user-VA top not checked): PASSED, test does not catch it"; exit 1; \ 1699 else grep -F "test_pipe: FAIL" $<.log && echo "test_pipe mutant (user-VA top not checked): FAILS as required"; fi 1700 1701 # N3 context assembly + approval binding (core/context.c, core/context_proposal.c, aienos#329): pure logic over 1702 # the argus SHA-256. Own rule (needs sha256.c). The mutant skips the foreign-binding check: test_context must 1703 # FAIL against it (red before green); "make test" fails if the test stops catching it. Host only (context.c 1704 # refuses the flag outside CK_CTX_HOST_TEST). 1705 CONTEXT_SRCS := $(KDIR)/core/context.c $(KDIR)/core/context_proposal.c $(NATIVE)/argus/sha256.c 1706 $(OUT)/host/test_context: $(KDIR)/tests/test_context.c $(CONTEXT_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1707 @mkdir -p $(dir $@) 1708 $(HOSTCC) $(HCFLAGS) -DCK_CTX_HOST_TEST -o $@ $< $(CONTEXT_SRCS) 1709 1710 $(OUT)/host-san/test_context: $(KDIR)/tests/test_context.c $(CONTEXT_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1711 @mkdir -p $(dir $@) 1712 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -DCK_CTX_HOST_TEST -o $@ $< $(CONTEXT_SRCS) 1713 1714 $(OUT)/host/test_context_mutant: $(KDIR)/tests/test_context.c $(CONTEXT_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1715 @mkdir -p $(dir $@) 1716 $(HOSTCC) $(HCFLAGS) -DCK_CTX_HOST_TEST -DCK_CTX_MUTANT_SKIP_BINDING -o $@ $< $(CONTEXT_SRCS) 1717 1718 context-mutant: $(OUT)/host/test_context_mutant 1719 @if $< > $<.log 2>&1; then cat $<.log; echo "test_context mutant (foreign binding check skipped): PASSED, test does not catch it"; exit 1; \ 1720 else grep -F "test_context: FAIL" $<.log && echo "test_context mutant (foreign binding check skipped): FAILS as required"; fi 1721 1722 # PI5-7 cut 2 card command script parser (core/agent_cmd.c): the mutant accepts any word as a verb (a script could then carry unlock 1723 # or rotate); test_agent_cmd must FAIL against it (red before green). Host only, never part of an image. 1724 $(OUT)/host/test_agent_cmd_mutant: $(KDIR)/tests/test_agent_cmd.c $(KDIR)/core/agent_cmd.c $(KDIR)/core/agent_cmd.h $(KDIR)/tests/ck_test.h 1725 @mkdir -p $(dir $@) 1726 $(HOSTCC) $(HCFLAGS) -DCK_AGENT_CMD_MUTANT_ANY_VERB -o $@ $< $(KDIR)/core/agent_cmd.c 1727 1728 agent-cmd-mutant: $(OUT)/host/test_agent_cmd_mutant 1729 @if $< > $<.log 2>&1; then cat $<.log; echo "test_agent_cmd mutant (any verb allowed): PASSED, test does not catch it"; exit 1; \ 1730 else grep -F "test_agent_cmd: FAIL" $<.log && echo "test_agent_cmd mutant (any verb allowed): FAILS as required"; fi 1731 1732 # PI5-8 cut K ALLEN gate (core/allen_gate.c): the mutant proposes ALLEN's approve/deny/cancel like any other verb (ALLEN 1733 # would hold approval authority); test_allen_gate must FAIL against it (red before green). Host only, never part of an image. 1734 ALLEN_GATE_SRCS := $(KDIR)/core/allen_gate.c $(KDIR)/core/agent_cmd.c $(KDIR)/core/lifecycle_fsm.c 1735 $(OUT)/host/test_allen_gate_mutant: $(KDIR)/tests/test_allen_gate.c $(ALLEN_GATE_SRCS) $(KDIR)/core/allen_gate.h $(KDIR)/tests/ck_test.h 1736 @mkdir -p $(dir $@) 1737 $(HOSTCC) $(HCFLAGS) -DCK_ALLEN_GATE_MUTANT_TRUST_AUTHORITY -o $@ $< $(ALLEN_GATE_SRCS) 1738 1739 allen-gate-mutant: $(OUT)/host/test_allen_gate_mutant 1740 @if $< > $<.log 2>&1; then cat $<.log; echo "test_allen_gate mutant (ALLEN approve proposed): PASSED, test does not catch it"; exit 1; \ 1741 else grep -F "test_allen_gate: FAIL" $<.log && echo "test_allen_gate mutant (ALLEN approve proposed): FAILS as required"; fi 1742 1743 # PI5-7 cut 3 card artifact bundle parser (core/artifact_card.c): the mutant accepts bytes after the last entry (a second, unchecked 1744 # payload could ride along); test_artifact_card must FAIL against it (red before green). Host only, never part of an image. 1745 $(OUT)/host/test_artifact_card_mutant: $(KDIR)/tests/test_artifact_card.c $(KDIR)/core/artifact_card.c $(KDIR)/core/artifact_card.h $(KDIR)/tests/ck_test.h 1746 @mkdir -p $(dir $@) 1747 $(HOSTCC) $(HCFLAGS) -DCK_ACARD_MUTANT_TRAILING -o $@ $< $(KDIR)/core/artifact_card.c 1748 1749 artifact-card-mutant: $(OUT)/host/test_artifact_card_mutant 1750 @if $< > $<.log 2>&1; then cat $<.log; echo "test_artifact_card mutant (trailing bytes accepted): PASSED, test does not catch it"; exit 1; \ 1751 else grep -F "test_artifact_card: FAIL" $<.log && echo "test_artifact_card mutant (trailing bytes accepted): FAILS as required"; fi 1752 1753 # TEST-ONLY mutant of core/handoff_check.c (reserved0 check removed): the 1754 # handoff test must FAIL against it, so "make test" fails if the test stops 1755 # catching the mutation. Host only (handoff_check.c refuses it freestanding 1756 # and with CK_HARDWARE_STAGING); never part of an image. 1757 $(OUT)/host/test_handoff_mutant: $(KDIR)/tests/test_handoff.c $(HOST_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1758 @mkdir -p $(dir $@) 1759 $(HOSTCC) $(HCFLAGS) -DCK_HANDOFF_MUTANT_SKIP_RESERVED -o $@ $< $(HOST_SRCS) 1760 1761 handoff-mutant: $(OUT)/host/test_handoff_mutant 1762 @if $< > $<.log 2>&1; then cat $<.log; echo "test_handoff mutant (reserved0 check removed): PASSED, test does not catch it"; exit 1; \ 1763 else grep -F "test_handoff: FAIL" $<.log && echo "test_handoff mutant (reserved0 check removed): FAILS as required"; fi 1764 1765 # TEST-ONLY mutants of core/acpi_dev.c (NEXT-PHASE-3 cut 2): 1 = table 1766 # signature check removed, 2 = checksum check removed, 3 = length-versus- 1767 # buffer check removed (truncated table trusted). test_acpi_dev must FAIL 1768 # against each. Host only (acpi_dev.c refuses CK_AML_MUTANT freestanding). 1769 acpi-dev-mutant: $(KDIR)/tests/test_acpi_dev.c $(HOST_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 1770 @mkdir -p $(OUT)/host 1771 @for m in 1 2 3; do b=$(OUT)/host/test_acpi_dev_mutant$$m; \ 1772 $(HOSTCC) $(HCFLAGS) -DCK_AML_MUTANT=$$m -o $$b $(KDIR)/tests/test_acpi_dev.c $(HOST_SRCS) || exit 1; \ 1773 if $$b > $$b.log 2>&1; then cat $$b.log; echo "test_acpi_dev mutant $$m: PASSED, test does not catch it"; exit 1; \ 1774 else grep -F "test_acpi_dev: FAIL" $$b.log >/dev/null && echo "test_acpi_dev mutant $$m: FAILS as required" || { cat $$b.log; exit 1; }; fi; done 1775 1776 # TEST-ONLY mutants of the IORT parse/lookup in core/acpi.c: test_smmu must 1777 # FAIL against each (TRUNCATE: extra mappings dropped instead of the table 1778 # refused; SEGMENT_BLIND: lookup ignores the PCI segment; OVERLAP_OK: 1779 # overlapping input ranges in one segment accepted; OTHER_BLIND: mappings to 1780 # a second SMMUv3 node forgotten, so a GB10-shaped requester reads as "no 1781 # stream" instead of "behind another SMMU"; RMR_BLIND: RMR nodes ignored, so 1782 # the GB10 stream would lose its firmware-reserved ranges; RMR_EXCLUSIVE: 1783 # the RMR stream range read as exclusive, dropping the last stream (the 1784 # GB10, 0x100); ROUTE_FIRST: every requester routed to the first SMMU, so the 1785 # GB10 would be programmed on the wrong SMMU). Host only (acpi.c refuses them 1786 # freestanding and with CK_HARDWARE_STAGING). 1787 IORT_MUTANTS := CK_IORT_MUTANT_TRUNCATE CK_IORT_MUTANT_SEGMENT_BLIND CK_IORT_MUTANT_OVERLAP_OK CK_IORT_MUTANT_OTHER_BLIND \ 1788 CK_IORT_MUTANT_RMR_BLIND CK_IORT_MUTANT_RMR_EXCLUSIVE CK_IORT_MUTANT_ROUTE_FIRST 1789 iort-mutants: $(OUT)/host/test_smmu 1790 @mkdir -p $(OUT)/host-mut; fail=0; \ 1791 $(OUT)/host/test_smmu > $(OUT)/host-mut/iort-base.log 2>&1 || { echo "unmutated test_smmu fails"; fail=1; }; \ 1792 for m in $(IORT_MUTANTS); do \ 1793 b=$(OUT)/host-mut/test_smmu_$$m; \ 1794 if ! $(HOSTCC) $(HCFLAGS) -D$$m -o $$b $(KDIR)/tests/test_smmu.c $(HOST_SRCS); then \ 1795 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 1796 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 1797 elif grep -q "^test_smmu: FAIL" $$b.log; then \ 1798 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 1799 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 1800 done; \ 1801 if $(HOSTCC) $(HCFLAGS) -DCK_HARDWARE_STAGING=1 -DCK_IORT_MUTANT_SEGMENT_BLIND \ 1802 -fsyntax-only $(KDIR)/core/acpi.c 2>/dev/null; then \ 1803 echo "mutant flag accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 1804 else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ 1805 if [ $$fail = 0 ]; then echo "CK_IORT_MUTANTS: PASS"; else echo "CK_IORT_MUTANTS: FAIL"; exit 1; fi 1806 1807 # TEST-ONLY mutants of the two-level stream table in core/smmu.c: test_smmu 1808 # must FAIL against each (SPAN_OVERFLOW: L1STD Span past SPLIT + 1; 1809 # UNGRANTED_VALID: L1STDs valid before any grant; BAD_L1_PTR: misaligned L1 1810 # table accepted; L2_NO_FILL: a new L2 page published without abort STEs). 1811 # Host only (smmu.c refuses them freestanding and with CK_HARDWARE_STAGING). 1812 # Also kills DROP_EVENT: consuming the queue without visiting its records. 1813 SMMU_L2_MUTANTS := CK_SMMU_MUTANT_SPAN_OVERFLOW CK_SMMU_MUTANT_UNGRANTED_VALID CK_SMMU_MUTANT_BAD_L1_PTR CK_SMMU_MUTANT_L2_NO_FILL CK_SMMU_MUTANT_DROP_EVENT 1814 smmu-l2-mutants: $(OUT)/host/test_smmu 1815 @mkdir -p $(OUT)/host-mut; fail=0; \ 1816 $(OUT)/host/test_smmu > $(OUT)/host-mut/smmu-l2-base.log 2>&1 || { echo "unmutated test_smmu fails"; fail=1; }; \ 1817 for m in $(SMMU_L2_MUTANTS); do \ 1818 b=$(OUT)/host-mut/test_smmu_$$m; \ 1819 if ! $(HOSTCC) $(HCFLAGS) -D$$m -o $$b $(KDIR)/tests/test_smmu.c $(HOST_SRCS); then \ 1820 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 1821 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 1822 elif grep -q "^test_smmu: FAIL" $$b.log; then \ 1823 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 1824 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 1825 done; \ 1826 if $(HOSTCC) $(HCFLAGS) -DCK_HARDWARE_STAGING=1 -DCK_SMMU_MUTANT_SPAN_OVERFLOW \ 1827 -fsyntax-only $(KDIR)/core/smmu.c 2>/dev/null; then \ 1828 echo "mutant flag accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 1829 else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ 1830 if [ $$fail = 0 ]; then echo "CK_SMMU_L2_MUTANTS: PASS"; else echo "CK_SMMU_L2_MUTANTS: FAIL"; exit 1; fi 1831 1832 test: $(addprefix $(OUT)/host/,$(TESTS)) osc-receipt-mutants osc-receipt-release osc-code-flip-guard handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant pipe-mutant pipe-slice-mutant pipe-bounce-mutant pipe-top-mutant spinlock-mutant context-mutant agent-cmd-mutant allen-gate-mutant artifact-card-mutant artifact-tier-pi5 artifact-tier-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test gb10-gsp-free gb10-gsp-nvhdr-check gb10-gsp-mutants slot-test slot-free package-test slot-loader-check 1833 @fail=0; for t in $(filter-out osc-receipt-mutants osc-receipt-release osc-code-flip-guard handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant pipe-mutant pipe-slice-mutant pipe-bounce-mutant pipe-top-mutant spinlock-mutant context-mutant agent-cmd-mutant allen-gate-mutant artifact-card-mutant artifact-tier-pi5 artifact-tier-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test gb10-gsp-free gb10-gsp-nvhdr-check gb10-gsp-mutants slot-test slot-free package-test slot-loader-check,$^); do $$t || fail=1; done; \ 1834 if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS"; else echo "CK_CORE_HOST: FAIL"; exit 1; fi 1835 1836 sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) 1837 @fail=0; for t in $^; do ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $$t || fail=1; done; \ 1838 if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS (sanitize)"; else echo "CK_CORE_HOST: FAIL (sanitize)"; exit 1; fi 1839 1840 # ---- host tool for the M0_ROLLBACK gate (scripts/qemu_ck_rollback_test.sh) ---- 1841 uefi-vars: $(OUT)/host/ck_uefi_vars 1842 $(OUT)/host/ck_uefi_vars: $(KDIR)/tools/ck_uefi_vars.c 1843 @mkdir -p $(dir $@) 1844 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 1845 1846 # ---- host tool for the AIENOS_CK_NET gate (scripts/qemu_ck_net_test.sh) ---- 1847 udp-echo: $(OUT)/host/ck_udp_echo 1848 $(OUT)/host/ck_udp_echo: $(KDIR)/tools/ck_udp_echo.c 1849 @mkdir -p $(dir $@) 1850 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 1851 1852 # ---- receiver for the iMac kernel's network report (run on a machine on the iMac's network) ---- 1853 imac-report-listen: $(OUT)/host/ck_imac_report_listen 1854 $(OUT)/host/ck_imac_report_listen: $(KDIR)/tools/ck_imac_report_listen.c 1855 @mkdir -p $(dir $@) 1856 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 1857 1858 # Artifact library host test and the in-tree C artifact tool (pack, sign with 1859 # TEST keys, negative corpus, bundle, receipt check) used by the QEMU gate. 1860 ART_HOST_SRCS := $(KDIR)/artifact/format.c $(KDIR)/artifact/admission.c $(KDIR)/artifact/receipt.c $(KDIR)/artifact/osc_unit.c $(KDIR)/artifact/osc_receipt.c $(KDIR)/artifact/osc_launch.c \ 1861 $(NATIVE)/argus/sha256.c $(NATIVE)/sig/sha512.c $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/ct.c 1862 ART_HOST_INC := -I$(KDIR)/artifact -I$(NATIVE)/sig -I$(NATIVE)/argus 1863 ART_HOST_DEPS := $(ART_HOST_SRCS) $(wildcard $(KDIR)/artifact/*.h) $(ART_HDRS) 1864 1865 $(OUT)/host/test_artifact: $(KDIR)/tests/test_artifact.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1866 @mkdir -p $(dir $@) 1867 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -o $@ $< $(ART_HOST_SRCS) 1868 1869 # PI5-8 Q3: the receipt tier is chosen by the image. test_artifact built with -DCK_PI5 (the Pi image's define) must see 1870 # SEED-0B-PI5; the mutant (-DCKA_TIER_MUTANT, Pi image still writes the QEMU tier) must make that test FAIL. 1871 $(OUT)/host/test_artifact_pi5: $(KDIR)/tests/test_artifact.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1872 @mkdir -p $(dir $@) 1873 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DCK_PI5 -o $@ $< $(ART_HOST_SRCS) 1874 1875 $(OUT)/host/test_artifact_pi5_mutant: $(KDIR)/tests/test_artifact.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1876 @mkdir -p $(dir $@) 1877 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DCK_PI5 -DCKA_TIER_MUTANT -o $@ $< $(ART_HOST_SRCS) 1878 1879 artifact-tier-pi5: $(OUT)/host/test_artifact_pi5 1880 @$< 1881 1882 artifact-tier-mutant: $(OUT)/host/test_artifact_pi5_mutant 1883 @if $< > $<.log 2>&1; then cat $<.log; echo "test_artifact Pi tier mutant (Pi image writes the QEMU tier): PASSED, test does not catch it"; exit 1; \ 1884 else echo "test_artifact Pi tier mutant (Pi image writes the QEMU tier): FAILS as required"; fi 1885 1886 $(OUT)/host/test_osc_unit: $(KDIR)/tests/test_osc_unit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1887 @mkdir -p $(dir $@) 1888 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures/osc_unit)"' -o $@ $< $(ART_HOST_SRCS) 1889 1890 $(OUT)/host-san/test_osc_unit: $(KDIR)/tests/test_osc_unit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1891 @mkdir -p $(dir $@) 1892 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures/osc_unit)"' -o $@ $< $(ART_HOST_SRCS) 1893 1894 $(OUT)/host-san/test_artifact: $(KDIR)/tests/test_artifact.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1895 @mkdir -p $(dir $@) 1896 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) -o $@ $< $(ART_HOST_SRCS) 1897 1898 # C3-3a launch: pure parts (artifact/osc_launch.c) plus the spec's own C reference for the argument rule. 1899 $(OUT)/host/osc-launch-check: $(KDIR)/tests/fixtures/osc_unit/launch/osc-launch-check.c 1900 @mkdir -p $(dir $@) 1901 $(HOSTCC) -std=c99 -O1 -Wall -Wextra -Werror -o $@ $< 1902 1903 $(OUT)/host/test_osc_launch: $(KDIR)/tests/test_osc_launch.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(OUT)/host/osc-launch-check 1904 @mkdir -p $(dir $@) 1905 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures/osc_unit)"' -DOSC_LAUNCH_REF='"$(abspath $(OUT)/host/osc-launch-check)"' -o $@ $< $(ART_HOST_SRCS) 1906 1907 $(OUT)/host-san/test_osc_launch: $(KDIR)/tests/test_osc_launch.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(OUT)/host/osc-launch-check 1908 @mkdir -p $(dir $@) 1909 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures/osc_unit)"' -DOSC_LAUNCH_REF='"$(abspath $(OUT)/host/osc-launch-check)"' -o $@ $< $(ART_HOST_SRCS) 1910 1911 # osc_admit.c reporting (oversize Store entry): host test with ck_printf captured. 1912 $(OUT)/host/test_osc_admit: $(KDIR)/tests/test_osc_admit.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1913 @mkdir -p $(dir $@) 1914 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -I$(KDIR)/include -o $@ $< $(KDIR)/core/osc_admit.c $(ART_HOST_SRCS) 1915 1916 $(OUT)/host-san/test_osc_admit: $(KDIR)/tests/test_osc_admit.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h 1917 @mkdir -p $(dir $@) 1918 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) -I$(KDIR)/include -o $@ $< $(KDIR)/core/osc_admit.c $(ART_HOST_SRCS) 1919 1920 # aienos#383 realization receipts (artifact/osc_receipt.c): host test over the checker2-minted fixtures 1921 # (tests/fixtures/osc_receipt) and the kernel's own policy (core/osc_admit.c, release and qualification builds), plus 1922 # the mutation run: each MUT(n) guard of osc_receipt.c removed in turn (-DOSC_RCPT_MUTANT=n) must make the test FAIL. 1923 # The run refuses a guard count that differs from OSC_RCPT_MUTANTS, and a kernel-side build of a mutant. 1924 OSC_RCPT_MUTANTS := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1925 OSC_RCPT_TEST_DEF := -DOSC_RCPT_HOST_TEST -I$(KDIR)/include -DOSC_FIXTURE_DIR='"$(abspath $(KDIR)/tests/fixtures)"' 1926 OSC_RCPT_TEST_SRCS := $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_SRCS) 1927 $(OUT)/host/test_osc_receipt: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) $(wildcard $(KDIR)/tests/fixtures/osc_receipt_owner/*) 1928 @mkdir -p $(dir $@) 1929 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -o $@ $(OSC_RCPT_TEST_SRCS) 1930 1931 $(OUT)/host-san/test_osc_receipt: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) $(wildcard $(KDIR)/tests/fixtures/osc_receipt_owner/*) 1932 @mkdir -p $(dir $@) 1933 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -o $@ $(OSC_RCPT_TEST_SRCS) 1934 1935 # the same test against the release policy of core/osc_admit.c (no CK_SEED0B_TEST_ANCHOR): every TEST receipt refused 1936 $(OUT)/host/test_osc_receipt_release: $(KDIR)/tests/test_osc_receipt.c $(KDIR)/core/osc_admit.c $(ART_HOST_DEPS) $(KDIR)/tests/ck_test.h $(wildcard $(KDIR)/tests/fixtures/osc_receipt/*) $(wildcard $(KDIR)/tests/fixtures/osc_receipt_owner/*) 1937 @mkdir -p $(dir $@) 1938 $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -o $@ $(OSC_RCPT_TEST_SRCS) 1939 1940 osc-receipt-release: $(OUT)/host/test_osc_receipt_release 1941 @$< 1942 1943 # The code byte flip must be absent from a default object, a seed-anchor object 1944 # and a launch self-test object. It is present only with CK_OSC_RECEIPT_CODE_FLIP 1945 # (which also requires CK_OSC_RECEIPT_TEST). The compiler refuses the receipt-test 1946 # define without that opt-in, the opt-in alone, and the opt-in together with 1947 # CK_RELEASE_IMAGE, CK_HARDWARE_STAGING, CK_SERVICE, or a release build (no seed 1948 # anchor). make refuses the make variable for a release build, CK_HARDWARE_STAGING 1949 # and CK_SERVICE. 1950 OSC_FLIP_CC := $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -I$(KDIR)/include 1951 OSC_FLIP_SRC := $(KDIR)/core/osc_admit.c 1952 OSC_FLIP_OPT := -DCK_SEED0B_TEST_ANCHOR=1 -DCK_OSC_LAUNCH_TEST=1 -DCK_OSC_RECEIPT_TEST=1 -DCK_OSC_RECEIPT_CODE_FLIP=1 1953 osc-code-flip-guard: 1954 @mkdir -p $(OUT)/host-mut; fail=0; \ 1955 def=$(OUT)/host-mut/osc_admit_default.o; \ 1956 lau=$(OUT)/host-mut/osc_admit_launch.o; \ 1957 seed=$(OUT)/host-mut/osc_admit_seed.o; \ 1958 rcp=$(OUT)/host-mut/osc_admit_receipt.o; \ 1959 log=$(OUT)/host-mut/osc_flip_guard.log; \ 1960 if ! $(OSC_FLIP_CC) -c -o $$def $(OSC_FLIP_SRC); then echo "default osc_admit.c failed to compile (FAIL)"; fail=1; \ 1961 elif grep -aqF "TEST-ONLY post-admission code byte flip" $$def || nm $$def | grep -q ck_osc_receipt_test_code_flip; then \ 1962 echo "default osc_admit.o contains the code byte flip (FAIL)"; fail=1; \ 1963 else echo "default osc_admit.o has no code byte flip"; fi; \ 1964 if ! $(OSC_FLIP_CC) -DCK_SEED0B_TEST_ANCHOR=1 -c -o $$seed $(OSC_FLIP_SRC); then \ 1965 echo "seed-anchor osc_admit.c failed to compile (FAIL)"; fail=1; \ 1966 elif grep -aqF "TEST-ONLY post-admission code byte flip" $$seed || nm $$seed | grep -q ck_osc_receipt_test_code_flip; then \ 1967 echo "CK_SEED0B_TEST_ANCHOR object contains the code byte flip (FAIL)"; fail=1; \ 1968 else echo "CK_SEED0B_TEST_ANCHOR object has no code byte flip"; fi; \ 1969 if ! $(OSC_FLIP_CC) -DCK_SEED0B_TEST_ANCHOR=1 -DCK_OSC_LAUNCH_TEST=1 -c -o $$lau $(OSC_FLIP_SRC); then \ 1970 echo "launch-test osc_admit.c failed to compile (FAIL)"; fail=1; \ 1971 elif grep -aqF "TEST-ONLY post-admission code byte flip" $$lau || nm $$lau | grep -q ck_osc_receipt_test_code_flip; then \ 1972 echo "CK_OSC_LAUNCH_TEST object contains the code byte flip (FAIL)"; fail=1; \ 1973 else echo "CK_OSC_LAUNCH_TEST object has no code byte flip"; fi; \ 1974 if $(OSC_FLIP_CC) -DCK_SEED0B_TEST_ANCHOR=1 -DCK_OSC_LAUNCH_TEST=1 -DCK_OSC_RECEIPT_TEST=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 1975 echo "seed anchor plus CK_OSC_RECEIPT_TEST compiled the flip without CK_OSC_RECEIPT_CODE_FLIP (FAIL)"; fail=1; \ 1976 elif ! grep -qF "CK_SEED0B_TEST_ANCHOR does not enable the post-admission code byte flip" $$log; then \ 1977 echo "missing-opt-in refusal did not name CK_SEED0B_TEST_ANCHOR (FAIL)"; cat $$log; fail=1; \ 1978 else echo "CK_OSC_RECEIPT_TEST with only the seed anchor refused"; fi; \ 1979 if ! $(OSC_FLIP_CC) $(OSC_FLIP_OPT) -c -o $$rcp $(OSC_FLIP_SRC); then \ 1980 echo "receipt-test osc_admit.c failed to compile (FAIL)"; fail=1; \ 1981 elif ! grep -aqF "TEST-ONLY post-admission code byte flip" $$rcp || ! nm $$rcp | grep -q ck_osc_receipt_test_code_flip; then \ 1982 echo "CK_OSC_RECEIPT_CODE_FLIP object lacks the code byte flip (FAIL)"; fail=1; \ 1983 else echo "CK_OSC_RECEIPT_CODE_FLIP object contains the code byte flip"; fi; \ 1984 if $(OSC_FLIP_CC) -DCK_OSC_RECEIPT_CODE_FLIP=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 1985 echo "opt-in alone compiled (FAIL)"; fail=1; \ 1986 elif ! grep -qF "requires CK_OSC_RECEIPT_TEST" $$log; then \ 1987 echo "opt-in-alone refusal did not require CK_OSC_RECEIPT_TEST (FAIL)"; cat $$log; fail=1; \ 1988 else echo "CK_OSC_RECEIPT_CODE_FLIP alone refused"; fi; \ 1989 if $(OSC_FLIP_CC) -DCK_OSC_RECEIPT_TEST=1 -DCK_OSC_RECEIPT_CODE_FLIP=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 1990 echo "release build accepted the code byte flip (FAIL)"; fail=1; \ 1991 elif ! grep -qF "cannot be compiled into a release build" $$log; then \ 1992 echo "release refusal did not name the release build (FAIL)"; cat $$log; fail=1; \ 1993 else echo "code byte flip refused in a release build"; fi; \ 1994 if $(OSC_FLIP_CC) $(OSC_FLIP_OPT) -DCK_RELEASE_IMAGE=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 1995 echo "CK_RELEASE_IMAGE accepted the code byte flip (FAIL)"; fail=1; \ 1996 elif ! grep -qF "production or release define is present: CK_RELEASE_IMAGE" $$log; then \ 1997 echo "CK_RELEASE_IMAGE refusal did not name CK_RELEASE_IMAGE (FAIL)"; cat $$log; fail=1; \ 1998 else echo "code byte flip refused with CK_RELEASE_IMAGE"; fi; \ 1999 if $(OSC_FLIP_CC) $(OSC_FLIP_OPT) -DCK_HARDWARE_STAGING=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 2000 echo "CK_HARDWARE_STAGING accepted the code byte flip (FAIL)"; fail=1; \ 2001 elif ! grep -qF "production or release define is present: CK_HARDWARE_STAGING" $$log; then \ 2002 echo "hardware-staging refusal did not name CK_HARDWARE_STAGING (FAIL)"; cat $$log; fail=1; \ 2003 else echo "code byte flip refused with CK_HARDWARE_STAGING"; fi; \ 2004 if $(OSC_FLIP_CC) $(OSC_FLIP_OPT) -DCK_SERVICE=1 -fsyntax-only $(OSC_FLIP_SRC) >$$log 2>&1; then \ 2005 echo "CK_SERVICE accepted the code byte flip (FAIL)"; fail=1; \ 2006 elif ! grep -qF "production or release define is present: CK_SERVICE" $$log; then \ 2007 echo "service refusal did not name CK_SERVICE (FAIL)"; cat $$log; fail=1; \ 2008 else echo "code byte flip refused with CK_SERVICE"; fi; \ 2009 if $(MAKE) -s -n OUT=$(OUT)/host-mut/flip-mk-rel CK_OSC_RECEIPT_TEST=1 full >$$log 2>&1; then \ 2010 echo "make accepted CK_OSC_RECEIPT_TEST on a release build (FAIL)"; fail=1; \ 2011 elif ! grep -qF "cannot be compiled into a release build" $$log; then \ 2012 echo "make release refusal did not name the release build (FAIL)"; cat $$log; fail=1; \ 2013 else echo "make refuses CK_OSC_RECEIPT_TEST on a release build"; fi; \ 2014 if $(MAKE) -s -n OUT=$(OUT)/host-mut/flip-mk-hw CK_OSC_RECEIPT_TEST=1 CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=$(KDIR)/tests/fixtures/owner/TEST-FIXTURE-owner-pubkeys.txt CK_MACHINE_ID=$(KDIR)/tests/fixtures/owner/TEST-FIXTURE-machine-id.txt full >$$log 2>&1; then \ 2015 echo "make accepted CK_OSC_RECEIPT_TEST with CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2016 elif ! grep -qF "cannot be combined with CK_HARDWARE_STAGING" $$log; then \ 2017 echo "make hardware-staging refusal did not name CK_HARDWARE_STAGING (FAIL)"; cat $$log; fail=1; \ 2018 else echo "make refuses CK_OSC_RECEIPT_TEST with CK_HARDWARE_STAGING"; fi; \ 2019 if $(MAKE) -s -n OUT=$(OUT)/host-mut/flip-mk-svc CK_SERVICE=1 CK_OSC_RECEIPT_TEST=1 full >$$log 2>&1; then \ 2020 echo "make accepted CK_OSC_RECEIPT_TEST with CK_SERVICE (FAIL)"; fail=1; \ 2021 elif ! grep -qF "cannot be combined with CK_SERVICE" $$log; then \ 2022 echo "make service refusal did not name CK_SERVICE (FAIL)"; cat $$log; fail=1; \ 2023 else echo "make refuses CK_OSC_RECEIPT_TEST with CK_SERVICE"; fi; \ 2024 if [ $$fail = 0 ]; then echo "CK_OSC_CODE_FLIP_GUARD: PASS"; else echo "CK_OSC_CODE_FLIP_GUARD: FAIL"; exit 1; fi 2025 2026 osc-receipt-mutants: $(OUT)/host/test_osc_receipt 2027 @mkdir -p $(OUT)/host-mut; fail=0; \ 2028 tags=$$(grep -o 'MUT([0-9]*)' $(KDIR)/artifact/osc_receipt.c | sort -u | wc -l); \ 2029 uses=$$(grep -o 'MUT([0-9]*)' $(KDIR)/artifact/osc_receipt.c | wc -l); \ 2030 if [ $$tags != $(words $(OSC_RCPT_MUTANTS)) ] || [ $$uses != $$tags ]; then \ 2031 echo "guard count: $$uses uses, $$tags distinct, $(words $(OSC_RCPT_MUTANTS)) mutants listed (FAIL)"; fail=1; fi; \ 2032 $(OUT)/host/test_osc_receipt > $(OUT)/host-mut/osc_receipt_base.log 2>&1 || { echo "unmutated test_osc_receipt fails"; fail=1; }; \ 2033 killed=0; \ 2034 for m in $(OSC_RCPT_MUTANTS); do \ 2035 b=$(OUT)/host-mut/test_osc_receipt_m$$m; \ 2036 if ! $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) $(OSC_RCPT_TEST_DEF) -DCK_SEED0B_TEST_ANCHOR=1 -DOSC_RCPT_MUTANT=$$m -o $$b $(OSC_RCPT_TEST_SRCS); then \ 2037 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 2038 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 2039 elif grep -q "^test_osc_receipt: FAIL" $$b.log; then killed=$$((killed + 1)); \ 2040 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2041 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 2042 done; \ 2043 if $(HOSTCC) $(HCFLAGS) $(ART_HOST_INC) -DOSC_RCPT_MUTANT=1 -fsyntax-only $(KDIR)/artifact/osc_receipt.c 2>/dev/null; then \ 2044 echo "mutant flag accepted without OSC_RCPT_HOST_TEST (FAIL)"; fail=1; \ 2045 else echo "mutant flag refused without OSC_RCPT_HOST_TEST"; fi; \ 2046 if [ $$fail = 0 ]; then echo "CK_OSC_RECEIPT_MUTANTS: PASS ($$killed of $(words $(OSC_RCPT_MUTANTS)) killed)"; else echo "CK_OSC_RECEIPT_MUTANTS: FAIL"; exit 1; fi 2047 2048 # Continuity codec (C port cut 1, contract CONTINUITY_RECOVERY_CONTRACT.md, 2049 # aienos#222): host test plus TEST-only -D mutants, each of which must make 2050 # the test print its FAIL verdict. Mutant flags are refused under 2051 # CK_HARDWARE_STAGING (svc/continuity_codec.h). 2052 CC_HOST_SRCS := $(KDIR)/svc/continuity_codec.c $(NATIVE)/argus/sha256.c $(NATIVE)/store/store_v1.c 2053 CC_HOST_INC := -I$(KDIR)/svc -I$(NATIVE)/argus -I$(NATIVE)/store 2054 CC_HOST_DEPS := $(wildcard $(KDIR)/tests/fixtures/continuity_*.txt) $(CC_HOST_SRCS) $(KDIR)/svc/continuity_codec.h $(NATIVE)/argus/sha256.h \ 2055 $(NATIVE)/store/store_v1.h $(KDIR)/tests/ck_test.h 2056 # Cut 2 adds UNCHECKED_FORK_SUM (wrapping fork-count sum), MANIFEST_LAST_WAL_ZERO 2057 # (only the golden vectors see it), SKIP_D1 and SKIP_D2 (test-side: the golden 2058 # or the decode-agreement comparison is skipped; the test counts its 2059 # comparisons, so skipping one is a FAIL). 2060 CC_MUTANTS := CC_MUTANT_SKIP_TAKE_BOUND CC_MUTANT_ACCEPT_RESERVED CC_MUTANT_CHILD_INDEX_LE \ 2061 CC_MUTANT_TRUNCATE_AT_CAP CC_MUTANT_UNCHECKED_FORK_SUM CC_MUTANT_MANIFEST_LAST_WAL_ZERO \ 2062 CC_MUTANT_SKIP_D1 CC_MUTANT_SKIP_D2 2063 # Rust-emitted fixtures (D-1, D-2) read by the test at run time. 2064 CC_FIXTURES := $(abspath $(KDIR)/tests/fixtures) 2065 CC_FIXTURE_DEF := -DCC_FIXTURE_DIR='"$(CC_FIXTURES)"' 2066 2067 $(OUT)/host/test_continuity_codec: $(KDIR)/tests/test_continuity_codec.c $(CC_HOST_DEPS) 2068 @mkdir -p $(dir $@) 2069 $(HOSTCC) $(HCFLAGS) $(CC_HOST_INC) $(CC_FIXTURE_DEF) -o $@ $< $(CC_HOST_SRCS) 2070 2071 $(OUT)/host-san/test_continuity_codec: $(KDIR)/tests/test_continuity_codec.c $(CC_HOST_DEPS) 2072 @mkdir -p $(dir $@) 2073 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CC_HOST_INC) $(CC_FIXTURE_DEF) -o $@ $< $(CC_HOST_SRCS) 2074 2075 continuity-mutants: $(OUT)/host/test_continuity_codec continuity-resolve-mutants continuity-commit-mutants continuity-recovery-mutants continuity-subject-mutants continuity-subject-provision-mutants 2076 @mkdir -p $(OUT)/host-mut; fail=0; \ 2077 $(OUT)/host/test_continuity_codec > $(OUT)/host-mut/base.log 2>&1 || { echo "unmutated test_continuity_codec fails"; fail=1; }; \ 2078 for m in $(CC_MUTANTS); do \ 2079 b=$(OUT)/host-mut/test_continuity_codec_$$m; \ 2080 if ! $(HOSTCC) $(HCFLAGS) $(CC_HOST_INC) $(CC_FIXTURE_DEF) -D$$m -o $$b $(KDIR)/tests/test_continuity_codec.c $(CC_HOST_SRCS); then \ 2081 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 2082 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 2083 elif grep -q "^test_continuity_codec: FAIL" $$b.log; then \ 2084 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2085 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 2086 done; \ 2087 if $(HOSTCC) $(HCFLAGS) $(CC_HOST_INC) -DCK_HARDWARE_STAGING=1 -DCC_MUTANT_SKIP_TAKE_BOUND \ 2088 -fsyntax-only $(KDIR)/svc/continuity_codec.c 2>/dev/null; then \ 2089 echo "mutant flag accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2090 else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ 2091 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_CODEC_MUTANTS: PASS"; else echo "CK_CONTINUITY_CODEC_MUTANTS: FAIL"; exit 1; fi 2092 2093 # Continuity resolve + challenge/HMAC (C port cut 3): host test over the REAL 2094 # sealed Store in a file (native/store + m5 + crypto + disk), TEST-only -D 2095 # mutants, each of which must make the test print its FAIL verdict. Mutant flags 2096 # are refused under CK_HARDWARE_STAGING (svc/continuity_resolve.h). 2097 CR_STORE_SRCS := $(NATIVE)/store/store_v1.c $(NATIVE)/store/store_engine.c $(NATIVE)/store/store_disk.c \ 2098 $(NATIVE)/store/store_sealed.c $(NATIVE)/store/torn_slot.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \ 2099 $(NATIVE)/m5/m5_keys.c $(NATIVE)/m5/m5_envelope.c $(NATIVE)/m5/m5_state.c $(NATIVE)/crypto/aes.c \ 2100 $(NATIVE)/crypto/polyval.c $(NATIVE)/crypto/gcm_siv.c $(NATIVE)/crypto/hmac.c $(NATIVE)/crypto/ct.c 2101 CR_HOST_SRCS := $(KDIR)/svc/continuity_resolve.c $(KDIR)/svc/continuity_resolve_sealed.c \ 2102 $(KDIR)/svc/continuity_codec.c $(NATIVE)/argus/sha256.c $(CR_STORE_SRCS) 2103 CR_HOST_INC := -I$(KDIR)/svc -I$(NATIVE)/argus -I$(NATIVE)/store -I$(NATIVE)/disk -I$(NATIVE)/m5 -I$(NATIVE)/crypto 2104 CR_HOST_DEPS := $(wildcard $(KDIR)/tests/fixtures/continuity_*.txt) $(CR_HOST_SRCS) $(wildcard $(KDIR)/svc/continuity_*.h) \ 2105 $(wildcard $(NATIVE)/store/*.h $(NATIVE)/m5/*.h $(NATIVE)/disk/*.h $(NATIVE)/crypto/*.h) $(KDIR)/tests/ck_test.h 2106 CR_FIXTURE_DEF := -DCR_FIXTURE_DIR='"$(CC_FIXTURES)"' 2107 # MC-2 orphan check, MC-4 previous, MC-12 conflict, MR-2 digest, MR-3 action, 2108 # MR-4 16-byte compare, MR-8 bare SHA-256 and no domain. 2109 CR_MUTANTS := CR_MUTANT_NO_ORPHAN_CHECK CR_MUTANT_IGNORE_PREVIOUS CR_MUTANT_SKIP_CONFLICT \ 2110 CR_MUTANT_CHALLENGE_NO_DIGEST CR_MUTANT_CHALLENGE_NO_ACTION CR_MUTANT_COMPARE_16 \ 2111 CR_MUTANT_BARE_SHA256 CR_MUTANT_NO_DOMAIN 2112 2113 $(OUT)/host/test_continuity_resolve: $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_DEPS) 2114 @mkdir -p $(dir $@) 2115 $(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -o $@ $< $(CR_HOST_SRCS) 2116 2117 $(OUT)/host-san/test_continuity_resolve: $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_DEPS) 2118 @mkdir -p $(dir $@) 2119 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -o $@ $< $(CR_HOST_SRCS) 2120 2121 continuity-resolve-mutants: $(OUT)/host/test_continuity_resolve 2122 @mkdir -p $(OUT)/host-mut; fail=0; \ 2123 $(OUT)/host/test_continuity_resolve > $(OUT)/host-mut/resolve_base.log 2>&1 || { echo "unmutated test_continuity_resolve fails"; fail=1; }; \ 2124 for m in $(CR_MUTANTS); do \ 2125 b=$(OUT)/host-mut/test_continuity_resolve_$$m; \ 2126 if ! $(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -D$$m -o $$b $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_SRCS); then \ 2127 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 2128 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 2129 elif grep -q "^test_continuity_resolve: FAIL" $$b.log; then \ 2130 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2131 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 2132 done; \ 2133 for m in $(CR_MUTANTS); do \ 2134 if $(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \ 2135 -fsyntax-only $(KDIR)/svc/continuity_resolve.c 2>/dev/null; then \ 2136 echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2137 else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \ 2138 done; \ 2139 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_RESOLVE_MUTANTS: PASS"; else echo "CK_CONTINUITY_RESOLVE_MUTANTS: FAIL"; exit 1; fi 2140 2141 2142 # Continuity provision/commit/resume (C port cut 4): host test over the REAL sealed 2143 # Store in a file with the real ck_rng over a mocked RNDR, power cuts at every 2144 # checkpoint and block boundary, and TEST-only -D mutants, each of which must make 2145 # the test print its FAIL verdict. Mutant flags are refused under 2146 # CK_HARDWARE_STAGING (svc/continuity_commit.h; MC-11 in svc/continuity_codec.h). 2147 CM_HOST_SRCS := $(KDIR)/svc/continuity_commit.c $(CR_HOST_SRCS) $(KDIR)/core/entropy.c 2148 CM_HOST_INC := $(CR_HOST_INC) -I$(KDIR)/core 2149 CM_HOST_DEPS := $(CM_HOST_SRCS) $(wildcard $(KDIR)/svc/continuity_*.h) $(KDIR)/core/entropy.h \ 2150 $(wildcard $(NATIVE)/store/*.h $(NATIVE)/m5/*.h $(NATIVE)/disk/*.h $(NATIVE)/crypto/*.h) $(KDIR)/tests/ck_test.h 2151 # MC-1 resume provisions, MC-3 resume skips the commit, MC-7 provision with a root, 2152 # MC-8 split transaction, MC-9 writable check removed, MC-10 fixed agent id, 2153 # MC-11 silent truncation (the codec's CC_MUTANT_TRUNCATE_AT_CAP). 2154 CM_MUTANTS := CM_MUTANT_RESUME_PROVISIONS CM_MUTANT_RESUME_NO_COMMIT CM_MUTANT_PROVISION_WITH_ROOT \ 2155 CM_MUTANT_SPLIT_TXN CM_MUTANT_NO_WRITABLE_CHECK CM_MUTANT_FIXED_AGENT CC_MUTANT_TRUNCATE_AT_CAP 2156 2157 $(OUT)/host/test_continuity_commit: $(KDIR)/tests/test_continuity_commit.c $(CM_HOST_DEPS) 2158 @mkdir -p $(dir $@) 2159 $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -o $@ $< $(CM_HOST_SRCS) 2160 2161 $(OUT)/host-san/test_continuity_commit: $(KDIR)/tests/test_continuity_commit.c $(CM_HOST_DEPS) 2162 @mkdir -p $(dir $@) 2163 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CM_HOST_INC) -o $@ $< $(CM_HOST_SRCS) 2164 2165 continuity-commit-mutants: $(OUT)/host/test_continuity_commit 2166 @mkdir -p $(OUT)/host-mut; fail=0; \ 2167 $(OUT)/host/test_continuity_commit > $(OUT)/host-mut/commit_base.log 2>&1 || { echo "unmutated test_continuity_commit fails"; fail=1; }; \ 2168 for m in $(CM_MUTANTS); do \ 2169 b=$(OUT)/host-mut/test_continuity_commit_$$m; \ 2170 if ! $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -D$$m -o $$b $(KDIR)/tests/test_continuity_commit.c $(CM_HOST_SRCS); then \ 2171 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 2172 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 2173 elif grep -q "^test_continuity_commit: FAIL" $$b.log; then \ 2174 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2175 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 2176 done; \ 2177 for m in $(CM_MUTANTS); do \ 2178 if $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \ 2179 -fsyntax-only $(KDIR)/svc/continuity_commit.c 2>/dev/null; then \ 2180 echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2181 else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \ 2182 done; \ 2183 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_COMMIT_MUTANTS: PASS"; else echo "CK_CONTINUITY_COMMIT_MUTANTS: FAIL"; exit 1; fi 2184 2185 # ALLEN subject state (continuity object kind 24; ARCH-0035 / OS-0018, PROPOSED): 2186 # host test over the REAL sealed Store in a file, a two-process restart proof 2187 # (test-continuity-subject-restart) and TEST-only -D mutants, each of which must 2188 # make the test print its FAIL verdict. Mutant flags are refused under 2189 # CK_HARDWARE_STAGING (svc/continuity_subject.h). 2190 CS_HOST_SRCS := $(KDIR)/svc/continuity_subject.c $(CM_HOST_SRCS) 2191 CS_HOST_DEPS := $(CS_HOST_SRCS) $(wildcard $(KDIR)/svc/continuity_*.h) $(KDIR)/core/entropy.h \ 2192 $(wildcard $(NATIVE)/store/*.h $(NATIVE)/m5/*.h $(NATIVE)/disk/*.h $(NATIVE)/crypto/*.h) $(KDIR)/tests/ck_test.h 2193 # MS-1 foreign root/agent accepted at resolve, MS-2 two active intents in one slot 2194 # accepted, MS-3 intent id derivation not checked, MS-4 chain fork accepted. 2195 CS_MUTANTS := CS_MUTANT_ACCEPT_FOREIGN CS_MUTANT_ACCEPT_TWO_ACTIVE CS_MUTANT_SKIP_INTENT_ID CS_MUTANT_ACCEPT_FORK 2196 2197 $(OUT)/host/test_continuity_subject: $(KDIR)/tests/test_continuity_subject.c $(CS_HOST_DEPS) 2198 @mkdir -p $(dir $@) 2199 $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -o $@ $< $(CS_HOST_SRCS) 2200 2201 $(OUT)/host-san/test_continuity_subject: $(KDIR)/tests/test_continuity_subject.c $(CS_HOST_DEPS) 2202 @mkdir -p $(dir $@) 2203 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CM_HOST_INC) -o $@ $< $(CS_HOST_SRCS) 2204 2205 # ALLEN-G2 on the host: the writer process provisions and commits a subject with 2206 # one standing intent and exits; a second process reopens the same Store image, 2207 # resolves the same subject object and finds the same intent. 2208 .PHONY: test-continuity-subject-restart 2209 test-continuity-subject-restart: $(OUT)/host/test_continuity_subject 2210 @mkdir -p $(OUT)/host-subject; img=$(OUT)/host-subject/allen.img; rm -f $$img; \ 2211 $(OUT)/host/test_continuity_subject --write $$img > $(OUT)/host-subject/write.log || { cat $(OUT)/host-subject/write.log; exit 1; }; \ 2212 id=$$(sed -n 's/^ALLEN subject id: //p' $(OUT)/host-subject/write.log); \ 2213 test -n "$$id" || { echo "no subject id from the writer"; exit 1; }; \ 2214 $(OUT)/host/test_continuity_subject --restore $$img $$id > $(OUT)/host-subject/restore.log || { cat $(OUT)/host-subject/restore.log; exit 1; }; \ 2215 grep -h '^ALLEN' $(OUT)/host-subject/write.log $(OUT)/host-subject/restore.log; \ 2216 echo "CK_CONTINUITY_SUBJECT_RESTART: PASS (two processes, sealed Store image $$img)" 2217 2218 continuity-subject-mutants: $(OUT)/host/test_continuity_subject 2219 @mkdir -p $(OUT)/host-mut; fail=0; \ 2220 $(OUT)/host/test_continuity_subject > $(OUT)/host-mut/subject_base.log 2>&1 || { echo "unmutated test_continuity_subject fails"; fail=1; }; \ 2221 for m in $(CS_MUTANTS); do \ 2222 b=$(OUT)/host-mut/test_continuity_subject_$$m; \ 2223 if ! $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -D$$m -o $$b $(KDIR)/tests/test_continuity_subject.c $(CS_HOST_SRCS); then \ 2224 echo "mutant $$m does not build (FAIL)"; fail=1; continue; fi; \ 2225 $$b > $$b.log 2>&1; \ 2226 if grep -q "^test_continuity_subject: FAIL" $$b.log; then echo "mutant $$m caught"; \ 2227 else echo "mutant $$m NOT caught (FAIL)"; fail=1; fi; \ 2228 if $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \ 2229 -fsyntax-only $(KDIR)/svc/continuity_subject.c 2>/dev/null; then \ 2230 echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2231 else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \ 2232 done; \ 2233 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_SUBJECT_MUTANTS: PASS"; else echo "CK_CONTINUITY_SUBJECT_MUTANTS: FAIL"; exit 1; fi 2234 2235 # ALLEN genesis at identity provisioning (svc/continuity_subject_provision.c; 2236 # ARCH-0035 / OS-0018, PROPOSED): identity and genesis subject in ONE Store 2237 # transaction, power cuts at every checkpoint and block boundary, and the 2238 # TEST-only split-transaction mutant (MSP-1), which the test must catch. The 2239 # mutant flag is refused under CK_HARDWARE_STAGING. 2240 CSP_HOST_SRCS := $(KDIR)/svc/continuity_subject_provision.c $(CS_HOST_SRCS) 2241 CSP_HOST_DEPS := $(CSP_HOST_SRCS) $(CS_HOST_DEPS) 2242 CSP_MUTANTS := CS_MUTANT_PROVISION_SPLIT_TXN 2243 2244 $(OUT)/host/test_continuity_subject_provision: $(KDIR)/tests/test_continuity_subject_provision.c $(CSP_HOST_DEPS) 2245 @mkdir -p $(dir $@) 2246 $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -o $@ $< $(CSP_HOST_SRCS) 2247 2248 $(OUT)/host-san/test_continuity_subject_provision: $(KDIR)/tests/test_continuity_subject_provision.c $(CSP_HOST_DEPS) 2249 @mkdir -p $(dir $@) 2250 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CM_HOST_INC) -o $@ $< $(CSP_HOST_SRCS) 2251 2252 continuity-subject-provision-mutants: $(OUT)/host/test_continuity_subject_provision 2253 @mkdir -p $(OUT)/host-mut; fail=0; \ 2254 $(OUT)/host/test_continuity_subject_provision > $(OUT)/host-mut/subject_provision_base.log 2>&1 || { echo "unmutated test_continuity_subject_provision fails"; fail=1; }; \ 2255 for m in $(CSP_MUTANTS); do \ 2256 b=$(OUT)/host-mut/test_continuity_subject_provision_$$m; \ 2257 if ! $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -D$$m -o $$b $(KDIR)/tests/test_continuity_subject_provision.c $(CSP_HOST_SRCS); then \ 2258 echo "mutant $$m does not build (FAIL)"; fail=1; continue; fi; \ 2259 $$b > $$b.log 2>&1; \ 2260 if grep -q "^test_continuity_subject_provision: FAIL" $$b.log; then echo "mutant $$m caught ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2261 else echo "mutant $$m NOT caught (FAIL)"; fail=1; fi; \ 2262 if $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \ 2263 -fsyntax-only $(KDIR)/svc/continuity_subject_provision.c 2>/dev/null; then \ 2264 echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2265 else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \ 2266 done; \ 2267 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_SUBJECT_PROVISION_MUTANTS: PASS"; else echo "CK_CONTINUITY_SUBJECT_PROVISION_MUTANTS: FAIL"; exit 1; fi 2268 2269 # Continuity Recovery Core (C port cut 5): host test over the REAL sealed Store in a 2270 # file, TEST-only -D mutants, each of which must make the test print its FAIL verdict. 2271 # Mutant flags are refused under CK_HARDWARE_STAGING (svc/continuity_recovery.h). 2272 RC_HOST_SRCS := $(KDIR)/svc/continuity_recovery.c $(CM_HOST_SRCS) 2273 RC_HOST_DEPS := $(RC_HOST_SRCS) $(wildcard $(KDIR)/svc/continuity_*.h) $(KDIR)/core/entropy.h \ 2274 $(wildcard $(NATIVE)/store/*.h $(NATIVE)/m5/*.h $(NATIVE)/disk/*.h $(NATIVE)/crypto/*.h) $(KDIR)/tests/ck_test.h 2275 # MR-1 inspection writes, MR-5 degraded mount read as Unprovisioned, MR-6 repair zeroes the 2276 # active slot, MR-7 repair without a resolved identity, MR-9 operator provisioning writes 2277 # source Qualification. (MR-2, MR-3, MR-4, MR-8 are the cut 3 mutants.) 2278 RC_MUTANTS := RC_MUTANT_INSPECT_WRITES RC_MUTANT_DEGRADED_IS_UNPROVISIONED RC_MUTANT_REPAIR_ACTIVE \ 2279 RC_MUTANT_REPAIR_NO_IDENTITY RC_MUTANT_PROVISION_QUALIFICATION 2280 2281 $(OUT)/host/test_continuity_recovery: $(KDIR)/tests/test_continuity_recovery.c $(RC_HOST_DEPS) 2282 @mkdir -p $(dir $@) 2283 $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -o $@ $< $(RC_HOST_SRCS) 2284 2285 $(OUT)/host-san/test_continuity_recovery: $(KDIR)/tests/test_continuity_recovery.c $(RC_HOST_DEPS) 2286 @mkdir -p $(dir $@) 2287 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CM_HOST_INC) -o $@ $< $(RC_HOST_SRCS) 2288 2289 # K-6 region geometry (cut 7): host test over the real sealed Store in a file; needs dev/disk_layout.h. 2290 $(OUT)/host/test_continuity_geometry: $(KDIR)/tests/test_continuity_geometry.c $(RC_HOST_DEPS) $(KDIR)/dev/disk_layout.h 2291 @mkdir -p $(dir $@) 2292 $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -I$(KDIR)/dev -o $@ $< $(RC_HOST_SRCS) 2293 2294 $(OUT)/host-san/test_continuity_geometry: $(KDIR)/tests/test_continuity_geometry.c $(RC_HOST_DEPS) $(KDIR)/dev/disk_layout.h 2295 @mkdir -p $(dir $@) 2296 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CM_HOST_INC) -I$(KDIR)/dev -o $@ $< $(RC_HOST_SRCS) 2297 2298 continuity-recovery-mutants: $(OUT)/host/test_continuity_recovery 2299 @mkdir -p $(OUT)/host-mut; fail=0; \ 2300 $(OUT)/host/test_continuity_recovery > $(OUT)/host-mut/recovery_base.log 2>&1 || { echo "unmutated test_continuity_recovery fails"; fail=1; }; \ 2301 for m in $(RC_MUTANTS); do \ 2302 b=$(OUT)/host-mut/test_continuity_recovery_$$m; \ 2303 if ! $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -D$$m -o $$b $(KDIR)/tests/test_continuity_recovery.c $(RC_HOST_SRCS); then \ 2304 echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \ 2305 if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \ 2306 elif grep -q "^test_continuity_recovery: FAIL" $$b.log; then \ 2307 echo "mutant $$m: killed ($$(grep -c '^ FAIL ' $$b.log) checks failed)"; \ 2308 else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \ 2309 done; \ 2310 for m in $(RC_MUTANTS); do \ 2311 if $(HOSTCC) $(HCFLAGS) $(CM_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \ 2312 -fsyntax-only $(KDIR)/svc/continuity_recovery.c 2>/dev/null; then \ 2313 echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \ 2314 else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \ 2315 done; \ 2316 if [ $$fail = 0 ]; then echo "CK_CONTINUITY_RECOVERY_MUTANTS: PASS"; else echo "CK_CONTINUITY_RECOVERY_MUTANTS: FAIL"; exit 1; fi 2317 2318 ART_TOOL := $(OUT)/host/ck_artifact_tool 2319 $(ART_TOOL): $(KDIR)/tools/ck_artifact_tool.c $(ART_HOST_DEPS) 2320 @mkdir -p $(dir $@) 2321 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror $(ART_HOST_INC) -o $@ $< $(ART_HOST_SRCS) 2322 tool: $(ART_TOOL) 2323 2324 # Boot-disk image tool (scripts/qemu_ck_artifact_test.sh): writes signed artifacts 2325 # into the sealed Store on a raw NVMe image with the kernel's own Store code 2326 # (store_boot.c, artifact_store.c). Hosted; never part of an image. 2327 STORE_IMG_TOOL := $(OUT)/host/ck_store_image 2328 STORE_IMG_SRCS := $(STAGE_OWN_SRCS) $(KDIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(NATIVE)/disk/disk_file.c \ 2329 $(KDIR)/svc/tests/ck_host.c $(KDIR)/tools/ck_store_image.c 2330 $(STORE_IMG_TOOL): $(STORE_IMG_SRCS) $(STAGE_HDRS) 2331 @mkdir -p $(dir $@) 2332 $(HOSTCC) $(STAGE_HOST_FLAGS) $(STAGE_INC) -o $@ $(STORE_IMG_SRCS) 2333 store-image: $(STORE_IMG_TOOL) 2334 2335 # N3 memory gate tool (scripts/qemu_ck_memory_test.sh, aienos#329): appends a 2336 # foreign-bound or a corrupted record to the Cortex journal of a provisioned 2337 # TEST-keys disk image. Hosted; never part of an image. 2338 CORTEX_IMG_TOOL := $(OUT)/host/ck_cortex_image 2339 CORTEX_IMG_SRCS := $(STAGE_OWN_SRCS) $(KDIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(NATIVE)/disk/disk_file.c \ 2340 $(KDIR)/svc/tests/ck_host.c $(STAGE_CORTEX_SRCS) $(KDIR)/core/context.c $(KDIR)/tools/ck_cortex_image.c 2341 $(CORTEX_IMG_TOOL): $(CORTEX_IMG_SRCS) $(STAGE_HDRS) $(KDIR)/core/context.h 2342 @mkdir -p $(dir $@) 2343 $(HOSTCC) $(STAGE_HOST_FLAGS) $(STAGE_INC) -o $@ $(CORTEX_IMG_SRCS) 2344 cortex-image: $(CORTEX_IMG_TOOL) 2345 2346 # Continuity / Recovery Core QEMU gate tool (scripts/qemu_ck_continuity_test.sh, 2347 # scripts/qemu_ck_recovery_test.sh): operator response, degraded-peer injection, 2348 # AgentRoot corruption on a boot-disk image. Hosted; never part of an image. 2349 CONT_TOOL := $(OUT)/host/ck_cont_tool 2350 CONT_TOOL_SRCS := $(STAGE_OWN_SRCS) $(KDIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(NATIVE)/disk/disk_file.c \ 2351 $(KDIR)/svc/tests/ck_host.c $(KDIR)/svc/continuity_resolve.c $(KDIR)/svc/continuity_codec.c \ 2352 $(KDIR)/svc/continuity_resolve_sealed.c $(KDIR)/svc/continuity_subject.c \ 2353 $(KDIR)/tools/ck_cont_tool.c 2354 $(CONT_TOOL): $(CONT_TOOL_SRCS) $(STAGE_HDRS) 2355 @mkdir -p $(dir $@) 2356 $(HOSTCC) $(STAGE_HOST_FLAGS) $(STAGE_INC) -idirafter $(KDIR)/core -o $@ $(CONT_TOOL_SRCS) 2357 cont-tool: $(CONT_TOOL) 2358 2359 # GPT boot-disk image tool (QEMU gates; hosted, never part of an image). 2360 GPT_IMG_TOOL := $(OUT)/host/ck_gpt_image 2361 GPT_IMG_SRCS := $(KDIR)/dev/disk_part.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \ 2362 $(KDIR)/tools/gpt_write.c $(KDIR)/tools/ck_gpt_image.c 2363 $(GPT_IMG_TOOL): $(GPT_IMG_SRCS) $(KDIR)/dev/disk_part.h $(KDIR)/tools/gpt_write.h $(NATIVE)/disk/disk.h $(BOOT)/slot_format.h 2364 @mkdir -p $(dir $@) 2365 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(KDIR)/dev -I$(KDIR)/tools -I$(NATIVE)/disk -o $@ $(GPT_IMG_SRCS) 2366 gpt-image: $(GPT_IMG_TOOL) 2367 2368 # MODEL.MAP tool (model ingest gate + the attended-boot staging; hosted, never 2369 # part of an image). SHA-256 is the kernel's own (argus). 2370 MODEL_MAP_TOOL := $(OUT)/host/ck_model_map 2371 $(MODEL_MAP_TOOL): $(KDIR)/tools/ck_model_map.c $(NATIVE)/argus/sha256.c $(BOOT)/model_map.h $(NATIVE)/argus/sha256.h 2372 @mkdir -p $(dir $@) 2373 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(BOOT) -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_model_map.c $(NATIVE)/argus/sha256.c 2374 model-map: $(MODEL_MAP_TOOL) 2375 2376 # GSP firmware container inspector (aienos#286 cut C, host work only: inventory 2377 # and refusal checks for the NVIDIA GSP-RM ELF container the pinned Linux 2378 # driver loads for the GB10; docs/GB10_FIRMWARE_INVENTORY.md). Never loads 2379 # anything. SHA-256 is the kernel's own (argus). The real file is optional: 2380 # when absent the inspect step is NOT_RUN, the self-test still runs. 2381 GSP_FW_TOOL := $(OUT)/host/ck_gsp_fw_inspect 2382 GSP_FW_FILE ?= /lib/firmware/nvidia/580.173.02/gsp_ga10x.bin 2383 GSP_FW_SHA256 := `32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963` 2384 $(GSP_FW_TOOL): $(KDIR)/tools/ck_gsp_fw_inspect.c $(NATIVE)/argus/sha256.c $(NATIVE)/argus/sha256.h 2385 @mkdir -p $(dir $@) 2386 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_gsp_fw_inspect.c $(NATIVE)/argus/sha256.c 2387 gsp-fw-inspect: $(GSP_FW_TOOL) 2388 gsp-fw-inspect-test: $(GSP_FW_TOOL) 2389 $(GSP_FW_TOOL) selftest 2390 @if [ -r "$(GSP_FW_FILE)" ]; then \ 2391 out=$$($(GSP_FW_TOOL) inspect "$(GSP_FW_FILE)" --family gb10y --expect-version 580.173.02) || { echo "$$out"; echo "CK_GSP_FW_INSPECT_PIN: FAIL (refused)"; exit 1; }; \ 2392 echo "$$out" | grep -E '^(fwversion|build_id|signature_section|sha256_file|RESULT)'; \ 2393 echo "$$out" | grep -q '^sha256_file $(GSP_FW_SHA256)$$' && echo "CK_GSP_FW_INSPECT_PIN: PASS" || { echo "CK_GSP_FW_INSPECT_PIN: FAIL (digest differs from the pin)"; exit 1; }; \ 2394 else echo "CK_GSP_FW_INSPECT_PIN: NOT_RUN ($(GSP_FW_FILE) absent)"; fi 2395 2396 # ---- host encoder/decoder for the SEC2 chain-of-trust boot message (aienos#286 cut C/D host work) ---- 2397 # Byte-exact NVDM-over-MCTP packet and GSP_FMC_BOOT_PARAMS layouts from the pinned 2398 # driver source; self-test = layouts, golden headers, round trips, every mutation refused. 2399 # Never loads anything. docs/GB10_FIRMWARE_INVENTORY.md section 10. 2400 GSP_COT_TOOL := $(OUT)/host/ck_gsp_cot_encode 2401 $(GSP_COT_TOOL): $(KDIR)/tools/ck_gsp_cot_encode.c $(NATIVE)/argus/sha256.c $(NATIVE)/argus/sha256.h 2402 @mkdir -p $(dir $@) 2403 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_gsp_cot_encode.c $(NATIVE)/argus/sha256.c 2404 gsp-cot-encode: $(GSP_COT_TOOL) 2405 gsp-cot-test: $(GSP_COT_TOOL) 2406 $(GSP_COT_TOOL) selftest | grep -E '^CK_GSP_COT_ENCODE_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_COT_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2407 @$(GSP_COT_TOOL) selftest | tail -1 2408 2409 # ---- host extractor for the GB10B firmware arrays compiled into the pinned driver (aienos#286 cut C host work) ---- 2410 # Parses the two public generated files g_bindata_kgspGetBinArchive{GspRmBoot,GspRmFmcGfwProdSigned}_GB10B.c 2411 # (MIT), cross-checks every size/flag/record, inflates the compressed descriptor with our own 2412 # DEFLATE decoder (CRC-32 + ISIZE trailer verified), checks UCODE_HASH == SHA-384(UCODE_IMAGE) 2413 # and the RM_RISCV_UCODE_DESC offsets, and writes the arrays as files. Never loads anything. 2414 # The driver files are optional (fetch them from the 580.173.02 tag into GSP_BINDATA_DIR); 2415 # when absent the pin step is NOT_RUN, the self-test still runs. docs/GB10_FIRMWARE_INVENTORY.md 3.3 and 11. 2416 GSP_BINDATA_TOOL := $(OUT)/host/ck_gsp_bindata_extract 2417 GSP_BINDATA_DIR ?= $(HOME)/.cache/aienos/open-gpu-kernel-modules-580.173.02 2418 GSP_BINDATA_FMC_IMAGE_SHA256 := `b13ead4b9a6b8a0d268f3094cc4f4521d6be8a9a525edbc9a8f3f397c86f1f2e` 2419 GSP_BINDATA_BOOT_PROD_SHA256 := `427a691d8453f02548d395f40ac900eb0d5b8ea864e8f14f958eef890ba400a2` 2420 $(GSP_BINDATA_TOOL): $(KDIR)/tools/ck_gsp_bindata_extract.c $(NATIVE)/argus/sha256.c $(NATIVE)/argus/sha256.h 2421 @mkdir -p $(dir $@) 2422 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_gsp_bindata_extract.c $(NATIVE)/argus/sha256.c 2423 gsp-bindata-extract: $(GSP_BINDATA_TOOL) 2424 gsp-bindata-test: $(GSP_BINDATA_TOOL) 2425 $(GSP_BINDATA_TOOL) selftest | grep -E '^CK_GSP_BINDATA_EXTRACT_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_BINDATA_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2426 @$(GSP_BINDATA_TOOL) selftest | tail -1 2427 @fmc="$(GSP_BINDATA_DIR)/g_bindata_kgspGetBinArchiveGspRmFmcGfwProdSigned_GB10B.c"; boot="$(GSP_BINDATA_DIR)/g_bindata_kgspGetBinArchiveGspRmBoot_GB10B.c"; \ 2428 if [ -r "$$fmc" ] && [ -r "$$boot" ]; then \ 2429 out=$$($(GSP_BINDATA_TOOL) extract "$$fmc") || { echo "$$out"; echo "CK_GSP_BINDATA_PIN: FAIL (FMC file refused)"; exit 1; }; \ 2430 echo "$$out" | grep -E '^(hash384|array .* UCODE_IMAGE |RESULT)'; \ 2431 echo "$$out" | grep -q '^array .* UCODE_IMAGE .* size=195912 sha256=$(GSP_BINDATA_FMC_IMAGE_SHA256)$$' || { echo "CK_GSP_BINDATA_PIN: FAIL (FMC image digest differs from the pin)"; exit 1; }; \ 2432 out=$$($(GSP_BINDATA_TOOL) extract "$$boot") || { echo "$$out"; echo "CK_GSP_BINDATA_PIN: FAIL (boot file refused)"; exit 1; }; \ 2433 echo "$$out" | grep -E '^(desc UCODE_DESC_PROD|array .* UCODE_IMAGE_PROD |RESULT)'; \ 2434 echo "$$out" | grep -q '^array .* UCODE_IMAGE_PROD .* size=196608 sha256=$(GSP_BINDATA_BOOT_PROD_SHA256)$$' || { echo "CK_GSP_BINDATA_PIN: FAIL (boot PROD image digest differs from the pin)"; exit 1; }; \ 2435 echo "$$out" | grep -q '^desc UCODE_DESC_PROD version=5 manifest=0x0+0xa00 monitor_data=0xa00+0xa600 monitor_code=0xb000+0x24d00 monitor_enabled=1 ' || { echo "CK_GSP_BINDATA_PIN: FAIL (descriptor differs from the pin)"; exit 1; }; \ 2436 echo "CK_GSP_BINDATA_PIN: PASS"; \ 2437 else echo "CK_GSP_BINDATA_PIN: NOT_RUN ($(GSP_BINDATA_DIR) lacks the two GB10B bindata files)"; fi 2438 2439 # ---- host encoder/decoder for the GSP-RM boot-argument blocks (aienos#286 cut C host work) ---- 2440 # Byte-exact GspFwWprMeta (256), libos init-argument page, log-buffer PTE prefix, 2441 # GSP_ARGUMENTS_CACHED page, RPC shared-buffer page table and radix-3 ELF table, with 2442 # the GB10B values traced from the pinned driver (heap 133 MiB, 7 logs + RMARGS, 129 PTEs). 2443 # Self-test = compiler layouts, golden constants, round trips, every mutation refused. 2444 # Never loads anything. docs/GB10_FIRMWARE_INVENTORY.md section 12. 2445 GSP_BOOTARGS_TOOL := $(OUT)/host/ck_gsp_boot_args_encode 2446 $(GSP_BOOTARGS_TOOL): $(KDIR)/tools/ck_gsp_boot_args_encode.c 2447 @mkdir -p $(dir $@) 2448 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $(KDIR)/tools/ck_gsp_boot_args_encode.c 2449 gsp-bootargs-encode: $(GSP_BOOTARGS_TOOL) 2450 gsp-bootargs-test: $(GSP_BOOTARGS_TOOL) 2451 $(GSP_BOOTARGS_TOOL) selftest | grep -E '^CK_GSP_BOOT_ARGS_ENCODE_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_BOOTARGS_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2452 @$(GSP_BOOTARGS_TOOL) selftest | tail -1 2453 2454 # ---- host encoder/decoder for the GSP-RM message queue (aienos#286 cut C host part 5) ---- 2455 # Byte-exact msgqTxHeader/msgqRxHeader, GSP_MSG_QUEUE_ELEMENT with checksum and sequence 2456 # rules, rpc_message_header_v03_00, continuation-record plan and PACKED_REGISTRY_TABLE, 2457 # all from the pinned driver. Self-test = compiler layouts, golden bytes, round trips, 2458 # every mutation refused. Never touches a device. docs/GB10_FIRMWARE_INVENTORY.md section 13. 2459 GSP_RPC_TOOL := $(OUT)/host/ck_gsp_rpc_encode 2460 $(GSP_RPC_TOOL): $(KDIR)/tools/ck_gsp_rpc_encode.c 2461 @mkdir -p $(dir $@) 2462 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $(KDIR)/tools/ck_gsp_rpc_encode.c 2463 gsp-rpc-encode: $(GSP_RPC_TOOL) 2464 gsp-rpc-test: $(GSP_RPC_TOOL) 2465 $(GSP_RPC_TOOL) selftest | grep -E '^CK_GSP_RPC_ENCODE_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_RPC_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2466 @$(GSP_RPC_TOOL) selftest | tail -1 2467 2468 # ---- GspSystemInfo encoder (L332 rung 2 window 1): the 936 bytes of GSP_SET_SYSTEM_INFO from a 2469 # "field value" text file. gsp-sysinfo-test = anchors, a known encoding, every refusal. 2470 # gsp-sysinfo-nvhdr-test = our field list against NVIDIA's own struct text, cut out of the pinned 2471 # tree (OGKM_DIR) at build time by line range; each cut is checked to start and end where expected. 2472 GSP_SI_TOOL := $(OUT)/host/ck_gsp_sysinfo_encode 2473 $(GSP_SI_TOOL): $(KDIR)/tools/ck_gsp_sysinfo_encode.c 2474 @mkdir -p $(dir $@) 2475 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 2476 gsp-sysinfo-test: $(GSP_SI_TOOL) 2477 $(GSP_SI_TOOL) selftest | grep -E '^CK_GSP_SYSINFO_ENCODE_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(GSP_SI_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2478 @$(GSP_SI_TOOL) selftest | tail -1 2479 GSP_SI_NV := $(OUT)/host/gsp_sysinfo_nvidia.h 2480 gsp-sysinfo-nvhdr-test: $(KDIR)/tools/ck_gsp_sysinfo_encode.c 2481 @test -d $(OGKM_SRC) || { echo "GSP_SYSINFO_NVHDR: FAIL (no open-gpu-kernel-modules 580.173.02 tree at OGKM_DIR=$(OGKM_DIR))"; exit 1; } 2482 @mkdir -p $(OUT)/host 2483 @cut() { sed -n "$$2,$$3p" "$(OGKM_SRC)/$$1" > $(GSP_SI_NV).part; \ 2484 head -1 $(GSP_SI_NV).part | grep -q "$$4" && tail -1 $(GSP_SI_NV).part | grep -q "$$5" || \ 2485 { echo "GSP_SYSINFO_NVHDR: FAIL ($$1:$$2-$$3 is not $$4 .. $$5)"; exit 1; }; cat $(GSP_SI_NV).part >> $(GSP_SI_NV); }; \ 2486 : > $(GSP_SI_NV); \ 2487 cut common/sdk/nvidia/inc/ctrl/ctrl0073/ctrl0073system.h 747 747 'NV0073_CTRL_SYSTEM_ACPI_ID_MAP_MAX_DISPLAYS' '(16U)' && \ 2488 cut nvidia/inc/kernel/gpu/gpu_acpi_data.h 72 115 'typedef struct DOD_METHOD_DATA' '} ACPI_METHOD_DATA;' && \ 2489 cut nvidia/generated/g_chipset_nvoc.h 220 227 'typedef struct' '} BUSINFO;' && \ 2490 cut nvidia/inc/kernel/gpu/gsp/gsp_static_config.h 45 62 'typedef struct GSP_VF_INFO' '} GSP_PCIE_CONFIG_REG;' && \ 2491 cut nvidia/inc/kernel/gpu/gsp/gsp_static_config.h 172 227 'typedef struct GspSystemInfo' '} GspSystemInfo;' 2492 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror $(OGKM_INC) -DCK_SYSINFO_NVHDR='"$(GSP_SI_NV)"' \ 2493 -o $(OUT)/host/ck_gsp_sysinfo_nvhdr $(KDIR)/tools/ck_gsp_sysinfo_encode.c 2494 $(OUT)/host/ck_gsp_sysinfo_nvhdr nvhdr 2495 2496 # ---- GB10 GSP boot builder, freestanding (L192, aienos#286 cut C host side) ---- 2497 # dev/gb10_gsp_boot.c composes every block above into one arena plus the SEC2 COT packet and the 2498 # post-init RPCs (GSP_RM_ALLOC / CONTROL / FREE, GET_GSP_STATIC_INFO). Bytes in memory only: no 2499 # MMIO, no firmware load. Not linked into any image yet. docs/GB10_FIRMWARE_INVENTORY.md section 14. 2500 # test_gb10_gsp_boot (in TESTS): layout, cross-links, ring, refusals, decoded at hand-written offsets 2501 # gb10-gsp-free: compiles with KCFLAGS, no undefined symbols, every frame <= 4 KiB of stack 2502 # gb10-gsp-nvhdr-test: mirrors vs the NVIDIA headers themselves (OGKM_DIR, MIT); FAILS if absent 2503 # gb10-gsp-nvhdr-check: same, NOT_RUN when OGKM_DIR is absent (used by make test) 2504 # gb10-gsp-mutants: each test-only mutant must make test_gb10_gsp_boot or the nvhdr test FAIL 2505 GSPB_SRCS := $(KDIR)/dev/gb10_gsp_boot.c 2506 GSPB_DEPS := $(KDIR)/tests/test_gb10_gsp_boot.c $(GSPB_SRCS) $(KDIR)/dev/gb10_gsp_boot.h $(KDIR)/tests/ck_test.h 2507 $(OUT)/host/test_gb10_gsp_boot: $(GSPB_DEPS) 2508 @mkdir -p $(dir $@) 2509 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -o $@ $< $(GSPB_SRCS) 2510 $(OUT)/host-san/test_gb10_gsp_boot: $(GSPB_DEPS) 2511 @mkdir -p $(dir $@) 2512 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -o $@ $< $(GSPB_SRCS) 2513 test-gb10-gsp-boot: $(OUT)/host/test_gb10_gsp_boot 2514 $< 2515 gb10-gsp-free: $(GSPB_SRCS) $(KDIR)/dev/gb10_gsp_boot.h 2516 @mkdir -p $(OUT)/free 2517 $(KCC) $(KCFLAGS) -Wstack-usage=4096 -c $(GSPB_SRCS) -o $(OUT)/free/gb10_gsp_boot.o 2518 @bad=$$($(CROSS)nm -u $(OUT)/free/gb10_gsp_boot.o | awk '{print $$2}' | grep -vxF -e _GLOBAL_OFFSET_TABLE_ || true); \ 2519 if [ -n "$$bad" ]; then echo "GB10_GSP_FREE: FAIL unexpected undefined symbols: $$bad"; exit 1; fi; \ 2520 echo "GB10_GSP_FREE: PASS (no undefined symbols, stack <= 4096 per function)" 2521 OGKM_DIR ?= $(HOME)/workspace/_ext/open-gpu-kernel-modules-580.173.02 2522 OGKM_SRC := $(OGKM_DIR)/src 2523 OGKM_INC := -I$(OGKM_SRC)/common/sdk/nvidia/inc -I$(OGKM_SRC)/nvidia/arch/nvalloc/common/inc \ 2524 -I$(OGKM_SRC)/common/uproc/os/common/include -I$(OGKM_SRC)/nvidia/inc/kernel -I$(OGKM_SRC)/nvidia/inc \ 2525 -I$(OGKM_SRC)/nvidia/generated -I$(OGKM_SRC)/common/shared/msgq/inc -I$(OGKM_SRC)/nvidia/interface \ 2526 -I$(OGKM_SRC)/common/inc 2527 GSPB_NV_DEPS := $(KDIR)/tests/test_gb10_gsp_nvhdr.c $(GSPB_SRCS) $(KDIR)/dev/gb10_gsp_boot.h $(KDIR)/tests/ck_test.h 2528 gb10-gsp-nvhdr-test: $(GSPB_NV_DEPS) 2529 @test -r $(OGKM_SRC)/nvidia/arch/nvalloc/common/inc/gsp/gsp_fw_wpr_meta.h || \ 2530 { echo "GB10_GSP_NVHDR: FAIL (no open-gpu-kernel-modules 580.173.02 tree at OGKM_DIR=$(OGKM_DIR))"; exit 1; } 2531 @mkdir -p $(OUT)/host-san 2532 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev $(OGKM_INC) -o $(OUT)/host-san/test_gb10_gsp_nvhdr $< $(GSPB_SRCS) 2533 $(OUT)/host-san/test_gb10_gsp_nvhdr 2534 gb10-gsp-nvhdr-check: 2535 @if [ -r $(OGKM_SRC)/nvidia/arch/nvalloc/common/inc/gsp/gsp_fw_wpr_meta.h ]; then $(MAKE) --no-print-directory gb10-gsp-nvhdr-test; \ 2536 else echo "GB10_GSP_NVHDR: NOT_RUN (no open-gpu-kernel-modules 580.173.02 tree at OGKM_DIR=$(OGKM_DIR))"; fi 2537 GSPB_MUTANTS := SWAPRX CKSUM RADIX ALLOCLEN 2538 gb10-gsp-mutants: $(GSPB_DEPS) $(GSPB_NV_DEPS) 2539 @mkdir -p $(OUT)/host 2540 @fail=0; for m in $(GSPB_MUTANTS); do \ 2541 $(HOSTCC) $(HCFLAGS) -DGSP_MUTANT_HOST -DGSP_MUTANT_$$m -I$(KDIR)/dev -o $(OUT)/host/test_gb10_gsp_boot_mut_$$m $(KDIR)/tests/test_gb10_gsp_boot.c $(GSPB_SRCS) || exit 1; \ 2542 if $(OUT)/host/test_gb10_gsp_boot_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 2543 done; test $$fail -eq 0 2544 .PHONY: test-gb10-gsp-boot gb10-gsp-free gb10-gsp-nvhdr-test gb10-gsp-nvhdr-check gb10-gsp-mutants 2545 2546 # ---- native image slots: host tool + freestanding check (native v1 plan P11 cut 1, gate N7) ---- 2547 # native/boot/slot_format.h + slot_select.c: the A/B slot manifest, control record and the 2548 # loader's selection rules (bounded candidate tries, generation floor, no boot loop, an 2549 # exhausted candidate never boots on its own authority). docs/NATIVE_IMAGE_SLOTS.md. 2550 # ck_slot_tool builds/signs/verifies manifests and simulates the decision; its self-test 2551 # is the format's oracle. slot-free proves slot_select.c compiles with the kernel's 2552 # freestanding flags and needs only the image's own digest/signature primitives. 2553 # No image code changes in this cut; the loader does not read slots yet. 2554 SLOT_TOOL := $(OUT)/host/ck_slot_tool 2555 SLOT_TOOL_SRCS := $(KDIR)/tools/ck_slot_tool.c $(BOOT)/slot_select.c $(BOOT)/slot_control.c $(BOOT)/slot_update.c $(NATIVE)/disk/disk.c $(NATIVE)/sig/sha512.c \ 2556 $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/ct.c $(NATIVE)/argus/sha256.c $(NATIVE)/store/torn_slot.c 2557 $(SLOT_TOOL): $(SLOT_TOOL_SRCS) $(BOOT)/slot_format.h $(BOOT)/slot_control.h $(BOOT)/slot_update.h 2558 @mkdir -p $(dir $@) 2559 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $(SLOT_TOOL_SRCS) 2560 slot-tool: $(SLOT_TOOL) 2561 # P11 cut 3: the service image's slot key table (see SVC_SLOT_KEY_SRC above). 2562 ifneq ($(SVC_SLOT_KEYS_C),) 2563 $(SVC_SLOT_KEYS_C): $(SLOT_TOOL) FORCE 2564 @mkdir -p $(dir $@) 2565 @$(SLOT_TOOL) keys-c $(SVC_SLOT_KEY_SRC) --out $@ 2566 endif 2567 slot-test: $(SLOT_TOOL) 2568 $(SLOT_TOOL) selftest | grep -E '^CK_SLOT_TOOL_SELFTEST: (PASS|FAIL)' | grep -q PASS || { $(SLOT_TOOL) selftest | grep -E 'FAIL|SELFTEST'; exit 1; } 2569 @$(SLOT_TOOL) selftest | tail -1 2570 SLOT_FREE_ALLOWED_U := aienos_sha512 aienos_`ed25519`_verify sha256_hash _GLOBAL_OFFSET_TABLE_ 2571 slot-free: $(BOOT)/slot_select.c $(BOOT)/slot_format.h 2572 @mkdir -p $(OUT)/free 2573 $(KCC) $(KCFLAGS) -c $(BOOT)/slot_select.c -o $(OUT)/free/slot_select.o 2574 @bad=$$($(CROSS)nm -u $(OUT)/free/slot_select.o | awk '{print $$2}' | grep -vxF $(foreach a,$(SLOT_FREE_ALLOWED_U),-e $(a)) || true); \ 2575 if [ -n "$$bad" ]; then echo "slot-free: FAIL unexpected undefined symbols: $$bad"; exit 1; fi; \ 2576 echo "SLOT_FREE: PASS (undefined: $(SLOT_FREE_ALLOWED_U))" 2577 2578 # ---- reproducible native package (scripts/native_package.sh, P11 cut 1b) ---- 2579 # Builds the image twice from a clean tree, refuses if they differ, records 2580 # PACKAGE.txt + SHA256SUMS, binds them into the slot manifest's provenance and 2581 # verifies the owner signature. package-test = scripts/native_package_test.sh 2582 # (TEST signer and TEST-FIXTURE owner files only; ~35 s; nothing booted). 2583 package-test: $(SLOT_TOOL) 2584 NATIVE_PACKAGE_TOOL_OUT=$(OUT) bash $(REPO)/scripts/native_package_test.sh | grep -E '^NATIVE_PACKAGE_TEST: (PASS|FAIL)' | grep -q PASS || { NATIVE_PACKAGE_TOOL_OUT=$(OUT) bash $(REPO)/scripts/native_package_test.sh | grep -E '^FAIL|NATIVE_PACKAGE_TEST'; exit 1; } 2585 @echo "NATIVE_PACKAGE_TEST: PASS" 2586 2587 # ---- SLOTLDR.EFI: the signed A/B slot loader (native v1 plan P11 cut 2a, gate N7) ---- 2588 # native/boot/slot_loader.c: a separate UEFI application in FRONT of the unchanged 2589 # stub + kernel image (BOOTAA64.EFI is not touched). It reads the slots partition, 2590 # verifies both slots against the keys baked in here, applies slot_select.c, commits 2591 # the control record before a candidate try, then LoadImage + StartImage of the 2592 # verified bytes. Own object list: no kernel objects (checked), no runtime services, 2593 # no UEFI variables, no ExitBootServices (checked in the source). Keys: CK_SLOT_KEYS 2594 # or CK_TEST_SLOT_KEY=1 (see the top of this file). docs/NATIVE_IMAGE_SLOTS.md. 2595 # make slot-loader CK_TEST_SLOT_KEY=1 -> $(OUT)/SLOTLDR.EFI (TEST-ONLY key) 2596 # make slot-loader CK_SLOT_KEYS= -> $(OUT)/SLOTLDR.EFI (owner keys) 2597 # make slot-loader-check build checks + refusals (in make test) 2598 # QEMU gate: scripts/qemu_ck_slot_loader_test.sh (AIENOS_CK_SLOT_LOADER). 2599 SLOTLDR_DIR := $(OUT)/slotldr 2600 SLOTLDR_ELF := $(SLOTLDR_DIR)/slotldr.elf 2601 SLOTLDR_EFI := $(OUT)/SLOTLDR.EFI 2602 SLOTLDR_KEYS_C := $(SLOTLDR_DIR)/slot_keys.c 2603 SLOTLDR_C := $(BOOT)/slot_loader.c $(BOOT)/slot_select.c $(BOOT)/slot_control.c $(NATIVE)/sig/sha512.c $(NATIVE)/sig/`ed25519`.c \ 2604 $(NATIVE)/sig/ct.c $(NATIVE)/argus/sha256.c $(NATIVE)/store/torn_slot.c $(KDIR)/core/libc_min.c \ 2605 $(KDIR)/core/fmt.c 2606 SLOTLDR_OBJS := $(patsubst $(NATIVE)/%.c,$(SLOTLDR_DIR)/obj/%.o,$(SLOTLDR_C)) \ 2607 $(SLOTLDR_DIR)/obj/boot/efi_entry.o $(SLOTLDR_DIR)/obj/slot_keys.o 2608 SLOTLDR_CFLAGS := $(KCFLAGS) $(ART_INC) -I$(NATIVE)/store 2609 SLOTLDR_HDRS := $(BOOT)/slot_format.h $(BOOT)/slot_control.h $(BOOT)/efi.h $(NATIVE)/store/torn_slot.h $(KDIR)/core/fmt.h $(ART_HDRS) 2610 SLOTLDR_KEY_SRC := $(if $(strip $(CK_TEST_SLOT_KEY)),--test-key,$(if $(strip $(CK_SLOT_KEYS)),--keys $(abspath $(CK_SLOT_KEYS)),)) 2611 $(SLOTLDR_DIR)/obj/%.o: $(NATIVE)/%.c $(SLOTLDR_HDRS) 2612 @mkdir -p $(dir $@) 2613 $(KCC) $(SLOTLDR_CFLAGS) -c -o $@ $< 2614 $(SLOTLDR_DIR)/obj/boot/slot_loader.o: $(BOOT)/slot_loader.c $(SLOTLDR_HDRS) $(OUT)/commit.stamp 2615 @mkdir -p $(dir $@) 2616 $(KCC) $(SLOTLDR_CFLAGS) -DAIENOS_COMMIT='"$(AIENOS_COMMIT)"' -c -o $@ $< 2617 $(SLOTLDR_DIR)/obj/boot/efi_entry.o: $(BOOT)/efi_entry.S 2618 @mkdir -p $(dir $@) 2619 $(KCC) $(KCFLAGS) -c -o $@ $< 2620 # Rewritten only when the key table changes (ck_slot_tool keys-c compares). 2621 $(SLOTLDR_KEYS_C): $(SLOT_TOOL) FORCE 2622 @[ -n "$(SLOTLDR_KEY_SRC)" ] || { echo "slot-loader: give CK_SLOT_KEYS= or CK_TEST_SLOT_KEY=1 (TEST only)"; exit 1; } 2623 @mkdir -p $(dir $@) 2624 @$(SLOT_TOOL) keys-c $(SLOTLDR_KEY_SRC) --out $@ 2625 $(SLOTLDR_DIR)/obj/slot_keys.o: $(SLOTLDR_KEYS_C) 2626 @mkdir -p $(dir $@) 2627 $(KCC) $(SLOTLDR_CFLAGS) -c -o $@ $< 2628 $(SLOTLDR_ELF): $(SLOTLDR_OBJS) $(BOOT)/image.ld 2629 @if grep -nE -- '->(RuntimeServices|ExitBootServices|SetVariable|GetVariable|SetWatchdogTimer)' $(BOOT)/slot_loader.c; then \ 2630 echo "slot_loader.c calls a service the slot loader must never call"; exit 1; fi 2631 $(call link_image,$@,$(SLOTLDR_OBJS)) 2632 @k=$$($(KNM) $@ | grep -E ' [TtDdBbRr] (ck_kernel_entry|kmain|ck_boot_model_load|ck_printf)$$' || true); \ 2633 if [ -n "$$k" ]; then echo "SLOTLDR links kernel objects: $$k"; rm -f $@; exit 1; fi 2634 @if [ "$(strip $(CK_TEST_SLOT_KEY))" = 1 ]; then \ 2635 grep -aqF "TEST-ONLY key" $@ || { echo "TEST-key SLOTLDR lacks its TEST-ONLY announcement"; rm -f $@; exit 1; }; \ 2636 elif grep -aqF "TEST-ONLY" $@; then echo "owner-key SLOTLDR carries a TEST-ONLY note"; rm -f $@; exit 1; fi 2637 $(SLOTLDR_EFI): $(SLOTLDR_ELF) 2638 $(call pe_image,$<,$@) 2639 slot-loader: $(SLOTLDR_EFI) 2640 SLOTLDR_FIXTURE_KEYS := $(KDIR)/tests/fixtures/owner/TEST-FIXTURE-owner-pubkeys.txt 2641 slot-loader-check: 2642 @$(MAKE) -s --no-print-directory OUT=$(OUT)/slotldr-check-test CK_TEST_SLOT_KEY=1 slot-loader >/dev/null 2643 @grep -aqF "TEST-ONLY key" $(OUT)/slotldr-check-test/SLOTLDR.EFI 2644 @$(MAKE) -s --no-print-directory OUT=$(OUT)/slotldr-check-owner CK_SLOT_KEYS=$(SLOTLDR_FIXTURE_KEYS) slot-loader >/dev/null 2645 @if grep -aqF "TEST-ONLY" $(OUT)/slotldr-check-owner/SLOTLDR.EFI; then echo "SLOT_LOADER_BUILD: FAIL owner-key loader carries TEST-ONLY"; exit 1; fi 2646 @for c in "CK_HARDWARE_STAGING=1 CK_TEST_SLOT_KEY=1|cannot be combined with CK_HARDWARE_STAGING" \ 2647 "CK_TEST_SLOT_KEY=1 CK_SLOT_KEYS=$(SLOTLDR_FIXTURE_KEYS)|are exclusive" \ 2648 "CK_SLOT_KEYS=$(SLOTLDR_FIXTURE_KEYS:.txt=.missing)|cannot read the keys file" \ 2649 "|give CK_SLOT_KEYS"; do \ 2650 args=$${c%%|*}; want=$${c#*|}; \ 2651 if $(MAKE) -s --no-print-directory OUT=$(OUT)/slotldr-check-refuse $$args slot-loader >$(OUT)/slotldr-refuse.log 2>&1; then \ 2652 echo "SLOT_LOADER_BUILD: FAIL not refused: $$args"; exit 1; fi; \ 2653 grep -qF -- "$$want" $(OUT)/slotldr-refuse.log || { echo "SLOT_LOADER_BUILD: FAIL refused without '$$want': $$args"; cat $(OUT)/slotldr-refuse.log; exit 1; }; \ 2654 echo "slot-loader refused as required: $${args:-no key source} ($$want)"; \ 2655 done 2656 @echo "SLOT_LOADER_BUILD: PASS (TEST-key and owner-key loaders built; TEST key refused with hardware staging)" 2657 2658 # ---- PI5DIAG.EFI: AIENOS-PI5-BOOT-0, the Raspberry Pi 5 firmware diagnostic ---- 2659 # native/boot/diag_main.c: a UEFI application that reports what the firmware shows 2660 # (ConOut + \EFI\AIENOS\PI5BOOT0.TXT) and returns. Own object list, no kernel, no 2661 # ExitBootServices (checked). Copy to the card as EFI/BOOT/BOOTAA64.EFI. 2662 # make pi5-diag -> $(OUT)/PI5DIAG.EFI QEMU test: scripts/qemu_ck_pi5_diag_test.sh 2663 PI5DIAG_DIR := $(OUT)/pi5diag 2664 PI5DIAG_ELF := $(PI5DIAG_DIR)/pi5diag.elf 2665 PI5DIAG_EFI := $(OUT)/PI5DIAG.EFI 2666 PI5DIAG_OBJS := $(PI5DIAG_DIR)/diag_main.o $(PI5DIAG_DIR)/efi_entry.o $(PI5DIAG_DIR)/fmt.o $(PI5DIAG_DIR)/libc_min.o 2667 $(PI5DIAG_DIR)/diag_main.o: $(BOOT)/diag_main.c $(BOOT)/diag.h $(BOOT)/efi.h $(KDIR)/core/fmt.h 2668 @mkdir -p $(dir $@) 2669 $(KCC) $(KCFLAGS) -c -o $@ $< 2670 $(PI5DIAG_DIR)/efi_entry.o: $(BOOT)/efi_entry.S 2671 @mkdir -p $(dir $@) 2672 $(KCC) $(KCFLAGS) -c -o $@ $< 2673 $(PI5DIAG_DIR)/fmt.o: $(KDIR)/core/fmt.c $(KDIR)/core/fmt.h 2674 @mkdir -p $(dir $@) 2675 $(KCC) $(KCFLAGS) -c -o $@ $< 2676 $(PI5DIAG_DIR)/libc_min.o: $(KDIR)/core/libc_min.c 2677 @mkdir -p $(dir $@) 2678 $(KCC) $(KCFLAGS) -c -o $@ $< 2679 $(PI5DIAG_ELF): $(PI5DIAG_OBJS) $(BOOT)/image.ld 2680 @if grep -nE -- '->ExitBootServices' $(BOOT)/diag_main.c || grep -nE -- 'rt->' $(BOOT)/diag_main.c | grep -vE -- 'rt->ResetSystem'; then \ 2681 echo "diag_main.c calls a service the diagnostic must never call (only ResetSystem is allowed)"; exit 1; fi 2682 $(call link_image,$@,$(PI5DIAG_OBJS)) 2683 @k=$$($(KNM) $@ | grep -E ' [TtDdBbRr] (ck_kernel_entry|kmain|ck_boot_model_load|ck_printf)$$' || true); \ 2684 if [ -n "$$k" ]; then echo "PI5DIAG links kernel objects: $$k"; rm -f $@; exit 1; fi 2685 $(PI5DIAG_EFI): $(PI5DIAG_ELF) 2686 $(call pe_image,$<,$@) 2687 pi5-diag: $(PI5DIAG_EFI) 2688 2689 # ---- IMACDIAG.EFI: AIENOS-IMAC-BOOT-0, the same diagnostic for x86_64 (2017 iMac) ---- 2690 # diag_main.c + diag_x86.c (CPUID, SMBIOS identity, PCI, GOP, disks), report in 2691 # \EFI\AIENOS\IMACBOOT.TXT, then power off. The only x86_64 image in this tree: its own 2692 # cross toolchain and flags (-mabi=ms: every function uses the UEFI x64 convention), 2693 # its own entry (efi_entry_x86_64.S) and PE header (image_x86_64.ld, Machine 0x8664). 2694 # Copy to a FAT stick as EFI/BOOT/BOOTX64.EFI. 2695 # make imac-diag -> $(OUT)/IMACDIAG.EFI QEMU test: scripts/qemu_ck_imac_diag_test.sh 2696 ifeq ($(HOST_ARCH),x86_64) 2697 X86_CROSS ?= 2698 else 2699 X86_CROSS ?= x86_64-linux-gnu- 2700 endif 2701 X86CC := $(X86_CROSS)gcc 2702 X86LD := $(X86_CROSS)ld 2703 X86OBJCOPY := $(X86_CROSS)objcopy 2704 X86NM := $(X86_CROSS)nm 2705 X86READELF := $(X86_CROSS)readelf 2706 X86CFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin \ 2707 -fno-stack-protector -fno-tree-loop-distribute-patterns -mgeneral-regs-only -mno-red-zone \ 2708 -mabi=ms -fcf-protection=none -fno-asynchronous-unwind-tables -fpie -fvisibility=hidden -fno-plt \ 2709 -I$(KDIR)/core -I$(BOOT) 2710 X86LDFLAGS := -nostdlib -pie --no-dynamic-linker -z norelro -z noexecstack -z max-page-size=4096 \ 2711 --no-warn-rwx-segments -T $(BOOT)/image_x86_64.ld 2712 IMACDIAG_DIR := $(OUT)/imacdiag 2713 IMACDIAG_ELF := $(IMACDIAG_DIR)/imacdiag.elf 2714 IMACDIAG_EFI := $(OUT)/IMACDIAG.EFI 2715 IMACDIAG_OBJS := $(IMACDIAG_DIR)/diag_main.o $(IMACDIAG_DIR)/diag_x86.o $(IMACDIAG_DIR)/efi_entry_x86_64.o \ 2716 $(IMACDIAG_DIR)/fmt.o $(IMACDIAG_DIR)/libc_min.o 2717 $(IMACDIAG_DIR)/diag_main.o: $(BOOT)/diag_main.c $(BOOT)/diag.h $(BOOT)/efi.h $(KDIR)/core/fmt.h 2718 $(IMACDIAG_DIR)/diag_x86.o: $(BOOT)/diag_x86.c $(BOOT)/diag.h $(BOOT)/efi.h 2719 $(IMACDIAG_DIR)/efi_entry_x86_64.o: $(BOOT)/efi_entry_x86_64.S 2720 $(IMACDIAG_DIR)/fmt.o: $(KDIR)/core/fmt.c $(KDIR)/core/fmt.h 2721 $(IMACDIAG_DIR)/libc_min.o: $(KDIR)/core/libc_min.c 2722 $(IMACDIAG_OBJS): 2723 @mkdir -p $(dir $@) 2724 $(X86CC) $(X86CFLAGS) -c -o $@ $< 2725 $(IMACDIAG_ELF): $(IMACDIAG_OBJS) $(BOOT)/image_x86_64.ld 2726 @if grep -nE -- '->ExitBootServices' $(BOOT)/diag_main.c $(BOOT)/diag_x86.c || grep -nE -- 'rt->' $(BOOT)/diag_main.c $(BOOT)/diag_x86.c | grep -vE -- 'rt->ResetSystem'; then \ 2727 echo "the diagnostic calls a service it must never call (only ResetSystem is allowed)"; exit 1; fi 2728 @mkdir -p $(dir $@) 2729 $(X86LD) $(X86LDFLAGS) -o $@ $(IMACDIAG_OBJS) 2730 @u=$$($(X86NM) -u $@ | grep -v ' w ' || true); \ 2731 if [ -n "$$u" ]; then echo "image has undefined symbols: $$u"; rm -f $@; exit 1; fi 2732 @bad=$$($(X86READELF) -rW $@ | grep -E '^[0-9a-f]+ ' | grep -v R_X86_64_RELATIVE || true); \ 2733 if [ -n "$$bad" ]; then echo "image has non-RELATIVE relocations:"; echo "$$bad"; rm -f $@; exit 1; fi 2734 @k=$$($(X86NM) $@ | grep -E ' [TtDdBbRr] (ck_kernel_entry|kmain|ck_boot_model_load|ck_printf)$$' || true); \ 2735 if [ -n "$$k" ]; then echo "IMACDIAG links kernel objects: $$k"; rm -f $@; exit 1; fi 2736 $(IMACDIAG_EFI): $(IMACDIAG_ELF) 2737 $(X86OBJCOPY) -O binary $< $@ 2738 @sz=$$(stat -c %s $@); pad=$$(( (4096 - sz % 4096) % 4096 )); \ 2739 if [ $$pad -gt 0 ]; then head -c $$pad /dev/zero >> $@; fi 2740 @[ "$$(head -c 2 $@)" = "MZ" ] || { echo "not a PE image"; rm -f $@; exit 1; } 2741 @[ "$$(od -An -tx1 -j68 -N2 $@ | tr -d ' ')" = "6486" ] || { echo "PE Machine is not x86_64 (0x8664)"; rm -f $@; exit 1; } 2742 @echo "built $@ (commit $(AIENOS_COMMIT))" 2743 imac-diag: $(IMACDIAG_EFI) 2744 2745 # ---- IMACKERN.EFI: AIENOS-KERNEL-0, the C kernel core on x86_64 (2017 iMac) ---- 2746 # x86/efi_x86.c (stub: GOP, RSDP, memory map, ExitBootServices, CHANDOF3) + x86/kmain_x86.c 2747 # (GDT/TSS/IDT, own page tables, guard page, HPET-timed TSC, local APIC timer, ACPI S5) 2748 # + x86/pci_x86.c (PCI walk; AHCI via x86/ahci_x86.c and NVMe via ../disk/disk_nvme.c, both 2749 # read-only, GPT checked by dev/disk_part.c; a look at the Ethernet chip) + x86/smp_x86.S 2750 # (secondary cores started and parked) + x86/xhci_x86.c (USB boot keyboard, polled, hubs; key 2751 # decode and line editor from dev/usb_hid.c) + x86/tg3_x86.c (BCM57766 Ethernet: link detection; no 2752 # transmit in the default image) + ui/allen_ui.c, ui/allen_font.c (Allen's window on the screen, drawn 2753 # with its own stroke typeface; ui/night.c, the night sky of the startup, and ui/mind.c, Allen's presence, on ui/paint.c; 2754 # drawn by the secondary cores) + svc/allen_reply.c (Allen's first local answers) 2755 # + x86/trap.S + x86/console_x86.c (COM1 when present, GOP framebuffer), on the 2756 # arch-neutral core: fbcon, fmt, acpi, handoff_check, frames, heap. Same toolchain and PE 2757 # header as IMACDIAG. Copy to a FAT stick as EFI/BOOT/BOOTX64.EFI. 2758 # make imac-kernel -> $(OUT)/IMACKERN.EFI QEMU test: scripts/qemu_ck_imac_kernel_test.sh 2759 # The network report is a LAB-ONLY diagnostic, opt-in and default off: 2760 # make imac-kernel CK_X86_REPORT=1 -> $(OUT)/IMACKERN-LAB.EFI (own object dir) 2761 # adds x86/report_x86.c + ../../net/aienos_net.c and tg3 transmit (-DCK_X86_REPORT=1): during the 2762 # hold it broadcasts only allowlisted console lines (IMACKERN_REPORT_SYMS := ck_x86_report_hold|ck_x86_report_frame|ck_x86_report_filter|ck_x86_report_parts|ck_x86_tg3_send|ck_x86_tg3_drain|ck_x86_tg3_recv|ck_courier_udp_init|net_udp_build, never the raw console) 2763 # as UDP to port 47031, header "AIENOS-REPORT v=2 auth=none": UNAUTHENTICATED, never a 2764 # receipt, evidence or a command. Host test scripts/ck_imac_report_test.sh, receiver 2765 # tools/ck_imac_report_listen.c. The default image, and any resident or service (ALLEN) build, 2766 # must not contain it: the link step below fails a default image that has a report symbol. 2767 CK_X86_REPORT ?= 0 2768 # QEMU test switches (lab builds only; refused otherwise, see below): CK_X86_SWAP_TEST_DISK=1 stages 2769 # a swap image from a raw disk (scripts/qemu_ck_imac_swap_test.sh); CK_X86_BENCH_TEST=1 replaces the 2770 # GPU BARs with RAM stand-ins and moves the bench packets to COM1 (scripts/qemu_ck_gpu_bench_test.sh); 2771 # CK_X86_SWAP_TRAMP_PAD=1 pads the swap trampoline past its page, so the swap must refuse it before 2772 # it stops anything (scripts/qemu_ck_imac_swap_test.sh run 3). 2773 CK_X86_SWAP_TEST_DISK ?= 0 2774 CK_X86_BENCH_TEST ?= 0 2775 CK_X86_SWAP_TRAMP_PAD ?= 0 2776 IMACKERN_TRAMP_FLAGS := 2777 X86K := $(KDIR)/x86 2778 # CK_X86_HOSTDESC=1 builds the launcher image (IMACKERN-HOST.EFI): the setup wizard also reads the host 2779 # description a launcher (aienos-run) hands over as the QEMU fw_cfg file opt/aienos/host 2780 # (x86/fwcfg_x86.c, read-only). The default and lab images carry no fw_cfg code or string; 2781 # the link step below checks it, like fwcfg_check for the core images. 2782 CK_X86_HOSTDESC ?= 0 2783 ifeq ($(CK_X86_REPORT),1) 2784 IMACKERN_DIR := $(OUT)/imackern-lab 2785 IMACKERN_EFI := $(OUT)/IMACKERN-LAB.EFI 2786 else ifeq ($(CK_X86_REPORT),0) 2787 IMACKERN_DIR := $(OUT)/imackern 2788 IMACKERN_EFI := $(OUT)/IMACKERN.EFI 2789 else 2790 $(error CK_X86_REPORT must be 0 (default) or 1 (lab-only network report)) 2791 endif 2792 ifeq ($(CK_X86_HOSTDESC),1) 2793 IMACKERN_DIR := $(IMACKERN_DIR)-host 2794 IMACKERN_EFI := $(IMACKERN_EFI:.EFI=-HOST.EFI) 2795 else ifneq ($(CK_X86_HOSTDESC),0) 2796 $(error CK_X86_HOSTDESC must be 0 (default) or 1 (launcher image that reads the host description)) 2797 endif 2798 CK_LOCAL_TEST ?= 0 2799 ifeq ($(CK_LOCAL_TEST),1) 2800 IMACKERN_DIR := $(IMACKERN_DIR)-local-test 2801 IMACKERN_EFI := $(IMACKERN_EFI:.EFI=-LOCAL-TEST.EFI) 2802 else ifneq ($(CK_LOCAL_TEST),0) 2803 $(error CK_LOCAL_TEST must be 0 (release) or 1 (hostile QEMU fixtures)) 2804 endif 2805 CK_LOCAL_MODEL ?= 0 2806 ifeq ($(CK_LOCAL_MODEL),1) 2807 IMACKERN_DIR := $(IMACKERN_DIR)-model 2808 IMACKERN_EFI := $(IMACKERN_EFI:.EFI=-MODEL.EFI) 2809 else ifneq ($(CK_LOCAL_MODEL),0) 2810 $(error CK_LOCAL_MODEL must be 0 or 1) 2811 endif 2812 IMACKERN_ELF := $(IMACKERN_DIR)/imackern.elf 2813 IMACKERN_CFLAGS := $(X86CFLAGS) -I$(KDIR)/include -I$(KDIR)/mm -I$(KDIR)/dev -I$(NATIVE)/disk -I$(NATIVE)/net \ 2814 -I$(NATIVE)/argus -I$(NATIVE)/sig 2815 IMACKERN_OBJS := $(IMACKERN_DIR)/efi_entry_x86_64.o $(IMACKERN_DIR)/efi_x86.o $(IMACKERN_DIR)/efi_gop.o \ 2816 $(IMACKERN_DIR)/kmain_x86.o $(IMACKERN_DIR)/console_x86.o $(IMACKERN_DIR)/trap.o \ 2817 $(IMACKERN_DIR)/local_tools.o $(IMACKERN_DIR)/local_wire.o $(IMACKERN_DIR)/local_enter.o $(IMACKERN_DIR)/local_format.o $(IMACKERN_DIR)/`ed25519`.o \ 2818 $(IMACKERN_DIR)/fbcon.o $(IMACKERN_DIR)/fmt.o $(IMACKERN_DIR)/acpi.o $(IMACKERN_DIR)/dmar.o $(IMACKERN_DIR)/dmar_x86.o $(IMACKERN_DIR)/handoff_check.o \ 2819 $(IMACKERN_DIR)/frames.o $(IMACKERN_DIR)/heap.o $(IMACKERN_DIR)/libc_min.o \ 2820 $(IMACKERN_DIR)/ahci_x86.o $(IMACKERN_DIR)/disk_part.o $(IMACKERN_DIR)/disk.o \ 2821 $(IMACKERN_DIR)/pci_x86.o $(IMACKERN_DIR)/smp_x86.o $(IMACKERN_DIR)/disk_nvme.o \ 2822 $(IMACKERN_DIR)/tg3_x86.o $(IMACKERN_DIR)/xhci_x86.o $(IMACKERN_DIR)/hda_x86.o $(IMACKERN_DIR)/usb_hid.o $(IMACKERN_DIR)/sha256.o \ 2823 $(IMACKERN_DIR)/allen_ui.o $(IMACKERN_DIR)/allen_font.o $(IMACKERN_DIR)/allen_reply.o $(IMACKERN_DIR)/allen_intent.o $(IMACKERN_DIR)/allen_code.o $(IMACKERN_DIR)/courier_x86.o \ 2824 $(IMACKERN_DIR)/paint.o $(IMACKERN_DIR)/night.o $(IMACKERN_DIR)/sky_real.o $(IMACKERN_DIR)/sky_data.o $(IMACKERN_DIR)/mind.o $(IMACKERN_DIR)/flow.o $(IMACKERN_DIR)/chirp.o \ 2825 $(IMACKERN_DIR)/allen_memory.o $(IMACKERN_DIR)/allen_notes.o $(IMACKERN_DIR)/gpt_add.o $(IMACKERN_DIR)/memory_x86.o \ 2826 $(IMACKERN_DIR)/fat_boot.o $(IMACKERN_DIR)/sha512.o $(IMACKERN_DIR)/ct.o $(IMACKERN_DIR)/panel_x86.o \ 2827 $(IMACKERN_DIR)/gpu_x86.o $(IMACKERN_DIR)/swap_x86.o $(IMACKERN_DIR)/bench_x86.o \ 2828 $(IMACKERN_DIR)/setup_inv.o $(IMACKERN_DIR)/setup_wizard.o $(IMACKERN_DIR)/setup_store.o $(IMACKERN_DIR)/setup_x86.o 2829 # Every image verifies owner signatures before installing a boot image. 2830 # No configured keys means an empty trust store and no boot-image installation. 2831 IMACKERN_SLOT_KEYS_C := $(IMACKERN_DIR)/imac_slot_keys.c 2832 IMACKERN_KEY_SRC := $(if $(strip $(CK_TEST_SLOT_KEY)),--test-key,$(if $(strip $(CK_SLOT_KEYS)),--keys $(abspath $(CK_SLOT_KEYS)),)) 2833 IMACKERN_OBJS += $(IMACKERN_DIR)/slot_select.o $(IMACKERN_DIR)/imac_slot_keys.o 2834 # Lab-only objects: the report, Ethernet courier and swap trampoline. 2835 IMACKERN_REPORT_OBJS := $(IMACKERN_DIR)/report_x86.o $(IMACKERN_DIR)/aienos_net.o $(IMACKERN_DIR)/courier_udp_x86.o \ 2836 $(IMACKERN_DIR)/swap_tramp.o 2837 # The far side of Allen's Ethernet courier (x86/courier_udp.h): broadcast by default, a lab address overrides. 2838 CK_COURIER_PEER ?= 255.255.255.255 2839 # Symbols only the lab image may contain; the default image is checked for them after linking. 2840 IMACKERN_REPORT_SYMS := ck_x86_report_hold|ck_x86_report_frame|ck_x86_report_filter|ck_x86_report_parts|ck_x86_tg3_send|ck_x86_tg3_drain|ck_x86_tg3_recv|ck_courier_udp_init|net_udp_build 2841 ifeq ($(CK_X86_REPORT),1) 2842 IMACKERN_OBJS += $(IMACKERN_REPORT_OBJS) 2843 IMACKERN_CFLAGS += -DCK_X86_REPORT=1 -DCK_COURIER_PEER_STR=\"$(CK_COURIER_PEER)\" -DCK_X86_SWAP=1 -DCK_X86_BENCH=1 -I$(NATIVE)/sig -I$(BOOT) 2844 ifeq ($(CK_X86_SWAP_TEST_DISK),1) 2845 IMACKERN_CFLAGS += -DCK_X86_SWAP_TEST_DISK=1 2846 endif 2847 ifeq ($(CK_X86_BENCH_TEST),1) 2848 IMACKERN_CFLAGS += -DCK_X86_BENCH_TEST=1 2849 endif 2850 ifeq ($(CK_X86_SWAP_TRAMP_PAD),1) 2851 IMACKERN_TRAMP_FLAGS += -DCK_X86_SWAP_TRAMP_PAD=1 2852 endif 2853 # Lab swap requires configured owner keys (the default image may have none). 2854 # CK_TEST_SLOT_KEY=1 embeds RFC 8032 TEST keys, for QEMU only. 2855 ifeq ($(strip $(IMACKERN_KEY_SRC)),) 2856 $(error the lab kernel (CK_X86_REPORT=1) needs swap owner keys: give CK_SLOT_KEYS=, or CK_TEST_SLOT_KEY=1 (TEST key, QEMU tests only)) 2857 endif 2858 endif 2859 ifneq ($(CK_X86_REPORT),1) 2860 ifneq ($(filter 1,$(CK_X86_SWAP_TEST_DISK) $(CK_X86_BENCH_TEST) $(CK_X86_SWAP_TRAMP_PAD)),) 2861 $(error CK_X86_SWAP_TEST_DISK, CK_X86_BENCH_TEST and CK_X86_SWAP_TRAMP_PAD are QEMU lab test switches: they need CK_X86_REPORT=1) 2862 endif 2863 endif 2864 ifeq ($(CK_X86_HOSTDESC),1) 2865 IMACKERN_OBJS += $(IMACKERN_DIR)/fwcfg_x86.o 2866 IMACKERN_CFLAGS += -DCK_X86_HOSTDESC=1 2867 endif 2868 IMACKERN_HDRS := $(X86K)/x86.h $(BOOT)/handoff.h $(BOOT)/efi.h $(KDIR)/core/ck_internal.h $(KDIR)/include/ck.h 2869 GPU_DIR := $(KDIR)/gpu 2870 # CK_X86_GPU: drive the AMD GPU (DCE 11.2 page flip, GMC, SMU, gfx/SDMA/compute rings). 2871 # Default 0 (stubs) until each bring-up step has run on the real iMac through 2872 # the bench (feat/imac-gpu-bench): a wrong GPU register write can wedge the 2873 # PCIe link, and only a 4 s power hold (a firmware boot) recovers it. Lab 2874 # builds opt in with CK_X86_GPU=1. The chip is not present in QEMU (says so once). CK_X86_GPU_UCODE=1 additionally embeds the polaris11 2875 # firmware blobs fetched by scripts/fetch_gpu_ucode.sh (never committed). 2876 CK_X86_GPU ?= 0 2877 ifeq ($(CK_X86_GPU),1) 2878 IMACKERN_CFLAGS += -DCK_X86_GPU=1 2879 # The driver itself is linked only when it is on; with it off, gpu_x86.c 2880 # supplies the stubs (linking both defined every ck_gpu_* entry twice). 2881 IMACKERN_OBJS += $(IMACKERN_DIR)/amd_display.o $(IMACKERN_DIR)/amd_mc.o $(IMACKERN_DIR)/amd_smu.o \ 2882 $(IMACKERN_DIR)/amd_ucode.o $(IMACKERN_DIR)/amd_sdma.o $(IMACKERN_DIR)/amd_compute.o 2883 CK_X86_GPU_UCODE ?= 0 2884 ifeq ($(CK_X86_GPU_UCODE),1) 2885 ifeq ($(wildcard $(REPO)/target/native-kernel/gpu_ucode.inc),) 2886 $(error CK_X86_GPU_UCODE=1 needs $(REPO)/target/native-kernel/gpu_ucode.inc: run sh scripts/fetch_gpu_ucode.sh first) 2887 endif 2888 IMACKERN_CFLAGS += -DCK_X86_GPU_UCODE=1 -I$(REPO)/target/native-kernel 2889 endif 2890 else ifeq ($(CK_X86_GPU),0) 2891 IMACKERN_CFLAGS += -DCK_X86_GPU=0 2892 else 2893 $(error CK_X86_GPU must be 1 (GPU driver, lab) or 0 (default: stubs)) 2894 endif 2895 $(IMACKERN_DIR)/efi_entry_x86_64.o: $(BOOT)/efi_entry_x86_64.S 2896 $(IMACKERN_DIR)/efi_x86.o: $(X86K)/efi_x86.c $(IMACKERN_HDRS) $(BOOT)/netboot_proto.h 2897 $(IMACKERN_DIR)/efi_gop.o: $(BOOT)/efi_gop.c $(IMACKERN_HDRS) 2898 $(IMACKERN_DIR)/kmain_x86.o: $(X86K)/kmain_x86.c $(IMACKERN_HDRS) $(KDIR)/core/handoff_check.h $(KDIR)/core/spinlock.h $(KDIR)/mm/frames.h $(KDIR)/mm/heap.h $(KDIR)/ui/allen_ui.h $(KDIR)/svc/allen_reply.h $(KDIR)/svc/allen_intent.h $(KDIR)/svc/allen_code.h $(KDIR)/dev/usb_hid.h $(KDIR)/svc/courier.h $(X86K)/courier_udp.h $(KDIR)/svc/setup_wizard.h $(OUT)/commit.stamp 2899 $(IMACKERN_DIR)/console_x86.o: $(X86K)/console_x86.c $(IMACKERN_HDRS) $(KDIR)/core/fbcon.h 2900 $(IMACKERN_DIR)/trap.o: $(X86K)/trap.S 2901 ifeq ($(CK_LOCAL_MODEL),1) 2902 IMACKERN_CFLAGS += -DCK_LOCAL_MODEL=1 2903 IMACKERN_OBJS += $(IMACKERN_DIR)/model_assets.o 2904 $(IMACKERN_DIR)/model_assets.o: $(X86K)/model/assets.S $(CK_LOCAL_MODEL_FILE) $(CK_LOCAL_TOKENIZER_FILE) 2905 @mkdir -p $(@D) 2906 $(X86CC) $(IMACKERN_CFLAGS) -DCK_MODEL_FILE='"$(CK_LOCAL_MODEL_FILE)"' -DCK_TOKENIZER_FILE='"$(CK_LOCAL_TOKENIZER_FILE)"' -c $< -o $@ 2907 endif 2908 $(IMACKERN_DIR)/local_tools.o: $(X86K)/local_tools.c $(X86K)/local_tools.h $(X86K)/local_bundle.h $(X86K)/local_tests.inc 2909 ifeq ($(CK_LOCAL_MODEL),1) 2910 $(IMACKERN_DIR)/local_tools.o: $(X86K)/model/model_bundle.h $(X86K)/model/runtime.inc $(X86K)/model/tests.inc 2911 endif 2912 $(IMACKERN_DIR)/local_wire.o: $(X86K)/local_wire.c $(X86K)/local_wire.h $(X86K)/local_tools.h 2913 $(IMACKERN_DIR)/local_enter.o: $(X86K)/local_enter.S 2914 $(IMACKERN_DIR)/local_format.o: $(KDIR)/artifact/format.c $(KDIR)/artifact/ck_artifact.h 2915 ifeq ($(CK_LOCAL_TEST),1) 2916 IMACKERN_CFLAGS += -DCK_LOCAL_TEST=1 -DCK_X86_HOLD_S=1 2917 endif 2918 $(IMACKERN_DIR)/fbcon.o: $(KDIR)/core/fbcon.c $(KDIR)/core/fbcon.h $(KDIR)/core/font8x8.h 2919 $(IMACKERN_DIR)/fmt.o: $(KDIR)/core/fmt.c $(KDIR)/core/fmt.h 2920 $(IMACKERN_DIR)/acpi.o: $(KDIR)/core/acpi.c $(KDIR)/core/acpi.h 2921 $(IMACKERN_DIR)/dmar.o: $(KDIR)/core/dmar.c $(KDIR)/core/dmar.h 2922 $(IMACKERN_DIR)/dmar_x86.o: $(X86K)/dmar_x86.c $(KDIR)/core/dmar.h $(IMACKERN_HDRS) 2923 $(IMACKERN_DIR)/handoff_check.o: $(KDIR)/core/handoff_check.c $(KDIR)/core/handoff_check.h $(BOOT)/handoff.h 2924 $(IMACKERN_DIR)/frames.o: $(KDIR)/mm/frames.c $(KDIR)/mm/frames.h 2925 $(IMACKERN_DIR)/heap.o: $(KDIR)/mm/heap.c $(KDIR)/mm/heap.h 2926 $(IMACKERN_DIR)/libc_min.o: $(KDIR)/core/libc_min.c 2927 $(IMACKERN_DIR)/ahci_x86.o: $(X86K)/ahci_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h $(KDIR)/dev/disk_part.h $(NATIVE)/disk/disk.h 2928 $(IMACKERN_DIR)/disk_part.o: $(KDIR)/dev/disk_part.c $(KDIR)/dev/disk_part.h $(NATIVE)/disk/disk.h 2929 $(IMACKERN_DIR)/disk.o: $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk.h 2930 $(IMACKERN_DIR)/pci_x86.o: $(X86K)/pci_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h $(KDIR)/dev/disk_part.h $(NATIVE)/disk/disk.h $(NATIVE)/disk/disk_nvme.h 2931 $(IMACKERN_DIR)/panel_x86.o: $(X86K)/panel_x86.c $(IMACKERN_HDRS) 2932 $(IMACKERN_DIR)/gpu_x86.o: $(GPU_DIR)/gpu_x86.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_ring.h $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h $(KDIR)/mm/frames.h 2933 $(IMACKERN_DIR)/amd_display.o: $(GPU_DIR)/amd_display.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h 2934 $(IMACKERN_DIR)/amd_mc.o: $(GPU_DIR)/amd_mc.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h 2935 $(IMACKERN_DIR)/amd_smu.o: $(GPU_DIR)/amd_smu.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h 2936 $(IMACKERN_DIR)/amd_ucode.o: $(GPU_DIR)/amd_ucode.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h $(if $(filter 1,$(CK_X86_GPU_UCODE)),$(REPO)/target/native-kernel/gpu_ucode.inc) 2937 $(IMACKERN_DIR)/amd_sdma.o: $(GPU_DIR)/amd_sdma.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h 2938 $(IMACKERN_DIR)/amd_compute.o: $(GPU_DIR)/amd_compute.c $(IMACKERN_HDRS) $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_gpu_regs.h 2939 $(IMACKERN_DIR)/swap_x86.o: $(X86K)/swap_x86.c $(X86K)/x86.h $(X86K)/swap_proto.h $(X86K)/swap_x86.h $(BOOT)/slot_format.h 2940 $(IMACKERN_DIR)/swap_tramp.o: $(X86K)/swap_tramp.S 2941 @mkdir -p $(dir $@) 2942 $(X86CC) -c $(ASFLAGS) $(IMACKERN_TRAMP_FLAGS) -o $@ $< 2943 $(IMACKERN_SLOT_KEYS_C): $(SLOT_TOOL) FORCE 2944 @mkdir -p $(dir $@) 2945 @if [ -n "$(IMACKERN_KEY_SRC)" ]; then $(SLOT_TOOL) keys-c $(IMACKERN_KEY_SRC) --out $@; \ 2946 else printf '#include \nconst uint8_t ck_slot_loader_keys[1][32] = {{0}};\nconst unsigned ck_slot_loader_nkeys = 0;\n' > $@.tmp; \ 2947 cmp -s $@.tmp $@ || mv $@.tmp $@; rm -f $@.tmp; fi 2948 $(IMACKERN_DIR)/imac_slot_keys.o: $(IMACKERN_SLOT_KEYS_C) 2949 $(IMACKERN_DIR)/bench_x86.o: $(X86K)/bench_x86.c $(X86K)/x86.h $(X86K)/bench_proto.h $(X86K)/bench_x86.h $(NATIVE)/argus/sha256.h 2950 # CK_X86_BENCH_KEY_FILE: a 32-byte key file (on the Spark ~/.config/aienos/imac-bench.key; the Spark tool 2951 # takes the same file with --key) bound in as the bench console's HMAC key through a header made in the 2952 # build dir, mode 0600, so the key is never on a command line or in the build output. 2953 ifdef CK_X86_BENCH_KEY_FILE 2954 IMACKERN_CFLAGS += -DCK_X86_BENCH_KEY_H='"$(IMACKERN_DIR)/bench_key.h"' 2955 $(IMACKERN_DIR)/bench_key.h: $(CK_X86_BENCH_KEY_FILE) 2956 @mkdir -p $(@D) 2957 @test "$$(wc -c < '$<')" -eq 32 || { echo "CK_X86_BENCH_KEY_FILE: $< is not 32 bytes" >&2; exit 1; } 2958 @umask 077; { printf '#define CK_X86_BENCH_KEY '; od -An -v -tu1 '$<' | tr -s ' \n' ' ' | sed 's/^ //; s/ $$//; s/ /,/g'; echo; } > $@ 2959 $(IMACKERN_DIR)/bench_x86.o: $(IMACKERN_DIR)/bench_key.h 2960 endif 2961 $(IMACKERN_DIR)/slot_select.o: $(BOOT)/slot_select.c $(BOOT)/slot_format.h 2962 $(IMACKERN_DIR)/`ed25519`.o: $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/aienos_sig.h 2963 $(IMACKERN_DIR)/smp_x86.o: $(X86K)/smp_x86.S 2964 $(IMACKERN_DIR)/disk_nvme.o: $(NATIVE)/disk/disk_nvme.c $(NATIVE)/disk/disk_nvme.h $(NATIVE)/disk/disk.h 2965 $(IMACKERN_DIR)/tg3_x86.o: $(X86K)/tg3_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h 2966 $(IMACKERN_DIR)/xhci_x86.o: $(X86K)/xhci_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h $(KDIR)/dev/usb_hid.h 2967 $(IMACKERN_DIR)/hda_x86.o: $(X86K)/hda_x86.c $(IMACKERN_HDRS) $(KDIR)/mm/frames.h $(KDIR)/ui/chirp.h $(KDIR)/ui/night.h 2968 $(IMACKERN_DIR)/usb_hid.o: $(KDIR)/dev/usb_hid.c $(KDIR)/dev/usb_hid.h $(NATIVE)/argus/sha256.h 2969 $(IMACKERN_DIR)/sha256.o: $(NATIVE)/argus/sha256.c $(NATIVE)/argus/sha256.h 2970 $(IMACKERN_DIR)/allen_ui.o: $(KDIR)/ui/allen_ui.c $(KDIR)/ui/allen_ui.h $(KDIR)/core/spinlock.h $(KDIR)/ui/allen_font.h $(KDIR)/ui/night.h $(KDIR)/ui/mind.h $(KDIR)/ui/flow.h $(KDIR)/ui/paint.h $(KDIR)/ui/canvas.h $(KDIR)/svc/allen_code.h 2971 $(IMACKERN_DIR)/allen_font.o: $(KDIR)/ui/allen_font.c $(KDIR)/ui/allen_font.h 2972 $(IMACKERN_DIR)/paint.o: $(KDIR)/ui/paint.c $(KDIR)/ui/paint.h $(KDIR)/ui/allen_font.h 2973 $(IMACKERN_DIR)/night.o: $(KDIR)/ui/night.c $(KDIR)/ui/night.h $(KDIR)/ui/paint.h $(KDIR)/ui/sky_real.h $(KDIR)/ui/sky_data.h 2974 $(IMACKERN_DIR)/sky_real.o: $(KDIR)/ui/sky_real.c $(KDIR)/ui/sky_real.h $(KDIR)/ui/sky_data.h $(KDIR)/ui/night.h $(KDIR)/ui/paint.h 2975 $(IMACKERN_DIR)/sky_data.o: $(KDIR)/ui/sky_data.c $(KDIR)/ui/sky_data.h 2976 $(IMACKERN_DIR)/chirp.o: $(KDIR)/ui/chirp.c $(KDIR)/ui/chirp.h $(KDIR)/ui/night.h 2977 $(IMACKERN_DIR)/mind.o: $(KDIR)/ui/mind.c $(KDIR)/ui/mind.h $(KDIR)/ui/paint.h 2978 $(IMACKERN_DIR)/flow.o: $(KDIR)/ui/flow.c $(KDIR)/ui/flow.h $(KDIR)/ui/paint.h 2979 # Allen's canvas: the scene the model writes (svc/allen_scene.c) and how it is painted (ui/canvas.c). 2980 IMACKERN_OBJS += $(IMACKERN_DIR)/canvas.o $(IMACKERN_DIR)/allen_scene.o 2981 $(IMACKERN_DIR)/canvas.o: $(KDIR)/ui/canvas.c $(KDIR)/ui/canvas.h $(KDIR)/ui/paint.h $(KDIR)/ui/flow.h $(KDIR)/ui/allen_font.h $(KDIR)/svc/allen_scene.h 2982 $(IMACKERN_DIR)/allen_scene.o: $(KDIR)/svc/allen_scene.c $(KDIR)/svc/allen_scene.h 2983 $(IMACKERN_DIR)/allen_reply.o: $(KDIR)/svc/allen_reply.c $(KDIR)/svc/allen_reply.h $(KDIR)/svc/allen_notes.h 2984 $(IMACKERN_DIR)/allen_intent.o: $(KDIR)/svc/allen_intent.c $(KDIR)/svc/allen_intent.h $(KDIR)/svc/allen_reply.h 2985 $(IMACKERN_DIR)/allen_code.o: $(KDIR)/svc/allen_code.c $(KDIR)/svc/allen_code.h 2986 $(IMACKERN_DIR)/courier_x86.o: $(X86K)/courier_x86.c $(IMACKERN_HDRS) $(KDIR)/svc/courier.h 2987 $(IMACKERN_DIR)/allen_notes.o: $(KDIR)/svc/allen_notes.c $(KDIR)/svc/allen_notes.h 2988 $(IMACKERN_DIR)/allen_memory.o: $(KDIR)/svc/allen_memory.c $(KDIR)/svc/allen_memory.h $(KDIR)/svc/allen_reply.h $(KDIR)/svc/allen_notes.h $(NATIVE)/disk/disk.h $(NATIVE)/argus/sha256.h 2989 $(IMACKERN_DIR)/gpt_add.o: $(KDIR)/dev/gpt_add.c $(KDIR)/dev/gpt_add.h $(KDIR)/dev/disk_part.h $(NATIVE)/disk/disk.h $(NATIVE)/argus/sha256.h 2990 $(IMACKERN_DIR)/memory_x86.o: $(X86K)/memory_x86.c $(IMACKERN_HDRS) $(KDIR)/svc/allen_memory.h $(KDIR)/svc/allen_notes.h $(KDIR)/dev/gpt_add.h $(KDIR)/dev/disk_part.h \ 2991 $(KDIR)/dev/fat_boot.h $(BOOT)/netboot_proto.h $(BOOT)/slot_format.h $(NATIVE)/sig/aienos_sig.h $(KDIR)/svc/setup_store.h 2992 $(IMACKERN_DIR)/fat_boot.o: $(KDIR)/dev/fat_boot.c $(KDIR)/dev/fat_boot.h $(NATIVE)/disk/disk.h 2993 $(IMACKERN_DIR)/sha512.o: $(NATIVE)/sig/sha512.c $(NATIVE)/sig/aienos_sig.h 2994 $(IMACKERN_DIR)/ct.o: $(NATIVE)/sig/ct.c $(NATIVE)/sig/aienos_sig.h 2995 $(IMACKERN_DIR)/setup_inv.o: $(KDIR)/svc/setup_inv.c $(KDIR)/svc/setup_inv.h 2996 $(IMACKERN_DIR)/setup_wizard.o: $(KDIR)/svc/setup_wizard.c $(KDIR)/svc/setup_wizard.h $(KDIR)/svc/setup_inv.h 2997 $(IMACKERN_DIR)/setup_store.o: $(KDIR)/svc/setup_store.c $(KDIR)/svc/setup_store.h $(KDIR)/svc/allen_memory.h $(NATIVE)/disk/disk.h $(NATIVE)/argus/sha256.h 2998 $(IMACKERN_DIR)/setup_x86.o: $(X86K)/setup_x86.c $(IMACKERN_HDRS) $(KDIR)/svc/setup_inv.h $(KDIR)/svc/setup_wizard.h $(KDIR)/svc/setup_store.h \ 2999 $(KDIR)/ui/setup_view.h $(KDIR)/ui/allen_ui.h $(KDIR)/svc/courier.h $(KDIR)/dev/usb_hid.h 3000 $(IMACKERN_DIR)/fwcfg_x86.o: $(X86K)/fwcfg_x86.c $(IMACKERN_HDRS) $(KDIR)/core/acpi.h 3001 $(IMACKERN_DIR)/report_x86.o: $(X86K)/report_x86.c $(X86K)/report_x86.h $(IMACKERN_HDRS) $(NATIVE)/net/aienos_net.h 3002 $(IMACKERN_DIR)/courier_udp_x86.o: $(X86K)/courier_udp_x86.c $(X86K)/courier_udp.h $(IMACKERN_HDRS) $(NATIVE)/net/aienos_net.h $(KDIR)/svc/courier.h 3003 $(IMACKERN_DIR)/aienos_net.o: $(NATIVE)/net/aienos_net.c $(NATIVE)/net/aienos_net.h 3004 $(sort $(filter-out %/swap_tramp.o %/model_assets.o,$(IMACKERN_OBJS) $(IMACKERN_REPORT_OBJS))): 3005 @mkdir -p $(dir $@) 3006 $(X86CC) $(IMACKERN_CFLAGS) -DAIENOS_COMMIT='"$(AIENOS_COMMIT)"' -c -o $@ $< 3007 $(IMACKERN_ELF): $(IMACKERN_OBJS) $(BOOT)/image_x86_64.ld 3008 @if grep -nE -- 'rt->|RuntimeServices' $(X86K)/*.c; then \ 3009 echo "the x86 kernel calls a UEFI runtime service; it must never call one"; exit 1; fi 3010 @if grep -nE "define ATA_" $(X86K)/ahci_x86.c | grep -vE "ATA_(IDENTIFY 0xec|READ_DMA_EXT 0x25|WRITE_DMA_EXT 0x35|FLUSH_CACHE_EXT 0xea)$$"; then \ 3011 echo "ahci_x86.c defines an ATA command other than IDENTIFY, READ/WRITE DMA EXT and FLUSH CACHE EXT"; exit 1; fi 3012 @if grep -nE "ck_x86_ahci_allow\(" $(X86K)/*.c | grep -vE "^$(X86K)/(memory_x86\.c|ahci_x86\.c:[0-9]+:int ck_x86_ahci_allow\()"; then \ 3013 echo "only memory_x86.c may open a write range on an AHCI disk"; exit 1; fi 3014 @if grep -nE "nvme_(write|flush)\(" $(X86K)/*.c; then \ 3015 echo "the x86 kernel calls nvme_write or nvme_flush; its disks are read-only"; exit 1; fi 3016 @mkdir -p $(dir $@) 3017 $(X86LD) $(X86LDFLAGS) -o $@ $(IMACKERN_OBJS) 3018 @u=$$($(X86NM) -u $@ | grep -v ' w ' || true); \ 3019 if [ -n "$$u" ]; then echo "image has undefined symbols: $$u"; rm -f $@; exit 1; fi 3020 @bad=$$($(X86READELF) -rW $@ | grep -E '^[0-9a-f]+ ' | grep -v R_X86_64_RELATIVE || true); \ 3021 if [ -n "$$bad" ]; then echo "image has non-RELATIVE relocations:"; echo "$$bad"; rm -f $@; exit 1; fi 3022 @n=$$($(X86NM) $@ | grep -c ' t isr_common$$' || true); s=$$($(X86NM) $@ | grep ' T ck_x86_isr_stubs$$' | cut -c1-16); \ 3023 e=$$($(X86NM) $@ | grep ' t isr_common$$' | cut -c1-16); \ 3024 if [ "$$n" != 1 ] || [ $$((0x$$e - 0x$$s)) != 4096 ]; then echo "interrupt stubs are not 256 x 16 bytes"; rm -f $@; exit 1; fi 3025 @r=$$($(X86NM) $@ | grep -E ' [TtDdBbRr] ($(IMACKERN_REPORT_SYMS))$$' || true); \ 3026 if [ "$(CK_X86_REPORT)" = 1 ]; then \ 3027 for s in ck_x86_report_hold ck_x86_report_filter ck_x86_report_frame; do \ 3028 echo "$$r" | grep -q " $$s$$" || { echo "lab image lacks $$s"; rm -f $@; exit 1; }; done; \ 3029 elif [ -n "$$r" ]; then \ 3030 echo "default iMac image links the lab-only network report (build it with CK_X86_REPORT=1 only):"; \ 3031 echo "$$r"; rm -f $@; exit 1; fi 3032 @if [ "$(CK_X86_REPORT)" != 1 ] && grep -aq "AIENOS-REPORT" $@; then \ 3033 echo "default iMac image carries the report header string"; rm -f $@; exit 1; fi 3034 @if [ "$(CK_X86_REPORT)" != 1 ]; then s=$$($(X86NM) $@ | grep -E ' [TtDdBbRr] (ck_x86_swap_tramp|ck_x86_swap_read_inbox)$$' || true); \ 3035 if [ -n "$$s" ]; then echo "default iMac image links the swap receiver (lab builds only):"; echo "$$s"; rm -f $@; exit 1; fi; fi 3036 @f=$$($(X86NM) $@ | grep -E ' [TtDdBbRr] ck_x86_fwcfg_file$$' || true); s=$$(grep -aoE "opt/aienos/host|QEMU0002" $@ | sort -u | tr "\n" " "); \ 3037 if [ "$(CK_X86_HOSTDESC)" = 1 ]; then \ 3038 [ -n "$$f" ] && grep -aqF "launcher image: the setup wizard reads the host description" $@ || { echo "launcher image lacks the host description reader or its announcement"; rm -f $@; exit 1; }; \ 3039 elif [ -n "$$f$$s" ]; then echo "default iMac image carries fw_cfg code (build it with CK_X86_HOSTDESC=1 only): $$f $$s"; rm -f $@; exit 1; fi 3040 @if [ "$(CK_LOCAL_TEST)" != 1 ] && grep -aq 'local_test:' $@; then \ 3041 echo "release image contains hostile local-tool fixtures"; rm -f $@; exit 1; fi 3042 $(IMACKERN_EFI): $(IMACKERN_ELF) 3043 $(X86OBJCOPY) -O binary $< $@ 3044 @sz=$$(stat -c %s $@); pad=$$(( (4096 - sz % 4096) % 4096 )); \ 3045 if [ $$pad -gt 0 ]; then head -c $$pad /dev/zero >> $@; fi 3046 @[ "$$(head -c 2 $@)" = "MZ" ] || { echo "not a PE image"; rm -f $@; exit 1; } 3047 @[ "$$(od -An -tx1 -j68 -N2 $@ | tr -d ' ')" = "6486" ] || { echo "PE Machine is not x86_64 (0x8664)"; rm -f $@; exit 1; } 3048 @echo "built $@ (commit $(AIENOS_COMMIT))" 3049 imac-kernel: $(IMACKERN_EFI) 3050 3051 # ---- AMD GPU driver host test (mock MMIO, no hardware needed) ---- 3052 # Checks register access sequences for display flip, MC, SMU, ring submit 3053 # and fence against Linux dce_v11_0.c / gmc_v8_0.c / gfx_v8_0.c source paths. 3054 GPU_TEST_SRC := $(KDIR)/tests/test_amd_gpu.c 3055 $(OUT)/host/test_amd_gpu: $(GPU_TEST_SRC) $(GPU_DIR)/amd_gpu_regs.h $(GPU_DIR)/amd_ring.h 3056 @mkdir -p $(OUT)/host 3057 $(CC) -std=c11 -Wall -DAMD_GPU_TEST_HOST=1 -I$(KDIR) -I$(GPU_DIR) -I$(X86K) -o $@ $< 3058 @echo "host test: running test_amd_gpu"; $@ 3059 imac-gpu-test: $(OUT)/host/test_amd_gpu $(OUT)/host/test_amd_gpu_ring 3060 # Ring code under test: the driver's own amd_ucode.c and frames.c; the GPU is a model thread (tests/test_amd_gpu_ring.c). 3061 GPU_RING_TEST_SRC := $(KDIR)/tests/test_amd_gpu_ring.c 3062 $(OUT)/host/test_amd_gpu_ring: $(GPU_RING_TEST_SRC) $(GPU_DIR)/amd_ucode.c $(KDIR)/mm/frames.c $(GPU_DIR)/amd_gpu.h $(GPU_DIR)/amd_host_shim.h $(GPU_DIR)/amd_gpu_regs.h $(GPU_DIR)/amd_ring.h $(KDIR)/mm/frames.h 3063 @mkdir -p $(OUT)/host 3064 $(CC) -std=c11 -Wall -pthread -DAMD_GPU_TEST_HOST=1 -I$(KDIR) -I$(KDIR)/include -I$(KDIR)/mm -I$(BOOT) -I$(GPU_DIR) -I$(X86K) -o $@ $(GPU_RING_TEST_SRC) $(GPU_DIR)/amd_ucode.c $(KDIR)/mm/frames.c 3065 @echo "host test: running test_amd_gpu_ring"; $@ 3066 # Host tools for the lab bench/swap (C only, no third-party libraries). Built with cc, not into the image. 3067 GPU_BENCH_TOOL := $(OUT)/host/ck_gpu_bench 3068 IMAC_SWAP_TOOL := $(OUT)/host/ck_imac_swap 3069 $(GPU_BENCH_TOOL): $(KDIR)/tools/ck_gpu_bench.c $(X86K)/bench_proto.h 3070 @mkdir -p $(dir $@) 3071 cc -O2 -std=c11 -Wall -Wextra -o $@ $< 3072 $(IMAC_SWAP_TOOL): $(KDIR)/tools/ck_imac_swap.c $(X86K)/swap_proto.h 3073 @mkdir -p $(dir $@) 3074 cc -O2 -std=c11 -Wall -Wextra -o $@ $< 3075 .PHONY: ck-gpu-bench ck-imac-swap 3076 ck-gpu-bench: $(GPU_BENCH_TOOL) 3077 ck-imac-swap: $(IMAC_SWAP_TOOL) 3078 # W^X and TLB negative controls (#409, #484, #485), TEST-ONLY, QEMU only, never deployed: IMACKERN_WX_MUTANT=no_nx 3079 # drops every NX bit, =text_writable leaves the kernel's code writable, =ap_no_wp starts the secondary cores 3080 # without CR0.WP, =no_shootdown flushes a changed page from the boot core's TLB only. The kernel's W^X and TLB 3081 # probes (or, for ap_no_wp, the wx_audit core count) must then panic 3082 # (scripts/qemu_ck_imac_kernel_test.sh builds each into its own OUT). The stamp rebuilds kmain_x86.o and 3083 # smp_x86.o whenever the setting changes, so a mutant object never lingers in a default build. 3084 IMACKERN_WX_MUTANT ?= 3085 ifeq ($(strip $(IMACKERN_WX_MUTANT)),) 3086 IMACKERN_WX_FLAGS := 3087 else ifeq ($(strip $(IMACKERN_WX_MUTANT)),no_nx) 3088 IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_NO_NX=1 3089 else ifeq ($(strip $(IMACKERN_WX_MUTANT)),text_writable) 3090 IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_TEXT_RW=1 3091 else ifeq ($(strip $(IMACKERN_WX_MUTANT)),ap_no_wp) 3092 IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_AP_NO_WP=1 3093 else ifeq ($(strip $(IMACKERN_WX_MUTANT)),no_shootdown) 3094 IMACKERN_WX_FLAGS := -DCK_X86_WX_MUTANT_NO_SHOOTDOWN=1 3095 else 3096 $(error IMACKERN_WX_MUTANT must be empty, no_nx, text_writable, ap_no_wp or no_shootdown) 3097 endif 3098 # CK_X86_IDLE_S: seconds without a key before Allen's screen sleeps (kmain_x86.c default 600, 0 never). 3099 # Set only for test builds (scripts/qemu_ck_imac_keyboard_test.sh uses 25), into their own OUT directory. 3100 ifdef CK_X86_IDLE_S 3101 IMACKERN_CFLAGS += -DCK_X86_IDLE_S=$(CK_X86_IDLE_S)u 3102 endif 3103 # CK_X86_PANEL_OFF: while Allen rests, switch the display panel off for real through the AMD 3104 # display chip's panel power sequencer (x86/panel_x86.c; DCE 11.2 registers, Polaris parts only, 3105 # every write read back, every wait TSC-bounded) and on again when he wakes. Default 1 for 3106 # `make imac-kernel`. The code finds no such chip in QEMU and says so (`screen: panel: ...`); 3107 # 0 leaves it out of the image altogether (own OUT directory). 3108 CK_X86_PANEL_OFF ?= 1 3109 ifeq ($(CK_X86_PANEL_OFF),1) 3110 IMACKERN_CFLAGS += -DCK_X86_PANEL_OFF=1 3111 else ifeq ($(CK_X86_PANEL_OFF),0) 3112 IMACKERN_CFLAGS += -DCK_X86_PANEL_OFF=0 3113 else 3114 $(error CK_X86_PANEL_OFF must be 1 (default: the panel is switched off while Allen rests) or 0) 3115 endif 3116 $(IMACKERN_DIR)/kmain_x86.o $(IMACKERN_DIR)/smp_x86.o: IMACKERN_CFLAGS += $(IMACKERN_WX_FLAGS) 3117 $(IMACKERN_DIR)/kmain_x86.o $(IMACKERN_DIR)/smp_x86.o: $(IMACKERN_DIR)/wx_mutant.stamp 3118 $(IMACKERN_DIR)/wx_mutant.stamp: FORCE 3119 @mkdir -p $(dir $@) 3120 @echo '$(strip $(IMACKERN_WX_MUTANT))' | cmp -s - $@ || echo '$(strip $(IMACKERN_WX_MUTANT))' > $@ 3121 3122 # ---- NETLDR.EFI: the lab network loader for the 2017 iMac (x86_64) ---- 3123 # native/boot/net_loader.c + netboot_proto.c (wire spec netboot_proto.h). Stays on the stick as 3124 # EFI/BOOT/BOOTX64.EFI; at every power-on it fetches a kernel from tools/ck_imac_netboot.c over 3125 # the LAN, verifies it with the SLOTLDR verifier (ck_slot_verify: Ed25519 manifest signature, 3126 # SHA-512 of the image) against the public keys baked in from CK_NETLDR_KEYS ("owner_root_`ed25519` 3127 # <64 hex>" lines; ck_imac_netboot keygen writes one) and only then starts it. No answer for 3128 # CK_NETLDR_FALLBACK_S seconds: it starts \EFI\AIENOS\IMACKERN.EFI from the stick instead. 3129 # make imac-netldr CK_NETLDR_KEYS= -> $(OUT)/NETLDR.EFI 3130 # make imac-netboot-tool -> $(OUT)/host/ck_imac_netboot (keygen, sign, serve) 3131 # QEMU test: scripts/qemu_ck_imac_netboot_test.sh (AIENOS_IMAC_NETBOOT). 3132 CK_NETLDR_KEYS ?= 3133 CK_NETLDR_FALLBACK_S ?= 30 3134 ifeq ($(shell echo '$(CK_NETLDR_FALLBACK_S)' | grep -xE '[1-9][0-9]{0,3}'),) 3135 $(error CK_NETLDR_FALLBACK_S must be a whole number of seconds, 1..9999) 3136 endif 3137 NETLDR_DIR := $(OUT)/netldr 3138 NETLDR_ELF := $(NETLDR_DIR)/netldr.elf 3139 NETLDR_EFI := $(OUT)/NETLDR.EFI 3140 NETLDR_KEYS_C := $(NETLDR_DIR)/netldr_keys.c 3141 NETLDR_C := $(BOOT)/net_loader.c $(BOOT)/netboot_proto.c $(BOOT)/slot_select.c $(NATIVE)/net/aienos_net.c \ 3142 $(NATIVE)/sig/sha512.c $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/ct.c $(NATIVE)/argus/sha256.c \ 3143 $(KDIR)/core/libc_min.c $(KDIR)/core/fmt.c 3144 NETLDR_OBJS := $(patsubst $(NATIVE)/%.c,$(NETLDR_DIR)/obj/%.o,$(NETLDR_C)) \ 3145 $(NETLDR_DIR)/obj/efi_entry_x86_64.o $(NETLDR_DIR)/obj/netldr_keys.o 3146 NETLDR_CFLAGS := $(X86CFLAGS) $(ART_INC) -I$(NATIVE)/net -I$(NATIVE)/store 3147 NETLDR_HDRS := $(BOOT)/netboot_proto.h $(BOOT)/slot_format.h $(BOOT)/efi.h $(NATIVE)/net/aienos_net.h \ 3148 $(KDIR)/core/fmt.h $(ART_HDRS) 3149 $(NETLDR_DIR)/obj/%.o: $(NATIVE)/%.c $(NETLDR_HDRS) 3150 @mkdir -p $(dir $@) 3151 $(X86CC) $(NETLDR_CFLAGS) -c -o $@ $< 3152 # The fallback delay is compiled in; the stamp rebuilds the loader when it changes. 3153 $(NETLDR_DIR)/fallback.stamp: FORCE 3154 @mkdir -p $(dir $@) 3155 @[ "$$(cat $@ 2>/dev/null)" = "$(CK_NETLDR_FALLBACK_S)" ] || echo "$(CK_NETLDR_FALLBACK_S)" > $@ 3156 $(NETLDR_DIR)/obj/boot/net_loader.o: $(BOOT)/net_loader.c $(NETLDR_HDRS) $(OUT)/commit.stamp $(NETLDR_DIR)/fallback.stamp 3157 @mkdir -p $(dir $@) 3158 $(X86CC) $(NETLDR_CFLAGS) -DAIENOS_COMMIT='"$(AIENOS_COMMIT)"' -DCK_NETLDR_FALLBACK_S=$(CK_NETLDR_FALLBACK_S)u -c -o $@ $< 3159 $(NETLDR_DIR)/obj/efi_entry_x86_64.o: $(BOOT)/efi_entry_x86_64.S 3160 @mkdir -p $(dir $@) 3161 $(X86CC) $(X86CFLAGS) -c -o $@ $< 3162 $(NETLDR_KEYS_C): $(SLOT_TOOL) FORCE 3163 @[ -n "$(strip $(CK_NETLDR_KEYS))" ] || { echo "imac-netldr: give CK_NETLDR_KEYS= (ck_imac_netboot keygen writes one)"; exit 1; } 3164 @mkdir -p $(dir $@) 3165 @$(SLOT_TOOL) keys-c --keys $(abspath $(CK_NETLDR_KEYS)) --out $@ 3166 $(NETLDR_DIR)/obj/netldr_keys.o: $(NETLDR_KEYS_C) 3167 @mkdir -p $(dir $@) 3168 $(X86CC) $(NETLDR_CFLAGS) -c -o $@ $< 3169 $(NETLDR_ELF): $(NETLDR_OBJS) $(BOOT)/image_x86_64.ld 3170 @if grep -nE -- '->(RuntimeServices|ExitBootServices|SetVariable|GetVariable)|RuntimeServices' $(BOOT)/net_loader.c; then \ 3171 echo "net_loader.c calls a service the network loader must never call"; exit 1; fi 3172 @mkdir -p $(dir $@) 3173 $(X86LD) $(X86LDFLAGS) -o $@ $(NETLDR_OBJS) 3174 @u=$$($(X86NM) -u $@ | grep -v ' w ' || true); \ 3175 if [ -n "$$u" ]; then echo "image has undefined symbols: $$u"; rm -f $@; exit 1; fi 3176 @bad=$$($(X86READELF) -rW $@ | grep -E '^[0-9a-f]+ ' | grep -v R_X86_64_RELATIVE || true); \ 3177 if [ -n "$$bad" ]; then echo "image has non-RELATIVE relocations:"; echo "$$bad"; rm -f $@; exit 1; fi 3178 @k=$$($(X86NM) $@ | grep -E ' [TtDdBbRr] (ck_x86_kernel_entry|kernel_main|ck_printf)$$' || true); \ 3179 if [ -n "$$k" ]; then echo "NETLDR links kernel objects: $$k"; rm -f $@; exit 1; fi 3180 @if grep -aqF "TEST-ONLY" $@; then echo "NETLDR carries a TEST-ONLY key note"; rm -f $@; exit 1; fi 3181 $(NETLDR_EFI): $(NETLDR_ELF) 3182 $(X86OBJCOPY) -O binary $< $@ 3183 @sz=$$(stat -c %s $@); pad=$$(( (4096 - sz % 4096) % 4096 )); \ 3184 if [ $$pad -gt 0 ]; then head -c $$pad /dev/zero >> $@; fi 3185 @[ "$$(head -c 2 $@)" = "MZ" ] || { echo "not a PE image"; rm -f $@; exit 1; } 3186 @[ "$$(od -An -tx1 -j68 -N2 $@ | tr -d ' ')" = "6486" ] || { echo "PE Machine is not x86_64 (0x8664)"; rm -f $@; exit 1; } 3187 @echo "built $@ (commit $(AIENOS_COMMIT), fallback $(CK_NETLDR_FALLBACK_S) s)" 3188 imac-netldr: $(NETLDR_EFI) 3189 NETBOOT_TOOL := $(OUT)/host/ck_imac_netboot 3190 NETBOOT_TOOL_SRCS := $(KDIR)/tools/ck_imac_netboot.c $(BOOT)/netboot_proto.c $(NATIVE)/net/aienos_net.c \ 3191 $(NATIVE)/sig/sha512.c $(NATIVE)/sig/`ed25519`.c $(NATIVE)/sig/ct.c 3192 $(NETBOOT_TOOL): $(NETBOOT_TOOL_SRCS) $(BOOT)/netboot_proto.h $(NATIVE)/net/aienos_net.h $(NATIVE)/sig/aienos_sig.h 3193 @mkdir -p $(dir $@) 3194 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(BOOT) -I$(NATIVE)/net -I$(NATIVE)/sig -o $@ $(NETBOOT_TOOL_SRCS) 3195 # Apple NetBoot answerer (BSDP + one-file TFTP): the iMac starts NETLDR.EFI from the Spark with N held. 3196 BSDP_TOOL := $(OUT)/host/ck_imac_bsdp 3197 $(BSDP_TOOL): $(KDIR)/tools/ck_imac_bsdp.c 3198 @mkdir -p $(dir $@) 3199 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 3200 imac-netboot-tool: $(NETBOOT_TOOL) $(BSDP_TOOL) 3201 3202 # Raspberry Pi 5 board image (see CK_PI5 above): target/native-kernel-pi5/BOOTAA64.EFI 3203 pi5-store: 3204 $(MAKE) CK_PI5_STORE=1 full 3205 3206 # PI5-8 Q1: --remap-path-prefix keeps the build directory out of the Rust panic-location strings, so the three Pi images 3207 # that link this library are byte-identical when built from different checkout paths (scripts/ck_pi5_repro_check.sh). 3208 PI5_INFER_LIB := $(REPO)/target/infer-kernel/aarch64-unknown-none/release/libaienos_infer_kernel.a 3209 pi5-infer: 3210 RUSTFLAGS="--remap-path-prefix=$(REPO)=/aienos" CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml 3211 $(MAKE) CK_PI5_INFER=1 CK_INFER_LIB=$(PI5_INFER_LIB) all 3212 pi5-unlock: 3213 $(MAKE) CK_PI5_UNLOCK=1 full 3214 3215 pi5-unlock-card: 3216 $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 full 3217 3218 pi5-fact: 3219 $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1 full 3220 3221 pi5-agent: 3222 RUSTFLAGS="--remap-path-prefix=$(REPO)=/aienos" CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml 3223 $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_AGENT=1 CK_INFER_LIB=$(PI5_INFER_LIB) full 3224 3225 pi5-lifecycle: 3226 RUSTFLAGS="--remap-path-prefix=$(REPO)=/aienos" CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml 3227 $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=$(PI5_INFER_LIB) full 3228 3229 pi5-artifact: 3230 $(MAKE) CK_PI5_ARTIFACT=1 all 3231 3232 # PI5-8 cut K: the ALLEN unit (crates/allen-reflex-kernel) for aarch64-unknown-none, same path remap as pi5-infer. 3233 ALLEN_LIB := $(REPO)/target/allen-kernel/aarch64-unknown-none/release/liballen_reflex_kernel.a 3234 allen-lib: 3235 RUSTFLAGS="--remap-path-prefix=$(REPO)=/aienos" CARGO_TARGET_DIR=$(REPO)/target/allen-kernel cargo build -q --release --locked --target aarch64-unknown-none --manifest-path $(REPO)/crates/allen-reflex-kernel/Cargo.toml 3236 3237 # Raspberry Pi 5 ALLEN exam image (see CK_PI5_ALLEN above): target/native-kernel-pi5-allen/BOOTAA64.EFI 3238 pi5-allen: allen-lib 3239 $(MAKE) CK_PI5_ALLEN=1 CK_ALLEN_LIB=$(ALLEN_LIB) all 3240 3241 pi5: 3242 $(MAKE) CK_PI5=1 all 3243 3244 # Raspberry Pi 5 PCIe/RP1 enumerator image (see CK_PI5_PCIE above): target/native-kernel-pi5-pcie/BOOTAA64.EFI 3245 pi5-net: 3246 $(MAKE) CK_PI5_NET=1 all 3247 3248 pi5-pcie: 3249 $(MAKE) CK_PI5_PCIE=1 all 3250 3251 # ---- host checker for the AIENOS_CK_SCREEN gate (scripts/qemu_ck_screen_test.sh) ---- 3252 FB_CHECK_TOOL := $(OUT)/host/ck_fb_check 3253 $(FB_CHECK_TOOL): $(KDIR)/tools/ck_fb_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/fbcon.h $(KDIR)/core/font8x8.h 3254 @mkdir -p $(dir $@) 3255 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $(KDIR)/tools/ck_fb_check.c $(KDIR)/core/fbcon.c 3256 fb-check: $(FB_CHECK_TOOL) 3257 3258 # ---- platform xHCI discovery over dumped firmware tables (NEXT-PHASE-3 cut 2) ---- 3259 # Runs the kernel scan (core/acpi_dev.c) and IORT lookup (core/acpi.c) over 3260 # DSDT/SSDT/IORT files read under Linux and prints the lines the kernel 3261 # fence prints (dev/xhci_acpi_fmt.h). Hosted; never part of an image. 3262 ACPI_SCAN_TOOL := $(OUT)/host/ck_acpi_scan 3263 $(ACPI_SCAN_TOOL): $(KDIR)/tools/ck_acpi_scan.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/acpi.c \ 3264 $(KDIR)/core/acpi_dev.h $(KDIR)/core/acpi.h $(KDIR)/dev/xhci_acpi_fmt.h 3265 @mkdir -p $(dir $@) 3266 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/dev -I$(BOOT) -o $@ \ 3267 $(KDIR)/tools/ck_acpi_scan.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/acpi.c 3268 acpi-scan: $(ACPI_SCAN_TOOL) 3269 3270 # Owner provisioning generator (hosted; never part of an image) and the 3271 # generated header for the hardware staging image. 3272 OWNER_GEN := $(OUT)/host/ck_owner_gen 3273 $(OWNER_GEN): $(KDIR)/tools/ck_owner_gen.c 3274 @mkdir -p $(dir $@) 3275 $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $< 3276 owner-gen: $(OWNER_GEN) 3277 ifneq ($(OWNER_HDR),) 3278 $(OWNER_HDR): $(OWNER_GEN) $(OWNER_PUBKEYS_FILE) $(OWNER_MACHINE_FILE) 3279 @mkdir -p $(dir $@) 3280 $(OWNER_GEN) $(OWNER_PUBKEYS_FILE) $(OWNER_MACHINE_FILE) $@ 3281 endif 3282 3283 clean: 3284 rm -rf $(OUT) 3285 3286 # AIENOS-PI5 RNG200 hardware entropy source: driver logic over a mocked register block, real core/entropy.c rules. 3287 PI5_RNG_SRCS := $(KDIR)/dev/pi5_rng.c $(KDIR)/core/entropy.c 3288 $(OUT)/host/test_pi5_rng: $(KDIR)/tests/test_pi5_rng.c $(PI5_RNG_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/pi5_rng.h $(KDIR)/core/entropy.h 3289 @mkdir -p $(dir $@) 3290 $(HOSTCC) $(HCFLAGS) -DCK_RNG200_SPINS=1000 -I$(KDIR)/dev -o $@ $< $(PI5_RNG_SRCS) 3291 test-pi5-rng: $(OUT)/host/test_pi5_rng 3292 $< 3293 $(OUT)/host-san/test_pi5_rng: $(KDIR)/tests/test_pi5_rng.c $(PI5_RNG_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/pi5_rng.h $(KDIR)/core/entropy.h 3294 @mkdir -p $(dir $@) 3295 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -DCK_RNG200_SPINS=1000 -I$(KDIR)/dev -o $@ $< $(PI5_RNG_SRCS) 3296 3297 FORCE: 3298 .PHONY: uefi-vars slot-loader slot-loader-check pi5-diag imac-diag imac-kernel imac-netldr imac-netboot-tool 3299 .PHONY: artifact-tier-pi5 artifact-tier-mutant 3300 .PHONY: osc-receipt-mutants osc-receipt-release osc-code-flip-guard all full pi5 pi5-store pi5-infer pi5-unlock pi5-unlock-card pi5-fact pi5-agent pi5-lifecycle pi5-artifact pi5-allen allen-lib artifact-card-mutant test sanitize context-mutant agent-cmd-mutant allen-gate-mutant cortex-image handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE 3301 3302 # AIENOS-PI5 step 3 marker + Pi card GPT test (hosted; a file stands in for the card, QEMU cannot model the Pi SD host). 3303 PI5_MARKER_SRCS := $(KDIR)/core/pi5_marker.c $(KDIR)/dev/disk_part.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \ 3304 $(KDIR)/tools/gpt_write.c 3305 $(OUT)/host/test_pi5_marker: $(KDIR)/tests/test_pi5_marker.c $(PI5_MARKER_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/core/pi5_marker.h 3306 @mkdir -p $(dir $@) 3307 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -I$(KDIR)/tools -I$(NATIVE)/disk -o $@ $< $(PI5_MARKER_SRCS) 3308 test-pi5-marker: $(OUT)/host/test_pi5_marker 3309 $< 3310 $(OUT)/host-san/test_pi5_marker: $(KDIR)/tests/test_pi5_marker.c $(PI5_MARKER_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/core/pi5_marker.h 3311 @mkdir -p $(dir $@) 3312 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -I$(KDIR)/tools -I$(NATIVE)/disk -o $@ $< $(PI5_MARKER_SRCS) 3313 3314 # AIENOS-PI5 software-only DMA confinement (ADR 0020): host test only, not linked into any image. 3315 DMAW_SRCS := $(KDIR)/dev/dma_window.c 3316 DMAW_DEPS := $(KDIR)/tests/test_dma_window.c $(DMAW_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/dma_window.h 3317 $(OUT)/host/test_dma_window: $(DMAW_DEPS) 3318 @mkdir -p $(dir $@) 3319 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -o $@ $< $(DMAW_SRCS) 3320 $(OUT)/host-san/test_dma_window: $(DMAW_DEPS) 3321 @mkdir -p $(dir $@) 3322 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -o $@ $< $(DMAW_SRCS) 3323 test-dma-window: $(OUT)/host/test_dma_window 3324 $< 3325 # Each mutant removes one check; the test must FAIL for every one. (The explicit "addr below base" test is not a 3326 # mutant: with unsigned arithmetic the end check already refuses it, so it is kept as defence in depth.) 3327 DMAW_MUTANTS := NO_END WRAP NO_ZERO NO_LATCH NO_STALE NO_ALIGN NO_FRAMECAP NO_GOT NO_INDEX 3328 dma-window-mutants: 3329 @mkdir -p $(OUT)/host 3330 @fail=0; for m in $(DMAW_MUTANTS); do \ 3331 $(HOSTCC) $(HCFLAGS) -DCK_DMAW_MUTANT_$$m -I$(KDIR)/dev -o $(OUT)/host/test_dma_window_mut_$$m $(KDIR)/tests/test_dma_window.c $(DMAW_SRCS) || exit 1; \ 3332 if $(OUT)/host/test_dma_window_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 3333 done; test $$fail -eq 0 3334 .PHONY: test-dma-window dma-window-mutants 3335 3336 # SMMU DMA service refusals (core/smmu_svc.c, #480): the test includes the service source to lay out its static 3337 # instance table, and stubs the platform hooks itself. Host only. 3338 SMMU_SVC_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/mm/frames.c $(KDIR)/mm/pt.c $(KDIR)/mm/heap.c 3339 SMMU_SVC_DEPS := $(KDIR)/tests/test_smmu_svc.c $(KDIR)/core/smmu_svc.c $(SMMU_SVC_SRCS) $(KDIR)/tests/ck_test.h $(HDRS) 3340 $(OUT)/host/test_smmu_svc: $(SMMU_SVC_DEPS) 3341 @mkdir -p $(dir $@) 3342 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/include -o $@ $< $(SMMU_SVC_SRCS) 3343 $(OUT)/host-san/test_smmu_svc: $(SMMU_SVC_DEPS) 3344 @mkdir -p $(dir $@) 3345 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/include -o $@ $< $(SMMU_SVC_SRCS) 3346 3347 # AIENOS-GB10 cut D, host side: GPU page tables, allocator and channel over a simulated GB10 3348 # (gpu/gpu_sim.c). Host test only, not linked into any image (dependency map: kernel-side D code waits for #163/B). 3349 GPU_SIM_SRCS := $(KDIR)/gpu/gmmu.c $(KDIR)/gpu/gpu_mem.c $(KDIR)/gpu/gpu_chan.c $(KDIR)/gpu/gpu_sim.c 3350 GPU_SIM_HDRS := $(KDIR)/gpu/gmmu.h $(KDIR)/gpu/gpu_mem.h $(KDIR)/gpu/gpu_chan.h $(KDIR)/gpu/gpu_sim.h 3351 GPU_SIM_DEPS := $(KDIR)/tests/test_gpu_sim.c $(GPU_SIM_SRCS) $(GPU_SIM_HDRS) $(KDIR)/tests/ck_test.h 3352 $(OUT)/host/test_gpu_sim: $(GPU_SIM_DEPS) 3353 @mkdir -p $(dir $@) 3354 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS) 3355 $(OUT)/host-san/test_gpu_sim: $(GPU_SIM_DEPS) 3356 @mkdir -p $(dir $@) 3357 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS) 3358 test-gpu-sim: $(OUT)/host/test_gpu_sim 3359 $< 3360 # The three files that would run in the kernel must build with the kernel compiler and KCFLAGS and need no symbol from outside. 3361 gpu-freestanding: 3362 @mkdir -p $(OUT)/host/gpu-fs 3363 @for f in gmmu gpu_mem gpu_chan; do \ 3364 $(KCC) $(KCFLAGS) -I$(KDIR)/gpu -c -o $(OUT)/host/gpu-fs/$$f.o $(KDIR)/gpu/$$f.c || exit 1; \ 3365 done; \ 3366 $(CROSS)ld -r -o $(OUT)/host/gpu-fs/gpu.o $(OUT)/host/gpu-fs/gmmu.o $(OUT)/host/gpu-fs/gpu_mem.o $(OUT)/host/gpu-fs/gpu_chan.o || exit 1; \ 3367 if nm -u $(OUT)/host/gpu-fs/gpu.o | grep -v " _GLOBAL_OFFSET_TABLE_$$" | grep -q .; then nm -u $(OUT)/host/gpu-fs/gpu.o; echo "gpu-freestanding: FAIL (undefined symbols)"; exit 1; fi; \ 3368 echo "gpu-freestanding: PASS (gmmu gpu_mem gpu_chan built with KCC/KCFLAGS, linked -r, no undefined symbol except the PIE GOT)" 3369 # Each mutant removes one check; test_gpu_sim must FAIL for every one. 3370 GPU_SIM_MUTANTS := NO_OVERLAP NO_PA_RANGE NO_VA_BITS NO_POOL_COUNT NO_INVAL_POLL NO_TIMEOUT_LATCH NO_QUARANTINE \ 3371 NO_POLLED_UNCACHED NO_GP_VA40 NO_RING_FULL NO_IDLE_QUARANTINE NO_MIXED_PAGES NO_INST_PDB NO_CHID_WIDTH NO_USERD_WIDTH NO_DISABLE \ 3372 NO_PDE_CHECK NO_POOL_OVERLAP 3373 gpu-sim-mutants: 3374 @mkdir -p $(OUT)/host 3375 @fail=0; for m in $(GPU_SIM_MUTANTS); do \ 3376 $(HOSTCC) $(HCFLAGS) -DCK_GPU_MUTANT_$$m -I$(KDIR)/gpu -o $(OUT)/host/test_gpu_sim_mut_$$m $(KDIR)/tests/test_gpu_sim.c $(GPU_SIM_SRCS) || exit 1; \ 3377 if $(OUT)/host/test_gpu_sim_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 3378 done; test $$fail -eq 0 3379 .PHONY: test-gpu-sim gpu-freestanding gpu-sim-mutants 3380 3381 # L332 rung 1: the same channel as a device contract (gpu/contract/gb10_chan.devc, ADR 0021 class gpu-chan), compiled by 3382 # crates/aienos-devc into gpu/contract/gen/gch_contract.c (committed; the kernel build never runs cargo). The generated twin 3383 # must pass test_gpu_sim like the hand one, and the differential trace (every register access and a hash of all simulated 3384 # memory after each of ~330 operations) must be byte-identical between the two. 3385 GPU_CONTRACT_C := $(KDIR)/gpu/contract/gen/gch_contract.c 3386 GPU_SIM_SRCS_CONTRACT := $(filter-out $(KDIR)/gpu/gpu_chan.c,$(GPU_SIM_SRCS)) $(GPU_CONTRACT_C) 3387 $(OUT)/host/test_gpu_sim_contract: $(KDIR)/tests/test_gpu_sim.c $(GPU_SIM_SRCS_CONTRACT) $(GPU_SIM_HDRS) $(KDIR)/tests/ck_test.h 3388 @mkdir -p $(dir $@) 3389 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS_CONTRACT) 3390 $(OUT)/host-san/test_gpu_sim_contract: $(KDIR)/tests/test_gpu_sim.c $(GPU_SIM_SRCS_CONTRACT) $(GPU_SIM_HDRS) $(KDIR)/tests/ck_test.h 3391 @mkdir -p $(dir $@) 3392 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS_CONTRACT) 3393 $(OUT)/host/gpu_chan_trace_hand: $(KDIR)/tests/gpu_chan_trace.c $(GPU_SIM_SRCS) $(GPU_SIM_HDRS) 3394 @mkdir -p $(dir $@) 3395 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS) 3396 $(OUT)/host/gpu_chan_trace_contract: $(KDIR)/tests/gpu_chan_trace.c $(GPU_SIM_SRCS_CONTRACT) $(GPU_SIM_HDRS) 3397 @mkdir -p $(dir $@) 3398 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GPU_SIM_SRCS_CONTRACT) 3399 test-gpu-contract: $(OUT)/host/test_gpu_sim_contract $(OUT)/host-san/test_gpu_sim_contract 3400 $(OUT)/host/test_gpu_sim_contract 3401 $(OUT)/host-san/test_gpu_sim_contract 3402 gpu-contract-trace: $(OUT)/host/gpu_chan_trace_hand $(OUT)/host/gpu_chan_trace_contract 3403 @$(OUT)/host/gpu_chan_trace_hand > $(OUT)/host/gpu_chan_trace_hand.txt 3404 @$(OUT)/host/gpu_chan_trace_contract > $(OUT)/host/gpu_chan_trace_contract.txt 3405 @cmp $(OUT)/host/gpu_chan_trace_hand.txt $(OUT)/host/gpu_chan_trace_contract.txt \ 3406 && echo "gpu-contract-trace: PASS ($$(wc -l < $(OUT)/host/gpu_chan_trace_hand.txt) lines identical, hand vs contract)" 3407 gpu-contract-freestanding: 3408 @mkdir -p $(OUT)/host/gpu-fs 3409 @$(KCC) $(KCFLAGS) -I$(KDIR)/gpu -c -o $(OUT)/host/gpu-fs/gch_contract.o $(GPU_CONTRACT_C) || exit 1; \ 3410 if nm -u $(OUT)/host/gpu-fs/gch_contract.o | grep -v " _GLOBAL_OFFSET_TABLE_$$" | grep -vE " ck_gmem_(alloc|free|quarantine)$$" | grep -q .; then \ 3411 nm -u $(OUT)/host/gpu-fs/gch_contract.o; echo "gpu-contract-freestanding: FAIL"; exit 1; fi; \ 3412 echo "gpu-contract-freestanding: PASS (gch_contract.c with KCC/KCFLAGS, needs only the ck_gmem allocator)" 3413 .PHONY: test-gpu-contract gpu-contract-trace gpu-contract-freestanding 3414 3415 # L332 / L346: the GB10B GSP start-up on BAR0 (gpu/gsp_mmio.c, steps and driver-source lines in gsp_mmio.h) against a 3416 # simulated SEC2 + GSP falcon (gpu/gsp_sim.c). Host only. gsp-mmio-freestanding: gsp_mmio.c with KCC/KCFLAGS, no symbol needed. 3417 GSP_MMIO_SRCS := $(KDIR)/gpu/gsp_mmio.c $(KDIR)/gpu/gsp_sim.c 3418 GSP_MMIO_DEPS := $(KDIR)/tests/test_gsp_mmio.c $(GSP_MMIO_SRCS) $(KDIR)/gpu/gsp_mmio.h $(KDIR)/gpu/gsp_sim.h $(KDIR)/gpu/gmmu.h $(KDIR)/tests/ck_test.h 3419 $(OUT)/host/test_gsp_mmio: $(GSP_MMIO_DEPS) 3420 @mkdir -p $(dir $@) 3421 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(GSP_MMIO_SRCS) 3422 $(OUT)/host-san/test_gsp_mmio: $(GSP_MMIO_DEPS) 3423 @mkdir -p $(dir $@) 3424 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GSP_MMIO_SRCS) 3425 test-gsp-mmio: $(OUT)/host/test_gsp_mmio $(OUT)/host-san/test_gsp_mmio 3426 $(OUT)/host/test_gsp_mmio 3427 $(OUT)/host-san/test_gsp_mmio 3428 gsp-mmio-freestanding: 3429 @mkdir -p $(OUT)/host/gpu-fs 3430 @$(KCC) $(KCFLAGS) -I$(KDIR)/gpu -c -o $(OUT)/host/gpu-fs/gsp_mmio.o $(KDIR)/gpu/gsp_mmio.c || exit 1; \ 3431 if nm -u $(OUT)/host/gpu-fs/gsp_mmio.o | grep -v " _GLOBAL_OFFSET_TABLE_$$" | grep -q .; then \ 3432 nm -u $(OUT)/host/gpu-fs/gsp_mmio.o; echo "gsp-mmio-freestanding: FAIL"; exit 1; fi; \ 3433 echo "gsp-mmio-freestanding: PASS (gsp_mmio.c with KCC/KCFLAGS, no undefined symbol)" 3434 .PHONY: test-gsp-mmio gsp-mmio-freestanding 3435 # The same start-up written from gpu/contract/gb10_gsp.devc (aienos-devc class gpu-boot, branch feat/devc-gpu): 3436 # gen/gsb_contract.c has the gsp_mmio.h API with the contract's own offsets. It must pass test_gsp_mmio and match 3437 # the hand twin access for access in every gsp_boot_trace scenario. 3438 GSP_CONTRACT_C := $(KDIR)/gpu/contract/gen/gsb_contract.c 3439 GSP_TRACE_DEPS := $(KDIR)/tests/gsp_boot_trace.c $(KDIR)/gpu/gsp_sim.c $(KDIR)/gpu/gsp_mmio.h $(KDIR)/gpu/gsp_sim.h $(KDIR)/gpu/gmmu.h 3440 $(OUT)/host/test_gsp_mmio_contract: $(GSP_MMIO_DEPS) $(GSP_CONTRACT_C) 3441 @mkdir -p $(dir $@) 3442 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(GSP_CONTRACT_C) $(KDIR)/gpu/gsp_sim.c 3443 $(OUT)/host-san/test_gsp_mmio_contract: $(GSP_MMIO_DEPS) $(GSP_CONTRACT_C) 3444 @mkdir -p $(dir $@) 3445 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/gpu -o $@ $< $(GSP_CONTRACT_C) $(KDIR)/gpu/gsp_sim.c 3446 $(OUT)/host/gsp_boot_trace_hand: $(GSP_TRACE_DEPS) $(KDIR)/gpu/gsp_mmio.c 3447 @mkdir -p $(dir $@) 3448 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(KDIR)/gpu/gsp_mmio.c $(KDIR)/gpu/gsp_sim.c 3449 $(OUT)/host/gsp_boot_trace_contract: $(GSP_TRACE_DEPS) $(GSP_CONTRACT_C) 3450 @mkdir -p $(dir $@) 3451 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/gpu -o $@ $< $(GSP_CONTRACT_C) $(KDIR)/gpu/gsp_sim.c 3452 test-gsp-contract: $(OUT)/host/test_gsp_mmio_contract $(OUT)/host-san/test_gsp_mmio_contract 3453 $(OUT)/host/test_gsp_mmio_contract 3454 $(OUT)/host-san/test_gsp_mmio_contract 3455 gsp-contract-trace: $(OUT)/host/gsp_boot_trace_hand $(OUT)/host/gsp_boot_trace_contract 3456 @$(OUT)/host/gsp_boot_trace_hand > $(OUT)/host/gsp_boot_trace_hand.txt 3457 @$(OUT)/host/gsp_boot_trace_contract > $(OUT)/host/gsp_boot_trace_contract.txt 3458 @cmp $(OUT)/host/gsp_boot_trace_hand.txt $(OUT)/host/gsp_boot_trace_contract.txt \ 3459 && echo "gsp-contract-trace: PASS ($$(wc -l < $(OUT)/host/gsp_boot_trace_hand.txt) lines identical, hand vs contract)" 3460 gsp-contract-freestanding: 3461 @mkdir -p $(OUT)/host/gpu-fs 3462 @$(KCC) $(KCFLAGS) -I$(KDIR)/gpu -c -o $(OUT)/host/gpu-fs/gsb_contract.o $(GSP_CONTRACT_C) || exit 1; \ 3463 if nm -u $(OUT)/host/gpu-fs/gsb_contract.o | grep -v " _GLOBAL_OFFSET_TABLE_$$" | grep -q .; then \ 3464 nm -u $(OUT)/host/gpu-fs/gsb_contract.o; echo "gsp-contract-freestanding: FAIL"; exit 1; fi; \ 3465 echo "gsp-contract-freestanding: PASS (gsb_contract.c with KCC/KCFLAGS, no undefined symbol)" 3466 .PHONY: test-gsp-contract gsp-contract-trace gsp-contract-freestanding 3467 3468 3469 # AIENOS-PI5 PCIe root complex / RP1 enumerator logic over a fake register file. Not the hardware. 3470 PI5PCIE_SRCS := $(KDIR)/dev/pi5_pcie.c 3471 PI5PCIE_DEPS := $(KDIR)/tests/test_pi5_pcie.c $(PI5PCIE_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/pi5_pcie.h 3472 $(OUT)/host/test_pi5_pcie: $(PI5PCIE_DEPS) 3473 @mkdir -p $(dir $@) 3474 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5PCIE_SRCS) 3475 $(OUT)/host-san/test_pi5_pcie: $(PI5PCIE_DEPS) 3476 @mkdir -p $(dir $@) 3477 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5PCIE_SRCS) 3478 test-pi5-pcie: $(OUT)/host/test_pi5_pcie 3479 $< 3480 # Each mutant removes one decision; the test must FAIL for every one. 3481 PI5PCIE_MUTANTS := NO_OUTSIDE NO_FULLCOVER NO_REMAP NO_INDEX NO_ALIGN NO_MERGE 3482 pi5-pcie-mutants: 3483 @mkdir -p $(OUT)/host 3484 @fail=0; for m in $(PI5PCIE_MUTANTS); do \ 3485 $(HOSTCC) $(HCFLAGS) -DCK_PCIE_MUTANT_$$m -I$(KDIR)/dev -o $(OUT)/host/test_pi5_pcie_mut_$$m $(KDIR)/tests/test_pi5_pcie.c $(PI5PCIE_SRCS) || exit 1; \ 3486 if $(OUT)/host/test_pi5_pcie_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 3487 done; test $$fail -eq 0 3488 .PHONY: test-pi5-pcie pi5-pcie-mutants pi5-pcie 3489 3490 # AIENOS-PI5 network cut 2 (inbound window plan, RP1 quiesce, clocks, PHY reset, MDIO, PHY ID) over fake registers. 3491 PI5NET_SRCS := $(KDIR)/dev/pi5_net.c $(KDIR)/dev/pi5_pcie.c 3492 PI5NET_DEPS := $(KDIR)/tests/test_pi5_net.c $(PI5NET_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/pi5_net.h $(KDIR)/dev/pi5_pcie.h 3493 $(OUT)/host/test_pi5_net: $(PI5NET_DEPS) 3494 @mkdir -p $(dir $@) 3495 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5NET_SRCS) 3496 $(OUT)/host-san/test_pi5_net: $(PI5NET_DEPS) 3497 @mkdir -p $(dir $@) 3498 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5NET_SRCS) 3499 test-pi5-net: $(OUT)/host/test_pi5_net 3500 $< 3501 # Each mutant removes one decision; the test must FAIL for every one. 3502 PI5NET_MUTANTS := NO_STRADDLE NO_REMAP_EN NO_DISABLE_FIRST NO_READBACK NO_RESTORE NO_OTHERS NO_STATUS_MASK NO_QUIESCE_CHECK OB_NO_LIMIT NO_ASSERT NO_HOLD NO_RELEASE NO_HIGH_FIRST NO_IDLE_AFTER NO_MPE TOUCH_ON_CLOCK NO_EXACT_DIV NO_CLK_VERIFY OUI_ORDER BAD_CLASS NO_BOUNDS NO_MDC_DIV PARTIAL_ANY 3503 pi5-net-mutants: 3504 @mkdir -p $(OUT)/host 3505 @fail=0; for m in $(PI5NET_MUTANTS); do \ 3506 $(HOSTCC) $(HCFLAGS) -DCK_NET_MUTANT_$$m -I$(KDIR)/dev -o $(OUT)/host/test_pi5_net_mut_$$m $(KDIR)/tests/test_pi5_net.c $(PI5NET_SRCS) || exit 1; \ 3507 if $(OUT)/host/test_pi5_net_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 3508 done; test $$fail -eq 0 3509 .PHONY: test-pi5-net pi5-net-mutants pi5-net 3510 3511 # AIENOS-PI5 network cut 3 (GEM descriptors, transfer order, bus-master window, PHY loopback) over a fake GEM that checks every DMA it makes. 3512 PI5GEM_SRCS := $(KDIR)/dev/pi5_gem.c $(KDIR)/dev/pi5_net.c $(KDIR)/dev/pi5_pcie.c $(KDIR)/dev/dma_window.c 3513 PI5GEM_DEPS := $(KDIR)/tests/test_pi5_gem.c $(PI5GEM_SRCS) $(KDIR)/tests/ck_test.h $(KDIR)/dev/pi5_gem.h $(KDIR)/dev/pi5_net.h $(KDIR)/dev/pi5_pcie.h $(KDIR)/dev/dma_window.h 3514 $(OUT)/host/test_pi5_gem: $(PI5GEM_DEPS) 3515 @mkdir -p $(dir $@) 3516 $(HOSTCC) $(HCFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5GEM_SRCS) 3517 $(OUT)/host-san/test_pi5_gem: $(PI5GEM_DEPS) 3518 @mkdir -p $(dir $@) 3519 $(HOSTCC) $(HCFLAGS) $(SANFLAGS) -I$(KDIR)/dev -o $@ $< $(PI5GEM_SRCS) 3520 test-pi5-gem: $(OUT)/host/test_pi5_gem 3521 $< 3522 # Each mutant removes one decision; the test must FAIL for every one. 3523 PI5GEM_MUTANTS := NO_VALIDATE BME_EARLY BME_LEFT_ON NO_QUIESCE_WAIT NO_RETE_OFF NO_BARRIER NO_TIEOFF NO_RXLEN_CHECK NO_TX_LAST NO_SENTINEL_USED NO_ADDR64 NO_HWWIN NOT_STICKY NO_FRAMECAP NO_SEQ NO_DIFF MDIO_OP PHYLB_BIT NO_WRAP NO_GBE NO_DRFCS NO_BME_VERIFY NO_LLB_CLEAR 3524 pi5-gem-mutants: 3525 @mkdir -p $(OUT)/host 3526 @fail=0; for m in $(PI5GEM_MUTANTS); do \ 3527 $(HOSTCC) $(HCFLAGS) -DCK_GEM_MUTANT_$$m -I$(KDIR)/dev -o $(OUT)/host/test_pi5_gem_mut_$$m $(KDIR)/tests/test_pi5_gem.c $(PI5GEM_SRCS) || exit 1; \ 3528 if $(OUT)/host/test_pi5_gem_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ 3529 done; test $$fail -eq 0 3530 .PHONY: test-pi5-gem pi5-gem-mutants