public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Haojian Zhuang <haojian.zhuang@linaro.org>
To: edk2-devel@lists.01.org
Cc: Haojian Zhuang <haojian.zhuang@linaro.org>,
	Laszlo Ersek <lersek@redhat.com>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v3 2/2] ArmPkg/PlatformBootManagerLib: load platform boot options
Date: Thu, 19 Apr 2018 18:42:40 +0800	[thread overview]
Message-ID: <1524134560-1245-3-git-send-email-haojian.zhuang@linaro.org> (raw)
In-Reply-To: <1524134560-1245-1-git-send-email-haojian.zhuang@linaro.org>

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>
---
 ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 83 ++++++++++++++++++++++
 .../PlatformBootManagerLib.inf                     |  2 +
 2 files changed, 85 insertions(+)

diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
index 61ab61ccc780..3a40592b58dd 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,86 @@ PlatformRegisterFvBootOption (
 
 STATIC
 VOID
+GetPlatformOptions (
+  VOID
+  )
+{
+  EFI_STATUS                      Status;
+  EFI_BOOT_MANAGER_LOAD_OPTION    *CurrentBootOptions;
+  EFI_BOOT_MANAGER_LOAD_OPTION    *PlatformBootOptionArray;
+  EFI_INPUT_KEY                   *PlatformKeyArray;
+  PLATFORM_BOOT_MANAGER_PROTOCOL  *PlatformBootManager;
+  UINTN                           CurrentBootOptionCount;
+  UINTN                           OptionIndex;
+  UINTN                           Index;
+
+  Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL,
+                  (VOID **)&PlatformBootManager);
+  if (EFI_ERROR (Status)) {
+    return;
+  }
+  Status = PlatformBootManager->GetPlatformBootOptionsAndKeys (
+             &PlatformBootOptionArray,
+             &PlatformKeyArray
+             );
+  if (EFI_ERROR (Status)) {
+    return;
+  }
+  CurrentBootOptions = EfiBootManagerGetLoadOptions (
+                         &CurrentBootOptionCount, LoadOptionTypeBoot
+                         );
+  OptionIndex = EfiBootManagerFindLoadOption (
+                  &PlatformBootOptionArray[0],
+                  CurrentBootOptions,
+                  CurrentBootOptionCount
+                  );
+  if (OptionIndex == -1) {
+    OptionIndex = 1;
+  } else {
+    OptionIndex = OptionIndex + 1;
+  }
+  Index = 0;
+  //
+  // Last entries of PlatformBootOptionArray and PlatformKeyArray are empty.
+  //
+  while (PlatformBootOptionArray[Index].Description != NULL) {
+    if (OptionIndex == 1) {
+      //
+      // Append the BootLoadOption
+      //
+      Status = EfiBootManagerAddLoadOptionVariable (
+                 &PlatformBootOptionArray[Index],
+                 OptionIndex + Index
+                 );
+      ASSERT_EFI_ERROR (Status);
+    }
+    //
+    // If UnicodeChar isn't empty, there's a hot key.
+    //
+    if (PlatformKeyArray[Index].UnicodeChar) {
+      //
+      // The index of Boot Options counts from 1.
+      // The last index equals to the count of total Boot Options.
+      //
+      Status = EfiBootManagerAddKeyOptionVariable (
+                 NULL, OptionIndex + Index, 0,
+                 PlatformKeyArray[Index], NULL
+                 );
+      ASSERT_EFI_ERROR (Status);
+    }
+    Index++;
+  }
+  EfiBootManagerFreeLoadOptions (
+    CurrentBootOptions, CurrentBootOptionCount
+    );
+  EfiBootManagerFreeLoadOptions (
+    PlatformBootOptionArray, Index
+    );
+  FreePool (PlatformKeyArray);
+}
+
+STATIC
+VOID
 PlatformRegisterOptionsAndKeys (
   VOID
   )
@@ -402,6 +483,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 71f1d04a87ee..e8cbb10dabdd 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -35,6 +35,7 @@ [Sources]
   PlatformBm.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   ShellPkg/ShellPkg.dec
@@ -84,3 +85,4 @@ [Protocols]
   gEfiPciRootBridgeIoProtocolGuid
   gEfiSimpleFileSystemProtocolGuid
   gEsrtManagementProtocolGuid
+  gPlatformBootManagerProtocolGuid
-- 
2.7.4



  parent reply	other threads:[~2018-04-19 10:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 10:42 [PATCH v3 0/2] add platform boot manager protocol Haojian Zhuang
2018-04-19 10:42 ` [PATCH v3 1/2] EmbeddedPkg: " Haojian Zhuang
2018-04-20 11:33   ` Laszlo Ersek
2018-04-19 10:42 ` Haojian Zhuang [this message]
2018-04-20 12:55   ` [PATCH v3 2/2] ArmPkg/PlatformBootManagerLib: load platform boot options Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1524134560-1245-3-git-send-email-haojian.zhuang@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox