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#365 (code only)
Apply it
git checkout -b patch-25f0ac5526f98b91 b03a06bfc29bb984c2618d645b96fa86622c1de0 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/25f0ac5526f98b91.patch | git am
Provenance
github-import 1
aien-dev/aienux
365
e9ab9d0ec38d6fca52b80cffecf1b39d96606664
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":365,"url":"https://github.com/aien-dev/aienux/pull/365","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:17Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index cb7b3f26..3ba09c0c 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "dc2bf879c3b063d7c9e6d70857b446d9b31ef056eb9cbd91ba29b9f140d7333a", - "last_commit": "217b815", + "digest": "a2eb5c6669ae3a678242786963d929f044f425929e7de3d2e9ea39adfdbe8009", + "last_commit": "013dfa6", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "3185a027a07a43ff646175b497f190296c275c06c40e1f2b0513eb9af09b07b1", - "last_commit": "87b8037", + "digest": "f497c9f7a4854444dec6fb7a02af1acbcbc2b54f9b02421817271263a7b3cae0", + "last_commit": "013dfa6", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "e854b415aa0c2a7f1fe45aa6dc9987b2219b91916ddd826b4a49b9efae60a27e", - "last_commit": "e4b583e", + "digest": "f94d1bca3f533e19fd6fee07f9e931ba85bacec7633de4f456534426c4a31bb4", + "last_commit": "013dfa6", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:2c36e26b7268f94f2a19fff4bfaeaf29d8ef9169ee794004a62c6e7a662b24b7", - "compiled_at": "2026-10-13T16:35:24Z", + "children_root": "sha256:cb7062ed32d6f81f47c79a99fa3dd039bb664442e6f95dacfb07ae6828650f8f", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:6ef8c4b8ed2946cce50037f982f319871f70aa702d9580d1c97cc8c67016f719", + "digest": "sha256:4ceff2643dfeb46c21079cf3bf9783c4a60a27d73a9aba82a464c5e83c7b97ed", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3167, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:8e1f362b69073b6e31f0a7d5bf1c7d6ccd8f0c4cf1cd73356fd03009d0076655" + "files": 3175, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:fa1d57b2d15bae766884ca889f47fedd3043373567df95ff305dd783b44ddc91" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 968fc917..046ad41b 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:c5d7ca9ce0145309c90a439711adcb6dd8e8e40ff48b90455f545e63c05f04c8", - "compiled_at": "2026-10-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:dc2bf879c3b063d7c9e6d70857b446d9b31ef056eb9cbd91ba29b9f140d7333a", + "digest": "sha256:a2eb5c6669ae3a678242786963d929f044f425929e7de3d2e9ea39adfdbe8009", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 76, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:86de11b2295a9adf7055ab68039e35cf8effcb488bb2b88353c42129d9abbbce" + "files": 77, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:249d191c99c98e5cfdbe01810eb16fdaa3539578e43f9fa777d9ed6ab0919c47" }, "owner_lane": "", "provenance": { diff --git a/docs/native/PI5-5-CORTEX-RUNS.md b/docs/native/PI5-5-CORTEX-RUNS.md new file mode 100644 index 00000000..6ae02a86 --- /dev/null +++ b/docs/native/PI5-5-CORTEX-RUNS.md @@ -0,0 +1,53 @@ +# PI5-5 Cortex memory on the Raspberry Pi 5 (qualification record) + +Tier: PI5-CORTEX-QUALIFICATION. Image: `make pi5-fact` (the PI5-4 `pi5-unlock-card` image, production-class +Store opened by the Slot 1 recovery secret, plus the Cortex fact stage). It never builds on the TEST-key +store tier. Hardware runs F1 to F3 are NOT_RUN in this document until the Pi is free; the host proof is below. + +## What is reused + +- Cortex store: the canonical Omega store (`third_party/omega/rx_cortex.c`, wrapper `svc/cortex_store.c`) over + the sealed Store journal (`svc/cortex_journal.c`, chunks of kind `CJ`, one record = one sealed transaction). + This is the path the service lifecycle's `remember` and `facts` verbs use (`core/lifecycle.c`, QEMU rows 179 + to 181 of `native/kernel/GATES.md`). The record is the same: one `CX_CLAIM` about subject 0 (the owner), text + packed into 64-bit words, tag = byte length, `t` = record count + 1, generation = the Store generation the + append commits. The two shared constants (`CK_CX_SUBJECTS`, `CK_CX_FACT_SUBJECT`) now live in + `svc/cortex_journal.h` so the lifecycle and the Pi stage cannot drift. +- Store open: PI5-4 (`ck_store_pi5_unlock_run`, recovery secret from `\EFI\AIENOS\UNLOCK.REQ`). + +## What is new + +- `core/fact_req.[ch]`, `native/boot/efi_fact.c`: the labelled card request `\EFI\AIENOS\FACT.REQ` + (QUALIFICATION ONLY, 512 bytes, magic `AIENFCT1`, tag `QUALIF-FACT-DATA`, one fact of 1 to 48 printable + ASCII characters). The UEFI stub reads it before ExitBootServices; the run tool deletes it after the run. + `scripts/pi5_fact_req.sh <out> "<fact>"` writes one. +- `svc/pi5_fact.[ch]`, hook `ck_store_pi5_fact_stage` in `svc/store_boot.c`, run right after the Store stage: + - request present: open or create the journal (one sealed header transaction), append the fact (one sealed + transaction), print `fact_stage: remembered id=.. t=.. store_gen=.. bytes=.. text="..."`, then read it back + (`fact_stage: readback ...`, digest and chain checked). + - no request: replay the journal; print `fact_stage: recalled id=.. t=.. store_gen=.. text="..."` for each fact, + then `fact_stage: recall records=N shown=N newest_id=.. newest_store_gen=.. chain=ok`. No journal on the disk: + `fact_stage: recall none cortex=none records=0`, nothing is created. + - Store refused (wrong recovery secret): `fact_stage: NOTHING RECALLED: the Store is not open ...`; the journal is + not read and a fact request in the same boot is dropped, nothing is written. +- `make pi5-fact` = `CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1`; the Makefile refuses CK_PI5_FACT + without both unlock flags and with CK_PI5_STORE, CK_PI5_INFER or CK_PI5_PCIE. + +## Host proof (file-backed card, `dev/tests/pi5_fact_test.c`, run by `stage-test` and `stage-sanitize`) + +77 checks, ASan + UBSan clean. Every boot reopens the file and starts from a cold C state. Boot 1 (card fact) +remembers `prefer short notes` and prints its Store generation; boot 2 (no request) recalls the same text at the +same generation, adds no record, chain ok; the wrong secret recalls nothing, prints no fact text and leaves the +card byte-identical (also when a fact request comes with it); the right secret afterwards recalls again; a second +fact keeps both in order; a card with no journal says `none` and creates none; the request checker refuses every +malformed layout. Mutation proof (`make -f stage.mk pi5-fact-mutants`): `CK_FACT_MUTANT_NO_APPEND` (the commit +skipped, success still reported) and `CK_FACT_MUTANT_RECALL_BLIND` (recall never reads the journal) both make the +test fail (mutants killed). + +## Pi runs (NOT_RUN) + +F1 remember (boot 1, `FACT.REQ` placed, `UNLOCK.REQ` with secret S), F2 cold-boot recall (power-cycled by the +run tool, `UNLOCK.REQ` with S, no `FACT.REQ`), F3 wrong secret W (no `FACT.REQ`): the fact is not recalled. The +exact commands are in the PR description. Limits: the AIENOS partition holds a PRODUCTION-class Store from PI5-4; +there is no TPM, the secret comes from the card; the anchor shares the disk, so a whole-disk rollback is not +detectable (needs TPM NV or another external counter). diff --git a/native/.crumb b/native/.crumb index 2615b17b..90d91958 100644 --- a/native/.crumb +++ b/native/.crumb @@ -55,8 +55,8 @@ "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "a0fa7029b69edd1b451162c0eee5d816edb1efb37ee972b167b460a0f21f0629", - "last_commit": "e4b583e", + "digest": "929ed085c32fffd1530eb09cec90c2554c7bf0bb02ad70db53cf8cd94761e5f4", + "last_commit": "013dfa6", "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": "e74b106cc74d7a7ee2b3f41b3f1758d6d254f6e240d5d84ee2a80f490d1cd733", - "last_commit": "87b8037", + "digest": "db24cfca50e9f5c96b8bec3858420bb97cc5ddaa4f2d4e2050b3b98ce0a0a660", + "last_commit": "013dfa6", "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:a6db62c83dc48da1518ff86baa4bdd8b30a1de67df5a2c4d600bef48576ea442", - "compiled_at": "2026-10-13T16:35:24Z", + "children_root": "sha256:3a49c1addd1c30a7734661248d997b9f01318df3f2845be392abe186fb1fd9ce", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:3185a027a07a43ff646175b497f190296c275c06c40e1f2b0513eb9af09b07b1", + "digest": "sha256:f497c9f7a4854444dec6fb7a02af1acbcbc2b54f9b02421817271263a7b3cae0", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 529, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:814f2a0be82b29eec99dc35d5841ccdaeb0659a5c6d1e2abbd2036b6f400b6ba" + "files": 535, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:317529d8c8851c09d980a1ba4e131bcded950d15c6e99cfa808b2a2be4ab4019" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index 1d475a8c..cf514536 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:a0fa7029b69edd1b451162c0eee5d816edb1efb37ee972b167b460a0f21f0629", + "digest": "sha256:929ed085c32fffd1530eb09cec90c2554c7bf0bb02ad70db53cf8cd94761e5f4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 19, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:fca5a91929e8d47e6407d601622820b70befacf67f07098ea3e269c63bc2ef4c" + "files": 20, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:d18adafbac793081e6007ae51c691e57290353b4d1ef0866d2fc5e15001b3638" }, "owner_lane": "", "provenance": { diff --git a/native/boot/efi_fact.c b/native/boot/efi_fact.c new file mode 100644 index 00000000..0779af9d --- /dev/null +++ b/native/boot/efi_fact.c @@ -0,0 +1,62 @@ +/* efi_fact.c -- read \EFI\AIENOS\FACT.REQ from the boot volume before ExitBootServices + * (Raspberry Pi 5 Cortex qualification image, CK_PI5_FACT). Nothing is written. The file holds one short + * fact placed by the run tool (native/kernel/core/fact_req.h). Result in ck_fact_req_boot (stub and + * kernel are one image): ABSENT (no file: boot 2 recalls, not an error), REFUSED (printed why), FOUND. */ +#include "efi.h" +#include "../kernel/core/fact_req.h" +#include "../kernel/arch/arch.h" +#include "../kernel/core/ck_internal.h" + +static uint8_t buf[CK_FACT_REQ_SIZE + 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_fact_req_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', '\\', + 'F', 'A', 'C', 'T', '.', 'R', 'E', 'Q', 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_fact_req_boot.state = CK_FACT_REQ_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("fact_req: absent (boot volume not readable); nothing to remember this boot\n"); + return; + } + if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) { + root->Close(root); + ck_puts("fact_req: absent (no " CK_FACT_REQ_PATH "); nothing to remember this boot\n"); + return; + } + wipe_buf(); + uint64_t n = sizeof buf; /* one byte more than the format: a longer file is refused */ + EFI_STATUS s = f->Read(f, &n, buf); + f->Close(f); + root->Close(root); + ck_fact_req_boot.state = CK_FACT_REQ_REFUSED; + if (s != EFI_SUCCESS || n != CK_FACT_REQ_SIZE) { + ck_printf("fact_req: refused (read status=0x%llx bytes=%llu, want exactly %u)\n", (unsigned long long)s, + (unsigned long long)n, (unsigned)CK_FACT_REQ_SIZE); + wipe_buf(); + return; + } + const char *why = 0; + if (ck_fact_req_check((const struct ck_fact_req *)buf, &why)) { + ck_printf("fact_req: refused (%s)\n", why ? why : "malformed"); + wipe_buf(); + return; + } + ck_fact_req_store((const struct ck_fact_req *)buf); + wipe_buf(); + ck_puts("fact_req: found a well-formed request file (QUALIFICATION ONLY, one fact to remember)\n"); +} diff --git a/native/boot/efi_main.c b/native/boot/efi_main.c index 70939417..3279f043 100644 --- a/native/boot/efi_main.c +++ b/native/boot/efi_main.c @@ -41,6 +41,9 @@ int ck_boot_model_load(EFI_HANDLE image, EFI_SYSTEM_TABLE *st, struct ck_handoff #ifdef CK_PI5_UNLOCK_CARD void ck_boot_unlock_req_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st); #endif +#ifdef CK_PI5_FACT +void ck_boot_fact_req_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 @@ -140,6 +143,10 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) #ifdef CK_PI5_UNLOCK_CARD /* Pi qualification unlock image: the throwaway recovery secret request file (efi_unlock.c). */ ck_boot_unlock_req_find(image, st); +#endif +#ifdef CK_PI5_FACT + /* PI5-5 qualification image: the one-fact request file (efi_fact.c). */ + ck_boot_fact_req_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 aff955ae..47d4b74b 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": "a11644b4a41b1271abc62a97c1c3e8197ed5a14a572854957de19e5b58d0aef3", - "last_commit": "e4b583e", + "digest": "7d244641327a07e507217ef39fafe416f7d0b970dd1c8121a73c77034703be16", + "last_commit": "013dfa6", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { - "digest": "300982b2d7ddbdc225d86b0ca28c5ca94546f209f62ba2bdccff19b1018ffd37", - "last_commit": "87b8037", + "digest": "a80356e38bcc9fc135fffc058dc782bc2fc4f56869f6e06caaf0c2e169338212", + "last_commit": "013dfa6", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, @@ -81,33 +81,33 @@ "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { - "digest": "1269af87b047348f0eec4bf57ba98cbff4fd643a8bb7a619fa1771183c95cf17", - "last_commit": "e52f104", + "digest": "11e19f80d8332984392eda3141fe2a5b50b9032fbb4d1ace6aabf29e445cf9ab", + "last_commit": "013dfa6", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "9e5198a69ae2ce95ae1ab8a0f0c770806678dfd5098c03d1f58eced3f4e2e5e9", - "last_commit": "e4b583e", + "last_commit": "b03a06b", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "b95fb9d4f0446d87fdd8ea5a3e22bb7678fc2dcb68c72d82c1c07d0de2bd9921", - "last_commit": "87b8037", + "last_commit": "b03a06b", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:17b2657d1ef477d7bbc5bbb62c91f5d9c311237ca46498853de57ed38578f0d0", - "compiled_at": "2026-10-13T16:35:24Z", + "children_root": "sha256:295cee93e4b0844f124c3fc8d605f23e81116d11348d211f13cc3d9d19fec303", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:e74b106cc74d7a7ee2b3f41b3f1758d6d254f6e240d5d84ee2a80f490d1cd733", + "digest": "sha256:db24cfca50e9f5c96b8bec3858420bb97cc5ddaa4f2d4e2050b3b98ce0a0a660", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 351, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:839164f315fade1a6bb65cb60f05a89b10e21aa252ce0b566d1d674d39b7cc25" + "files": 356, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:61283ac374ac07b5b45578895c16005cd00bd3e187c7234ea63c086221ecf736" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 206a2982..0e398fe1 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -219,12 +219,31 @@ 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) +OUT ?= $(REPO)/target/native-kernel-pi5-unlock$(if $(strip $(CK_PI5_UNLOCK_CARD)),-card)$(if $(strip $(CK_PI5_FACT)),-fact) CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK=1 ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) CK_EXTRA_CFLAGS += -DCK_PI5_UNLOCK_CARD=1 endif endif + +# Pi Cortex fact image (CK_PI5_FACT=1, "make pi5-fact", PI5-5): the Pi unlock-card image (production-class Store +# opened by the Slot 1 recovery secret from the card request file) plus the Cortex fact stage (svc/pi5_fact.c): a +# fact from \EFI\AIENOS\FACT.REQ (QUALIFICATION ONLY, core/fact_req.h) is appended to the Cortex journal of the +# sealed Store, and a boot without that file recalls it. It needs CK_PI5_UNLOCK=1 and CK_PI5_UNLOCK_CARD=1, refuses +# every other tier flag and has its own OUT. +CK_PI5_FACT ?= +ifneq ($(strip $(CK_PI5_FACT)),) +ifneq ($(strip $(CK_PI5_FACT)),1) +$(error CK_PI5_FACT must be empty or 1) +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)),) +$(error CK_PI5_FACT cannot be combined with CK_PI5_STORE, CK_PI5_INFER or CK_PI5_PCIE) +endif +CK_EXTRA_CFLAGS += -DCK_PI5_FACT=1 +endif CK_PI5 ?= ifneq ($(strip $(CK_PI5)),) ifneq ($(strip $(CK_PI5)),1) @@ -749,6 +768,9 @@ endif ifneq ($(strip $(CK_PI5_UNLOCK_CARD)),) CORE_C += $(BOOT)/efi_unlock.c $(KDIR)/core/unlock_req.c endif +ifneq ($(strip $(CK_PI5_FACT)),) +CORE_C += $(BOOT)/efi_fact.c $(KDIR)/core/fact_req.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. @@ -863,10 +885,13 @@ 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),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),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) +ifneq ($(strip $(CK_PI5_FACT)),) +STAGE_SRCS += $(KDIR)/svc/pi5_fact.c $(STAGE_CORTEX_SRCS) +endif endif FULL_OUT := $(OUT)/$(FULL_NAME) STAGE_KOBJ := $(OUT)/obj/stage-$(FULL_NAME) @@ -1905,6 +1930,9 @@ pi5-unlock: pi5-unlock-card: $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 full +pi5-fact: + $(MAKE) CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1 full + pi5: $(MAKE) CK_PI5=1 all @@ -1960,7 +1988,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 test sanitize 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 test sanitize 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 685422d2..0e79a8e6 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-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:a11644b4a41b1271abc62a97c1c3e8197ed5a14a572854957de19e5b58d0aef3", + "digest": "sha256:7d244641327a07e507217ef39fafe416f7d0b970dd1c8121a73c77034703be16", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 57, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:117d9b2086cde94d2e022444a24ed85f9ce1f03e563fbd25cdaa743b5a572f6a" + "files": 59, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:a9f76afbb883d34ef2a04e2b744783beca6b2cb0d6a931ffd0a7a7a6c13145c1" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/fact_req.c b/native/kernel/core/fact_req.c new file mode 100644 index 00000000..a94eb1b9 --- /dev/null +++ b/native/kernel/core/fact_req.c @@ -0,0 +1,77 @@ +/* fact_req.c -- see fact_req.h. */ +#include "fact_req.h" + +struct ck_fact_req_boot ck_fact_req_boot; + +int ck_fact_req_check(const struct ck_fact_req *q, const char **why) +{ + const char *w = 0; + const uint8_t *p = (const uint8_t *)q; + if (!q) { + w = "no request"; + goto out; + } + for (unsigned i = 0; i < 8; i++) + if (q->magic[i] != (uint8_t)CK_FACT_REQ_MAGIC[i]) { + w = "bad magic"; + goto out; + } + if (q->version != CK_FACT_REQ_VERSION) { + w = "bad version"; + goto out; + } + if (q->flags != 0) { + w = "flags must be zero"; + goto out; + } + for (unsigned i = 0; i < 16; i++) + if (q->tag[i] != (uint8_t)CK_FACT_REQ_TAG[i]) { + w = "tier tag is not QUALIF-FACT-DATA"; + goto out; + } + if (q->len < 1 || q->len > CK_FACT_REQ_TEXT_MAX) { + w = "fact length must be 1..48"; + goto out; + } + if (q->reserved != 0) { + w = "reserved must be zero"; + goto out; + } + for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) { + if (i < q->len) { + if (q->text[i] < 0x20 || q->text[i] > 0x7e) { + w = "fact text must be printable ASCII"; + goto out; + } + } else if (q->text[i] != 0) { + w = "text past the length is not zero"; + goto out; + } + } + for (unsigned i = 88; i < CK_FACT_REQ_SIZE; i++) + if (p[i] != 0) { + w = "padding is not zero"; + goto out; + } +out: + if (why) + *why = w; + return w ? -1 : 0; +} + +void ck_fact_req_store(const struct ck_fact_req *q) +{ + ck_fact_req_boot.len = q->len; + for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) + ck_fact_req_boot.text[i] = q->text[i]; + ck_fact_req_boot.state = CK_FACT_REQ_FOUND; +} + +void ck_fact_req_clear(void) +{ + ck_fact_req_boot.len = 0; + for (unsigned i = 0; i < CK_FACT_REQ_TEXT_MAX; i++) + ck_fact_req_boot.text[i] = 0; + if (ck_fact_req_boot.state == CK_FACT_REQ_FOUND) + ck_fact_req_boot.state = CK_FACT_REQ_NONE; +} diff --git a/native/kernel/core/fact_req.h b/native/kernel/core/fact_req.h new file mode 100644 index 00000000..53837c58 --- /dev/null +++ b/native/kernel/core/fact_req.h @@ -0,0 +1,58 @@ +/* fact_req.h -- the card fact request file of the Pi Cortex qualification image + * (PI5-5, build flag CK_PI5_FACT, 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\FACT.REQ on the card's EFI partition holding ONE short fact. The UEFI stub + * (native/boot/efi_fact.c) reads it before ExitBootServices; after the Store is open the fact stage + * (svc/pi5_fact.c) appends it to the Cortex journal of the sealed Store, the same record + * `remember <text>` writes in the service lifecycle. The run tool deletes the file after the run. + * A fact is not a secret, but the file is still a labelled qualification input, not a user interface. + * + * File layout, exactly 512 bytes, little endian, everything else zero: + * 0 magic "AIENFCT1" + * 8 version 1 + * 12 flags 0 + * 16 tag "QUALIF-FACT-DATA" (16 ASCII bytes, no NUL) + * 32 length of the fact, 1..48 + * 36 reserved 0 + * 40 fact text, printable ASCII 0x20..0x7e, `length` bytes, then zero to byte 88 + * 88 zero padding to 512 */ +#ifndef AIENOS_CK_FACT_REQ_H +#define AIENOS_CK_FACT_REQ_H +#include <stddef.h> +#include <stdint.h> + +#define CK_FACT_REQ_MAGIC "AIENFCT1" +#define CK_FACT_REQ_TAG "QUALIF-FACT-DATA" +#define CK_FACT_REQ_VERSION 1u +#define CK_FACT_REQ_SIZE 512u +#define CK_FACT_REQ_TEXT_MAX 48u +#define CK_FACT_REQ_PATH "\\EFI\\AIENOS\\FACT.REQ" + +struct ck_fact_req { + uint8_t magic[8]; + uint32_t version; + uint32_t flags; + uint8_t tag[16]; + uint32_t len; + uint32_t reserved; + uint8_t text[CK_FACT_REQ_TEXT_MAX]; + uint8_t pad[CK_FACT_REQ_SIZE - 88]; +}; + +/* 0 = well formed; else -1 and *why names the first failed check. */ +int ck_fact_req_check(const struct ck_fact_req *q, const char **why); + +enum { CK_FACT_REQ_NONE = 0, CK_FACT_REQ_ABSENT = 1, CK_FACT_REQ_REFUSED = 2, CK_FACT_REQ_FOUND = 3 }; + +/* What the UEFI stub found (the stub and the kernel are one image). */ +struct ck_fact_req_boot { + int state; /* CK_FACT_REQ_* */ + uint32_t len; /* only while FOUND */ + uint8_t text[CK_FACT_REQ_TEXT_MAX]; /* only while FOUND */ +}; +extern struct ck_fact_req_boot ck_fact_req_boot; + +void ck_fact_req_store(const struct ck_fact_req *q); /* the stub stores a checked request */ +void ck_fact_req_clear(void); /* one-shot: the fact stage wipes it after use */ +#endif diff --git a/native/kernel/core/lifecycle.c b/native/kernel/core/lifecycle.c index a4b0832e..b4d7555e 100644 --- a/native/kernel/core/lifecycle.c +++ b/native/kernel/core/lifecycle.c @@ -90,8 +90,6 @@ static uint64_t g_last_gen; static unsigned g_overlong; /* The Cortex store over the sealed Store (P06 cuts 3 and 4). */ -#define CK_CX_SUBJECTS 2u /* subject 0: the owner (facts); 1: reserved for ALLEN */ -#define CK_CX_FACT_SUBJECT 0u #define CK_CX_FACTS_SHOWN 16u /* `facts` lists at most the newest 16 */ #define CK_CX_HEAP_BYTES (CK_CX_HEAP_PAGES * 4096u) static ck_cj g_cj; diff --git a/native/kernel/dev/.crumb b/native/kernel/dev/.crumb index 9e4ba757..6bf2e421 100644 --- a/native/kernel/dev/.crumb +++ b/native/kernel/dev/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:300982b2d7ddbdc225d86b0ca28c5ca94546f209f62ba2bdccff19b1018ffd37", + "digest": "sha256:a80356e38bcc9fc135fffc058dc782bc2fc4f56869f6e06caaf0c2e169338212", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 37, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:6821178973f9af920bf1ac64c4559a38d24123b3e8803419ed931731bbd94d28" + "files": 38, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:e54dedd48e0569396d3df6353fe27cedb3fe0da29c39822fa811717d69f8968b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/dev/tests/pi5_fact_test.c b/native/kernel/dev/tests/pi5_fact_test.c new file mode 100644 index 00000000..5c0f0e73 --- /dev/null +++ b/native/kernel/dev/tests/pi5_fact_test.c @@ -0,0 +1,240 @@ +/* pi5_fact_test.c -- AIENOS PI5-5 host test: the Pi Cortex fact stage (svc/pi5_fact.c, hooked by + * svc/store_boot.c ck_store_pi5_fact_stage, compiled with -DCK_PI5_UNLOCK -DCK_PI5_UNLOCK_CARD -DCK_PI5_FACT + * exactly as "make pi5-fact" builds it) over the Pi card layout. A file stands in for the card; every "boot" + * reopens the file and starts from a cold C state (no Store or Cortex object survives between boots). + * + * Proves: boot 1 (card fact request) stores a fact into the sealed Store through the Cortex journal and + * prints it with the Store generation that committed it; boot 2 (no request) recalls the same text and the + * same generation from the disk, writes no new fact and verifies the chain; a third boot with a second fact + * keeps both in order; a boot with the wrong recovery secret recalls nothing, prints no fact text and writes + * nothing; the right secret afterwards still recalls; a card with no journal says "none" and creates none; + * the request file checker refuses every malformed layout. Built with -DCK_FACT_MUTANT_NO_APPEND (the commit + * skipped) or -DCK_FACT_MUTANT_RECALL_BLIND (recall never reads the journal) this test must FAIL. + * Hosted test code only. */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "ck.h" +#include "ck_host.h" +#include "disk_file.h" +#include "disk_layout.h" +#include "disk_part.h" +#include "gpt_write.h" +#include "../../core/pi5_marker.h" +#include "m5.h" +#include "store_boot.h" +#include "../../core/unlock_req.h" +#include "../../core/fact_req.h" +#include "../../svc/pi5_fact.h" + +#if !defined(CK_PI5_UNLOCK) || !defined(CK_PI5_FACT) +#error "pi5_fact_test.c must be built with -DCK_PI5_UNLOCK -DCK_PI5_FACT (the image's policy)" +#endif + +static int checks, failures; +#define CHECK(c) \ + do { \ + checks++; \ + if (!(c)) { \ + failures++; \ + printf(" FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); \ + } \ + } while (0) + +extern int ck_host_entropy_refuse; +int ck_pi5_unlock_secret(uint8_t out[CK_SB_SECRET_LEN], const char **source) +{ + (void)out; + (void)source; + return -1; +} + +#define BLOCKS 262144ull +#define PART_FIRST 8192u +#define PART_SECS 8192u +static char g_path[256]; + +/* One boot: open the card file, run the Store stage exactly as ck_stage_store does (unlock policy, then the + * fact hook), close the card. text NULL: no request file this boot (the stub says ABSENT). Output captured. */ +static int boot(const uint8_t *secret, const char *text, ck_store_report *r, char **cap) +{ + disk_file f; + disk_dev d; + ck_part p, sp; + ck_gpt_info gi; + if (disk_file_open(&f, &d, g_path, 512, 0, 0)) return -9999; + if (ck_gpt_find_aienos(&d, &p, &gi) || ck_pi5_store_view(&p, &sp)) { disk_file_close(&f); return -9998; } + memset(&ck_fact_req_boot, 0, sizeof ck_fact_req_boot); + if (text) { + struct ck_fact_req q; + const char *why = 0; + memset(&q, 0, sizeof q); + memcpy(q.magic, CK_FACT_REQ_MAGIC, 8); + q.version = CK_FACT_REQ_VERSION; + memcpy(q.tag, CK_FACT_REQ_TAG, 16); + q.len = (uint32_t)strlen(text); + memcpy(q.text, text, q.len); + CHECK(ck_fact_req_check(&q, &why) == 0); + ck_fact_req_store(&q); + } else { + ck_fact_req_boot.state = CK_FACT_REQ_ABSENT; + } + ck_host_quiet = 1; + ck_host_capture_start(); + int rc = ck_store_pi5_unlock_run(&sp.dev, secret, "pi5-fact-test", r); + int frc = ck_store_pi5_fact_stage(r); + CHECK(frc == 0); + *cap = strdup(ck_host_capture_text()); + ck_host_capture_stop(); + ck_host_quiet = 0; + CHECK(ck_fact_req_boot.state != CK_FACT_REQ_FOUND); /* the request is single use per boot */ + disk_file_close(&f); + return rc; +} + +static uint8_t *slurp(size_t *n) +{ + FILE *fp = fopen(g_path, "rb"); + CHECK(fp != 0); + if (!fp) { *n = 0; return 0; } + fseek(fp, 0, SEEK_END); + *n = (size_t)ftell(fp); + rewind(fp); + uint8_t *m = malloc(*n); + CHECK(m && fread(m, 1, *n, fp) == *n); + fclose(fp); + return m; +} + +/* "key=NNN" after the first occurrence of `after` in s; 0 when absent. */ +static unsigned long long num_after(const char *s, const char *after, const char *key) +{ + const char *p = strstr(s, after); + if (!p) return 0; + p = strstr(p, key); + if (!p) return 0; + return strtoull(p + strlen(key), 0, 10); +} + +static void req_with(struct ck_fact_req *q) +{ + memset(q, 0, sizeof *q); + memcpy(q->magic, CK_FACT_REQ_MAGIC, 8); + q->version = CK_FACT_REQ_VERSION; + memcpy(q->tag, CK_FACT_REQ_TAG, 16); + q->len = 5; + memcpy(q->text, "hello", 5); +} + +int main(void) +{ + snprintf(g_path, sizeof g_path, "/tmp/aienos-pi5-fact-test-%d.img", (int)getpid()); + gw_part gp[2] = {{gw_esp_type, 2048, 4095, "AIENOSPI5-ESP", 0x5a}, {ck_aienos_part_type, PART_FIRST, PART_FIRST + PART_SECS - 1, "AIENOS", 0}}; + CHECK(gw_write(g_path, 512, BLOCKS, gp, 2, 0) == 0); + uint8_t S[CK_SB_SECRET_LEN], W[CK_SB_SECRET_LEN]; + for (int i = 0; i < 32; i++) S[i] = (uint8_t)(i * 7 + 5); + memcpy(W, S, 32); + W[31] ^= 0x80; + ck_store_report r; + char *c1, *c2, *c3, *c4, *c5; + size_t n0, n1; + uint8_t *b, *a; + const char *FACT = "prefer short notes"; + + /* 0. The request file checker. */ + { + struct ck_fact_req q; + const char *why = 0; + req_with(&q); + CHECK(ck_fact_req_check(&q, &why) == 0 && why == 0); + req_with(&q); q.magic[0] = 'X'; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.version = 2; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.flags = 1; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.tag[0] = 'q'; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.len = 0; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.len = 49; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.reserved = 1; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.text[1] = 0x07; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.text[7] = 'z'; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.pad[0] = 1; CHECK(ck_fact_req_check(&q, &why) != 0); + req_with(&q); q.len = 48; memset(q.text, 'a', 48); CHECK(ck_fact_req_check(&q, &why) == 0); + CHECK(ck_fact_req_check(0, &why) != 0); + } + + /* 1. Blank card, no request: the Store is created, recall says none, no journal is created. */ + CHECK(boot(S, 0, &r, &c1) == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 1); + CHECK(strstr(c1, "fact_stage: recall none cortex=none records=0")); + CHECK(!strstr(c1, "cortex open")); + free(c1); + + /* 2. Boot 1 (F1): the card request stores a fact through the Cortex journal. */ + CHECK(boot(S, FACT, &r, &c1) == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 0); + CHECK(strstr(c1, "fact_stage: cortex open records=0 chunks=1")); + CHECK(strstr(c1, "fact_stage: remembered id=1 t=1 ")); + CHECK(strstr(c1, "bytes=18 text=\"prefer short notes\"")); + CHECK(strstr(c1, "fact_stage: readback id=1 t=1 ")); + CHECK(strstr(c1, "fact_stage: remember records=1 shown=1 newest_id=1")); + CHECK(strstr(c1, "chain=ok")); + unsigned long long gen1 = num_after(c1, "fact_stage: remembered", "store_gen="); + CHECK(gen1 > 0); + CHECK(num_after(c1, "fact_stage: readback", "store_gen=") == gen1); + + /* 3. Boot 2 (F2): cold start, no request file: the same fact and generation come back from the disk. */ + b = slurp(&n0); + CHECK(boot(S, 0, &r, &c2) == 0 && r.verdict == CK_SB_COMMITTED && r.formatted == 0); + CHECK(strstr(c2, "fact_stage: cortex open records=1 chunks=2")); + CHECK(strstr(c2, "fact_stage: recalled id=1 t=1 ")); + CHECK(strstr(c2, "text=\"prefer short notes\"")); + CHECK(num_after(c2, "fact_stage: recalled", "store_gen=") == gen1); + CHECK(strstr(c2, "fact_stage: recall records=1 shown=1 newest_id=1")); + CHECK(strstr(c2, "chain=ok")); + CHECK(!strstr(c2, "remembered") && !strstr(c2, "readback")); + a = slurp(&n1); + CHECK(n0 == n1); /* a recall adds no fact; only the boot record advanced */ + free(a); + free(b); + + /* 4. Negative control (F3): the wrong recovery secret opens nothing, recalls nothing, writes nothing. */ + b = slurp(&n0); + CHECK(boot(W, 0, &r, &c3) == CK_SB_E_SECRET_REJECTED && r.verdict == CK_SB_REFUSED); + a = slurp(&n1); + CHECK(n0 == n1 && memcmp(b, a, n0) == 0); + CHECK(strstr(c3, "fact_stage: NOTHING RECALLED")); + CHECK(!strstr(c3, "prefer short notes") && !strstr(c3, "recalled id=") && !strstr(c3, "cortex open")); + free(a); + free(b); + /* a wrong secret together with a request file also writes nothing (the request is dropped) */ + b = slurp(&n0); + CHECK(boot(W, "must not be stored", &r, &c4) == CK_SB_E_SECRET_REJECTED); + a = slurp(&n1); + CHECK(memcmp(b, a, n0) == 0 && strstr(c4, "NOTHING RECALLED") && !strstr(c4, "must not be stored")); + free(a); + free(b); + + /* 5. The right secret still recalls after the refusals; a second fact keeps both, in order. */ + CHECK(boot(S, "second fact", &r, &c5) == 0); + CHECK(strstr(c5, "fact_stage: remembered id=2 t=2 ")); + CHECK(strstr(c5, "fact_stage: readback id=1 ") && strstr(c5, "fact_stage: readback id=2 ")); + free(c5); + CHECK(boot(S, 0, &r, &c5) == 0); + { + const char *p1 = strstr(c5, "recalled id=1 "); + const char *p2 = strstr(c5, "recalled id=2 "); + CHECK(p1 && p2 && p1 < p2); + CHECK(strstr(c5, "text=\"prefer short notes\"") && strstr(c5, "text=\"second fact\"")); + CHECK(strstr(c5, "fact_stage: recall records=2 shown=2")); + } + free(c5); + + free(c1); + free(c2); + free(c3); + free(c4); + memset(S, 0, sizeof S); + memset(W, 0, sizeof W); + unlink(g_path); + printf("pi5_fact_test: %d checks, %d failures\n", checks, failures); + printf("CK_PI5_FACT_HOST: %s\n", failures ? "FAIL" : "PASS"); + return failures ? 1 : 0; +} diff --git a/native/kernel/stage.mk b/native/kernel/stage.mk index 66f55f70..a498dc2d 100644 --- a/native/kernel/stage.mk +++ b/native/kernel/stage.mk @@ -201,3 +201,29 @@ $(STAGE_OUT)/ck_pi5_store_locate: $(PI5_LOCATE_TOOL_SRCS) $(STAGE_DIR)/tools/ck_ $(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 .PHONY: pi5-store-locate pi5-store-locate: $(STAGE_OUT)/ck_pi5_store_locate + +# ---- AIENOS PI5-5: the Pi Cortex fact stage (dev/tests/pi5_fact_test.c) ---- +# store_boot.c is compiled with -DCK_PI5_UNLOCK -DCK_PI5_UNLOCK_CARD -DCK_PI5_FACT, as "make pi5-fact" builds it. +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 +PI5_FACT_DEPS := $(PI5_FACT_TEST_SRCS) $(DISK_PART_TEST_DEPS) $(STAGE_DIR)/core/fact_req.h $(STAGE_DIR)/svc/pi5_fact.h +PI5_FACT_FLAGS := -DCK_PI5_UNLOCK=1 -DCK_PI5_UNLOCK_CARD=1 -DCK_PI5_FACT=1 +$(STAGE_OUT)/pi5_fact_test: $(PI5_FACT_DEPS) + @mkdir -p $(@D) + $(STAGE_CC) $(STAGE_HOST_FLAGS) $(PI5_FACT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_FACT_TEST_SRCS) +$(STAGE_OUT)/pi5_fact_test_san: $(PI5_FACT_DEPS) + @mkdir -p $(@D) + $(STAGE_CC) $(STAGE_HOST_FLAGS) $(STAGE_SAN_FLAGS) $(PI5_FACT_FLAGS) $(DISK_PART_INC) -o $@ $(PI5_FACT_TEST_SRCS) +.PHONY: pi5-fact-test pi5-fact-sanitize pi5-fact-mutants +pi5-fact-test: $(STAGE_OUT)/pi5_fact_test + $< +pi5-fact-sanitize: $(STAGE_OUT)/pi5_fact_test_san + ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 $< +# Mutation proof: each TEST-ONLY mutant of the fact stage must make the host test FAIL. +pi5-fact-mutants: + @mkdir -p $(STAGE_OUT); fail=0; \ + for m in NO_APPEND RECALL_BLIND; do \ + $(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; \ + if $(STAGE_OUT)/pi5_fact_test_mut_$$m >/dev/null; then echo "MUTANT SURVIVED: $$m"; fail=1; else echo "mutant killed: $$m"; fi; \ + done; exit $$fail +stage-test: pi5-fact-test +stage-sanitize: pi5-fact-sanitize diff --git a/native/kernel/svc/.crumb b/native/kernel/svc/.crumb index fdf46f44..d980d3ee 100644 --- a/native/kernel/svc/.crumb +++ b/native/kernel/svc/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:d835471b1405ca482a41beb34ed339d21e11064a59138599ee5754d198926878", - "compiled_at": "2026-10-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:1269af87b047348f0eec4bf57ba98cbff4fd643a8bb7a619fa1771183c95cf17", + "digest": "sha256:11e19f80d8332984392eda3141fe2a5b50b9032fbb4d1ace6aabf29e445cf9ab", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 43, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:f9821387dc747782d77349245ac1145e74fc8da871f0aca910d16863c9af185f" + "files": 45, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:f0980993d2cb977ee81d799f40ad44096f3a996c1a6b82a6963403724a97153e" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/svc/cortex_journal.h b/native/kernel/svc/cortex_journal.h index bdd73c8d..0e84aab3 100644 --- a/native/kernel/svc/cortex_journal.h +++ b/native/kernel/svc/cortex_journal.h @@ -38,6 +38,8 @@ #define CK_CJ_MAX_CHUNKS 64u /* 1 MiB of journal */ #define CK_CJ_MAX_RECORD (SS_MAX_OBJECTS * SS_MAX_PLAINTEXT) /* 128 KiB per append */ #define CK_CX_HEAP_PAGES 1024u /* 4 MiB: the whole journal plus its replay */ +#define CK_CX_SUBJECTS 2u /* subject 0: the owner (facts); 1: reserved for ALLEN */ +#define CK_CX_FACT_SUBJECT 0u /* remembered facts: lifecycle `remember` and the Pi fact stage */ typedef struct { uint8_t sid[32]; diff --git a/native/kernel/svc/pi5_fact.c b/native/kernel/svc/pi5_fact.c new file mode 100644 index 00000000..8fad086a --- /dev/null +++ b/native/kernel/svc/pi5_fact.c @@ -0,0 +1,139 @@ +/* pi5_fact.c -- see pi5_fact.h. */ +#include "pi5_fact.h" +#include <stddef.h> +#include "ck.h" +#include "cortex_journal.h" + +#define FACT_HEAP_BYTES (512u * 1024u) /* replay of a journal of a few facts peaks well below this */ +static uint8_t g_heap[FACT_HEAP_BYTES] __attribute__((aligned(16))); +static ck_cj g_cj; +static CxStore g_cx; + +static uint32_t journal_chunks(const ss_store *s) +{ + uint32_t k, n = 0; + for (k = 0; k < s->nclaims; k++) + if (s->ws->claims[k].c.obj.object_kind == CK_CJ_KIND) n++; + return n; +} + +static void show(char *out, const uint8_t *b, size_t n) +{ + for (size_t i = 0; i < n; i++) out[i] = (b[i] >= 0x20 && b[i] <= 0x7e) ? (char)b[i] : '?'; + out[n] = 0; +} + +/* Same record as core/lifecycle.c remember(): payload = text packed into little-endian 64-bit words, + * tag = byte length, t = record count + 1, generation = the Store generation this append commits. */ +static int remember(ss_store *s, const struct ck_fact_req_boot *req) +{ + uint64_t pay[(CK_FACT_REQ_TEXT_MAX + 7) / 8]; + uint32_t nw = (req->len + 7) / 8, i; + CxHeader h; + uint64_t id = 0; + for (i = 0; i < nw; i++) pay[i] = 0; + for (i = 0; i < req->len; i++) pay[i / 8] |= (uint64_t)req->text[i] << (8 * (i % 8)); + for (i = 0; i < sizeof h; i++) ((uint8_t *)&h)[i] = 0; + h.cls = CX_CLAIM; + h.kind = CX_K_CLAIM; + h.subject = CK_CX_FACT_SUBJECT; + h.t = g_cx.n + 1; + h.generation = ss_generation(s) + 1; + h.tag = req->len; +#ifdef CK_FACT_MUTANT_NO_APPEND + /* TEST-ONLY mutant: skip the commit but still report success. */ + int rc = CX_OK; + id = g_cx.n + 1; +#else + int rc = cx_append(&g_cx, &h, pay, nw, &id); +#endif + if (rc != CX_OK) { + ck_printf("fact_stage: REFUSED remember rc=%d reason=\"cortex append failed, nothing written\"\n", rc); + return -1; + } + { + char shown[CK_FACT_REQ_TEXT_MAX + 1]; + show(shown, req->text, req->len); + ck_printf("fact_stage: remembered id=%llu t=%llu store_gen=%llu bytes=%u text=\"%s\"\n", + (unsigned long long)id, (unsigned long long)h.t, (unsigned long long)ss_generation(s), + (unsigned)req->len, shown); + } + return 0; +} + +/* Every fact, oldest first (label "readback" right after a remember in the same boot, "recalled" on a later boot), each read back through cx_recall_id (digest re-checked); then the chain. */ +static int recall(ss_store *s, struct ck_fact_result *out, const char *label) +{ + static CxRecord r; + uint64_t id; + (void)s; + for (id = 1; id <= g_cx.n; id++) { + uint8_t text[CK_FACT_REQ_TEXT_MAX]; + char shown[CK_FACT_REQ_TEXT_MAX + 1]; + size_t len, i; + if (cx_recall_id(&g_cx, id, &r) != CX_OK || !r.verified) { + ck_printf("fact_stage: fact id=%llu DIGEST_FAIL\n", (unsigned long long)id); + continue; + } + if (r.hdr.cls != CX_CLAIM || r.hdr.kind != CX_K_CLAIM || r.hdr.subject != CK_CX_FACT_SUBJECT) continue; + len = (size_t)r.hdr.tag; + if (len > sizeof text || len > (size_t)r.hdr.n * 8) len = 0; + for (i = 0; i < len; i++) text[i] = (uint8_t)(r.payload[i / 8] >> (8 * (i % 8))); + show(shown, text, len); + ck_printf("fact_stage: %s id=%llu t=%llu store_gen=%llu text=\"%s\"\n", label, (unsigned long long)id, + (unsigned long long)r.hdr.t, (unsigned long long)r.hdr.generation, shown); + out->shown++; + out->last_id = id; + out->last_gen = r.hdr.generation; + } + return 0; +} + +int ck_pi5_fact_run(ss_store *s, const struct ck_fact_req_boot *req, struct ck_fact_result *out) +{ + struct ck_fact_result z = {0}; + int want_write = req && req->state == CK_FACT_REQ_FOUND; + int rc; + *out = z; + if (!s) { + out->mode = CK_FACT_MODE_NOSTORE; + ck_puts("fact_stage: NOTHING RECALLED: the Store is not open (recovery secret missing or rejected, or the disk " + "was refused); no Cortex was read, nothing was written\n"); + return 0; + } + out->mode = want_write ? CK_FACT_MODE_REMEMBER : CK_FACT_MODE_RECALL; +#ifdef CK_FACT_MUTANT_RECALL_BLIND + /* TEST-ONLY mutant: recall never looks at the journal. */ + if (!want_write) { +#else + if (!want_write && journal_chunks(s) == 0) { +#endif + ck_puts("fact_stage: recall none cortex=none records=0 (no journal on this disk; nothing created)\n"); + out->chain_ok = 1; + return 0; + } + ck_cx_heap_init(g_heap, sizeof g_heap); + ck_cj_init(&g_cj, s); + rc = cx_open_with(&g_cx, &ck_cx_journal_store, &g_cj, "cortex", CK_CX_SUBJECTS, 0); + if (rc != CX_OK) { + ck_printf("fact_stage: REFUSED cortex open rc=%d chunks=%u\n", rc, journal_chunks(s)); + return -1; + } + ck_printf("fact_stage: cortex open records=%llu chunks=%u journal_bytes=%u store_gen=%llu chain=%s\n", + (unsigned long long)g_cx.n, g_cj.nchunks, (unsigned)g_cj.len, (unsigned long long)ss_generation(s), + cx_verify_chain(&g_cx) == CX_OK ? "ok" : "FAIL"); + rc = want_write ? remember(s, req) : 0; + if (rc == 0) { + /* Read everything back the way a cold boot would: from the journal replayed at open (remember + * appended to the open store, which is the same state a replay rebuilds). */ + rc = recall(s, out, want_write ? "readback" : "recalled"); + } + out->records = g_cx.n; + out->chain_ok = cx_verify_chain(&g_cx) == CX_OK; + ck_printf("fact_stage: %s records=%llu shown=%llu newest_id=%llu newest_store_gen=%llu journal_bytes=%u chain=%s\n", + want_write ? "remember" : "recall", (unsigned long long)out->records, (unsigned long long)out->shown, + (unsigned long long)out->last_id, (unsigned long long)out->last_gen, (unsigned)g_cj.len, + out->chain_ok ? "ok" : "FAIL"); + cx_close(&g_cx); + return rc; +} diff --git a/native/kernel/svc/pi5_fact.h b/native/kernel/svc/pi5_fact.h new file mode 100644 index 00000000..5650088d --- /dev/null +++ b/native/kernel/svc/pi5_fact.h @@ -0,0 +1,32 @@ +/* pi5_fact.h -- the Pi 5 Cortex fact stage (PI5-5, CK_PI5_FACT, QUALIFICATION ONLY). + * + * After the Store stage opened the sealed Store through the Slot 1 recovery path, this stage does what + * the service lifecycle's `remember` and `facts` verbs do (core/lifecycle.c, QEMU rows 179-181), with + * the same Cortex records on the same journal ('CJ' chunks, one record = one sealed transaction): + * - a fact request from the card (core/fact_req.h): open or create the journal, append one CX_CLAIM + * about the owner subject, read it back, print it with the Store generation that committed it; + * - no request: replay the journal, re-check every digest and the chain, print each fact with the + * Store generation it was committed at. A disk with no journal prints "none" and writes nothing. + * The Store not being open (wrong recovery secret) prints the refusal and recalls nothing. */ +#ifndef AIENOS_CK_PI5_FACT_H +#define AIENOS_CK_PI5_FACT_H +#include "store_sealed.h" +#include "../core/fact_req.h" + +enum { CK_FACT_MODE_REMEMBER = 1, CK_FACT_MODE_RECALL = 2, CK_FACT_MODE_NOSTORE = 3 }; + +struct ck_fact_result { + int mode; /* CK_FACT_MODE_* */ + uint64_t records; /* Cortex records in the journal after the stage */ + uint64_t shown; /* facts printed */ + uint64_t last_id; /* newest fact id (0: none) */ + uint64_t last_gen; /* Store generation that committed the newest fact */ + int chain_ok; +}; + +/* s: the open writable Store, or NULL when the Store is not open. req: the card request (state FOUND + * remembers it; any other state recalls). Returns 0 when the stage did what the mode says; <0 on a + * Cortex or Store failure (printed). NULL s returns 0 with mode NOSTORE (a refusal, not a failure of + * this stage). */ +int ck_pi5_fact_run(ss_store *s, const struct ck_fact_req_boot *req, struct ck_fact_result *out); +#endif diff --git a/native/kernel/svc/store_boot.c b/native/kernel/svc/store_boot.c index 4e3ec30b..c204fcf9 100644 --- a/native/kernel/svc/store_boot.c +++ b/native/kernel/svc/store_boot.c @@ -9,6 +9,9 @@ #include "store_v1.h" #include "store_crash.h" #include "continuity_boot.h" +#ifdef CK_PI5_FACT +#include "pi5_fact.h" +#endif #ifdef CK_SERVICE #include "continuity_service.h" #endif @@ -735,6 +738,19 @@ int ck_store_pi5_unlock_run(const disk_dev *d, const uint8_t *secret, const char } #endif +#ifdef CK_PI5_FACT +#if !defined(CK_PI5_UNLOCK) || !defined(CK_PI5_UNLOCK_CARD) +#error "CK_PI5_FACT needs CK_PI5_UNLOCK and CK_PI5_UNLOCK_CARD (production-class Store, card request source)" +#endif +int ck_store_pi5_fact_stage(const ck_store_report *r) +{ + struct ck_fact_result fr; + int rc = ck_pi5_fact_run(r->verdict == CK_SB_COMMITTED ? g_ss : 0, &ck_fact_req_boot, &fr); + ck_fact_req_clear(); + return rc; +} +#endif + /* Kernel stage. ck_dev_boot_disk comes from dev/devices.c. */ const disk_dev *ck_dev_boot_disk(void); void ck_dev_nvme_release(void); @@ -835,6 +851,12 @@ int ck_stage_store(void) /* Signed artifact candidates live in this Store: read them while the disk * is still bound (the loader verifies them later, as untrusted bytes). */ ck_art_stage_load(r.verdict == CK_SB_COMMITTED ? g_ss : 0, r.step); +#ifdef CK_PI5_FACT + { + int frc = ck_store_pi5_fact_stage(&r); + if (frc && rc == 0) rc = frc; + } +#endif #ifdef CK_SERVICE /* Service lifetime (core/lifecycle.c): an open Store keeps the NVMe bound * until the lifecycle stop order releases it, in that order. A refused diff --git a/native/kernel/svc/store_boot.h b/native/kernel/svc/store_boot.h index 8cdb26fa..cec4c699 100644 --- a/native/kernel/svc/store_boot.h +++ b/native/kernel/svc/store_boot.h @@ -160,6 +160,11 @@ int ck_store_rotate_recovery(const disk_dev *d, const uint8_t current[CK_SB_SECR * Slot 1 path with the hardware policy (TEST keys and TEST uuid do not exist in this image). Prints nothing. */ int ck_pi5_unlock_secret(uint8_t out[CK_SB_SECRET_LEN], const char **source); int ck_store_pi5_unlock_run(const disk_dev *d, const uint8_t *secret, const char *commit, ck_store_report *r); +#ifdef CK_PI5_FACT +/* PI5-5 (QUALIFICATION ONLY): the Cortex fact stage after the Store stage. r: the report of the Store boot. The + * Store is passed on only when it committed; a refused Store (wrong secret) recalls nothing. */ +int ck_store_pi5_fact_stage(const ck_store_report *r); +#endif #endif /* Print the report lines (also used by the host test). */ void store_boot_print(const ck_store_report *r); diff --git a/scripts/.crumb b/scripts/.crumb index eee86705..c3fa8860 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-13T16:35:24Z", + "compiled_at": "2026-10-13T17:02:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:e854b415aa0c2a7f1fe45aa6dc9987b2219b91916ddd826b4a49b9efae60a27e", + "digest": "sha256:f94d1bca3f533e19fd6fee07f9e931ba85bacec7633de4f456534426c4a31bb4", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 94, - "generated_at_commit": "217b81531a2b482c136354325bb06a237ee81577", - "source_tree": "sha256:962e2329a53e51a5561129a1603da2be5e2fb2bb8af3cb6ce347a2fd693d042f" + "files": 95, + "generated_at_commit": "013dfa602cad3a9f4435359ccf01f9b61eecfaf5", + "source_tree": "sha256:408809dcf2be375e4a0d6c1f6d304b5653a5b3a924f353b9e86ace197b583d56" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_pi5_build_check.sh b/scripts/ck_pi5_build_check.sh index b96dc090..0801ccdd 100755 --- a/scripts/ck_pi5_build_check.sh +++ b/scripts/ck_pi5_build_check.sh @@ -110,4 +110,32 @@ for combo in "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_PRODUCTION=1" "CK_PI5_ 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 test -s "${root}/target/native-kernel-pi5-unlock-card/full-pi5-unlock-card/BOOTAA64.EFI" || { echo "FAIL no pi5-unlock-card BOOTAA64.EFI"; fail=1; } +# PI5-5: the Cortex fact stage and the FACT.REQ reader exist only in the pi5-fact image. +make -C "${root}/native/kernel" pi5-fact >/dev/null +uf="${root}/target/native-kernel-pi5-unlock-card-fact/full-pi5-unlock-card-fact/aienos-ck.elf" +for s in ck_pi5_fact_run ck_store_pi5_fact_stage ck_boot_fact_req_find ck_fact_req_check ck_store_pi5_unlock_run cx_open_with; do + if defined "${uf}" "${s}"; then echo "PASS pi5-fact image defines ${s}"; else echo "FAIL pi5-fact image lacks ${s}"; fail=1; fi +done +for s in ck_pi5_fact_run ck_store_pi5_fact_stage ck_boot_fact_req_find ck_fact_req_check cx_open_with; do + for other in "${uc}" "${uo}" "${ps}" "${pi5}" "${def}"; do + if defined "${other}" "${s}"; then echo "FAIL ${other} defines ${s}"; fail=1; fi + done +done +echo "PASS no other image (pi5-unlock-card, pi5-unlock, pi5-store, pi5, default) defines the fact stage or its request reader" +for s in ck_store_test_keys ck_store_test_uuid; do + if defined "${uf}" "${s}"; then echo "FAIL pi5-fact image defines ${s}"; fail=1; else echo "PASS pi5-fact image has no ${s}"; fi +done +uf_strings="$(strings -a "${uf}")" +if grep -q "AIEN-TEST-BOOT\|LANE18-TEST-KVOL\|SEED-0B-" <<<"${uf_strings}"; then echo "FAIL pi5-fact image carries a TEST label"; fail=1; else echo "PASS pi5-fact image carries no TEST label (production-class Store)"; fi +for combo in "CK_PI5_FACT=1" "CK_PI5_UNLOCK=1 CK_PI5_FACT=1" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1 CK_PI5_STORE=1" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1 CK_PI5_INFER=1" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=1 CK_PI5_PCIE=1" "CK_PI5_UNLOCK=1 CK_PI5_UNLOCK_CARD=1 CK_PI5_FACT=2"; 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 combo in CK_PI5_FACT=1; do + for other in CK_PI5_STORE=1 CK_PI5_INFER=1 CK_PI5_PCIE=1; do + # shellcheck disable=SC2086 + if make -n -C "${root}/native/kernel" ${other} ${combo} full >/dev/null 2>&1; then echo "FAIL Makefile accepts ${other} ${combo}"; fail=1; else echo "PASS Makefile refuses ${other} ${combo}"; fi + done +done +test -s "${root}/target/native-kernel-pi5-unlock-card-fact/full-pi5-unlock-card-fact/BOOTAA64.EFI" || { echo "FAIL no pi5-fact BOOTAA64.EFI"; fail=1; } if [[ ${fail} == 0 ]]; then echo "CK_PI5_BUILD: PASS"; else echo "CK_PI5_BUILD: FAIL"; exit 1; fi diff --git a/scripts/pi5_fact_req.sh b/scripts/pi5_fact_req.sh new file mode 100755 index 00000000..bb2ef359 --- /dev/null +++ b/scripts/pi5_fact_req.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# pi5_fact_req.sh -- write a fact request file for the PI5-5 Cortex qualification image (make pi5-fact). +# QUALIFICATION ONLY. Layout: native/kernel/core/fact_req.h (512 bytes: magic AIENFCT1, version 1, flags 0, +# tag QUALIF-FACT-DATA, length 1..48, reserved 0, printable ASCII text, zero padding). +# +# pi5_fact_req.sh <out file> "<fact text, 1..48 printable ASCII characters>" +# +# Refuses an existing output file. A fact is not a secret; do not put one in it anyway. +set -euo pipefail +out="${1:?output file}" +txt="${2:?fact text}" +[[ ! -e "${out}" ]] || { echo "refusing: ${out} exists" >&2; exit 1; } +n=${#txt} +(( n >= 1 && n <= 48 )) || { echo "fact must be 1..48 characters (got ${n})" >&2; exit 1; } +LC_ALL=C +[[ "${txt}" =~ ^[\ -~]+$ ]] || { echo "fact must be printable ASCII" >&2; exit 1; } +{ + printf 'AIENFCT1\x01\x00\x00\x00\x00\x00\x00\x00QUALIF-FACT-DATA' + printf "\\x$(printf '%02x' "${n}")\\x00\\x00\\x00\\x00\\x00\\x00\\x00" + printf '%s' "${txt}" + head -c $((48 - n)) /dev/zero + head -c 424 /dev/zero +} > "${out}" +[[ "$(stat -c %s "${out}")" == 512 ]] || { rm -f "${out}"; echo "internal error: size" >&2; exit 1; } +echo "wrote ${out} (512 bytes, fact of ${n} characters)"