interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / boot / efi_artifact.c

84 lines · 4124 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* efi_artifact.c -- read \EFI\AIENOS\ARTIFACT.BND from the boot volume before ExitBootServices
18 * (EL0 artifact qualification image, CK_ARTIFACT_CARD: the Raspberry Pi 5 image and its QEMU twin).
19 * Nothing is written. The file is a bundle of signed artifacts placed by the run tool
20 * (native/kernel/core/artifact_card.h); it is untrusted input, parsed strictly here and verified by the
21 * core loader later. Result in ck_acard_boot (stub and kernel are one image): ABSENT (no file: the loader
22 * reports no source), REFUSED (printed why), FOUND. Same pattern as efi_agentcmd.c. */
23#include "efi.h"
24#include "../kernel/core/artifact_card.h"
25#include "../kernel/arch/arch.h"
26#include "../kernel/core/ck_internal.h"
27
28static void wipe_buf(void)
29{
30 volatile uint8_t *b = ck_acard_buf;
31 for (unsigned i = 0; i < sizeof ck_acard_buf; i++)
32 b[i] = 0;
33}
34
35void ck_boot_artifact_card_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st)
36{
37 static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT;
38 static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT;
39 static CHAR16 path[] = {'\\', 'E', 'F', 'I', '\\', 'A', 'I', 'E', 'N', 'O', 'S', '\\',
40 'A', 'R', 'T', 'I', 'F', 'A', 'C', 'T', '.', 'B', 'N', 'D', 0};
41 EFI_BOOT_SERVICES *bs = st->BootServices;
42 EFI_LOADED_IMAGE_PROTOCOL *li = 0;
43 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0;
44 EFI_FILE_PROTOCOL *root = 0, *f = 0;
45 ck_acard_boot.state = CK_ACARD_ABSENT;
46 ck_acard_boot.why = "no card artifact bundle (boot volume not readable)";
47 if (bs->HandleProtocol(image, &li_guid, (void **)&li) != EFI_SUCCESS || !li || !li->DeviceHandle ||
48 bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs) != EFI_SUCCESS || !fs ||
49 fs->OpenVolume(fs, &root) != EFI_SUCCESS || !root) {
50 ck_puts("artifact_card: absent (boot volume not readable); no artifact candidates this boot\n");
51 return;
52 }
53 if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) {
54 root->Close(root);
55 ck_acard_boot.why = "no card artifact bundle (file absent)";
56 ck_puts("artifact_card: absent (no " CK_ACARD_PATH "); no artifact candidates this boot\n");
57 return;
58 }
59 wipe_buf();
60 uint64_t n = sizeof ck_acard_buf; /* one byte more than the format allows: a longer file is refused */
61 EFI_STATUS s = f->Read(f, &n, ck_acard_buf);
62 f->Close(f);
63 root->Close(root);
64 ck_acard_boot.state = CK_ACARD_REFUSED;
65 ck_acard_boot.why = "card artifact bundle refused (read failed or size out of range)";
66 if (s != EFI_SUCCESS || n < 1 || n > CK_ACARD_FILE_MAX) {
67 ck_printf("artifact_card: refused (read status=0x%llx bytes=%llu, want 12..%u)\n", (unsigned long long)s,
68 (unsigned long long)n, (unsigned)CK_ACARD_FILE_MAX);
69 wipe_buf();
70 return;
71 }
72 const char *why = 0;
73 if (ck_acard_parse(ck_acard_buf, (size_t)n, &ck_acard_boot.set, &why)) {
74 ck_acard_boot.why = "card artifact bundle refused (malformed)";
75 ck_printf("artifact_card: refused (%s)\n", why ? why : "malformed");
76 wipe_buf();
77 return;
78 }
79 ck_acard_boot.state = CK_ACARD_FOUND;
80 ck_acard_boot.why = 0;
81 ck_acard_boot.file_len = (uint32_t)n;
82 ck_printf("artifact_card: found a well-formed bundle (QUALIFICATION ONLY, TEST keys, %u entries, %u bytes)\n",
83 (unsigned)ck_acard_boot.set.count, (unsigned)n);
84}