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/blob/main/native/boot/efi_agentcmd.c # 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 branch `main` Branches Tags History `aienux / native / boot / efi_agentcmd.c` 80 lines ยท 3619 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_agentcmd.c -- read \EFI\AIENOS\AGENT.CMD from the boot volume before ExitBootServices 18 * (Raspberry Pi 5 resident-lifecycle qualification image, CK_PI5_LIFECYCLE). Nothing is written. The file 19 * holds a short list of lifecycle verbs placed by the run tool (native/kernel/core/agent_cmd.h). Result in 20 * ck_agent_cmd_boot (stub and kernel are one image): ABSENT (no file: the lifecycle just stops), REFUSED 21 * (printed why), FOUND. */ 22 #include "efi.h" 23 #include "../kernel/core/agent_cmd.h" 24 #include "../kernel/arch/arch.h" 25 #include "../kernel/core/ck_internal.h" 26 27 static uint8_t buf[CK_AGENT_CMD_FILE_MAX + 1u] __attribute__((aligned(64))); 28 29 static void wipe_buf(void) 30 { 31 volatile uint8_t *b = buf; 32 for (unsigned i = 0; i < sizeof buf; i++) 33 b[i] = 0; 34 } 35 36 void ck_boot_agent_cmd_find(EFI_HANDLE image, EFI_SYSTEM_TABLE *st) 37 { 38 static const EFI_GUID li_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID_INIT; 39 static const EFI_GUID fs_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID_INIT; 40 static CHAR16 path[] = {'\\', 'E', 'F', 'I', '\\', 'A', 'I', 'E', 'N', 'O', 'S', '\\', 41 'A', 'G', 'E', 'N', 'T', '.', 'C', 'M', 'D', 0}; 42 EFI_BOOT_SERVICES *bs = st->BootServices; 43 EFI_LOADED_IMAGE_PROTOCOL *li = 0; 44 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = 0; 45 EFI_FILE_PROTOCOL *root = 0, *f = 0; 46 ck_agent_cmd_boot.state = CK_AGENT_CMD_ABSENT; 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("agent_cmd: absent (boot volume not readable); no command script 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_puts("agent_cmd: absent (no " CK_AGENT_CMD_PATH "); no command script this boot\n"); 56 return; 57 } 58 wipe_buf(); 59 uint64_t n = sizeof buf; /* one byte more than the format allows: a longer file is refused */ 60 EFI_STATUS s = f->Read(f, &n, buf); 61 f->Close(f); 62 root->Close(root); 63 ck_agent_cmd_boot.state = CK_AGENT_CMD_REFUSED; 64 if (s != EFI_SUCCESS || n < 1 || n > CK_AGENT_CMD_FILE_MAX) { 65 ck_printf("agent_cmd: refused (read status=0x%llx bytes=%llu, want 1..%u)\n", (unsigned long long)s, 66 (unsigned long long)n, (unsigned)CK_AGENT_CMD_FILE_MAX); 67 wipe_buf(); 68 return; 69 } 70 const char *why = 0; 71 if (ck_agent_cmd_parse(buf, (size_t)n, &ck_agent_cmd_boot.cmd, &why)) { 72 ck_printf("agent_cmd: refused (%s)\n", why ? why : "malformed"); 73 wipe_buf(); 74 return; 75 } 76 ck_agent_cmd_boot.state = CK_AGENT_CMD_FOUND; 77 ck_printf("agent_cmd: found a well-formed command script (QUALIFICATION ONLY, %u lines)\n", 78 (unsigned)ck_agent_cmd_boot.cmd.nlines); 79 wipe_buf(); 80 }