Enhance grub.cfg to support CentOS

CentOS live CD iso image has different path for grub.cfg file. It
also used "linuxefi" and "initrdefi" for keywords. This patch added
support for it. With this patch, verified it can boot to CentOS
live-cd on APL platform.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
This commit is contained in:
Maurice Ma 2020-11-29 17:09:34 -08:00
parent 5f1923604d
commit e51ab53016
2 changed files with 31 additions and 9 deletions

View File

@ -29,14 +29,19 @@ ParseLinuxBootConfig (
UINT32 Idx;
UINT32 LineLen;
UINT32 EntryNum;
BOOLEAN FirstEntry;
BOOLEAN FoundEntry;
BOOLEAN IsKernel;
BOOLEAN IsInitRd;
MenuEntry = LinuxBootCfg->MenuEntry;
FirstEntry = TRUE;
FoundEntry = FALSE;
EntryNum = 0;
CurrLine = CfgBuffer;
while ((CurrLine != NULL) && (EntryNum < MAX_BOOT_MENU_ENTRY)) {
IsKernel = FALSE;
IsInitRd = FALSE;
NextLine = GetNextLine (CurrLine, &LineLen);
EndLine = CurrLine + LineLen;
CurrLine = TrimLeft (CurrLine);
@ -64,8 +69,8 @@ ParseLinuxBootConfig (
}
} else if (MatchKeyWord (CurrLine, "menuentry") > 0) {
// Mark boot option name
if (FirstEntry) {
FirstEntry = FALSE;
if (!FoundEntry) {
FoundEntry = TRUE;
} else {
EntryNum++;
}
@ -86,7 +91,19 @@ ParseLinuxBootConfig (
}
} else if (MatchKeyWord (CurrLine, "linux") > 0) {
CurrLine += 5;
IsKernel = TRUE;
} else if (MatchKeyWord (CurrLine, "linuxefi") > 0) {
CurrLine += 8;
IsKernel = TRUE;
} else if (MatchKeyWord (CurrLine, "initrd") > 0) {
CurrLine += 6;
IsInitRd = TRUE;
} else if (MatchKeyWord (CurrLine, "initrdefi") > 0) {
CurrLine += 9;
IsInitRd = TRUE;
}
if (IsKernel) {
// Mark kernel path
CurrLine = TrimLeft (CurrLine);
MenuEntry[EntryNum].Kernel.Pos = (UINT32)(CurrLine - CfgBuffer);
@ -98,9 +115,9 @@ ParseLinuxBootConfig (
MenuEntry[EntryNum].Command.Pos = (UINT32)(CurrLine - CfgBuffer);
EndLine = TrimRight (EndLine);
MenuEntry[EntryNum].Command.Len = (UINT32)(EndLine - CfgBuffer - MenuEntry[EntryNum].Command.Pos + 1);
} else if (MatchKeyWord (CurrLine, "initrd") > 0) {
CurrLine += 6;
}
if (IsInitRd) {
// Mark initrd path
CurrLine = TrimLeft (CurrLine);
MenuEntry[EntryNum].InitRd.Pos = (UINT32)(CurrLine - CfgBuffer);
@ -112,6 +129,10 @@ ParseLinuxBootConfig (
}
// Make sure the settings are reasonable
if (FoundEntry) {
EntryNum += 1;
}
LinuxBootCfg->EntryNum = EntryNum;
if (LinuxBootCfg->Settings.Default >= (UINT32)EntryNum) {
LinuxBootCfg->Settings.Default = 0;

View File

@ -14,9 +14,10 @@ typedef struct {
LOADED_IMAGE *LoadedImageList[LoadImageTypeMax];
} LOADED_IMAGES_INFO;
STATIC CONST CHAR16 *mConfigFileName[2] = {
STATIC CONST CHAR16 *mConfigFileName[3] = {
L"config.cfg",
L"boot/grub/grub.cfg"
L"boot/grub/grub.cfg",
L"EFI/BOOT/grub.cfg"
};
/**
@ -422,7 +423,7 @@ GetTraditionalLinux (
DEBUG ((DEBUG_INFO, "Try booting Linux from config file ...\n"));
for (Index = 0; Index < (UINTN)(FeaturePcdGet (PcdGrubBootCfgEnabled) ? 2 : 1); Index++) {
for (Index = 0; Index < (UINTN)(FeaturePcdGet (PcdGrubBootCfgEnabled) ? 3 : 1); Index++) {
DEBUG ((DEBUG_INFO, "Checking %s\n",mConfigFileName[Index]));
ConfigFile = NULL;
ConfigFileSize = 0;