[edk2] [PATCH] OvmfPkg/BDS: Provide platform callback for ultimate boot failure

Ruiyu Ni posted 1 patch 5 years, 9 months ago
Failed in applying to current master (apply log)
.../Library/PlatformBootManagerLib/BdsPlatform.c   | 56 ++++++++++++++++++++--
1 file changed, 51 insertions(+), 5 deletions(-)
[edk2] [PATCH] OvmfPkg/BDS: Provide platform callback for ultimate boot failure
Posted by Ruiyu Ni 5 years, 9 months ago
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
---
 .../Library/PlatformBootManagerLib/BdsPlatform.c   | 56 ++++++++++++++++++++--
 1 file changed, 51 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 57870cb856..3b59ba9397 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -1,7 +1,7 @@
 /** @file
   Platform BDS customizations.
 
-  Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials are licensed and made available
   under the terms and conditions of the BSD License which accompanies this
   distribution.  The full text of the license may be found at
@@ -337,6 +337,50 @@ SaveS3BootScript (
 //
 // BDS Platform Functions
 //
+
+VOID
+EFIAPI
+UnableToBoot (
+  VOID
+  )
+{
+  EFI_STATUS                      Status;
+  UINTN                           Index;
+  EFI_INPUT_KEY                   Key;
+  EFI_BOOT_MANAGER_LOAD_OPTION    BootManagerMenu;
+  //
+  // AsciiPrint() will NULL-check gST->ConOut internally. We check gST->ConIn
+  // here to see if it makes sense to request and wait for a keypress.
+  //
+  if (gST->ConIn != NULL) {
+    AsciiPrint (
+      "%a: No bootable option or device was found.\n"
+      "%a: Press any key to enter the Boot Manager Menu.\n",
+      gEfiCallerBaseName,
+      gEfiCallerBaseName
+      );
+    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
+    ASSERT_EFI_ERROR (Status);
+    ASSERT (Index == 0);
+
+    //
+    // Drain any queued keys.
+    //
+    while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) {
+      //
+      // just throw away Key
+      //
+    }
+  }
+
+  Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
+  if (!EFI_ERROR (Status)) {
+    while (TRUE) {
+      EfiBootManagerBoot (&BootManagerMenu);
+    }
+  }
+}
+
 /**
   Do the platform init, can be customized by OEM/IBV
 
@@ -410,6 +454,8 @@ PlatformBootManagerBeforeConsole (
 
   PlatformRegisterOptionsAndKeys ();
 
+  EfiBootManagerRegisterUnableToBootHandler (UnableToBoot);
+
   //
   // Install both VIRTIO_DEVICE_PROTOCOL and (dependent) EFI_RNG_PROTOCOL
   // instances on Virtio PCI RNG devices.
@@ -1531,14 +1577,14 @@ PlatformBootManagerAfterConsole (
   //
   PlatformBdsConnectSequence ();
 
-  EfiBootManagerRefreshAllBootOption ();
+  //EfiBootManagerRefreshAllBootOption ();
 
   //
   // Register UEFI Shell
   //
-  PlatformRegisterFvBootOption (
-    PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE
-    );
+  //PlatformRegisterFvBootOption (
+  //  PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE
+  //  );
 
   RemoveStaleFvFileOptions ();
   SetBootOrderFromQemu ();
-- 
2.16.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] OvmfPkg/BDS: Provide platform callback for ultimate boot failure
Posted by Laszlo Ersek 5 years, 9 months ago
Hi Ray,

thanks a lot for this patch, I have some small logic requests:

On 06/29/18 08:05, Ruiyu Ni wrote:
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> ---
>  .../Library/PlatformBootManagerLib/BdsPlatform.c   | 56 ++++++++++++++++++++--
>  1 file changed, 51 insertions(+), 5 deletions(-)
> 
> diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
> index 57870cb856..3b59ba9397 100644
> --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
> +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
> @@ -1,7 +1,7 @@
>  /** @file
>    Platform BDS customizations.
>  
> -  Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials are licensed and made available
>    under the terms and conditions of the BSD License which accompanies this
>    distribution.  The full text of the license may be found at
> @@ -337,6 +337,50 @@ SaveS3BootScript (
>  //
>  // BDS Platform Functions
>  //
> +
> +VOID
> +EFIAPI
> +UnableToBoot (
> +  VOID
> +  )
> +{
> +  EFI_STATUS                      Status;
> +  UINTN                           Index;
> +  EFI_INPUT_KEY                   Key;
> +  EFI_BOOT_MANAGER_LOAD_OPTION    BootManagerMenu;
> +  //
> +  // AsciiPrint() will NULL-check gST->ConOut internally. We check gST->ConIn
> +  // here to see if it makes sense to request and wait for a keypress.
> +  //
> +  if (gST->ConIn != NULL) {
> +    AsciiPrint (
> +      "%a: No bootable option or device was found.\n"
> +      "%a: Press any key to enter the Boot Manager Menu.\n",
> +      gEfiCallerBaseName,
> +      gEfiCallerBaseName
> +      );
> +    Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
> +    ASSERT_EFI_ERROR (Status);
> +    ASSERT (Index == 0);
> +
> +    //
> +    // Drain any queued keys.
> +    //
> +    while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) {
> +      //
> +      // just throw away Key
> +      //
> +    }
> +  }
> +
> +  Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);

(1) In order to preserve the previous behavior, can you please move this
function call to the top of UnableToBoot(), and return silently if the
boot manager menu is not found?

That will cause generic BDS to hang at once (silently), which is
identical to the previous behavior. I'd like to preserve that.

> +  if (!EFI_ERROR (Status)) {
> +    while (TRUE) {
> +      EfiBootManagerBoot (&BootManagerMenu);
> +    }
> +  }
> +}
> +
>  /**
>    Do the platform init, can be customized by OEM/IBV
>  
> @@ -410,6 +454,8 @@ PlatformBootManagerBeforeConsole (
>  
>    PlatformRegisterOptionsAndKeys ();
>  
> +  EfiBootManagerRegisterUnableToBootHandler (UnableToBoot);
> +
>    //
>    // Install both VIRTIO_DEVICE_PROTOCOL and (dependent) EFI_RNG_PROTOCOL
>    // instances on Virtio PCI RNG devices.
> @@ -1531,14 +1577,14 @@ PlatformBootManagerAfterConsole (
>    //
>    PlatformBdsConnectSequence ();
>  
> -  EfiBootManagerRefreshAllBootOption ();
> +  //EfiBootManagerRefreshAllBootOption ();
>  
>    //
>    // Register UEFI Shell
>    //
> -  PlatformRegisterFvBootOption (
> -    PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE
> -    );
> +  //PlatformRegisterFvBootOption (
> +  //  PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE
> +  //  );
>  
>    RemoveStaleFvFileOptions ();
>    SetBootOrderFromQemu ();
> 

(2) I think the changes you did to PlatformBootManagerAfterConsole()
were for your local testing; can you please remove them from the patch?

I hope we can commit the next version of this patch, and then I will
port it to "ArmVirtPkg/Library/PlatformBootManagerLib" as well.

Many thanks!
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel