diff options
| author | Ian M. <ian@aptel.org> | 2026-09-11 05:26:15 +0000 |
|---|---|---|
| committer | Ian M. <ian@aptel.org> | 2026-09-11 05:28:59 +0000 |
| commit | d1ae146b1fcecdd6ae688cedf523a5be0d7980c5 (patch) | |
| tree | 8a4fc10f7cd365ee0f6beb3f23fc0145cc426835 /core/file.c | |
| parent | 3b895e69140aa265929871217df9d34e40bad3fe (diff) | |
core: sboot: Read kernel binary
Signed-off-by: Ian M. <ian@aptel.org>
Diffstat (limited to 'core/file.c')
| -rw-r--r-- | core/file.c | 72 |
1 files changed, 72 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; +} |
