diff options
author | Haojian Zhuang <haojian.zhuang@linaro.org> | 2018-04-23 14:21:54 +0800 |
---|---|---|
committer | Leif Lindholm <leif.lindholm@linaro.org> | 2018-06-05 15:50:11 +0100 |
commit | 1b6e7633cad8135547f337eeef47f446f57a2505 (patch) | |
tree | b425213e064c4eb8c1ef7352ac05c5b6f90a32d0 | |
parent | 7e074d15e7b98c0101a17547cce2b464827df540 (diff) | |
download | edk2-1b6e7633cad8135547f337eeef47f446f57a2505.zip edk2-1b6e7633cad8135547f337eeef47f446f57a2505.tar.gz edk2-1b6e7633cad8135547f337eeef47f446f57a2505.tar.bz2 |
ArmPkg/PlatformBootManagerLib: load platform boot options
Make platform driver to create predefined boot options and related
hot keys.
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
-rw-r--r-- | ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 103 | ||||
-rw-r--r-- | ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 |
2 files changed, 105 insertions, 0 deletions
diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c index 61ab61c..3456a71 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -30,6 +30,7 @@ #include <Protocol/LoadedImage.h>
#include <Protocol/PciIo.h>
#include <Protocol/PciRootBridgeIo.h>
+#include <Protocol/PlatformBootManager.h>
#include <Guid/EventGroup.h>
#include <Guid/TtyTerm.h>
@@ -392,6 +393,106 @@ PlatformRegisterFvBootOption ( STATIC
VOID
+GetPlatformOptions (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_BOOT_MANAGER_LOAD_OPTION *CurrentBootOptions;
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
+ EFI_INPUT_KEY *BootKeys;
+ PLATFORM_BOOT_MANAGER_PROTOCOL *PlatformBootManager;
+ UINTN CurrentBootOptionCount;
+ UINTN Index;
+ UINTN BootCount;
+
+ Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL,
+ (VOID **)&PlatformBootManager);
+ if (EFI_ERROR (Status)) {
+ return;
+ }
+ Status = PlatformBootManager->GetPlatformBootOptionsAndKeys (
+ &BootCount,
+ &BootOptions,
+ &BootKeys
+ );
+ if (EFI_ERROR (Status)) {
+ return;
+ }
+ //
+ // Fetch the existent boot options. If there are none, CurrentBootCount
+ // will be zeroed.
+ //
+ CurrentBootOptions = EfiBootManagerGetLoadOptions (
+ &CurrentBootOptionCount,
+ LoadOptionTypeBoot
+ );
+ //
+ // Process the platform boot options.
+ //
+ for (Index = 0; Index < BootCount; Index++) {
+ INTN Match;
+ UINTN BootOptionNumber;
+
+ //
+ // If there are any preexistent boot options, and the subject platform boot
+ // option is already among them, then don't try to add it. Just get its
+ // assigned boot option number so we can associate a hotkey with it. Note
+ // that EfiBootManagerFindLoadOption() deals fine with (CurrentBootOptions
+ // == NULL) if (CurrentBootCount == 0).
+ //
+ Match = EfiBootManagerFindLoadOption (
+ &BootOptions[Index],
+ CurrentBootOptions,
+ CurrentBootOptionCount
+ );
+ if (Match >= 0) {
+ BootOptionNumber = CurrentBootOptions[Match].OptionNumber;
+ } else {
+ //
+ // Add the platform boot options as a new one, at the end of the boot
+ // order. Note that if the platform provided this boot option with an
+ // unassigned option number, then the below function call will assign a
+ // number.
+ //
+ Status = EfiBootManagerAddLoadOptionVariable (
+ &BootOptions[Index],
+ MAX_UINTN
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to register \"%s\": %r\n",
+ __FUNCTION__, BootOptions[Index].Description, Status));
+ continue;
+ }
+ BootOptionNumber = BootOptions[Index].OptionNumber;
+ }
+
+ //
+ // Register a hotkey with the boot option, if requested.
+ //
+ if (BootKeys[Index].UnicodeChar == L'\0') {
+ continue;
+ }
+
+ Status = EfiBootManagerAddKeyOptionVariable (
+ NULL,
+ BootOptionNumber,
+ 0,
+ BootKeys[Index],
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n",
+ __FUNCTION__, BootOptions[Index].Description, Status));
+ }
+ }
+ EfiBootManagerFreeLoadOptions (CurrentBootOptions, CurrentBootOptionCount);
+ EfiBootManagerFreeLoadOptions (BootOptions, BootCount);
+ FreePool (BootKeys);
+}
+
+STATIC
+VOID
PlatformRegisterOptionsAndKeys (
VOID
)
@@ -402,6 +503,8 @@ PlatformRegisterOptionsAndKeys ( EFI_INPUT_KEY Esc;
EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
+ GetPlatformOptions ();
+
//
// Register ENTER as CONTINUE key
//
diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 71f1d04..e8cbb10 100644 --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -35,6 +35,7 @@ PlatformBm.c
[Packages]
+ EmbeddedPkg/EmbeddedPkg.dec
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
@@ -84,3 +85,4 @@ gEfiPciRootBridgeIoProtocolGuid
gEfiSimpleFileSystemProtocolGuid
gEsrtManagementProtocolGuid
+ gPlatformBootManagerProtocolGuid
|