INI configuration parser for XTLDR
This commit is contained in:
parent
a66456979a
commit
cb7f4deb37
@ -20,5 +20,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"terminal.integrated.defaultProfile.linux": "xtchain",
|
"terminal.integrated.defaultProfile.linux": "xtchain",
|
||||||
|
"files.associations": {
|
||||||
|
"globals.h": "c"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,19 @@
|
|||||||
|
|
||||||
#include <xttypes.h>
|
#include <xttypes.h>
|
||||||
|
|
||||||
|
typedef struct _XTBL_INI_SECTION
|
||||||
|
{
|
||||||
|
LIST_ENTRY Flink;
|
||||||
|
LIST_ENTRY Options;
|
||||||
|
PWCHAR SectionName;
|
||||||
|
} XTBL_INI_SECTION, *PXTBL_INI_SECTION;
|
||||||
|
|
||||||
|
typedef struct _XTBL_INI_OPTION
|
||||||
|
{
|
||||||
|
LIST_ENTRY Flink;
|
||||||
|
PWCHAR Name;
|
||||||
|
PWCHAR Value;
|
||||||
|
} XTBL_INI_OPTION, *PXTBL_INI_OPTION;
|
||||||
|
|
||||||
/* XTLDR configuration data */
|
/* XTLDR configuration data */
|
||||||
typedef struct _XTBM_CONFIGURATION
|
typedef struct _XTBM_CONFIGURATION
|
||||||
|
105
xtldr2/config.c
105
xtldr2/config.c
@ -4,10 +4,115 @@
|
|||||||
* FILE: xtldr/config.c
|
* FILE: xtldr/config.c
|
||||||
* DESCRIPTION: XT Boot Loader Configuration
|
* DESCRIPTION: XT Boot Loader Configuration
|
||||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||||
|
* Jozef Nagy <schkwve@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xtbm.h>
|
#include <xtbm.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 returns a status code.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
XTSTATUS
|
||||||
|
BlConfigParseIniFile(IN PWCHAR FileContents,
|
||||||
|
OUT PLIST_ENTRY Sections)
|
||||||
|
{
|
||||||
|
PWCHAR Argument, LastArg, CurrentSectionName;
|
||||||
|
SIZE_T Length;
|
||||||
|
|
||||||
|
/* Set a default section name */
|
||||||
|
CurrentSectionName = L"Unknown";
|
||||||
|
|
||||||
|
/* Tokenize provided options */
|
||||||
|
Argument = RtlWideStringTokenize(FileContents, L"\r\n", &LastArg);
|
||||||
|
|
||||||
|
/* Iterate over all arguments passed to boot loader */
|
||||||
|
while(Argument != NULL)
|
||||||
|
{
|
||||||
|
/* Check every line */
|
||||||
|
if(RtlWideStringCompare(Argument, L"[", 1) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the section name */
|
||||||
|
Argument += 1;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Everything until ']' belongs to the section's name */
|
||||||
|
// CurrentSectionName = RtlWideStringTokenize(Argument, L"]", &LastArg);
|
||||||
|
BlConsolePrint(L"New section: %S\n", CurrentSectionName);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"Default=", 8) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the argument value and calculate argument length */
|
||||||
|
Argument += 8;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Set a default section */
|
||||||
|
BlConsolePrint(L"Setting DEFAULT value to %S\n", Argument);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"Debug=", 6) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the argument value */
|
||||||
|
Argument += 6;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Set a debug port and baud rate */
|
||||||
|
BlConsolePrint(L"Setting DEBUG value to %S\n", Argument);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"Theme=", 6) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the argument value */
|
||||||
|
Argument += 6;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Set a theme name */
|
||||||
|
BlConsolePrint(L"Setting THEME value to %S\n", Argument);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"Timeout=", 8) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the argument value */
|
||||||
|
Argument += 8;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Set a timeout */
|
||||||
|
BlConsolePrint(L"Setting TIMEOUT value to %S\n", Argument);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"Tune=", 5) == 0)
|
||||||
|
{
|
||||||
|
/* Skip to the argument value */
|
||||||
|
Argument += 5;
|
||||||
|
Length = RtlWideStringLength(Argument, 0);
|
||||||
|
|
||||||
|
/* Set a tune */
|
||||||
|
BlConsolePrint(L"Setting TUNE value to %S\n", Argument);
|
||||||
|
}
|
||||||
|
else if(RtlWideStringCompare(Argument, L"#", 1) == 0)
|
||||||
|
{
|
||||||
|
/* We can safely ignore a comment */
|
||||||
|
Argument += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Configuration file might be corrupt */
|
||||||
|
BlConsolePrint(L"Unknown argument: %S\n", Argument);
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Take next argument */
|
||||||
|
Argument = RtlWideStringTokenize(NULL, L"\n", &LastArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses command line arguments and updates global configuration.
|
* Parses command line arguments and updates global configuration.
|
||||||
|
@ -79,6 +79,11 @@ BlpStringFormat(IN BMPRINTCHAR PrintCharRoutine,
|
|||||||
IN PUINT16 Format,
|
IN PUINT16 Format,
|
||||||
IN ...);
|
IN ...);
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
XTSTATUS
|
||||||
|
BlConfigParseIniFile(IN PWCHAR FileContents,
|
||||||
|
OUT PLIST_ENTRY Sections);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
VOID
|
VOID
|
||||||
BlpConfigParseCommandLine(VOID);
|
BlpConfigParseCommandLine(VOID);
|
||||||
|
@ -28,15 +28,22 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
|||||||
IN PEFI_SYSTEM_TABLE SystemTable)
|
IN PEFI_SYSTEM_TABLE SystemTable)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
LIST_ENTRY ConfigSections;
|
||||||
|
|
||||||
/* Set the system table and image handle */
|
/* Set the system table and image handle */
|
||||||
EfiImageHandle = ImageHandle;
|
EfiImageHandle = ImageHandle;
|
||||||
EfiSystemTable = SystemTable;
|
EfiSystemTable = SystemTable;
|
||||||
|
|
||||||
|
|
||||||
|
RtlInitializeListHead(&ConfigSections);
|
||||||
|
|
||||||
/* Initialize UEFI console and early print XTLDR version */
|
/* Initialize UEFI console and early print XTLDR version */
|
||||||
BlConsoleInitialize();
|
BlConsoleInitialize();
|
||||||
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
||||||
|
|
||||||
|
/* Parse INI Configuration file */
|
||||||
|
BlConfigParseIniFile(L"# This is the XT Boot Loader (XTLDR) configuration file. It follows an INI format and is divided into sections, which\r\n# contain a properties. Each property has a name and value delimited by an equal (=) character. Comments must start\r\n# with a semicolon (;) or a hash character (#) and run to the end of the line.\r\n#\r\n# Basic section is [XTLDR] which contains a bootloader specific options:\r\n# Debug - enables the debugging port and consists of two comma-separated parameters: com port and baud rate;\r\n# it is also possible to specify custom port address with: COM0:[address],[baud_rate]\r\n# Default - specifies which operating system listen in config file will be started if no choice is made\r\n# Theme - allows to set a custom theme to personalize XTLDR's look'n'feel\r\n# Timeout - sets the countdown timer (in seconds) before the default OS get started automatically\r\n# Tune - plays a tune on the pcspeaker right before the XTLDR loads\r\n#\r\n# Another type of section is [OS-Section] which adds a new position (operating system) to the boot menu. Each type\r\n# of the operating system provides a set of available parameters. If unsupported option is added, it is being ignored\r\n# by the XT Boot Loader. The available options are:\r\n# SystemName - sets a long operating system name that will be shown on the boot menu\r\n# SystemType - specifies an OS type from a predefined list of supported boot protocols\r\n# SystemPath - the ARC path, eg. multi(0)disk(0)rdisk(0)partition(1)\r\n# KernelFile - sets kernel filename with optional path relative to SystemPath\r\n# InitrdFile - sets initramfs image filename with optional path relative to SystemPath\r\n# HalFile - sets HAL filename with optional path relative to SystemPath\r\n# Parameters - specifies extra boot options for the kernel\r\n[XTLDR]Tune=400 880 2 988 2 783 2 392 2 587 3Debug=COM1,115200Timeout=30Theme=FancyDefault=ExectOS[ExectOS]SystemName=\"ExectOS Operating System\"SystemType=XTOSSystemPath=multi(0)disk(0)rdisk(0)partition(1)/ExectOSKernelFile=xtoskrnl.exeParameters=DEBUG DEBUGPORT=COM1,115200[Windows]SystemName=\"Microsoft Windows 2000\"SystemType=NT50SystemPath=multi(0)disk(0)rdisk(0)partition(2)/WindowsKernelFile=ntoskrnl.exeHalFile=hal.dllParameters=/NOGUIBOOT /MININT[Linux]SystemName=\"GNU/Linux\"SystemType=LINUXSystemPath=multi(0)disk(0)rdisk(0)partition(3)/bootKernelFile=vmlinuzInitrdFile=initramfs.cpio.gzParameters=root=/dev/xvda3 rootfstype=ext4", &ConfigSections);
|
||||||
|
|
||||||
/* Temporary infinite loop */
|
/* Temporary infinite loop */
|
||||||
for(;;);
|
for(;;);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user