Add support for boot protocols
This commit is contained in:
@@ -143,7 +143,8 @@ BlpInitializeEfiBootLoader()
|
||||
/* Print XTLDR version */
|
||||
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
||||
|
||||
/* Initialize XTLDR configuration and loaded modules lists */
|
||||
/* Initialize XTLDR configuration linked lists */
|
||||
RtlInitializeListHead(&BlpBootProtocols);
|
||||
RtlInitializeListHead(&BlpConfig);
|
||||
RtlInitializeListHead(&BlpLoadedModules);
|
||||
|
||||
|
@@ -9,6 +9,9 @@
|
||||
#include <xtldr.h>
|
||||
|
||||
|
||||
/* XT Boot Loader registered boot protocol list */
|
||||
LIST_ENTRY BlpBootProtocols;
|
||||
|
||||
/* XT Boot Loader configuration list */
|
||||
LIST_ENTRY BlpConfig;
|
||||
|
||||
|
@@ -78,6 +78,11 @@ XTCDECL
|
||||
EFI_STATUS
|
||||
BlExitBootServices(IN UINT_PTR MapKey);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlFindBootProtocol(IN PWCHAR SystemType,
|
||||
OUT PEFI_GUID BootProtocolGuid);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlFindVolumeDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL FsHandle,
|
||||
@@ -105,6 +110,10 @@ BlInitializeBootMenuList(OUT PXTBL_BOOTMENU_ITEM MenuEntries,
|
||||
OUT PULONG EntriesCount,
|
||||
OUT PULONG DefaultId);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlLoadModule(IN PWCHAR ModuleName);
|
||||
@@ -163,6 +172,11 @@ XTCDECL
|
||||
VOID
|
||||
BlRegisterBootMenu(PVOID BootMenuRoutine);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlRegisterBootProtocol(IN PWCHAR SystemType,
|
||||
IN PEFI_GUID BootProtocolGuid);
|
||||
|
||||
XTCDECL
|
||||
VOID
|
||||
BlResetConsoleInputBuffer();
|
||||
|
@@ -12,6 +12,9 @@
|
||||
#include <xtblapi.h>
|
||||
|
||||
|
||||
/* XT Boot Loader registered boot protocol list */
|
||||
EXTERN LIST_ENTRY BlpBootProtocols;
|
||||
|
||||
/* XT Boot Loader configuration list */
|
||||
EXTERN LIST_ENTRY BlpConfig;
|
||||
|
||||
|
@@ -9,6 +9,49 @@
|
||||
#include <xtldr.h>
|
||||
|
||||
|
||||
/**
|
||||
* Finds a boot protocol for specified system type.
|
||||
*
|
||||
* @param SystemType
|
||||
* Specifies the system type to search for.
|
||||
*
|
||||
* @param BootProtocolGuid
|
||||
* Receives the GUID of the registered boot protocol, that supports specified system.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlFindBootProtocol(IN PWCHAR SystemType,
|
||||
OUT PEFI_GUID BootProtocolGuid)
|
||||
{
|
||||
PXTBL_KNOWN_BOOT_PROTOCOL ProtocolEntry;
|
||||
PLIST_ENTRY ProtocolListEntry;
|
||||
|
||||
ProtocolListEntry = BlpBootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BlpBootProtocols)
|
||||
{
|
||||
/* Get boot protocol entry */
|
||||
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
|
||||
|
||||
/* Check if this boot protocol supports specified system */
|
||||
if(RtlCompareWideStringInsensitive(ProtocolEntry->SystemType, SystemType, 0) == 0)
|
||||
{
|
||||
/* Boot protocol matched, return success */
|
||||
BootProtocolGuid = &ProtocolEntry->Guid;
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/* Move to the next registered boot protocol */
|
||||
ProtocolListEntry = ProtocolListEntry->Flink;
|
||||
}
|
||||
|
||||
/* Boot protocol not found, return error */
|
||||
return STATUS_EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specified XTLDR module from disk.
|
||||
*
|
||||
@@ -287,7 +330,7 @@ BlLoadModules(IN PWCHAR ModulesList)
|
||||
* @param ProtocolGuid
|
||||
* Supplies a pointer to the unique protocol GUID.
|
||||
*
|
||||
* @return This routine returns status code.
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
@@ -361,10 +404,66 @@ BlRegisterBootMenu(PVOID BootMenuRoutine)
|
||||
BlpStatus.BootMenu = BootMenuRoutine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a known boot protocol for a specified OS.
|
||||
*
|
||||
* @param SystemType
|
||||
* Supplies the type of the OS, such as "LINUX", "XTOS", etc. that is supported by the boot protocol.
|
||||
*
|
||||
* @param BootProtocolGuid
|
||||
* Supplies a pointer to the unique protocol GUID.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlRegisterBootProtocol(IN PWCHAR SystemType,
|
||||
IN PEFI_GUID BootProtocolGuid)
|
||||
{
|
||||
PXTBL_KNOWN_BOOT_PROTOCOL ProtocolEntry;
|
||||
PLIST_ENTRY ProtocolListEntry;
|
||||
EFI_STATUS Status;
|
||||
|
||||
ProtocolListEntry = BlpBootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BlpBootProtocols)
|
||||
{
|
||||
/* Get boot protocol entry */
|
||||
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
|
||||
|
||||
/* Check if boot protocol already registered for specified system */
|
||||
if(RtlCompareWideStringInsensitive(ProtocolEntry->SystemType, SystemType, 0) == 0)
|
||||
{
|
||||
/* Boot protocol already registered */
|
||||
return STATUS_EFI_ABORTED;
|
||||
}
|
||||
|
||||
/* Move to the next registered boot protocol */
|
||||
ProtocolListEntry = ProtocolListEntry->Flink;
|
||||
}
|
||||
|
||||
/* Create new boot protocol entry */
|
||||
Status = BlMemoryAllocatePool(sizeof(XTBL_BOOT_PROTOCOL), (PVOID *)&ProtocolEntry);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
return STATUS_EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* Set protocol properties and add it to the list */
|
||||
ProtocolEntry->SystemType = SystemType;
|
||||
ProtocolEntry->Guid = *BootProtocolGuid;
|
||||
RtlInsertTailList(&BlpBootProtocols, &ProtocolEntry->Flink);
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine registers XTLDR protocol for further usage by modules.
|
||||
*
|
||||
* @return This routine returns status code.
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
@@ -377,6 +476,11 @@ BlpRegisterXtLoaderProtocol()
|
||||
EFI_HANDLE Handle = NULL;
|
||||
|
||||
/* Set all routines available via loader protocol */
|
||||
LdrProtocol.Boot.FindProtocol = BlFindBootProtocol;
|
||||
LdrProtocol.Boot.InitializeMenuList = BlInitializeBootMenuList;
|
||||
LdrProtocol.Boot.InvokeProtocol = BlInvokeBootProtocol;
|
||||
LdrProtocol.Boot.RegisterMenu = BlRegisterBootMenu;
|
||||
LdrProtocol.Boot.RegisterProtocol = BlRegisterBootProtocol;
|
||||
LdrProtocol.Console.ClearLine = BlClearConsoleLine;
|
||||
LdrProtocol.Console.ClearScreen = BlClearConsoleScreen;
|
||||
LdrProtocol.Console.DisableCursor = BlDisableConsoleCursor;
|
||||
@@ -396,9 +500,7 @@ BlpRegisterXtLoaderProtocol()
|
||||
LdrProtocol.Memory.AllocatePool = BlMemoryAllocatePool;
|
||||
LdrProtocol.Memory.FreePages = BlMemoryFreePages;
|
||||
LdrProtocol.Memory.FreePool = BlMemoryFreePool;
|
||||
LdrProtocol.Protocol.InitializeBootMenuList = BlInitializeBootMenuList;
|
||||
LdrProtocol.Protocol.OpenProtocol = BlOpenXtProtocol;
|
||||
LdrProtocol.Protocol.RegisterBootMenu = BlRegisterBootMenu;
|
||||
LdrProtocol.Protocol.Open = BlOpenXtProtocol;
|
||||
LdrProtocol.Tui.DisplayErrorDialog = BlDisplayErrorDialog;
|
||||
LdrProtocol.Tui.DisplayInfoDialog = BlDisplayInfoDialog;
|
||||
LdrProtocol.Tui.DisplayProgressDialog = BlDisplayProgressDialog;
|
||||
|
@@ -111,10 +111,12 @@ EFI_STATUS
|
||||
BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList)
|
||||
{
|
||||
XTBL_BOOT_PARAMETERS BootParameters;
|
||||
PWCHAR ModulesList;
|
||||
PXTBL_BOOT_PROTOCOL BootProtocol;
|
||||
PLIST_ENTRY OptionsListEntry;
|
||||
PXTBL_CONFIG_ENTRY Option;
|
||||
EFI_GUID BootProtocolGuid;
|
||||
SIZE_T ModuleListLength;
|
||||
PWCHAR ModulesList;
|
||||
EFI_STATUS Status;
|
||||
|
||||
/* Initialize boot parameters */
|
||||
@@ -151,8 +153,14 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList)
|
||||
}
|
||||
else if(RtlCompareWideStringInsensitive(Option->Name, L"SYSTEMPATH", 0) == 0)
|
||||
{
|
||||
/* System path found, get boot volume */
|
||||
|
||||
/* System path found, get volume device path */
|
||||
Status = BlGetVolumeDevicePath((PWCHAR)Option->Value, &BootParameters.DevicePath, &BootParameters.ArcName, &BootParameters.SystemPath);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to find volume */
|
||||
BlDebugPrint(L"ERROR: Failed to find volume device path (Status Code: 0x%lx)\n", Status);
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
else if(RtlCompareWideStringInsensitive(Option->Name, L"KERNELFILE", 0) == 0)
|
||||
{
|
||||
@@ -188,11 +196,26 @@ BlInvokeBootProtocol(IN PLIST_ENTRY OptionsList)
|
||||
return STATUS_EFI_NOT_READY;
|
||||
}
|
||||
|
||||
// TODO: Add support for boot protocol and invoke it
|
||||
return STATUS_EFI_UNSUPPORTED;
|
||||
/* Attempt to get boot protocol GUID */
|
||||
Status = BlFindBootProtocol(BootParameters.SystemType, &BootProtocolGuid);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to get boot protocol GUID */
|
||||
BlDebugPrint(L"ERROR: Unable to find appropriate boot protocol (Status Code: 0x%lx)\n", Status);
|
||||
return STATUS_EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/* This point should never be reached */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
/* Open boot protocol */
|
||||
Status = BlOpenXtProtocol((PVOID *)&BootProtocol, &BootProtocolGuid);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to open boot protocol */
|
||||
BlDebugPrint(L"ERROR: Failed to open boot protocol (Status Code: 0x%lx)\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Boot Operating System */
|
||||
return BootProtocol->BootSystem(&BootParameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user