aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / boot / efi_fact.c
| 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_fact.c -- read \EFI\AIENOS\FACT.REQ from the boot volume before ExitBootServices |
| 18 | * (Raspberry Pi 5 Cortex qualification image, CK_PI5_FACT). Nothing is written. The file holds one short |
| 19 | * fact placed by the run tool (native/kernel/core/fact_req.h). Result in ck_fact_req_boot (stub and |
| 20 | * kernel are one image): ABSENT (no file: boot 2 recalls, not an error), REFUSED (printed why), FOUND. */ |
| 21 | #include "efi.h" |
| 22 | #include "../kernel/core/fact_req.h" |
| 23 | #include "../kernel/arch/arch.h" |
| 24 | #include "../kernel/core/ck_internal.h" |
| 25 | |
| 26 | static uint8_t buf[CK_FACT_REQ_SIZE + 1u] __attribute__((aligned(64))); |
| 27 | |
| 28 | static void wipe_buf(void) |
| 29 | { |
| 30 | volatile uint8_t *b = buf; |
| 31 | for (unsigned i = 0; i < sizeof buf; i++) |
| 32 | b[i] = 0; |
| 33 | } |
| 34 | |
| 35 | void ck_boot_fact_req_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 | 'F', 'A', 'C', 'T', '.', 'R', 'E', 'Q', 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_fact_req_boot.state = CK_FACT_REQ_ABSENT; |
| 46 | if (bs->HandleProtocol(image, &li_guid, (void **)&li) != EFI_SUCCESS || !li || !li->DeviceHandle || |
| 47 | bs->HandleProtocol(li->DeviceHandle, &fs_guid, (void **)&fs) != EFI_SUCCESS || !fs || |
| 48 | fs->OpenVolume(fs, &root) != EFI_SUCCESS || !root) { |
| 49 | ck_puts("fact_req: absent (boot volume not readable); nothing to remember this boot\n"); |
| 50 | return; |
| 51 | } |
| 52 | if (root->Open(root, &f, path, EFI_FILE_MODE_READ, 0) != EFI_SUCCESS || !f) { |
| 53 | root->Close(root); |
| 54 | ck_puts("fact_req: absent (no " CK_FACT_REQ_PATH "); nothing to remember this boot\n"); |
| 55 | return; |
| 56 | } |
| 57 | wipe_buf(); |
| 58 | uint64_t n = sizeof buf; /* one byte more than the format: a longer file is refused */ |
| 59 | EFI_STATUS s = f->Read(f, &n, buf); |
| 60 | f->Close(f); |
| 61 | root->Close(root); |
| 62 | ck_fact_req_boot.state = CK_FACT_REQ_REFUSED; |
| 63 | if (s != EFI_SUCCESS || n != CK_FACT_REQ_SIZE) { |
| 64 | ck_printf("fact_req: refused (read status=0x%llx bytes=%llu, want exactly %u)\n", (unsigned long long)s, |
| 65 | (unsigned long long)n, (unsigned)CK_FACT_REQ_SIZE); |
| 66 | wipe_buf(); |
| 67 | return; |
| 68 | } |
| 69 | const char *why = 0; |
| 70 | if (ck_fact_req_check((const struct ck_fact_req *)buf, &why)) { |
| 71 | ck_printf("fact_req: refused (%s)\n", why ? why : "malformed"); |
| 72 | wipe_buf(); |
| 73 | return; |
| 74 | } |
| 75 | ck_fact_req_store((const struct ck_fact_req *)buf); |
| 76 | wipe_buf(); |
| 77 | ck_puts("fact_req: found a well-formed request file (QUALIFICATION ONLY, one fact to remember)\n"); |
| 78 | } |