summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan M. <ian@aptel.org>2026-09-11 05:26:15 +0000
committerIan M. <ian@aptel.org>2026-09-11 05:28:59 +0000
commitd1ae146b1fcecdd6ae688cedf523a5be0d7980c5 (patch)
tree8a4fc10f7cd365ee0f6beb3f23fc0145cc426835
parent3b895e69140aa265929871217df9d34e40bad3fe (diff)
core: sboot: Read kernel binary
Signed-off-by: Ian M. <ian@aptel.org>
-rw-r--r--core/file.c72
-rw-r--r--core/sboot.c9
-rw-r--r--head/sboot/file.h5
3 files changed, 86 insertions, 0 deletions
diff --git a/core/file.c b/core/file.c
index 717e506..9ad1fd8 100644
--- a/core/file.c
+++ b/core/file.c
@@ -6,6 +6,18 @@
#include <sboot/file.h>
#include <sboot/fwi.h>
+static UINT64
+FileSize(EFI_FILE_HANDLE FileHandle)
+{
+ EFI_FILE_INFO *FileInfo;
+ UINT64 Size;
+
+ FileInfo = LibFileInfo(FileHandle);
+ Size = FileInfo->FileSize;
+ FreePool(FileInfo);
+ return Size;
+}
+
EFI_STATUS
FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle)
{
@@ -53,3 +65,63 @@ FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle)
*Handle = Volume;
return EFI_SUCCESS;
}
+
+EFI_STATUS
+FileReadToBuffer(IN CHAR16 *FileName, OUT VOID **Buffer)
+{
+ EFI_FILE_HANDLE Handle;
+ EFI_STATUS Status;
+ UINT64 ReadSize;
+ UINT8 *DataBuffer;
+
+ Status = uefi_call_wrapper(
+ gBootVolume->Open,
+ 5,
+ gBootVolume,
+ &Handle,
+ FileName,
+ EFI_FILE_MODE_READ,
+ EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: could not open %s\n", FileName);
+ return Status;
+ }
+
+ ReadSize = FileSize(Handle);
+ Status = uefi_call_wrapper(
+ gBS->AllocatePool,
+ 3,
+ EfiLoaderData,
+ ReadSize,
+ &DataBuffer
+ );
+
+ if (EFI_ERROR(Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = uefi_call_wrapper(
+ Handle->Read,
+ 3,
+ Handle,
+ &ReadSize,
+ DataBuffer
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"fatal: could not read %s\n", FileName);
+ FreePool(DataBuffer);
+ return Status;
+ }
+
+ uefi_call_wrapper(
+ Handle->Close,
+ 1,
+ Handle
+ );
+
+ *Buffer = DataBuffer;
+ return EFI_SUCCESS;
+}
diff --git a/core/sboot.c b/core/sboot.c
index 5511ca4..604c768 100644
--- a/core/sboot.c
+++ b/core/sboot.c
@@ -10,6 +10,10 @@
#include <sboot/fwi.h>
#include <sboot/file.h>
+/* Private globals */
+static UINT8 *KernelBin = NULL;
+
+/* Globals */
EFI_FILE_HANDLE gBootVolume;
EFI_STATUS
@@ -41,5 +45,10 @@ efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
);
SBootMenu(&Entry);
+ Status = FileReadToBuffer(Entry.BootPath, (VOID **)&KernelBin);
+ if (EFI_ERROR(Status)) {
+ Hcf();
+ }
+
for (;;);
}
diff --git a/head/sboot/file.h b/head/sboot/file.h
index cdae2bc..44e8fbb 100644
--- a/head/sboot/file.h
+++ b/head/sboot/file.h
@@ -18,4 +18,9 @@ extern EFI_FILE_HANDLE gBootVolume;
*/
EFI_STATUS FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle);
+/*
+ * Read a file into a buffer.
+ */
+EFI_STATUS FileReadToBuffer(IN CHAR16 *FileName, OUT VOID **Buffer);
+
#endif /* !_SBOOT_FILE_H_ */