Implement BlLoadEfiImage() and BlStartEfiImage() routines
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 29s
Builds / ExectOS (i686) (push) Successful in 27s

This commit is contained in:
2024-01-22 23:04:24 +01:00
parent 6733e092ba
commit 435ee66ce1
4 changed files with 66 additions and 3 deletions

View File

@@ -99,6 +99,36 @@ BlGetSecureBootStatus()
return SecureBootStatus;
}
/**
* Loads an EFI image into memory.
*
* @param DevicePath
* Specifies a device path from which the image is loaded.
*
* @param ImageData
* Supplies a pointer to the memory are containing a copy of the EFI image.
*
* @param ImageSize
* Supplies the size (in bytes) of the EFI image.
*
* @param ImageHandle
* Supplies a pointer to the memory area, where an EFI_image handle will be stored.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlLoadEfiImage(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath,
IN PVOID ImageData,
IN SIZE_T ImageSize,
OUT PEFI_HANDLE ImageHandle)
{
/* Load EFI image */
return EfiSystemTable->BootServices->LoadImage(FALSE, EfiImageHandle, DevicePath, ImageData, ImageSize, ImageHandle);
}
/**
* Reboots the machine.
*
@@ -146,6 +176,23 @@ BlSleepExecution(IN ULONG_PTR Milliseconds)
EfiSystemTable->BootServices->Stall(Milliseconds * 1000);
}
/**
* Executes a loaded EFI image entry point.
*
* @param ImageHandle
* Provides a handle of loaded image, that will be started.
*
* @return This routine returns a status code.
*
* @since XT 1.0
*/
XTCDECL
EFI_STATUS
BlStartEfiImage(IN EFI_HANDLE ImageHandle)
{
return EfiSystemTable->BootServices->StartImage(ImageHandle, NULL, NULL);
}
/**
* Waits for one or more EFI events.
*

View File

@@ -178,6 +178,13 @@ XTCDECL
EFI_STATUS
BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList);
XTCDECL
EFI_STATUS
BlLoadEfiImage(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath,
IN PVOID ImageData,
IN SIZE_T ImageSize,
OUT PEFI_HANDLE ImageHandle);
XTCDECL
EFI_STATUS
BlLoadModule(IN PWCHAR ModuleName);
@@ -289,6 +296,10 @@ XTCDECL
VOID
BlSleepExecution(IN ULONG_PTR Milliseconds);
XTCDECL
EFI_STATUS
BlStartEfiImage(IN EFI_HANDLE ImageHandle);
XTCDECL
VOID
BlStartLoaderShell();

View File

@@ -287,8 +287,7 @@ BlLoadModule(IN PWCHAR ModuleName)
ModuleDevicePath[1].Header.SubType = EFI_END_ENTIRE_DP;
/* Load EFI image */
Status = EfiSystemTable->BootServices->LoadImage(FALSE, EfiImageHandle, (PEFI_DEVICE_PATH_PROTOCOL)ModuleDevicePath,
ModuleData, ModuleSize, &ModuleHandle);
Status = BlLoadEfiImage((PEFI_DEVICE_PATH_PROTOCOL)ModuleDevicePath, ModuleData, ModuleSize, &ModuleHandle);
if(Status != STATUS_EFI_SUCCESS)
{
/* Check if caused by secure boot */
@@ -337,7 +336,7 @@ BlLoadModule(IN PWCHAR ModuleName)
EfiSystemTable->BootServices->CloseProtocol(LoadedImage, &LIPGuid, LoadedImage, NULL);
/* Start EFI image */
Status = EfiSystemTable->BootServices->StartImage(ModuleHandle, NULL, NULL);
Status = BlStartEfiImage(ModuleHandle);
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to start module image */
@@ -651,9 +650,11 @@ BlpInstallXtLoaderProtocol()
BlpLdrProtocol.Tui.UpdateProgressBar = BlUpdateProgressBar;
BlpLdrProtocol.Util.ExitBootServices = BlExitBootServices;
BlpLdrProtocol.Util.GetSecureBootStatus = BlGetSecureBootStatus;
BlpLdrProtocol.Util.LoadEfiImage = BlLoadEfiImage;
BlpLdrProtocol.Util.RebootSystem = BlRebootSystem;
BlpLdrProtocol.Util.ShutdownSystem = BlShutdownSystem;
BlpLdrProtocol.Util.SleepExecution = BlSleepExecution;
BlpLdrProtocol.Util.StartEfiImage = BlStartEfiImage;
BlpLdrProtocol.Util.WaitForEfiEvent = BlWaitForEfiEvent;
/* Register XTLDR loader protocol */