I am writing a UEFI 'chainloader' to learn more about how it works. I am using gnu-efi, and trying to load and start an EFI image. I want my main.efi to load and run hello.efi, located in the same ESP. I just don't understand what to call and how to call it. This is my code:
#include <efi.h> // EFI header
#include <efilib.h> // EFI library header
int DisableTimeout(EFI_SYSTEM_TABLE *SystemTable); // Allows us to call in efi_main
EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
InitializeLib(ImageHandle, SystemTable);
EFI_STATUS Status;
EFI_HANDLE ImageHandle2 = NULL;
const CHAR16 *FileName = L"HELLO.efi";
EFI_DEVICE_PATH_PROTOCOL *FilePath;
uefi_call_wrapper(SystemTable->ConOut->SetAttribute, 1, SystemTable->ConOut, 0x0F); // Set text to white
uefi_call_wrapper(SystemTable->ConOut->ClearScreen, 1, SystemTable->ConOut); // Clear screen
Print(L"Begin boot process.\nBooting from system with ");
Print(SystemTable->FirmwareVendor);
Print(L" firmware.\n");
Status = DisableTimeout(SystemTable); // Pass system table so it can shut off timer
Status = SystemTable->BootServices->LoadImage(TRUE, ImageHandle, FilePath, NULL, 0, &ImageHandle2);
Status = SystemTable->BootServices->StartImage(ImageHandle2, NULL, NULL);
Print(L"Boot complete.\n");
WaitForSingleEvent(SystemTable->ConIn->WaitForKey, 0); // Wait for keypress
return EFI_SUCCESS;
}
The DisableTimeout() is a function I made.
Sorry, I am very new to UEFI development.