aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / stage.mk
| 1 | # stage.mk -- Lane 18 boot stages (devices, security, Store) for the AIENOS |
| 2 | # C kernel. Included by native/kernel/Makefile, or run alone: |
| 3 | # make -C native/kernel -f stage.mk stage-test host tests (libc, pthreads) |
| 4 | # make -C native/kernel -f stage.mk stage-sanitize same under ASan + UBSan |
| 5 | # make -C native/kernel -f stage.mk stage-free freestanding compile + nm -u check |
| 6 | # make -C native/kernel -f stage.mk disk-part-test GPT parser + LBA translation host test |
| 7 | # (dev/tests/disk_part_test.c), built normally (must PASS) and as the |
| 8 | # TEST-ONLY translation-bypass mutant (must FAIL); stage-test and |
| 9 | # stage-sanitize run it too |
| 10 | # Exports for the kernel image build: |
| 11 | # STAGE_SRCS every .c the stages need (own files + unmodified native/*) |
| 12 | # STAGE_CFLAGS include paths and defines; add to the kernel's freestanding CFLAGS |
| 13 | # No Python, no Rust, no outside libraries. |
| 14 | |
| 15 | STAGE_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) |
| 16 | STAGE_NATIVE := $(STAGE_DIR)/.. |
| 17 | # Per-tree default (inside this checkout, under the git-ignored /target/), so two |
| 18 | # clones never share object files. Override with STAGE_OUT=<dir> if needed. |
| 19 | STAGE_OUT ?= $(abspath $(STAGE_DIR)/../../target/stage) |
| 20 | |
| 21 | # Own sources (image). |
| 22 | STAGE_OWN_SRCS := $(STAGE_DIR)/dev/pci.c $(STAGE_DIR)/dev/mmio_window.c $(STAGE_DIR)/dev/disk_part.c $(STAGE_DIR)/dev/nvme_bind.c $(STAGE_DIR)/dev/nvme_shutdown.c $(STAGE_DIR)/dev/virtio_net.c \ |
| 23 | $(STAGE_DIR)/dev/net_bind.c $(STAGE_DIR)/dev/net_udp.c $(STAGE_DIR)/dev/rtl8127_bind.c $(STAGE_DIR)/dev/xhci_fence.c \ |
| 24 | $(STAGE_DIR)/dev/usb_hid.c $(STAGE_DIR)/dev/usb_kbd.c \ |
| 25 | $(STAGE_DIR)/dev/virtio_q.c $(STAGE_DIR)/dev/virtio_bind.c $(STAGE_DIR)/dev/virtio_gpu.c $(STAGE_DIR)/dev/virtio_snd.c \ |
| 26 | $(STAGE_DIR)/ui/boot_show.c $(STAGE_DIR)/ui/allen_ui.c $(STAGE_DIR)/svc/allen_code.c $(STAGE_DIR)/ui/paint.c \ |
| 27 | $(STAGE_DIR)/ui/night.c $(STAGE_DIR)/ui/mind.c $(STAGE_DIR)/ui/allen_font.c $(STAGE_DIR)/ui/chirp.c \ |
| 28 | $(STAGE_DIR)/ui/sky_real.c $(STAGE_DIR)/ui/sky_data.c $(STAGE_DIR)/ui/flow.c $(STAGE_DIR)/ui/canvas.c $(STAGE_DIR)/svc/allen_scene.c \ |
| 29 | $(STAGE_DIR)/dev/devices.c $(STAGE_DIR)/svc/security.c $(STAGE_DIR)/svc/store_boot.c \ |
| 30 | $(STAGE_DIR)/svc/artifact_store.c $(STAGE_DIR)/svc/store_crash.c |
| 31 | # Native modules, compiled unmodified. |
| 32 | STAGE_NATIVE_SRCS := \ |
| 33 | $(STAGE_NATIVE)/disk/disk.c $(STAGE_NATIVE)/disk/disk_nvme.c \ |
| 34 | $(STAGE_NATIVE)/store/store_v1.c $(STAGE_NATIVE)/store/store_engine.c $(STAGE_NATIVE)/store/store_disk.c \ |
| 35 | $(STAGE_NATIVE)/store/store_sealed.c $(STAGE_NATIVE)/store/torn_slot.c \ |
| 36 | $(STAGE_NATIVE)/m5/m5_keys.c $(STAGE_NATIVE)/m5/m5_envelope.c $(STAGE_NATIVE)/m5/m5_state.c \ |
| 37 | $(STAGE_NATIVE)/crypto/aes.c $(STAGE_NATIVE)/crypto/polyval.c $(STAGE_NATIVE)/crypto/gcm_siv.c \ |
| 38 | $(STAGE_NATIVE)/crypto/hmac.c $(STAGE_NATIVE)/crypto/ct.c \ |
| 39 | $(STAGE_NATIVE)/argus/sha256.c $(STAGE_NATIVE)/argus/argus_event.c $(STAGE_NATIVE)/argus/argus_core.c \ |
| 40 | $(STAGE_NATIVE)/argus/argus_detect.c $(STAGE_NATIVE)/argus/argus_contain.c \ |
| 41 | $(STAGE_NATIVE)/argus/bridge/argus_aegis_bridge.c \ |
| 42 | $(STAGE_NATIVE)/capability/aienos_capability.c $(STAGE_NATIVE)/capability/aienos_contain.c \ |
| 43 | $(STAGE_NATIVE)/net/aienos_virtio_pci.c $(STAGE_NATIVE)/net/aienos_virtio_net.c $(STAGE_NATIVE)/net/aienos_net.c \ |
| 44 | $(STAGE_NATIVE)/net/aienos_rtl8127.c $(STAGE_NATIVE)/net/aienos_report.c |
| 45 | # Kernel-only glue: hosted-header stand-ins for capability/ARGUS + weak mem*. |
| 46 | STAGE_KERNEL_SRCS := $(STAGE_DIR)/svc/ck_compat.c |
| 47 | |
| 48 | STAGE_SRCS := $(STAGE_OWN_SRCS) $(STAGE_NATIVE_SRCS) $(STAGE_KERNEL_SRCS) |
| 49 | # P06 cut 3: the canonical Omega Cortex store (third_party/omega, pinned by |
| 50 | # omega.lock) over the sealed Store. Linked into the CK_SERVICE image by the |
| 51 | # kernel Makefile; compiled freestanding here so stage-free proves the link. |
| 52 | STAGE_CORTEX_SRCS := $(STAGE_DIR)/svc/cortex_store.c $(STAGE_DIR)/svc/cortex_journal.c |
| 53 | # audio.output slice 1 (issue #85): USB Audio Class output pure logic. Not |
| 54 | # linked into any image yet (no xHCI isochronous endpoint); compiled |
| 55 | # freestanding here and host tested by usb-audio-test. |
| 56 | STAGE_AUDIO_SRCS := $(STAGE_DIR)/dev/usb_audio.c |
| 57 | STAGE_FREE_SRCS := $(STAGE_SRCS) $(STAGE_CORTEX_SRCS) $(STAGE_AUDIO_SRCS) |
| 58 | |
| 59 | STAGE_INC := -I$(STAGE_DIR)/include -I$(STAGE_DIR)/dev -I$(STAGE_DIR)/svc \ |
| 60 | -I$(STAGE_NATIVE)/disk -I$(STAGE_NATIVE)/store -I$(STAGE_NATIVE)/m5 -I$(STAGE_NATIVE)/crypto \ |
| 61 | -I$(STAGE_NATIVE)/argus -I$(STAGE_NATIVE)/capability -I$(STAGE_NATIVE)/net |
| 62 | # compat first: <pthread.h> <stdlib.h> <stdio.h> <time.h> resolve to the stand-ins. |
| 63 | # NVMe DMA: SMMU-confined (ck_dma_confine) or refused. The kernel Makefile |
| 64 | # adds -DCK_QEMU_UNSAFE_DMA=1 only for "make full CK_QEMU_UNSAFE_DMA=1" (TEST-ONLY, |
| 65 | # one boot of the QEMU store gate); dev/nvme_bind.c refuses it together with CK_HARDWARE_STAGING. |
| 66 | STAGE_CFLAGS := -I$(STAGE_DIR)/svc/compat $(STAGE_INC) |
| 67 | |
| 68 | # ---- freestanding check -------------------------------------------------- |
| 69 | STAGE_CC ?= cc |
| 70 | STAGE_LD ?= ld |
| 71 | STAGE_NM ?= nm |
| 72 | STAGE_FREE_FLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin \ |
| 73 | -fno-stack-protector -fno-tree-loop-distribute-patterns -mgeneral-regs-only -mno-outline-atomics \ |
| 74 | -fno-pic -fno-pie -fstack-usage -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 |
| 75 | # The only undefined symbols the stages may leave for the core: ck.h services. |
| 76 | STAGE_ALLOWED_U := ck_puts ck_printf ck_vprintf ck_panic ck_alloc ck_free ck_dma_alloc ck_mmio_map \ |
| 77 | ck_dma_confine ck_dma_unconfine ck_dma_faults \ |
| 78 | ck_mb ck_acpi_find ck_time_us ck_udelay ck_commit ck_exception_level ck_conventional_memory_kb \ |
| 79 | ck_acpi_platform_devices ck_dma_confine_named ck_mmio_try_map ck_mmio_map_exclusive ck_mmio_unmap_exclusive ck_mmio_is_mapped \ |
| 80 | ck_cap_init ck_cap_insert ck_cap_lookup ck_cap_revoke \ |
| 81 | ck_entropy_fill ck_entropy_status ck_entropy_reason \ |
| 82 | ck_console_rx_ready ck_console_rx_poll ck_console_uart_name ck_console_uart_base |
| 83 | |
| 84 | STAGE_FREE_OBJS := $(foreach s,$(STAGE_FREE_SRCS),$(STAGE_OUT)/free/$(subst /,_,$(subst $(STAGE_NATIVE)/,,$(s:.c=.o)))) |
| 85 | |
| 86 | define stage_free_rule |
| 87 | $(STAGE_OUT)/free/$(subst /,_,$(subst $(STAGE_NATIVE)/,,$(1:.c=.o))): $(1) |
| 88 | @mkdir -p $$(@D) |
| 89 | $$(STAGE_CC) $$(STAGE_FREE_FLAGS) $$(STAGE_CFLAGS) -c -o $$@ $$< |
| 90 | endef |
| 91 | $(foreach s,$(STAGE_FREE_SRCS),$(eval $(call stage_free_rule,$(s)))) |
| 92 | |
| 93 | $(STAGE_OUT)/stage_all.o: $(STAGE_FREE_OBJS) |
| 94 | $(STAGE_LD) -r -o $@ $^ |
| 95 | |
| 96 | .PHONY: stage-free stage-test stage-sanitize stage-clean disk-part-test disk-part-sanitize |
| 97 | stage-free: $(STAGE_OUT)/stage_all.o |
| 98 | @bad=$$($(STAGE_NM) -u $< | awk '{print $$2}' | grep -vxF $(foreach a,$(STAGE_ALLOWED_U),-e $(a)) || true); \ |
| 99 | if [ -n "$$bad" ]; then echo "CK_STAGE_FREE: FAIL undefined: $$bad"; exit 1; fi; \ |
| 100 | echo "undefined (ck.h services only): $$($(STAGE_NM) -u $< | awk '{print $$2}' | tr '\n' ' ')"; \ |
| 101 | echo "weak symbols defined here: $$($(STAGE_NM) $< | awk '$$2=="W"{print $$3}' | tr '\n' ' ')"; \ |
| 102 | echo "largest stack frames: $$(cat $(STAGE_OUT)/free/*.su | sort -t' ' -k2 -n -r | head -3 | awk -F' ' '{printf "%s=%s ", $$1, $$2}')"; \ |
| 103 | echo "CK_STAGE_FREE: PASS objects=$(words $(STAGE_FREE_OBJS))" |
| 104 | |
| 105 | # ---- host tests ---------------------------------------------------------- |
| 106 | # P05: the production continuity layer (svc/continuity_service.c) is tested here |
| 107 | # with CK_CONT_SERVICE_HOST_TEST (the image links it only under CK_SERVICE=1). |
| 108 | STAGE_CONT_SRCS := $(STAGE_DIR)/svc/continuity_codec.c $(STAGE_DIR)/svc/continuity_resolve.c \ |
| 109 | $(STAGE_DIR)/svc/continuity_resolve_sealed.c $(STAGE_DIR)/svc/continuity_commit.c \ |
| 110 | $(STAGE_DIR)/svc/continuity_subject.c $(STAGE_DIR)/svc/continuity_subject_provision.c $(STAGE_DIR)/svc/continuity_service.c \ |
| 111 | $(STAGE_DIR)/core/entropy.c $(STAGE_DIR)/core/fmt.c |
| 112 | STAGE_HOST_SRCS := $(STAGE_OWN_SRCS) $(STAGE_DIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(STAGE_NATIVE)/disk/disk_file.c \ |
| 113 | $(STAGE_CONT_SRCS) $(STAGE_CORTEX_SRCS) $(STAGE_DIR)/svc/tests/ck_host.c $(STAGE_DIR)/svc/tests/stage_test.c |
| 114 | STAGE_HOST_FLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -pthread -DCK_ART_STORE_WRITER -DCK_HOST_TEST \ |
| 115 | -DCK_CONT_SERVICE_HOST_TEST -I$(STAGE_DIR)/core |
| 116 | STAGE_SAN_FLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer |
| 117 | |
| 118 | $(STAGE_OUT)/stage_test: $(STAGE_HOST_SRCS) $(wildcard $(STAGE_DIR)/dev/*.h $(STAGE_DIR)/svc/*.h $(STAGE_DIR)/include/*.h) |
| 119 | @mkdir -p $(@D) |
| 120 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_INC) -o $@ $(STAGE_HOST_SRCS) |
| 121 | |
| 122 | $(STAGE_OUT)/stage_test_san: $(STAGE_HOST_SRCS) $(wildcard $(STAGE_DIR)/dev/*.h $(STAGE_DIR)/svc/*.h $(STAGE_DIR)/include/*.h) |
| 123 | @mkdir -p $(@D) |
| 124 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(STAGE_INC) -o $@ $(STAGE_HOST_SRCS) |
| 125 | |
| 126 | stage-test: $(STAGE_OUT)/stage_test |
| 127 | $< |
| 128 | |
| 129 | stage-sanitize: $(STAGE_OUT)/stage_test_san |
| 130 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 131 | |
| 132 | stage-clean: |
| 133 | rm -rf $(STAGE_OUT) |
| 134 | |
| 135 | # ---- GPT parser / translation layer host test (dev/tests/disk_part_test.c) ---- |
| 136 | # Linked with the same stage sources as stage_test (a whole Store boot runs on |
| 137 | # the partition view) plus the hosted GPT writer tools/gpt_write.c. The mutant |
| 138 | # is the same test built with -DCK_TEST_DISK_XLATE_BYPASS (translation layer |
| 139 | # adds no partition offset): it must FAIL, so the checks are shown to catch a |
| 140 | # bypass. |
| 141 | DISK_PART_TEST_SRCS := $(STAGE_OWN_SRCS) $(STAGE_DIR)/core/ipc.c $(STAGE_NATIVE_SRCS) $(STAGE_NATIVE)/disk/disk_file.c \ |
| 142 | $(STAGE_DIR)/svc/tests/ck_host.c $(STAGE_DIR)/tools/gpt_write.c $(STAGE_DIR)/dev/tests/disk_part_test.c |
| 143 | DISK_PART_TEST_DEPS := $(DISK_PART_TEST_SRCS) $(wildcard $(STAGE_DIR)/dev/*.h $(STAGE_DIR)/svc/*.h \ |
| 144 | $(STAGE_DIR)/include/*.h $(STAGE_DIR)/tools/*.h) |
| 145 | DISK_PART_INC := $(STAGE_INC) -I$(STAGE_DIR)/tools -I$(STAGE_DIR)/svc/tests |
| 146 | |
| 147 | $(STAGE_OUT)/disk_part_test: $(DISK_PART_TEST_DEPS) |
| 148 | @mkdir -p $(@D) |
| 149 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(DISK_PART_INC) -o $@ $(DISK_PART_TEST_SRCS) |
| 150 | $(STAGE_OUT)/disk_part_test_mutant: $(DISK_PART_TEST_DEPS) |
| 151 | @mkdir -p $(@D) |
| 152 | $(STAGE_CC) $(STAGE_HOST_FLAGS) -DCK_TEST_DISK_XLATE_BYPASS=1 $(DISK_PART_INC) -o $@ $(DISK_PART_TEST_SRCS) |
| 153 | $(STAGE_OUT)/disk_part_test_san: $(DISK_PART_TEST_DEPS) |
| 154 | @mkdir -p $(@D) |
| 155 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(DISK_PART_INC) -o $@ $(DISK_PART_TEST_SRCS) |
| 156 | |
| 157 | disk-part-test: $(STAGE_OUT)/disk_part_test $(STAGE_OUT)/disk_part_test_mutant |
| 158 | $(STAGE_OUT)/disk_part_test |
| 159 | @if $(STAGE_OUT)/disk_part_test_mutant >$(STAGE_OUT)/disk_part_test_mutant.log 2>&1; then \ |
| 160 | echo "CK_DISK_PART_MUTANT: FAIL (translation bypass mutant passed the host checks)"; exit 1; fi; \ |
| 161 | n=$$(grep -c "^ FAIL " $(STAGE_OUT)/disk_part_test_mutant.log || true); \ |
| 162 | if [ "$$n" -lt 1 ]; then echo "CK_DISK_PART_MUTANT: FAIL (mutant exited non-zero without a failing check: crash?)"; exit 1; fi; \ |
| 163 | echo "CK_DISK_PART_MUTANT: PASS (translation bypass mutant caught by $$n failing checks)" |
| 164 | |
| 165 | disk-part-sanitize: $(STAGE_OUT)/disk_part_test_san |
| 166 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 167 | |
| 168 | stage-test: disk-part-test |
| 169 | stage-sanitize: disk-part-sanitize |
| 170 | |
| 171 | # ---- audio.output pure logic host test (dev/tests/usb_audio_test.c, issue #85) ---- |
| 172 | USB_AUDIO_TEST_SRCS := $(STAGE_AUDIO_SRCS) $(STAGE_DIR)/dev/tests/usb_audio_test.c |
| 173 | USB_AUDIO_TEST_DEPS := $(USB_AUDIO_TEST_SRCS) $(STAGE_DIR)/dev/usb_audio.h |
| 174 | $(STAGE_OUT)/usb_audio_test: $(USB_AUDIO_TEST_DEPS) |
| 175 | @mkdir -p $(@D) |
| 176 | $(STAGE_CC) $(STAGE_HOST_FLAGS) -I$(STAGE_DIR)/dev -o $@ $(USB_AUDIO_TEST_SRCS) |
| 177 | $(STAGE_OUT)/usb_audio_test_san: $(USB_AUDIO_TEST_DEPS) |
| 178 | @mkdir -p $(@D) |
| 179 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) -I$(STAGE_DIR)/dev -o $@ $(USB_AUDIO_TEST_SRCS) |
| 180 | |
| 181 | .PHONY: usb-audio-test usb-audio-sanitize |
| 182 | usb-audio-test: $(STAGE_OUT)/usb_audio_test |
| 183 | $< |
| 184 | usb-audio-sanitize: $(STAGE_OUT)/usb_audio_test_san |
| 185 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 186 | |
| 187 | stage-test: usb-audio-test |
| 188 | stage-sanitize: usb-audio-sanitize |
| 189 | |
| 190 | # ---- AIENOS-PI5 step 3b: sealed Store over the Pi card layout (dev/tests/pi5_store_test.c) ---- |
| 191 | # Same sources as disk_part_test; the image build of this stage is "make pi5-store". |
| 192 | PI5_STORE_TEST_SRCS := $(filter-out %/disk_part_test.c,$(DISK_PART_TEST_SRCS)) $(STAGE_DIR)/core/pi5_marker.c $(STAGE_DIR)/dev/tests/pi5_store_test.c |
| 193 | $(STAGE_OUT)/pi5_store_test: $(PI5_STORE_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.c $(STAGE_DIR)/core/pi5_marker.h $(STAGE_DIR)/dev/tests/pi5_store_test.c |
| 194 | @mkdir -p $(@D) |
| 195 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_STORE_TEST_SRCS) |
| 196 | $(STAGE_OUT)/pi5_store_test_san: $(PI5_STORE_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.c $(STAGE_DIR)/core/pi5_marker.h $(STAGE_DIR)/dev/tests/pi5_store_test.c |
| 197 | @mkdir -p $(@D) |
| 198 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_STORE_TEST_SRCS) |
| 199 | .PHONY: pi5-store-test pi5-store-sanitize |
| 200 | pi5-store-test: $(STAGE_OUT)/pi5_store_test |
| 201 | $< |
| 202 | pi5-store-sanitize: $(STAGE_OUT)/pi5_store_test_san |
| 203 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 204 | stage-test: pi5-store-test |
| 205 | stage-sanitize: pi5-store-sanitize |
| 206 | |
| 207 | # ---- AIENOS PI5-4 cut 1: the Pi unlock image's Store policy (dev/tests/pi5_unlock_test.c) ---- |
| 208 | # store_boot.c is compiled with -DCK_PI5_UNLOCK, as "make pi5-unlock" builds it: no TEST keys, no TEST uuid. |
| 209 | PI5_UNLOCK_TEST_SRCS := $(filter-out %/disk_part_test.c,$(DISK_PART_TEST_SRCS)) $(STAGE_CONT_SRCS) $(STAGE_DIR)/core/pi5_marker.c $(STAGE_DIR)/core/unlock_req.c $(STAGE_DIR)/dev/tests/pi5_unlock_test.c $(STAGE_DIR)/tools/pi5_store_locate.c |
| 210 | $(STAGE_OUT)/pi5_unlock_test: $(PI5_UNLOCK_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.h |
| 211 | @mkdir -p $(@D) |
| 212 | $(STAGE_CC) $(STAGE_HOST_FLAGS) -DCK_PI5_UNLOCK=1 $(DISK_PART_INC) -o $@ $(PI5_UNLOCK_TEST_SRCS) |
| 213 | $(STAGE_OUT)/pi5_unlock_test_san: $(PI5_UNLOCK_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/pi5_marker.h |
| 214 | @mkdir -p $(@D) |
| 215 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) -DCK_PI5_UNLOCK=1 $(DISK_PART_INC) -o $@ $(PI5_UNLOCK_TEST_SRCS) |
| 216 | .PHONY: pi5-unlock-test pi5-unlock-sanitize |
| 217 | pi5-unlock-test: $(STAGE_OUT)/pi5_unlock_test |
| 218 | $< |
| 219 | pi5-unlock-sanitize: $(STAGE_OUT)/pi5_unlock_test_san |
| 220 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 221 | stage-test: pi5-unlock-test |
| 222 | stage-sanitize: pi5-unlock-sanitize |
| 223 | |
| 224 | # ---- AIENOS PI5-4 cut 4: host locator for the KeySlotManifest on a copy of the Pi card's AIENOS partition ---- |
| 225 | # tools/pi5_store_locate.c (used by the tamper run and by its rehearsal in pi5_unlock_test) and the CLI around it. |
| 226 | PI5_LOCATE_TOOL_SRCS := $(filter-out %/pi5_unlock_test.c,$(PI5_UNLOCK_TEST_SRCS)) |
| 227 | $(STAGE_OUT)/ck_pi5_store_locate: $(PI5_LOCATE_TOOL_SRCS) $(STAGE_DIR)/tools/ck_pi5_store_locate.c $(STAGE_DIR)/tools/pi5_store_locate.h $(DISK_PART_TEST_DEPS) |
| 228 | @mkdir -p $(@D) |
| 229 | $(STAGE_CC) $(STAGE_HOST_FLAGS) -DCK_PI5_UNLOCK=1 $(DISK_PART_INC) -o $@ $(PI5_LOCATE_TOOL_SRCS) $(STAGE_DIR)/tools/ck_pi5_store_locate.c |
| 230 | .PHONY: pi5-store-locate |
| 231 | pi5-store-locate: $(STAGE_OUT)/ck_pi5_store_locate |
| 232 | |
| 233 | # ---- AIENOS PI5-5: the Pi Cortex fact stage (dev/tests/pi5_fact_test.c) ---- |
| 234 | # store_boot.c is compiled with -DCK_PI5_UNLOCK -DCK_PI5_UNLOCK_CARD -DCK_PI5_FACT, as "make pi5-fact" builds it. |
| 235 | PI5_FACT_TEST_SRCS := $(filter-out %/pi5_unlock_test.c,$(PI5_UNLOCK_TEST_SRCS)) $(STAGE_CORTEX_SRCS) $(STAGE_DIR)/svc/pi5_fact.c $(STAGE_DIR)/core/fact_req.c $(STAGE_DIR)/dev/tests/pi5_fact_test.c |
| 236 | PI5_FACT_DEPS := $(PI5_FACT_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/fact_req.h $(STAGE_DIR)/svc/pi5_fact.h |
| 237 | PI5_FACT_FLAGS := -DCK_PI5_UNLOCK=1 -DCK_PI5_UNLOCK_CARD=1 -DCK_PI5_FACT=1 |
| 238 | $(STAGE_OUT)/pi5_fact_test: $(PI5_FACT_DEPS) |
| 239 | @mkdir -p $(@D) |
| 240 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(PI5_FACT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_FACT_TEST_SRCS) |
| 241 | $(STAGE_OUT)/pi5_fact_test_san: $(PI5_FACT_DEPS) |
| 242 | @mkdir -p $(@D) |
| 243 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(PI5_FACT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_FACT_TEST_SRCS) |
| 244 | .PHONY: pi5-fact-test pi5-fact-sanitize pi5-fact-mutants |
| 245 | pi5-fact-test: $(STAGE_OUT)/pi5_fact_test |
| 246 | $< |
| 247 | pi5-fact-sanitize: $(STAGE_OUT)/pi5_fact_test_san |
| 248 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 249 | # Mutation proof: each TEST-ONLY mutant of the fact stage must make the host test FAIL. |
| 250 | pi5-fact-mutants: |
| 251 | @mkdir -p $(STAGE_OUT); fail=0; \ |
| 252 | for m in NO_APPEND RECALL_BLIND; do \ |
| 253 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(PI5_FACT_FLAGS) -DCK_FACT_MUTANT_$$m=1 $(DISK_PART_INC) -o $(STAGE_OUT)/pi5_fact_test_mut_$$m $(PI5_FACT_TEST_SRCS) || exit 1; \ |
| 254 | if $(STAGE_OUT)/pi5_fact_test_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ |
| 255 | done; exit $$fail |
| 256 | stage-test: pi5-fact-test |
| 257 | stage-sanitize: pi5-fact-sanitize |
| 258 | |
| 259 | # ---- AIENOS PI5-6 final cut: the Pi agent stage (dev/tests/pi5_agent_test.c) ---- |
| 260 | # store_boot.c is compiled with -DCK_PI5_UNLOCK -DCK_PI5_UNLOCK_CARD -DCK_PI5_AGENT, as "make pi5-agent" builds it. The inference unit |
| 261 | # is a stub in the test (a 770 MiB model cannot run on the host); the stage's policy is the real svc/pi5_agent.c. |
| 262 | PI5_AGENT_TEST_SRCS := $(filter-out %/pi5_unlock_test.c,$(PI5_UNLOCK_TEST_SRCS)) $(STAGE_DIR)/svc/pi5_agent.c $(STAGE_DIR)/dev/tests/pi5_agent_test.c |
| 263 | PI5_AGENT_DEPS := $(PI5_AGENT_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/svc/pi5_agent.h $(STAGE_DIR)/core/reply_obj.h |
| 264 | PI5_AGENT_FLAGS := -DCK_PI5_UNLOCK=1 -DCK_PI5_UNLOCK_CARD=1 -DCK_PI5_AGENT=1 |
| 265 | $(STAGE_OUT)/pi5_agent_test: $(PI5_AGENT_DEPS) |
| 266 | @mkdir -p $(@D) |
| 267 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(PI5_AGENT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_AGENT_TEST_SRCS) |
| 268 | $(STAGE_OUT)/pi5_agent_test_san: $(PI5_AGENT_DEPS) |
| 269 | @mkdir -p $(@D) |
| 270 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(PI5_AGENT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_AGENT_TEST_SRCS) |
| 271 | .PHONY: pi5-agent-test pi5-agent-sanitize pi5-agent-mutants |
| 272 | pi5-agent-test: $(STAGE_OUT)/pi5_agent_test |
| 273 | $< |
| 274 | pi5-agent-sanitize: $(STAGE_OUT)/pi5_agent_test_san |
| 275 | ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< |
| 276 | # Mutation proof: each TEST-ONLY mutant of the agent stage must make the host test FAIL. |
| 277 | pi5-agent-mutants: |
| 278 | @mkdir -p $(STAGE_OUT); fail=0; \ |
| 279 | for m in NO_COMMIT RECOVER_BLIND NO_GOLDEN_CHECK NO_PROMPT_CHECK RECOVER_NO_CHECK MODEL_FIRST; do \ |
| 280 | $(STAGE_CC) $(STAGE_HOST_FLAGS) $(PI5_AGENT_FLAGS) -DCK_AGENT_MUTANT_$$m=1 $(DISK_PART_INC) -o $(STAGE_OUT)/pi5_agent_test_mut_$$m $(PI5_AGENT_TEST_SRCS) || exit 1; \ |
| 281 | if $(STAGE_OUT)/pi5_agent_test_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ |
| 282 | done; exit $$fail |
| 283 | stage-test: pi5-agent-test |
| 284 | stage-sanitize: pi5-agent-sanitize |