summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan M. <ian@aptel.org>2026-09-11 05:14:00 +0000
committerIan M. <ian@aptel.org>2026-09-11 05:14:00 +0000
commit3b895e69140aa265929871217df9d34e40bad3fe (patch)
tree2690ddde952423e4e294f91374615e8369dedfa5
parentff0e017888dbbafd9a29f21b4be0c51494725d5b (diff)
core: file: Get boot volume
Signed-off-by: Ian M. <ian@aptel.org>
-rw-r--r--core/file.c55
-rw-r--r--core/sboot.c9
-rw-r--r--head/sboot/file.h21
3 files changed, 85 insertions, 0 deletions
diff --git a/core/file.c b/core/file.c
new file mode 100644
index 0000000..717e506
--- /dev/null
+++ b/core/file.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <sboot/file.h>
+#include <sboot/fwi.h>
+
+EFI_STATUS
+FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle)
+{
+ EFI_LOADED_IMAGE *LoadedImage = NULL;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *IoVolume;
+ EFI_GUID LipGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
+ EFI_GUID FsGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
+ EFI_FILE_HANDLE Volume;
+ EFI_STATUS Status;
+
+ Status = FwiHandleProtocol(
+ ImageHandle,
+ &LipGuid,
+ (VOID **)&LoadedImage
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: could not get loaded image\n");
+ return Status;
+ }
+
+ Status = FwiHandleProtocol(
+ LoadedImage->DeviceHandle,
+ &FsGuid,
+ (VOID *)&IoVolume
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: could not I/O volume\n");
+ return Status;
+ }
+
+ Status = uefi_call_wrapper(
+ IoVolume->OpenVolume,
+ 2,
+ IoVolume,
+ &Volume
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: failed to get volume\n");
+ return Status;
+ }
+
+ *Handle = Volume;
+ return EFI_SUCCESS;
+}
diff --git a/core/sboot.c b/core/sboot.c
index 1a3d7d1..5511ca4 100644
--- a/core/sboot.c
+++ b/core/sboot.c
@@ -8,12 +8,16 @@
#include <sboot/sboot.h>
#include <sboot/config.h>
#include <sboot/fwi.h>
+#include <sboot/file.h>
+
+EFI_FILE_HANDLE gBootVolume;
EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
BOOT_ENTRY Entry;
+ EFI_STATUS Status;
InitializeLib(ImageHandle, SystemTable);
@@ -25,6 +29,11 @@ efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
NULL
);
+ Status = FileGetVolume(ImageHandle, &gBootVolume);
+ if (EFI_ERROR(Status)) {
+ Hcf();
+ }
+
Print(
L"SBOOT %s - %d boot entrie(s)\n",
SBOOT_VERSION,
diff --git a/head/sboot/file.h b/head/sboot/file.h
new file mode 100644
index 0000000..cdae2bc
--- /dev/null
+++ b/head/sboot/file.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef _SBOOT_FILE_H_
+#define _SBOOT_FILE_H_ 1
+
+#include <efi.h>
+#include <efilib.h>
+
+extern EFI_FILE_HANDLE gBootVolume;
+
+/*
+ * Obtain the boot volume
+ *
+ * @ImageHandle: Image handle
+ */
+EFI_STATUS FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle);
+
+#endif /* !_SBOOT_FILE_H_ */