From 689d3fc36ca662d5be40da162bf9c2f86489649c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kr=C3=B3l?= Date: Mon, 23 Oct 2023 23:01:51 +0200 Subject: [PATCH] OvmfPkg: register ipxe.efi file as boot option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add ipxe.efi to the firmware volume. * Based on NetBootEnable UEFI variable register or unregister iPXE as boot option. Signed-off-by: Piotr Król --- .../PlatformBootManagerLib/BdsPlatform.c | 42 ++++++++++++++++++- .../PlatformBootManagerLib.inf | 6 +++ OvmfPkg/OvmfPkg.dec | 4 ++ OvmfPkg/OvmfPkgX64.fdf | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c index 1a5e8cd03b..f9c9969ba0 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -1699,6 +1699,9 @@ PlatformBootManagerAfterConsole ( ) { EFI_BOOT_MODE BootMode; + BOOLEAN NetBootEnabled; + UINTN VarSize; + EFI_STATUS Status; DEBUG ((EFI_D_INFO, "PlatformBootManagerAfterConsole\n")); @@ -1758,11 +1761,48 @@ PlatformBootManagerAfterConsole ( EfiBootManagerRefreshAllBootOption (); + VarSize = sizeof (NetBootEnabled); + Status = gRT->GetVariable ( + L"NetworkBoot", + &gDasharoSystemFeaturesGuid, + NULL, + &VarSize, + &NetBootEnabled + ); + + // + // Register iPXE + // + if ((Status != EFI_NOT_FOUND) && (VarSize == sizeof(NetBootEnabled))) { + if (NetBootEnabled) { + DEBUG((DEBUG_INFO, "Registering iPXE boot option by variable\n")); + PlatformRegisterFvBootOption (PcdGetPtr (PcdiPXEFile), + (CHAR16 *) PcdGetPtr(PcdiPXEOptionName), + LOAD_OPTION_ACTIVE, + FALSE); + } else { + DEBUG((DEBUG_INFO, "Unregistering iPXE boot option by variable\n")); + PlatformUnregisterFvBootOption (PcdGetPtr (PcdiPXEFile), + (CHAR16 *) PcdGetPtr(PcdiPXEOptionName), + LOAD_OPTION_ACTIVE); + } + } else if ((Status == EFI_NOT_FOUND) && FixedPcdGetBool(PcdDefaultNetworkBootEnable)) { + DEBUG((DEBUG_INFO, "Registering iPXE boot option by policy\n")); + PlatformRegisterFvBootOption (PcdGetPtr (PcdiPXEFile), + (CHAR16 *) PcdGetPtr(PcdiPXEOptionName), + LOAD_OPTION_ACTIVE, + FALSE); + } else { + DEBUG((DEBUG_INFO, "Unregistering iPXE boot option\n")); + PlatformUnregisterFvBootOption (PcdGetPtr (PcdiPXEFile), + (CHAR16 *) PcdGetPtr(PcdiPXEOptionName), + LOAD_OPTION_ACTIVE); + } // // Register UEFI Shell // PlatformRegisterFvBootOption ( - &gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE + &gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE, FALSE ); RemoveStaleFvFileOptions (); diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index e403767005..142734f063 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -33,6 +33,8 @@ OvmfPkg/OvmfPkg.dec SecurityPkg/SecurityPkg.dec ShellPkg/ShellPkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + DasharoModulePkg/DasharoModulePkg.dec [LibraryClasses] BaseLib @@ -61,6 +63,9 @@ gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId + gUefiPayloadPkgTokenSpaceGuid.PcdiPXEFile + gUefiPayloadPkgTokenSpaceGuid.PcdiPXEOptionName + gDasharoSystemFeaturesTokenSpaceGuid.PcdDefaultNetworkBootEnable gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate ## CONSUMES gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits ## CONSUMES @@ -84,3 +89,4 @@ gRootBridgesConnectedEventGroupGuid gUefiShellFileGuid gEfiTtyTermGuid + gDasharoSystemFeaturesGuid diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index eae4d5e7ab..f4b5cc33ed 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -256,6 +256,10 @@ ## Number of page frames to use for storing grant table entries. gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33 + ## FFS filename to find the ipxe application. + gUefiPayloadPkgTokenSpaceGuid.PcdiPXEFile|{ 0xC7, 0x53, 0x86, 0xb6, 0xA1, 0xEE, 0x35, 0x44, 0xA1, 0x99, 0xA4, 0x4F, 0x59, 0xE4, 0x47, 0x6C }|VOID*|0x10000006 + gUefiPayloadPkgTokenSpaceGuid.PcdiPXEOptionName|L"iPXE"|VOID*|0x10000007 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index c1b2d2712f..00a1da2300 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -327,7 +327,7 @@ INF MdeModulePkg/Logo/LogoDxe.inf # build system or user should put the ipxe.efi file here before EDK2 build # FILE FREEFORM = B68653C7-EEA1-4435-A199-A44F59E4476C { - SECTION PE32 = UefiPayloadPkg/NetworkDrivers/ipxe.efi + SECTION PE32 = ipxe.efi } !endif