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#330 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/9f692fef1ad362ef.bundle -o 9f692fef1ad362ef.bundle git fetch 9f692fef1ad362ef.bundle refs/pull/330/head
Provenance
github-import 1
aien-dev/aienux
330
cc911e48f641e7df7f571f87ec4901bf64e95ce6
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":330,"url":"https://github.com/aien-dev/aienux/pull/330","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:13Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index e55da201..b2a3f5e0 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "ac5354ec8aed2e3d31d4c528d1277c3019bebd593ef7fc3648b4017f37ee9504", - "last_commit": "4900d1f", + "digest": "cfef8fc0d5a18c271db0e0f2c4be218a349bfcbd6f9a787248d290e922cea11b", + "last_commit": "0fef154", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "c426ad5c19f8a955eec686eb38a6b4110782931a238c9f85d24bcc8278f7fdad", - "last_commit": "d7c6c9c", + "digest": "4a8025437e443ba91c36713f71a2b722792f8c3d77339792fd07436e61ceb78e", + "last_commit": "0fef154", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "472997503f5d637af1f91e8eab7ecfe10ddee01e79bd42fb46ba245f061c3607", - "last_commit": "6813d62", + "digest": "fa53022eb88e3cb8dbbeae8d5da3a7601ba4ca51030d9169e4fefafa8db5ee29", + "last_commit": "0fef154", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:3f23e1bc11c583943fec01ea5e8c05e81f09ea30eb40de3261d35e0ac3a117a7", - "compiled_at": "2026-10-12T17:02:49Z", + "children_root": "sha256:b6a5581321088ca3ffbcdcecb4d8381ea6dc573a037ff3c36d673901660b196a", + "compiled_at": "2026-10-12T17:55:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:1f89952d8d9efbbab43565a6117c6b8648963662f9d97df357ae8aa358a1101f", - "evidence_files": 155, - "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7", - "files": 3104, - "generated_at_commit": "d7c6c9c90f6711626732bcb168f95cbf45671685", - "source_tree": "sha256:479eab5581119f0dbab41f828cfd2680553baec0e4c4e7eb36db3ca9cca64ad1" + "digest": "sha256:03f6c70248a47ac956d0aed3c7d0f4d28a260453fa437eae7bb30d7c7cda102c", + "evidence_files": 156, + "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", + "files": 3109, + "generated_at_commit": "0fef1545d535093462d69b9318a40c232debd709", + "source_tree": "sha256:92d07e2d236661e96b5d864bdf8650f5c9b3b4b8bb59b5d0d63857be41b3b5a9" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 2d101e05..71312aee 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:baea130f2c52779b57d90139beb66ac01b21ab499d113471a334be5500f3e369", - "compiled_at": "2026-10-12T17:02:49Z", + "compiled_at": "2026-10-12T17:55:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:ac5354ec8aed2e3d31d4c528d1277c3019bebd593ef7fc3648b4017f37ee9504", + "digest": "sha256:cfef8fc0d5a18c271db0e0f2c4be218a349bfcbd6f9a787248d290e922cea11b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 74, - "generated_at_commit": "d7c6c9c90f6711626732bcb168f95cbf45671685", - "source_tree": "sha256:2a74ca0a64b7964f84a6827626631cdb85db7844d31490d34ba9ded1532828f1" + "generated_at_commit": "0fef1545d535093462d69b9318a40c232debd709", + "source_tree": "sha256:1b60cac45947f800b14ae5ac1c4c8cb99db6559c8c6ec4185bcb29bf5f0d9065" }, "owner_lane": "", "provenance": { diff --git a/docs/ATTENDED_SESSION_N1.md b/docs/ATTENDED_SESSION_N1.md index 78b36caa..5a73e3ae 100644 --- a/docs/ATTENDED_SESSION_N1.md +++ b/docs/ATTENDED_SESSION_N1.md @@ -66,28 +66,45 @@ What this session does **not** prove, stated so nobody reads more into it: ### 2.2 Blocking prerequisites (each one alone makes today a NO-GO) -**B1. Operator input on the Spark's console.** The lifecycle reads operator -lines only from a PL011 serial receiver (`native/kernel/core/lifecycle.c` -header: "Operator input: the polled PL011 serial receive ... The USB keyboard -binding stays with the xHCI session code and is a later cut"; -`native/kernel/GATES.md` row 167b). `ck_console_rx_ready` returns 0 for any -UART that is not PL011/SBSA (`native/kernel/core/console.c` lines 185-193), -and then the lifecycle prints `lifecycle: REFUSED no operator input (console -UART has no PL011 receiver): stop order` and shuts down -(`lifecycle.c` ck_lifecycle_run). The Spark's console UART is described as -16550-style at `0x16A00000` (`docs/MILESTONES.md` line 239, -`docs/HARDWARE_TEST_RIG.md` line 96) and Linux on the Spark boots with -`earlycon=uart,mmio32,0x16A00000 console=ttyS0,921600` -(`evidence/trust1_gate0_capture_2026-09-30/eventlog_parsed.yaml` line 747), -which is the 8250/16550 driver. The SPCR interface type itself is UNVERIFIED -(the table is root-only; not read for this plan). Also UNVERIFIED: whether -any serial cable is wired (`docs/HARDWARE_TEST_RIG.md` line 50 plans a Pi GPIO -UART at 3.3 V). Needed: a desk-side cut that binds the USB keyboard to the -lifecycle line editor (the keyboard and xHCI path already exist: -`native/kernel/dev/usb_kbd.c`, CONSOLE gate), or 16550 receive in -`core/console.c` plus a wired, verified serial link, each with a QEMU gate. -Recommended: the USB keyboard, because the screen and keyboard are already -the attended setup and need no wiring. +**B1. Operator input on the Spark's console.** Half solved at the desk +(aienos#328); the other half is an operator step that needs a cable. + +Verified on the Spark on 2026-10-12 (read-only, Linux running, no write): +the ACPI SPCR (80 bytes, revision 2) names interface type **0x01** (16550 +subset, Linux `ACPI_DBG2_16550_SUBSET`), a memory-mapped UART at +**0x16A00000** with 32-bit dword-spaced registers (GAS access size 3), +interrupt GSIV 878, baud byte 7 (115200). Linux drives the same port as +`ttyS0` (`console=ttyS0,921600`, device `MTKI0511:00`, ACPI `\_SB_.COM1`, +`io_type=3` 32-bit MMIO, `iomem_reg_shift=2`, `uartclk=26000000`). +Before aienos#328 the kernel accepted SPCR types 0x00 and 0x12 only, so by +the code (not observed on the machine) it had no serial console on the +Spark at all, and the lifecycle would have stopped with `REFUSED no +operator input`. + +Implemented by aienos#328 (desk, host-tested; `native/kernel/GATES.md` +rows 167c-167f): the kernel selects that 16550 from the SPCR for output and +for operator input, reads it with 32-bit accesses, polls it (no +interrupts) between lifecycle steps and between generation steps (so +`cancel` works), refuses overlong lines and lines with a receive error +(overrun, parity, framing, break) whole, and prints `lifecycle: ready ... +(operator input: serial 16550 at 0x16a00000, polled)`. With no supported +UART it prints `lifecycle: REFUSED console input unsupported on this +platform` and stops. QEMU cannot run the 16550 path (QEMU virt has only a +PL011); the PL011 path passes the full lifecycle QEMU gate. + +Still an operator step and UNVERIFIED: (1) whether the Spark's 16550 is +wired to a connector you can reach (no documented external serial port; +`docs/HARDWARE_TEST_RIG.md` plans the hub Pi's 3.3 V GPIO UART); (2) the +line speed AIENOS inherits, because the kernel never reprograms the UART +(try 115200 from the SPCR first, then 921600, 8N1, no flow control). +**A prompt on the screen does not prove input.** What proves it: the bytes +you type echo back on the serial terminal, `status` is answered with a +`lifecycle: state=... store=...` line, and `shutdown` is answered with +`lifecycle: shutdown accepted`, the `lifecycle: stop order ...` line and +the final report. If no reachable serial connector exists, the remaining +path is the local USB keyboard bound to the service lifecycle (the keyboard +and xHCI code exist in `native/kernel/dev/usb_kbd.c`, CONSOLE gate, in a +TEST-only image), which is a separate desk cut not done yet. **B2. A hardware service image with resident CPU inference.** The milestone image is `make full CK_SERVICE=1 CK_HARDWARE_STAGING=1 CK_INFER_LIB=...`. @@ -202,7 +219,7 @@ below. Any one of these stops the session: | S2 | nothing new on screen for 60 s at any time outside generation; during generation (after `lifecycle: generating`), nothing for 600 s | abort | | S3 | `Secure Boot Violation` or any firmware refusal | firmware returns to `BootOrder` by itself; record, never bypass | | S4 | any `report_kind: panic` or `report_kind: fault`, any `panic:` line, any handoff refusal line of `docs/BOOT_HANDOFF_CONTRACT.md` section 6 | abort (the kernel resets itself) | -| S5 | `lifecycle: REFUSED no operator input` | soft (the image already stopped): B1 is not solved | +| S5 | `lifecycle: REFUSED console input unsupported on this platform` or `REFUSED console input not ready`, or no echo / no answer to `status` on the serial terminal | a refusal: soft (the image already stopped); no echo or no answer: abort. Either way B1 is not solved | | S6 | `disk: no AIENOS partition, refusing writes` or `store: ... no boot disk` | soft: B3 is not solved | | S7 | any `store: ... REFUSED` or `store: unlock REFUSED` line after `unlock <S>` (wrong secret, keyslot, SecurityManifest, rollback anchor), any `continuity: REFUSED`, `degraded` or `RESUMED_READONLY` | soft; never retype a different secret in the same window | | S8 | `store: blank disk ... formatted` in boot 2 (the Store did not survive) | soft; a finding against N2 | diff --git a/evidence/ck_lifecycle_16550_input_qemu_2026-10-12.txt b/evidence/ck_lifecycle_16550_input_qemu_2026-10-12.txt new file mode 100644 index 00000000..10547ad2 --- /dev/null +++ b/evidence/ck_lifecycle_16550_input_qemu_2026-10-12.txt @@ -0,0 +1,198 @@ +# scripts/qemu_ck_lifecycle_test.sh, local TCG run on the Spark host, 2026-10-12, worker w-console (aienos#328). +# Tree: aienos d60d904 code (base ff5da2d); docs-only edits after the run started. 193 ROW PASS, 0 ROW FAIL. +# Rows 163 (ready line names the UART) and 167c (input counters) are new or changed in this PR. +ROW build PASS default image carries no resident lifecycle +ROW build PASS production service image carries no TEST key banner +ROW 173 PASS service image carries the production continuity layer and no TEST mode selection +ROW build PASS refuses CK_SERVICE with CK_CONSOLE_SESSION=1 +ROW build PASS refuses CK_SERVICE with CK_QEMU_UNSAFE_DMA=1 +ROW build PASS refuses CK_SERVICE with CK_TEST_STORE_CRASH=1 +ROW build PASS refuses TEST keys with CK_HARDWARE_STAGING +ROW 160 PASS lifecycle after mm_usage (lines 113 < 114) +ROW 160 PASS Store stage refused with the production key source (BlockedOperator), disk not read +ROW 160 PASS Store LOCKED keeps the NVMe bound for a later unlock +ROW 160 PASS no NVMe revoke before the locked lifecycle +ROW 160 PASS no TEST key banner +ROW 161 PASS task refused while locked +ROW 161 PASS unlock refused, still locked +ROW 161 PASS unlock asked the production key source again +ROW 161 PASS status answered +ROW 161 PASS help answered +ROW 161 PASS evidence answered +ROW 162 PASS stop order with no Store +ROW 162 PASS locked lifecycle ready < NVMe revoke (revoke only at the stop order) (lines 114 < 129) +ROW 162 PASS NVMe revoke < stop order line (lines 129 < 131) +ROW 162 PASS stop order < stage result (lines 131 < 133) +ROW 162 PASS stage result < final report (lines 133 < 137) +ROW 162 PASS no panic or fault +ROW 173 PASS no continuity line while locked +ROW 162 PASS QEMU exit 0 +ROW 162 PASS M1 checks +ROW 163 PASS TEST-ONLY banner +ROW 163 PASS Store open, NVMe kept bound for the service lifetime +ROW 163 PASS lifecycle ready +ROW 182 PASS TEST-key Store: security manifest sequence 1 at genesis, no keyslot +ROW 173 PASS test-keys image provisions continuity at boot +ROW 173 PASS PROVISIONED < Store open line (lines 110 < 112) +ROW 163 PASS no NVMe revoke before the lifecycle +ROW 164 PASS task proposed +ROW 164 PASS approve committed to the Store +ROW 165 PASS second task while pending refused +ROW 165 PASS approve with nothing pending refused +ROW 165 PASS deny drops +ROW 165 PASS cancel drops +ROW 166 PASS overlong line refused whole +ROW 166 PASS evidence counts +ROW 167 PASS stop order closed the Store +ROW 167c PASS input counters after the stop order (PL011, polled) +ROW 167c PASS stop order line < input counters (lines 159 < 160) +ROW 167c PASS no console-input refusal on QEMU virt +ROW 179 PASS remember created the journal (header transaction, no records yet) +ROW 179 PASS remembered as record 1 (one sealed transaction) +ROW 179 PASS facts lists the fact in the same boot +ROW 179 PASS facts summary, chain verified +ROW 179 PASS journal closed first in the stop order +ROW 179 PASS cortex closed < stop order line (lines 155 < 159) +ROW 179 PASS no refusal of remember or facts +ROW 167 PASS lifecycle ready < NVMe revoke (revoke only at the stop order) (lines 124 < 157) +ROW 167 PASS NVMe revoke < stop order line (lines 157 < 159) +ROW 167 PASS stop order < stage result (lines 159 < 161) +ROW 167 PASS stage result < final report (lines 161 < 165) +ROW 167 PASS no panic or fault +ROW 167 PASS QEMU exit 0 +ROW 167 PASS M1 checks +ROW 168 PASS lifecycle came up locked +ROW 168 PASS short secret refused (64 hex digits expected) +ROW 168 PASS blank disk formatted as a production store +ROW 168 PASS key source line: recovery keyslot genesis +ROW 168 PASS store committed generation 2 boot 1 +ROW 183 PASS production genesis: security manifest sequence 1 binds the keyslot +ROW 168 PASS unlock ok +ROW 168 PASS lifecycle unlocked to ready +ROW 168 PASS status open +ROW 168 PASS task proposed +ROW 168 PASS approve committed generation 4 (after the continuity genesis at 3) +ROW 171 PASS genesis inputs declared +ROW 171 PASS identity PROVISIONED incarnation 1 +ROW 171 PASS ALLEN subject GENESIS sequence 1 +ROW 171 PASS unlock ok < PROVISIONED (lines 126 < 129) +ROW 171 PASS PROVISIONED < lifecycle unlock ok (lines 129 < 131) +ROW 171 PASS status reports continuity +ROW 168 PASS stop order closed the Store +ROW 180 PASS production Store: journal created after the note (header at generation 5) +ROW 180 PASS production Store: fact committed at generation 6 +ROW 180 PASS production Store: facts lists it +ROW 180 PASS evidence counts the two verbs +ROW 180 PASS no refusal of remember or facts +ROW 168 PASS stop order < stage result (lines 152 < 154) +ROW 168 PASS no panic or fault +ROW 168 PASS QEMU exit 0 +ROW 168 PASS M1 checks +ROW 170 PASS secret hex never in the serial log (genesis boot) +ROW 170 PASS typed secret echoed as 64 '*' +ROW 170 PASS no TEST key banner +ROW 169 PASS lifecycle came up locked +ROW 169 PASS wrong secret refused by the keyslot tag +ROW 169 PASS lifecycle still locked after the wrong secret +ROW 169 PASS status still locked +ROW 169 PASS not reformatted +ROW 169 PASS key source line: recovery keyslot resume +ROW 169 PASS store opened at generation 6 (keyslot + boot record + continuity genesis + note + journal header + fact), boot_count 1 +ROW 169 PASS store committed generation 7 boot 2 +ROW 183 PASS production resume: security manifest sequence 2 links the genesis one, keyslot bound +ROW 183 PASS no SecurityManifest refusal in any boot +ROW 169 PASS unlock ok, no genesis +ROW 172 PASS ALLEN subject RESTORED sequence 1 +ROW 172 PASS identity RESUMED incarnation 2, same agent as the genesis boot +ROW 172 PASS no second genesis +ROW 172 PASS no degraded mount +ROW 172 PASS unlock ok < RESUMED (lines 130 < 133) +ROW 172 PASS RESUMED < lifecycle unlock ok (lines 133 < 134) +ROW 172 PASS status reports resumed +ROW 169 PASS lifecycle unlocked to ready +ROW 169 PASS evidence: one refused unlock +ROW 169 PASS stop order closed the Store +ROW 181 PASS cold boot: journal opened from the disk, chain verified (1 record, 2 chunks) +ROW 181 PASS cold boot: the fact answers from the disk, not restated +ROW 181 PASS cold boot: facts summary +ROW 181 PASS cold boot: the fact was never typed in this boot +ROW 181 PASS cold boot: nothing remembered in this boot +ROW 181 PASS cold boot: evidence shows facts only +ROW 181 PASS cold boot: journal closed before the stop order +ROW 181 PASS cold boot: cortex closed < stop order (lines 145 < 149) +ROW 169 PASS no panic or fault +ROW 169 PASS QEMU exit 0 +ROW 169 PASS M1 checks +ROW 170 PASS secret hex never in the serial log (resume boot) +ROW 170 PASS wrong secret hex never in the serial log +ROW 184 PASS lifecycle came up locked +ROW 184 PASS store opened at generation 6 (the boot-3 disk), boot_count 1 +ROW 184 PASS boot transaction: security manifest sequence 2 +ROW 184 PASS unlock ok with the current secret +ROW 184 PASS continuity RESUMED incarnation 2 +ROW 184 PASS rotation committed: KeySlotManifest sequence 2, SecurityManifest sequence 3, one generation (9) +ROW 184 PASS lifecycle rotate ok, state ready +ROW 184 PASS rotate not refused +ROW 184 PASS typed rotate line echoed as 129 '*' +ROW 184 PASS status ready after rotation +ROW 184 PASS stop order closed the Store +ROW 184 PASS no panic or fault +ROW 184 PASS QEMU exit 0 +ROW 184 PASS M1 checks +ROW 184 PASS current secret hex never in the serial log (rotation boot) +ROW 184 PASS new secret hex never in the serial log (rotation boot) +ROW 185 PASS lifecycle came up locked +ROW 185 PASS old secret refused by the keyslot tag of the newest manifest +ROW 185 PASS lifecycle still locked after the old secret +ROW 185 PASS status still locked +ROW 185 PASS store opened at generation 9 (rotation committed), boot_count 2 +ROW 185 PASS security manifest sequence 4 links the rotation one, keyslot bound +ROW 185 PASS no SecurityManifest refusal after rotation +ROW 185 PASS new secret unlock ok, no genesis +ROW 185 PASS continuity RESUMED incarnation 3 +ROW 185 PASS no second genesis +ROW 185 PASS not reformatted +ROW 185 PASS lifecycle unlocked to ready +ROW 185 PASS the fact still answers from the disk after rotation +ROW 185 PASS evidence: one refused unlock +ROW 185 PASS stop order closed the Store +ROW 185 PASS no panic or fault +ROW 185 PASS QEMU exit 0 +ROW 185 PASS M1 checks +ROW 185 PASS old secret hex never in the serial log (post-rotation boot) +ROW 185 PASS new secret hex never in the serial log (post-rotation boot) +ROW 174 PASS only the CK_INFER_LIB service image carries the resident session +ROW 174 PASS TEST-ONLY fw_cfg model source declared +ROW 174 PASS resident session open with the declared limits +ROW 174 PASS resident open < lifecycle ready (lines 126 < 129) +ROW 174 PASS TEST-ONLY banner +ROW 174 PASS generating line +ROW 174 PASS golden reply ids (17 prompt ids, 25 steps) +ROW 174 PASS reply is the pending proposal +ROW 174 PASS approve committed the reply object +ROW 175 PASS second prompt cancelled between steps (produced 0, nothing pending) +ROW 175 PASS the cancel was not refused +ROW 175 PASS no prompt refused +ROW 175 PASS recall (same boot) reads the reply back through the sealed Store +ROW 176 PASS evidence counters +ROW 176 PASS resident close +ROW 176 PASS unload returned every frame (1020855 = 1020855) +ROW 176 PASS resident close < unload line (lines 147 < 148) +ROW 176 PASS unload line < stop order (lines 148 < 152) +ROW 176 PASS stop order closed the Store +ROW 176 PASS stop order < stage result (lines 152 < 154) +ROW 176 PASS no panic or fault +ROW 176 PASS QEMU exit 0 +ROW 176 PASS M1 checks +ROW 175 PASS cold boot: resident session open again +ROW 175 PASS cold boot: continuity RESUMED on the same disk +ROW 175 PASS cold boot: no second genesis +ROW 175 PASS cold boot: recall returns the approved reply from the disk +ROW 175 PASS cold boot: evidence shows one recall, no prompt +ROW 175 PASS cold boot: unload returned every frame (1020855 = 1020855) +ROW 175 PASS cold boot: stop order closed the Store +ROW 175 PASS cold boot: no panic or fault +ROW 175 PASS cold boot: QEMU exit 0 +ROW 175 PASS M1 checks +AIENOS_CK_LIFECYCLE_INFER: PASS (QEMU only; hardware NOT_RUN) +AIENOS_CK_LIFECYCLE: PASS (QEMU only; hardware NOT_RUN) diff --git a/native/.crumb b/native/.crumb index 3d8952ae..ddff06e5 100644 --- a/native/.crumb +++ b/native/.crumb @@ -56,7 +56,7 @@ }, { "digest": "ac53ad497e153b30849f7064154f0dccedafe1af34a5b6de118327ee0e5c39d3", - "last_commit": "21e0473", + "last_commit": "aa76c36", "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": "e67a5cfded2e60d58d49917a9807e23b1d5d71be32548f900c36a577f3d0c151", - "last_commit": "d7c6c9c", + "digest": "2da253b686dabae0b952913f09ed51793c89b9a993be9ad4b1251bc37caa8b82", + "last_commit": "0fef154", "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:a6ba30bd8c3b3fb4095890cdaa90571d7bc8cc4cadbd65a83e141755631abe35", - "compiled_at": "2026-10-12T17:02:49Z", + "children_root": "sha256:ec8ff1f5ee937605da49ef43f40bd0e62eeb7d9952d8aade9563852b916c3af8", + "compiled_at": "2026-10-12T17:55:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:c426ad5c19f8a955eec686eb38a6b4110782931a238c9f85d24bcc8278f7fdad", + "digest": "sha256:4a8025437e443ba91c36713f71a2b722792f8c3d77339792fd07436e61ceb78e", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 478, - "generated_at_commit": "d7c6c9c90f6711626732bcb168f95cbf45671685", - "source_tree": "sha256:c75aa7d409696ef48f3477a61e8309d5d843e09aee3224a3ac9adfb64e4f7db6" + "files": 482, + "generated_at_commit": "0fef1545d535093462d69b9318a40c232debd709", + "source_tree": "sha256:2323966cd83d45b38f315dd1e8a913fa44f995a03621c840ee8a37fc8f68e627" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 823b31f5..f91f142a 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -57,8 +57,8 @@ "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { - "digest": "13c7a827e3ccb3c9395a86080f2a7c7540037fc7c4fb6039c80fbcc6b7413bdf", - "last_commit": "22eb360", + "digest": "713ba40c584588b6328e0216f0b7fc3d70ad06679941b6401db3db1fc4222635", + "last_commit": "d60d904", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -69,8 +69,8 @@ "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { - "digest": "5641b8a18b587d5e35df3dccc6a157af5f4ea14d72713bb6fb970b903b554eb9", - "last_commit": "9b3b71b", + "digest": "b169dbabaac665af04845138be24e36fa9993a6ff761c6e4ea11f4dd81689657", + "last_commit": "d60d904", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, @@ -87,27 +87,27 @@ "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "c65a92ef6ebb21a41f8148c443f9e87d142734e5f08b3d0402644060ff07c4bf", - "last_commit": "22eb360", + "digest": "9aa43b7cb6119b9cb8fe1fc72e35e2983048acb1c839695a12de88c230c5f580", + "last_commit": "d60d904", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "2443251e4e44b6fb0efc7889c87eb6fa5510eb06d7ed84f64ec487621a2b859e", - "last_commit": "4900d1f", + "last_commit": "aa76c36", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:5c4f07aa34ddf2d4f6148bbfc57d942862d4d74c93bce798f61a479ce2c1de6f", - "compiled_at": "2026-10-12T17:02:49Z", + "children_root": "sha256:cf0c34c19b5c82e7a014bca7bf392f6c5ad5ee559b4d4ee410783995aa6a64cf", + "compiled_at": "2026-10-12T17:55:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:e67a5cfded2e60d58d49917a9807e23b1d5d71be32548f900c36a577f3d0c151", + "digest": "sha256:2da253b686dabae0b952913f09ed51793c89b9a993be9ad4b1251bc37caa8b82", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 311, - "generated_at_commit": "d7c6c9c90f6711626732bcb168f95cbf45671685", - "source_tree": "sha256:98db14a6e3bddb8499fc9dad63509be6709a180df4ed206d4a81b101105ea6b5" + "files": 315, + "generated_at_commit": "0fef1545d535093462d69b9318a40c232debd709", + "source_tree": "sha256:b5a9c2e9e1d09bb5f9f830c54ff2c84ff4be4ebf357d6ab697a11a65d5dd314b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index fc0b9af4..cf9e2ba0 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -847,7 +847,11 @@ The product boundary. A `CK_SERVICE=1` image (`full-service/`, allowed with `CK_ | 166 | bounds: a 145-byte line (limit 144, room for `rotate ` + two 64-hex secrets) is refused whole and never run; `evidence` counts agree (`tasks=3 approved=1 denied=1 cancelled=1 overlong=1`) with the last commit generation and object id | LIFECYCLE | QEMU PASS (hardware NOT_RUN) | | 167 | stop order: `lifecycle: ready` < `dma_gate: nvme bus master revoked` < `stop order store=closed nvme=released` < `stage lifecycle: ok` < final report; no panic or fault; QEMU exit 0; M1 checks | LIFECYCLE | QEMU PASS (hardware NOT_RUN) | | 167a | build shape: the default image carries no lifecycle; `CK_SERVICE` refused with `CK_CONSOLE_SESSION`, `CK_QEMU_UNSAFE_DMA` and any `CK_TEST_*`; `CK_SERVICE_TEST_KEYS` refused with `CK_HARDWARE_STAGING` | LIFECYCLE (build) | PASS | -| 167b | limits: operator input is serial only (USB keyboard binding stays with the xHCI session code, later cut); a committed note or reply is read back by `recall` (row 175) but the memory-only fact of N3 (the Omega CxStore adapter record) is the next P06 cut; the lifecycle loop polls with interrupts as the boot stages left them (no scheduler integration yet) | LIFECYCLE | LIMIT (declared) | +| 167b | limits: operator input is serial only (PL011 or 16550 per the SPCR, rows 167c-167f; USB keyboard binding stays with the xHCI session code, later cut); a committed note or reply is read back by `recall` (row 175) but the memory-only fact of N3 (the Omega CxStore adapter record) is the next P06 cut; the lifecycle loop polls with interrupts as the boot stages left them (no scheduler integration yet) | LIFECYCLE | LIMIT (declared) | +| 167c | operator input names its UART and is polled (aienos#328): the ready line reads `(operator input: serial pl011 at 0x9000000, polled)` on QEMU virt; after the stop order `lifecycle: input uart=pl011 rx_errors=0 overruns=0 damaged_lines=0 overlong=1 dropped=N`; no `REFUSED console input` line. The receive side uses the UART the boot stub chose from the ACPI SPCR for output (`ck_console_set_uart`, `core/uart_rx.h` `ck_uart_from_spcr`): no second console table | LIFECYCLE | QEMU PASS (hardware NOT_RUN) | +| 167d | 16550 receive (the DGX Spark console: SPCR type 0x01, GAS memory 32-bit dword, base 0x16A00000, read from the Spark's own SPCR on 2026-10-12): host test `tests/test_console_rx.c` (`CK_CONSOLE_RX`, plain and sanitized) parses the Spark's exact 80 SPCR bytes and selects the 16550 with stride 4 (32-bit accesses, as Linux drives it: `io_type=3`, `iomem_reg_shift=2`); readiness (LCR.DLAB clear, LSR not all ones); decode on a simulated register file: byte, empty, overrun (OE with and without a byte), parity, framing, break, floating bus never read as data; PL011 decode the same way (OE, FE, BE, receiver off). Types 0x00/0x12 accepted, 0x05 (NVIDIA 16550 variant) and others refused. QEMU: NOT RUN, because QEMU virt (the only board our UEFI firmware boots) has no memory-mapped 16550 and its SPCR always names the PL011; a PCI 16550 sits behind an I/O BAR the kernel does not map | LIFECYCLE | host PASS (QEMU NOT_RUN: no 16550 on virt; hardware NOT_RUN) | +| 167e | one bounded line assembler (`core/line_rx.c`) for the prompt and for the cancel poll between generation steps: 144-byte limit, a longer line refused whole (no longer truncated in the cancel path), a line with a lost or damaged byte refused whole (`REFUSED verb=invalid reason="receive error in the line ..."`, never run; a lost Enter joins the next line and both are refused), at most 256 bytes per poll call (a UART that never runs dry cannot hold the lifecycle); `cancel` split across steps 3 and 5 of an 8-step run stops it at step 5; `status`/`shutdown` during a run refused and not run; a damaged `cancel` refused, the retyped one cancels. Six mutants (type 0x01 dropped, 16550 OE ignored, DLAB unchecked, damaged lines run, overlong truncated, unbounded burst) each make `CK_CONSOLE_RX` FAIL | LIFECYCLE | host PASS (hardware NOT_RUN) | +| 167f | refusals and limits: no PL011/SBSA or 16550 in the SPCR -> `lifecycle: REFUSED console input unsupported on this platform (...)` and the stop order; a UART whose receiver is off or not answering -> `REFUSED console input not ready (uart=... base=... regs=...)` and the stop order (both paths have no QEMU run: QEMU virt always has a ready PL011). POLLED only: no UART interrupt is enabled and no UART control register is written (baud, FIFO, word length stay as the firmware left them; the Spark SPCR says 115200, Linux reprograms 921600: the line speed under AIENOS is UNVERIFIED). Physical: whether the Spark's 16550 is wired to a connector an operator can reach is UNVERIFIED; the local USB keyboard on the service image is a separate cut | LIFECYCLE | LIMIT (declared) | | 168 | P04 cut 1, recovery keyslot GENESIS (production service image, blank disk): `unlock deadbeef` refused (`rc=-2004`, 64 hex digits expected); `unlock <64-hex secret>` draws K_vol/salt/nonce from the entropy service, wraps K_vol into the ADR 0017 Slot 1 Recovery_RawSecret descriptor (HKDF-SHA256 KEK) and commits the KeySlotManifest (kind 21, plaintext, bound by the sealed transaction record) in the same first transaction as the boot record: `formatted production store`, `key source=recovery-keyslot genesis=1`, `committed generation=2 boot_count=1`, `unlock ok ... genesis=1`, lifecycle READY; the continuity genesis commits generation 3 (row 171); a note is approved and committed at generation 4; stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | | 169 | P04 cut 1, recovery keyslot RESUME (same disk, cold boot): the wrong secret is refused by the keyslot AES-GCM-SIV tag (`RecoverySecretRejected rc=-2004`, disk not opened, not reformatted, lifecycle stays locked, `refused=1`); the right secret unwraps K_vol, derives PRODUCTION-class keys (owner hierarchy generation = active_key_epoch 1), the keyed open re-binds the manifest through the transaction record: `opened generation=4 boot_count=1 ... anchor=valid-resume`, `committed generation=5 boot_count=2`, `unlock ok ... genesis=0`; the continuity resume commits generation 6 (row 172); stop order closes the Store; QEMU exit 0; M1 checks | LIFECYCLE / TRUST-1 | QEMU PASS (hardware NOT_RUN) | | 170 | secret hygiene and limits: the typed secret is echoed as 64 `*` and neither secret's hex appears in any serial log; no TEST key banner; no key material is compiled into the image (`ck_store_production_keys` still refuses `rc=-2002`: TPM Slot 0 BLOCKED_HARDWARE); no key rotation (`active_key_epoch` 1); the manifest is not yet bound into the secman `keyslot_manifest_id`; host rig (`stage_test` `test_unlock_recovery`): entropy refusal leaves a blank disk untouched, wrong secret and wrong provisioned uuid leave the image byte-identical, a TEST-key Store has no manifest (`NoKeyslotManifest rc=-2003`) | LIFECYCLE / TRUST-1 | QEMU PASS + LIMIT (declared) | diff --git a/native/kernel/Makefile b/native/kernel/Makefile index d9a9144e..67bd89d6 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -692,7 +692,7 @@ else FULL_NAME := full-service$(if $(strip $(CK_HARDWARE_STAGING)),-hardware-staging,) STAGE_DMA_FLAGS += -DCK_SERVICE=1 endif -STAGE_SRCS += $(KDIR)/core/lifecycle.c $(KDIR)/core/lifecycle_fsm.c +STAGE_SRCS += $(KDIR)/core/lifecycle.c $(KDIR)/core/lifecycle_fsm.c $(KDIR)/core/line_rx.c # P06 cut 3: the canonical Omega Cortex store over the sealed Store (svc/cortex_journal.c). STAGE_SRCS += $(STAGE_CORTEX_SRCS) # P05 cut 1: production continuity on the service lifecycle (svc/continuity_service.c): @@ -984,10 +984,11 @@ $(FULL_EFI): $(FULL_ELF) # ---- host unit tests ---- 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/handoff_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/acpi_dev.c $(KDIR)/core/lifecycle_fsm.c \ + $(KDIR)/core/line_rx.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_continuity_subject test_continuity_subject_provision test_lifecycle test_console_rx 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 diff --git a/native/kernel/README.md b/native/kernel/README.md index 1ec8e948..94320caa 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -243,18 +243,28 @@ driver; reading a powered-down block could fault), and whether `tests/fixtures/spark_xhci_acpi_expected.txt` (KEYBOARD row 32b, NOT_RUN). +### Service lifecycle serial input (native v1 N1, aienos#328) + +Status: **host-tested 16550, QEMU PL011.** `GATES.md` rows 167c-167f. Hardware NOT_RUN. + +- **One console table.** The boot stub picks the console UART from the ACPI SPCR once (`ck_console_set_uart`); output and operator input both use it. PL011/SBSA (types 0x03, 0x0d, 0x0e: QEMU virt) and 16550 (types 0x00, 0x01, 0x12). The DGX Spark's SPCR (read on the machine 2026-10-12) is type 0x01, a 32-bit dword-spaced 16550 at 0x16A00000; before this cut the kernel refused that type, so by the code (not observed on the machine) it had no serial console on the Spark at all. +- **Polled, never interrupt driven.** The lifecycle polls the receiver between its steps and, while the model generates, between generation steps, so `cancel` works. No UART register is written: the line speed is whatever the firmware left (the SPCR says 115200; UNVERIFIED on the machine). +- **Bounded lines.** `core/line_rx.c`: 144 bytes; an overlong line, or one in which the UART reported an overrun, parity, framing or break error, is refused whole and never run. +- **Refusals.** No supported UART: `lifecycle: REFUSED console input unsupported on this platform` and the stop order. Receiver off or not answering: `REFUSED console input not ready`. +- **Operator step.** A serial cable (3.3 V) to that UART and a terminal on the other end. Whether the Spark exposes it on a reachable connector is UNVERIFIED. The local USB keyboard on the service image is a separate cut. + ### Console session (Campaign 3 cut C3-1a, QEMU test image only) Status: **QEMU only.** CK gate `CONSOLE` (rows 146-155 in `GATES.md`). Hardware NOT_RUN. The default image does not contain it. `make full CK_CONSOLE_SESSION=1` builds a TEST-ONLY image with a final boot stage `console`, entered only after every other boot step. The bounded boot shell above (60 s, idle 15 s) and the recovery window are unchanged. The session then keeps taking input for as long as the operator uses it, with no time limit and no idle exit, until the shell's `exit`: -- **Two sources, one line.** PL011 serial receive (polled, on the UART base the console already prints to; the kernel only reads UARTCR and never reconfigures the UART) and the USB keyboard both feed the same 64-byte line editor and the same shell. Printable keys only; a 65th key makes the whole line refused. +- **Two sources, one line.** Serial receive (polled, on the UART the console already prints to: PL011/SBSA or 16550 per the ACPI SPCR, `core/uart_rx.h`; the kernel only reads UART registers and never reconfigures the UART) and the USB keyboard both feed the same 64-byte line editor and the same shell. Printable keys only; a 65th key makes the whole line refused. - **No interleaving inside a line.** The first source that types into a line owns it until Enter. Keys from the other source are dropped and counted in a printed line: `console_input: dropped N key(s) from <source> while <owner> owned the line`. - **DMA confinement unchanged.** The USB half runs inside a second xHCI fence: SMMU window first, no SMMU means no DMA, and its DMA stays in that one window for the whole session. `exit` halts the controller, turns bus mastering off, returns the stream to abort and prints the same revoke lines. If the keyboard is unavailable, is unplugged (PORTSC connect bit clear) or its endpoint halts, the fence is revoked and serial goes on alone. Only a printable key claims a line, so Backspace on an empty line cannot lock the other source out. - **No new authority.** The console runs the existing commands only (`help mem el report uptime exit`). -Not yet: the 16550 UART (only PL011 receive is read), any recovery-access change, and any hardware run (the Spark's UART and USB are unmeasured by this code). +Not yet: any recovery-access change and any hardware run (the Spark's UART and USB are unmeasured by this code; 16550 receive, aienos#328, is host-tested only). ### Physical attended boot: what it will look like diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index 69f30a86..f57864ee 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-12T10:28:17Z", + "compiled_at": "2026-10-12T16:18:21Z", "compiler": "crumb-compile/1", - "digest": "sha256:13c7a827e3ccb3c9395a86080f2a7c7540037fc7c4fb6039c80fbcc6b7413bdf", + "digest": "sha256:713ba40c584588b6328e0216f0b7fc3d70ad06679941b6401db3db1fc4222635", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 42, - "generated_at_commit": "56d125f12abf2b8ba2886d6da4d86fda8dd244b3", - "source_tree": "sha256:30523c9d1ccd0f870c17ab6a7903d0d43df25d4ca13f7cae9d601d045320085a" + "files": 45, + "generated_at_commit": "d60d904d6960d80246ce628332c1ed63971cb96f", + "source_tree": "sha256:dd1d5eb317ffda51458c26a7ca1b58898ea51534cb3605b89a0a4e9f6409680a" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/acpi.h b/native/kernel/core/acpi.h index af8a372b..0f0aeab5 100644 --- a/native/kernel/core/acpi.h +++ b/native/kernel/core/acpi.h @@ -73,7 +73,7 @@ int ck_place_task(const struct ck_cpu_topology *t, uint32_t task_index, uint8_t uint32_t *core); struct ck_spcr { - uint8_t interface_type; /* 0x03 PL011, 0x0d/0x0e SBSA, 0x00/0x12 16550 */ + uint8_t interface_type; /* 0x03 PL011, 0x0d/0x0e SBSA, 0x00/0x01/0x12 16550 (core/uart_rx.h) */ uint8_t space; /* GAS address space: 0 = system memory */ uint8_t bit_width; uint8_t access_size; /* GAS access size: 1 byte .. 4 qword */ diff --git a/native/kernel/core/console.c b/native/kernel/core/console.c index d704a935..a8933f20 100644 --- a/native/kernel/core/console.c +++ b/native/kernel/core/console.c @@ -8,6 +8,7 @@ #include "ck_internal.h" #include "fbcon.h" #include "arch.h" +#include "uart_rx.h" #ifndef CK_FB_HOLD_S #define CK_FB_HOLD_S 0 @@ -28,23 +29,14 @@ void ck_console_set_efi(void (*write)(const char *s, size_t n)) int ck_console_set_uart(const struct ck_spcr *s) { + int kind; + unsigned stride; if (!s || s->space != 0 || !s->base) return -1; - switch (s->interface_type) { - case 0x03: /* ARM PL011 */ - case 0x0d: /* ARM SBSA generic UART, 32-bit only */ - case 0x0e: /* ARM SBSA generic UART */ - uart_kind = 1; - uart_stride = 4; - break; - case 0x00: /* 16550 */ - case 0x12: /* 16550 with GAS */ - uart_kind = 2; - uart_stride = s->access_size == 3 ? 4 : s->access_size == 4 ? 8 : 1; - break; - default: + if (ck_uart_from_spcr(s->interface_type, s->access_size, &kind, &stride) != 0) return -1; - } + uart_kind = kind; + uart_stride = stride; uart_phys = s->base; uart = (volatile uint8_t *)(uintptr_t)s->base; return 0; @@ -68,10 +60,12 @@ static void uart_putc(char c) ; *(volatile uint32_t *)(uart + 0x00) = (uint8_t)c; } else if (uart_kind == 2) { - volatile uint8_t *lsr = uart + 5 * uart_stride; - for (unsigned i = 0; i < 1000000 && !(*lsr & 0x20); i++) + /* Access width from the SPCR GAS (ck_16550_width): the Spark's 16550 + * is dword-spaced and Linux drives it with 32-bit accesses only. */ + unsigned w = ck_16550_width(uart_stride); + for (unsigned i = 0; i < 1000000 && !(ck_uart_rd(uart, CK_16550_LSR * uart_stride, w) & 0x20); i++) ; - if (uart_stride == 4) + if (w == 4) *(volatile uint32_t *)uart = (uint8_t)c; else *uart = (uint8_t)c; @@ -174,39 +168,34 @@ void ck_printf(const char *fmt, ...) va_end(ap); } -/* ---- PL011 receive, polled (console session; see include/ck.h) ---- - * Registers (offsets and bits from Linux include/linux/amba/serial.h, the Arm - * PL011 TRM page being unreadable here; see the docs-read record): UARTDR at - * 0x00 (DATA bits 7:0, error flags OE/BE/PE/FE bits 11:8), UARTFR at 0x18 - * (RXFE bit 4 = receive FIFO empty), UARTCR at 0x30 (UARTEN bit 0, RXE bit 9). - * The kernel only READS UARTCR; it never reconfigures the UART. */ -static unsigned rx_errs; +/* ---- console receive, POLLED (operator input; see include/ck.h) ---- + * The receive side uses the UART the transmit side already chose from the + * ACPI SPCR (ck_console_set_uart): PL011/SBSA (QEMU virt) or 16550 (the DGX + * Spark, SPCR type 0x01 at 0x16A00000). Register decode, readiness and the + * error rules live in core/uart_rx.h, shared with the host test. No + * interrupt is used: the lifecycle polls between its steps. The kernel never + * writes a UART control register (baud, FIFO, enables stay as the firmware + * left them). */ +static struct ck_uart_rx_count rx_count; int ck_console_rx_ready(uint32_t *cr) { - if (uart_kind != 1) - return 0; - uint32_t v = *(volatile uint32_t *)(uart + 0x30); - if (cr) - *cr = v; - return (v & 1u) && (v & (1u << 9)); + return ck_uart_rx_ready(uart_kind, uart, uart_stride, cr); } int ck_console_rx_poll(void) { - if (uart_kind != 1) - return -1; - if (*(volatile uint32_t *)(uart + 0x18) & (1u << 4)) - return -1; - uint32_t d = *(volatile uint32_t *)(uart + 0x00); - if (d & 0xf00u) { - rx_errs++; - return -2; /* an errored byte: dropped and counted, distinct from an empty FIFO */ - } - return (int)(d & 0xffu); + if (uart_kind != CK_UART_PL011 && uart_kind != CK_UART_16550) + return CK_UART_RX_EMPTY; + return ck_uart_rx_take(uart_kind, uart, uart_stride, &rx_count); } unsigned ck_console_rx_errors(void) { - return rx_errs; + return rx_count.errors; +} + +unsigned ck_console_rx_overruns(void) +{ + return rx_count.overruns; } diff --git a/native/kernel/core/lifecycle.c b/native/kernel/core/lifecycle.c index 42ec92fa..ae68c285 100644 --- a/native/kernel/core/lifecycle.c +++ b/native/kernel/core/lifecycle.c @@ -6,10 +6,14 @@ * image ends in ck_reset(). The diagnostic images are untouched (they do not * link this file; the weak ck_lifecycle_run is absent there). * - * Operator input: the polled PL011 serial receive the console already owns - * (core/console.c), one bounded line editor (CK_LC_LINE_MAX bytes, overlong - * lines refused whole). The USB keyboard binding stays with the xHCI session - * code and is a later cut. Verbs and transitions: core/lifecycle_fsm.c. + * Operator input: the POLLED serial receive of the console UART the boot + * stub chose from the ACPI SPCR (core/console.c, core/uart_rx.h: PL011/SBSA + * on QEMU virt, 16550 on the DGX Spark), no interrupts. One bounded line + * assembler (core/line_rx.c: CK_LC_LINE_MAX bytes, overlong or damaged lines + * refused whole) serves the prompt and the cancel poll between generation + * steps. Neither UART kind: `console input unsupported on this platform` and + * the stop order. The USB keyboard binding stays with the xHCI session code + * and is a later cut. Verbs and transitions: core/lifecycle_fsm.c. * * Store: the sealed Store opened by the store stage stays open and the NVMe * stays bound for the service lifetime (svc/store_boot.c, CK_SERVICE). An @@ -46,6 +50,7 @@ #include "ck.h" #include "ck_internal.h" #include "lifecycle_fsm.h" +#include "line_rx.h" #include "store_boot.h" #include "store_sealed.h" #include "continuity_service.h" @@ -74,7 +79,7 @@ int ck_store_service_rotate(const char *arg, size_t arg_len); static ck_lc g_lc; static uint8_t g_last_id[32]; static uint64_t g_last_gen; -static unsigned g_overlong, g_dropped; +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 */ @@ -163,31 +168,19 @@ static int commit_task(void) return rc; } -/* Between generation steps the console is polled: a complete line "cancel" - * abandons the request; any other complete line is refused (only cancel is - * accepted while generating). */ -static char g_gen_line[CK_LC_LINE_MAX + 1]; -static size_t g_gen_len; +/* Between generation steps the console is polled (no interrupts): a complete + * line "cancel" abandons the request; any other complete line, and an + * overlong or damaged one, is refused and never run (only cancel is + * accepted while generating). Same line rules as the prompt (core/line_rx.c). */ +static struct ck_line_rx g_gen_rx; +static void gen_refuse(enum ck_lc_verb v, const char *reason) +{ + g_lc.refused++; + ck_printf("lifecycle: REFUSED verb=%s reason=\"%s\"\n", ck_lc_verb_name(v), reason); +} static int cancel_poll(void) { - for (;;) { - int b = ck_console_rx_poll(); - if (b == -1) return 0; - if (b == -2) continue; - char c = (char)b; - if (c == '\r' || c == '\n') { - const char *arg; - size_t arg_len; - enum ck_lc_verb v = g_gen_len ? ck_lc_decode(g_gen_line, g_gen_len, &arg, &arg_len) : CK_LC_V_EMPTY; - g_gen_len = 0; - if (v == CK_LC_V_CANCEL) return 1; - if (v == CK_LC_V_EMPTY) continue; - g_lc.refused++; - ck_printf("lifecycle: REFUSED verb=%s reason=\"generating: only cancel is accepted\"\n", ck_lc_verb_name(v)); - continue; - } - if (c >= 0x20 && c <= 0x7e && g_gen_len < CK_LC_LINE_MAX) g_gen_line[g_gen_len++] = c; - } + return ck_line_rx_cancel_poll(&g_gen_rx, ck_console_rx_poll, gen_refuse); } /* prompt accepted: the resident model generates a bounded reply, which @@ -206,7 +199,7 @@ static void generate(void) return; } ck_printf("lifecycle: generating prompt=\"%s\" (cancel stops it between steps)\n", g_lc.task); - g_gen_len = 0; + ck_line_rx_init(&g_gen_rx); int rc = ck_infer_prompt(g_lc.task, g_lc.task_len, cancel_poll, &r); if (rc < 0) { ck_lc_generate_done(&g_lc, CK_LC_GEN_FAILED, 0, 0); @@ -508,63 +501,71 @@ static int in_secret(const char *buf, size_t len) return after_verb(buf, len, "unlock") || after_verb(buf, len, "rotate"); } -/* Bounded serial line editor: printable bytes collected, Backspace edits, - * CR or LF ends the line; a line past CK_LC_LINE_MAX is refused whole (the - * rest of it is dropped until the next Enter). Returns 1 when the line is complete. */ -static int rx_line(char *buf, size_t *len, int *overflow) +/* Bounded serial line editor over the POLLED console receive (no + * interrupts): the rules are core/line_rx.c (printable bytes collected, + * Backspace edits, CR or LF ends the line, a line past CK_LC_LINE_MAX or one + * with a lost or damaged byte is refused whole at its Enter). This function + * 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; +static int rx_line(void) { - for (;;) { + for (unsigned n = 0; n < CK_LINE_RX_BURST; n++) { int b = ck_console_rx_poll(); - if (b == -1) return 0; - if (b == -2) continue; /* error byte: counted by the console, dropped here */ - char c = (char)b; - if (c == '\r' || c == '\n') { - if (*overflow) { - g_overlong++; - ck_puts("\n"); - ck_printf("lifecycle: REFUSED verb=invalid reason=\"line longer than %u bytes\"\n", (unsigned)CK_LC_LINE_MAX); - *overflow = 0; - *len = 0; - return 0; - } - ck_puts("\n"); - return 1; + if (b == CK_LINE_RX_EMPTY) return 0; + switch (ck_line_rx_feed(&g_rx, b)) { + case CK_LINE_ECHO: { + char e[2] = { in_secret(g_rx.buf, g_rx.len - 1) ? '*' : g_rx.buf[g_rx.len - 1], 0 }; + ck_puts(e); + break; } - if (c == 0x7f || c == 0x08) { - if (*len && !*overflow) { (*len)--; ck_puts("\b \b"); } - continue; + case CK_LINE_ERASE: ck_puts("\b \b"); break; + case CK_LINE_DONE: ck_puts("\n"); return 1; + case CK_LINE_OVERLONG: + g_overlong++; + ck_puts("\n"); + ck_printf("lifecycle: REFUSED verb=invalid reason=\"line longer than %u bytes\"\n", (unsigned)CK_LC_LINE_MAX); + return 0; + case CK_LINE_DAMAGED: + ck_puts("\n"); + ck_puts("lifecycle: REFUSED verb=invalid reason=\"receive error in the line (overrun, parity, framing or break): type it again\"\n"); + return 0; + default: break; } - if (c < 0x20 || c > 0x7e) { g_dropped++; continue; } - if (*overflow) continue; - if (*len >= CK_LC_LINE_MAX) { *overflow = 1; continue; } - { char e[2] = { in_secret(buf, *len) ? '*' : c, 0 }; buf[(*len)++] = c; ck_puts(e); } } + return 0; } /* Returns 0 after an orderly stop (kmain then prints the final report and * resets). Never returns while serving. */ int ck_lifecycle_run(void) { - char line[CK_LC_LINE_MAX + 1]; - size_t len = 0; - int overflow = 0; - uint32_t cr; + uint32_t cr = 0; ck_lc_init(&g_lc); + ck_line_rx_init(&g_rx); + ck_line_rx_init(&g_gen_rx); #ifdef CK_SERVICE_TEST_KEYS ck_puts("lifecycle: TEST-ONLY service image (CK_SERVICE_TEST_KEYS=1: TEST Store keys; QEMU only, never a production boot)\n"); #endif ck_lc_start(&g_lc, ck_store_service_ready()); - if (!ck_console_rx_ready(&cr)) { - ck_puts("lifecycle: REFUSED no operator input (console UART has no PL011 receiver): stop order\n"); + /* 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(); + if (uname[0] == 'n') { /* "none": no console UART of a kind this kernel drives */ + ck_puts("lifecycle: REFUSED console input unsupported on this platform (no PL011/SBSA or 16550 console UART in the ACPI SPCR): stop order\n"); + ck_lc_apply(&g_lc, CK_LC_V_SHUTDOWN, "", 0); + } else if (!ck_console_rx_ready(&cr)) { + ck_printf("lifecycle: REFUSED console input not ready (uart=%s base=0x%llx regs=0x%x): stop order\n", uname, + (unsigned long long)ck_console_uart_base(), cr); ck_lc_apply(&g_lc, CK_LC_V_SHUTDOWN, "", 0); } else { - ck_printf("lifecycle: ready state=%s store=%s (operator input: serial)\n", ck_lc_state_name(g_lc.state), - ck_store_service_ready() ? "open" : "locked"); + ck_printf("lifecycle: ready state=%s store=%s (operator input: serial %s at 0x%llx, polled)\n", + ck_lc_state_name(g_lc.state), ck_store_service_ready() ? "open" : "locked", uname, + (unsigned long long)ck_console_uart_base()); ck_puts("> "); while (g_lc.state != CK_LC_QUIESCE) { - if (rx_line(line, &len, &overflow)) { - handle_line(line, len); - len = 0; + if (rx_line()) { + handle_line(g_rx.buf, g_rx.len); if (g_lc.state != CK_LC_QUIESCE) ck_puts("> "); } else { __asm__ volatile("yield"); @@ -581,5 +582,8 @@ int ck_lifecycle_run(void) ck_lc_stopped(&g_lc); ck_printf("lifecycle: stop order store=%s nvme=released state=%s requests=%u\n", closed ? "closed" : "was-locked", ck_lc_state_name(g_lc.state), g_lc.requests); + ck_printf("lifecycle: input uart=%s rx_errors=%u overruns=%u damaged_lines=%u overlong=%u dropped=%u\n", uname, + ck_console_rx_errors(), ck_console_rx_overruns(), g_rx.damaged_lines + g_gen_rx.damaged_lines, + g_rx.overlong + g_gen_rx.overlong, g_rx.dropped + g_gen_rx.dropped); return 0; } diff --git a/native/kernel/core/line_rx.c b/native/kernel/core/line_rx.c new file mode 100644 index 00000000..9b317d24 --- /dev/null +++ b/native/kernel/core/line_rx.c @@ -0,0 +1,91 @@ +/* line_rx.c -- operator line assembler (see line_rx.h). Pure logic. */ +#include "line_rx.h" + +void ck_line_rx_init(struct ck_line_rx *l) +{ + l->len = 0; + l->overflow = l->damaged = l->done = 0; + l->buf[0] = 0; + l->overlong = l->damaged_lines = l->dropped = 0; +} + +static void clear(struct ck_line_rx *l) +{ + l->len = 0; + l->overflow = l->damaged = 0; + l->buf[0] = 0; +} + +enum ck_line_ev ck_line_rx_feed(struct ck_line_rx *l, int b) +{ + if (l->done) { /* the previous call handed out a complete line */ + l->done = 0; + clear(l); + } + if (b == CK_LINE_RX_ERR) { + l->damaged = 1; + return CK_LINE_NONE; + } + if (b < 0 || b > 0xff) + return CK_LINE_NONE; + char c = (char)b; + if (c == '\r' || c == '\n') { + if (l->overflow) { + l->overlong++; + clear(l); + return CK_LINE_OVERLONG; + } + if (l->damaged) { + l->damaged_lines++; + clear(l); + return CK_LINE_DAMAGED; + } + l->buf[l->len] = 0; + l->done = 1; + return CK_LINE_DONE; + } + if (c == 0x7f || c == 0x08) { + if (l->len && !l->overflow) { + l->len--; + return CK_LINE_ERASE; + } + return CK_LINE_NONE; + } + if (b < 0x20 || b > 0x7e) { + l->dropped++; + return CK_LINE_NONE; + } + if (l->overflow) + return CK_LINE_NONE; + if (l->len >= CK_LC_LINE_MAX) { + l->overflow = 1; + return CK_LINE_NONE; + } + l->buf[l->len++] = c; + return CK_LINE_ECHO; +} + +int ck_line_rx_cancel_poll(struct ck_line_rx *l, int (*poll)(void), void (*refuse)(enum ck_lc_verb v, const char *reason)) +{ + for (unsigned n = 0; n < CK_LINE_RX_BURST; n++) { + int b = poll(); + if (b == CK_LINE_RX_EMPTY) + return 0; + switch (ck_line_rx_feed(l, b)) { + case CK_LINE_DONE: { + const char *arg; + size_t arg_len; + enum ck_lc_verb v = l->len ? ck_lc_decode(l->buf, l->len, &arg, &arg_len) : CK_LC_V_EMPTY; + if (v == CK_LC_V_CANCEL) + return 1; + if (v != CK_LC_V_EMPTY) + refuse(v, "generating: only cancel is accepted"); + break; + } + case CK_LINE_OVERLONG: refuse(CK_LC_V_INVALID, "line longer than the limit"); break; + case CK_LINE_DAMAGED: refuse(CK_LC_V_INVALID, "receive error in the line (overrun, parity, framing or break): type it again"); break; + default: break; + } + } + return 0; +} diff --git a/native/kernel/core/line_rx.h b/native/kernel/core/line_rx.h new file mode 100644 index 00000000..1a5e69f0 --- /dev/null +++ b/native/kernel/core/line_rx.h @@ -0,0 +1,62 @@ +/* line_rx.h -- the operator line assembler of the service lifecycle: one + * bounded state machine fed byte by byte from the POLLED console receive + * (core/console.c, core/uart_rx.h). Pure logic (no kernel calls, no libc): + * the host test tests/test_console_rx.c compiles it as is; core/lifecycle.c + * uses it for the main prompt and for the cancel poll between generation + * steps, so both follow the same rules. + * + * Rules (feed one byte, or CK_LINE_RX_ERR for a byte the UART dropped): + * - printable ASCII 0x20..0x7e is collected, up to CK_LC_LINE_MAX bytes; + * - Backspace (0x08) or DEL (0x7f) removes the last byte; + * - CR or LF ends the line (a CR LF pair gives one line and one empty line); + * - any other control byte is dropped and counted; + * - a line past CK_LC_LINE_MAX is refused whole at its Enter (OVERLONG), + * the rest of it is dropped until then; + * - a line during which the UART reported a lost or damaged byte is + * refused whole at its Enter (DAMAGED): a command with a missing byte + * never runs. If the lost byte was the Enter itself, the next line is + * joined to the damaged one and refused with it (safe side). */ +#ifndef AIENOS_CK_LINE_RX_H +#define AIENOS_CK_LINE_RX_H + +#include <stddef.h> +#include <stdint.h> +#include "lifecycle_fsm.h" + +#define CK_LINE_RX_ERR (-2) /* same value as ck_console_rx_poll's error result */ +#define CK_LINE_RX_EMPTY (-1) +/* Bytes taken per poll call at most, so a UART that never runs dry (a stuck + * data-ready bit) cannot hold the lifecycle in one call. */ +#define CK_LINE_RX_BURST 256u + +enum ck_line_ev { + CK_LINE_NONE = 0, /* nothing to show */ + CK_LINE_ECHO, /* one byte appended: buf[len - 1] */ + CK_LINE_ERASE, /* one byte removed */ + CK_LINE_DONE, /* buf[0..len) is a complete line, NUL-terminated */ + CK_LINE_OVERLONG, /* the line ended and is refused: longer than CK_LC_LINE_MAX */ + CK_LINE_DAMAGED, /* the line ended and is refused: a byte was lost or damaged */ +}; + +struct ck_line_rx { + char buf[CK_LC_LINE_MAX + 1]; + size_t len; + uint8_t overflow, damaged, done; + unsigned overlong; /* lines refused for length */ + unsigned damaged_lines; /* lines refused for a receive error */ + unsigned dropped; /* control bytes dropped */ +}; + +void ck_line_rx_init(struct ck_line_rx *l); +enum ck_line_ev ck_line_rx_feed(struct ck_line_rx *l, int b); + +/* The cancel check between generation steps: drains at most + * CK_LINE_RX_BURST bytes from poll() (no echo) and returns 1 as soon as a + * complete line decodes to `cancel`, 0 when the input ran dry or the burst + * ended. Every other complete line (a verb other than cancel, an overlong or + * damaged line) is refused: refuse(verb, reason) is called and the line is + * never run. Empty lines are ignored. A partial line stays in l for the + * next call. */ +int ck_line_rx_cancel_poll(struct ck_line_rx *l, int (*poll)(void), void (*refuse)(enum ck_lc_verb v, const char *reason)); + +#endif diff --git a/native/kernel/core/uart_rx.h b/native/kernel/core/uart_rx.h new file mode 100644 index 00000000..54ea1c65 --- /dev/null +++ b/native/kernel/core/uart_rx.h @@ -0,0 +1,161 @@ +/* uart_rx.h -- polled console UART receive: register decode for the PL011 + * (QEMU virt, SBSA) and the 16550 (the DGX Spark console, SPCR type 0x01 at + * 0x16A00000). Shared by core/console.c (the real MMIO base) and the host + * test tests/test_console_rx.c (a simulated register file). + * + * POLLING ONLY. Nothing here enables, routes or acknowledges an interrupt, + * and nothing writes a UART register: the firmware's line settings (baud, + * word length, FIFO) are used as found. The caller polls between lifecycle + * steps and between generation steps. + * + * Registers (no-write reads only): + * PL011 (Linux include/linux/amba/serial.h): UARTDR 0x00 (data bits 7:0, + * FE bit 8, PE bit 9, BE bit 10, OE bit 11), UARTFR 0x18 (RXFE bit 4), + * UARTCR 0x30 (UARTEN bit 0, RXE bit 9). + * 16550 (Linux include/uapi/linux/serial_reg.h): RBR 0 (DLAB=0), LCR 3 + * (DLAB bit 7), LSR 5 (DR 0x01, OE 0x02, PE 0x04, FE 0x08, BI 0x10). + * Register n sits at n * stride; stride 4 means 32-bit accesses (SPCR + * GAS access size 3, Linux UPIO_MEM32 on the Spark), stride 1 byte + * accesses. Reading LSR clears OE/PE/FE/BI, so it is read exactly once + * per byte and every flag is taken from that one read. + * + * Decode result: 0..255 a good byte; CK_UART_RX_EMPTY nothing waiting; + * CK_UART_RX_ERROR a byte was lost or arrived damaged (overrun, parity, + * framing, break): the byte is dropped and counted, and the line assembler + * (core/line_rx.c) refuses the line it belonged to. */ +#ifndef AIENOS_CK_UART_RX_H +#define AIENOS_CK_UART_RX_H + +#include <stdint.h> + +enum ck_uart_kind { CK_UART_NONE = 0, CK_UART_PL011 = 1, CK_UART_16550 = 2 }; + +#define CK_UART_RX_EMPTY (-1) +#define CK_UART_RX_ERROR (-2) + +#define CK_PL011_DR 0x00u +#define CK_PL011_FR 0x18u +#define CK_PL011_CR 0x30u +#define CK_PL011_FR_RXFE (1u << 4) +#define CK_PL011_DR_FE (1u << 8) +#define CK_PL011_DR_PE (1u << 9) +#define CK_PL011_DR_BE (1u << 10) +#define CK_PL011_DR_OE (1u << 11) +#define CK_PL011_CR_UARTEN (1u << 0) +#define CK_PL011_CR_RXE (1u << 9) + +#define CK_16550_RBR 0u +#define CK_16550_LCR 3u +#define CK_16550_LSR 5u +#define CK_16550_LCR_DLAB 0x80u +#define CK_16550_LSR_DR 0x01u +#define CK_16550_LSR_OE 0x02u +#define CK_16550_LSR_PE 0x04u +#define CK_16550_LSR_FE 0x08u +#define CK_16550_LSR_BI 0x10u + +struct ck_uart_rx_count { + unsigned errors; /* every dropped byte (overrun, parity, framing, break) */ + unsigned overruns; /* of those: overruns (a byte was lost before this one) */ +}; + +/* SPCR interface type -> UART kind and 16550 register stride. -1: no + * console UART of a kind this kernel can drive (output dropped, no input). + * Types from Linux include/acpi/actbl1.h (ACPI_DBG2_*). */ +static inline int ck_uart_from_spcr(uint8_t interface_type, uint8_t access_size, int *kind, unsigned *stride) +{ + switch (interface_type) { + case 0x03: /* ARM PL011 */ + case 0x0d: /* ARM SBSA generic UART, 32-bit only */ + case 0x0e: /* ARM SBSA generic UART */ + *kind = CK_UART_PL011; + *stride = 4; + return 0; + case 0x00: /* 16550 fully compatible */ + case 0x01: /* 16550 subset (DBGP rev 1): the DGX Spark's SPCR */ + case 0x12: /* 16550 with parameters in the GAS */ + *kind = CK_UART_16550; + *stride = access_size == 3 ? 4 : access_size == 4 ? 8 : 1; + return 0; + default: + return -1; + } +} + +static inline uint32_t ck_uart_rd(volatile uint8_t *base, unsigned off, unsigned width) +{ + if (width == 1) + return *(volatile uint8_t *)(base + off); + return *(volatile uint32_t *)(base + off); +} + +/* 16550 register access width: 32-bit for stride 4 and 8 (the low 32 bits + * of a qword-spaced register), byte for stride 1. */ +static inline unsigned ck_16550_width(unsigned stride) +{ + return stride == 1 ? 1 : 4; +} + +/* 1 when the receiver can deliver bytes; *regs gets the register that + * proves it (PL011 UARTCR; 16550 LCR << 8 | LSR) for the report line. + * 16550: there is no receiver-enable bit; not ready when LSR reads all ones + * (nothing answering at that address) or LCR.DLAB is set (offset 0 is then + * the divisor latch, not the receive buffer). */ +static inline int ck_uart_rx_ready(int kind, volatile uint8_t *base, unsigned stride, uint32_t *regs) +{ + if (!base) + return 0; + if (kind == CK_UART_PL011) { + uint32_t cr = ck_uart_rd(base, CK_PL011_CR, 4); + if (regs) + *regs = cr; + return (cr & CK_PL011_CR_UARTEN) && (cr & CK_PL011_CR_RXE); + } + if (kind == CK_UART_16550) { + unsigned w = ck_16550_width(stride); + uint32_t lcr = ck_uart_rd(base, CK_16550_LCR * stride, w) & 0xffu; + uint32_t lsr = ck_uart_rd(base, CK_16550_LSR * stride, w) & 0xffu; + if (regs) + *regs = lcr << 8 | lsr; + return lsr != 0xffu && !(lcr & CK_16550_LCR_DLAB); + } + return 0; +} + +/* One polled receive: a byte, CK_UART_RX_EMPTY or CK_UART_RX_ERROR. */ +static inline int ck_uart_rx_take(int kind, volatile uint8_t *base, unsigned stride, struct ck_uart_rx_count *c) +{ + if (!base) + return CK_UART_RX_EMPTY; + if (kind == CK_UART_PL011) { + if (ck_uart_rd(base, CK_PL011_FR, 4) & CK_PL011_FR_RXFE) + return CK_UART_RX_EMPTY; + uint32_t d = ck_uart_rd(base, CK_PL011_DR, 4); + if (d & (CK_PL011_DR_FE | CK_PL011_DR_PE | CK_PL011_DR_BE | CK_PL011_DR_OE)) { + c->errors++; + if (d & CK_PL011_DR_OE) + c->overruns++; + return CK_UART_RX_ERROR; + } + return (int)(d & 0xffu); + } + if (kind == CK_UART_16550) { + unsigned w = ck_16550_width(stride); + uint32_t lsr = ck_uart_rd(base, CK_16550_LSR * stride, w) & 0xffu; + if (lsr == 0xffu) + return CK_UART_RX_EMPTY; /* nothing answering: never a byte stream of 0xff */ + int byte = CK_UART_RX_EMPTY; + if (lsr & CK_16550_LSR_DR) + byte = (int)(ck_uart_rd(base, CK_16550_RBR * stride, w) & 0xffu); /* pops it either way */ + if (lsr & (CK_16550_LSR_OE | CK_16550_LSR_PE | CK_16550_LSR_FE | CK_16550_LSR_BI)) { + c->errors++; + if (lsr & CK_16550_LSR_OE) + c->overruns++; + return CK_UART_RX_ERROR; /* OE alone: an earlier byte was lost, the line is damaged */ + } + return byte; + } + return CK_UART_RX_EMPTY; +} + +#endif diff --git a/native/kernel/include/.crumb b/native/kernel/include/.crumb index ca083320..fd0ebbb1 100644 --- a/native/kernel/include/.crumb +++ b/native/kernel/include/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T08:33:35Z", + "compiled_at": "2026-10-12T16:18:21Z", "compiler": "crumb-compile/1", - "digest": "sha256:5641b8a18b587d5e35df3dccc6a157af5f4ea14d72713bb6fb970b903b554eb9", + "digest": "sha256:b169dbabaac665af04845138be24e36fa9993a6ff761c6e4ea11f4dd81689657", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 1, - "generated_at_commit": "620210ed8651c274e7f13efd78d836b9d567f9f0", - "source_tree": "sha256:3b68dd7854ac89039e7084496587b660f78cf43ff74536029d098a1150ab45f0" + "generated_at_commit": "d60d904d6960d80246ce628332c1ed63971cb96f", + "source_tree": "sha256:fcdd9d04df8c5b6d2db5379d9def85ff1056c9094617e403160634efdfa6c2ca" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/include/ck.h b/native/kernel/include/ck.h index 9efc5d69..31e7b3a2 100644 --- a/native/kernel/include/ck.h +++ b/native/kernel/include/ck.h @@ -207,17 +207,22 @@ __attribute__((weak)) int ck_stage_console_session(void); * every diagnostic image. */ __attribute__((weak)) int ck_lifecycle_run(void); -/* PL011 serial receive (core/console.c), polled. ck_console_rx_ready: 1 when the - * console UART is a PL011 whose UARTCR has UARTEN and RXE set (*cr gets UARTCR); - * 0 otherwise (16550, none, receiver off): then no byte is ever read. ck_console_rx_poll: - * -1 when the receive FIFO is empty (UARTFR.RXFE), -2 for a byte with an error - * flag (UARTDR[11:8]; dropped and counted, more may be waiting), else the byte - * of UARTDR[7:0]. */ +/* Console serial receive (core/console.c + core/uart_rx.h), POLLED, no + * interrupts. It uses the UART the transmit side chose from the ACPI SPCR: + * PL011/SBSA (QEMU virt) or 16550 (types 0x00/0x01/0x12; the DGX Spark's + * console is type 0x01 at 0x16A00000). ck_console_rx_ready: 1 when that UART + * can deliver bytes (PL011: UARTCR UARTEN and RXE; 16550: LCR.DLAB clear and + * LSR not all ones), *cr gets the proving register (PL011 UARTCR, 16550 + * LCR << 8 | LSR); 0 for no console UART or a receiver that is off: then no + * byte is ever read. ck_console_rx_poll: -1 nothing waiting, -2 a byte lost or + * damaged (overrun, parity, framing, break; dropped and counted, more may be + * waiting), else the byte. The kernel never writes a UART control register. */ const char *ck_console_uart_name(void); uint64_t ck_console_uart_base(void); int ck_console_rx_ready(uint32_t *cr); int ck_console_rx_poll(void); unsigned ck_console_rx_errors(void); +unsigned ck_console_rx_overruns(void); /* Resident inference (core/infer.c, native v1 P06): a CK_SERVICE image built * with CK_INFER_LIB keeps the ingested model and one bounded session open diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index e59657c2..b93b2bb3 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-12T10:28:17Z", + "compiled_at": "2026-10-12T16:18:21Z", "compiler": "crumb-compile/1", - "digest": "sha256:c65a92ef6ebb21a41f8148c443f9e87d142734e5f08b3d0402644060ff07c4bf", + "digest": "sha256:9aa43b7cb6119b9cb8fe1fc72e35e2983048acb1c839695a12de88c230c5f580", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 150, - "generated_at_commit": "56d125f12abf2b8ba2886d6da4d86fda8dd244b3", - "source_tree": "sha256:ff91f3553e2525cde42fd32c98bac1bf33d22e47248747152c01cd437aa6c55c" + "files": 151, + "generated_at_commit": "d60d904d6960d80246ce628332c1ed63971cb96f", + "source_tree": "sha256:c9b5a15196836b17ef25f4416dad20b6d783448f7f9008ee43a7044dd25705de" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_console_rx.c b/native/kernel/tests/test_console_rx.c new file mode 100644 index 00000000..f2e83cb7 --- /dev/null +++ b/native/kernel/tests/test_console_rx.c @@ -0,0 +1,259 @@ +/* test_console_rx.c -- the service lifecycle's operator input on the host: + * SPCR -> console UART selection (the DGX Spark's exact SPCR bytes), the + * POLLED 16550 and PL011 receive decode (core/uart_rx.h) on a simulated + * register file (byte, empty, overrun, parity, framing, break, not ready, + * nothing answering), the line assembler (core/line_rx.c: assembly, erase, + * overlong and damaged lines refused whole), and cancel arriving in the + * middle of a multi-step run (ck_line_rx_cancel_poll, the function + * core/lifecycle.c calls between generation steps). */ +#include <string.h> +#include "ck_test.h" +#include "acpi.h" +#include "uart_rx.h" +#include "line_rx.h" + +/* /sys/firmware/acpi/tables/SPCR read on the DGX Spark, 2026-10-12 (80 + * bytes, revision 2, ALASKA/AMI): type 0x01 at byte 36, GAS memory/32-bit/ + * dword at 0x16A00000. */ +static const uint8_t spark_spcr[80] = { + 0x53, 0x50, 0x43, 0x52, 0x50, 0x00, 0x00, 0x00, 0x02, 0x53, 0x41, 0x4c, 0x41, 0x53, 0x4b, 0x41, + 0x41, 0x20, 0x4d, 0x20, 0x49, 0x20, 0x00, 0x00, 0x21, 0x02, 0x13, 0x20, 0x41, 0x4d, 0x49, 0x20, + 0x99, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0xa0, 0x16, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x6e, 0x03, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x02, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +/* A 16550 with dword-spaced registers (stride 4), and one with byte registers. */ +static uint32_t u4[8]; +static uint8_t u1[8]; +#define U4 ((volatile uint8_t *)u4) +#define U1 ((volatile uint8_t *)u1) +/* A PL011 (UARTDR 0x00, UARTFR 0x18, UARTCR 0x30). */ +static uint32_t pl[0x40 / 4]; +#define PL ((volatile uint8_t *)pl) + +static enum ck_line_ev feed_s(struct ck_line_rx *l, const char *s) +{ + enum ck_line_ev ev = CK_LINE_NONE; + for (; *s; s++) ev = ck_line_rx_feed(l, *s == '#' ? CK_LINE_RX_ERR : (uint8_t)*s); + return ev; +} + +/* Bytes arriving through the simulated 16550: each byte is placed in RBR + * with its LSR flags, then taken by the real decode. */ +struct wire { uint8_t lsr; uint8_t byte; }; +static const struct wire *g_wire; +static size_t g_wire_n, g_wire_pos; +static struct ck_uart_rx_count g_wire_count; +static int wire_poll(void) +{ + if (g_wire_pos == g_wire_n) { u4[CK_16550_LSR] = 0x60; return ck_uart_rx_take(CK_UART_16550, U4, 4, &g_wire_count); } + u4[CK_16550_LSR] = g_wire[g_wire_pos].lsr; + u4[CK_16550_RBR] = g_wire[g_wire_pos].byte; + g_wire_pos++; + return ck_uart_rx_take(CK_UART_16550, U4, 4, &g_wire_count); +} + +/* A multi-step run (stands in for ck_infer_prompt's generation loop): at + * step i the bytes script[i] become readable ('#' = a byte the UART lost), + * then the cancel poll runs, as lifecycle.c's cancel_poll does between steps. */ +static const char *const *g_script; +static size_t g_pos; +static int g_step; +static unsigned g_polls; +static int script_poll(void) +{ + g_polls++; + const char *s = g_script[g_step]; + if (!s || !s[g_pos]) return CK_LINE_RX_EMPTY; + char c = s[g_pos++]; + return c == '#' ? CK_LINE_RX_ERR : (uint8_t)c; +} +static unsigned g_refused, g_refused_invalid; +static enum ck_lc_verb g_last_refused; +static void refuse(enum ck_lc_verb v, const char *reason) +{ + (void)reason; + g_refused++; + if (v == CK_LC_V_INVALID) g_refused_invalid++; + g_last_refused = v; +} +/* Runs up to `steps` steps; returns the step at which cancel stopped it, or 0. */ +static int run(const char *const *script, int steps, struct ck_line_rx *l) +{ + g_script = script; + g_refused = g_refused_invalid = 0; + g_last_refused = CK_LC_V_UNKNOWN; + ck_line_rx_init(l); + for (g_step = 0; g_step < steps; g_step++) { + g_pos = 0; + if (ck_line_rx_cancel_poll(l, script_poll, refuse)) return g_step + 1; + } + return 0; +} +static int g_always_a(void) { g_polls++; return 'a'; } + +int main(void) +{ + int kind = -9; + unsigned stride = 0; + + /* ---- SPCR -> console UART (the same table the transmit side uses) ---- */ + struct ck_spcr s; + CHECK(ck_spcr_parse(spark_spcr, &s) == 0); + CHECK(s.interface_type == 0x01 && s.space == 0 && s.bit_width == 32 && s.access_size == 3 && s.base == 0x16A00000ull); + CHECK(ck_uart_from_spcr(s.interface_type, s.access_size, &kind, &stride) == 0 && kind == CK_UART_16550 && stride == 4); + CHECK(ck_uart_from_spcr(0x03, 3, &kind, &stride) == 0 && kind == CK_UART_PL011 && stride == 4); + CHECK(ck_uart_from_spcr(0x0e, 3, &kind, &stride) == 0 && kind == CK_UART_PL011); + CHECK(ck_uart_from_spcr(0x00, 1, &kind, &stride) == 0 && kind == CK_UART_16550 && stride == 1); + CHECK(ck_uart_from_spcr(0x12, 4, &kind, &stride) == 0 && kind == CK_UART_16550 && stride == 8); + kind = -9; + CHECK(ck_uart_from_spcr(0x05, 3, &kind, &stride) == -1 && kind == -9); /* NVIDIA 16550 variant: not claimed */ + CHECK(ck_uart_from_spcr(0x0f, 3, &kind, &stride) == -1); /* Arm DCC */ + CHECK(ck_uart_from_spcr(0x02, 3, &kind, &stride) == -1); /* MAX311x SPI */ + + /* ---- 16550 readiness (stride 4: dword registers, low byte meaningful) ---- */ + uint32_t regs = 0; + u4[CK_16550_LCR] = 0x03; /* 8N1, DLAB clear */ + u4[CK_16550_LSR] = 0x60; /* THRE + TEMT, nothing received */ + CHECK(ck_uart_rx_ready(CK_UART_16550, U4, 4, ®s) == 1 && regs == 0x0360); + u4[CK_16550_LCR] = 0x83; /* DLAB set: offset 0 is the divisor latch */ + CHECK(ck_uart_rx_ready(CK_UART_16550, U4, 4, ®s) == 0 && regs == 0x8360); + u4[CK_16550_LCR] = 0x03; + u4[CK_16550_LSR] = 0xffffffffu; /* nothing answering at the address */ + CHECK(ck_uart_rx_ready(CK_UART_16550, U4, 4, ®s) == 0); + CHECK(ck_uart_rx_ready(CK_UART_16550, 0, 4, ®s) == 0); + CHECK(ck_uart_rx_ready(CK_UART_NONE, U4, 4, ®s) == 0); + + /* ---- 16550 receive decode ---- */ + struct ck_uart_rx_count c = {0, 0}; + u4[CK_16550_LSR] = 0x60; + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_EMPTY); + u4[CK_16550_LSR] = 0x61; u4[CK_16550_RBR] = 0xabcd0041u; /* only the low byte is data */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == 'A' && c.errors == 0); + u4[CK_16550_LSR] = 0x63; /* DR + OE: an earlier byte was lost */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_ERROR && c.errors == 1 && c.overruns == 1); + u4[CK_16550_LSR] = 0x62; /* OE with nothing waiting */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_ERROR && c.errors == 2 && c.overruns == 2); + u4[CK_16550_LSR] = 0x65; /* parity */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_ERROR && c.errors == 3 && c.overruns == 2); + u4[CK_16550_LSR] = 0x69; /* framing */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_ERROR && c.errors == 4); + u4[CK_16550_LSR] = 0x71; /* break */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_ERROR && c.errors == 5 && c.overruns == 2); + u4[CK_16550_LSR] = 0xffffffffu; /* floating bus: never a stream of 0xff bytes */ + CHECK(ck_uart_rx_take(CK_UART_16550, U4, 4, &c) == CK_UART_RX_EMPTY && c.errors == 5); + /* byte-spaced 16550 (stride 1) */ + u1[CK_16550_LCR] = 0x03; u1[CK_16550_LSR] = 0x61; u1[CK_16550_RBR] = 'z'; + CHECK(ck_uart_rx_ready(CK_UART_16550, U1, 1, ®s) == 1 && regs == 0x0361); + CHECK(ck_uart_rx_take(CK_UART_16550, U1, 1, &c) == 'z'); + u1[CK_16550_LSR] = 0x60; + CHECK(ck_uart_rx_take(CK_UART_16550, U1, 1, &c) == CK_UART_RX_EMPTY); + + /* ---- PL011 (QEMU virt) readiness and decode ---- */ + pl[CK_PL011_CR / 4] = 0x301; /* UARTEN + TXE + RXE */ + CHECK(ck_uart_rx_ready(CK_UART_PL011, PL, 4, ®s) == 1 && regs == 0x301); + pl[CK_PL011_CR / 4] = 0x101; /* receiver off */ + CHECK(ck_uart_rx_ready(CK_UART_PL011, PL, 4, ®s) == 0); + struct ck_uart_rx_count pc = {0, 0}; + pl[CK_PL011_FR / 4] = CK_PL011_FR_RXFE; + CHECK(ck_uart_rx_take(CK_UART_PL011, PL, 4, &pc) == CK_UART_RX_EMPTY); + pl[CK_PL011_FR / 4] = 0; pl[CK_PL011_DR / 4] = 0x41; + CHECK(ck_uart_rx_take(CK_UART_PL011, PL, 4, &pc) == 'A'); + pl[CK_PL011_DR / 4] = 0x841; /* OE */ + CHECK(ck_uart_rx_take(CK_UART_PL011, PL, 4, &pc) == CK_UART_RX_ERROR && pc.errors == 1 && pc.overruns == 1); + pl[CK_PL011_DR / 4] = 0x141; /* FE */ + CHECK(ck_uart_rx_take(CK_UART_PL011, PL, 4, &pc) == CK_UART_RX_ERROR && pc.errors == 2 && pc.overruns == 1); + pl[CK_PL011_DR / 4] = 0x441; /* BE */ + CHECK(ck_uart_rx_take(CK_UART_PL011, PL, 4, &pc) == CK_UART_RX_ERROR && pc.errors == 3); + CHECK(ck_uart_rx_take(CK_UART_NONE, PL, 4, &pc) == CK_UART_RX_EMPTY); + + /* ---- line assembly ---- */ + static struct ck_line_rx l; + ck_line_rx_init(&l); + CHECK(ck_line_rx_feed(&l, 's') == CK_LINE_ECHO && l.len == 1 && l.buf[0] == 's'); + CHECK(feed_s(&l, "tatus\r") == CK_LINE_DONE && l.len == 6 && strcmp(l.buf, "status") == 0); + CHECK(ck_line_rx_feed(&l, '\n') == CK_LINE_DONE && l.len == 0); /* CR LF: one line, one empty line */ + CHECK(feed_s(&l, "sxy") == CK_LINE_ECHO && ck_line_rx_feed(&l, 0x7f) == CK_LINE_ERASE && ck_line_rx_feed(&l, 0x08) == CK_LINE_ERASE); + CHECK(feed_s(&l, "tatus\n") == CK_LINE_DONE && strcmp(l.buf, "status") == 0); + CHECK(ck_line_rx_feed(&l, 0x7f) == CK_LINE_NONE && l.len == 0); /* erase on an empty line */ + CHECK(ck_line_rx_feed(&l, 0x01) == CK_LINE_NONE && ck_line_rx_feed(&l, 0x1b) == CK_LINE_NONE && ck_line_rx_feed(&l, 0x80) == CK_LINE_NONE && l.dropped == 3 && l.len == 0); + CHECK(feed_s(&l, "help\r") == CK_LINE_DONE && strcmp(l.buf, "help") == 0); + { + char line[CK_LC_LINE_MAX + 2]; + memset(line, 'a', sizeof line); + line[CK_LC_LINE_MAX] = '\r'; line[CK_LC_LINE_MAX + 1] = 0; /* exactly the limit */ + CHECK(feed_s(&l, line) == CK_LINE_DONE && l.len == CK_LC_LINE_MAX && l.overlong == 0); + line[CK_LC_LINE_MAX] = 'a'; line[CK_LC_LINE_MAX + 1] = 0; /* limit + 1 */ + CHECK(feed_s(&l, line) == CK_LINE_NONE && l.overflow == 1); + CHECK(ck_line_rx_feed(&l, 0x7f) == CK_LINE_NONE); /* erasing cannot rescue it */ + CHECK(ck_line_rx_feed(&l, '\r') == CK_LINE_OVERLONG && l.overlong == 1 && l.len == 0); + CHECK(feed_s(&l, "status\r") == CK_LINE_DONE && strcmp(l.buf, "status") == 0); /* next line is clean */ + } + /* damaged: a lost byte anywhere refuses the whole line */ + CHECK(feed_s(&l, "shut#down\r") == CK_LINE_DAMAGED && l.damaged_lines == 1 && l.len == 0); + CHECK(feed_s(&l, "status\r") == CK_LINE_DONE && strcmp(l.buf, "status") == 0); + /* the lost byte was the Enter: the next line is joined and refused with it */ + CHECK(feed_s(&l, "statu#shutdown\r") == CK_LINE_DAMAGED && l.damaged_lines == 2); + CHECK(feed_s(&l, "#\r") == CK_LINE_DAMAGED && l.damaged_lines == 3); + + /* ---- the same through the simulated 16550: an overrun mid-line ---- */ + { + static const struct wire w[] = { + { 0x61, 's' }, { 0x61, 't' }, { 0x63, 'o' } /* OE: a byte lost before 'o' */, { 0x61, 'p' }, { 0x61, '\r' }, + { 0x61, 'h' }, { 0x61, 'e' }, { 0x61, 'l' }, { 0x61, 'p' }, { 0x61, '\r' }, + }; + g_wire = w; g_wire_n = sizeof w / sizeof w[0]; g_wire_pos = 0; + g_wire_count.errors = g_wire_count.overruns = 0; + ck_line_rx_init(&l); + enum ck_line_ev ev[16]; + int n = 0, b; + while ((b = wire_poll()) != CK_UART_RX_EMPTY && n < 16) ev[n++] = ck_line_rx_feed(&l, b); + CHECK(n == 10 && ev[4] == CK_LINE_DAMAGED && ev[9] == CK_LINE_DONE && strcmp(l.buf, "help") == 0); + CHECK(g_wire_count.errors == 1 && g_wire_count.overruns == 1 && l.damaged_lines == 1); + } + + /* ---- cancel during a multi-step run ---- */ + static struct ck_line_rx g; + { + /* "cancel" split over steps 3 and 5: the run stops at step 5, not earlier, not later */ + static const char *const sc[9] = { "", "", "can", "", "cel\r", "", "", "", 0 }; + CHECK(run(sc, 8, &g) == 5 && g_refused == 0); + } + { + /* another verb during the run is refused, never run, and the run goes on */ + static const char *const sc[9] = { "sta", "tus\r", "", "shutdown\r", "", "", "", "", 0 }; + CHECK(run(sc, 8, &g) == 0 && g_refused == 2 && g_last_refused == CK_LC_V_SHUTDOWN && g_refused_invalid == 0); + } + { + /* a damaged "cancel" is refused (type it again); the retyped one cancels */ + static const char *const sc[9] = { "can#cel\r", "", "cancel\r", "", "", "", "", "", 0 }; + CHECK(run(sc, 8, &g) == 3 && g_refused == 1 && g_refused_invalid == 1 && g.damaged_lines == 1); + } + { + /* an overlong line that starts with "cancel" is refused whole, not truncated into a cancel */ + static char longc[CK_LC_LINE_MAX + 16]; + memset(longc, 'x', sizeof longc); + memcpy(longc, "cancel ", 7); + longc[CK_LC_LINE_MAX + 14] = '\r'; longc[CK_LC_LINE_MAX + 15] = 0; + static const char *sc[9] = { 0, "", "", "", "", "", "", "", 0 }; + sc[0] = longc; + CHECK(run(sc, 8, &g) == 0 && g_refused == 1 && g_refused_invalid == 1 && g.overlong == 1); + } + { + /* empty lines and a CR LF pair are ignored; " cancel " with spaces cancels at once */ + static const char *const sc[9] = { "\r\n\r\n", " cancel \r\n", "", "", "", "", "", "", 0 }; + CHECK(run(sc, 8, &g) == 2 && g_refused == 0); + } + { + /* nothing typed: every step runs */ + static const char *const sc[9] = { "", "", "", "", "", "", "", "", 0 }; + CHECK(run(sc, 8, &g) == 0 && g_refused == 0); + } + /* bounded: a UART that never runs dry cannot hold one poll call */ + ck_line_rx_init(&g); + g_polls = 0; + CHECK(ck_line_rx_cancel_poll(&g, g_always_a, refuse) == 0 && g_polls == CK_LINE_RX_BURST && g.overflow == 1); + + return ck_t_verdict("CK_CONSOLE_RX"); +} diff --git a/scripts/.crumb b/scripts/.crumb index ecc91bd0..11b69ded 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T17:02:49Z", + "compiled_at": "2026-10-12T17:55:37Z", "compiler": "crumb-compile/1", - "digest": "sha256:472997503f5d637af1f91e8eab7ecfe10ddee01e79bd42fb46ba245f061c3607", + "digest": "sha256:fa53022eb88e3cb8dbbeae8d5da3a7601ba4ca51030d9169e4fefafa8db5ee29", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 87, - "generated_at_commit": "d7c6c9c90f6711626732bcb168f95cbf45671685", - "source_tree": "sha256:6135f7ced35ec6d2f1cd76121c425b428064f5c344d255c1c6e760f1eca6fb76" + "generated_at_commit": "0fef1545d535093462d69b9318a40c232debd709", + "source_tree": "sha256:9df55cbd7fff1fa567534651db1578cfd22251e8e5c4d81407348b045c76cbed" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_lifecycle_test.sh b/scripts/qemu_ck_lifecycle_test.sh index d79c3fd4..5318523c 100755 --- a/scripts/qemu_ck_lifecycle_test.sh +++ b/scripts/qemu_ck_lifecycle_test.sh @@ -43,6 +43,12 @@ # row 167 stop order: store=closed, then dma_gate nvme bus master revoked, # then smmu stream back to abort, then stage lifecycle ok, then the # final report; QEMU exit 0; M1 checks +# row 167c operator input is the POLLED serial receive of the SPCR console +# UART: the ready line names it (`serial pl011 at 0x9000000, polled` +# on QEMU virt), and after the stop order `lifecycle: input +# uart=pl011 rx_errors=0 overruns=0 damaged_lines=0 overlong=1`; no +# `REFUSED console input` line (the 16550 path is host-tested only: +# QEMU virt has no memory-mapped 16550, see GATES.md row 167d) # row 168 unlock genesis (service image, blank disk): `unlock deadbeef` refused # (64 hex digits expected); `unlock <secret>` formats a production # Store with the keyslot manifest (genesis=1, generation 2, boot 1), @@ -339,7 +345,7 @@ m1 162 boot testkeys "${testkeys_efi}" drive_ready rcheck 163 "TEST-ONLY banner" '^lifecycle: TEST-ONLY service image \(CK_SERVICE_TEST_KEYS=1: TEST Store keys; QEMU only, never a production boot\)$' rcheck 163 "Store open, NVMe kept bound for the service lifetime" '^store: service lifetime: Store open, NVMe stays bound until the lifecycle stop order$' -rcheck 163 "lifecycle ready" '^lifecycle: ready state=ready store=open \(operator input: serial\)$' +rcheck 163 "lifecycle ready" '^lifecycle: ready state=ready store=open \(operator input: serial pl011 at 0x9000000, polled\)$' rcheck 182 "TEST-key Store: security manifest sequence 1 at genesis, no keyslot" '^store: security manifest sequence=1 generation=2 keyslot=none previous=genesis$' rcheck 173 "test-keys image provisions continuity at boot" '^continuity: PROVISIONED agent=[0-9a-f]{64} incarnation=1 sequence=1 cortex=0 branches=1$' before 173 "PROVISIONED < Store open line" '^continuity: PROVISIONED' '^store: service lifetime: Store open' @@ -353,6 +359,9 @@ rcheck 165 "cancel drops" '^lifecycle: cancelled state=ready$' rcheck 166 "overlong line refused whole" '^lifecycle: REFUSED verb=invalid reason="line longer than 144 bytes"$' rcheck 166 "evidence counts" '^lifecycle: evidence requests=12 refused=2 invalid=0 tasks=3 approved=1 denied=1 cancelled=1 overlong=1 last_commit_gen=[0-9]+ last_id=[0-9a-f]{8} prompts=0 replies=0 gen_cancelled=0 gen_failed=0 recalls=0 inference=none remembers=1 facts=1 cortex=open records=1$' rcheck 167 "stop order closed the Store" '^lifecycle: stop order store=closed nvme=released state=stop requests=13$' +rcheck 167c "input counters after the stop order (PL011, polled)" '^lifecycle: input uart=pl011 rx_errors=0 overruns=0 damaged_lines=0 overlong=1 dropped=[0-9]+$' +before 167c "stop order line < input counters" '^lifecycle: stop order store=closed' '^lifecycle: input uart=pl011 ' +rabsent 167c "no console-input refusal on QEMU virt" '^lifecycle: REFUSED console input' rcheck 179 "remember created the journal (header transaction, no records yet)" '^lifecycle: cortex open records=0 chunks=1 journal_bytes=32 store_gen=[0-9]+ heap_used_kib=[0-9]+ chain=ok$' rcheck 179 "remembered as record 1 (one sealed transaction)" '^lifecycle: remembered id=1 t=1 store_gen=[0-9]+ bytes=18 text="prefer short notes"$' rcheck 179 "facts lists the fact in the same boot" '^lifecycle: fact id=1 t=1 store_gen=[0-9]+ text="prefer short notes"$'