Load other efi file from an efi file
Posted: Sun Dec 18, 2022 4:16 pm
Hello guys,
at the moment i am trying to make a uefi bootloader using gnu-efi and i want to load an other efi file which is located on the same device but in an other directory and give control to it.
My problem is that it says Failed to load the JellyBoot.EFI! Reason: Invalid Parameter. I do not know how to fix this problem i hope anyone can help me.
Source code:
at the moment i am trying to make a uefi bootloader using gnu-efi and i want to load an other efi file which is located on the same device but in an other directory and give control to it.
My problem is that it says Failed to load the JellyBoot.EFI! Reason: Invalid Parameter. I do not know how to fix this problem i hope anyone can help me.
Source code:
Code: Select all
// Import libraries
#include <efi.h>
#include <efilib.h>
EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
// Initialize the UEFI
InitializeLib(ImageHandle, SystemTable);
// Define variables
EFI_STATUS Status;
EFI_HANDLE LoadedImageHandle;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
EFI_DEVICE_PATH *DevicePath;
CHAR16 *FilePath = L"\\EFI\\JellyBoot\\JellyBoot.EFI";
// Get a the loaded image protocol for the current image
LoadedImage = (EFI_LOADED_IMAGE_PROTOCOL *)(ImageHandle);
// Create a device path for the file
DevicePath = FileDevicePath(
LoadedImage->DeviceHandle,
FilePath
);
if(DevicePath == NULL) {
Print(L"Failed to create device path for file!\n");
}
// Load the JellyBoot.EFI into memory
Status = SystemTable->BootServices->LoadImage(
FALSE,
LoadedImage->DeviceHandle,
DevicePath,
NULL,
0,
&LoadedImageHandle
);
if(EFI_ERROR(Status)) {
Print(L"Failed to load the JellyBoot.EFI!\nReason: %r\n", Status);
}
// Start the JellyBoot.EFI and check if it started successfully
Status = SystemTable->BootServices->StartImage(
LoadedImageHandle,
NULL,
NULL
);
if(EFI_ERROR(Status)) {
Print(L"Failed to start the JellyBoot.EFI!\nReason %r\n", Status);
} else {
Print(L"JellyBoot.EFI started successfully!\n");
}
while(1){};
return EFI_SUCCESS;
}