From 74ceeb9bee5a67227411e3926d91f5b2408c683b Mon Sep 17 00:00:00 2001 From: Aaron <105021049+apop5@users.noreply.github.com> Date: Mon, 17 Apr 2023 12:44:26 -0700 Subject: [PATCH] Infinite boot retries (#347) ## Description This is a draft of infinite boot retries based on a newly created PCD. When true, the system will never stop retrying the boot options. PCD default is FALSE to match existing functionality. For each item, place an "x" in between `[` and `]` if true. Example: `[x]`. _(you can also check items in the GitHub UI)_ - [X] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested ## Integration Instructions n/a --- MdeModulePkg/MdeModulePkg.dec | 9 ++++++ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf | 1 + MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 40 ++++++++++++++++++------ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 90e8d0dad4..5b5fcfd146 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1272,6 +1272,15 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSupportAlternativeQueueSize|FALSE|BOOLEAN|0x40000151 # MU_CHANGE [END] + # MU_CHANGE [BEGIN] - Support indefinite boot retries + # # Some platforms require that all EfiLoadOptions are retried until one of the options + # # succeeds. When True, this Pcd will force Bds to retry all the valid EfiLoadOptions + # # indefinitely until one of the options succeeds. + # # TRUE - Efi boot options will be retried indefinitely. + # # FALSE - Efi boot options will not be retried. + gEfiMdeModulePkgTokenSpaceGuid.PcdSupportInfiniteBootRetries|FALSE|BOOLEAN|0x40000152 + # MU_CHANGE [END] + [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 9310b4dccb..2fc9d54c56 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf @@ -97,6 +97,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSupportInfiniteBootRetries ## CONSUMES // MU_CHANGE [Depex] TRUE diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index 4fe354f6c1..56e1bc20a3 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -417,16 +417,38 @@ BootBootOptions ( PlatformBootManagerProcessBootCompletion (&BootOptions[Index]); // MSCHANGE 00076 - record boot status - // - // If the boot via Boot#### returns with a status of EFI_SUCCESS, platform firmware - // supports boot manager menu, and if firmware is configured to boot in an - // interactive mode, the boot manager will stop processing the BootOrder variable and - // present a boot manager menu to the user. - // - if ((BootManagerMenu != NULL) && (BootOptions[Index].Status == EFI_SUCCESS)) { - EfiBootManagerBoot (BootManagerMenu); - break; + // MU_CHANGE [BEGIN] - Support infinite boot retries + // Changes for PcdSupportInfiniteBootRetries are meant to minimize upkeep in mu repos. + // If/when upstreaming this change, refactoring calling loop in BdsEntry() would be + // better location. + if (!PcdGetBool (PcdSupportInfiniteBootRetries)) { + // MU_CHANGE [END] - Support infinite boot retries + + // + // If the boot via Boot#### returns with a status of EFI_SUCCESS, platform firmware + // supports boot manager menu, and if firmware is configured to boot in an + // interactive mode, the boot manager will stop processing the BootOrder variable and + // present a boot manager menu to the user. + // + if ((BootManagerMenu != NULL) && (BootOptions[Index].Status == EFI_SUCCESS)) { + EfiBootManagerBoot (BootManagerMenu); + break; + } + + // MU_CHANGE [BEGIN]- Support infinite boot retries + // Changes for PcdSupportInfiniteBootRetries are meant to minimize upkeep in mu repos. + // If/when upstreaming this change, refactoring calling loop in BdsEntry() would be + // better location. + } + + if (PcdGetBool (PcdSupportInfiniteBootRetries)) { + if (Index == (BootOptionCount - 1)) { + // Resetting index back to -1 so loop increment will result in Index 0 for next iteration + Index = (UINTN)-1; + } } + + // MU_CHANGE [END]- Support infinite boot retries } return (BOOLEAN)(Index < BootOptionCount);