Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/patches/80b74a15afda018e # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/aienux#256 (code only) closed derived `80b74a15afda018e` #256 Imported from GitHub aien-dev/aienux#256 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `a93e27b8a26d45330e58e1b8df1b35faf7146886` · Head `465f135da3cfbc6ff5ece03b93483a15bbe521dc` github-advanced-security[bot] commented on `native/kernel/core/fbcon.c` line 68 on 2026-10-04 16:50 UTC ## CodeQL / Multiplication result converted to larger type Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'. Show more details github-advanced-security[bot] commented on `native/kernel/tools/ck_fb_check.c` line 222 on 2026-10-04 16:50 UTC ## CodeQL / Multiplication result converted to larger type Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'. Show more details github-advanced-security[bot] reviewed (COMMENTED) on 2026-10-04 16:50 UTC ### Apply it ``` git checkout -b patch-80b74a15afda018e a93e27b8a26d45330e58e1b8df1b35faf7146886 curl -fsSL https://interplane.io/drakestapleton/aienux/patches/80b74a15afda018e.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/aienux 256 465f135da3cfbc6ff5ece03b93483a15bbe521dc ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"aienux","number":256,"url":"https://github.com/aien-dev/aienux/pull/256","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:04Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index d41d1558..408a0bbe 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "9e7b47432d0ed2b4d3c5c5116b46dd1e6f822461349cdea84b675996e68ec493", - "last_commit": "25836ba", + "digest": "dadeade54c0150c968676ef8d07425d6bd80aba8bfcda7c6e651a911aa7775d3", + "last_commit": "1e28ff5", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "089867f62d3d142c6e7f5f9f1b8443f22504ab8d9397338824ef470456c3b2db", - "last_commit": "25836ba", + "digest": "26b2b9ef6aa2558a23af185081b97d8c20682dff0bd3027b673716db0735a4bf", + "last_commit": "741813e", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "f99911001560491e4c719aa841ac33c9cec413ee578fe55da847f4c781e992af", - "last_commit": "25836ba", + "digest": "c2faf9bb1f39cfe42057ef4fc740d04cc8c614bd4e31917f41b5cbe1acb8fcb6", + "last_commit": "1e28ff5", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:9813bfe9562ded60c5bf50caba75a7362a6c81aaac5b870227602f895501683c", - "compiled_at": "2026-10-04T15:51:27Z", + "children_root": "sha256:732633cd3795a4a92c3b89bc1f5fa53e1e8561b3c9102f16ad39b307732fd1d5", + "compiled_at": "2026-10-04T17:21:47Z", "compiler": "crumb-compile/1", - "digest": "sha256:2d09cd441f8ed98cd6f0569cf8d4460223f7debe8f5857da351688035c22ed8d", - "evidence_files": 142, - "evidence_root": "sha256:3b8ecf493ee0e4513ffb21827d50f30092f361f8a9a66e5abe4791e94c1cc8ec", - "files": 2832, - "generated_at_commit": "25836ba4a841e7c2b5777554919e0df79a0e665f", - "source_tree": "sha256:67f997b567d64f720308cfe9004e1ea9f053260f217dd5d5982ab73515229625" + "digest": "sha256:936d15f0099b43c18b244d8b6d384354f846081182a425eb0680e7c4d9799e39", + "evidence_files": 143, + "evidence_root": "sha256:3a3cbeef2e097d532b986e4579accee3f65ae5815e78716aefe3fd5f569812cf", + "files": 2841, + "generated_at_commit": "741813ed9493cd9165c2a14fc6b58a2e43025027", + "source_tree": "sha256:7dad0c994ecaf94880bbd5f3617b6b79e5c4eeef3e1a5ff512065bd79f3e191a" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index 706fa575..ca84d56f 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -62,7 +62,7 @@ jobs: - name: Install toolchain, QEMU and AAVMF firmware run: | sudo apt-get update - sudo apt-get install -y build-essential qemu-system-arm qemu-efi-aarch64 + sudo apt-get install -y build-essential qemu-system-arm qemu-efi-aarch64 socat uname -m gcc --version | head -1 qemu-system-aarch64 --version | head -1 @@ -90,6 +90,9 @@ jobs: - name: QEMU TCG gates env: AIENOS_QUIET_FLAG: ${{ runner.temp }}/spark-quiet + # The FPU, INFER and SCREEN children take the QEMU gate lock by exclusive create; + # its default home (~/workspace) does not exist on the runner. + AIENOS_GATE_LOCK: ${{ runner.temp }}/qemu-gate-lock run: | mkdir -p "${RUNNER_TEMP}/ck-receipt" set +e @@ -103,6 +106,7 @@ jobs: # FPU and INFER are not required: they need the Rust target aarch64-unknown-none (and INFER the 800 MB model file), which this # runner image is not known to have, so it prints NOT_RUN there (aienos#34 lanes 0, 4 and 5; INFER now also # requires the exact llama.cpp token sequence, "Paris" in the decoded text and a clean unload). + # SCREEN is required: it needs only QEMU (ramfb), AAVMF and socat (installed above) for the QMP screendump. # Every gate with a C implementation (source != missing in the # ck_gates.sh table) must be PASS. required=$(sed -n "/^CK_GATE_TABLE='/,/^'/p" scripts/ck_gates.sh | awk -F'|' 'NF==3 && $2!="missing" && $1!="FPU" && $1!="INFER" {print $1}') diff --git a/docs/.crumb b/docs/.crumb index 09fa8ede..d82ff49d 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -30,14 +30,14 @@ } ], "children_root": "sha256:55d44b8c5361b8f2452ed7fab6a4b51a8bb1f92763f67f1273dd9be45f8cfde0", - "compiled_at": "2026-10-04T15:01:15Z", + "compiled_at": "2026-10-04T16:47:58Z", "compiler": "crumb-compile/1", - "digest": "sha256:9e7b47432d0ed2b4d3c5c5116b46dd1e6f822461349cdea84b675996e68ec493", + "digest": "sha256:dadeade54c0150c968676ef8d07425d6bd80aba8bfcda7c6e651a911aa7775d3", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 56, - "generated_at_commit": "39e611ed040126791acdb667dbbc288a3757858a", - "source_tree": "sha256:be6a02bd78283cef9fec88ec889967fdc517875dc68e939c382ceefbb06dc248" + "generated_at_commit": "2e44c0bba93bcc605dd45570ee8cfb8d56591cc3", + "source_tree": "sha256:7f40b47e69ed9e07cad80117e9c38548253fe5ce1e5420403904b8ba062cd641" }, "owner_lane": "", "provenance": { diff --git a/docs/BOOT_HANDOFF_CONTRACT.md b/docs/BOOT_HANDOFF_CONTRACT.md index 2cb3ea6a..dc835c0a 100644 --- a/docs/BOOT_HANDOFF_CONTRACT.md +++ b/docs/BOOT_HANDOFF_CONTRACT.md @@ -45,7 +45,7 @@ There is **no Rust loader to C kernel handoff in the code**. Three facts: exists anywhere (ADR 0024 Q3). So this contract freezes the record the C kernel already accepts -(`ck_handoff`, magic `CHANDOF2`) as the **one** entry ABI. Any loader (the C +(`ck_handoff`, magic `CHANDOF3`) as the **one** entry ABI. Any loader (the C stub today; the Rust loader only if Q3 is reopened; Atlas later) must produce exactly this record. The Rust loader is not extended by this document. @@ -68,7 +68,7 @@ little endian). **They are not compiler-checked**: the code cut in section | Off | Size | Field | Meaning | Producer | Kernel reads it? | | --- | --- | --- | --- | --- | --- | -| 0 | 8 | `magic` | `CK_HANDOFF_MAGIC` = `0x32464f444e414843`, ASCII `CHANDOF2` little endian (`handoff.h`). `CK_HANDOFF_MAGIC_V1` (`CHANDOF1`, the 112-byte layout) is refused | `efi_main.c` | yes, `kmain.c`, `core/handoff_check.c` | +| 0 | 8 | `magic` | `CK_HANDOFF_MAGIC` = `0x33464f444e414843`, ASCII `CHANDOF3` little endian (`handoff.h`). `CHANDOF1` (the 112-byte layout) and `CHANDOF2` (the 192-byte layout) are refused as `unsupported version 1` / `2` | `efi_main.c` | yes, `kmain.c`, `core/handoff_check.c` | | 8 | 4 | `firmware_el` | `CurrentEL` at UEFI entry | `efi_main.c:61,63` | yes, report only `kmain.c:57` | | 12 | 4 | `desc_version` | UEFI memory descriptor version from `GetMemoryMap` | `efi_main.c:128` | **no** (never checked) | | 16 | 8 | `firmware_ttbr0` | `TTBR0_EL2` (or EL1) of the firmware regime | `efi_main.c:67,70` | yes, report only `kmain.c:53` | @@ -93,16 +93,24 @@ little endian). **They are not compiler-checked**: the code cut in section | 176 | 8 | `model_disk_last_block` | `EFI_BLOCK_IO_MEDIA.LastBlock` of the matched whole disk | `efi_model.c` | report only | | 184 | 4 | `model_block_size` | 512 or 4096 | `efi_model.c` | yes, `core/handoff_check.c` | | 188 | 4 | `reserved1` | zero; refused if nonzero | zero (BSS) | yes, `core/handoff_check.c` | -| 192 | | end | total size 192 bytes (`_Static_assert` in `handoff.h`) | | | +| 192 | 8 | `fb_base` | CHANDOF3: `FrameBufferBase` of the chosen GOP mode (physical address of pixel (0,0), UEFI 2.10 section 12.9.2); 0 unless `fb_status` is 1 | `efi_gop.c` | yes, `core/handoff_check.c`, mapped Device-nGnRE by `mm/mmu.c` (`ck_mmio_map`) | +| 200 | 8 | `fb_size` | `FrameBufferSize`; must be at least `fb_pitch * fb_height * 4` | `efi_gop.c` | yes, `core/handoff_check.c` | +| 208 | 4 | `fb_width` | `HorizontalResolution`, 1..16384 | `efi_gop.c` | yes, check + `core/fbcon.c` | +| 212 | 4 | `fb_height` | `VerticalResolution`, 1..16384 | `efi_gop.c` | yes, check + `core/fbcon.c` | +| 216 | 4 | `fb_pitch` | `PixelsPerScanLine` (pixels, not bytes), `fb_width`..16384 | `efi_gop.c` | yes, check + `core/fbcon.c` | +| 220 | 4 | `fb_format` | `EFI_GRAPHICS_PIXEL_FORMAT`: 0 RGBX or 1 BGRX when present; with `fb_status` 2 the format the first GOP reported (report only) | `efi_gop.c` | yes, `core/handoff_check.c` | +| 224 | 4 | `fb_status` | 0 `CK_HANDOFF_FB_NONE` (no GOP; every `fb_*` field zero), 1 `CK_HANDOFF_FB_PRESENT`, 2 `CK_HANDOFF_FB_NO_LINEAR` (GOP present, only `PixelBitMask`/`PixelBltOnly`; `fb_base`/`fb_size` zero); other values refused | `efi_gop.c` | yes, `core/handoff_check.c`, `core/kmain.c` | +| 228 | 4 | `fb_gop_handles` | GOP handles `LocateHandleBuffer` returned (report only; nonzero unless `fb_status` is 0) | `efi_gop.c` | check only | +| 232 | | end | total size 232 bytes (`_Static_assert` in `handoff.h`) | | | ### 3.1 Inputs the task asked about that are not in the record | Input | Status today | Where it comes from instead | | --- | --- | --- | -| Version field | The version is the trailing digit inside the magic (`CHANDOF2`, `handoff.h`); a new layout gets a new magic, there is no separate version number. `CHANDOF2` (2026-10-04) appended the boot-disk model block (offsets 112..192, section 3). `CHANDOF1` records are refused (`handoff_check.c`, `test_handoff.c` case 2). | | -| Record size field | **MISSING.** The magic fixes the size: `CHANDOF1` = 112 bytes, `CHANDOF2` = 192 bytes (`_Static_assert` in `handoff.h`). | | +| Version field | The version is the trailing digit inside the magic (`CHANDOF3`, `handoff.h`); a new layout gets a new magic, there is no separate version number. `CHANDOF2` (2026-10-04) appended the boot-disk model block (offsets 112..192), `CHANDOF3` (2026-10-04, L6-C) the GOP framebuffer block (offsets 192..232, section 3). `CHANDOF1` and `CHANDOF2` records are refused with `handoff: unsupported version (kernel reads CHANDOF3 only)` (`handoff_check.c`, `test_handoff.c` case 2; QEMU: the AIENOS_CK_SCREEN negative control). | | +| Record size field | **MISSING.** The magic fixes the size: `CHANDOF1` = 112 bytes, `CHANDOF2` = 192 bytes, `CHANDOF3` = 232 bytes (`_Static_assert` in `handoff.h`). | | | DTB pointer | **MISSING.** The C kernel is ACPI only (no `fdt`/`dtb` symbol anywhere in `native/`). Not part of v1. | | -| Framebuffer (GOP) | **MISSING** in `ck_handoff`. The Rust loader captures one (`crates/aienos-boot/src/handoff.rs:1170-1178`, type `crates/aienos-kernel/src/display/mod.rs:22-30`), the C stub does not. Not part of v1. | | +| Framebuffer (GOP) | **In the record since `CHANDOF3`** (offsets 192..232). The stub (`native/boot/efi_gop.c`) takes the GOP on ConOut's handle when it has a linear 32-bit framebuffer, else the first GOP handle that does; it reads the current mode only (no `SetMode`, no `Blt`). The kernel maps the visible bytes (`fb_pitch * fb_height * 4`) Device-nGnRE with `ck_mmio_map` when they lie outside every RAM range it maps write-back, else refuses the screen and says so on the UART (`screen: refused ...`). It then mirrors every console line on screen (`core/fbcon.c`: 8x8 font, white on black, half-scroll). No GOP: `screen: none ...` on the UART and the boot goes on. | | | Console UART | Not in the record. The stub parses SPCR and configures the console **inside the shared image** (`efi_main.c:91-95`); the kernel inherits that state through static variables, not through the record. A separately linked kernel would get no console. **MISSING** for that case. | | | Entropy | Not in the record. The kernel probes `RNDR` itself and fails closed (`kmain.c:121-132`, `arch/rndr.c`). No loader-supplied seed; PROPOSED: never accept one (a loader seed would be an unverified input). | | | Owner key material (after #215) | Not in the record. Owner **public** keys and machine id are compiled into the hardware staging image at build time (`native/kernel/Makefile:97-125`, `CK_OWNER_PUBKEYS`, `CK_MACHINE_ID`). PROPOSED: the handoff never carries key material. | | @@ -178,7 +186,7 @@ panic: | --- | --- | --- | | `h == NULL` | **not checked**: `kmain.c:174` dereferences | PROPOSED `panic: handoff: null record` | | bad magic | CODE `kmain.c:174-175` | `panic: handoff: bad magic` (exists, frozen) | -| unknown newer magic `CHANDOF` | refused as bad magic (same line) | PROPOSED `panic: handoff: unsupported version ` | +| unknown newer magic `CHANDOF` | CODE `core/handoff_check.c` (any `CHANDOF` other than 3, including the old 1 and 2) | `panic: handoff: unsupported version (kernel reads CHANDOF3 only)` | | `reserved0 != 0` | **not checked** | PROPOSED `panic: handoff: reserved field nonzero` | | `desc_size < 40` or not a multiple of 8 | partly: `< 40` makes `ck_frames_from_efi` return -1 and the kernel panics `mm: no usable memory in the UEFI map` (`mm/frames.c:95`, `mm/mmu.c:113-116`) | PROPOSED `panic: handoff: bad descriptor size ` | | `desc_version != 1` | **not checked** | PROPOSED `panic: handoff: bad descriptor version ` (value 1 per UEFI `EFI_MEMORY_DESCRIPTOR_VERSION`, UNVERIFIED in this cut) | @@ -193,6 +201,8 @@ panic: | model present with `model_len == 0`, `model_base` not 4 KiB aligned, base+len overflow, `model_block_size` not 512/4096, or `model_extents` 0 or > 128 | CODE `core/handoff_check.c`, `tests/test_handoff.c` case 7 | `handoff: bad model range` / `model base unaligned` / `model range overflow` / `bad model block size` / `bad model extents` | | no model (`model_flags == 0`) but any model field or `model_sha256` byte nonzero | CODE `core/handoff_check.c` | `handoff: model fields without model` | | `reserved1 != 0` | CODE `core/handoff_check.c` | `handoff: reserved1 field nonzero` | +| `fb_status` not 0/1/2; `fb_status` 0 with any `fb_*` field nonzero; `fb_status` 2 with `fb_base`/`fb_size` set or no GOP handle; `fb_status` 1 with `fb_format` not 0/1, width/height 0 or > 16384, pitch < width or > 16384, base 0 or not 4-byte aligned, `fb_size < fb_pitch * fb_height * 4`, base+size overflow, or no GOP handle | CODE `core/handoff_check.c`, `tests/test_handoff.c` case 8 | `handoff: bad fb status ` / `fb fields without gop` / `fb range without linear framebuffer ` / `bad fb gop handles 0` / `bad fb format ` / `bad fb width ` / `bad fb height ` / `bad fb pitch ` / `bad fb base ` / `fb size too small ` / `fb range overflow ` | +| framebuffer overlaps a RAM range the kernel maps write-back | CODE `mm/mmu.c` (not a panic: no screen) | `screen: refused (framebuffer 0x+0x overlaps RAM mapped write-back); report on UART only` | | declared `model_sha256` differs from the SHA-256 of the loaded bytes | CODE `core/infer.c` (not a panic: the kernel refuses to decode and reports `AIENOS_CK_INFER: FAIL`) | `infer: sha256 mismatch declared=` | Every PROPOSED check runs **before** `ck_mm_build` (before the first frame @@ -273,7 +283,7 @@ QEMU only; Machine 1 is NOT_RUN. ## 8. Frozen forever vs extensible -**Frozen (v2, `CHANDOF2`; v1 `CHANDOF1` is superseded and refused):** the magic value; the 192-byte layout and every +**Frozen (v3, `CHANDOF3`; v1 `CHANDOF1` and v2 `CHANDOF2` are superseded and refused):** the magic value; the 232-byte layout and every offset in section 3; the meaning of every field; `x0` = record address; `ExitBootServices` done before the call; the reserved-range rules in section 5; the `panic: handoff: bad magic` line; "no rollback state and no @@ -291,7 +301,7 @@ Host unit tests (no QEMU) against a PROPOSED pure validator, each with the exact refusal line from section 6: 1. NULL record. -2. Magic off by one bit; the old magic `CHANDOF1` (DONE: `tests/test_handoff.c` case 2). +2. Magic off by one bit; the old magics `CHANDOF1` and `CHANDOF2` and a future `CHANDOF4` (DONE: `tests/test_handoff.c` case 2; `CHANDOF2` also in QEMU, `scripts/qemu_ck_screen_test.sh` negative control). 3. `reserved0 = 1`. 4. `desc_size` 0, 39, 41 (not a multiple of 8). 5. `desc_version` 0 and 2. diff --git a/docs/NATIVE_BOOT_ONE_TIME.md b/docs/NATIVE_BOOT_ONE_TIME.md index 5e731c7d..68f84419 100644 --- a/docs/NATIVE_BOOT_ONE_TIME.md +++ b/docs/NATIVE_BOOT_ONE_TIME.md @@ -75,6 +75,14 @@ The staging script: 3. Creates/verifies non-default boot entry `Boot0000 "AIENOS handoff (one-time)"`. 4. Sets `BootNext = 0000`. +#### Step 2 (C kernel variant, L6 / L6-C): `scripts/stage_one_time_boot_ck.sh` +For the C kernel infer image plus `MODEL.MAP` (the yardstick model read through the firmware's Block I/O, aienos#34 lane 6), with its console mirrored on the GOP framebuffer (CHANDOF3) and held on screen for 120 s before the reset: +```bash +scripts/stage_one_time_boot_ck.sh --dry-run # prints every command, touches nothing +scripts/stage_one_time_boot_ck.sh --apply # operator only, attended boot follows +``` +One of the two flags is required. `--apply` stops before touching anything if the tree is dirty, the model or the ESP is not on `/dev/nvme0n1`, Secure Boot is on, `BootNext` is already set, or `Boot0004 AIENOSRECOV` is absent. In order it: builds the image (`CK_INFER_LIB`, `CK_FB_HOLD_S=120`) and `ck_model_map`; `chattr +i` on the model (first, so its blocks cannot move after the map is made); `ck_model_map make --fiemap --part-start auto --disk /dev/nvme0n1`, then `ck_model_map check` (re-reads every extent by LBA and recomputes the SHA-256) and requires the pinned model hash; `verify_native_rollback.sh --capture-pre`; copies `aienos-ck.efi`, `MODEL.MAP` and `STAGED-CK.TXT` to `\EFI\AIENOS`; creates a create-only boot entry, restores `BootOrder` if it changed, checks `Boot0004 AIENOSRECOV` is still present, and sets `BootNext` once. It never reboots. After the return to Linux: `--capture-post`, then `sudo chattr -i` on the model. + ### Step 3: Candidate Boot & Observation 1. Reboot the machine: ```bash diff --git a/evidence/ck_gates_ad05e004e30237e57e72fc1d3362cfe2b31af9b99451d9d2bb2414238e4d6590.json b/evidence/ck_gates_ad05e004e30237e57e72fc1d3362cfe2b31af9b99451d9d2bb2414238e4d6590.json new file mode 100644 index 00000000..f4164e4e --- /dev/null +++ b/evidence/ck_gates_ad05e004e30237e57e72fc1d3362cfe2b31af9b99451d9d2bb2414238e4d6590.json @@ -0,0 +1,55 @@ +{ + "schema": "aienos.ck_gates.v1", + "started_utc": "2026-10-04T16:45:20Z", + "finished_utc": "2026-10-04T17:19:57Z", + "commit": "2e44c0bba93bcc605dd45570ee8cfb8d56591cc3", + "commit_subject": "native: AIENOS_CK_SCREEN gate (ramfb + QMP screendump) for the screen console", + "tree_clean_before": true, + "tree_clean_after": true, + "quiet_flag": "/tmp/l6c-quiet-flag", + "quiet_flag_present_at_start": false, + "host": {"hostname": "spark-b87b", "arch": "aarch64", "kernel": "7.0.0-1019-nvidia", "cpu_model": "Cortex-A725;Cortex-X925"}, + "qemu": {"binary": "/usr/bin/qemu-system-aarch64", "version": "QEMU emulator version 8.2.2 (Debian 1:8.2.2+ds-0ubuntu1.18)"}, + "firmware": {"aavmf_code": "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd", "aavmf_code_sha256": "4a4cb7f6d8106bb2a7dd8c763fab14b1810152136fc4304e5b728f0043e84f12", "aavmf_vars": "/usr/share/AAVMF/AAVMF_VARS.fd", "aavmf_vars_sha256": "b3b855c5a80310168051164986855692d1bdb06e67619856177965cd87c6774f"}, + "nvme_dma_mode": "Confined (QEMU SMMUv3 stage 1, out-of-window DMA faulted); no-SMMU boot denied (NoSmmu); TEST-ONLY bypass image checked separately", + "children": [ + {"name": "boot", "script": "scripts/qemu_ck_boot_test.sh", "present": true, "script_sha256": "d17a7e0f00081e935a804c092c9b05c0bd1f319f5dd5c8bd90f3982e8939c3c8", "exit": "0", "seconds": 8, "log_sha256": "3ef663a8b5ee94f58d5f7d9d8e52b4a6295bb8209fa0b35124080514148c91da", "log_lines": 24}, + {"name": "store", "script": "scripts/qemu_ck_store_test.sh", "present": true, "script_sha256": "0b31a44af9388302d5488fdef318a509c4f26c2420f82ceb2fa7f7b698647748", "exit": "0", "seconds": 94, "log_sha256": "4a12904b986e6dc1d0e1913f74f44a1886341a2320db307eb824bd94b534a8d4", "log_lines": 612}, + {"name": "net", "script": "scripts/qemu_ck_net_test.sh", "present": true, "script_sha256": "ea051cc946c206f92c0c1563b3463b6bebffbce04e361e76d51dd49c1be4a6cf", "exit": "0", "seconds": 19, "log_sha256": "65f6e6e38ffdb0ceae54ac20211ca8e3282509007f1a4263ab1011136b7b4008", "log_lines": 95}, + {"name": "artifact", "script": "scripts/qemu_ck_artifact_test.sh", "present": true, "script_sha256": "e60f6c4aed822f693a530cb98b2fa4689b7b56e7c0efed5f9bf9ff4e9f75fc67", "exit": "0", "seconds": 32, "log_sha256": "e72bad216f91a9855982d2c3de0f7c50281879bda167e3551a79bba75a60f681", "log_lines": 215}, + {"name": "smp", "script": "scripts/qemu_ck_smp_test.sh", "present": true, "script_sha256": "b5665568394f391c17aaa9148bce2358f1145240cc38422c2927664b0ffd41d6", "exit": "0", "seconds": 6, "log_sha256": "46d107d9db7ccfbe0bc5327b5b96b99fd952b6efce203c98c7dbe58b00f76f0e", "log_lines": 16}, + {"name": "crash", "script": "scripts/qemu_ck_store_crash_test.sh", "present": true, "script_sha256": "3d04ca0775db7e70a244b6a09b19c5adf987f777b6ff630874c42e339add7765", "exit": "0", "seconds": 676, "log_sha256": "4059e2ca3fc2df078693ca717505424da031e32d9b8da1a159ced4e993dc12c6", "log_lines": 239}, + {"name": "disk", "script": "scripts/qemu_ck_disk_layout_test.sh", "present": true, "script_sha256": "f490548245252b97518e9049ce8e7078f5297c81584b60f08f802cfea6bb3110", "exit": "0", "seconds": 57, "log_sha256": "f06f9ca1b2b5a698f7420206cd78594ae38d95ef6fb9f9e9cfa554fe3e0002ad", "log_lines": 264}, + {"name": "cont", "script": "scripts/qemu_ck_continuity_test.sh", "present": true, "script_sha256": "30a8eb2dbb949eab29ad046231869a306199908022cb2345151988ea4957cf2e", "exit": "0", "seconds": 183, "log_sha256": "5287c408f8d63d4ab8dc961b887c72b3d41f1553d44de4bf757cb5e3ecdf5be3", "log_lines": 57}, + {"name": "recov", "script": "scripts/qemu_ck_recovery_test.sh", "present": true, "script_sha256": "89c461e211532f6577d2c88668ae8ca0d32d91f3b29ce6e39f7082a03a45b8cc", "exit": "0", "seconds": 115, "log_sha256": "500cd02050eae8f2f4aa34fdb004ff4d5399751de25de9dfe554ed5cdca32e30", "log_lines": 46}, + {"name": "fpu", "script": "scripts/qemu_ck_fpu_test.sh", "present": true, "script_sha256": "f04fa538752f6864bc2d5f9ff5af6eac71a5e3a005fe9c76b77477012325cc14", "exit": "0", "seconds": 8, "log_sha256": "13096f2e5a583d9f1ace84452186aeafb0806807c5d17ae87c12a0f0df4e5f38", "log_lines": 13}, + {"name": "infer", "script": "scripts/qemu_ck_infer_test.sh", "present": true, "script_sha256": "185c78b8688004dc6a807182c81e319b1598414935934b6c881cfafae5ce31fa", "exit": "0", "seconds": 862, "log_sha256": "ceb0955ff1d4a7960310747590689acf5193639f28b6d5890e2340c163862d20", "log_lines": 35}, + {"name": "screen", "script": "scripts/qemu_ck_screen_test.sh", "present": true, "script_sha256": "b2b71aff7fb9274eb15d8381e44dda9d7b700821fd45a23cde1c9a1132dc6b3f", "exit": "0", "seconds": 16, "log_sha256": "3d956bb4633a2acbaa986e74987caebf811230508e53bb16f4400a214c5a79ec", "log_lines": 30} + ], + "gates": [ + {"id": "M1", "marker": "AIENOS_CK_M1", "source": "boot", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M3", "marker": "AIENOS_CK_M3", "source": "boot", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "SMMU", "marker": "AIENOS_CK_SMMU", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "NVME_SHUTDOWN", "marker": "AIENOS_CK_NVME_SHUTDOWN", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "P2_ARTIFACT", "marker": "AIENOS_CK_P2_ARTIFACT", "source": "artifact", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M0_ROLLBACK", "marker": "AIENOS_CK_M0_ROLLBACK", "source": "missing", "verdict": "NOT_RUN", "reason": "MISSING_IMPLEMENTATION: C loader signatures, A/B, BootNext and rollback are parked (native/boot/README.md)"}, + {"id": "M4_NVME", "marker": "AIENOS_CK_M4_NVME", "source": "store", "verdict": "PASS", "reason": "SMMU-confined NVMe DMA in QEMU (iommu=smmuv3, default build); TEST-ONLY bypass build boot-checked separately"}, + {"id": "M4_STORE", "marker": "AIENOS_CK_M4_STORE", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_STORE_CRASH", "marker": "AIENOS_CK_M4_STORE_CRASH", "source": "crash", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_CONTINUITY", "marker": "AIENOS_CK_M4_CONTINUITY", "source": "cont", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "M4_RECOVERY", "marker": "AIENOS_CK_M4_RECOVERY", "source": "recov", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "ARGUS1_REVOKE", "marker": "AIENOS_CK_ARGUS1_REVOKE", "source": "store", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "KEYBOARD", "marker": "AIENOS_CK_KEYBOARD", "source": "missing", "verdict": "NOT_RUN", "reason": "MISSING_IMPLEMENTATION: no xHCI/USB HID keyboard driver in the C kernel"}, + {"id": "NET", "marker": "AIENOS_CK_NET", "source": "net", "verdict": "PASS", "reason": "QEMU user networking (slirp), virtio-net with ACCESS_PLATFORM required behind the smmuv3 vIOMMU; this PASS covers: attach, UDP TX seen by the host helper, UDP reply RX parsed by M6-A, an out-of-window device DMA refused (F_TRANSLATION, page intact) and recovery by reset, as checked by this run only; QEMU, not hardware"}, + {"id": "SMP", "marker": "AIENOS_CK_SMP", "source": "smp", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "DISK_LAYOUT", "marker": "AIENOS_CK_DISK_LAYOUT", "source": "disk", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "FPU", "marker": "AIENOS_CK_FPU", "source": "fpu", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "INFER", "marker": "AIENOS_CK_INFER", "source": "infer", "verdict": "PASS", "reason": "child reported PASS, exit 0"}, + {"id": "SCREEN", "marker": "AIENOS_CK_SCREEN", "source": "screen", "verdict": "PASS", "reason": "child reported PASS, exit 0"} + ], + "counts": {"total": 19, "pass": 17, "fail": 0, "not_run": 2}, + "verdict": "NOT_ALL_GATES_PASS", + "parity": "native/kernel/GATES.md", + "physical": "NOT_RUN", + "physical_statement": "QEMU emulator runs only. Nothing here was run on Machine 1 or any GB10; no physical qualification is claimed." +} diff --git a/native/.crumb b/native/.crumb index df0e513e..9f1bcfec 100644 --- a/native/.crumb +++ b/native/.crumb @@ -55,8 +55,8 @@ "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "5e920ca9d6fae601ce4e308e7a38fd9cfec409cb532199052942bf55900ebf52", - "last_commit": "25836ba", + "digest": "f181cbf296165f1d483535eafbc9d7a1056ab20aa838ea23e39ef55fb80d9b1b", + "last_commit": "2e44c0b", "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": "722d02a0ebe40a245474586e556ca0fa1de514db35c363ecf42a8e75f8956cd0", - "last_commit": "25836ba", + "digest": "9ee6c06ce6047c883f876c781369b1d9339e703fc3a8463e3aa15d2292f0eab9", + "last_commit": "c2232ef", "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:d352344bc35416b2b37b5d0182913e84fd1dee543b41719bf6147fe54eddb074", - "compiled_at": "2026-10-04T15:51:27Z", + "children_root": "sha256:f4c7b8fbe0a234ba02f5f12d89aa6063c4cc13b86ae2ec667851819cbd74b9a9", + "compiled_at": "2026-10-04T17:20:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:089867f62d3d142c6e7f5f9f1b8443f22504ab8d9397338824ef470456c3b2db", + "digest": "sha256:26b2b9ef6aa2558a23af185081b97d8c20682dff0bd3027b673716db0735a4bf", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 294, - "generated_at_commit": "25836ba4a841e7c2b5777554919e0df79a0e665f", - "source_tree": "sha256:af2f78a5886f4014434c00746ae6af6b9c9f7f4eb1a310241f1e6c89d91dc624" + "files": 300, + "generated_at_commit": "c2232ef1575db74f797a28751152427d476a95b5", + "source_tree": "sha256:048466ad9405f6f56ed880e07bf527d5d274a84db303ed4f0bf8ebe79b08343d" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index ca9ed19d..ee88a3ba 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T15:01:15Z", + "compiled_at": "2026-10-04T16:44:17Z", "compiler": "crumb-compile/1", - "digest": "sha256:5e920ca9d6fae601ce4e308e7a38fd9cfec409cb532199052942bf55900ebf52", + "digest": "sha256:f181cbf296165f1d483535eafbc9d7a1056ab20aa838ea23e39ef55fb80d9b1b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 8, - "generated_at_commit": "39e611ed040126791acdb667dbbc288a3757858a", - "source_tree": "sha256:42b450baaa15f4ff10b97162c6b0ea2ebc9e3fc76f7a768ae88b323e4f673d63" + "files": 9, + "generated_at_commit": "f37c8b3a5d191f4e14282ae44aedd95e82581907", + "source_tree": "sha256:bb6a59836d733bce358a2d9d38d92b8de5ba05ffe94ebc598ea3e7d9df837364" }, "owner_lane": "", "provenance": { diff --git a/native/boot/efi.h b/native/boot/efi.h index e4e10896..b10861f9 100644 --- a/native/boot/efi.h +++ b/native/boot/efi.h @@ -2,7 +2,7 @@ * boot services it calls (GetMemoryMap, ExitBootServices, SetWatchdogTimer, * AllocatePages, FreePages, FreePool, HandleProtocol, LocateHandleBuffer), * the Loaded Image, Simple File System and Block I/O protocols (model ingest, - * efi_model.c). Field orders and offsets follow UEFI 2.10 (edk2 + * efi_model.c) and the Graphics Output Protocol (framebuffer, efi_gop.c). Field orders and offsets follow UEFI 2.10 (edk2 * MdePkg/Include/Uefi/UefiSpec.h, Protocol/BlockIo.h, SimpleFileSystem.h, * LoadedImage.h); _Static_asserts below pin the offsets this stub relies on. * Everything not used is a void pointer placeholder of the right size. */ @@ -198,4 +198,39 @@ _Static_assert(offsetof(EFI_BLOCK_IO_MEDIA, BlockSize) == 12, "Media.BlockSize") _Static_assert(offsetof(EFI_BLOCK_IO_MEDIA, LastBlock) == 24, "Media.LastBlock"); _Static_assert(offsetof(EFI_BLOCK_IO_PROTOCOL, ReadBlocks) == 0x18, "BlockIo.ReadBlocks"); +/* --- Graphics Output Protocol (UEFI 2.10 section 12.9.2) --- */ +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID_INIT \ + { 0x9042a9de, 0x23dc, 0x4a38, { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } } +/* EFI_GRAPHICS_PIXEL_FORMAT */ +enum { PixelRedGreenBlueReserved8BitPerColor, PixelBlueGreenRedReserved8BitPerColor, PixelBitMask, + PixelBltOnly, PixelFormatMax }; +typedef struct { + uint32_t RedMask, GreenMask, BlueMask, ReservedMask; +} EFI_PIXEL_BITMASK; +typedef struct { + uint32_t Version; + uint32_t HorizontalResolution; + uint32_t VerticalResolution; + uint32_t PixelFormat; /* EFI_GRAPHICS_PIXEL_FORMAT (a C enum, 4 bytes) */ + EFI_PIXEL_BITMASK PixelInformation; + uint32_t PixelsPerScanLine; +} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION; +typedef struct { + uint32_t MaxMode; + uint32_t Mode; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + uint64_t SizeOfInfo; + uint64_t FrameBufferBase; /* EFI_PHYSICAL_ADDRESS */ + uint64_t FrameBufferSize; /* UINTN */ +} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; +typedef struct EFI_GRAPHICS_OUTPUT_PROTOCOL { + void *QueryMode, *SetMode, *Blt; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; +} EFI_GRAPHICS_OUTPUT_PROTOCOL; +_Static_assert(offsetof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION, PixelFormat) == 12, "Gop.Info.PixelFormat"); +_Static_assert(offsetof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION, PixelsPerScanLine) == 32, "Gop.Info.PixelsPerScanLine"); +_Static_assert(offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE, FrameBufferBase) == 24, "Gop.Mode.FrameBufferBase"); +_Static_assert(offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE, FrameBufferSize) == 32, "Gop.Mode.FrameBufferSize"); +_Static_assert(offsetof(EFI_GRAPHICS_OUTPUT_PROTOCOL, Mode) == 24, "Gop.Mode"); + #endif diff --git a/native/boot/efi_gop.c b/native/boot/efi_gop.c new file mode 100644 index 00000000..85ff0177 --- /dev/null +++ b/native/boot/efi_gop.c @@ -0,0 +1,84 @@ +/* efi_gop.c -- find the UEFI Graphics Output Protocol framebuffer before + * ExitBootServices and record it in the CHANDOF3 handoff (fb_* fields), so + * the kernel can draw its report on the screen (native/kernel/core/fbcon.c). + * + * UEFI 2.10 section 12.9: "The EFI_GRAPHICS_OUTPUT_PROTOCOL also exports + * enough information about the current mode for operating system startup + * software to access the linear frame buffer directly." The stub reads the + * current mode only; it never calls SetMode (the screen keeps the mode the + * firmware chose) and never calls Blt. + * + * Choice: the GOP on ConOut's handle when it has a linear framebuffer; + * otherwise the first handle (LocateHandleBuffer order) whose mode is + * PixelRedGreenBlueReserved8BitPerColor or PixelBlueGreenRedReserved8BitPerColor + * with a nonzero FrameBufferBase. (edk2's console splitter may put a + * Blt-only GOP on the ConOut handle; that one is skipped.) PixelBitMask and + * PixelBltOnly modes are not used: fb_status NO_LINEAR. No GOP at all: + * fb_status NONE, every fb_* field zero, and the kernel boots on the UART. */ +#include "efi.h" +#include "../kernel/core/ck_internal.h" + +static int linear(const EFI_GRAPHICS_OUTPUT_PROTOCOL *g) +{ + const EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *m = g ? g->Mode : 0; + if (!m || !m->Info || !m->FrameBufferBase) + return 0; + return m->Info->PixelFormat == PixelRedGreenBlueReserved8BitPerColor || + m->Info->PixelFormat == PixelBlueGreenRedReserved8BitPerColor; +} + +static void record(struct ck_handoff *h, const EFI_GRAPHICS_OUTPUT_PROTOCOL *g, const char *from) +{ + const EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *m = g->Mode; + const EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *i = m->Info; + h->fb_status = CK_HANDOFF_FB_PRESENT; + h->fb_base = m->FrameBufferBase; + h->fb_size = m->FrameBufferSize; + h->fb_width = i->HorizontalResolution; + h->fb_height = i->VerticalResolution; + h->fb_pitch = i->PixelsPerScanLine; + h->fb_format = i->PixelFormat; + ck_printf("gop: ok from=%s handles=%u mode=%u/%u %ux%u pitch=%u format=%u base=0x%llx size=0x%llx\n", + from, h->fb_gop_handles, m->Mode, m->MaxMode, i->HorizontalResolution, + i->VerticalResolution, i->PixelsPerScanLine, i->PixelFormat, + (unsigned long long)m->FrameBufferBase, (unsigned long long)m->FrameBufferSize); +} + +void ck_boot_gop_find(EFI_SYSTEM_TABLE *st, struct ck_handoff *h) +{ + static const EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID_INIT; + EFI_BOOT_SERVICES *bs = st->BootServices; + EFI_HANDLE *handles = 0; + uint64_t n = 0; + EFI_STATUS s = bs->LocateHandleBuffer(ByProtocol, &gop_guid, 0, &n, &handles); + if (s != EFI_SUCCESS || !n || !handles) { + ck_printf("gop: none (LocateHandleBuffer status=0x%llx handles=%llu)\n", (unsigned long long)s, + (unsigned long long)n); + return; /* fb_status NONE, every fb_* field still zero (BSS) */ + } + h->fb_gop_handles = n > 0xffffffffull ? 0xffffffffu : (uint32_t)n; + + EFI_GRAPHICS_OUTPUT_PROTOCOL *g = 0; + if (st->ConsoleOutHandle && + bs->HandleProtocol(st->ConsoleOutHandle, &gop_guid, (void **)&g) == EFI_SUCCESS && linear(g)) { + bs->FreePool(handles); + record(h, g, "conout"); + return; + } + uint32_t first_format = PixelFormatMax; + for (uint64_t k = 0; k < n; k++) { + g = 0; + if (bs->HandleProtocol(handles[k], &gop_guid, (void **)&g) != EFI_SUCCESS || !g) + continue; + if (linear(g)) { + bs->FreePool(handles); + record(h, g, "handle"); + return; + } + if (first_format == PixelFormatMax && g->Mode && g->Mode->Info) + first_format = g->Mode->Info->PixelFormat; + } + bs->FreePool(handles); + h->fb_status = CK_HANDOFF_FB_NO_LINEAR; + ck_printf("gop: no linear framebuffer (handles=%u first_format=%u)\n", h->fb_gop_handles, first_format); +} diff --git a/native/boot/efi_main.c b/native/boot/efi_main.c index 4a1c799e..39136eab 100644 --- a/native/boot/efi_main.c +++ b/native/boot/efi_main.c @@ -11,6 +11,13 @@ #include "../kernel/arch/arch.h" #include "../kernel/core/ck_internal.h" +/* TEST-ONLY (AIENOS_CK_SCREEN negative control, native/kernel/Makefile + * CK_TEST_STALE_HANDOFF=2): hand the kernel a CHANDOF2 magic. Never in a + * hardware staging image. */ +#if defined(CK_TEST_STALE_HANDOFF) && defined(CK_HARDWARE_STAGING) +#error "CK_TEST_STALE_HANDOFF is TEST-only and cannot be combined with CK_HARDWARE_STAGING" +#endif + #define MAP_BYTES (64u << 10) #define EXIT_TRIES 8 @@ -21,6 +28,7 @@ static struct ck_handoff handoff; static EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout; int ck_boot_model_load(EFI_HANDLE image, EFI_SYSTEM_TABLE *st, struct ck_handoff *h); +void ck_boot_gop_find(EFI_SYSTEM_TABLE *st, struct ck_handoff *h); static void efi_write(const char *s, size_t n) { @@ -98,6 +106,11 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) ck_puts("\n"); ck_report_header("pre_exit"); + /* The GOP framebuffer for the kernel's screen console (efi_gop.c, CHANDOF3). */ + ck_boot_gop_find(st, h); +#ifdef CK_TEST_STALE_HANDOFF + ck_puts("handoff: TEST-ONLY stale handoff image: the kernel gets a CHANDOF2 record; never counts toward a PASS\n"); +#endif /* The yardstick model from the boot disk, while the firmware drivers are * still up (efi_model.c). Absent map: boot continues without a model. */ ck_boot_model_load(image, st, h); @@ -146,5 +159,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) /* Boot services are gone: ConOut too. */ ck_console_set_efi(0); ck_set_stage("kernel_entry"); +#ifdef CK_TEST_STALE_HANDOFF + h->magic = CK_HANDOFF_MAGIC_V2; +#endif ck_kernel_entry(h); } diff --git a/native/boot/handoff.h b/native/boot/handoff.h index 7ccc36c3..17791e20 100644 --- a/native/boot/handoff.h +++ b/native/boot/handoff.h @@ -4,21 +4,38 @@ * * CHANDOF2 (2026-10-04, aienos#34 lane 6): CHANDOF1 plus the yardstick * model's bytes, read by the stub from the boot disk before ExitBootServices - * (native/boot/efi_model.c, map format native/boot/model_map.h). Per the - * contract (docs/BOOT_HANDOFF_CONTRACT.md section 8) a new layout gets a new - * magic; a kernel built for CHANDOF2 refuses CHANDOF1 as "bad magic". */ + * (native/boot/efi_model.c, map format native/boot/model_map.h). + * CHANDOF3 (2026-10-04, L6-C): CHANDOF2 plus the UEFI Graphics Output + * Protocol linear framebuffer the stub found before ExitBootServices + * (native/boot/efi_gop.c), so the kernel can show its report on a screen + * (core/fbcon.c). Per the contract (docs/BOOT_HANDOFF_CONTRACT.md section 8) + * a new layout gets a new magic; a kernel built for CHANDOF3 refuses + * CHANDOF1 and CHANDOF2 as "unsupported version ". */ #ifndef AIENOS_CK_HANDOFF_H #define AIENOS_CK_HANDOFF_H #include #include -#define CK_HANDOFF_MAGIC 0x32464f444e414843ull /* "CHANDOF2" */ +#define CK_HANDOFF_MAGIC 0x33464f444e414843ull /* "CHANDOF3" */ #define CK_HANDOFF_MAGIC_V1 0x31464f444e414843ull /* "CHANDOF1": refused */ +#define CK_HANDOFF_MAGIC_V2 0x32464f444e414843ull /* "CHANDOF2": refused */ +/* The seven bytes "CHANDOF" (little endian, low 56 bits); the top byte is + * the ASCII version digit. */ +#define CK_HANDOFF_MAGIC_STEM 0x00464f444e414843ull /* model_flags */ #define CK_HANDOFF_MODEL_PRESENT 1u /* model_base/model_len hold the model */ #define CK_HANDOFF_MODEL_BLOCKIO 2u /* read through UEFI Block I/O from MODEL.MAP */ +/* fb_status (CHANDOF3) */ +#define CK_HANDOFF_FB_NONE 0u /* no Graphics Output Protocol: every fb_* field zero */ +#define CK_HANDOFF_FB_PRESENT 1u /* linear 32-bit framebuffer, fb_format 0 (RGBX) or 1 (BGRX) */ +#define CK_HANDOFF_FB_NO_LINEAR 2u /* GOP found, but PixelBitMask/PixelBltOnly: fb_base/fb_size zero */ +/* fb_format: EFI_GRAPHICS_PIXEL_FORMAT (UEFI 2.10 section 12.9.2) */ +#define CK_HANDOFF_FB_RGBX 0u /* PixelRedGreenBlueReserved8BitPerColor: byte 0 red */ +#define CK_HANDOFF_FB_BGRX 1u /* PixelBlueGreenRedReserved8BitPerColor: byte 0 blue */ +#define CK_HANDOFF_FB_MAX_DIM 16384u /* refused above this width/height/pitch */ + struct ck_handoff { uint64_t magic; uint32_t firmware_el; /* CurrentEL at UEFI entry (2 on QEMU virtualization=on) */ @@ -46,10 +63,20 @@ struct ck_handoff { uint64_t model_disk_last_block; /* EFI_BLOCK_IO_MEDIA.LastBlock of the disk */ uint32_t model_block_size; /* EFI_BLOCK_IO_MEDIA.BlockSize of the disk */ uint32_t reserved1; /* zero */ + /* CHANDOF3: the GOP framebuffer (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE and its + * Info, UEFI 2.10 section 12.9.2), or all zero without a GOP. */ + uint64_t fb_base; /* FrameBufferBase: physical, pixel (0,0) */ + uint64_t fb_size; /* FrameBufferSize, bytes */ + uint32_t fb_width; /* HorizontalResolution, pixels */ + uint32_t fb_height; /* VerticalResolution, pixels */ + uint32_t fb_pitch; /* PixelsPerScanLine (pixels, not bytes) */ + uint32_t fb_format; /* CK_HANDOFF_FB_RGBX / _BGRX (EFI enum value) */ + uint32_t fb_status; /* CK_HANDOFF_FB_* */ + uint32_t fb_gop_handles; /* GOP handles the stub saw (report only) */ }; -/* Layout pins for the frozen CHANDOF2 record (docs/BOOT_HANDOFF_CONTRACT.md +/* Layout pins for the frozen CHANDOF3 record (docs/BOOT_HANDOFF_CONTRACT.md * section 3, LP64): a reorder, resize or new field fails the build. */ -_Static_assert(sizeof(struct ck_handoff) == 192, "ck_handoff size"); +_Static_assert(sizeof(struct ck_handoff) == 232, "ck_handoff size"); _Static_assert(offsetof(struct ck_handoff, magic) == 0, "ck_handoff.magic offset"); _Static_assert(offsetof(struct ck_handoff, firmware_el) == 8, "ck_handoff.firmware_el offset"); _Static_assert(offsetof(struct ck_handoff, desc_version) == 12, "ck_handoff.desc_version offset"); @@ -75,6 +102,14 @@ _Static_assert(offsetof(struct ck_handoff, model_read_us) == 168, "ck_handoff.mo _Static_assert(offsetof(struct ck_handoff, model_disk_last_block) == 176, "ck_handoff.model_disk_last_block offset"); _Static_assert(offsetof(struct ck_handoff, model_block_size) == 184, "ck_handoff.model_block_size offset"); _Static_assert(offsetof(struct ck_handoff, reserved1) == 188, "ck_handoff.reserved1 offset"); +_Static_assert(offsetof(struct ck_handoff, fb_base) == 192, "ck_handoff.fb_base offset"); +_Static_assert(offsetof(struct ck_handoff, fb_size) == 200, "ck_handoff.fb_size offset"); +_Static_assert(offsetof(struct ck_handoff, fb_width) == 208, "ck_handoff.fb_width offset"); +_Static_assert(offsetof(struct ck_handoff, fb_height) == 212, "ck_handoff.fb_height offset"); +_Static_assert(offsetof(struct ck_handoff, fb_pitch) == 216, "ck_handoff.fb_pitch offset"); +_Static_assert(offsetof(struct ck_handoff, fb_format) == 220, "ck_handoff.fb_format offset"); +_Static_assert(offsetof(struct ck_handoff, fb_status) == 224, "ck_handoff.fb_status offset"); +_Static_assert(offsetof(struct ck_handoff, fb_gop_handles) == 228, "ck_handoff.fb_gop_handles offset"); /* Kernel core entry, still at the firmware EL with firmware translation. */ __attribute__((noreturn)) void ck_kernel_entry(struct ck_handoff *h); diff --git a/native/kernel/.crumb b/native/kernel/.crumb index f84d9467..f85a5203 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": "76e09442c61ce7502463145cf8b9540f435ee8fba3cd06fa9f3f09a7e8d6f72d", - "last_commit": "25836ba", + "digest": "dd6ebb445202c084d41a923774ff81d2c0c384393b7383c92ed09e77028d2307", + "last_commit": "c2232ef", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, @@ -75,8 +75,8 @@ "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { - "digest": "ca0e875c3967ed75fa04e83792468a1ca61755b47c7de27b8e8981e687a341f8", - "last_commit": "25836ba", + "digest": "272bc1dd7957e2024660c4f2850462671069bec77f4eee8d2c71b5b8788ab97e", + "last_commit": "f37c8b3", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, @@ -87,27 +87,27 @@ "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { - "digest": "306b7082c04bacc3a3315c88685b5dd729b25eb31985db569d05541ee0a5204a", - "last_commit": "25836ba", + "digest": "451e82cfde801fae5f0062cba5a86d572636bed23d5ce4cdd3529c1ce28ba417", + "last_commit": "f37c8b3", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { - "digest": "e5811b3cdf60c98c2da590e21889e5e94f48755e13193b973a0b03c18a3edf25", - "last_commit": "25836ba", + "digest": "76d69ccab500306184f1ee05b9b252c740236a9656ceda44fe96c93bce2f2b21", + "last_commit": "c2232ef", "name": "tools", "purpose": "Directory native/kernel/tools. Purpose not yet described by a human." } ], - "children_root": "sha256:1b5f867956f142c67a72afbf610e6e98e1faffef6421d557a851299fc0759d75", - "compiled_at": "2026-10-04T15:51:27Z", + "children_root": "sha256:d01e49eb49d0b6304690bff7ff81c2e7c6525aaf33ce7f19dabce8f3e6c6d335", + "compiled_at": "2026-10-04T17:20:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:722d02a0ebe40a245474586e556ca0fa1de514db35c363ecf42a8e75f8956cd0", + "digest": "sha256:9ee6c06ce6047c883f876c781369b1d9339e703fc3a8463e3aa15d2292f0eab9", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 131, - "generated_at_commit": "25836ba4a841e7c2b5777554919e0df79a0e665f", - "source_tree": "sha256:92155543d330b395920064364a495a6a08468b4998a6cea80dc4f94dadf39f01" + "files": 136, + "generated_at_commit": "c2232ef1575db74f797a28751152427d476a95b5", + "source_tree": "sha256:26233472004fc3bb2dfea000922f7ccf096ec7750c8266e924689e24a37b342d" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md index b3bef3d8..f6570344 100644 --- a/native/kernel/GATES.md +++ b/native/kernel/GATES.md @@ -25,7 +25,7 @@ C gates (one line each from `ck_gates.sh`): `M1` and `M3` (from `scripts/qemu_ck_net_test.sh`; rows 102-106 and 110-112; the script now also checks the virtio-net SMMU fence (ACCESS_PLATFORM required, out-of-window device DMA refused), rows 102 and 110-112 are QEMU PASS on this branch from the committed forge log `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, hardware NOT_RUN), the kernel entropy rows 107-109 (M1 via `scripts/lib_ck_m1_checks.sh`, ARGUS1_REVOKE and M4_STORE via the Store gate boot 7), `DISK_LAYOUT` (C-only, from `scripts/qemu_ck_disk_layout_test.sh`, rows 118-123: QEMU PASS at 741b2b8 before the merge with main 8555049, rerun pending at the merged head; row 123 host test), and the NOT_RUN gates `SMP` (C-only, from `scripts/qemu_ck_smp_test.sh`, rows 113-117, NOT_RUN pending forge receipt), `M0_ROLLBACK`, `M4_STORE_CRASH` (now read from `scripts/qemu_ck_store_crash_test.sh`, rows 73-80; NOT_RUN until a forge receipt exists), -`M4_CONTINUITY`, `M4_RECOVERY`, `KEYBOARD`, `FPU` (C-only, from `scripts/qemu_ck_fpu_test.sh`, rows 124-128; QEMU PASS, hardware NOT_RUN), and `INFER` (C-only, from `scripts/qemu_ck_infer_test.sh`, rows 129-139; QEMU PASS, hardware NOT_RUN). +`M4_CONTINUITY`, `M4_RECOVERY`, `KEYBOARD`, `FPU` (C-only, from `scripts/qemu_ck_fpu_test.sh`, rows 124-128; QEMU PASS, hardware NOT_RUN), `INFER` (C-only, from `scripts/qemu_ck_infer_test.sh`, rows 129-139; QEMU PASS, hardware NOT_RUN), and `SCREEN` (C-only, from `scripts/qemu_ck_screen_test.sh`, rows 140-145; QEMU PASS, hardware NOT_RUN). `M4_NVME` and `SMMU` PASS in the SMMU-confined mode (default `make full` image, QEMU `iommu=smmuv3`). The unconfined bypass build @@ -499,7 +499,7 @@ corruption is covered only by the host test `dev/tests/disk_part_test.c` ## Summary counts -**C kernel receipt tally (QEMU only, no physical run):** 16 CK gates since the merge of main 8555049 (#224 adds `SMP`, #226 moves `M4_STORE_CRASH` to its own child script) into the CK-4 branch. The newest full receipt, `evidence/ck_gates_d80363cc871372963743ae85fc08c6fa4608f9870c4e06e8988f21950c73ace6.json` (full `ck_gates.sh` run at 741b2b8, the CK-4 branch after merging main #221 and #225; log CK-4-184524.log, `AIENOS_CK_GATES: NOT_ALL_GATES_PASS (pass=10 fail=0 not_run=5 of 15; physical NOT_RUN)`), predates that merge: by it, 10 of 16 CK gates PASS (the 9 of the earlier receipt plus `DISK_LAYOUT`), 6 NOT_RUN (M0_ROLLBACK, M4_STORE_CRASH, M4_CONTINUITY, M4_RECOVERY, KEYBOARD; and SMP, not in that receipt, NOT_RUN pending forge receipt), 0 FAIL. No `ck_gates.sh` run exists at the merged head yet; `M4_STORE_CRASH` stays NOT_RUN until a forge receipt. `DISK_LAYOUT` also PASSed alone (log CK-4-184423.log, translation-bypass mutant killed); the Store, NET and artifact gates boot GPT images now and PASS in the same receipt. The receipt before it was 9 of 14 CK gates PASS, 5 NOT_RUN, 0 FAIL (`evidence/ck_gates_929f287e9c950c45c7dcd569c7caa03709ea62ecfe393635b435058afa969c54.json`, run at 41aa0e6, which adds the kernel entropy rows 107-109; that commit was then rebased onto #210, which changed only README.md and CONTRIBUTING.md). The row counts below are per Rust-parity row, not per gate. +**C kernel receipt tally (QEMU only, no physical run):** Newest: `evidence/ck_gates_ad05e004e30237e57e72fc1d3362cfe2b31af9b99451d9d2bb2414238e4d6590.json` (full `ck_gates.sh` at 2e44c0b, L6-C branch, 19 CK gates with `SCREEN`): 17 PASS, 0 FAIL, 2 NOT_RUN (M0_ROLLBACK, KEYBOARD: MISSING_IMPLEMENTATION). Earlier: 16 CK gates since the merge of main 8555049 (#224 adds `SMP`, #226 moves `M4_STORE_CRASH` to its own child script) into the CK-4 branch. The newest full receipt, `evidence/ck_gates_d80363cc871372963743ae85fc08c6fa4608f9870c4e06e8988f21950c73ace6.json` (full `ck_gates.sh` run at 741b2b8, the CK-4 branch after merging main #221 and #225; log CK-4-184524.log, `AIENOS_CK_GATES: NOT_ALL_GATES_PASS (pass=10 fail=0 not_run=5 of 15; physical NOT_RUN)`), predates that merge: by it, 10 of 16 CK gates PASS (the 9 of the earlier receipt plus `DISK_LAYOUT`), 6 NOT_RUN (M0_ROLLBACK, M4_STORE_CRASH, M4_CONTINUITY, M4_RECOVERY, KEYBOARD; and SMP, not in that receipt, NOT_RUN pending forge receipt), 0 FAIL. No `ck_gates.sh` run exists at the merged head yet; `M4_STORE_CRASH` stays NOT_RUN until a forge receipt. `DISK_LAYOUT` also PASSed alone (log CK-4-184423.log, translation-bypass mutant killed); the Store, NET and artifact gates boot GPT images now and PASS in the same receipt. The receipt before it was 9 of 14 CK gates PASS, 5 NOT_RUN, 0 FAIL (`evidence/ck_gates_929f287e9c950c45c7dcd569c7caa03709ea62ecfe393635b435058afa969c54.json`, run at 41aa0e6, which adds the kernel entropy rows 107-109; that commit was then rebased onto #210, which changed only README.md and CONTRIBUTING.md). The row counts below are per Rust-parity row, not per gate. Rows 118-123 (DISK_LAYOUT, C-only, CK-4; numbered 113-118 on the CK-4 branch before the merge with main, which gave 113-117 to SMP) are 5 QEMU PASS (118-122, receipt `ck_gates_d80363...` at 741b2b8, before the merge with main 8555049) and 1 host-test PASS (123), none NOT_RUN. With them, rows 1-123 plus the M4 continuity/recovery sub-rows: IDENTICAL 28, DIFFERS 39, NOT_RUN 91, PASS 6 (C-only DISK_LAYOUT, hardware NOT_RUN) (91 from the SMP line next; recounted from the table at the merge commit, status = each row's first status cell, escaped pipes read as text: 28 IDENTICAL, 39 DIFFERS, 87 NOT_RUN (82 + SMP 113-117), 9 QEMU PASS (NET 102, 110-112, counted as NOT_RUN as below, and DISK_LAYOUT 118-122), 1 PASS (123); sub-rows 24a and 24b not counted). @@ -575,3 +575,31 @@ required in CI (the runner has neither the model nor the target). | 137 | per-token timing line present: 7 decode forwards, mean > 0 us. First native CPU number: 40.40 s per decode token, prefill 553.9 s for 17 tokens, whole Rust call 837.8 s, under QEMU TCG single core (not hardware; host test on one Grace core is 0.59 s per forward) | INFER | QEMU PASS (hardware NOT_RUN) | | 138 | clean unload: `infer: unloaded` line present before the final report, frame-return rc 0,0, free frames after = before the ingest (1021097 = 1021097; 262728 frames returned), kernel then reaches M3, stages, final report, PSCI reset (QEMU exit 0) | INFER | QEMU PASS (hardware NOT_RUN) | | 139 | live control: the same serial log re-checked against a mutated expected-id list (second-to-last id + 1) must FAIL on the token check, else the gate FAILs; `--self-test` also covers wrong/short/swapped tokens, missing tokens/text/timing/unload lines, missing "Paris", leaked frames, refused frame return, unload after the final report | INFER | QEMU PASS (control caught; hardware NOT_RUN) | + +## SCREEN: scripts/qemu_ck_screen_test.sh -> CK `SCREEN` (L6-C prerequisite, C-only, no Rust-kernel counterpart) + +The UEFI stub finds the Graphics Output Protocol (UEFI 2.10 section 12.9) before ExitBootServices and passes the +linear framebuffer (base, size, width, height, pitch in pixels, format RGBX or BGRX) in the CHANDOF3 handoff +(`docs/BOOT_HANDOFF_CONTRACT.md`, offsets 192-231). The kernel refuses older records (`unsupported version N`), +maps the framebuffer with `ck_mmio_map` (Device-nGnRE) unless it overlaps RAM, and mirrors every console byte on +screen in white on black with the public-domain 8x8 font (`core/font8x8.h`, cell 8x10 times a scale of +height/540 clamped to 1..4 and lowered until 80 columns fit). Scrolling mode is half-scroll: when the screen is +full, it is cleared and the newest half of the rows is redrawn from a text copy (no read-back of device memory). +Without a GOP the kernel still boots and says `screen: none` on the UART. + +The gate boots the default image under QEMU with `-device ramfb` (AAVMF gives an 800x600 BGRX GOP on it), lets the +PSCI reset pause the VM (`-action reboot=shutdown,shutdown=pause`) and takes a QMP `screendump`. The host tool +`ck_fb_check` (`make -C native/kernel fb-check`) renders the serial log from the `screen: gop` line onward with the +same `core/fbcon.c` code and compares every pixel with the dump, then decodes every cell back to text. The gate is +NOT_RUN (never a silent pass) when QEMU, AAVMF, socat or the cross compiler is missing. + +| # | check | gate | status | +|---|---|---|---| +| 140 | stub prints a `gop: ok` line; the kernel prints exactly one `screen: gop` line whose geometry equals the screendump (800x600 BGRX on ramfb), reaches `kernel: alive`, no panic or fault | SCREEN | QEMU PASS (receipt `evidence/ck_gates_ad05e004e30237e57e72fc1d3362cfe2b31af9b99451d9d2bb2414238e4d6590.json`, full `ck_gates.sh` at 2e44c0b, 17 PASS 0 FAIL 2 NOT_RUN of 19; hardware NOT_RUN) | +| 141 | screendump = the expected rendering of the serial log, pixel for pixel (`mismatched=0`), every cell decodes to a font glyph (`undecodable=0`) | SCREEN | QEMU PASS (same receipt; hardware NOT_RUN) | +| 142 | the decoded screen holds the final verdict rows `report_kind: final` and `note: QEMU qualifies nothing physical` | SCREEN | QEMU PASS (same receipt; hardware NOT_RUN) | +| 143 | negative boot: the TEST-ONLY stale image (`make CK_TEST_STALE_HANDOFF=2`, announces itself, refused with `CK_HARDWARE_STAGING`) passes a CHANDOF2 record; the kernel panics with `handoff: unsupported version 2 (kernel reads CHANDOF3 only)`, draws nothing, and the pixel check on its dump FAILs; the default image contains no stale text | SCREEN | QEMU PASS (control caught, same receipt; hardware NOT_RUN) | +| 144 | host tests: `test_handoff` framebuffer cases (Spark-like 1920x1080 BGRX, padded pitch, every refusal reason, version refusals) and `test_fbcon` (glyphs, scale, refusals, pixels, lazy newline, wrap, half-scroll, unprintable bytes) | SCREEN (host, `make test`) | PASS (host test, `CK_CORE_HOST: PASS`) | +| 145 | `--self-test`: 12 canned logs, each wrong or missing line rejected by its own FAIL | SCREEN | PASS (script self-test) | + +Evidence: red on main a93e27b (`AIENOS_CK_SCREEN: FAIL`, gate script and branch-built checker copied in), green at 2e44c0b standalone and in the full receipt above, green again at c2232ef (CodeQL widening fix in fbcon.c): `fb_check: PASS 800x600 format=bgrx scale=1 grid=100x60 scrolls=1 pixels=480000 mismatched=0 undecodable=0`. Logs: `~/workspace/evidence-out/L6C/` on the Spark (not committed). diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 51bfc231..40abe8d6 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -136,6 +136,22 @@ SMP_TEST_FLAGS := -DCK_TEST_SMP_SKIP_CPU=1 else SMP_TEST_FLAGS := endif +# TEST-ONLY stale handoff (AIENOS_CK_SCREEN negative control, +# scripts/qemu_ck_screen_test.sh): the stub hands the kernel a CHANDOF2 magic; +# the kernel must refuse it ("panic: handoff: unsupported version 2 ..."). +# Own OUT; announces itself; refused with CK_HARDWARE_STAGING. The default +# image is checked to carry no trace of it ($(ELF) rule). +CK_TEST_STALE_HANDOFF ?= +ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),) +ifneq ($(strip $(CK_TEST_STALE_HANDOFF)),2) +$(error CK_TEST_STALE_HANDOFF must be empty or 2) +endif +ifneq ($(strip $(CK_HARDWARE_STAGING)),) +$(error CK_TEST_STALE_HANDOFF (TEST-only stale handoff) cannot be combined with CK_HARDWARE_STAGING) +endif +OUT ?= $(REPO)/target/native-kernel-test-stale-handoff +SMP_TEST_FLAGS += -DCK_TEST_STALE_HANDOFF=2 +endif OUT ?= $(REPO)/target/native-kernel AIENOS_COMMIT ?= $(shell git -C $(REPO) rev-parse HEAD 2>/dev/null || echo unknown) @@ -348,19 +364,28 @@ ifeq ($(strip $(CK_TEST_FWCFG_ARTIFACTS)),1) ART_TRUST_FLAGS += -DCK_TEST_FWCFG_ARTIFACTS=1 endif +# Screen hold before reset (core/console.c ck_console_fb_hold): seconds the +# GOP framebuffer console keeps the last report on screen before the PSCI +# reset, so an operator can read or photograph it. 0 (default) in every QEMU +# gate; scripts/stage_one_time_boot_ck.sh builds the hardware image with 120. +CK_FB_HOLD_S ?= 0 +ifeq ($(shell echo '$(CK_FB_HOLD_S)' | grep -Ex '[0-9]{1,4}'),) +$(error CK_FB_HOLD_S must be 0..9999 seconds) +endif + KINC := -I$(KDIR)/include -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/arch -I$(BOOT) MODULE_INC := -I$(NATIVE)/disk -I$(NATIVE)/store -I$(NATIVE)/m5 -I$(NATIVE)/crypto \ -I$(NATIVE)/capability -I$(NATIVE)/argus -I$(NATIVE)/net KCFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -nostdlib -fno-builtin \ -fno-stack-protector -fno-tree-loop-distribute-patterns -mstrict-align \ -mgeneral-regs-only -mno-outline-atomics -fno-asynchronous-unwind-tables -fpie \ - -fvisibility=hidden -fno-plt $(KINC) $(SMP_TEST_FLAGS) $(CK_EXTRA_CFLAGS) + -fvisibility=hidden -fno-plt $(KINC) $(SMP_TEST_FLAGS) -DCK_FB_HOLD_S=$(CK_FB_HOLD_S) $(CK_EXTRA_CFLAGS) KLDFLAGS := -nostdlib -pie --no-dynamic-linker -z norelro -z noexecstack -z max-page-size=4096 --no-warn-rwx-segments \ -T $(BOOT)/image.ld -CORE_C := $(BOOT)/efi_main.c $(BOOT)/efi_model.c \ +CORE_C := $(BOOT)/efi_main.c $(BOOT)/efi_model.c $(BOOT)/efi_gop.c \ $(KDIR)/arch/exception.c $(KDIR)/arch/gic.c $(KDIR)/arch/timer.c \ - $(KDIR)/core/acpi.c $(KDIR)/core/console.c $(KDIR)/core/fmt.c \ + $(KDIR)/core/acpi.c $(KDIR)/core/console.c $(KDIR)/core/fbcon.c $(KDIR)/core/fmt.c \ $(KDIR)/core/kmain.c $(KDIR)/core/handoff_check.c $(KDIR)/core/libc_min.c $(KDIR)/core/report.c \ $(KDIR)/core/smmu.c $(KDIR)/core/smmu_svc.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c \ $(KDIR)/core/fpu.c $(KDIR)/core/infer.c $(KDIR)/core/m3.c $(KDIR)/core/entropy.c $(KDIR)/arch/rndr.c $(KDIR)/core/smp.c \ @@ -586,6 +611,8 @@ endef $(ELF): $(CORE_OBJS) $(BOOT)/image.ld $(call link_image,$@,$(CORE_OBJS) $(CK_RUST_LIBS) $(CK_INFER_LIB)) + @if [ -z "$(strip $(CK_TEST_STALE_HANDOFF))" ] && grep -aqF "TEST-ONLY stale handoff" $@; then \ + echo "default image carries the TEST-only stale handoff"; rm -f $@; exit 1; fi @s=$$($(KNM) $@ | grep -E ' [TtDdBbWwVv] ck_stage_(devices|security|store|quiesce)$$' || true); \ if [ -n "$$s" ]; then echo "core image defines stage symbols: $$s"; rm -f $@; exit 1; fi $(call fwcfg_check,$@) @@ -611,8 +638,8 @@ $(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 -TESTS := test_fmt test_frames test_pt test_acpi test_heap test_smmu test_sched test_ipc test_artifact test_entropy test_handoff \ + $(KDIR)/core/handoff_check.c $(KDIR)/core/fbcon.c +TESTS := test_fmt test_frames test_pt test_acpi test_heap test_smmu test_sched test_ipc test_artifact test_entropy test_handoff test_fbcon \ test_continuity_codec test_continuity_resolve test_continuity_commit test_continuity_recovery test_continuity_geometry 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 @@ -898,6 +925,13 @@ $(MODEL_MAP_TOOL): $(KDIR)/tools/ck_model_map.c $(NATIVE)/argus/sha256.c $(BOOT) $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -I$(BOOT) -I$(NATIVE)/argus -o $@ $(KDIR)/tools/ck_model_map.c $(NATIVE)/argus/sha256.c model-map: $(MODEL_MAP_TOOL) +# ---- host checker for the AIENOS_CK_SCREEN gate (scripts/qemu_ck_screen_test.sh) ---- +FB_CHECK_TOOL := $(OUT)/host/ck_fb_check +$(FB_CHECK_TOOL): $(KDIR)/tools/ck_fb_check.c $(KDIR)/core/fbcon.c $(KDIR)/core/fbcon.h $(KDIR)/core/font8x8.h + @mkdir -p $(dir $@) + $(HOSTCC) -std=gnu11 -O2 -Wall -Wextra -Werror -o $@ $(KDIR)/tools/ck_fb_check.c $(KDIR)/core/fbcon.c +fb-check: $(FB_CHECK_TOOL) + # Owner provisioning generator (hosted; never part of an image) and the # generated header for the hardware staging image. OWNER_GEN := $(OUT)/host/ck_owner_gen @@ -915,4 +949,4 @@ clean: rm -rf $(OUT) FORCE: -.PHONY: all full test sanitize handoff-mutant clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen continuity-mutants continuity-resolve-mutants FORCE +.PHONY: all full test sanitize handoff-mutant clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE diff --git a/native/kernel/core/.crumb b/native/kernel/core/.crumb index d1cb7f64..153a0395 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-04T15:01:15Z", + "compiled_at": "2026-10-04T17:01:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:76e09442c61ce7502463145cf8b9540f435ee8fba3cd06fa9f3f09a7e8d6f72d", + "digest": "sha256:dd6ebb445202c084d41a923774ff81d2c0c384393b7383c92ed09e77028d2307", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 25, - "generated_at_commit": "39e611ed040126791acdb667dbbc288a3757858a", - "source_tree": "sha256:0b49a00bde4e84503ce53a949491eb90e781b5a0f7604a4b59ea30495f4ff267" + "files": 28, + "generated_at_commit": "1e28ff5b9ba3193a14e6063175d81e39d545e11f", + "source_tree": "sha256:604b927e35574ac0641a25f1901ac114185120b7801fb3f036fbd59a1fa413fc" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/core/ck_internal.h b/native/kernel/core/ck_internal.h index eb5500d4..01a2f9e0 100644 --- a/native/kernel/core/ck_internal.h +++ b/native/kernel/core/ck_internal.h @@ -21,6 +21,14 @@ int ck_console_set_uart(const struct ck_spcr *spcr); /* Name of the active UART driver for the report, e.g. "pl011". */ const char *ck_console_uart_name(void); uint64_t ck_console_uart_base(void); +/* GOP framebuffer console (core/fbcon.c): set up and clear the screen, then + * mirror every console byte on it. -1 if the geometry is unusable. */ +int ck_console_set_fb(volatile void *base, uint32_t width, uint32_t height, uint32_t pitch, + uint32_t format); +/* 0 and the grid while the screen console is on, else -1. */ +int ck_console_fb_info(uint32_t *scale, uint32_t *cols, uint32_t *rows); +/* Called by ck_reset: hold the screen CK_FB_HOLD_S seconds (build knob). */ +void ck_console_fb_hold(void); /* ---- report (core/report.c) ---- */ void ck_set_stage(const char *name); @@ -38,6 +46,9 @@ __attribute__((noreturn)) void ck_fault_report(const char *what, uint64_t esr, u uint64_t elr, unsigned el); /* ---- memory (mm/mmu.c) ---- */ +#define CK_MM_FB_NONE 0u +#define CK_MM_FB_MAPPED 1u +#define CK_MM_FB_OVERLAPS_RAM 2u struct ck_mm_report { uint64_t root; uint64_t pt_tables; @@ -45,6 +56,10 @@ struct ck_mm_report { uint64_t heap_lo, heap_hi, heap_guard_lo, heap_guard_hi; uint64_t dma_lo, dma_hi; uint64_t ram_ranges, free_bytes; + /* CHANDOF3 framebuffer: CK_MM_FB_NONE / _MAPPED (Device-nGnRE, ck_mmio_map) + * / _OVERLAPS_RAM (refused: inside a RAM range mapped write-back). */ + uint32_t fb_map; + uint64_t fb_map_bytes; }; /* EL2/firmware phase: frames from the map, our tables, stack, heap, DMA pool. * Returns the stack top for the EL1 entry. */ diff --git a/native/kernel/core/console.c b/native/kernel/core/console.c index 8f7406ea..27b0f7d2 100644 --- a/native/kernel/core/console.c +++ b/native/kernel/core/console.c @@ -1,14 +1,25 @@ /* console.c -- ck_puts/ck_printf. Before ExitBootServices the boot stub * attaches UEFI ConOut; afterwards output goes to the UART the ACPI SPCR * names (PL011/SBSA, or 16550 in MMIO). With neither, output is dropped and - * the panic path still resets. '\n' is sent as CR LF. */ + * the panic path still resets. '\n' is sent as CR LF. + * After ExitBootServices every byte the UART gets is also drawn on the GOP + * framebuffer once the kernel turned it on (ck_console_set_fb, core/fbcon.c); + * a fault while drawing turns the screen off for good, the UART goes on. */ #include "ck_internal.h" +#include "fbcon.h" +#include "arch.h" + +#ifndef CK_FB_HOLD_S +#define CK_FB_HOLD_S 0 +#endif static void (*efi_write)(const char *s, size_t n); static volatile uint8_t *uart; static int uart_kind; /* 0 none, 1 pl011, 2 16550 */ static unsigned uart_stride; static uint64_t uart_phys; +static struct ck_fbcon fb; +static int fb_on, fb_busy; void ck_console_set_efi(void (*write)(const char *s, size_t n)) { @@ -73,6 +84,15 @@ static void write_n(const char *s, size_t n) efi_write(s, n); return; } + if (fb_on) { + if (fb_busy) { + fb_on = 0; /* re-entered from a fault inside the drawing: screen off */ + } else { + fb_busy = 1; + ck_fbcon_write(&fb, s, n); + fb_busy = 0; + } + } if (!uart_kind) return; for (size_t i = 0; i < n; i++) { @@ -82,6 +102,41 @@ static void write_n(const char *s, size_t n) } } +int ck_console_set_fb(volatile void *base, uint32_t width, uint32_t height, uint32_t pitch, + uint32_t format) +{ + if (ck_fbcon_setup(&fb, base, width, height, pitch, format) != 0) + return -1; + fb_on = 1; + return 0; +} + +int ck_console_fb_info(uint32_t *scale, uint32_t *cols, uint32_t *rows) +{ + if (!fb_on) + return -1; + *scale = fb.scale; + *cols = fb.cols; + *rows = fb.rows; + return 0; +} + +/* Before a reset: keep the screen readable for CK_FB_HOLD_S seconds (0 in + * every QEMU build; the hardware staging build sets it so an operator can + * read or photograph the final report before the machine resets). */ +void ck_console_fb_hold(void) +{ + if (!fb_on || CK_FB_HOLD_S <= 0) + return; + uint64_t f = ck_rd(cntfrq_el0); + if (!f) + return; + ck_printf("screen: holding %u s before reset\n", (unsigned)CK_FB_HOLD_S); + uint64_t t0 = ck_rd(cntpct_el0); + while (ck_rd(cntpct_el0) - t0 < (uint64_t)CK_FB_HOLD_S * f) + __asm__ volatile("yield"); +} + void ck_puts(const char *s) { write_n(s, strlen(s)); diff --git a/native/kernel/core/fbcon.c b/native/kernel/core/fbcon.c new file mode 100644 index 00000000..4e95f08c --- /dev/null +++ b/native/kernel/core/fbcon.c @@ -0,0 +1,138 @@ +/* fbcon.c -- text console on a linear 32-bit framebuffer; see fbcon.h. */ +#include "fbcon.h" +#include "font8x8.h" + +uint32_t ck_fbcon_scale_for(uint32_t width, uint32_t height) +{ + uint32_t s = height / 540; + if (s < 1) + s = 1; + if (s > 4) + s = 4; + while (s > 1 && width / (CK_FBCON_CELL_W * s) < 80) + s--; + return s; +} + +int ck_fbcon_setup(struct ck_fbcon *c, volatile uint32_t *px, uint32_t width, uint32_t height, + uint32_t pitch, uint32_t format) +{ + if (!px || format > 1 || pitch < width) + return -1; + uint32_t s = ck_fbcon_scale_for(width, height); + uint32_t cols = width / (CK_FBCON_CELL_W * s), rows = height / (CK_FBCON_CELL_H * s); + if (!cols || !rows) + return -1; + if (cols > CK_FBCON_MAX_COLS) + cols = CK_FBCON_MAX_COLS; + if (rows > CK_FBCON_MAX_ROWS) + rows = CK_FBCON_MAX_ROWS; + c->px = px; + c->width = width; + c->height = height; + c->pitch = pitch; + c->format = format; + c->scale = s; + c->cols = cols; + c->rows = rows; + c->col = 0; + c->row = 0; + c->pending_nl = 0; + c->scrolls = 0; + for (uint32_t r = 0; r < CK_FBCON_MAX_ROWS; r++) + for (uint32_t k = 0; k < CK_FBCON_MAX_COLS; k++) + c->text[r][k] = 0; + ck_fbcon_clear(c); + return 0; +} + +void ck_fbcon_clear(struct ck_fbcon *c) +{ + for (uint32_t y = 0; y < c->height; y++) { + volatile uint32_t *p = c->px + (uint64_t)y * c->pitch; + for (uint32_t x = 0; x < c->width; x++) + p[x] = CK_FBCON_BG; + } +} + +/* One 8x8 glyph (times scale) into cell (col, row); the two gap rows of the + * cell are left as the clear made them. */ +static void glyph(struct ck_fbcon *c, uint32_t col, uint32_t row, unsigned char ch) +{ + const uint8_t *g = ck_font8x8[ch - CK_FONT_FIRST]; + uint32_t s = c->scale; + uint64_t x0 = (uint64_t)col * CK_FBCON_CELL_W * s; + uint64_t y0 = (uint64_t)row * CK_FBCON_CELL_H * s; + for (uint32_t gy = 0; gy < CK_FONT_H; gy++) { + for (uint32_t sy = 0; sy < s; sy++) { + volatile uint32_t *p = c->px + (y0 + (uint64_t)gy * s + sy) * c->pitch + x0; + for (uint32_t gx = 0; gx < CK_FONT_W; gx++) { + uint32_t v = (g[gy] >> gx) & 1 ? CK_FBCON_FG : CK_FBCON_BG; + for (uint32_t sx = 0; sx < s; sx++) + *p++ = v; + } + } + } +} + +static void draw(struct ck_fbcon *c, unsigned char ch) +{ + if (ch < CK_FONT_FIRST || ch > CK_FONT_LAST) + ch = '?'; + c->text[c->row][c->col] = (char)ch; + glyph(c, c->col, c->row, ch); +} + +/* Next row. Bottom row full: clear, move the newest half of the text rows + * to the top and redraw them; writing goes on below them. */ +static void advance(struct ck_fbcon *c) +{ + c->col = 0; + if (++c->row < c->rows) + return; + uint32_t keep = c->rows / 2; + ck_fbcon_clear(c); + for (uint32_t r = 0; r < c->rows; r++) + for (uint32_t k = 0; k < c->cols; k++) + c->text[r][k] = r < keep ? c->text[c->rows - keep + r][k] : 0; + for (uint32_t r = 0; r < keep; r++) + for (uint32_t k = 0; k < c->cols; k++) + if (c->text[r][k]) + glyph(c, k, r, (unsigned char)c->text[r][k]); + c->row = keep; + c->scrolls++; +} + +void ck_fbcon_write(struct ck_fbcon *c, const char *s, size_t n) +{ + for (size_t i = 0; i < n; i++) { + unsigned char ch = (unsigned char)s[i]; + if (ch == '\n') { + if (c->pending_nl) + advance(c); + c->pending_nl = 1; + continue; + } + if (ch == '\r') { + if (!c->pending_nl) + c->col = 0; + continue; + } + if (c->pending_nl) { + advance(c); + c->pending_nl = 0; + } + if (ch == '\t') { + uint32_t next = (c->col / 8 + 1) * 8; + while (c->col < next && c->col < c->cols) { + draw(c, ' '); + c->col++; + } + continue; + } + if (c->col >= c->cols) + advance(c); + draw(c, ch); + c->col++; + } +} diff --git a/native/kernel/core/fbcon.h b/native/kernel/core/fbcon.h new file mode 100644 index 00000000..73e5c75e --- /dev/null +++ b/native/kernel/core/fbcon.h @@ -0,0 +1,55 @@ +/* fbcon.h -- text console on a linear 32-bit framebuffer (the UEFI GOP + * framebuffer the boot stub hands over in the CHANDOF3 record). + * + * Pure layout and drawing: no globals, no I/O besides the pixel stores, so + * the kernel (core/console.c, framebuffer mapped Device-nGnRE) and the host + * checker (tools/ck_fb_check.c, a malloc'd buffer) run the same code and + * the checker can render the exact screen a serial log must produce. + * + * Layout: 8x8 glyphs (core/font8x8.h) in cells of 8 x 10 pixels times an + * integer scale; white on black. Scrolling is "half-scroll": when the + * bottom row is full, the screen is cleared and the newest half of the rows + * is redrawn at the top from a text copy kept here (no read-back of device + * memory), so the screen always shows at least half a screen of the latest + * lines, in order, and each line is drawn about twice. A newline is applied + * lazily, when the next character arrives, so the last line of a + * run stays on screen. Long lines wrap. Bytes outside 0x20..0x7e (except + * '\n', '\r', '\t') are drawn as '?'. */ +#ifndef AIENOS_CK_FBCON_H +#define AIENOS_CK_FBCON_H +#include +#include + +#define CK_FBCON_CELL_W 8 /* times scale */ +#define CK_FBCON_CELL_H 10 /* 8 glyph rows + 2 blank rows, times scale */ +#define CK_FBCON_FG 0x00ffffffu /* white in both RGBX and BGRX */ +#define CK_FBCON_BG 0x00000000u +#define CK_FBCON_MAX_COLS 256 /* text copy; wider screens leave the right edge black */ +#define CK_FBCON_MAX_ROWS 256 + +struct ck_fbcon { + volatile uint32_t *px; /* pixel (0,0) */ + uint32_t width, height; /* visible pixels */ + uint32_t pitch; /* pixels per scan line */ + uint32_t format; /* 0 RGBX, 1 BGRX (EFI_GRAPHICS_PIXEL_FORMAT) */ + uint32_t scale, cols, rows; + uint32_t col, row; + int pending_nl; /* a '\n' not yet applied */ + uint64_t scrolls; /* half-scrolls so far */ + char text[CK_FBCON_MAX_ROWS][CK_FBCON_MAX_COLS]; /* what each cell shows, 0 = never written */ +}; + +/* Scale for a screen: height / 540 clamped to 1..4, lowered until at least + * 80 columns fit (1920x1080 -> 2, 3840x2160 -> 4, 800x600 -> 1). */ +uint32_t ck_fbcon_scale_for(uint32_t width, uint32_t height); + +/* Sets up c for the framebuffer and clears the visible area. Returns -1 + * (and touches no pixel) when the geometry cannot hold one cell or the + * format is not 0/1. */ +int ck_fbcon_setup(struct ck_fbcon *c, volatile uint32_t *px, uint32_t width, uint32_t height, + uint32_t pitch, uint32_t format); + +void ck_fbcon_clear(struct ck_fbcon *c); +void ck_fbcon_write(struct ck_fbcon *c, const char *s, size_t n); + +#endif diff --git a/native/kernel/core/font8x8.h b/native/kernel/core/font8x8.h new file mode 100644 index 00000000..e3a618d6 --- /dev/null +++ b/native/kernel/core/font8x8.h @@ -0,0 +1,119 @@ +/* font8x8.h -- 8x8 bitmap glyphs for printable ASCII (0x20..0x7e), used by + * the framebuffer console (core/fbcon.c) and its host checker + * (tools/ck_fb_check.c). + * + * Source: font8x8_basic.h from https://github.com/dhepper/font8x8 (fetched + * 2026-10-04), Daniel Hepper, "License: Public Domain", based on Marcel + * Sondaar's font8x8.h and the IBM public domain VGA fonts. Rows only were + * copied, unchanged; the control characters and DEL are dropped. + * + * Encoding: 8 bytes per glyph, one per row, top row first; bit 0 (LSB) is the + * leftmost pixel of the row. */ +#ifndef AIENOS_CK_FONT8X8_H +#define AIENOS_CK_FONT8X8_H +#include + +#define CK_FONT_FIRST 0x20 +#define CK_FONT_LAST 0x7e +#define CK_FONT_W 8 +#define CK_FONT_H 8 + +static const uint8_t ck_font8x8[CK_FONT_LAST - CK_FONT_FIRST + 1][CK_FONT_H] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0020 (space) */ + {0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, /* U+0021 (!) */ + {0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0022 (") */ + {0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, /* U+0023 (#) */ + {0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00}, /* U+0024 ($) */ + {0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00}, /* U+0025 (%) */ + {0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00}, /* U+0026 (&) */ + {0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0027 (') */ + {0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00}, /* U+0028 (() */ + {0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00}, /* U+0029 ()) */ + {0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00}, /* U+002A (*) */ + {0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00}, /* U+002B (+) */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06}, /* U+002C (,) */ + {0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00}, /* U+002D (-) */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00}, /* U+002E (.) */ + {0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00}, /* U+002F (/) */ + {0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00}, /* U+0030 (0) */ + {0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00}, /* U+0031 (1) */ + {0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00}, /* U+0032 (2) */ + {0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00}, /* U+0033 (3) */ + {0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00}, /* U+0034 (4) */ + {0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00}, /* U+0035 (5) */ + {0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00}, /* U+0036 (6) */ + {0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00}, /* U+0037 (7) */ + {0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00}, /* U+0038 (8) */ + {0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00}, /* U+0039 (9) */ + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00}, /* U+003A (:) */ + {0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06}, /* U+003B (;) */ + {0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00}, /* U+003C (<) */ + {0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00}, /* U+003D (=) */ + {0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00}, /* U+003E (>) */ + {0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00}, /* U+003F (?) */ + {0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00}, /* U+0040 (@) */ + {0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00}, /* U+0041 (A) */ + {0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00}, /* U+0042 (B) */ + {0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00}, /* U+0043 (C) */ + {0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00}, /* U+0044 (D) */ + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00}, /* U+0045 (E) */ + {0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00}, /* U+0046 (F) */ + {0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00}, /* U+0047 (G) */ + {0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00}, /* U+0048 (H) */ + {0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, /* U+0049 (I) */ + {0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00}, /* U+004A (J) */ + {0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00}, /* U+004B (K) */ + {0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00}, /* U+004C (L) */ + {0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00}, /* U+004D (M) */ + {0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00}, /* U+004E (N) */ + {0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00}, /* U+004F (O) */ + {0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00}, /* U+0050 (P) */ + {0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00}, /* U+0051 (Q) */ + {0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00}, /* U+0052 (R) */ + {0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00}, /* U+0053 (S) */ + {0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, /* U+0054 (T) */ + {0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00}, /* U+0055 (U) */ + {0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, /* U+0056 (V) */ + {0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00}, /* U+0057 (W) */ + {0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00}, /* U+0058 (X) */ + {0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00}, /* U+0059 (Y) */ + {0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00}, /* U+005A (Z) */ + {0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00}, /* U+005B ([) */ + {0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00}, /* U+005C (\) */ + {0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00}, /* U+005D (]) */ + {0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00}, /* U+005E (^) */ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, /* U+005F (_) */ + {0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+0060 (`) */ + {0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00}, /* U+0061 (a) */ + {0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00}, /* U+0062 (b) */ + {0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00}, /* U+0063 (c) */ + {0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00}, /* U+0064 (d) */ + {0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00}, /* U+0065 (e) */ + {0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00}, /* U+0066 (f) */ + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F}, /* U+0067 (g) */ + {0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00}, /* U+0068 (h) */ + {0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, /* U+0069 (i) */ + {0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E}, /* U+006A (j) */ + {0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00}, /* U+006B (k) */ + {0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00}, /* U+006C (l) */ + {0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00}, /* U+006D (m) */ + {0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00}, /* U+006E (n) */ + {0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00}, /* U+006F (o) */ + {0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F}, /* U+0070 (p) */ + {0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78}, /* U+0071 (q) */ + {0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00}, /* U+0072 (r) */ + {0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00}, /* U+0073 (s) */ + {0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00}, /* U+0074 (t) */ + {0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00}, /* U+0075 (u) */ + {0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00}, /* U+0076 (v) */ + {0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00}, /* U+0077 (w) */ + {0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00}, /* U+0078 (x) */ + {0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F}, /* U+0079 (y) */ + {0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00}, /* U+007A (z) */ + {0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00}, /* U+007B ({) */ + {0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00}, /* U+007C (|) */ + {0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00}, /* U+007D (}) */ + {0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* U+007E (~) */ +}; + +#endif diff --git a/native/kernel/core/handoff_check.c b/native/kernel/core/handoff_check.c index 9bcdde3b..52f51c4e 100644 --- a/native/kernel/core/handoff_check.c +++ b/native/kernel/core/handoff_check.c @@ -1,7 +1,9 @@ /* handoff_check.c -- refuse a malformed loader -> kernel handoff record * before the kernel trusts any field of it (docs/BOOT_HANDOFF_CONTRACT.md - * section 6). Checked here: NULL record, magic (CHANDOF2 only; CHANDOF1 is - * "bad magic"), reserved0, reserved1, the CHANDOF2 model fields, descriptor + * section 6). Checked here: NULL record, magic (CHANDOF3 only; CHANDOF1 and + * CHANDOF2 are "unsupported version ", anything else "bad magic"), + * reserved0, reserved1, the CHANDOF2 model fields, the CHANDOF3 framebuffer + * fields, descriptor * stride and version, memory map size. The other PROPOSED refusals of the * contract (image range, overlaps, rsdp, firmware_el, CHANDOF version * line) are not part of this cut. */ @@ -19,7 +21,7 @@ #endif #endif -static char why_buf[64]; +static char why_buf[80]; static int refuse(const char **why, const char *what, unsigned long long n) { @@ -28,6 +30,50 @@ static int refuse(const char **why, const char *what, unsigned long long n) return -1; } +/* CHANDOF3 framebuffer block (docs/BOOT_HANDOFF_CONTRACT.md section 3). */ +static int fb_check(const struct ck_handoff *h, const char **why) +{ + switch (h->fb_status) { + case CK_HANDOFF_FB_NONE: + if (h->fb_base || h->fb_size || h->fb_width || h->fb_height || h->fb_pitch || h->fb_format || + h->fb_gop_handles) { + *why = "fb fields without gop"; + return -1; + } + return 0; + case CK_HANDOFF_FB_NO_LINEAR: + if (h->fb_base || h->fb_size) + return refuse(why, "fb range without linear framebuffer", (unsigned long long)h->fb_size); + if (!h->fb_gop_handles) + return refuse(why, "bad fb gop handles", 0); + return 0; + case CK_HANDOFF_FB_PRESENT: + break; + default: + return refuse(why, "bad fb status", (unsigned long long)h->fb_status); + } + if (h->fb_format != CK_HANDOFF_FB_RGBX && h->fb_format != CK_HANDOFF_FB_BGRX) + return refuse(why, "bad fb format", (unsigned long long)h->fb_format); + if (!h->fb_width || h->fb_width > CK_HANDOFF_FB_MAX_DIM) + return refuse(why, "bad fb width", (unsigned long long)h->fb_width); + if (!h->fb_height || h->fb_height > CK_HANDOFF_FB_MAX_DIM) + return refuse(why, "bad fb height", (unsigned long long)h->fb_height); + if (h->fb_pitch < h->fb_width || h->fb_pitch > CK_HANDOFF_FB_MAX_DIM) + return refuse(why, "bad fb pitch", (unsigned long long)h->fb_pitch); + if (!h->fb_base || h->fb_base % 4) + return refuse(why, "bad fb base", (unsigned long long)h->fb_base); + /* UEFI 2.10 12.9.2: FrameBufferSize = PixelsPerScanLine x VerticalResolution + * x PixelElementSize (4 bytes for both accepted formats). At most 1 GiB. */ + uint64_t need = (uint64_t)h->fb_pitch * h->fb_height * 4u; + if (h->fb_size < need) + return refuse(why, "fb size too small", (unsigned long long)h->fb_size); + if (h->fb_base + h->fb_size < h->fb_base) + return refuse(why, "fb range overflow", (unsigned long long)h->fb_size); + if (!h->fb_gop_handles) + return refuse(why, "bad fb gop handles", 0); + return 0; +} + int ck_handoff_check(const struct ck_handoff *h, const char **why) { if (!h) { @@ -35,6 +81,13 @@ int ck_handoff_check(const struct ck_handoff *h, const char **why) return -1; } if (h->magic != CK_HANDOFF_MAGIC) { + unsigned d = (unsigned)(h->magic >> 56); + if ((h->magic & 0x00ffffffffffffffull) == CK_HANDOFF_MAGIC_STEM && d >= '0' && d <= '9') { + ck_snprintf(why_buf, sizeof why_buf, "unsupported version %u (kernel reads CHANDOF3 only)", + d - '0'); + *why = why_buf; + return -1; + } *why = "bad magic"; return -1; } @@ -72,6 +125,8 @@ int ck_handoff_check(const struct ck_handoff *h, const char **why) return -1; } } + if (fb_check(h, why) != 0) + return -1; if (h->desc_size < CK_HANDOFF_DESC_MIN || h->desc_size % 8 != 0) return refuse(why, "bad descriptor size", (unsigned long long)h->desc_size); if (h->desc_version != CK_HANDOFF_DESC_VERSION) diff --git a/native/kernel/core/handoff_check.h b/native/kernel/core/handoff_check.h index 4c6ddccd..34f1e9ce 100644 --- a/native/kernel/core/handoff_check.h +++ b/native/kernel/core/handoff_check.h @@ -1,5 +1,5 @@ /* handoff_check.h -- pure validator of the loader -> kernel handoff record - * (docs/BOOT_HANDOFF_CONTRACT.md section 6, CHANDOF1 v1). No I/O, no + * (docs/BOOT_HANDOFF_CONTRACT.md section 6, CHANDOF3). No I/O, no * globals the caller can see; host tested by tests/test_handoff.c. */ #ifndef AIENOS_CK_HANDOFF_CHECK_H #define AIENOS_CK_HANDOFF_CHECK_H @@ -14,7 +14,7 @@ /* UEFI EFI_MEMORY_DESCRIPTOR_VERSION. */ #define CK_HANDOFF_DESC_VERSION 1u -/* Returns 0 when h is an acceptable CHANDOF1 record. Otherwise returns -1 +/* Returns 0 when h is an acceptable CHANDOF3 record. Otherwise returns -1 * and sets *why to the refusal reason without the "handoff: " prefix * (for example "bad magic"); the kernel panics with "handoff: ". * *why may point at a static buffer overwritten by the next call. */ diff --git a/native/kernel/core/kmain.c b/native/kernel/core/kmain.c index 14e31978..e6c4df95 100644 --- a/native/kernel/core/kmain.c +++ b/native/kernel/core/kmain.c @@ -38,12 +38,48 @@ static void run_stage(const char *name, int (*fn)(void)) ck_printf("stage %s: FAIL rc=%d\n", name, rc); } +/* CHANDOF3: put the console on the GOP framebuffer (mapped by ck_mm_build) + * or say on the UART why there is no screen. The first line drawn on the + * screen is the "screen: gop" line (scripts/qemu_ck_screen_test.sh renders + * the serial log from that line on and compares it with a QEMU screendump). */ +static void screen_start(const struct ck_handoff *h, const struct ck_mm_report *mm) +{ + if (h->fb_status == CK_HANDOFF_FB_NONE) { + ck_puts("screen: none (no UEFI Graphics Output Protocol); report on UART only\n"); + return; + } + if (h->fb_status == CK_HANDOFF_FB_NO_LINEAR) { + ck_printf("screen: none (GOP handles=%u, none with a linear 32-bit framebuffer); report on UART only\n", + h->fb_gop_handles); + return; + } + if (mm->fb_map != CK_MM_FB_MAPPED) { + ck_printf("screen: refused (framebuffer 0x%llx+0x%llx overlaps RAM mapped write-back); report on UART " + "only\n", + (unsigned long long)h->fb_base, (unsigned long long)mm->fb_map_bytes); + return; + } + if (ck_console_set_fb((volatile void *)(uintptr_t)h->fb_base, h->fb_width, h->fb_height, h->fb_pitch, + h->fb_format) != 0) { + ck_printf("screen: refused (geometry %ux%u pitch=%u format=%u unusable); report on UART only\n", + h->fb_width, h->fb_height, h->fb_pitch, h->fb_format); + return; + } + uint32_t scale = 0, cols = 0, rows = 0; + ck_console_fb_info(&scale, &cols, &rows); + ck_printf("screen: gop %ux%u pitch=%u format=%s base=0x%llx bytes=0x%llx scale=%u grid=%ux%u font=8x8 " + "mode=half-scroll\n", + h->fb_width, h->fb_height, h->fb_pitch, h->fb_format == CK_HANDOFF_FB_RGBX ? "rgbx" : "bgrx", + (unsigned long long)h->fb_base, (unsigned long long)mm->fb_map_bytes, scale, cols, rows); +} + static __attribute__((noreturn)) void ck_el1_main(void *arg) { struct ck_handoff *h = arg; ck_set_stage("kernel_el1"); ck_mm_el1_ready(); const struct ck_mm_report *mm = ck_mm_report(); + screen_start(h, mm); ck_puts("\n"); ck_report_header("kernel"); diff --git a/native/kernel/core/report.c b/native/kernel/core/report.c index 2a8aee01..d38371b5 100644 --- a/native/kernel/core/report.c +++ b/native/kernel/core/report.c @@ -66,6 +66,7 @@ void ck_reset(void) quiescing = 1; /* a panic inside the hook resets without it */ ck_stage_quiesce(); } + ck_console_fb_hold(); ck_mb(); psci_call(0x84000009u); /* PSCI SYSTEM_RESET */ psci_call(0x84000008u); /* SYSTEM_OFF if reset was refused */ diff --git a/native/kernel/mm/.crumb b/native/kernel/mm/.crumb index da1c926f..52d19725 100644 --- a/native/kernel/mm/.crumb +++ b/native/kernel/mm/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T15:01:15Z", + "compiled_at": "2026-10-04T16:43:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:ca0e875c3967ed75fa04e83792468a1ca61755b47c7de27b8e8981e687a341f8", + "digest": "sha256:272bc1dd7957e2024660c4f2850462671069bec77f4eee8d2c71b5b8788ab97e", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 7, - "generated_at_commit": "39e611ed040126791acdb667dbbc288a3757858a", - "source_tree": "sha256:1258ccfff89117d426b5d97260118e23c096f5454c319658f15f753df1970f0c" + "generated_at_commit": "a93e27b8a26d45330e58e1b8df1b35faf7146886", + "source_tree": "sha256:5b0b5bcd5a7997bd091f9c7e9683022723ea3fd5113d77ec265b36405612f3c3" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/mm/mmu.c b/native/kernel/mm/mmu.c index 805e47f1..9026c817 100644 --- a/native/kernel/mm/mmu.c +++ b/native/kernel/mm/mmu.c @@ -7,6 +7,8 @@ * heap (64 MiB) RW, unmapped guard page on each side * DMA pool (8 MiB) Normal Non-cacheable (ck_dma_alloc) * MMIO Device-nGnRE, XN (ck_mmio_map) + * GOP framebuffer (CHANDOF3) Device-nGnRE, XN (ck_mmio_map), visible + * pitch x height x 4 bytes, only outside RAM * ACPI tables outside WB RAM Normal RO, XN * * Frames for tables, stack, heap and the pool come from the allocator, which @@ -205,6 +207,27 @@ uint64_t ck_mm_build(const struct ck_handoff *h) if (ub) ck_mmio_map(ub, CK_PAGE); + /* GOP framebuffer (CHANDOF3, validated by handoff_check.c): Device-nGnRE + * like any MMIO, the bytes the console touches (pitch x height x 4). + * UEFI 2.10 12.9 says nothing about the memory attributes of the frame + * buffer after ExitBootServices (DOCS SILENT); on QEMU ramfb and, per + * Linux /proc/iomem, on the Spark it lies in a firmware-reserved range + * this kernel does not map as RAM. If it overlaps a RAM range mapped + * write-back the kernel refuses it (no second, mismatched mapping) and + * reports on the UART only. */ + if (h->fb_status == CK_HANDOFF_FB_PRESENT) { + uint64_t fb_len = (uint64_t)h->fb_pitch * h->fb_height * 4u; + uint64_t lo = h->fb_base & ~(CK_PAGE - 1); + uint64_t hi = (h->fb_base + fb_len + CK_PAGE - 1) & ~(CK_PAGE - 1); + rep.fb_map_bytes = fb_len; + if (overlaps_ram(lo, hi)) { + rep.fb_map = CK_MM_FB_OVERLAPS_RAM; + } else { + ck_mmio_map(h->fb_base, fb_len); + rep.fb_map = CK_MM_FB_MAPPED; + } + } + /* Tables were written through the firmware's cacheable mapping and our * walks are cacheable too; make them visible before the switch. */ __asm__ volatile("dsb ish" ::: "memory"); diff --git a/native/kernel/tests/.crumb b/native/kernel/tests/.crumb index 25d121fc..538aa9f7 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-04T15:01:15Z", + "compiled_at": "2026-10-04T16:43:31Z", "compiler": "crumb-compile/1", - "digest": "sha256:306b7082c04bacc3a3315c88685b5dd729b25eb31985db569d05541ee0a5204a", + "digest": "sha256:451e82cfde801fae5f0062cba5a86d572636bed23d5ce4cdd3529c1ce28ba417", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 21, - "generated_at_commit": "39e611ed040126791acdb667dbbc288a3757858a", - "source_tree": "sha256:3ac6b3c3391f6ebe6bfb0549ae6dec2e6bfd810f0ed3b3d5819f9c80af98af29" + "files": 22, + "generated_at_commit": "a93e27b8a26d45330e58e1b8df1b35faf7146886", + "source_tree": "sha256:2de681613401aebe0d840c4e2596b92be15f9b5de9bcf47b1988acfe3a2f02f1" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tests/test_fbcon.c b/native/kernel/tests/test_fbcon.c new file mode 100644 index 00000000..1bde8ccf --- /dev/null +++ b/native/kernel/tests/test_fbcon.c @@ -0,0 +1,96 @@ +/* test_fbcon.c -- host tests of core/fbcon.c (the GOP framebuffer console) + * and core/font8x8.h: every printable glyph is distinct (the screen gate's + * checker decodes cells by exact match), the scale rule, lazy newline, line + * wrap, half-scroll, and the exact pixels of one glyph. */ +#include +#include "ck_test.h" +#include "fbcon.h" +#include "font8x8.h" + +static uint32_t px[800 * 600]; +static struct ck_fbcon con; + +/* Text of row r as the text copy holds it (0 cells end it). */ +static const char *row_text(uint32_t r) +{ + static char b[CK_FBCON_MAX_COLS + 1]; + uint32_t n = 0; + while (n < con.cols && con.text[r][n]) + b[n] = con.text[r][n], n++; + b[n] = 0; + return b; +} + +static void put(const char *s) { ck_fbcon_write(&con, s, strlen(s)); } + +int main(void) +{ + /* glyphs 0x20..0x7e pairwise distinct; only the space is blank */ + int distinct = 1, blank = 0; + for (int a = 0; a <= CK_FONT_LAST - CK_FONT_FIRST; a++) { + uint8_t z[8] = {0}; + blank += !memcmp(ck_font8x8[a], z, 8); + for (int b = a + 1; b <= CK_FONT_LAST - CK_FONT_FIRST; b++) + if (!memcmp(ck_font8x8[a], ck_font8x8[b], 8)) + distinct = 0; + } + CHECK(distinct); + CHECK(blank == 1); + + /* scale: 1080p -> 2, 4K -> 4, 800x600 -> 1, 1280x1024 -> 1 (80 columns) */ + CHECK(ck_fbcon_scale_for(1920, 1080) == 2); + CHECK(ck_fbcon_scale_for(3840, 2160) == 4); + CHECK(ck_fbcon_scale_for(800, 600) == 1); + CHECK(ck_fbcon_scale_for(1280, 1024) == 1); + CHECK(ck_fbcon_scale_for(640, 480) == 1); + + /* refusals: format 2, pitch < width, too small for one cell */ + CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 2) == -1); + CHECK(ck_fbcon_setup(&con, px, 800, 600, 799, 1) == -1); + CHECK(ck_fbcon_setup(&con, px, 7, 600, 800, 1) == -1); + + memset(px, 0x55, sizeof px); + CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 1) == 0); + CHECK(con.scale == 1 && con.cols == 100 && con.rows == 60); + CHECK(px[0] == CK_FBCON_BG && px[800 * 600 - 1] == CK_FBCON_BG); /* cleared */ + + /* 'A' at cell (0,0): row 0 of the glyph is 0x0C -> pixels 2 and 3 lit */ + put("A"); + CHECK(px[0] == CK_FBCON_BG && px[1] == CK_FBCON_BG && px[2] == CK_FBCON_FG && px[3] == CK_FBCON_FG && + px[4] == CK_FBCON_BG); + CHECK(px[8 * 800 + 2] == CK_FBCON_BG); /* gap row 8 stays black */ + + /* lazy newline: the trailing '\n' does not move to the next row yet */ + put("BC\n"); + CHECK(con.row == 0 && con.pending_nl == 1); + CHECK(!strcmp(row_text(0), "ABC")); + put("\r\nD"); /* "\r\n" from the UART stream behaves like one more '\n' */ + CHECK(con.row == 2 && !strcmp(row_text(2), "D")); + + /* wrap at 100 columns */ + put("\n"); + for (int i = 0; i < 105; i++) + put("x"); + CHECK(con.row == 4 && con.col == 5); + + /* half-scroll: fill to the bottom; the newest 30 rows move to the top */ + CHECK(ck_fbcon_setup(&con, px, 800, 600, 800, 0) == 0); + char line[16]; + for (int i = 0; i < 61; i++) { + snprintf(line, sizeof line, "%sL%02d", i ? "\n" : "", i); + put(line); + } + CHECK(con.scrolls == 1); + CHECK(!strcmp(row_text(0), "L30")); + CHECK(!strcmp(row_text(29), "L59")); + CHECK(!strcmp(row_text(30), "L60")); + CHECK(con.row == 30 && con.text[31][0] == 0); + /* the redrawn row 0 shows "L30": 'L' row 0 is 0x0F -> pixels 0..3 lit */ + CHECK(px[0] == CK_FBCON_FG && px[3] == CK_FBCON_FG && px[4] == CK_FBCON_BG); + + /* bytes outside 0x20..0x7e are drawn as '?' */ + put("\n\x01\xff"); + CHECK(!strcmp(row_text(31), "??")); + + return ck_t_verdict("test_fbcon"); +} diff --git a/native/kernel/tests/test_handoff.c b/native/kernel/tests/test_handoff.c index 9150e371..bf0149aa 100755 --- a/native/kernel/tests/test_handoff.c +++ b/native/kernel/tests/test_handoff.c @@ -77,12 +77,23 @@ int main(void) /* 1. NULL record */ expect(0, "handoff: null record"); - /* 2. bad magic: one bit off; CHANDOF1 (the previous layout) and 0 */ + /* 2. bad magic: one bit off and 0; the previous layouts CHANDOF1 and + * CHANDOF2 and a future CHANDOF4 get the "unsupported version" line + * (contract section 6), a non-digit version byte is plain bad magic. */ h = good(); - h.magic ^= 1; + h.magic ^= 1ull << 8; expect(&h, "handoff: bad magic"); h = good(); h.magic = CK_HANDOFF_MAGIC_V1; + expect(&h, "handoff: unsupported version 1 (kernel reads CHANDOF3 only)"); + h = good(); + h.magic = CK_HANDOFF_MAGIC_V2; + expect(&h, "handoff: unsupported version 2 (kernel reads CHANDOF3 only)"); + h = good(); + h.magic = CK_HANDOFF_MAGIC_STEM | (uint64_t)'4' << 56; + expect(&h, "handoff: unsupported version 4 (kernel reads CHANDOF3 only)"); + h = good(); + h.magic = CK_HANDOFF_MAGIC_STEM | (uint64_t)'X' << 56; expect(&h, "handoff: bad magic"); h = good(); h.magic = 0; @@ -182,6 +193,72 @@ int main(void) h.model_flags = CK_HANDOFF_MODEL_PRESENT; expect(&h, ""); + /* 8. CHANDOF3 framebuffer fields (contract section 3): absent GOP must be + * all zero; a GOP without a linear framebuffer carries no range; a + * present framebuffer (the Spark's Linux view: 1920x1080, 7680-byte + * stride, 32 bpp; QEMU ramfb) passes the geometry checks. */ + h = good(); + h.fb_width = 800; + expect(&h, "handoff: fb fields without gop"); + h = good(); + h.fb_gop_handles = 1; + expect(&h, "handoff: fb fields without gop"); + h = good(); + h.fb_status = 3; + expect(&h, "handoff: bad fb status 3"); + h = good(); + h.fb_status = CK_HANDOFF_FB_NO_LINEAR; + h.fb_gop_handles = 1; + h.fb_format = 3; /* PixelBltOnly, recorded for the report */ + expect(&h, ""); + h.fb_base = 0x80000000ull; + expect(&h, "handoff: fb range without linear framebuffer 0"); + h.fb_base = 0; + h.fb_gop_handles = 0; + expect(&h, "handoff: bad fb gop handles 0"); + struct ck_handoff f = good(); + f.fb_status = CK_HANDOFF_FB_PRESENT; + f.fb_base = 0x1f0000000ull; + f.fb_size = 1920ull * 1080 * 4; + f.fb_width = 1920; + f.fb_height = 1080; + f.fb_pitch = 1920; + f.fb_format = CK_HANDOFF_FB_BGRX; + f.fb_gop_handles = 1; + expect(&f, ""); + h = f; + h.fb_format = CK_HANDOFF_FB_RGBX; + expect(&h, ""); + h = f; + h.fb_format = 2; /* PixelBitMask is never PRESENT */ + expect(&h, "handoff: bad fb format 2"); + h = f; + h.fb_width = 0; + expect(&h, "handoff: bad fb width 0"); + h = f; + h.fb_height = 16385; + expect(&h, "handoff: bad fb height 16385"); + h = f; + h.fb_pitch = 1919; + expect(&h, "handoff: bad fb pitch 1919"); + h = f; + h.fb_pitch = 2048; /* padded scan lines: size must cover pitch, not width */ + expect(&h, "handoff: fb size too small 8294400"); + h.fb_size = 2048ull * 1080 * 4; + expect(&h, ""); + h = f; + h.fb_base = 0; + expect(&h, "handoff: bad fb base 0"); + h = f; + h.fb_base = 0x1f0000002ull; + expect(&h, "handoff: bad fb base 8321499138"); + h = f; + h.fb_base = ~0ull - 4095; + expect(&h, "handoff: fb range overflow 8294400"); + h = f; + h.fb_gop_handles = 0; + expect(&h, "handoff: bad fb gop handles 0"); + /* Check order: the first failing field is reported. */ h = good(); h.magic = 0; diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb index a871db80..20173a60 100644 --- a/native/kernel/tools/.crumb +++ b/native/kernel/tools/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T15:51:27Z", + "compiled_at": "2026-10-04T17:01:01Z", "compiler": "crumb-compile/1", - "digest": "sha256:e5811b3cdf60c98c2da590e21889e5e94f48755e13193b973a0b03c18a3edf25", + "digest": "sha256:76d69ccab500306184f1ee05b9b252c740236a9656ceda44fe96c93bce2f2b21", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 9, - "generated_at_commit": "25836ba4a841e7c2b5777554919e0df79a0e665f", - "source_tree": "sha256:2919b7af8d09dc97b3933861970c670bc9e1f0f360f45cd63d9209e71173c803" + "files": 10, + "generated_at_commit": "1e28ff5b9ba3193a14e6063175d81e39d545e11f", + "source_tree": "sha256:9dd19dc4affb3f453632808fe1454100fc3b8d554018f0e1c310002bea0bbd45" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/tools/ck_fb_check.c b/native/kernel/tools/ck_fb_check.c new file mode 100644 index 00000000..8c72cde2 --- /dev/null +++ b/native/kernel/tools/ck_fb_check.c @@ -0,0 +1,272 @@ +/* ck_fb_check -- host checker for the AIENOS_CK_SCREEN gate + * (scripts/qemu_ck_screen_test.sh): does a QEMU screendump show exactly + * what the kernel's framebuffer console (core/fbcon.c) must have drawn for + * the serial log of the same boot? Hosted C, test tooling only, never part + * of an image. No OCR: the expected screen is rendered by the kernel's own + * console code from the serial bytes, and the dump is decoded cell by cell + * against the kernel's own font. + * + * ck_fb_check --serial LOG [--ppm DUMP] [--render OUT.ppm] [--expect TEXT]... + * + * --render writes the screen rendered in step 2 as a PPM (evidence, and the + * gate's self-test input); without --ppm only steps 1-2 run. + * + * 1. LOG must hold exactly one line starting "screen: gop " (the first + * line the kernel draws, core/kmain.c screen_start); its geometry + * (WxH, format, scale, grid) must match DUMP (binary PPM, P6, maxval + * 255, as QMP screendump writes it) and what ck_fbcon_setup computes. + * 2. The serial bytes from that line to the end of LOG are fed through + * ck_fbcon_write into a host buffer; every visible pixel of DUMP must + * equal the rendered pixel (mismatched=0). + * 3. DUMP is decoded: each cell must be a font glyph or blank with uniform + * scale x scale blocks and black gap rows (undecodable=0); the rows are + * printed as "screen_row NNN|text|". + * 4. Each --expect TEXT must equal one decoded row (trailing blanks + * trimmed). + * Exit 0 only if all four hold (or the render was written); 1 otherwise; 2 + * usage or unreadable input. */ +#include +#include +#include +#include + +#include "../core/fbcon.h" +#include "../core/font8x8.h" + +#define MAX_EXPECT 16 + +static unsigned char *slurp(const char *path, size_t *len) +{ + FILE *f = fopen(path, "rb"); + if (!f) + return 0; + size_t cap = 1 << 16, n = 0; + unsigned char *b = malloc(cap + 1); + size_t r; + while (b && (r = fread(b + n, 1, cap - n, f)) > 0) { + n += r; + if (n == cap) { + cap *= 2; + unsigned char *nb = realloc(b, cap + 1); + if (!nb) { + free(b); + b = 0; + } + b = nb; + } + } + fclose(f); + if (b) + b[n] = 0; + *len = n; + return b; +} + +/* P6 header: "P6" ws W ws H ws 255 single-ws, no comments (QEMU writes none). */ +static const unsigned char *ppm_parse(const unsigned char *b, size_t len, uint32_t *w, uint32_t *h) +{ + unsigned mv = 0; + int off = 0; + if (len < 16 || sscanf((const char *)b, "P6 %u %u %u%n", w, h, &mv, &off) != 3 || mv != 255) + return 0; + off++; /* the single whitespace byte after maxval */ + if ((uint64_t)off + (uint64_t)*w * *h * 3 > len || !*w || !*h) + return 0; + return b + off; +} + +static uint32_t to_pixel(const unsigned char *rgb, uint32_t format) +{ + /* Memory bytes 0..2 of a 32-bit pixel: RGBX = R,G,B; BGRX = B,G,R; the + * uint32 is read little endian like the kernel stores it. */ + if (format == 0) + return (uint32_t)rgb[0] | (uint32_t)rgb[1] << 8 | (uint32_t)rgb[2] << 16; + return (uint32_t)rgb[2] | (uint32_t)rgb[1] << 8 | (uint32_t)rgb[0] << 16; +} + +static int usage(void) +{ + fprintf(stderr, "usage: ck_fb_check --serial LOG [--ppm DUMP] [--render OUT.ppm] [--expect TEXT]...\n"); + return 2; +} + +static int write_ppm(const char *path, const uint32_t *buf, uint32_t w, uint32_t h, uint32_t format) +{ + FILE *f = fopen(path, "wb"); + if (!f) + return -1; + fprintf(f, "P6\n%u %u\n255\n", w, h); + for (uint64_t i = 0; i < (uint64_t)w * h; i++) { + uint32_t v = buf[i]; + unsigned char rgb[3]; + if (format == 0) { + rgb[0] = v & 0xff, rgb[1] = (v >> 8) & 0xff, rgb[2] = (v >> 16) & 0xff; + } else { + rgb[2] = v & 0xff, rgb[1] = (v >> 8) & 0xff, rgb[0] = (v >> 16) & 0xff; + } + fwrite(rgb, 1, 3, f); + } + return fclose(f) == 0 ? 0 : -1; +} + +int main(int argc, char **argv) +{ + const char *serial = 0, *ppm = 0, *render = 0, *expect[MAX_EXPECT]; + int n_expect = 0; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--serial") && i + 1 < argc) + serial = argv[++i]; + else if (!strcmp(argv[i], "--ppm") && i + 1 < argc) + ppm = argv[++i]; + else if (!strcmp(argv[i], "--render") && i + 1 < argc) + render = argv[++i]; + else if (!strcmp(argv[i], "--expect") && i + 1 < argc && n_expect < MAX_EXPECT) + expect[n_expect++] = argv[++i]; + else + return usage(); + } + if (!serial || (!ppm && !render)) + return usage(); + size_t slen = 0; + unsigned char *log = slurp(serial, &slen); + if (!log) { + printf("fb_check: cannot read %s\n", serial); + return 2; + } + + /* 1. the marker line, exactly once, at a line start */ + static const char marker[] = "screen: gop "; + const char *start = 0; + unsigned markers = 0; + for (size_t i = 0; i + sizeof marker - 1 <= slen; i++) + if ((i == 0 || log[i - 1] == '\n') && !memcmp(log + i, marker, sizeof marker - 1)) { + markers++; + if (!start) + start = (const char *)log + i; + } + if (markers != 1) { + printf("fb_check: FAIL %u \"screen: gop\" lines in the serial log (want exactly 1)\n", markers); + return 1; + } + uint32_t lw, lh, pitch, scale, cols, rows; + char fmt[8] = {0}; + unsigned long long base, bytes; + if (sscanf(start, "screen: gop %ux%u pitch=%u format=%4s base=0x%llx bytes=0x%llx scale=%u grid=%ux%u", + &lw, &lh, &pitch, fmt, &base, &bytes, &scale, &cols, &rows) != 9 || + (strcmp(fmt, "rgbx") && strcmp(fmt, "bgrx"))) { + printf("fb_check: FAIL malformed \"screen: gop\" line\n"); + return 1; + } + uint32_t format = !strcmp(fmt, "bgrx"); + + /* 2. render the serial bytes from the marker on with the kernel's code */ + static struct ck_fbcon con; + uint32_t w = lw, h = lh; + uint32_t *buf = calloc((size_t)w * h, 4); + if (!buf || ck_fbcon_setup(&con, buf, w, h, w, format) != 0) { + printf("fb_check: FAIL cannot set up a %ux%u console\n", w, h); + return 1; + } + if (con.scale != scale || con.cols != cols || con.rows != rows) { + printf("fb_check: FAIL geometry: serial scale=%u grid=%ux%u, console code scale=%u grid=%ux%u\n", scale, + cols, rows, con.scale, con.cols, con.rows); + return 1; + } + ck_fbcon_write(&con, start, slen - (size_t)(start - (const char *)log)); + if (render && write_ppm(render, buf, w, h, format) != 0) { + printf("fb_check: cannot write %s\n", render); + return 2; + } + if (!ppm) { + printf("fb_check: rendered %ux%u format=%s scale=%u grid=%ux%u scrolls=%llu to %s\n", w, h, fmt, scale, + cols, rows, (unsigned long long)con.scrolls, render); + return 0; + } + + size_t plen = 0; + unsigned char *dump = slurp(ppm, &plen); + uint32_t dw = 0, dh = 0; + const unsigned char *px = dump ? ppm_parse(dump, plen, &dw, &dh) : 0; + if (!px) { + printf("fb_check: FAIL %s is missing or not a binary P6 PPM with maxval 255\n", ppm); + return 1; + } + if (dw != w || dh != h) { + printf("fb_check: FAIL geometry: serial %ux%u, dump %ux%u\n", w, h, dw, dh); + return 1; + } + uint64_t mismatched = 0; + for (uint32_t y = 0; y < h; y++) + for (uint32_t x = 0; x < w; x++) { + uint64_t i = (uint64_t)y * w + x; + if (to_pixel(px + 3 * i, format) != buf[i]) { + if (mismatched < 5) + printf("fb_check: pixel (%u,%u) dump=0x%06x rendered=0x%06x\n", x, y, + to_pixel(px + 3 * i, format), buf[i]); + mismatched++; + } + } + + /* 3. decode the dump against the font */ + uint64_t undecodable = 0; + char (*text)[CK_FBCON_MAX_COLS + 1] = calloc(rows, sizeof *text); + if (!text) + return 2; + uint32_t s = scale, cw = CK_FBCON_CELL_W * s, chh = CK_FBCON_CELL_H * s; + for (uint32_t r = 0; r < rows; r++) { + for (uint32_t k = 0; k < cols; k++) { + uint8_t bits[CK_FBCON_CELL_H] = {0}; + int bad = 0; + for (uint32_t cy = 0; cy < chh && !bad; cy++) + for (uint32_t cx = 0; cx < cw; cx++) { + uint64_t i = ((uint64_t)r * chh + cy) * w + (uint64_t)k * cw + cx; + uint32_t v = to_pixel(px + 3 * i, format); + if (v != CK_FBCON_FG && v != CK_FBCON_BG) { + bad = 1; + break; + } + int on = v == CK_FBCON_FG; + uint32_t gy = cy / s, gx = cx / s; + if (cy % s == 0 && cx % s == 0) { + if (on) + bits[gy] |= (uint8_t)(1u << gx); + } else if (on != ((bits[gy] >> gx) & 1)) { + bad = 1; /* scale x scale block not uniform */ + break; + } + } + if (!bad && (bits[8] || bits[9])) + bad = 1; /* the two gap rows of a cell stay black */ + char ch = 0; + for (int g = 0; !bad && g <= CK_FONT_LAST - CK_FONT_FIRST && !ch; g++) + if (!memcmp(bits, ck_font8x8[g], CK_FONT_H)) + ch = (char)(CK_FONT_FIRST + g); + if (!ch) { + ch = '?'; /* shown as '?', counted; a real '?' glyph is not counted */ + undecodable++; + } + text[r][k] = ch; + } + uint32_t n = cols; + while (n && text[r][n - 1] == ' ') + n--; + text[r][n] = 0; + printf("screen_row %03u|%s|\n", r, text[r]); + } + + /* 4. expected rows */ + int found_all = 1; + for (int e = 0; e < n_expect; e++) { + int found = 0; + for (uint32_t r = 0; r < rows && !found; r++) + found = !strcmp(text[r], expect[e]); + printf("fb_check: expect \"%s\": %s\n", expect[e], found ? "found" : "MISSING"); + found_all &= found; + } + int ok = mismatched == 0 && undecodable == 0 && found_all; + printf("fb_check: %s %ux%u format=%s scale=%u grid=%ux%u scrolls=%llu pixels=%llu mismatched=%llu " + "undecodable=%llu\n", + ok ? "PASS" : "FAIL", w, h, fmt, scale, cols, rows, (unsigned long long)con.scrolls, + (unsigned long long)w * h, (unsigned long long)mismatched, (unsigned long long)undecodable); + return ok ? 0 : 1; +} diff --git a/scripts/.crumb b/scripts/.crumb index 797f63ad..09875185 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T15:16:40Z", + "compiled_at": "2026-10-04T16:47:58Z", "compiler": "crumb-compile/1", - "digest": "sha256:f99911001560491e4c719aa841ac33c9cec413ee578fe55da847f4c781e992af", + "digest": "sha256:c2faf9bb1f39cfe42057ef4fc740d04cc8c614bd4e31917f41b5cbe1acb8fcb6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 60, - "generated_at_commit": "733a8419c1fa44a13dc5e8f525eca33cdea7c5dc", - "source_tree": "sha256:11bc11a213a89c83b74db884e14700018aec98cdb8be66d8c1550700473eb8d6" + "files": 62, + "generated_at_commit": "2e44c0bba93bcc605dd45570ee8cfb8d56591cc3", + "source_tree": "sha256:145f37544c387b2b7a0c69d7ee85d8c35911ffada9808e4c6b4b0b7a97b0ec61" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index 89af5c3d..1f896d7e 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -8,11 +8,11 @@ # scripts/qemu_ck_smp_test.sh, scripts/qemu_ck_store_crash_test.sh, # scripts/qemu_ck_disk_layout_test.sh, scripts/qemu_ck_continuity_test.sh, # scripts/qemu_ck_recovery_test.sh, scripts/qemu_ck_fpu_test.sh, -# scripts/qemu_ck_infer_test.sh), and prints +# scripts/qemu_ck_infer_test.sh, scripts/qemu_ck_screen_test.sh), and prints # one line per gate: # AIENOS_CK_: PASS|FAIL|NOT_RUN [(reason)] # for M1 M3 SMMU NVME_SHUTDOWN P2_ARTIFACT M0_ROLLBACK M4_NVME M4_STORE M4_STORE_CRASH -# M4_CONTINUITY M4_RECOVERY ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER. Gates with no C +# M4_CONTINUITY M4_RECOVERY ARGUS1_REVOKE KEYBOARD NET SMP DISK_LAYOUT FPU INFER SCREEN. Gates with no C # implementation print NOT_RUN (MISSING_IMPLEMENTATION: ) and never # run anything. A missing child script, a child that reports NOT_RUN, a child # that prints no verdict line, or a PASS line contradicted by the child's exit @@ -21,7 +21,7 @@ # # QEMU is an emulator: a PASS here qualifies nothing physical (the receipt # says "physical": "NOT_RUN"). The child scripts serialise themselves: the -# FPU and INFER children take the QEMU gate lock (~/workspace/.qemu-gate-lock, +# FPU, INFER and SCREEN children take the QEMU gate lock (~/workspace/.qemu-gate-lock, # exclusive create) and report NOT_RUN while another gate run holds it or # while the machine quiet flag (~/workspace/.spark-quiet) exists, which they # only read (no agent raises the quiet flag without Drake's approval); the @@ -55,6 +55,7 @@ set -uo pipefail # recov -> verdict line from scripts/qemu_ck_recovery_test.sh # fpu -> verdict line from scripts/qemu_ck_fpu_test.sh (NOT_RUN without the Rust target) # infer -> verdict line from scripts/qemu_ck_infer_test.sh (NOT_RUN without the model file or the Rust target) +# screen -> verdict line from scripts/qemu_ck_screen_test.sh (GOP framebuffer console vs a QMP screendump) # missing -> NOT_RUN (MISSING_IMPLEMENTATION), never run, never PASS # =========================================================================== CK_GATE_TABLE=' @@ -76,8 +77,9 @@ SMP|smp|- DISK_LAYOUT|disk|- FPU|fpu|- INFER|infer|- +SCREEN|screen|- ' -CHILDREN=(boot store net artifact smp crash disk cont recov fpu infer) +CHILDREN=(boot store net artifact smp crash disk cont recov fpu infer screen) # =========================================================================== repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -126,6 +128,7 @@ set_default_children() { [recov]="${repo_root}/scripts/qemu_ck_recovery_test.sh" [fpu]="${repo_root}/scripts/qemu_ck_fpu_test.sh" [infer]="${repo_root}/scripts/qemu_ck_infer_test.sh" + [screen]="${repo_root}/scripts/qemu_ck_screen_test.sh" ) } @@ -355,11 +358,11 @@ self_test() { } expect_missing_all() { local g - for g in P2_ARTIFACT M0_ROLLBACK M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY KEYBOARD DISK_LAYOUT FPU INFER; do expect "${g}" NOT_RUN; done # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S + for g in P2_ARTIFACT M0_ROLLBACK M4_STORE_CRASH M4_CONTINUITY M4_RECOVERY KEYBOARD DISK_LAYOUT FPU INFER SCREEN; do expect "${g}" NOT_RUN; done # P2_ARTIFACT: no artifact child in A..G; M4_STORE_CRASH: no crash child in A..J and R; DISK_LAYOUT: no disk child in A..S } scenario() { # NAME BOOT_SCRIPT STORE_SCRIPT [NET_SCRIPT] [ARTIFACT_SCRIPT] [SMP_SCRIPT] [CRASH_SCRIPT] [DISK_SCRIPT] (absent: missing) scen="$1" - declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh") + declare -gA child_script=([boot]="$2" [store]="$3" [net]="${4:-${tmp}/kids/net_not_present.sh}" [artifact]="${5:-${tmp}/kids/no_artifact_child.sh}" [smp]="${6:-${tmp}/kids/no_smp_child.sh}" [crash]="${7:-${tmp}/kids/no_crash_child.sh}" [disk]="${8:-${tmp}/kids/no_disk_child.sh}" [cont]="${tmp}/kids/no_cont_child.sh" [recov]="${tmp}/kids/no_recov_child.sh" [fpu]="${tmp}/kids/no_fpu_child.sh" [infer]="${tmp}/kids/no_infer_child.sh" [screen]="${tmp}/kids/no_screen_child.sh") run_children 2>/dev/null evaluate_table >"${tmp}/${scen}.out" } @@ -375,8 +378,8 @@ self_test() { "$(fake smpA 0 'PASS 3 secondary cores checked in' 'AIENOS_CK_SMP_MUTATION: FAIL' 'AIENOS_CK_SMP: PASS')" expect M1 PASS; expect M3 PASS; expect M4_NVME PASS; expect M4_STORE PASS; expect ARGUS1_REVOKE PASS; expect SMMU PASS; expect NVME_SHUTDOWN PASS; expect NET PASS; expect SMP PASS; expect_missing_all count_rows - [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/9/18" && ${overall} == NOT_ALL_GATES_PASS ]] \ - && ok "A: counts 9/0/9 of 18, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}" + [[ "${n_pass}/${n_fail}/${n_notrun}/${n_total}" == "9/0/10/19" && ${overall} == NOT_ALL_GATES_PASS ]] \ + && ok "A: counts 9/0/10 of 19, verdict NOT_ALL_GATES_PASS" || bad "A: counts ${n_pass}/${n_fail}/${n_notrun}/${n_total} ${overall}" [[ "$(nvme_dma_mode)" == "Confined (QEMU SMMUv3 stage 1, out-of-window DMA faulted); no-SMMU boot denied (NoSmmu); TEST-ONLY bypass image checked separately" ]] && ok "A: confined DMA mode recorded from the store PASS lines" || bad "A: dma mode '$(nvme_dma_mode)'" grep -qxF "AIENOS_CK_M4_NVME: PASS (${M4_NVME_PASS_NOTE})" "${tmp}/A.out" \ && ok "A: M4_NVME PASS line carries the confined-mode note" || bad "A: M4_NVME PASS line lacks the note" @@ -384,7 +387,7 @@ self_test() { && ok "A: NET PASS line carries the QEMU slirp / SMMU fence note" || bad "A: NET PASS line lacks the note" grep -qx 'AIENOS_CK_KEYBOARD: NOT_RUN (MISSING_IMPLEMENTATION: no xHCI/USB HID keyboard driver in the C kernel)' "${tmp}/A.out" \ && ok "A: missing gate prints NOT_RUN (MISSING_IMPLEMENTATION: reason)" || bad "A: KEYBOARD line wrong" - [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 18 ]] && ok "A: exactly 18 verdict lines" || bad "A: verdict line count" + [[ "$(grep -c '^AIENOS_CK_[A-Z0-9_]*: ' "${tmp}/A.out")" == 19 ]] && ok "A: exactly 19 verdict lines" || bad "A: verdict line count" # B: boot FAIL; store script missing -> its three gates NOT_RUN, never PASS. scenario B "$(fake bootB 1 'FAIL kernel: alive' 'AIENOS_CK_M3: FAIL' 'AIENOS_CK_M1: FAIL')" "${tmp}/kids/does_not_exist.sh" @@ -497,10 +500,10 @@ self_test() { # Restore the clean-tree receipt as the one the checks below look at. write_receipt if command -v jq >/dev/null; then - jq -e '.physical == "NOT_RUN" and (.gates | length) == 18 and .verdict == "NOT_ALL_GATES_PASS" + jq -e '.physical == "NOT_RUN" and (.gates | length) == 19 and .verdict == "NOT_ALL_GATES_PASS" and ([.gates[] | select(.id == "M1")][0].verdict == "PASS") and ([.gates[] | select(.id == "ARGUS1_REVOKE")][0].verdict == "FAIL") - and (.children | length) == 11 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ + and (.children | length) == 12 and .commit_subject == "quote \" backslash \\ tab\tend"' "${receipt_path}" >/dev/null \ && ok "receipt is valid JSON (jq) with expected fields" || bad "receipt JSON invalid or fields wrong" else echo "NOT_RUN jq not installed; JSON validity not machine-checked"; jq_skipped=1 @@ -513,18 +516,18 @@ self_test() { bad "an existing receipt was overwritten or the clash was not refused" fi - # The gate table parses: 18 rows, known sources, reasons only on missing rows. + # The gate table parses: 19 rows, known sources, reasons only on missing rows. local g s w rows=0 tbad=0 while IFS='|' read -r g s w; do [[ -n "${g}" ]] || continue rows=$((rows + 1)) case "${s}" in - boot|store|net|artifact|smp|crash|disk|cont|recov|fpu|infer) [[ "${w}" == - ]] || tbad=1 ;; + boot|store|net|artifact|smp|crash|disk|cont|recov|fpu|infer|screen) [[ "${w}" == - ]] || tbad=1 ;; missing) [[ -n "${w}" && "${w}" != - ]] || tbad=1 ;; *) tbad=1 ;; esac done <<<"${CK_GATE_TABLE}" - [[ ${tbad} == 0 && ${rows} == 18 ]] && ok "gate table: 18 rows well-formed" || bad "gate table malformed (${rows} rows)" + [[ ${tbad} == 0 && ${rows} == 19 ]] && ok "gate table: 19 rows well-formed" || bad "gate table malformed (${rows} rows)" # Dirty-tree refusal, end to end, on a private clone (never this tree). # Both runs stop before any child script (no QEMU). diff --git a/scripts/qemu_ck_screen_test.sh b/scripts/qemu_ck_screen_test.sh new file mode 100755 index 00000000..41ffca45 --- /dev/null +++ b/scripts/qemu_ck_screen_test.sh @@ -0,0 +1,252 @@ +#!/usr/bin/env bash +# Boot the AIENOS C kernel core in QEMU AArch64 (UEFI/AAVMF, EL2 like +# Machine 1) with a ramfb display and check that the kernel drew its console +# on the UEFI Graphics Output Protocol framebuffer the boot stub handed over +# in the CHANDOF3 record (native/boot/efi_gop.c, native/kernel/core/fbcon.c). +# Last line: AIENOS_CK_SCREEN: PASS|FAIL|NOT_RUN (read by scripts/ck_gates.sh). +# +# Two boots, both with "-device ramfb" and a QMP socket; QEMU runs with +# "-action reboot=shutdown,shutdown=pause", so the kernel's final PSCI reset +# pauses the guest with the last screen still in place, and the script takes a +# QMP "screendump" (binary PPM) before quitting QEMU. +# 1. default image (core only, as built by make): the serial log must show +# the stub's "gop: ok" line, exactly one "screen: gop" line, "kernel: +# alive", no panic/fault, a reset (QEMU status "shutdown"), and the host +# checker (native/kernel/tools/ck_fb_check.c) must find the screendump +# pixel-identical to the screen the kernel's own console code renders +# from the serial bytes, decode every cell against the kernel's font, +# and find the rows "report_kind: final" and "note: QEMU qualifies +# nothing physical" on screen. +# 2. negative control, TEST-only image (make CK_TEST_STALE_HANDOFF=2): the +# stub hands over a CHANDOF2 record; the kernel must refuse it with +# "panic: handoff: unsupported version 2 (kernel reads CHANDOF3 only)", +# never draw ("screen: gop" absent, "kernel: alive" absent), and the +# host checker must FAIL on that boot's serial log and screendump. +# QEMU is not hardware: a PASS here qualifies nothing physical. It says +# nothing about the Spark's own GOP (UNVERIFIED until an attended boot). +# +# NOT_RUN (never a silent pass) when qemu, AAVMF, socat or the host compiler +# is missing, the QEMU gate lock (~/workspace/.qemu-gate-lock, exclusive +# create, same rule as the FPU and INFER gates) is held, or the machine quiet +# flag (~/workspace/.spark-quiet) exists; this script never writes the quiet +# flag. +# +# Usage: bash scripts/qemu_ck_screen_test.sh the gate +# bash scripts/qemu_ck_screen_test.sh --self-test canned logs and +# rendered screens, no QEMU +# Environment: AIENOS_QEMU_TIMEOUT (300 s per boot), AIENOS_GATE_LOCK / +# AIENOS_GATE_TAG, AIENOS_QUIET_FLAG (read only), AIENOS_LOG_DIR (serial logs, +# screendumps, decoded rows and PNGs when ffmpeg exists), AIENOS_QEMU_VERBOSE, +# AIENOS_FB_CHECK_TOOL (prebuilt checker, for a red run on an older commit). +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +verdict_name=AIENOS_CK_SCREEN +stale_line='panic: handoff: unsupported version 2 (kernel reads CHANDOF3 only)' +expect_rows=("report_kind: final" "note: QEMU qualifies nothing physical") + +# positive_checks SERIAL PPM TOOL STATUS OUTPREFIX: PASS/FAIL line per check. +positive_checks() { + local serial="$1" ppm="$2" tool="$3" status="$4" pre="$5" n args=() e + ok() { echo "PASS $*"; } + bad() { echo "FAIL $*"; } + grep -qE '^gop: ok ' "${serial}" && ok "boot stub found a GOP linear framebuffer" || bad "no 'gop: ok' line from the boot stub" + n="$(grep -cE '^screen: gop ' "${serial}" || true)" + [[ "${n}" == 1 ]] && ok "kernel put its console on the framebuffer (one 'screen: gop' line)" || bad "${n} 'screen: gop' lines (want 1)" + grep -qx 'kernel: alive' "${serial}" && ok "kernel alive" || bad "kernel never reached kernel: alive" + if grep -qE 'report_kind: (panic|fault)' "${serial}"; then bad "panic or fault report"; else ok "no panic or fault"; fi + [[ "${status}" == shutdown ]] && ok "guest reset reached (QEMU paused at shutdown)" || bad "QEMU status '${status}' (want shutdown)" + for e in "${expect_rows[@]}"; do args+=(--expect "${e}"); done + if "${tool}" --serial "${serial}" --ppm "${ppm}" --render "${pre}.expected.ppm" "${args[@]}" >"${pre}.fbcheck.txt" 2>&1; then + ok "screendump matches the rendered console: $(tail -1 "${pre}.fbcheck.txt")" + else + bad "screen check: $(grep -E '^fb_check: (FAIL|expect .*MISSING|pixel)' "${pre}.fbcheck.txt" | head -3 | paste -sd';' -)" + fi +} + +# negative_checks SERIAL PPM TOOL STATUS OUTPREFIX +negative_checks() { + local serial="$1" ppm="$2" tool="$3" status="$4" pre="$5" + ok() { echo "PASS $*"; } + bad() { echo "FAIL $*"; } + grep -qF 'TEST-ONLY stale handoff image' "${serial}" && ok "negative image announced itself (TEST-ONLY)" || bad "negative image did not announce itself" + grep -qxF "${stale_line}" "${serial}" && ok "kernel refused the CHANDOF2 record: ${stale_line}" || bad "no '${stale_line}' line" + if grep -qE '^screen: gop ' "${serial}"; then bad "kernel drew on the screen after a stale record"; else ok "no screen console after the refusal"; fi + if grep -qx 'kernel: alive' "${serial}"; then bad "kernel went on after a stale record"; else ok "kernel stopped before kernel: alive"; fi + [[ "${status}" == shutdown ]] && ok "refusal ended in a reset (QEMU paused at shutdown)" || bad "QEMU status '${status}' (want shutdown)" + if "${tool}" --serial "${serial}" --ppm "${ppm}" --expect "${stale_line}" >"${pre}.fbcheck.txt" 2>&1; then + bad "screen check PASSED on the refused boot (checker does not discriminate)" + else + ok "screen check FAILS on the refused boot as required ($(tail -1 "${pre}.fbcheck.txt"))" + fi +} + +build_tool() { # OUT -> path of ck_fb_check (AIENOS_FB_CHECK_TOOL: a prebuilt + # checker, only for the red run on a commit that predates the tool) + if [[ -n "${AIENOS_FB_CHECK_TOOL:-}" ]]; then echo "${AIENOS_FB_CHECK_TOOL}"; return; fi + make -s -C native/kernel OUT="$1" fb-check >/dev/null + echo "$1/host/ck_fb_check" +} + +if [[ "${1:-}" == --self-test ]]; then + command -v "${HOSTCC:-cc}" >/dev/null || command -v gcc >/dev/null || { echo "${verdict_name}_SELF_TEST: NOT_RUN (no host compiler)"; exit 2; } + tmp="$(mktemp -d)"; trap 'rm -rf "${tmp}"' EXIT + tool="$(build_tool "${tmp}/out")" + st=0 + expect_result() { # NAME pass|fail OUTPUT-FILE + local f=0; grep -q '^FAIL' "$3" && f=1 + if [[ "$2" == pass && ${f} == 0 ]] || [[ "$2" == fail && ${f} == 1 ]]; then echo "PASS self-test $1"; else echo "FAIL self-test $1"; sed 's/^/ /' "$3"; st=1; fi + } + # A canned positive boot: firmware noise, the marker, 80 numbered lines + # (forces one half-scroll on the 60-row 800x600 grid), the final report. + { + printf 'BdsDxe: loading Boot0001\r\ngop: ok from=conout handles=2 mode=1/3 800x600 pitch=800 format=1 base=0xbc7a0000 size=0x300000\r\n' + printf 'screen: gop 800x600 pitch=800 format=bgrx base=0xbc7a0000 bytes=0x1d4c00 scale=1 grid=100x60 font=8x8 mode=half-scroll\r\n' + printf '\r\nkernel: alive\r\n' + for i in $(seq 1 80); do printf 'line %02d: the quick brown fox jumps over the lazy dog ~!@#$%%^&*()_+{}|:"<>?\r\n' "${i}"; done + printf 'report_kind: final\r\nnote: QEMU qualifies nothing physical\r\n' + } >"${tmp}/good.raw" + tr -d '\r' <"${tmp}/good.raw" >"${tmp}/good.log" + "${tool}" --serial "${tmp}/good.raw" --render "${tmp}/good.ppm" >/dev/null + positive_checks "${tmp}/good.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p1" >"${tmp}/r1"; expect_result positive-good pass "${tmp}/r1" + # one flipped pixel byte in the last row of the image + cp "${tmp}/good.ppm" "${tmp}/flip.ppm"; sz=$(stat -c %s "${tmp}/flip.ppm") + printf '\x80' | dd of="${tmp}/flip.ppm" bs=1 seek=$((sz - 7)) conv=notrunc status=none + positive_checks "${tmp}/good.log" "${tmp}/flip.ppm" "${tool}" shutdown "${tmp}/p2" >"${tmp}/r2"; expect_result one-pixel-off fail "${tmp}/r2" + # the screen of a different text (one character changed in the log) + sed 's/line 79: the quick/line 79: the quack/' "${tmp}/good.log" >"${tmp}/other.log" + positive_checks "${tmp}/other.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p3" >"${tmp}/r3"; expect_result one-char-off fail "${tmp}/r3" + # no marker line; marker twice; expected row missing; not reset; panic + grep -v '^screen: gop' "${tmp}/good.log" >"${tmp}/nomark.log" + positive_checks "${tmp}/nomark.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p4" >"${tmp}/r4"; expect_result no-marker fail "${tmp}/r4" + { cat "${tmp}/good.log"; grep '^screen: gop' "${tmp}/good.log"; } >"${tmp}/twomark.log" + positive_checks "${tmp}/twomark.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p5" >"${tmp}/r5"; expect_result two-markers fail "${tmp}/r5" + grep -v '^note: QEMU' "${tmp}/good.raw" >"${tmp}/nonote.raw"; tr -d '\r' <"${tmp}/nonote.raw" >"${tmp}/nonote.log" + "${tool}" --serial "${tmp}/nonote.raw" --render "${tmp}/nonote.ppm" >/dev/null + positive_checks "${tmp}/nonote.log" "${tmp}/nonote.ppm" "${tool}" shutdown "${tmp}/p6" >"${tmp}/r6"; expect_result expected-row-missing fail "${tmp}/r6" + positive_checks "${tmp}/good.log" "${tmp}/good.ppm" "${tool}" running "${tmp}/p7" >"${tmp}/r7"; expect_result no-reset fail "${tmp}/r7" + { cat "${tmp}/good.log"; echo "report_kind: panic"; } >"${tmp}/panic.log" + positive_checks "${tmp}/panic.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p8" >"${tmp}/r8"; expect_result panic fail "${tmp}/r8" + # negative control: a refused boot, and a "refused" boot that drew anyway + printf 'handoff: TEST-ONLY stale handoff image: the kernel gets a CHANDOF2 record; never counts toward a PASS\nreport_kind: panic\n%s\n' "${stale_line}" >"${tmp}/neg.log" + positive_checks "${tmp}/neg.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/p9" >"${tmp}/r9"; expect_result stale-boot-is-not-a-positive fail "${tmp}/r9" + negative_checks "${tmp}/neg.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/n1" >"${tmp}/r10"; expect_result negative-good pass "${tmp}/r10" + { cat "${tmp}/neg.log"; cat "${tmp}/good.log"; } >"${tmp}/negdrew.log" + negative_checks "${tmp}/negdrew.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/n2" >"${tmp}/r11"; expect_result negative-that-drew fail "${tmp}/r11" + grep -v "^panic: handoff" "${tmp}/neg.log" >"${tmp}/negnoline.log" + negative_checks "${tmp}/negnoline.log" "${tmp}/good.ppm" "${tool}" shutdown "${tmp}/n3" >"${tmp}/r12"; expect_result negative-without-refusal-line fail "${tmp}/r12" + [[ ${st} == 0 ]] && { echo "${verdict_name}_SELF_TEST: PASS"; exit 0; } + echo "${verdict_name}_SELF_TEST: FAIL"; exit 1 +fi + +notrun() { echo "NOT_RUN $*"; echo "${verdict_name}: NOT_RUN ($*)"; exit 2; } +command -v qemu-system-aarch64 >/dev/null || notrun "qemu-system-aarch64 not installed" +command -v socat >/dev/null || notrun "socat not installed (QMP screendump)" +code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || notrun "AAVMF firmware not found" + +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" +out="${repo_root}/target/native-kernel-screen" +out_neg="${repo_root}/target/native-kernel-test-stale-handoff" +make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" >/dev/null +make -s -C native/kernel CROSS="${cross}" OUT="${out_neg}" AIENOS_COMMIT="${commit}" CK_TEST_STALE_HANDOFF=2 >/dev/null +tool="$(build_tool "${out}")" + +# Machine-wide quiet flag: read only, never written here. +quiet_flag="${AIENOS_QUIET_FLAG:-${HOME}/workspace/.spark-quiet}" +if [[ -e "${quiet_flag}" ]]; then + echo "NOT_RUN quiet flag ${quiet_flag} is held: $(head -c 200 "${quiet_flag}" 2>/dev/null || true)" + echo "${verdict_name}: NOT_RUN" + exit 3 +fi +# One QEMU gate at a time: exclusive create (set -C) of the gate lock. +gate_lock="${AIENOS_GATE_LOCK:-${HOME}/workspace/.qemu-gate-lock}" +gate_tag="${AIENOS_GATE_TAG:-qemu_ck_screen_test $$}" +if ! ( set -C; echo "${gate_tag}" > "${gate_lock}" ) 2>/dev/null; then + echo "NOT_RUN QEMU gate lock ${gate_lock} is held: $(head -c 200 "${gate_lock}" 2>/dev/null || true)" + echo "${verdict_name}: NOT_RUN" + exit 3 +fi +own_lock=1 +release_lock() { + if [[ "${own_lock}" == 1 ]]; then + own_lock=0 + if [[ -f "${gate_lock}" ]] && grep -qxF -- "${gate_tag}" "${gate_lock}"; then rm -f "${gate_lock}"; fi + fi +} +work="$(mktemp -d)" +cleanup() { rm -rf "${work}"; release_lock; } +trap cleanup EXIT + +qmp() { # SOCKET JSON-COMMAND -> QEMU's replies + printf '{"execute":"qmp_capabilities"}\n%s\n' "$2" | socat -t3 - "UNIX-CONNECT:$1" 2>/dev/null || true +} + +# boot NAME EFI: one QEMU run; sets boot_status, boot_rc, boot_secs. +boot() { + local name="$1" efi="$2" d="${work}/$1" t0 deadline st qpid + mkdir -p "${d}/esp/EFI/BOOT" "${d}/esp/EFI/AIENOS" + touch "${d}/esp/EFI/AIENOS/BOOTREPORT.TXT" + cp "${efi}" "${d}/esp/EFI/BOOT/BOOTAA64.EFI" + cp "${vars_fd}" "${d}/vars.fd" + t0=$(date +%s); deadline=$(( t0 + ${AIENOS_QEMU_TIMEOUT:-300} )) + qemu-system-aarch64 \ + -M virt,virtualization=on,gic-version=3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ + -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ + -drive if=pflash,format=raw,file="${d}/vars.fd" \ + -drive if=none,id=esp,format=raw,file=fat:rw:"${d}/esp" \ + -device virtio-blk-pci,drive=esp \ + -device ramfb -display none -nic none \ + -serial file:"${d}/serial.raw" \ + -qmp unix:"${d}/qmp.sock",server=on,wait=off \ + -action reboot=shutdown,shutdown=pause & + qpid=$! + boot_status=timeout + while (( $(date +%s) < deadline )) && kill -0 "${qpid}" 2>/dev/null; do + sleep 2 + st="$(qmp "${d}/qmp.sock" '{"execute":"query-status"}' | sed -n 's/.*"status": *"\([a-z-]*\)".*/\1/p' | tail -1)" + if [[ -n "${st}" && "${st}" != running && "${st}" != prelaunch ]]; then boot_status="${st}"; break; fi + done + qmp "${d}/qmp.sock" "{\"execute\":\"screendump\",\"arguments\":{\"filename\":\"${d}/screen.ppm\"}}" >"${d}/qmp_screendump.txt" + qmp "${d}/qmp.sock" '{"execute":"quit"}' >/dev/null + set +e; wait "${qpid}"; boot_rc=$?; set -e + boot_secs=$(( $(date +%s) - t0 )) + tr -d '\r' <"${d}/serial.raw" >"${d}/serial.txt" 2>/dev/null || : >"${d}/serial.txt" + echo "qemu ${name}: status ${boot_status}, exit ${boot_rc} after ${boot_secs} s" +} + +started=$(date +%s) +boot positive "${out}/BOOTAA64.EFI"; pos_status="${boot_status}" +boot negative "${out_neg}/BOOTAA64.EFI"; neg_status="${boot_status}" +release_lock +echo "commit ${commit:0:12}, both boots in $(( $(date +%s) - started )) s" + +failed=0 +pos="$(positive_checks "${work}/positive/serial.txt" "${work}/positive/screen.ppm" "${tool}" "${pos_status}" "${work}/positive/out")" || true +neg="$(negative_checks "${work}/negative/serial.txt" "${work}/negative/screen.ppm" "${tool}" "${neg_status}" "${work}/negative/out")" || true +echo "-- default image (GOP console)"; printf '%s\n' "${pos}" +echo "-- negative control (TEST-only CHANDOF2 record)"; printf '%s\n' "${neg}" +grep -q '^FAIL' <<<"${pos}${neg}" && failed=1 +grep -E '^(gop|screen): ' "${work}/positive/serial.txt" || true +grep -E '^screen_row ' "${work}/positive/out.fbcheck.txt" 2>/dev/null | grep -v '||$' | tail -8 || true + +if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then + for b in positive negative; do + cp "${work}/${b}/serial.txt" "${AIENOS_LOG_DIR}/qemu_ck_screen_${b}_serial.log" 2>/dev/null || true + cp "${work}/${b}/screen.ppm" "${AIENOS_LOG_DIR}/qemu_ck_screen_${b}_screendump.ppm" 2>/dev/null || true + cp "${work}/${b}/out.fbcheck.txt" "${AIENOS_LOG_DIR}/qemu_ck_screen_${b}_fbcheck.txt" 2>/dev/null || true + if command -v ffmpeg >/dev/null && [[ -f "${work}/${b}/screen.ppm" ]]; then + ffmpeg -loglevel error -y -i "${work}/${b}/screen.ppm" "${AIENOS_LOG_DIR}/qemu_ck_screen_${b}_screendump.png" || true + fi + done + cp "${work}/positive/out.expected.ppm" "${AIENOS_LOG_DIR}/qemu_ck_screen_positive_expected.ppm" 2>/dev/null || true +fi +if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then + for b in positive negative; do echo "---- ${b} serial console (last 40 lines) ----"; tail -40 "${work}/${b}/serial.txt"; done +fi +if [[ "${failed}" == 0 ]]; then echo "${verdict_name}: PASS"; exit 0; fi +echo "${verdict_name}: FAIL"; exit 1 diff --git a/scripts/stage_one_time_boot_ck.sh b/scripts/stage_one_time_boot_ck.sh new file mode 100755 index 00000000..fc28a649 --- /dev/null +++ b/scripts/stage_one_time_boot_ck.sh @@ -0,0 +1,240 @@ +#!/usr/bin/env bash +# Stage the C kernel (native/kernel) inference image plus its MODEL.MAP on +# Machine 1 for exactly one attended boot (L6, aienos#34 lane 6; L6-C screen +# console). Variant of scripts/stage_one_time_boot.sh, which stages the Rust +# aienos-handoff image. +# +# scripts/stage_one_time_boot_ck.sh --dry-run print every command, touch nothing +# scripts/stage_one_time_boot_ck.sh --apply do it (needs sudo; operator only) +# +# Exactly one of the two is required; there is no default mode. +# +# --dry-run runs only read-only probes (git, findmnt, lsblk, lsattr, stat, +# efibootmgr without arguments, the Secure Boot variable) and prints every +# command --apply would run, in order. It builds nothing, writes nothing, +# creates no file or directory, and calls no sudo. +# +# --apply, in order: +# 1. builds the infer image (core-only C kernel + crates/aienos-infer-kernel, +# the image the L6 handoff chose: no NVMe stage, the model comes through +# the firmware's own Block I/O before ExitBootServices) with +# CK_FB_HOLD_S=120 so the last report stays on screen for two minutes +# before the reset, and the host tool ck_model_map; +# 2. sudo chattr +i on the model file, FIRST, so its blocks cannot move +# between the map and the boot; +# 3. sudo ck_model_map make MODEL.MAP --fiemap --part-start auto --disk +# /dev/nvme0n1, then sudo ck_model_map check (reads every extent by LBA +# from the raw disk and recomputes the SHA-256: the same bytes the +# firmware will read); +# 4. sudo scripts/verify_native_rollback.sh --capture-pre (before BootNext, +# which the capture requires absent); +# 5. copies the image and MODEL.MAP to \EFI\AIENOS on the ESP (the only +# scratch directory, docs/NATIVE_BOOT_ONE_TIME.md invariant 4) with a +# STAGED-CK.TXT record; +# 6. creates a boot entry WITHOUT adding it to BootOrder (BootOrder is +# restored if anything changed it), checks that Boot0004 AIENOSRECOV is +# still there, and sets BootNext once. +# +# It never reboots. The firmware consumes BootNext on that boot, so the next +# boot after it returns to the normal BootOrder (Linux). The boot itself is +# attended: Drake at the machine, AIENOSRECOV stick inserted (Boot0004). +# The model stays immutable until the operator runs, after the return: +# sudo chattr -i +# No Python. +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" + +mode="" +case "${1:-}" in + --dry-run) mode=dry ;; + --apply) mode=apply ;; + *) echo "usage: $0 --dry-run | --apply" >&2; exit 2 ;; +esac +[[ $# -eq 1 ]] || { echo "usage: $0 --dry-run | --apply" >&2; exit 2; } + +disk="/dev/nvme0n1" +esp="/boot/efi" +model="${AIENOS_MODEL:-${HOME}/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf}" +pinned_sha=3f5a22426976ab26cfe84dba63c1d08391717abb1af893e10f1b2968d862dcc1 +out="${repo_root}/target/native-kernel-l6c-staging" +lib="${repo_root}/target/infer-kernel/aarch64-unknown-none/release/libaienos_infer_kernel.a" +image="${out}/BOOTAA64.EFI" +map_tool="${out}/host/ck_model_map" +map="${out}/MODEL.MAP" +loader='\EFI\AIENOS\aienos-ck.efi' +label="AIENOS C kernel (one-time)" +recov_entry="0004" +recov_label="AIENOSRECOV" +hold_s=120 +secure_boot_var="/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" +stamp="$(date -u +%Y%m%dT%H%M%SZ)" +evidence_dir="${AIENOS_STAGE_OUT:-${HOME}/workspace/evidence-out/L6C/staging}/${stamp}" + +stops=() +stop() { stops+=("$*"); echo "STOP: $*"; } + +# Print a command; run it only with --apply. +run() { + printf '+' + printf ' %q' "$@" + printf '\n' + [[ "${mode}" == apply ]] || return 0 + "$@" +} + +echo "mode: ${mode}" + +# ---- read-only pre-flight ---- +if [[ -n "$(git status --porcelain)" ]]; then + stop "the checkout has uncommitted changes; the boot must map to one exact commit" +fi +commit="$(git rev-parse HEAD)" +echo "commit: ${commit}" + +[[ -f "${model}" ]] || stop "model file not found: ${model}" +model_dev="$(findmnt -no SOURCE -T "${model}" 2>/dev/null || true)" +model_disk="/dev/$(lsblk -no PKNAME "${model_dev}" 2>/dev/null | head -1)" +echo "model: ${model} on ${model_dev:-?} (disk ${model_disk})" +[[ "${model_disk}" == "${disk}" ]] || stop "the model's filesystem is not a plain partition of ${disk} (got '${model_dev}' on '${model_disk}'): the firmware reads raw LBAs" +echo "model attrs: $(lsattr "${model}" 2>/dev/null | cut -d' ' -f1 || echo '?')" + +esp_dev="$(findmnt -no SOURCE "${esp}" 2>/dev/null || true)" +esp_opts="$(findmnt -no OPTIONS "${esp}" 2>/dev/null || true)" +[[ -n "${esp_dev}" ]] || stop "the ESP is not mounted at ${esp}" +esp_disk="/dev/$(lsblk -no PKNAME "${esp_dev}" 2>/dev/null | head -1)" +esp_part="$(cat "/sys/class/block/$(basename "${esp_dev:-none}")/partition" 2>/dev/null || true)" +echo "esp: ${esp_dev:-?} partition ${esp_part:-?} of ${esp_disk} (${esp_opts%%,*})" +[[ "${esp_disk}" == "${disk}" ]] || stop "the ESP is not on ${disk} (MODEL.MAP is read from the boot volume, the model from ${disk})" +[[ ",${esp_opts}," == *",rw,"* ]] || stop "the ESP is not mounted read-write" + +if [[ -r "${secure_boot_var}" ]] && [[ "$(od -An -t u1 -j 4 -N 1 "${secure_boot_var}" | tr -d ' ')" == "1" ]]; then + stop "Secure Boot is enabled; the firmware will refuse the unsigned C image" +else + echo "secure boot: off or unreadable (recorded only; development decision 2026-10-01)" +fi + +boot_state="$(efibootmgr 2>/dev/null || true)" +[[ -n "${boot_state}" ]] || stop "efibootmgr gave no output" +order_before="$(sed -n 's/^BootOrder: //p' <<<"${boot_state}")" +current_before="$(sed -n 's/^BootCurrent: //p' <<<"${boot_state}")" +next_before="$(sed -n 's/^BootNext: //p' <<<"${boot_state}")" +recov_line="$(grep -E "^Boot${recov_entry}\*? " <<<"${boot_state}" || true)" +echo "BootCurrent: ${current_before}" +echo "BootOrder: ${order_before} (never changed)" +[[ -z "${next_before}" ]] || stop "BootNext is already set (${next_before}); another staging is pending" +if [[ "${recov_line}" == *"${recov_label}"* ]]; then + echo "recovery: Boot${recov_entry} ${recov_label} present (kept untouched)" +else + stop "Boot${recov_entry} ${recov_label} not present: insert the recovery stick and check docs/RECOVERY_MEDIA_MACHINE1.md (got: '${recov_line:-none}')" +fi +existing="$(sed -n "s/^Boot\([0-9A-F]\{4\}\)\*\{0,1\} ${label}.*/\1/p" <<<"${boot_state}" | head -1)" +echo "boot entry: '${label}' ${existing:+exists as Boot${existing}}${existing:-will be created (create-only, not in BootOrder)}" +echo "evidence: ${evidence_dir}" +echo "screen hold: ${hold_s} s before the reset (CK_FB_HOLD_S)" + +if [[ "${mode}" == apply && ${#stops[@]} -gt 0 ]]; then + echo "STOPPED before touching anything: ${#stops[@]} pre-flight problem(s) above." + exit 1 +fi + +echo +echo "commands (--apply runs them in this order; --dry-run only prints them):" + +# ---- 1. build ---- +cross="" +[[ "$(uname -m)" == aarch64 ]] || cross="aarch64-linux-gnu-" +run env CARGO_TARGET_DIR="${repo_root}/target/infer-kernel" cargo build -q --release \ + --target aarch64-unknown-none --manifest-path crates/aienos-infer-kernel/Cargo.toml +run make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="${commit}" \ + CK_INFER_LIB="${lib}" CK_FB_HOLD_S="${hold_s}" +run make -s -C native/kernel OUT="${out}" model-map +if [[ "${mode}" == apply ]]; then + grep -aqF "screen: gop " "${image}" || { echo "STOP: the image has no screen console"; exit 1; } + if grep -aqF "TEST-ONLY stale handoff" "${image}"; then echo "STOP: TEST-only stale handoff image"; exit 1; fi + digest="$(sha256sum "${image}" | cut -d' ' -f1)" + echo "image sha256: ${digest}" +else + digest="(computed after the build)" +fi + +# ---- 2. freeze the model's blocks, then 3. map and check ---- +run sudo chattr +i "${model}" +run sudo "${map_tool}" make "${map}" --file "${model}" --disk "${disk}" --fiemap --part-start auto +run sudo chown "$(id -u):$(id -g)" "${map}" +run sudo "${map_tool}" check "${map}" --disk "${disk}" +run "${map_tool}" show "${map}" +if [[ "${mode}" == apply ]]; then + "${map_tool}" show "${map}" | grep -q "${pinned_sha}" \ + || { echo "STOP: MODEL.MAP does not declare the pinned model hash ${pinned_sha}"; exit 1; } +fi + +# ---- 4. pre-boot capture (BootNext still absent) ---- +run mkdir -p "${evidence_dir}" +run sudo scripts/verify_native_rollback.sh --capture-pre "${evidence_dir}/pre_boot_capture.json" + +# ---- 5. ESP scratch directory \EFI\AIENOS ---- +record="${evidence_dir}/STAGED-CK.TXT" +if [[ "${mode}" == apply ]]; then + cat >"${record}" <>"${record}" +else + echo "+ (only if BootOrder changed: sudo efibootmgr --quiet --bootorder ${order_before})" + echo "+ (check Boot${recov_entry} ${recov_label} still present, else stop before BootNext)" +fi +run sudo install -m 0644 "${record}" "${esp}/EFI/AIENOS/STAGED-CK.TXT" +run sudo efibootmgr --quiet --bootnext "${entry}" + +echo +if [[ "${mode}" == dry ]]; then + if [[ ${#stops[@]} -gt 0 ]]; then + echo "Dry run: nothing touched. --apply would STOP now on ${#stops[@]} pre-flight problem(s) above." + else + echo "Dry run: nothing touched. Pre-flight clean; --apply would stage the boot above." + fi + exit 0 +fi +cat "${record}" +efibootmgr | sed -n '1,4p' +echo "Staged: the next boot runs Boot${entry} once. Nothing was rebooted." +echo "Reboot only with the operator at the machine and the ${recov_label} stick inserted." +echo "After the return to Linux: sudo scripts/verify_native_rollback.sh --capture-post, then sudo chattr -i ${model}." ```