UEFI 基础教程 (十四) - 设置默认启动项为UEFI Shell
一 编写源代码
OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
UINTN
BootOptionPriority (
CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
)
{
DEBUG ((EFI_D_ERROR," [CSDN] BootOptionPriority %S .\\n", BootOption->Description));
if (StrCmp (BootOption->Description, L"Boot Device List") == 0) {
return 4;
}
//
// Make sure Shell is last
//
if ( StrStr (BootOption->Description, L"EFI Internal Shell" ) != NULL) {
return 1;
}
return 30;
}
/
GC_TODO: add routine description@param Left - GC_TODO: add arg description
@param Right - GC_TODO: add arg description@retval (BOOLEAN) (BootOptionPriority (Left) < BootOptionPriority (Right)) - GC_TODO: add retval description
/
INTN
EFIAPI
CompareBootOption (
IN CONST VOID *Buffer1,
IN CONST VOID *Buffer2
)
{
return (BOOLEAN) (BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Buffer1) > BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION *) Buffer2));
}
VOID
EFIAPI
PlatformBootManagerAfterConsole (
VOID
)
{
//
// Register UEFI Shell
//
PlatformRegisterFvBootOption (
&gUefiShellFileGuid, L"EFI Internal Shell", LOAD_OPTION_ACTIVE
);
…
//Add default boot first option as uefi shell
DEBUG ((EFI_D_ERROR," [CSDN]: EfiBootManagerSortLoadOptionVariable before.\\n"));
EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
DEBUG ((EFI_D_ERROR," [CSDN]: EfiBootManagerSortLoadOptionVariable after.\\n"));
…
}
二、 编译生成EFI文件 & 运行
设置Shell为默认启动项后,BIOS启动会优先加载Shell(对于OVMD而言就不用等待前面的PXE、QEMU USB加载了, 可以节省时间)。 当然如果需要设置其他的启动项为默认项,只需要修改BootOptionPriority 中 StrCmp (BootOption->Description, L"EFI Internal Shell")为 StrCmp (BootOption->Description, L"XXXX")。