/** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory * FILE: xtldr/config.c * DESCRIPTION: XT Boot Loader Configuration * DEVELOPERS: Rafal Kupiec * Jozef Nagy */ #include /** * Parses configuration INI file contents. * * @param FileContents * Supplies a pointer to a wide string containing contents of the configuration file. * * @param Sections * Supplies a pointer to a linked list which will be written by this routine. * * @return This routine does not return any value. * * @since XT 1.0 */ XTCDECL VOID BlpConfigParseIniFile(IN PWCHAR FileContents, OUT PLIST_ENTRY SectionsHead) { PWCHAR CurrentSectionName, Key, Value; PWCHAR Input; UINT SectionLength, KeyLength, ValueLength; Input = FileContents; CurrentSectionName = L"None"; while(*Input != 0) { SectionLength = 0; KeyLength = 0; ValueLength = 0; if(*Input == ';' || *Input == '#') { /* Skip comments */ while(*Input != 0 && *Input != '\n') { Input++; } } else if(*Input == '\n') { /* Skip newline */ Input++; } else if(*Input == '[') { /* Get the section name */ Input++; CurrentSectionName = Input; /* Skip to the next line */ while(*Input != ']' && *Input != 0 && *Input != '\n') { SectionLength++; Input++; } Input++; } else { /* Get the length of key */ while(*Input != '=' && *Input != 0 && *Input != '\n') { KeyLength++; Input++; } /* Set key */ Key = Input - KeyLength; Key[KeyLength] = 0; Input++; /* Get the length of value */ while(*Input != 0 && *Input != '\n') { Input++; ValueLength++; } /* Set value */ Value = Input - ValueLength; Value[ValueLength] = 0; Input++; } } } /** * Parses command line arguments and updates global configuration. * * @return This routine does not return any value. * * @since XT 1.0 */ XTCDECL VOID BlpParseCommandLineOptions(VOID) { EFI_GUID LIPGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; PEFI_LOADED_IMAGE_PROTOCOL LoadedImage; EFI_STATUS Status; /* Handle loaded image protocol */ Status = EfiSystemTable->BootServices->HandleProtocol(EfiImageHandle, &LIPGuid, (PVOID *)&LoadedImage); if(Status == STATUS_EFI_SUCCESS) { /* Check if launched from UEFI shell */ if(LoadedImage && LoadedImage->LoadOptions) { /* Update global boot loader configuration */ BlpUpdateGlobalConfiguration(LoadedImage->LoadOptions); } } } /** * Updates XTLDR configuration based on provided options. * * @param Options * Supplies a formatted list of options to be processed and stored in global configuration. * * @return This routine does not return any value. * * @since XT 1.0 */ XTCDECL VOID BlpUpdateGlobalConfiguration(IN PWCHAR Options) { PWCHAR Argument, LastArg; SIZE_T Length; /* Tokenize provided options */ Argument = RtlTokenizeWideString(Options, L" ", &LastArg); /* Iterate over all arguments passed to boot loader */ while(Argument != NULL) { /* 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); /* 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); /* 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) { /* 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'; } /* Take next argument */ Argument = RtlTokenizeWideString(NULL, L" ", &LastArg); } }