aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#370 (code only)
Apply it
git checkout -b patch-60895d2e988af8ab 0fab4bc808ee4d945476da2007cd444f7f07cf96 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/60895d2e988af8ab.patch | git am
Provenance
github-import 1
aien-dev/aienux
370
ff2fde91810506c60b99bdb8c94b87efcb534ae1
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":370,"url":"https://github.com/aien-dev/aienux/pull/370","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:17Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 967df9ce..9e508ae4 100644 --- a/.crumb +++ b/.crumb @@ -28,32 +28,32 @@ }, { "digest": "25020cdb700e0f5b821988ff7a3c5a7e5bd9e9019ae4d26a79ce1367e4ebfce1", - "last_commit": "e7c361a", + "last_commit": "0fab4bc", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "a0bcd4afd87949d9d7bb92fefb489693d9035ee01fcd22cf418b630eb4127e28", - "last_commit": "5b0b9da", + "digest": "aaf01af1c67ace2137a6c3343225682262b3208d7b98dedac1410bc18e642c36", + "last_commit": "53de55c", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "17ca56cca1e53f3d5ef7813006097037d3e3bbf8b4882fc907ea6c6979756d08", - "last_commit": "5b0b9da", + "digest": "95951d5a52b7ade0f66bb972e92ebfd3fb14433557f1ee827bef14d6481a17a7", + "last_commit": "53de55c", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:46a1dd17cc083812966f373720f2fcba99c5a2186b6caa85d9e3e40d80dc94fa", - "compiled_at": "2026-10-13T22:05:34Z", + "children_root": "sha256:481462d0ba8e29d9f1456b9d42606f404e3c505e9c32e02ea072962e8bbb0d6b", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:7056633ab259accedf28870417868bba98e3d2f3172c5e2fee5e7754e44fc4dd", + "digest": "sha256:59de48de86c5964b2d8db84d8be0df96f5de3547d6dd74f81d46d5860d0257ba", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3192, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:d1d8f50283fa1e97f75a3267b0c82eb6d06268847eab7f838e993c0e052ac832" + "files": 3197, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:3510409465a633f52564105bf22f73acb73ac5ce9098a449d254275dcd1eacab" }, "owner_lane": "", "provenance": { diff --git a/native/.crumb b/native/.crumb index 58963cbe..93da5c03 100644 --- a/native/.crumb +++ b/native/.crumb @@ -55,8 +55,8 @@ "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "929ed085c32fffd1530eb09cec90c2554c7bf0bb02ad70db53cf8cd94761e5f4", - "last_commit": "6f35eab", + "digest": "441bb7a06c78208da659e10e8ff3c50998f4aac3fe8446bcc6259521d040b466", + "last_commit": "53de55c", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, @@ -79,8 +79,8 @@ "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "dad7c2c41e5b3ee793d9dd4cb57644b09e9987269506b04ea01352bc83ea2cbf", - "last_commit": "5b0b9da", + "digest": "e105bc4fbeb01dd053f104b85e784ba7f62cd52bd5574bcbd50bc3ddc150cf01", + "last_commit": "53de55c", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, @@ -109,15 +109,15 @@ "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:17931a0ea027fb5fdd5992c3ff9e9c5a394907c8e5915699c060acca3480ff4a", - "compiled_at": "2026-10-13T22:05:34Z", + "children_root": "sha256:99e5fdfd7c1323ebb984593edfe0c9683d3cf7a79192c1d0f95acb6c25558886", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:a0bcd4afd87949d9d7bb92fefb489693d9035ee01fcd22cf418b630eb4127e28", + "digest": "sha256:aaf01af1c67ace2137a6c3343225682262b3208d7b98dedac1410bc18e642c36", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 548, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:d04fb5884b942ca9fc7a24fc96a808fadd7a4a2becb1308f90accea48202a64b" + "files": 553, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:7f21c1caa14ee51248375281b89ed8737eb398d28e758a0c66cd170013837d8a" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index cf514536..2fc1939f 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T17:02:53Z", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:929ed085c32fffd1530eb09cec90c2554c7bf0bb02ad70db53cf8cd94761e5f4", + "digest": "sha256:441bb7a06c78208da659e10e8ff3c50998f4aac3fe8446bcc6259521d040b466", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 20, - "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", - "source_tree": "sha256:d18adafbac793081e6007ae51c691e57290353b4d1ef0866d2fc5e15001b3638" + "files": 21, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:db3871c89065883142387967d20b51a113fbc23931d452e7c860a15669d672e3" }, "owner_lane": "", "provenance": { diff --git a/native/boot/efi_agentcmd.c b/native/boot/efi_agentcmd.c new file mode 100644 index 00000000..0616e467 --- /dev/null +++ b/native/boot/efi_agentcmd.c @@ -0,0 +1,64 @@ +/* efi_agentcmd.c -- read \EFI\AIENOS\AGENT.CMD from the boot volume before ExitBootServices + * (Raspberry Pi 5 resident-lifecycle qualification image, CK_PI5_LIFECYCLE). Nothing is written. The file + * holds a short list of lifecycle verbs placed by the run tool (native/kernel/core/agent_cmd.h). Result in + * ck_agent_cmd_boot (stub and kernel are one image): ABSENT (no file: the lifecycle just stops), REFUSED + * (printed why), FOUND. */ +#include "efi.h" +#include "../kernel/core/agent_cmd.h" +#include "../kernel/arch/arch.h" +#include "../kernel/core/ck_internal.h" + +static uint8_t buf[CK_AGENT_CMD_FILE_MAX + 1u] __attribute__((aligned(64))); + +static void wipe_buf(void) +{ + volatile uint8_t *b = buf; + for (unsigned i = 0; i < sizeof buf; i++) + b[i] = 0; +} + +void ck_boot_agent_cmd_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) +{ + static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT; + static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT; + static CHAR16 path[] = {'\\', 'E', 'F', 'I', '\\', 'A', 'I', 'E', 'N', 'O', 'S', '\\', + 'A', 'G', 'E', 'N', 'T', '.', 'C', 'M', 'D', 0}; + EFI_BOOT_SERVICES *bs = st->BootServices; + EFI_LOADED_IMAGE_PROTOCOL *li = 0; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0; + EFI_FILE_PROTOCOL *root = 0, *f = 0; + ck_agent_cmd_boot.state = CK_AGENT_CMD_ABSENT; + if (bs->HandleProtocol(image, &li_guid, (void **)&li) != EFI_SUCCESS || !li || !li->DeviceHandle || + bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs) != EFI_SUCCESS || !fs || + fs->OpenVolume(fs, &root) != EFI_SUCCESS || !root) { + ck_puts("agent_cmd: absent (boot volume not readable); no command script this boot\n"); + return; + } + if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) { + root->Close(root); + ck_puts("agent_cmd: absent (no " CK_AGENT_CMD_PATH "); no command script this boot\n"); + return; + } + wipe_buf(); + uint64_t n = sizeof buf; /* one byte more than the format allows: a longer file is refused */ + EFI_STATUS s = f->Read(f, &n, buf); + f->Close(f); + root->Close(root); + ck_agent_cmd_boot.state = CK_AGENT_CMD_REFUSED; + if (s != EFI_SUCCESS || n < 1 || n > CK_AGENT_CMD_FILE_MAX) { + ck_printf("agent_cmd: refused (read status=0x%llx bytes=%llu, want 1..%u)\n", (unsigned long long)s, + (unsigned long long)n, (unsigned)CK_AGENT_CMD_FILE_MAX); + wipe_buf(); + return; + } + const char *why = 0; + if (ck_agent_cmd_parse(buf, (size_t)n, &ck_agent_cmd_boot.cmd, &why)) { + ck_printf("agent_cmd: refused (%s)\n", why ? why : "malformed"); + wipe_buf(); + return; + } + ck_agent_cmd_boot.state = CK_AGENT_CMD_FOUND; + ck_printf("agent_cmd: found a well-formed command script (QUALIFICATION ONLY, %u lines)\n", + (unsigned)ck_agent_cmd_boot.cmd.nlines); + wipe_buf(); +} diff --git a/native/boot/efi_main.c b/native/boot/efi_main.c index 3279f043..ebc2c446 100644 --- a/native/boot/efi_main.c +++ b/native/boot/efi_main.c @@ -44,6 +44,9 @@ void ck_boot_unlock_req_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #ifdef CK_PI5_FACT void ck_boot_fact_req_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #endif +#ifdef CK_PI5_LIFECYCLE +void ck_boot_agent_cmd_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); +#endif #ifdef CK_KLOG void ck_boot_klog_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #endif @@ -147,6 +150,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) #ifdef CK_PI5_FACT /* PI5-5 qualification image: the one-fact request file (efi_fact.c). */ ck_boot_fact_req_find(image, st); +#endif +#ifdef CK_PI5_LIFECYCLE + /* PI5-7 cut 2 qualification image: the lifecycle command script (efi_agentcmd.c). */ + ck_boot_agent_cmd_find(image, st); #endif ck_puts("kernel_impl: c (native/kernel, Lane 18)\n"); vendor_print(st->FirmwareVendor); diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 44fc774b..ec804c9b 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,14 +57,14 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "957bfad5ac7bb52cc3447b4520f3b029c421a8891b90b5c00dad842339294575", - "last_commit": "5b0b9da", + "digest": "4838185961eedd4d2053c8d8a6804065d1f8f450461ce74a819d5f7d4d8988f1", + "last_commit": "53de55c", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "9302f530853614d0541c387ba09fca4364bc195eef335a24bbe205dfd69f1ecd", - "last_commit": "5b0b9da", + "last_commit": "0fab4bc", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -81,14 +81,14 @@ "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "ef2c5b80defe4f152278954ff8a5b256a1898dd0f77d8220c5fbe6637e99bed0", - "last_commit": "0735543", + "digest": "2a98333d826d94a7131119aaeb5a15d8bc543baa5531fa930e6f0afc1fccb83d", + "last_commit": "53de55c", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "17f3ab5f5e8314d29db1d2ee908a01848745520cc61b8de1d95982f6657e065c", - "last_commit": "5b0b9da", + "digest": "b6bc9b845fa67108c0bdac73dc640d2a634f8606e833703096f3746df1c23257", + "last_commit": "53de55c", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, @@ -99,15 +99,15 @@ "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:f9f3a89da6f80d7778e39ff641df570c22ffaafa59862543d2bd5ad934617de3", - "compiled_at": "2026-10-13T22:05:34Z", + "children_root": "sha256:5b2f348bd7f112ca485a960f4de36a0ff131efa37d62877f42853fe129d31473", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:dad7c2c41e5b3ee793d9dd4cb57644b09e9987269506b04ea01352bc83ea2cbf", + "digest": "sha256:e105bc4fbeb01dd053f104b85e784ba7f62cd52bd5574bcbd50bc3ddc150cf01", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 369, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:ec50a94fd5ad0afc6e61b8553c4cfff7a9cc62480b509322a50c1ab74c83b518" + "files": 373, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:47a343bea2cb8478dbdbc4e04cd67c4665daba3acb8e12998148f3db92c45197" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 0f1ad8e9..2ff6a7f4 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -235,7 +235,7 @@ ifneq ($(strip $(CK_SERVICE)$(CK_TEST_STORE_CRASH)$(CK_TEST_CONTINUITY)$(CK_HARD $(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) endif CK_PI5 := 1 -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) +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) CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK=1 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK_CARD=1 @@ -255,8 +255,8 @@ endif ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) $(error CK_PI5_FACT (Cortex fact stage, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) endif -ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_AGENT)),) -$(error CK_PI5_FACT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET or CK_PI5_AGENT) +ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_AGENT)$(CK_PI5_LIFECYCLE)),) +$(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) endif CK_EXTRA_CFLAGS += -DCK_PI5_FACT=1 endif @@ -274,14 +274,39 @@ endif ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) $(error CK_PI5_AGENT (Store plus inference, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) endif -ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_INFER)$(CK_PI5_PCIE)$(CK_PI5_NET)$(CK_PI5_FACT)$(CK_SERVICE)$(CK_HARDWARE_STAGING)$(CK_TEST_FWCFG_ARTIFACTS)),) -$(error CK_PI5_AGENT cannot be combined with CK_PI5_STORE, CK_PI5_INFER, CK_PI5_PCIE, CK_PI5_NET, CK_PI5_FACT, CK_SERVICE, CK_HARDWARE_STAGING or CK_TEST_FWCFG_ARTIFACTS) +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)),) +$(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) endif ifeq ($(strip $(CK_INFER_LIB)),) $(error CK_PI5_AGENT needs CK_INFER_LIB=<libaienos_infer_kernel.a> (use "make pi5-agent", which builds it)) endif CK_EXTRA_CFLAGS += -DCK_PI5_AGENT=1 -DCK_INFER_DISK_ONLY=1 -DCK_INFER_RESIDENT=1 endif + +# Pi resident-lifecycle image (CK_PI5_LIFECYCLE=1, "make pi5-lifecycle", PI5-7 cut 2, QUALIFICATION ONLY while the secret comes from the +# card request file): the Pi unlock-card image (production-class Store opened by the Slot 1 recovery secret) plus the resident +# production lifecycle (core/lifecycle.c: remember, prefer, update, recall, approve, status, help, N3 context assembly) plus the resident +# 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 +# card command script \EFI\AIENOS\AGENT.CMD (core/agent_cmd.h) instead of the console and then runs its stop order. The lifecycle sources +# are the CK_SERVICE ones (-DCK_SERVICE=1 reaches only the stage sources, see the service block below); the secret still comes from the +# 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 +# flag and has its own OUT. +CK_PI5_LIFECYCLE ?= +ifneq ($(strip $(CK_PI5_LIFECYCLE)),) +ifneq ($(strip $(CK_PI5_LIFECYCLE)),1) +$(error CK_PI5_LIFECYCLE must be empty or 1) +endif +ifneq ($(strip $(CK_PI5_UNLOCK))$(strip $(CK_PI5_UNLOCK_CARD)),11) +$(error CK_PI5_LIFECYCLE (resident lifecycle, QUALIFICATION ONLY) needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1) +endif +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)),) +$(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) +endif +ifeq ($(strip $(CK_INFER_LIB)),) +$(error CK_PI5_LIFECYCLE needs CK_INFER_LIB=<libaienos_infer_kernel.a> (use "make pi5-lifecycle", which builds it)) +endif +CK_EXTRA_CFLAGS += -DCK_PI5_LIFECYCLE=1 -DCK_INFER_DISK_ONLY=1 -DCK_INFER_RESIDENT=1 +endif CK_PI5 ?= ifneq ($(strip $(CK_PI5)),) ifneq ($(strip $(CK_PI5)),1) @@ -812,6 +837,9 @@ endif ifneq ($(strip $(CK_PI5_FACT)),) CORE_C += $(BOOT)/efi_fact.c $(KDIR)/core/fact_req.c endif +ifneq ($(strip $(CK_PI5_LIFECYCLE)),) +CORE_C += $(BOOT)/efi_agentcmd.c $(KDIR)/core/agent_cmd.c +endif # P2 sealed-artifact loader: format/admission/receipt (artifact/), SHA-256 # (argus), Ed25519/SHA-512 (sig). Built into the core so every image carries # the loader; the TEST-anchor qualification build is CK_SEED0B_TEST_ANCHOR=1. @@ -882,7 +910,8 @@ STAGE_SRCS += $(KDIR)/svc/continuity_codec.c $(KDIR)/svc/continuity_resolve.c \ $(KDIR)/svc/continuity_resolve_sealed.c $(KDIR)/svc/continuity_commit.c $(KDIR)/svc/continuity_recovery.c \ $(KDIR)/svc/continuity_boot.c $(KDIR)/svc/continuity_subject.c $(KDIR)/svc/continuity_subject_provision.c endif -ifeq ($(strip $(CK_SERVICE)),1) +ifneq ($(strip $(CK_SERVICE)$(CK_PI5_LIFECYCLE)),) +SVC_STAGE_BASE := $(STAGE_SRCS) # Own OUT subdirectory: service objects never mix with a diagnostic image. ifeq ($(strip $(CK_SERVICE_TEST_KEYS)),1) FULL_NAME := full-service-testkeys @@ -917,6 +946,8 @@ SVC_SLOT_KEYS_C := $(OUT)/gen-$(FULL_NAME)/svc_slot_keys.c STAGE_SRCS += $(SVC_SLOT_KEYS_C) STAGE_DMA_FLAGS += -DCK_SLOT_UPDATE_KEYS=1 endif +# The sources this block added: the Pi block below restarts STAGE_SRCS, the lifecycle image takes them over. +SVC_STAGE_ADDED := $(filter-out $(SVC_STAGE_BASE),$(STAGE_SRCS)) endif ifeq ($(strip $(CK_TEST_DISK_XLATE_BYPASS)),1) FULL_NAME := $(FULL_NAME)-test-xlate-bypass @@ -928,7 +959,7 @@ endif # Pi path). core/pi5.c supplies ck_dev_boot_disk and ck_dev_nvme_release over the SD partition view. FULL_STAGE_SYMS := ck_stage_devices ck_stage_security ck_stage_store ck_stage_quiesce ck_stage_disk_artifacts ifneq ($(strip $(CK_PI5_STORE)$(CK_PI5_UNLOCK)),) -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),full-pi5-store) +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) FULL_STAGE_SYMS := ck_stage_store ck_stage_disk_artifacts STAGE_SRCS := $(KDIR)/svc/store_boot.c $(KDIR)/svc/artifact_store.c $(KDIR)/svc/store_crash.c $(KDIR)/svc/ck_compat.c \ $(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) @@ -938,6 +969,10 @@ endif ifneq ($(strip $(CK_PI5_AGENT)),) STAGE_SRCS += $(KDIR)/svc/pi5_agent.c endif +ifneq ($(strip $(CK_PI5_LIFECYCLE)),) +# The NVMe image-slot service is not part of the Pi image: its four hooks are answered by svc/slot_service_pi5.c. +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 +endif endif FULL_OUT := $(OUT)/$(FULL_NAME) STAGE_KOBJ := $(OUT)/obj/stage-$(FULL_NAME) @@ -1028,7 +1063,7 @@ $(foreach s,$(STAGE_SRCS),$(eval $(call stage_rule,$(s)))) # with inference (CK_INFER_LIB + CK_HARDWARE_STAGING, boot-disk only) must # carry the boot-disk source line, the resident session, and no fw_cfg code. define fwcfg_check - @if [ -n "$(strip $(CK_INFER_LIB))" ] && [ -z "$(strip $(CK_HARDWARE_STAGING))" ] && [ -z "$(strip $(CK_PI5_INFER))" ] && [ -z "$(strip $(CK_PI5_AGENT))" ]; then \ + @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 \ 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; }; \ elif [ "$(strip $(CK_TEST_FWCFG_ARTIFACTS))" = 1 ]; then \ 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; }; \ @@ -1064,7 +1099,7 @@ endef # service_check(elf): only a CK_SERVICE image may carry the resident lifecycle; # only a CK_SERVICE_TEST_KEYS image its TEST-ONLY banner. define service_check - @if [ "$(strip $(CK_SERVICE))" = 1 ]; then \ + @if [ "$(strip $(CK_SERVICE))" = 1 ] || [ -n "$(strip $(CK_PI5_LIFECYCLE))" ]; then \ grep -aqF "lifecycle: ready" $(1) || { echo "service image lacks the resident lifecycle"; rm -f $(1); exit 1; }; \ else \ if grep -aqF "lifecycle: ready" $(1); then echo "diagnostic image carries the resident lifecycle"; rm -f $(1); exit 1; fi; \ @@ -1164,7 +1199,7 @@ define cont_check grep -aqF "TEST-ONLY continuity mode selection image" $(1) || { echo "TEST continuity image lacks its TEST-ONLY announcement"; rm -f $(1); exit 1; }; \ else \ m="|TEST-ONLY MUTANT"; [ "$(strip $(CK_TEST_STORE_CRASH))" = 1 ] && m=""; \ - if [ "$(strip $(CK_SERVICE))" = 1 ]; then \ + if [ "$(strip $(CK_SERVICE))" = 1 ] || [ -n "$(strip $(CK_PI5_LIFECYCLE))" ]; then \ s=$$(grep -aoE "AIENCONT|RECOVERY_OPERATOR_KEY|RECOVERY_CORE:|CONTINUITY: $$m" $(1) | sort -u | tr "\n" " "); \ y=$$($(KNM) $(1) | grep -E " (ck_cont_boot_stage|rc_inspect)$$" | tr "\n" " "); \ grep -aqF "continuity: REFUSED" $(1) || { echo "service image lacks the production continuity wiring"; rm -f $(1); exit 1; }; \ @@ -1231,10 +1266,10 @@ $(FULL_EFI): $(FULL_ELF) HOST_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 $(KDIR)/core/sched.c $(KDIR)/core/ipc.c $(KDIR)/core/entropy.c \ $(KDIR)/core/handoff_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/lifecycle_fsm.c \ - $(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/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 TESTS := test_fmt test_frames test_pt test_acpi test_acpi_dev test_heap test_smmu test_sched test_ipc test_artifact test_osc_unit test_osc_launch test_osc_admit test_entropy test_handoff test_fbcon test_osh_op \ test_continuity_codec test_continuity_resolve test_continuity_commit test_continuity_recovery test_continuity_geometry \ - 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_unlock_req test_context + 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_unlock_req test_context test_agent_cmd HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT) SANFLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer @@ -1288,6 +1323,16 @@ context-mutant: $(OUT)/host/test_context_mutant @if $< > $<.log 2>&1; then cat $<.log; echo "test_context mutant (foreign binding check skipped): PASSED, test does not catch it"; exit 1; \ else grep -F "test_context: FAIL" $<.log && echo "test_context mutant (foreign binding check skipped): FAILS as required"; fi +# 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 +# or rotate); test_agent_cmd must FAIL against it (red before green). Host only, never part of an image. +$(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 + @mkdir -p $(dir $@) + $(HOSTCC) $(HCFLAGS) -DCK_AGENT_CMD_MUTANT_ANY_VERB -o $@ $< $(KDIR)/core/agent_cmd.c + +agent-cmd-mutant: $(OUT)/host/test_agent_cmd_mutant + @if $< > $<.log 2>&1; then cat $<.log; echo "test_agent_cmd mutant (any verb allowed): PASSED, test does not catch it"; exit 1; \ + else grep -F "test_agent_cmd: FAIL" $<.log && echo "test_agent_cmd mutant (any verb allowed): FAILS as required"; fi + # TEST-ONLY mutant of core/handoff_check.c (reserved0 check removed): the # handoff test must FAIL against it, so "make test" fails if the test stops # catching the mutation. Host only (handoff_check.c refuses it freestanding @@ -1366,8 +1411,8 @@ smmu-l2-mutants: $(OUT)/host/test_smmu else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \ if [ $$fail = 0 ]; then echo "CK_SMMU_L2_MUTANTS: PASS"; else echo "CK_SMMU_L2_MUTANTS: FAIL"; exit 1; fi -test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check - @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check,$^); do $$t || fail=1; done; \ +test: $(addprefix $(OUT)/host/,$(TESTS)) handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check + @fail=0; for t in $(filter-out handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants osh-op-mutant context-mutant agent-cmd-mutant test-continuity-subject-restart gsp-fw-inspect-test gsp-cot-test gsp-bindata-test gsp-bootargs-test gsp-rpc-test slot-test slot-free package-test slot-loader-check,$^); do $$t || fail=1; done; \ if [ $$fail = 0 ]; then echo "CK_CORE_HOST: PASS"; else echo "CK_CORE_HOST: FAIL"; exit 1; fi sanitize: $(addprefix $(OUT)/host-san/,$(TESTS)) @@ -2015,6 +2060,10 @@ pi5-agent: CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_AGENT=1 CK_INFER_LIB=$(PI5_INFER_LIB) full +pi5-lifecycle: + CARGO_TARGET_DIR=$(REPO)/target/infer-kernel cargo build -q --release --target aarch64-unknown-none --manifest-path $(REPO)/crates/aienos-infer-kernel/Cargo.toml + $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=$(PI5_INFER_LIB) full + pi5: $(MAKE) CK_PI5=1 all @@ -2073,7 +2122,7 @@ $(OUT)/host-san/test_pi5_rng: $(KDIR)/tests/test_pi5_rng.c $(PI5_RNG_SRCS) $(KDI FORCE: .PHONY: uefi-vars slot-loader slot-loader-check pi5-diag -.PHONY: all full pi5 pi5-store pi5-infer pi5-unlock pi5-unlock-card pi5-fact pi5-agent test sanitize context-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 +.PHONY: all full pi5 pi5-store pi5-infer pi5-unlock pi5-unlock-card pi5-fact pi5-agent pi5-lifecycle test sanitize context-mutant agent-cmd-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 # AIENOS-PI5 step 3 marker + Pi card GPT test (hosted; a file stands in for the card, QEMU cannot model the Pi SD host). PI5_MARKER_SRCS := $(KDIR)/core/pi5_marker.c $(KDIR)/dev/disk_part.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \ diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 75775b65..66724f9b 100644 --- a/native/kernel/core/.crumb +++ b/native/kernel/core/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T22:05:34Z", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:957bfad5ac7bb52cc3447b4520f3b029c421a8891b90b5c00dad842339294575", + "digest": "sha256:4838185961eedd4d2053c8d8a6804065d1f8f450461ce74a819d5f7d4d8988f1", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 64, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:cd057fbeedff2ee679d4166845d463c42bd8bc00e0486cf3955c78cb2f5a2a30" + "files": 66, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:0c79bbf69968edeb45698a019201c984931ae7b4ea457c0237c8fcca6a70a050" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/agent_cmd.c b/native/kernel/core/agent_cmd.c new file mode 100644 index 00000000..e3575977 --- /dev/null +++ b/native/kernel/core/agent_cmd.c @@ -0,0 +1,129 @@ +/* agent_cmd.c -- see agent_cmd.h. No kernel calls, no libc. */ +#include "agent_cmd.h" + +struct ck_agent_cmd_boot ck_agent_cmd_boot; + +struct verb { + const char *name; + int has_text; /* 1: needs text, 0: takes none */ +}; + +/* The only verbs a card script may carry. unlock, rotate, update and shutdown are deliberately absent. */ +static const struct verb verbs[] = { + {"status", 0}, {"help", 0}, {"evidence", 0}, {"recall", 0}, {"facts", 0}, {"approve", 0}, + {"deny", 0}, {"cancel", 0}, {"remember", 1}, {"prefer", 1}, {"prompt", 1}, {"task", 1}, +}; + +static void zero(struct ck_agent_cmd *o) +{ + unsigned char *p = (unsigned char *)o; + for (size_t i = 0; i < sizeof *o; i++) p[i] = 0; +} + +/* verb at line[0..vl): index in verbs[], or -1 */ +static int find_verb(const char *l, size_t vl) +{ +#ifdef CK_AGENT_CMD_MUTANT_ANY_VERB + /* TEST-ONLY mutant: any word is a verb (a script could carry unlock or rotate). */ + (void)l; (void)vl; (void)verbs; + return 0; +#else + for (size_t k = 0; k < sizeof verbs / sizeof verbs[0]; k++) { + size_t i = 0; + while (verbs[k].name[i] && i < vl && verbs[k].name[i] == l[i]) i++; + if (!verbs[k].name[i] && i == vl) return (int)k; + } + return -1; +#endif +} + +int ck_agent_cmd_parse(const uint8_t *buf, size_t n, struct ck_agent_cmd *out, const char **why) +{ + const char *w = 0; + size_t i, hl = sizeof CK_AGENT_CMD_HEADER - 1, at; + if (out) zero(out); + if (!buf || !out) { + w = "no request"; + goto out; + } + if (n == 0 || n > CK_AGENT_CMD_FILE_MAX) { + w = "file size must be 1..2048 bytes"; + goto out; + } + for (i = 0; i < n; i++) + if (!(buf[i] == '\n' || (buf[i] >= 0x20 && buf[i] <= 0x7e))) { + w = "only printable ASCII and LF line ends are allowed"; + goto out; + } + if (buf[n - 1] != '\n') { + w = "file does not end with a line feed"; + goto out; + } + if (n < hl + 1) { + w = "bad header line"; + goto out; + } + for (i = 0; i < hl; i++) + if (buf[i] != (uint8_t)CK_AGENT_CMD_HEADER[i]) { + w = "bad header line"; + goto out; + } + if (buf[hl] != '\n') { + w = "bad header line"; + goto out; + } + at = hl + 1; + while (at < n) { + size_t e = at, vl, tl; + int v; + uint32_t k = out->nlines; + while (buf[e] != '\n') e++; + if (e == at) { + w = "empty line"; + goto out; + } + if (buf[at] == ' ' || buf[e - 1] == ' ') { + w = "line has a leading or trailing blank"; + goto out; + } + if (k >= CK_AGENT_CMD_LINES_MAX) { + w = "more than 16 command lines"; + goto out; + } + vl = 0; + while (at + vl < e && buf[at + vl] != ' ') vl++; + v = find_verb((const char *)buf + at, vl); + if (v < 0) { + w = "verb not allowed in a card script"; + goto out; + } + tl = at + vl < e ? e - (at + vl + 1) : 0; +#ifndef CK_AGENT_CMD_MUTANT_ANY_VERB + if (verbs[v].has_text) { + if (tl == 0 || tl > CK_AGENT_CMD_TEXT_MAX || buf[at + vl + 1] == ' ') { + w = "text must be 1..48 bytes after one blank"; + goto out; + } + } else if (at + vl != e) { + w = "this verb takes no text"; + goto out; + } +#else + (void)tl; + if (e - at >= CK_AGENT_CMD_LINE_MAX) { + w = "line too long"; + goto out; + } +#endif + for (i = 0; i < e - at; i++) out->line[k][i] = (char)buf[at + i]; + out->line[k][e - at] = 0; + out->len[k] = (uint32_t)(e - at); + out->nlines++; + at = e + 1; + } + if (out->nlines == 0) w = "no command line"; +out: + if (w && out) zero(out); + if (why) *why = w; + return w ? -1 : 0; +} diff --git a/native/kernel/core/agent_cmd.h b/native/kernel/core/agent_cmd.h new file mode 100644 index 00000000..3f824239 --- /dev/null +++ b/native/kernel/core/agent_cmd.h @@ -0,0 +1,50 @@ +/* agent_cmd.h -- the card command script of the Pi resident-lifecycle qualification image + * (PI5-7 cut 2, build flag CK_PI5_LIFECYCLE, only with CK_PI5_UNLOCK_CARD). + * + * QUALIFICATION ONLY. Nothing reads the Pi's serial port during a run, so the run tool may place + * \EFI\AIENOS\AGENT.CMD on the card's EFI partition holding a short list of lifecycle verbs. The UEFI + * stub (native/boot/efi_agentcmd.c) reads it before ExitBootServices; after the Store stage the resident + * lifecycle (core/lifecycle.c) takes each line in order, exactly as if an operator had typed it on the + * console, prints the reply on the console and the klog, then runs its stop order. The run tool deletes + * the file after the run. The file is a labelled qualification input, never a user interface, and it can + * never carry a secret: unlock, rotate, update and shutdown are refused by the parser (the Store secret + * comes from the card UNLOCK.REQ request, core/unlock_req.h; shutdown is implicit at the end). + * + * File layout: plain text, at most CK_AGENT_CMD_FILE_MAX bytes, LF line ends. + * line 1 exactly "AIENAGC1 QUALIF-AGENT-CMD" + * lines 2.. 1..CK_AGENT_CMD_LINES_MAX command lines, each: + * <verb> status help evidence recall facts approve deny cancel + * <verb> <text> remember prefer prompt task (text 1..CK_AGENT_CMD_TEXT_MAX bytes) + * every byte is printable ASCII 0x20..0x7e or the LF that ends a line; the file ends with an LF; + * no empty line, no CR, no tab, no NUL; a line has no leading or trailing blank and a single blank + * between verb and text. */ +#ifndef AIENOS_CK_AGENT_CMD_H +#define AIENOS_CK_AGENT_CMD_H +#include <stddef.h> +#include <stdint.h> + +#define CK_AGENT_CMD_HEADER "AIENAGC1 QUALIF-AGENT-CMD" +#define CK_AGENT_CMD_PATH "\\EFI\\AIENOS\\AGENT.CMD" +#define CK_AGENT_CMD_FILE_MAX 2048u +#define CK_AGENT_CMD_LINES_MAX 16u +#define CK_AGENT_CMD_TEXT_MAX 48u /* the lifecycle's own text bound (CK_LC_TASK_MAX) */ +#define CK_AGENT_CMD_LINE_MAX 64u /* "remember " + 48 text + NUL fits */ + +struct ck_agent_cmd { + uint32_t nlines; + uint32_t len[CK_AGENT_CMD_LINES_MAX]; + char line[CK_AGENT_CMD_LINES_MAX][CK_AGENT_CMD_LINE_MAX]; +}; + +/* 0 = well formed and *out filled; else -1, *out zeroed and *why names the first failed check. */ +int ck_agent_cmd_parse(const uint8_t *buf, size_t n, struct ck_agent_cmd *out, const char **why); + +enum { CK_AGENT_CMD_NONE = 0, CK_AGENT_CMD_ABSENT = 1, CK_AGENT_CMD_REFUSED = 2, CK_AGENT_CMD_FOUND = 3 }; + +/* What the UEFI stub found (the stub and the kernel are one image). */ +struct ck_agent_cmd_boot { + int state; /* CK_AGENT_CMD_* */ + struct ck_agent_cmd cmd; /* only while FOUND */ +}; +extern struct ck_agent_cmd_boot ck_agent_cmd_boot; +#endif diff --git a/native/kernel/core/lifecycle.c b/native/kernel/core/lifecycle.c index c260581f..97269cde 100644 --- a/native/kernel/core/lifecycle.c +++ b/native/kernel/core/lifecycle.c @@ -77,6 +77,9 @@ #include "cortex_journal.h" #include "slot_service.h" #include "reply_obj.h" +#ifdef CK_PI5_LIFECYCLE +#include "agent_cmd.h" +#endif #if !defined(CK_SERVICE) #error "lifecycle.c is only part of a CK_SERVICE=1 image" @@ -88,6 +91,12 @@ #if defined(CK_SERVICE_TEST_KEYS) && defined(CK_HARDWARE_STAGING) #error "CK_SERVICE_TEST_KEYS (TEST keys) cannot be combined with CK_HARDWARE_STAGING" #endif +#if defined(CK_PI5_LIFECYCLE) && (!defined(CK_PI5_UNLOCK_CARD) || defined(CK_SERVICE_TEST_KEYS) || defined(CK_HARDWARE_STAGING)) +#error "CK_PI5_LIFECYCLE (card command script, QUALIFICATION ONLY) needs the card-secret Pi image and no TEST keys or hardware staging" +#endif +#ifdef CK_PI5_LIFECYCLE +_Static_assert(CK_AGENT_CMD_TEXT_MAX == CK_LC_TASK_MAX && CK_AGENT_CMD_LINE_MAX <= CK_LC_LINE_MAX, "script line bounds are the lifecycle bounds"); +#endif #define CK_LC_OBJ_KIND 0x4e31u /* 'N1': v1 approved note, version 1 */ #define CK_LC_REPLY_KIND CK_REPLY_OBJ_KIND /* 0x5231 'R1': v1 approved reply (prompt + generated text), version 1 */ @@ -385,7 +394,12 @@ static void gen_refuse(enum ck_lc_verb v, const char *reason) } static int cancel_poll(void) { +#ifdef CK_PI5_LIFECYCLE + (void)gen_refuse; /* the card script is never read while generating: no cancel, no refused lines */ + return 0; +#else return ck_line_rx_cancel_poll(&g_gen_rx, ck_console_rx_poll, gen_refuse); +#endif } /* prompt accepted: the resident model generates a bounded reply, which @@ -816,6 +830,7 @@ static void handle_line(const char *line, size_t len) } } +#ifndef CK_PI5_LIFECYCLE /* 1 when the line so far is "unlock" or "rotate" followed by its argument: * those bytes are recovery secrets and are echoed as '*' so the serial log * never carries them. */ @@ -831,6 +846,7 @@ static int in_secret(const char *buf, size_t len) { return after_verb(buf, len, "unlock") || after_verb(buf, len, "rotate"); } +#endif /* !CK_PI5_LIFECYCLE */ /* Bounded serial line editor over the POLLED console receive (no * interrupts): the rules are core/line_rx.c (printable bytes collected, @@ -839,6 +855,7 @@ static int in_secret(const char *buf, size_t len) * only echoes. At most CK_LINE_RX_BURST bytes per call. Returns 1 when * g_rx.buf[0..g_rx.len) is a complete line. */ static struct ck_line_rx g_rx; +#ifndef CK_PI5_LIFECYCLE static int rx_line(void) { for (unsigned n = 0; n < CK_LINE_RX_BURST; n++) { @@ -866,12 +883,41 @@ static int rx_line(void) } return 0; } +#endif /* !CK_PI5_LIFECYCLE */ + +#ifdef CK_PI5_LIFECYCLE +/* PI5-7 cut 2 (QUALIFICATION ONLY): the operator input is the card command script \EFI\AIENOS\AGENT.CMD + * (core/agent_cmd.h), already parsed and bounded by the UEFI stub. Each line goes through the same + * handle_line the console path uses, so every reply is the one an operator would see; the line is echoed + * after "> " first. The parser lets no secret-carrying or control verb through (unlock, rotate, update, + * shutdown), and the stop order follows the last line (or an absent or refused script) in any case. */ +static void run_script(void) +{ + const struct ck_agent_cmd_boot *b = &ck_agent_cmd_boot; + uint32_t i; + ck_printf("lifecycle: ready state=%s store=%s (operator input: card command script AGENT.CMD, QUALIFICATION ONLY, no serial)\n", + ck_lc_state_name(g_lc.state), ck_store_service_ready() ? "open" : "locked"); + if (b->state != CK_AGENT_CMD_FOUND) { + ck_printf("lifecycle: no command script (%s): nothing to run\n", + b->state == CK_AGENT_CMD_REFUSED ? "refused" : "absent"); + } else { + for (i = 0; i < b->cmd.nlines && g_lc.state != CK_LC_QUIESCE; i++) { + ck_printf("> %s\n", b->cmd.line[i]); + handle_line(b->cmd.line[i], b->cmd.len[i]); + } + ck_printf("lifecycle: command script done lines=%u\n", (unsigned)b->cmd.nlines); + } + if (g_lc.state != CK_LC_QUIESCE) handle_line("shutdown", 8); +} +#endif /* Returns 0 after an orderly stop (kmain then prints the final report and * resets). Never returns while serving. */ int ck_lifecycle_run(void) { +#ifndef CK_PI5_LIFECYCLE uint32_t cr = 0; +#endif ck_lc_init(&g_lc); ck_line_rx_init(&g_rx); ck_line_rx_init(&g_gen_rx); @@ -880,6 +926,10 @@ int ck_lifecycle_run(void) #endif ck_lc_start(&g_lc, ck_store_service_ready()); ck_slot_service_start(slot_healthy()); +#ifdef CK_PI5_LIFECYCLE + const char *uname = "none (card command script)"; + run_script(); +#else /* Operator input is the console UART the boot stub chose from the ACPI * SPCR (PL011/SBSA or 16550), POLLED: no interrupt is ever enabled. */ const char *uname = ck_console_uart_name(); @@ -904,6 +954,7 @@ int ck_lifecycle_run(void) } } } +#endif /* Stop order: Cortex journal closed (frames returned), inference session * closed (frames returned), Store closed, then NVMe released, then the * caller resets. */ diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index e0814284..dd0aab6a 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:d835471b1405ca482a41beb34ed339d21e11064a59138599ee5754d198926878", - "compiled_at": "2026-10-13T21:27:22Z", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:ef2c5b80defe4f152278954ff8a5b256a1898dd0f77d8220c5fbe6637e99bed0", + "digest": "sha256:2a98333d826d94a7131119aaeb5a15d8bc543baa5531fa930e6f0afc1fccb83d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 47, - "generated_at_commit": "03de8681ae58720bd01a45ccb5311c792f1d517b", - "source_tree": "sha256:bc4beefa0f01894c6db834266373a39adfacf6c9095b20f9c2687bf3ce624c59" + "files": 48, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:8ea0c11b9dedede3565f8e3d47b8192651e0790f8e3df92b172ce4a8dc936af1" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/slot_service_pi5.c b/native/kernel/svc/slot_service_pi5.c new file mode 100644 index 00000000..9cfb8191 --- /dev/null +++ b/native/kernel/svc/slot_service_pi5.c @@ -0,0 +1,30 @@ +/* slot_service_pi5.c -- the slot service of the Pi resident-lifecycle qualification image (CK_PI5_LIFECYCLE). + * The Pi card has no SLOTLDR.EFI image slots (P11 is the NVMe/GB10 layout), so there is nothing to promote, + * abandon or update: the lifecycle's four slot hooks (svc/slot_service.h) are present and say so. The real + * svc/slot_service.c needs the NVMe slot and inbox disks and is not linked. Freestanding. */ +#include "ck.h" +#include "slot_service.h" + +#ifndef CK_PI5_LIFECYCLE +#error "slot_service_pi5.c is only part of the CK_PI5_LIFECYCLE qualification image" +#endif + +void ck_slot_service_start(int healthy) +{ + (void)healthy; + ck_puts("slot: no image slots on the Pi qualification image (no SLOTLDR.EFI): slot service idle, nothing written\n"); +} + +void ck_slot_service_health(int healthy) +{ + (void)healthy; +} + +void ck_slot_service_stop(void) {} + +void ck_slot_service_update(const char *arg, size_t len) +{ + (void)arg; + (void)len; + ck_puts("lifecycle: update REFUSED reason=\"no image slots on the Pi qualification image\"\n"); +} diff --git a/native/kernel/svc/store_boot.c b/native/kernel/svc/store_boot.c index b02d618b..f0517c65 100644 --- a/native/kernel/svc/store_boot.c +++ b/native/kernel/svc/store_boot.c @@ -39,8 +39,11 @@ * (ck_store_pi5_unlock_run). No TEST keys, no TEST uuid are compiled, and the policy is the * hardware one: TEST-identity keys are refused before any disk access. It needs no owner * provisioning header (the store uuid is drawn at genesis or read from the manifest). */ -#if defined(CK_STORE_TEST_KEYS) || defined(CK_PI5_STORE) || defined(CK_TEST_STORE_CRASH) || defined(CK_SERVICE) -#error "CK_PI5_UNLOCK cannot be combined with TEST keys, CK_PI5_STORE, CK_TEST_STORE_CRASH or CK_SERVICE" +#if defined(CK_STORE_TEST_KEYS) || defined(CK_PI5_STORE) || defined(CK_TEST_STORE_CRASH) || (defined(CK_SERVICE) && !defined(CK_PI5_LIFECYCLE)) +#error "CK_PI5_UNLOCK cannot be combined with TEST keys, CK_PI5_STORE, CK_TEST_STORE_CRASH or CK_SERVICE (the one exception: the CK_PI5_LIFECYCLE qualification image, whose lifecycle sources are the CK_SERVICE ones)" +#endif +#if defined(CK_PI5_LIFECYCLE) && (!defined(CK_SERVICE) || !defined(CK_PI5_UNLOCK_CARD) || defined(CK_SERVICE_TEST_KEYS)) +#error "CK_PI5_LIFECYCLE needs CK_SERVICE sources, CK_PI5_UNLOCK_CARD (card secret) and no TEST keys" #endif #define CK_SB_HW 1 #else @@ -825,7 +828,7 @@ int ck_stage_store(void) } } #endif -#if defined(CK_SERVICE) && !defined(CK_SERVICE_TEST_KEYS) +#if defined(CK_SERVICE) && !defined(CK_SERVICE_TEST_KEYS) && !defined(CK_PI5_UNLOCK) /* Production service image without owner provisioning: the production * key source only (it refuses today: no in-kernel K_vol unwrap, P04). No * TEST key is ever used here. */ diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index d6c1cc21..236abf53 100644 --- a/native/kernel/tests/.crumb +++ b/native/kernel/tests/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T22:05:34Z", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:17f3ab5f5e8314d29db1d2ee908a01848745520cc61b8de1d95982f6657e065c", + "digest": "sha256:b6bc9b845fa67108c0bdac73dc640d2a634f8606e833703096f3746df1c23257", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 162, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:8578bae60fd303317f5f7a831a60d8fa6e8d065c2351f86710c16ee6726ac8a9" + "files": 163, + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:23e3a72107864253e896e995535687b6c314beb5420084129c66effb66d97b6b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_agent_cmd.c b/native/kernel/tests/test_agent_cmd.c new file mode 100644 index 00000000..edfe28be --- /dev/null +++ b/native/kernel/tests/test_agent_cmd.c @@ -0,0 +1,94 @@ +/* test_agent_cmd.c -- core/agent_cmd.c: the card command script of the Pi resident-lifecycle qualification + * image (CK_PI5_LIFECYCLE). A script is a labelled text file of a few lifecycle verbs; the parser is strict + * (header, bytes, line count, verb whitelist, text bounds) and can never let a secret-carrying or + * state-changing control verb (unlock, rotate, update, shutdown) through. */ +#include <string.h> +#include "ck_test.h" +#include "agent_cmd.h" + +#define H CK_AGENT_CMD_HEADER "\n" + +static int parse(const char *s, struct ck_agent_cmd *o, const char **why) +{ + return ck_agent_cmd_parse((const uint8_t *)s, strlen(s), o, why); +} + +static int refused(const char *s, const char *want) +{ + struct ck_agent_cmd o; + const char *why = 0; + int rc = parse(s, &o, &why); + /* a refused script leaves nothing behind */ + int clean = o.nlines == 0 && o.line[0][0] == 0; + return rc != 0 && why && strstr(why, want) != 0 && clean; +} + +int main(void) +{ + struct ck_agent_cmd o; + const char *why = (const char *)1; + CHECK(strlen(CK_AGENT_CMD_HEADER) == 25); + + /* the L1 script of the qualification run */ + CHECK(parse(H "prefer short notes\nstatus\nrecall\nprompt What is the capital of France?\napprove\n", &o, &why) == 0 && why == 0); + CHECK(o.nlines == 5 && o.len[0] == 18 && strcmp(o.line[0], "prefer short notes") == 0); + CHECK(strcmp(o.line[3], "prompt What is the capital of France?") == 0 && strcmp(o.line[4], "approve") == 0); + CHECK(parse(H "recall\nfacts\nevidence\nhelp\ndeny\ncancel\nremember a b c\ntask do it\n", &o, 0) == 0 && o.nlines == 8); + CHECK(ck_agent_cmd_parse(0, 0, &o, &why) != 0 && ck_agent_cmd_parse((const uint8_t *)"x", 1, 0, &why) != 0); + + /* header */ + CHECK(refused("", "size")); + CHECK(refused("status\n", "header")); + CHECK(refused("AIENAGC1 QUALIF-AGENT-CMD", "line feed")); + CHECK(refused("AIENAGC2 QUALIF-AGENT-CMD\nstatus\n", "header")); + CHECK(refused("AIENAGC1 QUALIF-AGENT-CMD \nstatus\n", "header")); + CHECK(refused(H, "no command line")); + + /* the control verbs can never ride in a card script */ + CHECK(refused(H "unlock\n", "not allowed")); + CHECK(refused(H "unlock 0000000000000000000000000000000000000000000000000000000000000000\n", "not allowed")); + CHECK(refused(H "rotate a b\n", "not allowed")); + CHECK(refused(H "update\n", "not allowed")); + CHECK(refused(H "shutdown\n", "not allowed")); + CHECK(refused(H "status\nunlock\n", "not allowed")); + CHECK(refused(H "Status\n", "not allowed")); + CHECK(refused(H "statuses\n", "not allowed")); + CHECK(refused(H "stat\n", "not allowed")); + CHECK(refused(H "frob\n", "not allowed")); + + /* shape of a line */ + CHECK(refused(H "status now\n", "no text")); + CHECK(refused(H "approve please\n", "no text")); + CHECK(refused(H "prefer\n", "text must be")); + CHECK(refused(H "prefer two blanks\n", "text must be")); + CHECK(refused(H " status\n", "blank")); + CHECK(refused(H "status \n", "blank")); + CHECK(refused(H "prefer short \n", "blank")); + CHECK(refused(H "status\n\nrecall\n", "empty line")); + CHECK(refused(H "prefer 0123456789012345678901234567890123456789012345678\n", "text must be")); /* 49 */ + CHECK(parse(H "prefer 012345678901234567890123456789012345678901234567\n", &o, &why) == 0 && o.len[0] == 7 + 48); /* 48 */ + + /* bytes */ + CHECK(refused(H "status\r\n", "printable")); + CHECK(refused(H "pre\tfer x\n", "printable")); + CHECK(refused("AIENAGC1 QUALIF-AGENT-CMD\nprefer caf\xc3\xa9\n", "printable")); + { + char z[64]; + strcpy(z, H "status\n"); + z[strlen(H) + 2] = 0; + CHECK(ck_agent_cmd_parse((const uint8_t *)z, strlen(H) + 7, &o, &why) != 0 && o.nlines == 0); + } + + /* count and size bounds */ + { + char big[CK_AGENT_CMD_FILE_MAX + 64]; + strcpy(big, H); + for (int i = 0; i < 16; i++) strcat(big, "status\n"); + CHECK(parse(big, &o, &why) == 0 && o.nlines == 16); + strcat(big, "status\n"); + CHECK(refused(big, "more than 16")); + memset(big, 'a', sizeof big); + CHECK(ck_agent_cmd_parse((const uint8_t *)big, CK_AGENT_CMD_FILE_MAX + 1, &o, &why) != 0 && strstr(why, "size")); + } + return ck_t_verdict("test_agent_cmd"); +} diff --git a/scripts/.crumb b/scripts/.crumb index 2846bcff..9b0c1168 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T22:05:34Z", + "compiled_at": "2026-10-13T23:07:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:17ca56cca1e53f3d5ef7813006097037d3e3bbf8b4882fc907ea6c6979756d08", + "digest": "sha256:95951d5a52b7ade0f66bb972e92ebfd3fb14433557f1ee827bef14d6481a17a7", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 96, - "generated_at_commit": "e7c361ad2f58c74e10e2e6dcb1d3210ea5c1c47a", - "source_tree": "sha256:fb2edc26100d338b6605de42a98d6832fa96927c73e4d0591529a999fb22b6e1" + "generated_at_commit": "53de55c5dd3485948cd34734caf0f646e28a68c4", + "source_tree": "sha256:ac8f9aa5b5a238cb102f7a679b798ed7ac5ff7059bcf8d7a2456279c7c6acae6" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_pi5_build_check.sh b/scripts/ck_pi5_build_check.sh index 4d27ec51..6d1d5e6b 100755 --- a/scripts/ck_pi5_build_check.sh +++ b/scripts/ck_pi5_build_check.sh @@ -189,4 +189,41 @@ for tier in CK_PI5_INFER=1 CK_PI5_PCIE=1 CK_PI5_FACT=1; do if make -n -C "${root}/native/kernel" ${tier} CK_PI5_AGENT=1 CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_INFER_LIB=/x/l.a full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${tier} with CK_PI5_AGENT=1"; fail=1; fi done test -s "${root}/target/native-kernel-pi5-unlock-card-agent/full-pi5-unlock-card-agent/BOOTAA64.EFI" || { echo "FAIL no pi5-agent BOOTAA64.EFI"; fail=1; } +# PI5-7 cut 2: the resident lifecycle driven by the card command script exists only in the pi5-lifecycle image. +make -C "${root}/native/kernel" pi5-lifecycle >/dev/null +ul="${root}/target/native-kernel-pi5-unlock-card-lifecycle/full-pi5-unlock-card-lifecycle/aienos-ck.elf" +for s in ck_lifecycle_run ck_boot_agent_cmd_find ck_agent_cmd_parse ck_cont_service_start ck_ctx_finish ck_infer_prompt ck_infer_resident_close ck_store_pi5_unlock_run ck_boot_unlock_req_find ck_slot_service_update cx_open_with; do + if defined "${ul}" "${s}"; then echo "PASS pi5-lifecycle image defines ${s}"; else echo "FAIL pi5-lifecycle image lacks ${s}"; fail=1; fi +done +for s in ck_lifecycle_run ck_boot_agent_cmd_find ck_agent_cmd_parse ck_cont_service_start ck_slot_service_update; do + for other in "${ua}" "${uf}" "${uc}" "${uo}" "${ps}" "${pi5}" "${pinf}" "${def}"; do + if defined "${other}" "${s}"; then echo "FAIL ${other} defines ${s}"; fail=1; fi + done +done +echo "PASS no other Pi image (pi5-agent, pi5-fact, pi5-unlock-card, pi5-unlock, pi5-store, pi5, pi5-infer) nor the default image defines the lifecycle or its script reader" +for s in ck_pi5_agent_run ck_store_pi5_agent_stage ck_pi5_fact_run ck_boot_fact_req_find ck_store_test_keys ck_store_test_uuid ck_slot_boot_capture ck_rc_inspect rc_inspect ck_cont_boot_stage fw_dma_read fwcfg_from_dsdt; do + if defined "${ul}" "${s}"; then echo "FAIL pi5-lifecycle image defines ${s}"; fail=1; else echo "PASS pi5-lifecycle image has no ${s}"; fi +done +ul_strings="$(strings -a "${ul}")" +if grep -q "AIEN-TEST-BOOT\|LANE18-TEST-KVOL\|SEED-0B-\|TEST-ONLY service image" <<<"${ul_strings}"; then echo "FAIL pi5-lifecycle image carries a TEST label"; fail=1; else echo "PASS pi5-lifecycle image carries no TEST label (production-class Store)"; fi +if grep -q "infer_source_mode: boot-disk model" <<<"${ul_strings}" && ! grep -q "opt/aienos/model\|TEST-ONLY QEMU fw_cfg" <<<"${ul_strings}"; then echo "PASS pi5-lifecycle image reads the model from the boot disk only (no fw_cfg source)"; else echo "FAIL pi5-lifecycle image model source"; fail=1; fi +if grep -q "QUALIFICATION ONLY, throwaway secret" <<<"${ul_strings}"; then echo "PASS the loud unlock_source label is in the pi5-lifecycle image"; else echo "FAIL pi5-lifecycle image lacks the unlock_source label"; fail=1; fi +if grep -q "card command script AGENT.CMD, QUALIFICATION ONLY" <<<"${ul_strings}"; then echo "PASS the loud command-script label is in the pi5-lifecycle image"; else echo "FAIL pi5-lifecycle image lacks the command-script label"; fail=1; fi +# the lifecycle image never reads the console: no serial input line in the image, the script is the only input. +if grep -q "operator input: serial" <<<"${ul_strings}"; then echo "FAIL pi5-lifecycle image carries the serial input path"; fail=1; else echo "PASS pi5-lifecycle image has no serial operator input"; fi +if make -n -C "${root}/native/kernel" CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=/nonexistent/lib.a full >/dev/null 2>&1; then echo "PASS Makefile accepts CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=<lib>"; else echo "FAIL Makefile refuses the pi5-lifecycle flag set"; fail=1; fi +for combo in "CK_PI5_LIFECYCLE=1" "CK_PI5_UNLOCK=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=/x/l.a" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=2 CK_INFER_LIB=/x/l.a" "CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=/x/l.a"; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${combo} full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${combo}"; fail=1; else echo "PASS Makefile refuses ${combo}"; fi +done +for other in CK_PI5_STORE=1 CK_PI5_INFER=1 CK_PI5_PCIE=1 CK_PI5_FACT=1 CK_PI5_AGENT=1 CK_SERVICE=1 CK_SERVICE_TEST_KEYS=1 CK_HARDWARE_STAGING=1 CK_TEST_FWCFG_ARTIFACTS=1; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${other} CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_LIFECYCLE=1 CK_INFER_LIB=/x/l.a full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${other} with CK_PI5_LIFECYCLE=1"; fail=1; else echo "PASS Makefile refuses ${other} with CK_PI5_LIFECYCLE=1"; fi +done +# the other direction: the older Pi tiers refuse the lifecycle flag too. +for tier in CK_PI5_INFER=1 CK_PI5_PCIE=1 CK_PI5_FACT=1 CK_PI5_AGENT=1; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${tier} CK_PI5_LIFECYCLE=1 CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_INFER_LIB=/x/l.a full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${tier} with CK_PI5_LIFECYCLE=1"; fail=1; fi +done +test -s "${root}/target/native-kernel-pi5-unlock-card-lifecycle/full-pi5-unlock-card-lifecycle/BOOTAA64.EFI" || { echo "FAIL no pi5-lifecycle BOOTAA64.EFI"; fail=1; } if [[ ${fail} == 0 ]]; then echo "CK_PI5_BUILD: PASS"; else echo "CK_PI5_BUILD: FAIL"; exit 1; fi