public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V3 0/2] Use a pcd to control Platform Recovery behavior
@ 2019-06-04  1:05 Gao, Zhichao
  2019-06-04  1:05 ` [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit Gao, Zhichao
  2019-06-04  1:05 ` [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery Gao, Zhichao
  0 siblings, 2 replies; 8+ messages in thread
From: Gao, Zhichao @ 2019-06-04  1:05 UTC (permalink / raw)
  To: devel
  Cc: Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

V1:
Add a pcd PcdPlatformRecoverySupport to control the variable
PlatformRecovery#### and the EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY
bit of variable "OsIndicationsSupported".

V2:
While PcdPlatformRecoverySupport is FALSE, do not set a PlatformRecovery####
Variable.
But remain boot from a default file path(such as \EFI\BOOT\BOOTX64.EFI).
Add memory check before build platform default boot option.

V3:
Modify the memory check operation. 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>

Bret Barkelew (1):
  MdeModulePkg: Add a pcd to set the OS indications bit

Zhichao Gao (1):
  MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery

 MdeModulePkg/MdeModulePkg.dec            |  6 ++
 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  3 +-
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 71 +++++++++++++++---------
 3 files changed, 53 insertions(+), 27 deletions(-)

-- 
2.21.0.windows.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit
  2019-06-04  1:05 [PATCH V3 0/2] Use a pcd to control Platform Recovery behavior Gao, Zhichao
@ 2019-06-04  1:05 ` Gao, Zhichao
  2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
  2019-06-13  7:39   ` Wu, Hao A
  2019-06-04  1:05 ` [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery Gao, Zhichao
  1 sibling, 2 replies; 8+ messages in thread
From: Gao, Zhichao @ 2019-06-04  1:05 UTC (permalink / raw)
  To: devel
  Cc: Bret Barkelew, Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao,
	Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1678

Add a pcd PcdPlatformRecoverySupport to conditionally
set an OS indications bit and set the 'PlatformRecovery####'
variable. This pcd would also control whether the BDS
support platform recovery or not.

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>
---
 MdeModulePkg/MdeModulePkg.dec | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 0a9fcddecc..da2b85770c 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1660,6 +1660,12 @@
   # @Prompt Reset on memory type information change.
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|TRUE|BOOLEAN|0x00010056
 
+  ## Indicates if the BDS supports Platform Recovery.<BR><BR>
+  #   TRUE  - BDS supports Platform Recovery.<BR>
+  #   FALSE - BDS does not support Platform Recovery.<BR>
+  # @Prompt Support Platform Recovery.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport|TRUE|BOOLEAN|0x00010078
+
   ## Specify the foreground color for Subtile text in HII Form Browser. The default value is EFI_BLUE.
   #  Only following values defined in UEFI specification are valid:<BR><BR>
   #  0x00 (EFI_BLACK)<BR>
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery
  2019-06-04  1:05 [PATCH V3 0/2] Use a pcd to control Platform Recovery behavior Gao, Zhichao
  2019-06-04  1:05 ` [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit Gao, Zhichao
@ 2019-06-04  1:05 ` Gao, Zhichao
  2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
  2019-06-13  7:39   ` Wu, Hao A
  1 sibling, 2 replies; 8+ messages in thread
From: Gao, Zhichao @ 2019-06-04  1:05 UTC (permalink / raw)
  To: devel
  Cc: Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

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>
---
 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  3 +-
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 71 +++++++++++++++---------
 2 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
index 6913389d34..7f94ca17df 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
@@ -5,7 +5,7 @@
 #  gEfiBdsArchProtocolGuid. After DxeCore finish dispatching, DxeCore will invoke Entry
 #  interface of protocol gEfiBdsArchProtocolGuid, then BDS phase is entered.
 #
-#  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -95,6 +95,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand              ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable              ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport           ## CONSUMES
 
 [Depex]
   TRUE
diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
index 9d312bd982..8c8a0b5236 100644
--- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
+++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -5,7 +5,7 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
   to enter BDS phase.
 
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -546,10 +546,14 @@ BdsFormalizeOSIndicationVariable (
   //
   Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
   if (Status != EFI_NOT_FOUND) {
-    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI | EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
+    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
     EfiBootManagerFreeLoadOption (&BootManagerMenu);
   } else {
-    OsIndicationSupport = EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
+    OsIndicationSupport = 0;
+  }
+
+  if (PcdGetBool (PcdPlatformRecoverySupport)) {
+    OsIndicationSupport |= EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
   }
 
   Status = gRT->SetVariable (
@@ -662,6 +666,7 @@ BdsEntry (
   BOOLEAN                         BootSuccess;
   EFI_DEVICE_PATH_PROTOCOL        *FilePath;
   EFI_STATUS                      BootManagerMenuStatus;
+  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;
 
   HotkeyTriggered = NULL;
   Status          = EFI_SUCCESS;
@@ -763,14 +768,13 @@ BdsEntry (
   //
   InitializeLanguage (TRUE);
 
-  //
-  // System firmware must include a PlatformRecovery#### variable specifying
-  // a short-form File Path Media Device Path containing the platform default
-  // file path for removable media
-  //
   FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);
+  if (FilePath == NULL) {
+    DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot file path. Unable to boot.\n"));
+    CpuDeadLoop ();
+  }
   Status = EfiBootManagerInitializeLoadOption (
-             &LoadOption,
+             &PlatformDefaultBootOption,
              LoadOptionNumberUnassigned,
              LoadOptionTypePlatformRecovery,
              LOAD_OPTION_ACTIVE,
@@ -780,24 +784,31 @@ BdsEntry (
              0
              );
   ASSERT_EFI_ERROR (Status);
-  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
-  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions, LoadOptionCount) == -1) {
-    for (Index = 0; Index < LoadOptionCount; Index++) {
-      //
-      // The PlatformRecovery#### options are sorted by OptionNumber.
-      // Find the the smallest unused number as the new OptionNumber.
-      //
-      if (LoadOptions[Index].OptionNumber != Index) {
-        break;
+
+  //
+  // System firmware must include a PlatformRecovery#### variable specifying
+  // a short-form File Path Media Device Path containing the platform default
+  // file path for removable media if the platform supports Platform Recovery.
+  //
+  if (PcdGetBool (PcdPlatformRecoverySupport)) {
+    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
+    if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions, LoadOptionCount) == -1) {
+      for (Index = 0; Index < LoadOptionCount; Index++) {
+        //
+        // The PlatformRecovery#### options are sorted by OptionNumber.
+        // Find the the smallest unused number as the new OptionNumber.
+        //
+        if (LoadOptions[Index].OptionNumber != Index) {
+          break;
+        }
       }
+      PlatformDefaultBootOption.OptionNumber = Index;
+      Status = EfiBootManagerLoadOptionToVariable (&PlatformDefaultBootOption);
+      ASSERT_EFI_ERROR (Status);
     }
-    LoadOption.OptionNumber = Index;
-    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
-    ASSERT_EFI_ERROR (Status);
+    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
   }
-  EfiBootManagerFreeLoadOption (&LoadOption);
   FreePool (FilePath);
-  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
 
   //
   // Report Status Code to indicate connecting drivers will happen
@@ -1043,10 +1054,18 @@ BdsEntry (
   }
 
   if (!BootSuccess) {
-    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
-    ProcessLoadOptions (LoadOptions, LoadOptionCount);
-    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
+    if (PlatformRecovery) {
+      LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
+      ProcessLoadOptions (LoadOptions, LoadOptionCount);
+      EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
+    } else {
+      //
+      // When platform recovery is not enabled, still boot to platform default file path.
+      //
+      EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);
+    }
   }
+  EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);
 
   DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));
   PlatformBootManagerUnableToBoot ();
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery
  2019-06-04  1:05 ` [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery Gao, Zhichao
@ 2019-06-04  6:16   ` Ni, Ray
  2019-06-13  7:39   ` Wu, Hao A
  1 sibling, 0 replies; 8+ messages in thread
From: Ni, Ray @ 2019-06-04  6:16 UTC (permalink / raw)
  To: devel@edk2.groups.io, Gao, Zhichao
  Cc: Wang, Jian J, Wu, Hao A, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Gao, Zhichao
> Sent: Tuesday, June 4, 2019 9:05 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao, Liming
> <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to
> control PlatformRecovery
> 
> 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>
> ---
>  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  3 +-
> MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 71 +++++++++++++++---------
>  2 files changed, 47 insertions(+), 27 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> index 6913389d34..7f94ca17df 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> @@ -5,7 +5,7 @@
>  #  gEfiBdsArchProtocolGuid. After DxeCore finish dispatching, DxeCore will
> invoke Entry  #  interface of protocol gEfiBdsArchProtocolGuid, then BDS
> phase is entered.
>  #
> -#  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) 2008 - 2019, Intel Corporation. All rights
> +reserved.<BR>
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -95,6 +95,7 @@
>    gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand
> ## CONSUMES
>    gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable              ##
> SOMETIMES_CONSUMES
>    gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ##
> CONSUMES
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport
> ## CONSUMES
> 
>  [Depex]
>    TRUE
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> index 9d312bd982..8c8a0b5236 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> @@ -5,7 +5,7 @@
>    After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be
> invoked
>    to enter BDS phase.
> 
> -Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
>  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
>  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent @@ -546,10 +546,14 @@
> BdsFormalizeOSIndicationVariable (
>    //
>    Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
>    if (Status != EFI_NOT_FOUND) {
> -    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI |
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> +    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
>      EfiBootManagerFreeLoadOption (&BootManagerMenu);
>    } else {
> -    OsIndicationSupport =
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> +    OsIndicationSupport = 0;
> +  }
> +
> +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> +    OsIndicationSupport |=
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
>    }
> 
>    Status = gRT->SetVariable (
> @@ -662,6 +666,7 @@ BdsEntry (
>    BOOLEAN                         BootSuccess;
>    EFI_DEVICE_PATH_PROTOCOL        *FilePath;
>    EFI_STATUS                      BootManagerMenuStatus;
> +  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;
> 
>    HotkeyTriggered = NULL;
>    Status          = EFI_SUCCESS;
> @@ -763,14 +768,13 @@ BdsEntry (
>    //
>    InitializeLanguage (TRUE);
> 
> -  //
> -  // System firmware must include a PlatformRecovery#### variable
> specifying
> -  // a short-form File Path Media Device Path containing the platform default
> -  // file path for removable media
> -  //
>    FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);
> +  if (FilePath == NULL) {
> +    DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot file
> path. Unable to boot.\n"));
> +    CpuDeadLoop ();
> +  }
>    Status = EfiBootManagerInitializeLoadOption (
> -             &LoadOption,
> +             &PlatformDefaultBootOption,
>               LoadOptionNumberUnassigned,
>               LoadOptionTypePlatformRecovery,
>               LOAD_OPTION_ACTIVE,
> @@ -780,24 +784,31 @@ BdsEntry (
>               0
>               );
>    ASSERT_EFI_ERROR (Status);
> -  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> -  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> LoadOptionCount) == -1) {
> -    for (Index = 0; Index < LoadOptionCount; Index++) {
> -      //
> -      // The PlatformRecovery#### options are sorted by OptionNumber.
> -      // Find the the smallest unused number as the new OptionNumber.
> -      //
> -      if (LoadOptions[Index].OptionNumber != Index) {
> -        break;
> +
> +  //
> +  // System firmware must include a PlatformRecovery#### variable
> + specifying  // a short-form File Path Media Device Path containing the
> + platform default  // file path for removable media if the platform supports
> Platform Recovery.
> +  //
> +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> +    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> +    if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> LoadOptionCount) == -1) {
> +      for (Index = 0; Index < LoadOptionCount; Index++) {
> +        //
> +        // The PlatformRecovery#### options are sorted by OptionNumber.
> +        // Find the the smallest unused number as the new OptionNumber.
> +        //
> +        if (LoadOptions[Index].OptionNumber != Index) {
> +          break;
> +        }
>        }
> +      PlatformDefaultBootOption.OptionNumber = Index;
> +      Status = EfiBootManagerLoadOptionToVariable
> (&PlatformDefaultBootOption);
> +      ASSERT_EFI_ERROR (Status);
>      }
> -    LoadOption.OptionNumber = Index;
> -    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> -    ASSERT_EFI_ERROR (Status);
> +    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
>    }
> -  EfiBootManagerFreeLoadOption (&LoadOption);
>    FreePool (FilePath);
> -  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> 
>    //
>    // Report Status Code to indicate connecting drivers will happen @@ -
> 1043,10 +1054,18 @@ BdsEntry (
>    }
> 
>    if (!BootSuccess) {
> -    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> -    ProcessLoadOptions (LoadOptions, LoadOptionCount);
> -    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> +    if (PlatformRecovery) {
> +      LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> +      ProcessLoadOptions (LoadOptions, LoadOptionCount);
> +      EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> +    } else {
> +      //
> +      // When platform recovery is not enabled, still boot to platform default
> file path.
> +      //
> +      EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);
> +    }
>    }
> +  EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);
> 
>    DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));
>    PlatformBootManagerUnableToBoot ();
> --
> 2.21.0.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit
  2019-06-04  1:05 ` [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit Gao, Zhichao
@ 2019-06-04  6:16   ` Ni, Ray
  2019-06-13  7:39   ` Wu, Hao A
  1 sibling, 0 replies; 8+ messages in thread
From: Ni, Ray @ 2019-06-04  6:16 UTC (permalink / raw)
  To: devel@edk2.groups.io, Gao, Zhichao
  Cc: Bret Barkelew, Wang, Jian J, Wu, Hao A, Zeng, Star, Gao, Liming,
	Sean Brogan, Michael Turner

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Gao, Zhichao
> Sent: Tuesday, June 4, 2019 9:05 AM
> To: devel@edk2.groups.io
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao, Liming
> <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>
> Subject: [edk2-devel] [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the
> OS indications bit
> 
> From: Bret Barkelew <Bret.Barkelew@microsoft.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1678
> 
> Add a pcd PcdPlatformRecoverySupport to conditionally set an OS
> indications bit and set the 'PlatformRecovery####'
> variable. This pcd would also control whether the BDS support platform
> recovery or not.
> 
> 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>
> ---
>  MdeModulePkg/MdeModulePkg.dec | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec index 0a9fcddecc..da2b85770c
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -1660,6 +1660,12 @@
>    # @Prompt Reset on memory type information change.
> 
> gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationCh
> ange|TRUE|BOOLEAN|0x00010056
> 
> +  ## Indicates if the BDS supports Platform Recovery.<BR><BR>
> +  #   TRUE  - BDS supports Platform Recovery.<BR>
> +  #   FALSE - BDS does not support Platform Recovery.<BR>
> +  # @Prompt Support Platform Recovery.
> +
> +
> gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport|TRUE|BO
> OLEAN
> + |0x00010078
> +
>    ## Specify the foreground color for Subtile text in HII Form Browser. The
> default value is EFI_BLUE.
>    #  Only following values defined in UEFI specification are valid:<BR><BR>
>    #  0x00 (EFI_BLACK)<BR>
> --
> 2.21.0.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit
  2019-06-04  1:05 ` [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit Gao, Zhichao
  2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
@ 2019-06-13  7:39   ` Wu, Hao A
  1 sibling, 0 replies; 8+ messages in thread
From: Wu, Hao A @ 2019-06-13  7:39 UTC (permalink / raw)
  To: devel@edk2.groups.io, Gao, Zhichao
  Cc: Bret Barkelew, Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming,
	Sean Brogan, Michael Turner

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Gao, Zhichao
> Sent: Tuesday, June 04, 2019 9:05 AM
> To: devel@edk2.groups.io
> Cc: Bret Barkelew; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming;
> Sean Brogan; Michael Turner
> Subject: [edk2-devel] [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the
> OS indications bit
> 
> From: Bret Barkelew <Bret.Barkelew@microsoft.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1678
> 
> Add a pcd PcdPlatformRecoverySupport to conditionally
> set an OS indications bit and set the 'PlatformRecovery####'
> variable. This pcd would also control whether the BDS
> support platform recovery or not.
> 
> 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>
> ---
>  MdeModulePkg/MdeModulePkg.dec | 6 ++++++


Really sorry for the delayed response.
Please help to update the MdeModulePkg.uni file for adding a new PCD.

With this handled:
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


>  1 file changed, 6 insertions(+)
> 
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec
> index 0a9fcddecc..da2b85770c 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -1660,6 +1660,12 @@
>    # @Prompt Reset on memory type information change.
> 
> gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationC
> hange|TRUE|BOOLEAN|0x00010056
> 
> +  ## Indicates if the BDS supports Platform Recovery.<BR><BR>
> +  #   TRUE  - BDS supports Platform Recovery.<BR>
> +  #   FALSE - BDS does not support Platform Recovery.<BR>
> +  # @Prompt Support Platform Recovery.
> +
> gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport|TRUE|B
> OOLEAN|0x00010078
> +
>    ## Specify the foreground color for Subtile text in HII Form Browser. The
> default value is EFI_BLUE.
>    #  Only following values defined in UEFI specification are valid:<BR><BR>
>    #  0x00 (EFI_BLACK)<BR>
> --
> 2.21.0.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery
  2019-06-04  1:05 ` [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery Gao, Zhichao
  2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
@ 2019-06-13  7:39   ` Wu, Hao A
  2019-06-13  7:51     ` Gao, Zhichao
  1 sibling, 1 reply; 8+ messages in thread
From: Wu, Hao A @ 2019-06-13  7:39 UTC (permalink / raw)
  To: devel@edk2.groups.io, Gao, Zhichao
  Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

One comment below:

> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> Gao, Zhichao
> Sent: Tuesday, June 04, 2019 9:05 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to
> control PlatformRecovery
> 
> 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>
> ---
>  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  3 +-
>  MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 71 +++++++++++++++------
> ---
>  2 files changed, 47 insertions(+), 27 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> index 6913389d34..7f94ca17df 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> @@ -5,7 +5,7 @@
>  #  gEfiBdsArchProtocolGuid. After DxeCore finish dispatching, DxeCore will
> invoke Entry
>  #  interface of protocol gEfiBdsArchProtocolGuid, then BDS phase is entered.
>  #
> -#  Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> @@ -95,6 +95,7 @@
>    gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand
> ## CONSUMES
>    gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable              ##
> SOMETIMES_CONSUMES
>    gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ##
> CONSUMES
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport
> ## CONSUMES
> 
>  [Depex]
>    TRUE
> diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> index 9d312bd982..8c8a0b5236 100644
> --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> @@ -5,7 +5,7 @@
>    After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be
> invoked
>    to enter BDS phase.
> 
> -Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
>  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
>  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -546,10 +546,14 @@ BdsFormalizeOSIndicationVariable (
>    //
>    Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
>    if (Status != EFI_NOT_FOUND) {
> -    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI |
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> +    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
>      EfiBootManagerFreeLoadOption (&BootManagerMenu);
>    } else {
> -    OsIndicationSupport =
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> +    OsIndicationSupport = 0;
> +  }
> +
> +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> +    OsIndicationSupport |=
> EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
>    }
> 
>    Status = gRT->SetVariable (
> @@ -662,6 +666,7 @@ BdsEntry (
>    BOOLEAN                         BootSuccess;
>    EFI_DEVICE_PATH_PROTOCOL        *FilePath;
>    EFI_STATUS                      BootManagerMenuStatus;
> +  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;
> 
>    HotkeyTriggered = NULL;
>    Status          = EFI_SUCCESS;
> @@ -763,14 +768,13 @@ BdsEntry (
>    //
>    InitializeLanguage (TRUE);
> 
> -  //
> -  // System firmware must include a PlatformRecovery#### variable
> specifying
> -  // a short-form File Path Media Device Path containing the platform default
> -  // file path for removable media
> -  //
>    FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);
> +  if (FilePath == NULL) {
> +    DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot file
> path. Unable to boot.\n"));
> +    CpuDeadLoop ();
> +  }
>    Status = EfiBootManagerInitializeLoadOption (
> -             &LoadOption,
> +             &PlatformDefaultBootOption,
>               LoadOptionNumberUnassigned,
>               LoadOptionTypePlatformRecovery,
>               LOAD_OPTION_ACTIVE,
> @@ -780,24 +784,31 @@ BdsEntry (
>               0
>               );
>    ASSERT_EFI_ERROR (Status);
> -  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> -  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> LoadOptionCount) == -1) {
> -    for (Index = 0; Index < LoadOptionCount; Index++) {
> -      //
> -      // The PlatformRecovery#### options are sorted by OptionNumber.
> -      // Find the the smallest unused number as the new OptionNumber.
> -      //
> -      if (LoadOptions[Index].OptionNumber != Index) {
> -        break;
> +
> +  //
> +  // System firmware must include a PlatformRecovery#### variable
> specifying
> +  // a short-form File Path Media Device Path containing the platform
> default
> +  // file path for removable media if the platform supports Platform
> Recovery.
> +  //
> +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> +    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> +    if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> LoadOptionCount) == -1) {


In the above 'if' statement, 'LoadOption' is not being initialized.
Is this a typo here?

Best Regards,
Hao Wu


> +      for (Index = 0; Index < LoadOptionCount; Index++) {
> +        //
> +        // The PlatformRecovery#### options are sorted by OptionNumber.
> +        // Find the the smallest unused number as the new OptionNumber.
> +        //
> +        if (LoadOptions[Index].OptionNumber != Index) {
> +          break;
> +        }
>        }
> +      PlatformDefaultBootOption.OptionNumber = Index;
> +      Status = EfiBootManagerLoadOptionToVariable
> (&PlatformDefaultBootOption);
> +      ASSERT_EFI_ERROR (Status);
>      }
> -    LoadOption.OptionNumber = Index;
> -    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> -    ASSERT_EFI_ERROR (Status);
> +    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
>    }
> -  EfiBootManagerFreeLoadOption (&LoadOption);
>    FreePool (FilePath);
> -  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> 
>    //
>    // Report Status Code to indicate connecting drivers will happen
> @@ -1043,10 +1054,18 @@ BdsEntry (
>    }
> 
>    if (!BootSuccess) {
> -    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> -    ProcessLoadOptions (LoadOptions, LoadOptionCount);
> -    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> +    if (PlatformRecovery) {
> +      LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> LoadOptionTypePlatformRecovery);
> +      ProcessLoadOptions (LoadOptions, LoadOptionCount);
> +      EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> +    } else {
> +      //
> +      // When platform recovery is not enabled, still boot to platform default
> file path.
> +      //
> +      EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);
> +    }
>    }
> +  EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);
> 
>    DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));
>    PlatformBootManagerUnableToBoot ();
> --
> 2.21.0.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery
  2019-06-13  7:39   ` Wu, Hao A
@ 2019-06-13  7:51     ` Gao, Zhichao
  0 siblings, 0 replies; 8+ messages in thread
From: Gao, Zhichao @ 2019-06-13  7:51 UTC (permalink / raw)
  To: Wu, Hao A, devel@edk2.groups.io
  Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew



> -----Original Message-----
> From: Wu, Hao A
> Sent: Thursday, June 13, 2019 3:39 PM
> To: devel@edk2.groups.io; Gao, Zhichao <zhichao.gao@intel.com>
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Ni, Ray <ray.ni@intel.com>; Zeng,
> Star <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>; Sean
> Brogan <sean.brogan@microsoft.com>; Michael Turner
> <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: RE: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd
> to control PlatformRecovery
> 
> One comment below:
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
> > Gao, Zhichao
> > Sent: Tuesday, June 04, 2019 9:05 AM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean
> > Brogan; Michael Turner; Bret Barkelew
> > Subject: [edk2-devel] [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd
> to
> > control PlatformRecovery
> >
> > 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>
> > ---
> >  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  3 +-
> > MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 71 +++++++++++++++-----
> -
> > ---
> >  2 files changed, 47 insertions(+), 27 deletions(-)
> >
> > diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> > b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> > index 6913389d34..7f94ca17df 100644
> > --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> > +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
> > @@ -5,7 +5,7 @@
> >  #  gEfiBdsArchProtocolGuid. After DxeCore finish dispatching, DxeCore
> > will invoke Entry  #  interface of protocol gEfiBdsArchProtocolGuid,
> > then BDS phase is entered.
> >  #
> > -#  Copyright (c) 2008 - 2018, Intel Corporation. All rights
> > reserved.<BR>
> > +#  Copyright (c) 2008 - 2019, Intel Corporation. All rights
> > +reserved.<BR>
> >  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ## @@ -95,6 +95,7
> > @@
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand
> > ## CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable              ##
> > SOMETIMES_CONSUMES
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ##
> > CONSUMES
> > +  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport
> > ## CONSUMES
> >
> >  [Depex]
> >    TRUE
> > diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> > b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> > index 9d312bd982..8c8a0b5236 100644
> > --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> > +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c
> > @@ -5,7 +5,7 @@
> >    After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry
> > will be invoked
> >    to enter BDS phase.
> >
> > -Copyright (c) 2004 - 2018, Intel Corporation. All rights
> > reserved.<BR>
> > +Copyright (c) 2004 - 2019, Intel Corporation. All rights
> > +reserved.<BR>
> >  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
> >  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
> >  SPDX-License-Identifier: BSD-2-Clause-Patent @@ -546,10 +546,14 @@
> > BdsFormalizeOSIndicationVariable (
> >    //
> >    Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
> >    if (Status != EFI_NOT_FOUND) {
> > -    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI |
> > EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> > +    OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
> >      EfiBootManagerFreeLoadOption (&BootManagerMenu);
> >    } else {
> > -    OsIndicationSupport =
> > EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> > +    OsIndicationSupport = 0;
> > +  }
> > +
> > +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> > +    OsIndicationSupport |=
> > EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY;
> >    }
> >
> >    Status = gRT->SetVariable (
> > @@ -662,6 +666,7 @@ BdsEntry (
> >    BOOLEAN                         BootSuccess;
> >    EFI_DEVICE_PATH_PROTOCOL        *FilePath;
> >    EFI_STATUS                      BootManagerMenuStatus;
> > +  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;
> >
> >    HotkeyTriggered = NULL;
> >    Status          = EFI_SUCCESS;
> > @@ -763,14 +768,13 @@ BdsEntry (
> >    //
> >    InitializeLanguage (TRUE);
> >
> > -  //
> > -  // System firmware must include a PlatformRecovery#### variable
> > specifying
> > -  // a short-form File Path Media Device Path containing the platform
> > default
> > -  // file path for removable media
> > -  //
> >    FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME);
> > +  if (FilePath == NULL) {
> > +    DEBUG ((DEBUG_ERROR, "Fail to allocate memory for defualt boot
> > + file
> > path. Unable to boot.\n"));
> > +    CpuDeadLoop ();
> > +  }
> >    Status = EfiBootManagerInitializeLoadOption (
> > -             &LoadOption,
> > +             &PlatformDefaultBootOption,
> >               LoadOptionNumberUnassigned,
> >               LoadOptionTypePlatformRecovery,
> >               LOAD_OPTION_ACTIVE,
> > @@ -780,24 +784,31 @@ BdsEntry (
> >               0
> >               );
> >    ASSERT_EFI_ERROR (Status);
> > -  LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> > LoadOptionTypePlatformRecovery);
> > -  if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> > LoadOptionCount) == -1) {
> > -    for (Index = 0; Index < LoadOptionCount; Index++) {
> > -      //
> > -      // The PlatformRecovery#### options are sorted by OptionNumber.
> > -      // Find the the smallest unused number as the new OptionNumber.
> > -      //
> > -      if (LoadOptions[Index].OptionNumber != Index) {
> > -        break;
> > +
> > +  //
> > +  // System firmware must include a PlatformRecovery#### variable
> > specifying
> > +  // a short-form File Path Media Device Path containing the platform
> > default
> > +  // file path for removable media if the platform supports Platform
> > Recovery.
> > +  //
> > +  if (PcdGetBool (PcdPlatformRecoverySupport)) {
> > +    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> > LoadOptionTypePlatformRecovery);
> > +    if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions,
> > LoadOptionCount) == -1) {
> 
> 
> In the above 'if' statement, 'LoadOption' is not being initialized.
> Is this a typo here?

Yes. You are right. 'LoadOption' should change to 'PlatformDefaultBootOption'.
I would update this patch set with your comments. And ignore my push request before.

Thanks,
Zhichao

> 
> Best Regards,
> Hao Wu
> 
> 
> > +      for (Index = 0; Index < LoadOptionCount; Index++) {
> > +        //
> > +        // The PlatformRecovery#### options are sorted by OptionNumber.
> > +        // Find the the smallest unused number as the new OptionNumber.
> > +        //
> > +        if (LoadOptions[Index].OptionNumber != Index) {
> > +          break;
> > +        }
> >        }
> > +      PlatformDefaultBootOption.OptionNumber = Index;
> > +      Status = EfiBootManagerLoadOptionToVariable
> > (&PlatformDefaultBootOption);
> > +      ASSERT_EFI_ERROR (Status);
> >      }
> > -    LoadOption.OptionNumber = Index;
> > -    Status = EfiBootManagerLoadOptionToVariable (&LoadOption);
> > -    ASSERT_EFI_ERROR (Status);
> > +    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> >    }
> > -  EfiBootManagerFreeLoadOption (&LoadOption);
> >    FreePool (FilePath);
> > -  EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> >
> >    //
> >    // Report Status Code to indicate connecting drivers will happen @@
> > -1043,10 +1054,18 @@ BdsEntry (
> >    }
> >
> >    if (!BootSuccess) {
> > -    LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> > LoadOptionTypePlatformRecovery);
> > -    ProcessLoadOptions (LoadOptions, LoadOptionCount);
> > -    EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> > +    if (PlatformRecovery) {
> > +      LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount,
> > LoadOptionTypePlatformRecovery);
> > +      ProcessLoadOptions (LoadOptions, LoadOptionCount);
> > +      EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
> > +    } else {
> > +      //
> > +      // When platform recovery is not enabled, still boot to
> > + platform default
> > file path.
> > +      //
> > +      EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption);
> > +    }
> >    }
> > +  EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);
> >
> >    DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n"));
> >    PlatformBootManagerUnableToBoot ();
> > --
> > 2.21.0.windows.1
> >
> >
> > 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-13  7:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-04  1:05 [PATCH V3 0/2] Use a pcd to control Platform Recovery behavior Gao, Zhichao
2019-06-04  1:05 ` [PATCH V3 1/2] MdeModulePkg: Add a pcd to set the OS indications bit Gao, Zhichao
2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
2019-06-13  7:39   ` Wu, Hao A
2019-06-04  1:05 ` [PATCH V3 2/2] MdeModulePkg/BdsDxe: Use a pcd to control PlatformRecovery Gao, Zhichao
2019-06-04  6:16   ` [edk2-devel] " Ni, Ray
2019-06-13  7:39   ` Wu, Hao A
2019-06-13  7:51     ` Gao, Zhichao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox