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