XTLDR Rewrite #7
@ -119,7 +119,7 @@ BlpLoadConfiguration()
|
||||
PCHAR ConfigData;
|
||||
|
||||
/* Initialize configuration pointer */
|
||||
RtlInitializeListHead(&BlpConfiguration);
|
||||
RtlInitializeListHead(&BlpConfigSections);
|
||||
|
||||
/* Read data from configuration file */
|
||||
Status = BlpReadConfigFile(L"\\EFI\\BOOT\\", L"XTLDR.INI", &ConfigData);
|
||||
@ -131,7 +131,7 @@ BlpLoadConfiguration()
|
||||
}
|
||||
|
||||
/* Parse configuration data */
|
||||
Status = BlpParseConfigFile(ConfigData, &BlpConfiguration);
|
||||
Status = BlpParseConfigFile(ConfigData, &BlpConfigSections);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to parse configuration */
|
||||
@ -140,8 +140,8 @@ BlpLoadConfiguration()
|
||||
}
|
||||
|
||||
/* Iterate through config sections */
|
||||
SectionListEntry = BlpConfiguration.Flink;
|
||||
while(SectionListEntry != &BlpConfiguration)
|
||||
SectionListEntry = BlpConfigSections.Flink;
|
||||
while(SectionListEntry != &BlpConfigSections)
|
||||
{
|
||||
/* Get config section */
|
||||
PXTBL_CONFIG_SECTION Section = CONTAIN_RECORD(SectionListEntry, XTBL_CONFIG_SECTION, Flink);
|
||||
@ -162,7 +162,7 @@ BlpLoadConfiguration()
|
||||
}
|
||||
|
||||
/* Update boot menu OS list */
|
||||
BlpMenuList = &BlpConfiguration;
|
||||
BlpMenuList = &BlpConfigSections;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
|
@ -82,7 +82,7 @@ BlConsolePrint(IN PUINT16 Format,
|
||||
if(RtlCompareWideString(EfiSystemTable->FirmwareVendor, L"EDK II", 6) != 0)
|
||||
{
|
||||
/* Check if debugging enabled and if EFI serial port is fully initialized */
|
||||
if(DEBUG && (BlpSerialPort.Flags & COMPORT_FLAG_INIT))
|
||||
if(DEBUG && (BlpStatus.SerialPort.Flags & COMPORT_FLAG_INIT))
|
||||
{
|
||||
/* Format and print the string to the serial console */
|
||||
BlpStringPrint(BlpDebugPutChar, Format, Arguments);
|
||||
|
@ -36,14 +36,14 @@ BlDebugPrint(IN PUINT16 Format,
|
||||
VA_START(Arguments, Format);
|
||||
|
||||
/* Check if serial debug port is enabled */
|
||||
if((BlpDebugPort & XTBL_DEBUGPORT_SERIAL) && (BlpSerialPort.Flags & COMPORT_FLAG_INIT))
|
||||
if((BlpStatus.DebugPort & XTBL_DEBUGPORT_SERIAL) && (BlpStatus.SerialPort.Flags & COMPORT_FLAG_INIT))
|
||||
{
|
||||
/* Format and print the string to the serial console */
|
||||
BlpStringPrint(BlpDebugPutChar, Format, Arguments);
|
||||
}
|
||||
|
||||
/* Check if screen debug port is enabled and Boot Services are still available */
|
||||
if((BlpDebugPort & XTBL_DEBUGPORT_SCREEN) && (BlpStatus.BootServices == TRUE))
|
||||
if((BlpStatus.DebugPort & XTBL_DEBUGPORT_SCREEN) && (BlpStatus.BootServices == TRUE))
|
||||
{
|
||||
/* Format and print the string to the screen */
|
||||
BlpStringPrint(BlpConsolePrintChar, Format, Arguments);
|
||||
@ -78,7 +78,7 @@ BlpInitializeDebugConsole()
|
||||
DebugConfiguration = BlGetConfigValue(L"DEBUG");
|
||||
|
||||
/* Make sure any debug options are provided and debug console is not initialized yet */
|
||||
if(DebugConfiguration && BlpDebugPort == 0)
|
||||
if(DebugConfiguration && BlpStatus.DebugPort == 0)
|
||||
{
|
||||
/* Find all debug ports */
|
||||
DebugPort = RtlTokenizeWideString(DebugConfiguration, L";", &LastPort);
|
||||
@ -141,12 +141,12 @@ BlpInitializeDebugConsole()
|
||||
}
|
||||
|
||||
/* Enable debug port */
|
||||
BlpDebugPort |= XTBL_DEBUGPORT_SERIAL;
|
||||
BlpStatus.DebugPort |= XTBL_DEBUGPORT_SERIAL;
|
||||
}
|
||||
else if(RtlCompareWideStringInsensitive(DebugPort, L"SCREEN", 5) == 0)
|
||||
{
|
||||
/* Enable debug port */
|
||||
BlpDebugPort |= XTBL_DEBUGPORT_SCREEN;
|
||||
BlpStatus.DebugPort |= XTBL_DEBUGPORT_SCREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -158,18 +158,18 @@ BlpInitializeDebugConsole()
|
||||
/* Take next debug port */
|
||||
DebugPort = RtlTokenizeWideString(NULL, L";", &LastPort);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if serial debug port is enabled */
|
||||
if(BlpDebugPort & XTBL_DEBUGPORT_SERIAL)
|
||||
{
|
||||
/* Try to initialize COM port */
|
||||
Status = BlpInitializeSerialPort(PortNumber, PortAddress, BaudRate);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
/* Check if serial debug port is enabled */
|
||||
if(BlpStatus.DebugPort & XTBL_DEBUGPORT_SERIAL)
|
||||
{
|
||||
/* Remove serial debug port, as COM port initialization failed and return */
|
||||
BlpDebugPort &= ~XTBL_DEBUGPORT_SERIAL;
|
||||
return Status;
|
||||
/* Try to initialize COM port */
|
||||
Status = BlpInitializeSerialPort(PortNumber, PortAddress, BaudRate);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Remove serial debug port, as COM port initialization failed and return */
|
||||
BlpStatus.DebugPort &= ~XTBL_DEBUGPORT_SERIAL;
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ BlpInitializeSerialPort(IN ULONG PortNumber,
|
||||
}
|
||||
|
||||
/* Initialize COM port */
|
||||
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
||||
Status = HlInitializeComPort(&BlpStatus.SerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
||||
|
||||
/* Port not found under supplied address */
|
||||
if(Status == STATUS_NOT_FOUND && PortAddress)
|
||||
@ -224,7 +224,7 @@ BlpInitializeSerialPort(IN ULONG PortNumber,
|
||||
{
|
||||
/* Try to reinitialize COM port */
|
||||
BlConsolePrint(L"Enabled I/O space access for all PCI(E) serial controllers found\n");
|
||||
Status = HlInitializeComPort(&BlpSerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
||||
Status = HlInitializeComPort(&BlpStatus.SerialPort, PortNumber, UlongToPtr(PortAddress), BaudRate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,5 +259,5 @@ BlpDebugPutChar(IN USHORT Character)
|
||||
Buffer[0] = Character;
|
||||
Buffer[1] = 0;
|
||||
|
||||
HlComPortPutByte(&BlpSerialPort, Buffer[0]);
|
||||
HlComPortPutByte(&BlpStatus.SerialPort, Buffer[0]);
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ BlExitBootServices(IN UINT_PTR MapKey)
|
||||
EFI_STATUS Status;
|
||||
|
||||
/* Attempt to exit boot services */
|
||||
Status = EfiSystemTable->BootServices->ExitBootServices(BlpStatus.ImageHandle, MapKey);
|
||||
Status = EfiSystemTable->BootServices->ExitBootServices(EfiImageHandle, MapKey);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Retry as UEFI spec says to do it twice */
|
||||
Status = EfiSystemTable->BootServices->ExitBootServices(BlpStatus.ImageHandle, MapKey);
|
||||
Status = EfiSystemTable->BootServices->ExitBootServices(EfiImageHandle, MapKey);
|
||||
}
|
||||
|
||||
/* Make sure boot services were successfully exited */
|
||||
@ -44,6 +44,39 @@ BlExitBootServices(IN UINT_PTR MapKey)
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether SecureBoot is enabled or not.
|
||||
*
|
||||
* @return Numeric representation of SecureBoot status (0 = Disabled, >0 = Enabled, <0 SetupMode).
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
INT_PTR
|
||||
BlGetSecureBootStatus()
|
||||
{
|
||||
EFI_GUID VarGuid = EFI_GLOBAL_VARIABLE_GUID;
|
||||
INT_PTR SecureBootStatus = 0;
|
||||
UCHAR VarValue = 0;
|
||||
UINT_PTR Size;
|
||||
|
||||
Size = sizeof(VarValue);
|
||||
if(EfiSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &VarGuid,
|
||||
NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS)
|
||||
{
|
||||
SecureBootStatus = (INT_PTR)VarValue;
|
||||
|
||||
if((EfiSystemTable->RuntimeServices->GetVariable(L"SetupMode", &VarGuid,
|
||||
NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS) && VarValue != 0)
|
||||
{
|
||||
SecureBootStatus = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return SecureBoot status */
|
||||
return SecureBootStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the system to sleep for the specified number of milliseconds.
|
||||
*
|
||||
@ -74,8 +107,6 @@ BlpInitializeEfiBootLoader()
|
||||
{
|
||||
/* Set current XTLDR status */
|
||||
BlpStatus.BootServices = TRUE;
|
||||
BlpStatus.ImageHandle = EfiImageHandle;
|
||||
BlpStatus.SystemTable = EfiSystemTable;
|
||||
|
||||
/* Initialize console */
|
||||
BlpInitializeConsole();
|
||||
|
@ -13,10 +13,7 @@
|
||||
PLIST_ENTRY BlpConfig = NULL;
|
||||
|
||||
/* XT Boot Loader loaded configuration */
|
||||
LIST_ENTRY BlpConfiguration;
|
||||
|
||||
/* XT Boot Loader debug port configuration */
|
||||
ULONG BlpDebugPort = 0;
|
||||
LIST_ENTRY BlpConfigSections;
|
||||
|
||||
/* XT Boot Loader hex table */
|
||||
STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
|
||||
@ -24,9 +21,6 @@ STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF";
|
||||
/* XT Boot Loader menu list */
|
||||
PLIST_ENTRY BlpMenuList = NULL;
|
||||
|
||||
/* Serial port configuration */
|
||||
CPPORT BlpSerialPort;
|
||||
|
||||
/* XT Boot Loader status data */
|
||||
XTBL_STATUS BlpStatus = {0};
|
||||
|
||||
|
@ -69,6 +69,10 @@ XTCDECL
|
||||
PWCHAR
|
||||
BlGetConfigValue(IN CONST PWCHAR ConfigName);
|
||||
|
||||
XTCDECL
|
||||
INT_PTR
|
||||
BlGetSecureBootStatus();
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
BlGetVolumeDevicePath(IN PCHAR SystemPath,
|
||||
|
@ -16,10 +16,7 @@
|
||||
EXTERN PLIST_ENTRY BlpConfig;
|
||||
|
||||
/* XT Boot Loader loaded configuration */
|
||||
EXTERN LIST_ENTRY BlpConfiguration;
|
||||
|
||||
/* XT Boot Loader debug port configuration */
|
||||
EXTERN ULONG BlpDebugPort;
|
||||
EXTERN LIST_ENTRY BlpConfigSections;
|
||||
|
||||
/* XT Boot Loader hex table */
|
||||
EXTERN PUINT16 BlpHexTable;
|
||||
@ -27,9 +24,6 @@ EXTERN PUINT16 BlpHexTable;
|
||||
/* XT Boot Loader menu list */
|
||||
EXTERN PLIST_ENTRY BlpMenuList;
|
||||
|
||||
/* Serial port configuration */
|
||||
EXTERN CPPORT BlpSerialPort;
|
||||
|
||||
/* XT Boot Loader status data */
|
||||
EXTERN XTBL_STATUS BlpStatus;
|
||||
|
||||
|
@ -108,6 +108,7 @@ BlpRegisterXtLoaderProtocol()
|
||||
LdrProtocol.Memory.FreePool = BlMemoryFreePool;
|
||||
LdrProtocol.Protocol.Open = BlOpenXtProtocol;
|
||||
LdrProtocol.Util.ExitBootServices = BlExitBootServices;
|
||||
LdrProtocol.Util.GetSecureBootStatus = BlGetSecureBootStatus;
|
||||
LdrProtocol.Util.SleepExecution = BlSleepExecution;
|
||||
|
||||
/* Register XTLDR loader protocol */
|
||||
|
Loading…
Reference in New Issue
Block a user