]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery
authorZhichao Gao <zhichao.gao@intel.com>
Wed, 22 May 2019 00:59:45 +0000 (08:59 +0800)
committerHao A Wu <hao.a.wu@intel.com>
Mon, 1 Jul 2019 06:59:20 +0000 (14:59 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1678

Use the PcdPlatformRecoverySupport to control the function
of platform recovery in BDS.
First, set the variable's ("OsIndicationsSupported")
EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY bit base on the pcd.
It would affect the variable "OsIndications".
While the platform does not support the platform recovery,
it is inappropriate to set a PlatformRecovery#### variable. So
skip setting the variable. But it should remain the behavior of
booting from a default file path (such as \EFI\BOOT\BOOTX64.EFI)
to be compatible with the previous version UEFI spec.

Add memory check before build platform default boot option. If
fail to allocate memory for the defualt boot file path, put the
system into dead loop to indicate it is unable to boot.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
MdeModulePkg/Universal/BdsDxe/BdsEntry.c

index 3d13c725ce51b7ce01f672873cc109ce2cae099a..9310b4dccb184ad3aa33746c972dbb208e5627e1 100644 (file)
@@ -96,6 +96,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable              ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport              ## CONSUMES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport           ## CONSUMES\r
 \r
 [Depex]\r
   TRUE\r
index 2a4ae9f488c36568048868b23b01762dbd5a0596..f3d5e5ac0615a7abbf55bbaf523a1d0238365faa 100644 (file)
@@ -546,10 +546,14 @@ BdsFormalizeOSIndicationVariable (
   //\r
   Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
   if (Status != EFI_NOT_FOUND) {\r
-    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
+    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;\r
     EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
   } else {\r
-    OsIndicationSupport = EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
+    OsIndicationSupport = 0;\r
+  }\r
+\r
+  if (PcdGetBool (PcdPlatformRecoverySupport)) {\r
+    OsIndicationSupport |= EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;\r
   }\r
 \r
   if (PcdGetBool(PcdCapsuleOnDiskSupport)) {\r
@@ -666,6 +670,7 @@ BdsEntry (
   BOOLEAN                         BootSuccess;\r
   EFI_DEVICE_PATH_PROTOCOL        *FilePath;\r
   EFI_STATUS                      BootManagerMenuStatus;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;\r
 \r
   HotkeyTriggered = NULL;\r
   Status          = EFI_SUCCESS;\r
@@ -767,14 +772,13 @@ BdsEntry (
   //\r
   InitializeLanguage (TRUE);\r
 \r
-  //\r
-  // System firmware must include a PlatformRecovery#### variable specifying\r
-  // a short-form File Path Media Device Path containing the platform default\r
-  // file path for removable media\r
-  //\r
   FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
+  if (FilePath == NULL) {\r
+    DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot file path. Unable to boot.\n"));\r
+    CpuDeadLoop ();\r
+  }\r
   Status = EfiBootManagerInitializeLoadOption (\r
-             &LoadOption,\r
+             &PlatformDefaultBootOption,\r
              LoadOptionNumberUnassigned,\r
              LoadOptionTypePlatformRecovery,\r
              LOAD_OPTION_ACTIVE,\r
@@ -784,24 +788,31 @@ BdsEntry (
              0\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
-  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
-  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions, LoadOptionCount) == -1) {\r
-    for (Index = 0; Index < LoadOptionCount; Index++) {\r
-      //\r
-      // The PlatformRecovery#### options are sorted by OptionNumber.\r
-      // Find the the smallest unused number as the new OptionNumber.\r
-      //\r
-      if (LoadOptions[Index].OptionNumber != Index) {\r
-        break;\r
+\r
+  //\r
+  // System firmware must include a PlatformRecovery#### variable specifying\r
+  // a short-form File Path Media Device Path containing the platform default\r
+  // file path for removable media if the platform supports Platform Recovery.\r
+  //\r
+  if (PcdGetBool (PcdPlatformRecoverySupport)) {\r
+    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
+    if (EfiBootManagerFindLoadOption (&PlatformDefaultBootOption, LoadOptions, LoadOptionCount) == -1) {\r
+      for (Index = 0; Index < LoadOptionCount; Index++) {\r
+        //\r
+        // The PlatformRecovery#### options are sorted by OptionNumber.\r
+        // Find the the smallest unused number as the new OptionNumber.\r
+        //\r
+        if (LoadOptions[Index].OptionNumber != Index) {\r
+          break;\r
+        }\r
       }\r
+      PlatformDefaultBootOption.OptionNumber = Index;\r
+      Status = EfiBootManagerLoadOptionToVariable (&PlatformDefaultBootOption);\r
+      ASSERT_EFI_ERROR (Status);\r
     }\r
-    LoadOption.OptionNumber = Index;\r
-    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);\r
-    ASSERT_EFI_ERROR (Status);\r
+    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
   }\r
-  EfiBootManagerFreeLoadOption (&LoadOption);\r
   FreePool (FilePath);\r
-  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
 \r
   //\r
   // Report Status Code to indicate connecting drivers will happen\r
@@ -1047,10 +1058,18 @@ BdsEntry (
   }\r
 \r
   if (!BootSuccess) {\r
-    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
-    ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
-    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
+    if (PlatformRecovery) {\r
+      LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);\r
+      ProcessLoadOptions (LoadOptions, LoadOptionCount);\r
+      EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);\r
+    } else {\r
+      //\r
+      // When platform recovery is not enabled, still boot to platform default file path.\r
+      //\r
+      EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);\r
+    }\r
   }\r
+  EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);\r
 \r
   DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));\r
   PlatformBootManagerUnableToBoot ();\r