Currently BdsEntry caches BootNext before calling PlatformBootManagerLib APIs, with the result that: - If BootNext is already set, a BootNext value written by the APIs will be ignored and deleted, and the current boot will use the cached BootNext value. - If BootNext is not present, a BootNext value written by the APIs will have no effect on the current boot, but will be used by the next boot.
This patch adds PcdAllowBootNextFromPlatformBootManagerLib so that a platform can enable PlatformBootManagerLib API calls to set BootNext to control the current boot. - If the PCD is FALSE (default), there is no change. - If the PCD is TRUE, then a BootNext value written by the PlatformBootManagerLib APIs will affect the current boot. Signed-off-by: Jeshua Smith <jesh...@nvidia.com> --- MdeModulePkg/MdeModulePkg.dec | 7 +++++ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf | 27 ++++++++++--------- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 34 ++++++++++++++++++------ 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 9605c617b7..0e74131712 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1093,6 +1093,13 @@ # @Prompt Enable UEFI Stack Guard. gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055 + ## Indicates whether PlatformBootManagerLib code can set BootNext for the current boot. + # If enabled, setting BootNext in PlatformBootManagerLib controls the current boot.<BR><BR> + # TRUE - BootNext value from PlatformBootManagerLib will affect the current boot.<BR> + # FALSE - BootNext value from PlatformBootManagerLib will affect the subsequent boot (or be ignored if already set).<BR> + # @Prompt Allow PlatformBootManagerLib to set BootNext for the current boot. + gEfiMdeModulePkgTokenSpaceGuid.PcdAllowBootNextFromPlatformBootManagerLib|FALSE|BOOLEAN|0x30001056 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Dynamic type PCD can be registered callback function for Pcd setting action. # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of callback function diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf index 5bac635def..b7a3560f5f 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf @@ -85,19 +85,20 @@ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES [Pcd] - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangCodes ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLang ## SOMETIMES_CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLangCodes ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangCodes ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLang ## SOMETIMES_CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLangCodes ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdAllowBootNextFromPlatformBootManagerLib ## CONSUMES [Depex] TRUE diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index 766dde3aae..6450406cce 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -787,15 +787,19 @@ BdsEntry ( // // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs - // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot. - // - GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); - if (DataSize != sizeof (UINT16)) { - if (BootNext != NULL) { - FreePool (BootNext); - } + // if the Platform isn't allowed to override BootNext. + // If "BootNext" was already set, a "BootNext" value set in PlatformBootManagerLib APIs + // will be ignored; otherwise it will not take effect until the next boot. + // + if (!PcdGetBool (PcdAllowBootNextFromPlatformBootManagerLib)) { + GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); + if (DataSize != sizeof (UINT16)) { + if (BootNext != NULL) { + FreePool (BootNext); + } - BootNext = NULL; + BootNext = NULL; + } } // @@ -1048,6 +1052,20 @@ BdsEntry ( EfiBootManagerHotkeyBoot (); + // + // If PlatformBootManagerLib APIs are allowed to override BootNext, read it just before use + // + if (PcdGetBool (PcdAllowBootNextFromPlatformBootManagerLib)) { + GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); + if (DataSize != sizeof (UINT16)) { + if (BootNext != NULL) { + FreePool (BootNext); + } + + BootNext = NULL; + } + } + if (BootNext != NULL) { // // Delete "BootNext" NV variable before transferring control to it to prevent loops. -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98905): https://edk2.groups.io/g/devel/message/98905 Mute This Topic: https://groups.io/mt/96382214/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-