diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/file.c | 72 | ||||
| -rw-r--r-- | core/sboot.c | 9 |
2 files changed, 81 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 (;;); } |
