diff --git a/.crumb b/.crumb index 760969e9..a8fc2312 100644 --- a/.crumb +++ b/.crumb @@ -22,38 +22,38 @@ "children": [ { "digest": "57ede5c58a883dfec8c7848c2aaaa559fa3c8b38c2a7ecc4db26828e0cbc3e12", - "last_commit": "bf70027", + "last_commit": "74f638c", "name": "crates", "purpose": "Directory crates. Purpose not yet described by a human." }, { "digest": "ff4b451c83c055a494d6598f83241ead8cc7bd43626e37cbadf4bf65ace5b74c", - "last_commit": "2cdd37f", + "last_commit": "74f638c", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "51c89e915314b1fea02b9fcb80f143c3146a4b52d71e090d0575ba89c996b0c1", - "last_commit": "2cdd37f", + "digest": "51dcba9cad880466f1cf88a3335e6524319493b0336adef7a78c848b308dbfba", + "last_commit": "555e6d1", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "8911239203abaca6f5315fecaa93bea68b0b425436b711cce44efeccdf221bdb", - "last_commit": "2cdd37f", + "digest": "28d270da3473f2714195a890c9119ca967eed7eadc9070e0ea06555477937d14", + "last_commit": "555e6d1", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:8ebf3d0c9cced3ed3855fceac4129f30b8431ad8251319ece42d02f460978f89", - "compiled_at": "2026-10-13T00:22:25Z", + "children_root": "sha256:8887900ec3350c15c1e4f6f0fc436329507b9a55c8a1ff95464018e634fcb192", + "compiled_at": "2026-10-13T01:55:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:5b9db016bc8b481e88d2d26cd5de24fc773ae562e43778ec988a886786bc5ac1", + "digest": "sha256:860aa2ba7c8709021f646bd87dc5153fa54d72e60c7924adceab5b7327699bd1", "evidence_files": 156, "evidence_root": "sha256:cd53ab119be9de6ce28c4f5949b106c9622f1fe105611de3de21c3bce7932694", - "files": 3117, - "generated_at_commit": "2cdd37fb844fa0f1cb91fa4e6ad7272f1fac547a", - "source_tree": "sha256:9e08afb48d800441a508ccd930952fef557b882f6e24d94f9d870cbe20546a5e" + "files": 3119, + "generated_at_commit": "555e6d1214f7922f640873cd70a06a0a64fcaade", + "source_tree": "sha256:9768a7a9302cfd544dc3b3d3d7d3c9cb061f86c899a530006838864877eed13b" }, "owner_lane": "", "provenance": { diff --git a/.github/workflows/ck-kernel.yml b/.github/workflows/ck-kernel.yml index 927d87be..2967fac9 100644 --- a/.github/workflows/ck-kernel.yml +++ b/.github/workflows/ck-kernel.yml @@ -107,6 +107,14 @@ jobs: - name: Hardware inference service image make refusals and the supported line (build only, aienos#34 gate N3) run: bash scripts/qemu_ck_service_disk_test.sh --build-only + - name: PI5DIAG.EFI QEMU test (AIENOS-PI5-BOOT-0, firmware diagnostic report read back from the image) + env: + AIENOS_QUIET_FLAG: ${{ runner.temp }}/spark-quiet + AIENOS_GATE_LOCK: ${{ runner.temp }}/qemu-gate-lock + run: | + sudo apt-get install -y mtools + bash scripts/qemu_ck_pi5_diag_test.sh + - name: Check the host tests left the tree clean (the gate runner refuses a dirty tree) run: | git status --porcelain --untracked-files=normal diff --git a/native/.crumb b/native/.crumb index 7eac8fb8..f7e10ad4 100644 --- a/native/.crumb +++ b/native/.crumb @@ -50,74 +50,74 @@ "children": [ { "digest": "7a5972d5e7135c13af527ba7bc91f6532fcebc206df0686e742e98c1050c6c29", - "last_commit": "130aa20", + "last_commit": "74f638c", "name": "argus", "purpose": "Directory native/argus. Purpose not yet described by a human." }, { - "digest": "43c12487524be9f610211b885b936ade7cb7fc907c7afbd37c57cbd517dfea81", - "last_commit": "fe21660", + "digest": "90408bbd282360e0d5c548617cf2a406bf50c9aa90760a008962c246c81594be", + "last_commit": "555e6d1", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, { "digest": "aaee52694510c1aea1e16ffd54201ce8e900742974d538bbf4640ab01d239872", - "last_commit": "51c05da", + "last_commit": "74f638c", "name": "capability", "purpose": "Directory native/capability. Purpose not yet described by a human." }, { "digest": "44513be407ed44a29feac97bfec222e968f9f6415631f0cd62dc65a522c420e4", - "last_commit": "a4bba0c", + "last_commit": "74f638c", "name": "crypto", "purpose": "Directory native/crypto. Purpose not yet described by a human." }, { "digest": "31584482d53c2b82d89a44a8a12f67c7f808f740d95ad5ad050b58bcca6b47aa", - "last_commit": "2f9b95a", + "last_commit": "74f638c", "name": "disk", "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "9ac3378c865ea4bfbf2380a6e9cb5dea03264870381bf314e96ce62c99e20a38", - "last_commit": "04e39e7", + "digest": "378c7c0c28b51193fbfaa4f52fa5477b8653296f0868f0978a4079fe264b53ae", + "last_commit": "555e6d1", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, { "digest": "3883ad91cdafdb9158b14c4d8b11d4dcbfe1205ad8071c988b8f7c4b959a4004", - "last_commit": "1feaca1", + "last_commit": "74f638c", "name": "m5", "purpose": "Directory native/m5. Purpose not yet described by a human." }, { "digest": "c91e9201f6ce9cb909ce3fadfa60d4869fc661db8d4266cd2c15e0688d384cf7", - "last_commit": "4a116e5", + "last_commit": "74f638c", "name": "net", "purpose": "Directory native/net. Purpose not yet described by a human." }, { "digest": "295150763e0b19f9f74a3b49d679213467075e9682f1f23d0e5ea838872d20e1", - "last_commit": "cea54be", + "last_commit": "74f638c", "name": "sig", "purpose": "Directory native/sig. Purpose not yet described by a human." }, { "digest": "eeec17e754d15d5723d77d953711620c568c160f47e6c90a4c927c85ec5bb32d", - "last_commit": "22eb360", + "last_commit": "74f638c", "name": "store", "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:7231f6ca9214a6886e126014dbd82c37be36c7e5ddf884ab0321cdc04c8650bd", - "compiled_at": "2026-10-12T20:56:51Z", + "children_root": "sha256:169d12bbb10d00df758e72ed9b819b68fd768bd11ccd46d79c031ac1c106aae4", + "compiled_at": "2026-10-13T01:55:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:51c89e915314b1fea02b9fcb80f143c3146a4b52d71e090d0575ba89c996b0c1", + "digest": "sha256:51dcba9cad880466f1cf88a3335e6524319493b0336adef7a78c848b308dbfba", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", - "files": 488, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:198cec669d0d505617ff5b4c423c4296ded1081ee2e1e2e0abdc88fa5c0f154d" + "files": 489, + "generated_at_commit": "555e6d1214f7922f640873cd70a06a0a64fcaade", + "source_tree": "sha256:153900796c2fa29ff664ec8cc01f40deff76d2c4210d1d6d4574f0fa9ce11359" }, "owner_lane": "", "provenance": { diff --git a/native/boot/.crumb b/native/boot/.crumb index fcebea11..fd4a1312 100644 --- a/native/boot/.crumb +++ b/native/boot/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T01:55:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:43c12487524be9f610211b885b936ade7cb7fc907c7afbd37c57cbd517dfea81", + "digest": "sha256:90408bbd282360e0d5c548617cf2a406bf50c9aa90760a008962c246c81594be", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 16, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:e871c0a19ada2f9543ed55c0455a103d92dc66cc32564dd59abd6bc7341dc617" + "files": 17, + "generated_at_commit": "555e6d1214f7922f640873cd70a06a0a64fcaade", + "source_tree": "sha256:378c422ef8696e0fc855d356d4d1b1376f3f8cc7f6e91d9e8242ee97ef7bc54b" }, "owner_lane": "", "provenance": { diff --git a/native/boot/README.md b/native/boot/README.md index 7516e1ca..7c005d69 100644 --- a/native/boot/README.md +++ b/native/boot/README.md @@ -31,6 +31,17 @@ touches UEFI variables, runtime services or `ExitBootServices`. Build: `scripts/qemu_ck_slot_loader_test.sh`; `docs/NATIVE_IMAGE_SLOTS.md`. This stub itself still has no slot logic, so the paragraph below stays true for it. +**AIENOS-PI5-BOOT-0 diagnostic, `diag_main.c` -> `PI5DIAG.EFI`:** a separate, +kernel-free UEFI application for the first Raspberry Pi 5 firmware boot. It +prints the firmware vendor and revisions, the exception level, a memory map +summary and every ConfigurationTable GUID (ACPI 1.0/2.0, SMBIOS, SMBIOS3, Device +Tree b1b621d5-f19c-41a5-830b-d9152c69aae0, per edk2 `Guid/Fdt.h`) to ConOut, writes +the same text to `\EFI\AIENOS\PI5BOOT0.TXT` on the volume it was loaded from, +waits about 10 s and returns `EFI_SUCCESS`. It never calls `ExitBootServices`. +Build: `make -C native/kernel pi5-diag` (output `PI5DIAG.EFI`, copy to the card as +`EFI/BOOT/BOOTAA64.EFI`); QEMU test: `scripts/qemu_ck_pi5_diag_test.sh` +(`AIENOS_PI5_DIAG`; an emulator, nothing about a Pi 5 is qualified by it). + **Parked, not here:** signature checks, BootNext staging, rollback and the boot-report file. The Rust `aienos-boot` crate has BootNext staging and a QEMU rollback test but no A/B slot selection (ADR 0024 Q3); it is frozen and diff --git a/native/boot/diag_main.c b/native/boot/diag_main.c new file mode 100644 index 00000000..a95c712a --- /dev/null +++ b/native/boot/diag_main.c @@ -0,0 +1,194 @@ +/* diag_main.c -- AIENOS-PI5-BOOT-0: a minimal AArch64 UEFI diagnostic. + * + * Prints what the firmware tells an application (vendor, revisions, EL, memory + * map summary, every ConfigurationTable GUID) to ConOut and to a buffer, writes + * the buffer to \EFI\AIENOS\PI5BOOT0.TXT on the volume the image was loaded + * from, waits ~10 s so a person can read the screen, and returns EFI_SUCCESS. + * It links no kernel and never calls ExitBootServices. Built as PI5DIAG.EFI + * (make -C native/kernel pi5-diag); on the card it is EFI/BOOT/BOOTAA64.EFI. + * Test: scripts/qemu_ck_pi5_diag_test.sh. */ +#include +#include +#include "efi.h" +#include "../kernel/core/fmt.h" + +#define REPORT_BYTES 16384 +#define MAP_BYTES (64u << 10) +#define LINE_BYTES 256 + +static EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout; +static char report[REPORT_BYTES]; +static size_t report_len; +static uint64_t map_buf[MAP_BYTES / 8]; + +struct line { + char b[LINE_BYTES]; + size_t n; +}; + +static void line_emit(void *ctx, char c) +{ + struct line *l = ctx; + if (l->n < sizeof l->b - 1) + l->b[l->n++] = c; +} + +/* Format one line, print it on ConOut (CRLF) and append it (LF) to the report. */ +static void say(const char *fmt, ...) __attribute__((format(printf, 1, 2))); +static void say(const char *fmt, ...) +{ + struct line l; + CHAR16 w[2 * LINE_BYTES + 1]; + size_t k = 0; + va_list ap; + l.n = 0; + va_start(ap, fmt); + ck_vformat(line_emit, &l, fmt, ap); + va_end(ap); + for (size_t i = 0; i < l.n; i++) { + if (l.b[i] == '\n') + w[k++] = '\r'; + w[k++] = (uint8_t)l.b[i]; + if (report_len < sizeof report) + report[report_len++] = l.b[i]; + } + w[k] = 0; + if (conout) + conout->OutputString(conout, w); +} + +struct named_guid { + EFI_GUID g; + const char *name; +}; + +/* Values from edk2 MdePkg/Include/Guid/{Acpi.h,SmBios.h,Fdt.h}. */ +static const struct named_guid known[] = { + {{0xeb9d2d30, 0x2d88, 0x11d3, {0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}, "ACPI 1.0"}, + {{0x8868e871, 0xe4f1, 0x11d3, {0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81}}, "ACPI 2.0"}, + {{0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}, "SMBIOS"}, + {{0xf2fd1544, 0x9794, 0x4a2c, {0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94}}, "SMBIOS3"}, + {{0xb1b621d5, 0xf19c, 0x41a5, {0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0}}, "Device Tree"}, +}; + +static const char *guid_name(const EFI_GUID *g) +{ + for (size_t i = 0; i < sizeof known / sizeof known[0]; i++) + if (memcmp(g, &known[i].g, sizeof *g) == 0) + return known[i].name; + return "unknown"; +} + +static void narrow(char *out, size_t cap, const CHAR16 *v) +{ + size_t i = 0; + for (; v && v[i] && i < cap - 1; i++) + out[i] = v[i] < 0x80 ? (char)v[i] : '?'; + out[i] = 0; +} + +static CHAR16 *wide(CHAR16 *out, const char *s) +{ + size_t i = 0; + for (; s[i]; i++) + out[i] = (uint8_t)s[i]; + out[i] = 0; + return out; +} + +static void memory_summary(EFI_BOOT_SERVICES *bs) +{ + uint64_t size = sizeof map_buf, key = 0, dsize = 0, conv = 0; + uint32_t dver = 0; + EFI_STATUS s = bs->GetMemoryMap(&size, (EFI_MEMORY_DESCRIPTOR *)map_buf, &key, &dsize, &dver); + if (s != EFI_SUCCESS || dsize < sizeof(EFI_MEMORY_DESCRIPTOR)) { + say("memory_map: GetMemoryMap failed status=0x%llx\n", (unsigned long long)s); + return; + } + uint64_t n = size / dsize; + for (uint64_t i = 0; i < n; i++) { + const EFI_MEMORY_DESCRIPTOR *d = (const void *)((const uint8_t *)map_buf + i * dsize); + if (d->Type == EfiConventionalMemory) + conv += d->NumberOfPages; + } + say("memory_map: entries=%llu conventional_mib=%llu map_key=0x%llx\n", (unsigned long long)n, + (unsigned long long)(conv >> 8), (unsigned long long)key); /* 256 pages of 4 KiB per MiB */ +} + +static EFI_STATUS write_report(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) +{ + static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT; + static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT; + EFI_BOOT_SERVICES *bs = st->BootServices; + EFI_LOADED_IMAGE_PROTOCOL *li = 0; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0; + EFI_FILE_PROTOCOL *root = 0, *dir = 0, *f = 0; + CHAR16 w[32]; + EFI_STATUS s = bs->HandleProtocol(image, &li_guid, (void **)&li); + if (s != EFI_SUCCESS) + return s; + s = bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs); + if (s != EFI_SUCCESS) + return s; + s = fs->OpenVolume(fs, &root); + if (s != EFI_SUCCESS) + return s; + const uint64_t rw = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE; + /* Opening an existing directory with CREATE returns it. */ + s = root->Open(root, &dir, wide(w, "\\EFI\\AIENOS"), rw | EFI_FILE_MODE_CREATE, EFI_FILE_DIRECTORY); + root->Close(root); + if (s != EFI_SUCCESS) + return s; + /* A stale report is deleted first so the file holds exactly this run. */ + if (dir->Open(dir, &f, wide(w, "PI5BOOT0.TXT"), rw, 0) == EFI_SUCCESS) + f->Delete(f); + f = 0; + s = dir->Open(dir, &f, wide(w, "PI5BOOT0.TXT"), rw | EFI_FILE_MODE_CREATE, 0); + if (s == EFI_SUCCESS) { + uint64_t n = report_len; + s = f->Write(f, &n, report); + if (s == EFI_SUCCESS && n != report_len) + s = EFI_DEVICE_ERROR; + if (s == EFI_SUCCESS) + s = f->Flush(f); + f->Close(f); + } + dir->Close(dir); + return s; +} + +EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) +{ + EFI_BOOT_SERVICES *bs = st->BootServices; + char vendor[80]; + uint64_t el; + conout = st->ConOut; + if (bs->SetWatchdogTimer) + bs->SetWatchdogTimer(0, 0, 0, 0); + __asm__ volatile("mrs %0, CurrentEL" : "=r"(el)); + + say("AIENOS-PI5-BOOT-0\n"); + narrow(vendor, sizeof vendor, st->FirmwareVendor); + say("firmware_vendor: %s\n", vendor); + say("firmware_revision: 0x%x\n", st->FirmwareRevision); + say("uefi_spec_revision: %u.%u\n", st->Hdr.Revision >> 16, st->Hdr.Revision & 0xffff); + say("current_el: EL%u\n", (unsigned)((el >> 2) & 3)); + memory_summary(bs); + say("config_tables: %llu\n", (unsigned long long)st->NumberOfTableEntries); + for (uint64_t i = 0; i < st->NumberOfTableEntries; i++) { + const EFI_GUID *g = &st->ConfigurationTable[i].VendorGuid; + say("table %llu: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x %s at 0x%llx\n", + (unsigned long long)i, g->d1, g->d2, g->d3, g->d4[0], g->d4[1], g->d4[2], g->d4[3], + g->d4[4], g->d4[5], g->d4[6], g->d4[7], guid_name(g), + (unsigned long long)(uintptr_t)st->ConfigurationTable[i].VendorTable); + } + + say("AIENOS-PI5-BOOT-0 DONE\n"); /* last line of the file; the write result below is console only */ + EFI_STATUS s = write_report(image, st); + if (s == EFI_SUCCESS) + say("report_file: written \\EFI\\AIENOS\\PI5BOOT0.TXT (%llu bytes)\n", (unsigned long long)report_len); + else + say("report_file: write FAILED status=0x%llx\n", (unsigned long long)s); + bs->Stall(10ull * 1000 * 1000); + return EFI_SUCCESS; +} diff --git a/native/boot/efi.h b/native/boot/efi.h index b10861f9..dbeb4d06 100644 --- a/native/boot/efi.h +++ b/native/boot/efi.h @@ -82,7 +82,8 @@ typedef struct { void *InstallConfigurationTable; void *LoadImage, *StartImage, *Exit, *UnloadImage; EFI_STATUS (*ExitBootServices)(EFI_HANDLE ImageHandle, uint64_t MapKey); - void *GetNextMonotonicCount, *Stall; + void *GetNextMonotonicCount; + EFI_STATUS (*Stall)(uint64_t Microseconds); EFI_STATUS (*SetWatchdogTimer)(uint64_t Timeout, uint64_t WatchdogCode, uint64_t DataSize, CHAR16 *WatchdogData); void *ConnectController, *DisconnectController; @@ -153,14 +154,19 @@ _Static_assert(offsetof(EFI_LOADED_IMAGE_PROTOCOL, DeviceHandle) == 0x18, "Devic #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT \ { 0x964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } } #define EFI_FILE_MODE_READ 0x0000000000000001ull +#define EFI_FILE_MODE_WRITE 0x0000000000000002ull +#define EFI_FILE_MODE_CREATE 0x8000000000000000ull +#define EFI_FILE_DIRECTORY 0x0000000000000010ull typedef struct EFI_FILE_PROTOCOL { uint64_t Revision; EFI_STATUS (*Open)(struct EFI_FILE_PROTOCOL *This, struct EFI_FILE_PROTOCOL **NewHandle, CHAR16 *FileName, uint64_t OpenMode, uint64_t Attributes); EFI_STATUS (*Close)(struct EFI_FILE_PROTOCOL *This); - void *Delete; + EFI_STATUS (*Delete)(struct EFI_FILE_PROTOCOL *This); EFI_STATUS (*Read)(struct EFI_FILE_PROTOCOL *This, uint64_t *BufferSize, void *Buffer); - void *Write, *GetPosition, *SetPosition, *GetInfo, *SetInfo, *Flush; + EFI_STATUS (*Write)(struct EFI_FILE_PROTOCOL *This, uint64_t *BufferSize, const void *Buffer); + void *GetPosition, *SetPosition, *GetInfo, *SetInfo; + EFI_STATUS (*Flush)(struct EFI_FILE_PROTOCOL *This); void *OpenEx, *ReadEx, *WriteEx, *FlushEx; } EFI_FILE_PROTOCOL; typedef struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL { @@ -168,6 +174,9 @@ typedef struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL { EFI_STATUS (*OpenVolume)(struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, EFI_FILE_PROTOCOL **Root); } EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; _Static_assert(offsetof(EFI_FILE_PROTOCOL, Read) == 0x20, "File.Read"); +_Static_assert(offsetof(EFI_FILE_PROTOCOL, Write) == 0x28, "File.Write"); +_Static_assert(offsetof(EFI_FILE_PROTOCOL, Flush) == 0x50, "File.Flush"); +_Static_assert(offsetof(EFI_BOOT_SERVICES, Stall) == 0xf8, "Stall"); /* --- Block I/O (UEFI 2.10 section 13.9) --- */ #define EFI_BLOCK_IO_PROTOCOL_GUID_INIT \ diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 2d675871..9ed3c3d5 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -46,68 +46,68 @@ "children": [ { "digest": "4c9da3fdaf762c784403ae3281c3a7e49b891596ed52ab27aaf62f2ea66c5502", - "last_commit": "2ee61b4", + "last_commit": "74f638c", "name": "arch", "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, { "digest": "90a737e620d9c654ae347aae26b4635b55477d4ef45c68ac10e983019f6af11c", - "last_commit": "827e20f", + "last_commit": "74f638c", "name": "artifact", "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { "digest": "5f5def88e2ef4bbd425e833cecb75d7cc805e7516a5128a88a7dea4e9b87cdd9", - "last_commit": "fe21660", + "last_commit": "74f638c", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "d7b81a8f888e7b4ca5337a5c9279671c33e1f4a70a7318ed20e1c5367c8a289b", - "last_commit": "fe21660", + "last_commit": "74f638c", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { "digest": "283a167327166bcfd270869cc04a1a03ea21366248471464db7ef1cf37058ada", - "last_commit": "3647654", + "last_commit": "74f638c", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { "digest": "8252fab960e4a3bb686f2e864b0d9a0571f43381d5006de2ff6c134c132ef092", - "last_commit": "2bc7146", + "last_commit": "74f638c", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { "digest": "f2ef5ffe9eae8f9119dd302b55989b8b50f68def6ad03a2db227e28dbd270ddd", - "last_commit": "fe21660", + "last_commit": "74f638c", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "515f5d05394be70d66a845c3d5f2aecdd11e5402c189aefeb817577857ad0118", - "last_commit": "fe21660", + "last_commit": "74f638c", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "e17d2e0716b7121a785c5db6d437ecce7061b40741c97b4859cdc3021878646e", - "last_commit": "fe21660", + "last_commit": "74f638c", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], "children_root": "sha256:6e029b6ca56fd468865463b2676ec83380dc39ac2541d45078cfb2e1e35f0669", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T01:55:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:9ac3378c865ea4bfbf2380a6e9cb5dea03264870381bf314e96ce62c99e20a38", + "digest": "sha256:378c7c0c28b51193fbfaa4f52fa5477b8653296f0868f0978a4079fe264b53ae", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 317, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:b484dc98127db90feb47194f1193e42c42ee4030295558feab5d995f5fe3645f" + "generated_at_commit": "555e6d1214f7922f640873cd70a06a0a64fcaade", + "source_tree": "sha256:1a08e5fa84f1588acb5955ac65d6fbdfb2a2e1fe2c40eb5d2b0ce43207adb149" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/Makefile b/native/kernel/Makefile index 7f180e17..af8d1a91 100644 --- a/native/kernel/Makefile +++ b/native/kernel/Makefile @@ -1728,6 +1728,37 @@ slot-loader-check: done @echo "SLOT_LOADER_BUILD: PASS (TEST-key and owner-key loaders built; TEST key refused with hardware staging)" +# ---- PI5DIAG.EFI: AIENOS-PI5-BOOT-0, the Raspberry Pi 5 firmware diagnostic ---- +# native/boot/diag_main.c: a UEFI application that reports what the firmware shows +# (ConOut + \EFI\AIENOS\PI5BOOT0.TXT) and returns. Own object list, no kernel, no +# ExitBootServices (checked). Copy to the card as EFI/BOOT/BOOTAA64.EFI. +# make pi5-diag -> $(OUT)/PI5DIAG.EFI QEMU test: scripts/qemu_ck_pi5_diag_test.sh +PI5DIAG_DIR := $(OUT)/pi5diag +PI5DIAG_ELF := $(PI5DIAG_DIR)/pi5diag.elf +PI5DIAG_EFI := $(OUT)/PI5DIAG.EFI +PI5DIAG_OBJS := $(PI5DIAG_DIR)/diag_main.o $(PI5DIAG_DIR)/efi_entry.o $(PI5DIAG_DIR)/fmt.o $(PI5DIAG_DIR)/libc_min.o +$(PI5DIAG_DIR)/diag_main.o: $(BOOT)/diag_main.c $(BOOT)/efi.h $(KDIR)/core/fmt.h + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) -c -o $@ $< +$(PI5DIAG_DIR)/efi_entry.o: $(BOOT)/efi_entry.S + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) -c -o $@ $< +$(PI5DIAG_DIR)/fmt.o: $(KDIR)/core/fmt.c $(KDIR)/core/fmt.h + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) -c -o $@ $< +$(PI5DIAG_DIR)/libc_min.o: $(KDIR)/core/libc_min.c + @mkdir -p $(dir $@) + $(KCC) $(KCFLAGS) -c -o $@ $< +$(PI5DIAG_ELF): $(PI5DIAG_OBJS) $(BOOT)/image.ld + @if grep -nE -- '->(ExitBootServices|RuntimeServices)' $(BOOT)/diag_main.c; then \ + echo "diag_main.c calls a service the diagnostic must never call"; exit 1; fi + $(call link_image,$@,$(PI5DIAG_OBJS)) + @k=$$($(KNM) $@ | grep -E ' [TtDdBbRr] (ck_kernel_entry|kmain|ck_boot_model_load|ck_printf)$$' || true); \ + if [ -n "$$k" ]; then echo "PI5DIAG links kernel objects: $$k"; rm -f $@; exit 1; fi +$(PI5DIAG_EFI): $(PI5DIAG_ELF) + $(call pe_image,$<,$@) +pi5-diag: $(PI5DIAG_EFI) + # ---- 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 @@ -1764,5 +1795,5 @@ clean: rm -rf $(OUT) FORCE: -.PHONY: uefi-vars slot-loader slot-loader-check +.PHONY: uefi-vars slot-loader slot-loader-check pi5-diag .PHONY: all full test sanitize handoff-mutant acpi-dev-mutant iort-mutants smmu-l2-mutants acpi-scan clean print-kcflags udp-echo tool store-image gpt-image cont-tool owner-gen fb-check continuity-mutants continuity-resolve-mutants FORCE diff --git a/scripts/.crumb b/scripts/.crumb index 2baf8eb4..9f0aea9d 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-12T20:56:51Z", + "compiled_at": "2026-10-13T01:55:27Z", "compiler": "crumb-compile/1", - "digest": "sha256:8911239203abaca6f5315fecaa93bea68b0b425436b711cce44efeccdf221bdb", + "digest": "sha256:28d270da3473f2714195a890c9119ca967eed7eadc9070e0ea06555477937d14", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 89, - "generated_at_commit": "04e39e7223149deef6c14e4175d40e80c63eee0a", - "source_tree": "sha256:d5c133e26d231b6fe0ac6e1021cec05c81407d981eefcafe916e9d067ce16918" + "files": 90, + "generated_at_commit": "555e6d1214f7922f640873cd70a06a0a64fcaade", + "source_tree": "sha256:ef703dfd9de89381c148434f2e2826c9fc15f703e800297a9edd660e086371a0" }, "owner_lane": "", "provenance": { diff --git a/scripts/qemu_ck_pi5_diag_test.sh b/scripts/qemu_ck_pi5_diag_test.sh new file mode 100755 index 00000000..cd01da92 --- /dev/null +++ b/scripts/qemu_ck_pi5_diag_test.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +# qemu_ck_pi5_diag_test.sh -- QEMU test for PI5DIAG.EFI (AIENOS-PI5-BOOT-0, +# native/boot/diag_main.c). QEMU is an emulator: a PASS here qualifies nothing +# about a Raspberry Pi 5. +# +# Builds PI5DIAG.EFI, puts it on a FAT image as EFI/BOOT/BOOTAA64.EFI, boots it in +# QEMU AArch64 with AAVMF, waits for "AIENOS-PI5-BOOT-0 DONE" on the serial log, +# stops QEMU, reads \EFI\AIENOS\PI5BOOT0.TXT back out of the image with mtools and +# checks: the title and vendor lines, a firmware table line (ACPI or Device Tree), +# the memory summary, "DONE", and that the app wrote the file (serial says so). +# Needs qemu-system-aarch64, AAVMF, mtools. Final line: +# AIENOS_PI5_DIAG: PASS|FAIL|NOT_RUN [(...)] exit 0 / 1 / 2 (tools) / 3 (NOT_RUN) +set -euo pipefail +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${repo_root}" +tag="AIENOS_PI5_DIAG" +code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" +vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" +for t in qemu-system-aarch64 mformat mmd mcopy; do + command -v "${t}" >/dev/null || { echo "${tag}: NOT_RUN (${t} missing)"; exit 2; } +done +[[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "${tag}: NOT_RUN (no AAVMF)"; exit 2; } +cross="" +if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi +out="${PI5DIAG_OUT:-${repo_root}/target/native-kernel-pi5-diag}" +make -s -C native/kernel CROSS="${cross}" OUT="${out}" AIENOS_COMMIT="$(git rev-parse HEAD 2>/dev/null || echo unknown)" pi5-diag >/dev/null + +. "${repo_root}/scripts/lib_gate_hold.sh" +if ! gh_quiet_check || ! gh_lock_take qemu_ck_pi5_diag_test "${AIENOS_GATE_MINUTES:-60}"; then + echo "${tag}: NOT_RUN (${gh_why})" + exit 3 +fi +work="$(mktemp -d)" +cleanup() { + [[ -z "${qpid:-}" ]] || kill "${qpid}" 2>/dev/null || true + rm -rf "${work}" + gh_lock_release +} +trap cleanup EXIT + +img="${work}/esp.img" +truncate -s 64M "${img}" +mformat -i "${img}" -F :: +mmd -i "${img}" ::/EFI ::/EFI/BOOT +mcopy -i "${img}" "${out}/PI5DIAG.EFI" ::/EFI/BOOT/BOOTAA64.EFI +cp "${vars_fd}" "${work}/vars.fd" +qemu-system-aarch64 -M virt -accel tcg -cpu max -m 1024 \ + -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ + -drive if=pflash,format=raw,file="${work}/vars.fd" \ + -drive if=none,id=esp,format=raw,file="${img}" -device virtio-blk-pci,drive=esp \ + -display none -nic none -serial file:"${work}/serial.log" -no-reboot & +qpid=$! +done_seen=0 +for _ in $(seq 1 ${AIENOS_PI5_DIAG_WAIT:-240}); do + if grep -aq "AIENOS-PI5-BOOT-0 DONE" "${work}/serial.log" 2>/dev/null; then done_seen=1; break; fi + kill -0 "${qpid}" 2>/dev/null || break + sleep 1 +done +kill "${qpid}" 2>/dev/null || true +wait "${qpid}" 2>/dev/null || true +qpid="" + +fails=0 +chk() { # description, file, pattern + if grep -aqE -- "$3" "$2"; then echo "PASS $1"; else echo "FAIL $1 (no match for: $3)"; fails=$((fails + 1)); fi +} +tr -d '\r' <"${work}/serial.log" >"${work}/serial.txt" 2>/dev/null || : >"${work}/serial.txt" +[[ ${done_seen} == 1 ]] || { echo "FAIL serial never showed DONE"; fails=$((fails + 1)); } +chk "serial: report_file written" "${work}/serial.txt" '^report_file: written ' +if mcopy -i "${img}" ::/EFI/AIENOS/PI5BOOT0.TXT "${work}/PI5BOOT0.TXT" 2>/dev/null; then + echo "PASS PI5BOOT0.TXT read back from the image" + chk "file: title" "${work}/PI5BOOT0.TXT" '^AIENOS-PI5-BOOT-0$' + chk "file: vendor line" "${work}/PI5BOOT0.TXT" '^firmware_vendor: .+' + chk "file: UEFI spec revision" "${work}/PI5BOOT0.TXT" '^uefi_spec_revision: [0-9]+\.[0-9]+$' + chk "file: current EL" "${work}/PI5BOOT0.TXT" '^current_el: EL[0-3]$' + chk "file: memory summary" "${work}/PI5BOOT0.TXT" '^memory_map: entries=[0-9]+ conventional_mib=[0-9]+ map_key=0x[0-9a-f]+$' + chk "file: ACPI or Device Tree table line" "${work}/PI5BOOT0.TXT" '^table [0-9]+: .* (ACPI 1\.0|ACPI 2\.0|Device Tree) at 0x' + chk "file: DONE" "${work}/PI5BOOT0.TXT" '^AIENOS-PI5-BOOT-0 DONE$' + echo "---- PI5BOOT0.TXT ----"; cat "${work}/PI5BOOT0.TXT"; echo "----" +else + echo "FAIL PI5BOOT0.TXT not found in the image"; fails=$((fails + 1)) +fi +if [[ ${fails} == 0 ]]; then echo "${tag}: PASS"; exit 0; fi +echo "${tag}: FAIL (${fails} checks)"; exit 1