From 0cea10ad42f962cc49502cc8e67c088f00f193f5 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 11 Dec 2023 16:31:15 +0100 Subject: [PATCH] Store all configuration in a linked list, read config from INI file and EFI shell --- sdk/xtdk/bltypes.h | 19 +-- xtldr2/config.c | 344 ++++++++++++++++++++++++++++---------- xtldr2/console.c | 2 +- xtldr2/debug.c | 23 +-- xtldr2/efiutils.c | 2 +- xtldr2/globals.c | 10 +- xtldr2/includes/bootman.h | 29 +++- xtldr2/includes/globals.h | 10 +- xtldr2/xtldr.c | 29 +++- 9 files changed, 344 insertions(+), 124 deletions(-) diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index ae291a9..67ba8e0 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -45,32 +45,21 @@ typedef EFI_STATUS (*PBL_OPEN_XT_PROTOCOL)(OUT PVOID *ProtocolHandler, IN PEFI_G typedef EFI_STATUS (*PBL_READ_FILE)(IN PEFI_FILE_HANDLE DirHandle, IN CONST PWCHAR FileName, OUT PVOID *FileData, OUT PSIZE_T FileSize); typedef VOID (*PBL_SLEEP_EXECUTION)(IN ULONG_PTR Milliseconds); -/* XTLDR Configuration */ -typedef struct _XTBL_CONFIGURATION -{ - PWCHAR Default; - PWCHAR Debug; - ULONG DebugPort; - BOOLEAN Shell; - ULONG Timeout; - PWCHAR Tune; -} XTBL_CONFIGURATION, *PXTBL_CONFIGURATION; - /* XTLDR Configuration data */ -typedef struct _XTBL_INI_OPTION +typedef struct _XTBL_CONFIG_ENTRY { LIST_ENTRY Flink; PWCHAR Name; PWCHAR Value; -} XTBL_INI_OPTION, *PXTBL_INI_OPTION; +} XTBL_CONFIG_ENTRY, *PXTBL_CONFIG_ENTRY; /* XTLDR Configuration section */ -typedef struct _XTBL_INI_SECTION +typedef struct _XTBL_CONFIG_SECTION { LIST_ENTRY Flink; LIST_ENTRY Options; PWCHAR SectionName; -} XTBL_INI_SECTION, *PXTBL_INI_SECTION; +} XTBL_CONFIG_SECTION, *PXTBL_CONFIG_SECTION; /* XTLDR Status data */ typedef struct _XTBL_STATUS diff --git a/xtldr2/config.c b/xtldr2/config.c index 7bdf1c8..9925bcd 100644 --- a/xtldr2/config.c +++ b/xtldr2/config.c @@ -9,19 +9,120 @@ #include +/** + * Returns a value of the specified configuration key. + * + * @param ConfigName + * Specifies the configuration key to return its value. + * + * @return This routine returns a pointer to the configuration value, or NULL if key was not found. + * + * @since XT 1.0 + */ +XTCDECL +PWCHAR +BlGetConfigValue(IN CONST PWCHAR ConfigName) +{ + PXTBL_CONFIG_ENTRY ConfigEntry; + PLIST_ENTRY ConfigListEntry; + SIZE_T Length; + + /* Get config entry name length */ + Length = RtlWideStringLength(ConfigName, 0); + + /* Iterate through config entries */ + ConfigListEntry = BlpConfig->Flink; + while(ConfigListEntry != BlpConfig) + { + /* Get config entry */ + ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink); + + /* Check if requested configuration found */ + if(RtlCompareWideStringInsensitive(ConfigEntry->Name, ConfigName, Length) == 0) + { + /* Return config value */ + return ConfigEntry->Value; + } + + /* Move to the next config entry */ + ConfigListEntry = ConfigListEntry->Flink; + } + + /* Config entry not found, return NULL */ + return NULL; +} + +/** + * Updates existing configuration value. + * + * @param ConfigName + * Specifies the configuration key to update. + * + * @param ConfigValue + * Specifies the new configuration value. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +BlSetConfigValue(IN CONST PWCHAR ConfigName, + IN CONST PWCHAR ConfigValue) +{ + PXTBL_CONFIG_ENTRY ConfigEntry; + PLIST_ENTRY ConfigListEntry; + SIZE_T Length; + + /* Get config entry name length */ + Length = RtlWideStringLength(ConfigName, 0); + + /* Iterate through config entries */ + ConfigListEntry = BlpConfig->Flink; + while(ConfigListEntry != BlpConfig) + { + /* Get config entry */ + ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink); + + /* Check if requested configuration found */ + if(RtlCompareWideStringInsensitive(ConfigEntry->Name, ConfigName, Length) == 0) + { + /* Update config value */ + ConfigEntry->Value = ConfigValue; + + /* Return success */ + return STATUS_EFI_SUCCESS; + } + + /* Move to the next config entry */ + ConfigListEntry = ConfigListEntry->Flink; + } + + /* Config entry not found */ + return STATUS_EFI_NOT_FOUND; +} + +/** + * Loads and parses XTLDR configuration file. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ XTCDECL EFI_STATUS BlpLoadConfiguration() { + PLIST_ENTRY SectionListEntry; + STATIC LIST_ENTRY Configuration; EFI_STATUS Status; - PLIST_ENTRY Configuration; PCHAR ConfigData; /* Initialize configuration pointer */ - Configuration = NULL; + RtlInitializeListHead(&Configuration); /* Read data from configuration file */ - Status = BlpReadConfigurationFile(L"\\EFI\\BOOT\\", L"XTLDR.INI", &ConfigData); + Status = BlpReadConfigFile(L"\\EFI\\BOOT\\", L"XTLDR.INI", &ConfigData); if(Status != STATUS_EFI_SUCCESS) { /* Failed to load configuration */ @@ -30,7 +131,7 @@ BlpLoadConfiguration() } /* Parse configuration data */ - Status = BlpParseConfigurationFile(ConfigData, Configuration); + Status = BlpParseConfigFile(ConfigData, &Configuration); if(Status != STATUS_EFI_SUCCESS) { /* Failed to parse configuration */ @@ -38,6 +139,31 @@ BlpLoadConfiguration() return Status; } + /* Iterate through config sections */ + SectionListEntry = Configuration.Flink; + while(SectionListEntry != &Configuration) + { + /* Get config section */ + PXTBL_CONFIG_SECTION Section = CONTAIN_RECORD(SectionListEntry, XTBL_CONFIG_SECTION, Flink); + + /* Look for global XTLDR configuration section */ + if(RtlCompareWideStringInsensitive(Section->SectionName, L"XTLDR", 5) == 0) + { + /* Update global configuration */ + BlpUpdateConfiguration(&Section->Options); + + /* Remove XTLDR section from the list */ + RtlRemoveEntryList(SectionListEntry); + break; + } + + /* Move to the next section */ + SectionListEntry = SectionListEntry->Flink; + } + + /* Update boot menu OS list */ + BlpMenuList = &Configuration; + /* Return success */ return STATUS_EFI_SUCCESS; } @@ -50,12 +176,19 @@ BlpLoadConfiguration() * @since XT 1.0 */ XTCDECL -VOID +EFI_STATUS BlpParseCommandLine(VOID) { EFI_GUID LIPGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; PEFI_LOADED_IMAGE_PROTOCOL LoadedImage; + PWCHAR Argument, Key, LastArg, Value; + PXTBL_CONFIG_ENTRY Option; EFI_STATUS Status; + SIZE_T KeyLength, ValueLength; + LIST_ENTRY Config; + + /* Initialize configuration list */ + RtlInitializeListHead(&Config); /* Handle loaded image protocol */ Status = EfiSystemTable->BootServices->HandleProtocol(EfiImageHandle, &LIPGuid, (PVOID *)&LoadedImage); @@ -64,21 +197,113 @@ BlpParseCommandLine(VOID) /* Check if launched from UEFI shell */ if(LoadedImage && LoadedImage->LoadOptions) { - /* Update global boot loader configuration */ - BlpUpdateGlobalConfiguration(LoadedImage->LoadOptions); + /* Tokenize provided options */ + Argument = RtlTokenizeWideString(LoadedImage->LoadOptions, L" ", &LastArg); + + /* Iterate over all arguments passed to boot loader */ + while(Argument != NULL) + { + /* Store key name */ + Key = Argument; + + /* Find end of the key */ + while(*Argument != '=' && *Argument != 0 && *Argument != '\n') + { + /* Advance to the next character */ + Argument++; + } + + /* Mark end of the key and advance to the next character */ + *Argument = 0; + Argument++; + + /* Store value */ + Value = Argument; + + /* Find end of the value */ + while(*Argument != 0 && *Argument != '\n') + { + /* Advance to the next character */ + Argument++; + } + + /* Mark end of the value and advance to the next character */ + *Argument = 0; + Argument++; + + /* Get length of the key and its value */ + KeyLength = RtlWideStringLength(Key, 0); + ValueLength = RtlWideStringLength(Value, 0); + + /* Check if argument is valid */ + if(KeyLength == 0 || ValueLength == 0) + { + /* Invalid argument, skip to the next one */ + continue; + } + + /* Allocate memory for new option */ + Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option); + if(Status == STATUS_EFI_SUCCESS) + { + /* Allocate more memory for option name */ + Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (KeyLength + 1), (PVOID*)&Option->Name); + if(Status == STATUS_EFI_SUCCESS) + { + /* Allocate even more memory for option value */ + Status = BlMemoryAllocatePool(sizeof(PWCHAR) * (ValueLength + 1), (PVOID*)&Option->Value); + } + } + if(Status != STATUS_EFI_SUCCESS) + { + /* Some memory allocation failed */ + return Status; + } + + /* Set entry name and value */ + RtlCopyMemory(Option->Name, Key, (KeyLength * sizeof(WCHAR))); + RtlCopyMemory(Option->Value, Value, (ValueLength * sizeof(WCHAR))); + Option->Name[KeyLength] = 0; + Option->Value[ValueLength] = 0; + + /* Add entry to the list */ + RtlInsertTailList(&Config, &Option->Flink); + + /* Take next argument */ + Argument = RtlTokenizeWideString(NULL, L" ", &LastArg); + } + + /* Update global configuration */ + BlpUpdateConfiguration(&Config); } } + + /* Return success */ + return STATUS_EFI_SUCCESS; } +/** + * Parses configuration INI file. + * + * @param RawConfig + * Suplies a pointer to configuration INI file to be parsed. + * + * @param Configuration + * Supplies a pointer to memory region where parsed configuration will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ XTCDECL EFI_STATUS -BlpParseConfigurationFile(IN CONST PCHAR RawConfig, - OUT PLIST_ENTRY Configuration) +BlpParseConfigFile(IN CONST PCHAR RawConfig, + OUT PLIST_ENTRY Configuration) { SIZE_T SectionLength, KeyLength, ValueLength; PCHAR InputData, Key, SectionName, Value; - PXTBL_INI_SECTION Section; - PXTBL_INI_OPTION Option; + PXTBL_CONFIG_SECTION Section; + PXTBL_CONFIG_ENTRY Option; EFI_STATUS Status; /* Initialize pointers */ @@ -139,7 +364,7 @@ BlpParseConfigurationFile(IN CONST PCHAR RawConfig, SectionLength = RtlStringLength(SectionName, 0); /* Allocate memory for new section */ - Status = BlMemoryAllocatePool(sizeof(XTBL_INI_SECTION), (PVOID*)&Section); + Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_SECTION), (PVOID*)&Section); if(Status == STATUS_EFI_SUCCESS) { /* Allocate more memory for section name */ @@ -209,7 +434,7 @@ BlpParseConfigurationFile(IN CONST PCHAR RawConfig, ValueLength = RtlStringLength(Value, 0); /* Allocate memory for new option */ - Status = BlMemoryAllocatePool(sizeof(XTBL_INI_OPTION), (PVOID*)&Option); + Status = BlMemoryAllocatePool(sizeof(XTBL_CONFIG_ENTRY), (PVOID*)&Option); if(Status == STATUS_EFI_SUCCESS) { /* Allocate more memory for option name */ @@ -255,9 +480,9 @@ BlpParseConfigurationFile(IN CONST PCHAR RawConfig, */ XTCDECL EFI_STATUS -BlpReadConfigurationFile(IN CONST PWCHAR ConfigDirectory, - IN CONST PWCHAR ConfigFile, - OUT PCHAR *ConfigData) +BlpReadConfigFile(IN CONST PWCHAR ConfigDirectory, + IN CONST PWCHAR ConfigFile, + OUT PCHAR *ConfigData) { PEFI_FILE_HANDLE DirHandle, FsHandle; EFI_HANDLE DiskHandle; @@ -295,10 +520,10 @@ BlpReadConfigurationFile(IN CONST PWCHAR ConfigDirectory, } /** - * Updates XTLDR configuration based on provided options. + * Adds new XTLDR configuration entries to the global configuration list. Existing entries are not overwritten. * - * @param Options - * Supplies a formatted list of options to be processed and stored in global configuration. + * @param NewConfig + * Supplies a pointer to a linked list containing new configuration entries. * * @return This routine does not return any value. * @@ -306,78 +531,29 @@ BlpReadConfigurationFile(IN CONST PWCHAR ConfigDirectory, */ XTCDECL VOID -BlpUpdateGlobalConfiguration(IN PWCHAR Options) +BlpUpdateConfiguration(IN PLIST_ENTRY NewConfig) { - PWCHAR Argument, LastArg; - SIZE_T Length; + PXTBL_CONFIG_ENTRY ConfigEntry; + PLIST_ENTRY ConfigListEntry, NextListEntry; - /* Tokenize provided options */ - Argument = RtlTokenizeWideString(Options, L" ", &LastArg); - - /* Iterate over all arguments passed to boot loader */ - while(Argument != NULL) + /* Iterate through new config entries */ + ConfigListEntry = NewConfig->Flink; + while(ConfigListEntry != NewConfig) { - /* Check all provided parameters */ - if(RtlCompareWideStringInsensitive(Argument, L"DEFAULT=", 8) == 0) - { - /* Skip to the argument value and calculate argument length */ - Argument += 8; - Length = RtlWideStringLength(Argument, 0); + /* Get new config entry */ + ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink); - /* Save default OS parameter in global configuration */ - BlMemoryAllocatePool(Length, (PVOID *)&BlpConfiguration.Default); - RtlCopyMemory(BlpConfiguration.Default, Argument, (Length * sizeof(WCHAR))); - BlpConfiguration.Default[Length] = '\0'; - } - else if(RtlCompareWideStringInsensitive(Argument, L"DEBUG=", 6) == 0) - { - /* Skip to the argument value */ - Argument += 6; - Length = RtlWideStringLength(Argument, 0); + /* Get next config entry */ + NextListEntry = ConfigListEntry->Flink; - /* Store debug port configuration if not set already */ - if(BlpConfiguration.Debug == NULL) - { - /* Save debug port in global configuration */ - BlMemoryAllocatePool(Length, (PVOID *)&BlpConfiguration.Debug); - RtlCopyMemory(BlpConfiguration.Debug, Argument, (Length * sizeof(WCHAR))); - BlpConfiguration.Debug[Length] = '\0'; - } - } - else if(RtlCompareWideStringInsensitive(Argument, L"SHELL", 5) == 0) + /* Make sure config entry does not exist yet */ + if(BlGetConfigValue(ConfigEntry->Name) == NULL) { - /* Force shell mode */ - BlpConfiguration.Shell = TRUE; - } - else if(RtlCompareWideStringInsensitive(Argument, L"TIMEOUT=", 8) == 0) - { - /* Skip to the argument value */ - Argument += 8; - - /* Zero the timeout */ - BlpConfiguration.Timeout = 0; - - /* Read the timeout value and store it in global configuration */ - while(*Argument >= '0' && *Argument <= '9') - { - BlpConfiguration.Timeout *= 10; - BlpConfiguration.Timeout += *Argument - '0'; - Argument++; - } - } - else if(RtlCompareWideStringInsensitive(Argument, L"TUNE=", 5) == 0) - { - /* Skip to the argument value */ - Argument += 5; - Length = RtlWideStringLength(Argument, 0); - - /* Save theme in global configuration */ - BlMemoryAllocatePool(Length, (PVOID *)&BlpConfiguration.Tune); - RtlCopyMemory(BlpConfiguration.Tune, Argument, (Length * sizeof(WCHAR))); - BlpConfiguration.Tune[Length] = '\0'; + /* Remove new config entry from input list and put it into global config list */ + RtlInsertTailList(BlpConfig, &ConfigEntry->Flink); } - /* Take next argument */ - Argument = RtlTokenizeWideString(NULL, L" ", &LastArg); + /* Move to the next new config entry */ + ConfigListEntry = NextListEntry; } } diff --git a/xtldr2/console.c b/xtldr2/console.c index 08f2341..d8a7b8e 100644 --- a/xtldr2/console.c +++ b/xtldr2/console.c @@ -102,7 +102,7 @@ BlConsolePrint(IN PUINT16 Format, */ XTCDECL VOID -BlpConsoleInitialize() +BlpInitializeConsole() { /* Clear console buffers */ EfiSystemTable->ConIn->Reset(EfiSystemTable->ConIn, TRUE); diff --git a/xtldr2/debug.c b/xtldr2/debug.c index 668766a..b431723 100644 --- a/xtldr2/debug.c +++ b/xtldr2/debug.c @@ -36,14 +36,14 @@ BlDebugPrint(IN PUINT16 Format, VA_START(Arguments, Format); /* Check if serial debug port is enabled */ - if((BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SERIAL) && (BlpSerialPort.Flags & COMPORT_FLAG_INIT)) + if((BlpDebugPort & XTBL_DEBUGPORT_SERIAL) && (BlpSerialPort.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((BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SCREEN) && (BlpStatus.BootServices == TRUE)) + if((BlpDebugPort & XTBL_DEBUGPORT_SCREEN) && (BlpStatus.BootServices == TRUE)) { /* Format and print the string to the screen */ BlpStringPrint(BlpConsolePrintChar, Format, Arguments); @@ -66,7 +66,7 @@ EFI_STATUS BlpInitializeDebugConsole() { ULONG PortAddress, PortNumber, BaudRate; - PWCHAR DebugPort, LastPort; + PWCHAR DebugConfiguration, DebugPort, LastPort; EFI_STATUS Status; /* Set default serial port options */ @@ -74,11 +74,14 @@ BlpInitializeDebugConsole() PortNumber = 0; BaudRate = 0; - /* Make sure any debug options are provided */ - if(BlpConfiguration.Debug) + /* Get debug configuration */ + DebugConfiguration = BlGetConfigValue(L"DEBUG"); + + /* Make sure any debug options are provided and debug console is not initialized yet */ + if(DebugConfiguration && BlpDebugPort == 0) { /* Find all debug ports */ - DebugPort = RtlTokenizeWideString(BlpConfiguration.Debug, L";", &LastPort); + DebugPort = RtlTokenizeWideString(DebugConfiguration, L";", &LastPort); /* Iterate over all debug ports */ while(DebugPort != NULL) @@ -138,12 +141,12 @@ BlpInitializeDebugConsole() } /* Enable debug port */ - BlpConfiguration.DebugPort |= XTBL_DEBUGPORT_SERIAL; + BlpDebugPort |= XTBL_DEBUGPORT_SERIAL; } else if(RtlCompareWideStringInsensitive(DebugPort, L"SCREEN", 5) == 0) { /* Enable debug port */ - BlpConfiguration.DebugPort |= XTBL_DEBUGPORT_SCREEN; + BlpDebugPort |= XTBL_DEBUGPORT_SCREEN; } else { @@ -158,14 +161,14 @@ BlpInitializeDebugConsole() } /* Check if serial debug port is enabled */ - if(BlpConfiguration.DebugPort & XTBL_DEBUGPORT_SERIAL) + if(BlpDebugPort & 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 */ - BlpConfiguration.DebugPort &= ~XTBL_DEBUGPORT_SERIAL; + BlpDebugPort &= ~XTBL_DEBUGPORT_SERIAL; return Status; } } diff --git a/xtldr2/efiutils.c b/xtldr2/efiutils.c index 104db69..bc41df4 100644 --- a/xtldr2/efiutils.c +++ b/xtldr2/efiutils.c @@ -78,5 +78,5 @@ BlpInitializeEfiBootLoader() BlpStatus.SystemTable = EfiSystemTable; /* Initialize console */ - BlpConsoleInitialize(); + BlpInitializeConsole(); } diff --git a/xtldr2/globals.c b/xtldr2/globals.c index ae67696..1d38120 100644 --- a/xtldr2/globals.c +++ b/xtldr2/globals.c @@ -9,12 +9,18 @@ #include -/* XT Boot Loader configuration data */ -XTBL_CONFIGURATION BlpConfiguration = {0}; +/* XT Boot Loader configuration list */ +PLIST_ENTRY BlpConfig = NULL; + +/* XT Boot Loader debug port configuration */ +ULONG BlpDebugPort = 0; /* XT Boot Loader hex table */ STATIC PUINT16 BlpHexTable = L"0123456789ABCDEF"; +/* XT Boot Loader menu list */ +PLIST_ENTRY BlpMenuList = NULL; + /* Serial port configuration */ CPPORT BlpSerialPort; diff --git a/xtldr2/includes/bootman.h b/xtldr2/includes/bootman.h index d8ae19b..73d0658 100644 --- a/xtldr2/includes/bootman.h +++ b/xtldr2/includes/bootman.h @@ -56,6 +56,10 @@ BlFindVolumeDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL FsHandle, IN CONST PWCHAR FileSystemPath, OUT PEFI_DEVICE_PATH_PROTOCOL* DevicePath); +XTCDECL +PWCHAR +BlGetConfigValue(IN CONST PWCHAR ConfigName); + XTCDECL EFI_STATUS BlGetVolumeDevicePath(IN PCHAR SystemPath, @@ -100,6 +104,11 @@ EFI_STATUS BlOpenXtProtocol(OUT PVOID *ProtocolHandler, IN PEFI_GUID ProtocolGuid); +XTCDECL +EFI_STATUS +BlSetConfigValue(IN CONST PWCHAR ConfigName, + IN CONST PWCHAR ConfigValue); + XTCDECL VOID BlSleepExecution(IN ULONG_PTR Milliseconds); @@ -115,7 +124,7 @@ BlpActivateSerialIOController(); XTCDECL VOID -BlpConsoleInitialize(); +BlpInitializeConsole(); XTCDECL VOID @@ -168,19 +177,23 @@ BlpInitializeSerialPort(IN ULONG PortNumber, IN ULONG BaudRate); XTCDECL -VOID +EFI_STATUS +BlpLoadConfiguration(); + +XTCDECL +EFI_STATUS BlpParseCommandLine(VOID); XTCDECL EFI_STATUS -BlpParseConfigurationFile(IN CONST PCHAR RawConfig, - OUT PLIST_ENTRY Configuration); +BlpParseConfigFile(IN CONST PCHAR RawConfig, + OUT PLIST_ENTRY Configuration); XTCDECL EFI_STATUS -BlpReadConfigurationFile(IN CONST PWCHAR ConfigDirectory, - IN CONST PWCHAR ConfigFile, - OUT PCHAR *ConfigData); +BlpReadConfigFile(IN CONST PWCHAR ConfigDirectory, + IN CONST PWCHAR ConfigFile, + OUT PCHAR *ConfigData); XTCDECL EFI_STATUS @@ -230,6 +243,6 @@ BlpStringReadPadding(IN PUINT16 *Format); XTCDECL VOID -BlpUpdateGlobalConfiguration(IN PWCHAR Options); +BlpUpdateConfiguration(IN PLIST_ENTRY NewConfig); #endif /* __XTLDR_BOOTMAN_H */ diff --git a/xtldr2/includes/globals.h b/xtldr2/includes/globals.h index c43b052..1db2504 100644 --- a/xtldr2/includes/globals.h +++ b/xtldr2/includes/globals.h @@ -12,12 +12,18 @@ #include -/* XT Boot Loader configuration data */ -EXTERN XTBL_CONFIGURATION BlpConfiguration; +/* XT Boot Loader configuration list */ +EXTERN PLIST_ENTRY BlpConfig; + +/* XT Boot Loader debug port configuration */ +EXTERN ULONG BlpDebugPort; /* XT Boot Loader hex table */ EXTERN PUINT16 BlpHexTable; +/* XT Boot Loader menu list */ +EXTERN PLIST_ENTRY BlpMenuList; + /* Serial port configuration */ EXTERN CPPORT BlpSerialPort; diff --git a/xtldr2/xtldr.c b/xtldr2/xtldr.c index 84c33da..06d5096 100644 --- a/xtldr2/xtldr.c +++ b/xtldr2/xtldr.c @@ -38,7 +38,13 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle, BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION); /* Parse configuration options passed from UEFI shell */ - BlpParseCommandLine(); + Status = BlpParseCommandLine(); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to parse command line options */ + BlConsolePrint(L"ERROR: Failed to parse command line options\n"); + BlSleepExecution(3000); + } /* Attempt to early initialize debug console */ if(DEBUG) @@ -52,6 +58,27 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle, } } + /* Load XTLDR configuration file */ + Status = BlpLoadConfiguration(); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to load/parse config file */ + BlConsolePrint(L"ERROR: Failed to load configuration file\n"); + BlSleepExecution(3000); + } + + /* Reinitialize debug console if it was not initialized earlier */ + if(DEBUG) + { + Status = BlpInitializeDebugConsole(); + if(Status != STATUS_EFI_SUCCESS) + { + /* Initialization failed, notify user on stdout */ + BlConsolePrint(L"ERROR: Failed to initialize debug console\n"); + BlSleepExecution(3000); + } + } + /* Disable watchdog timer */ Status = EfiSystemTable->BootServices->SetWatchdogTimer(0, 0x10000, 0, NULL); if(Status != STATUS_EFI_SUCCESS)