226 lines
6.5 KiB
C
226 lines
6.5 KiB
C
/**
|
|
* PROJECT: ExectOS
|
|
* COPYRIGHT: See COPYING.md in the top level directory
|
|
* FILE: xtldr/config.c
|
|
* DESCRIPTION: XT Boot Loader Configuration
|
|
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
|
* Jozef Nagy <schkwve@gmail.com>
|
|
*/
|
|
|
|
#include <xtldr.h>
|
|
|
|
/**
|
|
* Parses configuration INI file contents.
|
|
*
|
|
* @param FileContents
|
|
* Supplies a pointer to a 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 returns a status code.
|
|
*
|
|
* @since XT 1.0
|
|
*/
|
|
XTCDECL
|
|
XTSTATUS
|
|
BlConfigParseIniFile(IN PWCHAR FileContents,
|
|
OUT PLIST_ENTRY Sections)
|
|
{
|
|
PWCHAR Line, LastLine, Key, Value;
|
|
SIZE_T Length, KeyLength;
|
|
|
|
UINT Error;
|
|
|
|
/* There's not error at the moment */
|
|
Error = 0;
|
|
|
|
/* Tokenize provided options */
|
|
Line = RtlWideStringTokenize(FileContents, L"\n", &LastLine);
|
|
|
|
while(Line != NULL)
|
|
{
|
|
Length = RtlWideStringLength(Line, 0);
|
|
|
|
/* Don't parse a blank line */
|
|
if(Length <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
/* Parse */
|
|
if (Length < 1)
|
|
{
|
|
/* Blank line */
|
|
}
|
|
else if (RtlWideStringCompare(Line, L"#", 1) == 0 ||
|
|
RtlWideStringCompare(Line, L";", 1) == 0)
|
|
{
|
|
/* Don't parse a comment */
|
|
}
|
|
else if (RtlWideStringCompare(Line, L"[", 1) == 0 &&
|
|
RtlWideStringCompare(Line + Length - 3, L"]", 1) == 0)
|
|
{
|
|
|
|
/* Remove brackets around section name */
|
|
PWCHAR SectionName = Line + 1;
|
|
SectionName[Length - 3] = 0;
|
|
|
|
/* Save section name */
|
|
BlConsolePrint(L"Section: %S\n", SectionName);
|
|
}
|
|
else
|
|
{
|
|
KeyLength = 0;
|
|
|
|
/* Set key=value pair to the entire line for further processing */
|
|
Value = Line;
|
|
Key = Line;
|
|
|
|
/* Get the value */
|
|
while(Value != 0 &&
|
|
RtlWideStringCompare(Value, L"=", 1) != 0)
|
|
{
|
|
Value++;
|
|
KeyLength++;
|
|
}
|
|
|
|
/* Get rid of the leading '=' */
|
|
Value++;
|
|
|
|
/* Set the key */
|
|
Key[KeyLength] = 0;
|
|
|
|
BlConsolePrint(L"Key: %S\n Value: %S\n", Key, Value);
|
|
}
|
|
|
|
if(Error == 1)
|
|
{
|
|
/* Display error message and exit */
|
|
BlConsolePrint(L"Syntax error\n");
|
|
return STATUS_INVALID_PARAMETER;
|
|
}
|
|
|
|
/* Take next line */
|
|
Line = RtlWideStringTokenize(NULL, L"\n", &LastLine);
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* 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 = RtlWideStringTokenize(Options, L" ", &LastArg);
|
|
|
|
/* Iterate over all arguments passed to boot loader */
|
|
while(Argument != NULL)
|
|
{
|
|
/* Check all provided parameters */
|
|
if(RtlWideStringCompare(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)) - 1);
|
|
BlpConfiguration.Default[Length] = '\0';
|
|
}
|
|
else if(RtlWideStringCompare(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)) - 1);
|
|
BlpConfiguration.Debug[Length] = '\0';
|
|
}
|
|
}
|
|
else if(RtlWideStringCompare(Argument, L"SHELL", 5) == 0)
|
|
{
|
|
/* Force shell mode */
|
|
BlpConfiguration.Shell = TRUE;
|
|
}
|
|
else if(RtlWideStringCompare(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(RtlWideStringCompare(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)) - 1);
|
|
BlpConfiguration.Tune[Length] = '\0';
|
|
}
|
|
|
|
/* Take next argument */
|
|
Argument = RtlWideStringTokenize(NULL, L" ", &LastArg);
|
|
}
|
|
}
|