[Patch V3] UefiPayloadPkg: Get platform specific logic from protocol for BDS driver


Zhiguang Liu
 

V1:
Currently, BDS driver will link a PlatformBootManagerLib, which contains pl=
atform
sepcific logic. This patch get the platform specific logic from a protocol,=
so that
platform logic for Boot manager can be in another binary.

V2:
Add function comments in PlatformBootManagerOverride.h

V3:
Avoid using "PLD" term

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Guo Dong <guo.dong@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>

Reviewed-by: Guo Dong <guo.dong@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h |=
85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
++++++++++++++
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c |=
25 ++++++++++++++++++++++++-
UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf |=
3 ++-
UefiPayloadPkg/UefiPayloadPkg.dec |=
4 +++-
4 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h =
b/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h
new file mode 100644
index 0000000000..59544e417c
--- /dev/null
+++ b/UefiPayloadPkg/Include/Protocol/PlatformBootManagerOverride.h
@@ -0,0 +1,85 @@
+/** @file=0D
+ This file defines the Univeral Payload Platform BootManager Protocol.=0D
+=0D
+ Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#ifndef __PLATFORM_BOOT_MANAGER_OVERRIDE_H__=0D
+#define __PLATFORM_BOOT_MANAGER_OVERRIDE_H__=0D
+=0D
+=0D
+/**=0D
+ Do the platform specific action before the console is connected.=0D
+=0D
+ Such as:=0D
+ Update console variable;=0D
+ Register new Driver#### or Boot####;=0D
+ Signal ReadyToLock event.=0D
+=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_BEFORE_CONSOLE) =
(=0D
+ VOID=0D
+ );=0D
+=0D
+/**=0D
+ Do the platform specific action after the console is connected.=0D
+=0D
+ Such as:=0D
+ Dynamically switch output mode;=0D
+ Signal console ready platform customized event;=0D
+ Run diagnostics like memory testing;=0D
+ Connect certain devices;=0D
+ Dispatch aditional option roms.=0D
+=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_AFTER_CONSOLE) (=
=0D
+ VOID=0D
+ );=0D
+=0D
+/**=0D
+ This function is called each second during the boot manager waits the ti=
meout.=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+=0D
+ @param TimeoutRemain The remaining timeout.=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_WAIT_CALLBACK) (=
=0D
+ UINT16 TimeoutRemain=0D
+ );=0D
+=0D
+/**=0D
+ The function is called when no boot option could be launched,=0D
+ including platform recovery options and options pointing to applications=
=0D
+ built into firmware volumes.=0D
+=0D
+ If this function returns, BDS attempts to enter an infinite loop.=0D
+ This function will override the default behavior in PlatformBootManagerL=
ib=0D
+**/=0D
+typedef=0D
+VOID=0D
+(EFIAPI *UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_UNABLE_TO_BOOT) =
(=0D
+ VOID=0D
+ );=0D
+=0D
+///=0D
+/// Provides an interface to override the default behavior in PlatformBoot=
ManagerLib,=0D
+/// so platform can provide its own platform specific logic through this p=
rotocol=0D
+///=0D
+typedef struct {=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_BEFORE_CONSOLE B=
eforeConsole;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_AFTER_CONSOLE A=
fterConsole;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_WAIT_CALLBACK W=
aitCallback;=0D
+ UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_UNABLE_TO_BOOT U=
nableToBoot;=0D
+} UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_PROTOCOL;=0D
+=0D
+extern GUID gUniversalPayloadPlatformBootManagerOverrideProtocolGuid;=0D
+=0D
+#endif=0D
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
ger.c b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
index 7fa3a048b7..fce48d26a1 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
@@ -2,13 +2,16 @@
This file include all platform action which can be customized=0D
by IBV/OEM.=0D
=0D
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
=0D
**/=0D
=0D
#include "PlatformBootManager.h"=0D
#include "PlatformConsole.h"=0D
+#include <Protocol/PlatformBootManagerOverride.h>=0D
+=0D
+UNIVERSAL_PAYLOAD_PLATFORM_BOOT_MANAGER_OVERRIDE_PROTOCOL *mUniversalPayl=
oadPlatformBootManagerOverrideInstance =3D NULL;=0D
=0D
VOID=0D
InstallReadyToLock (=0D
@@ -156,6 +159,16 @@ PlatformBootManagerBeforeConsole (
EFI_INPUT_KEY F2;=0D
EFI_INPUT_KEY Down;=0D
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;=0D
+ EFI_STATUS Status;=0D
+=0D
+ Status =3D gBS->LocateProtocol (&gUniversalPayloadPlatformBootManagerOve=
rrideProtocolGuid, NULL, (VOID **) &mUniversalPayloadPlatformBootManagerOve=
rrideInstance);=0D
+ if (EFI_ERROR (Status)) {=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance =3D NULL;=0D
+ }=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->BeforeConsole();=
=0D
+ return;=0D
+ }=0D
=0D
//=0D
// Register ENTER as CONTINUE key=0D
@@ -213,6 +226,10 @@ PlatformBootManagerAfterConsole (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;=0D
EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;=0D
=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->AfterConsole();=
=0D
+ return;=0D
+ }=0D
Black.Blue =3D Black.Green =3D Black.Red =3D Black.Reserved =3D 0;=0D
White.Blue =3D White.Green =3D White.Red =3D White.Reserved =3D 0xFF;=0D
=0D
@@ -244,6 +261,9 @@ PlatformBootManagerWaitCallback (
UINT16 TimeoutRemain=0D
)=0D
{=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->WaitCallback (Ti=
meoutRemain);=0D
+ }=0D
return;=0D
}=0D
=0D
@@ -260,6 +280,9 @@ PlatformBootManagerUnableToBoot (
VOID=0D
)=0D
{=0D
+ if (mUniversalPayloadPlatformBootManagerOverrideInstance !=3D NULL){=0D
+ mUniversalPayloadPlatformBootManagerOverrideInstance->UnableToBoot();=
=0D
+ }=0D
return;=0D
}=0D
=0D
diff --git a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
gerLib.inf b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootMana=
gerLib.inf
index 1f5a0bcad0..600a535282 100644
--- a/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.=
inf
+++ b/UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.=
inf
@@ -1,7 +1,7 @@
## @file=0D
# Include all platform action which can be customized by IBV/OEM.=0D
#=0D
-# Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>=
=0D
+# Copyright (c) 2012 - 2021, Intel Corporation. All rights reserved.<BR>=
=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
##=0D
@@ -57,6 +57,7 @@
gEfiBootLogoProtocolGuid ## CONSUMES=0D
gEfiDxeSmmReadyToLockProtocolGuid=0D
gEfiSmmAccess2ProtocolGuid=0D
+ gUniversalPayloadPlatformBootManagerOverrideProtocolGuid=0D
=0D
[Pcd]=0D
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload=
Pkg.dec
index 99cb3311a6..105e1f5a1c 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -3,7 +3,7 @@
#=0D
# Provides drivers and definitions to create uefi payload for bootloaders.=
=0D
#=0D
-# Copyright (c) 2014 - 2020, Intel Corporation. All rights reserved.<BR>=0D
+# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>=0D
# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
#=0D
##=0D
@@ -43,6 +43,8 @@
#=0D
gPlatformGOPPolicyGuid =3D { 0xec2e931b, 0x3281, 0x48a5=
, { 0x81, 0x07, 0xdf, 0x8a, 0x8b, 0xed, 0x3c, 0x5d } }=0D
=0D
+ gUniversalPayloadPlatformBootManagerOverrideProtocolGuid =3D { 0xdb3fc2d=
f, 0x7376, 0x4a8d, { 0x82, 0xab, 0x91, 0x54, 0xa1, 0x36, 0xa6, 0x5a } }=0D
+=0D
##########################################################################=
######=0D
#=0D
# PCD Declarations section - list of all PCDs Declared by this Package=0D
--=20
2.30.0.windows.2

Join devel@edk2.groups.io to automatically receive all group messages.