public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ling Jia <jialing@phytium.com.cn>
To: devel@edk2.groups.io
Cc: Leif Lindholm <leif@nuviainc.com>,
	Peng Xie <xiepeng@phytium.com.cn>,
	Yiqi Shu <shuyiqi@phytium.com.cn>,
	"Liu, Zhiguang" <Zhiguang.Liu@intel.com>,
	Eric Dong <eric.dong@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Prince Agyeman <prince.agyeman@intel.com>,
	Ray Ni <ray.ni@intel.com>, Zhichao Gao <zhichao.gao@intel.com>
Subject: [PATCH v3 15/46] Intel/BoardModulePkg: sort load option in the first boot
Date: Fri, 12 Mar 2021 19:01:23 +0800	[thread overview]
Message-ID: <20210312110141.75749-4-jialing@phytium.com.cn> (raw)
In-Reply-To: <20210312110141.75749-1-jialing@phytium.com.cn>

From: "Liu, Zhiguang" <Zhiguang.Liu@intel.com>

Currently, load option is only sorted when setup is the first priority in boot
option. However, Below change in UefiBootManagerLib puts setup in the end, which
causes the sort function won't be called.
  MdeModulePkg/UefiBootManagerLib: Put BootMenu at the end of BootOrder
  SHA-1: 7f34681c488aee2563eaa2afcc6a2c8aa7c5b912

This patch will set a NV variable in the first boot, and sort the boot option
in first boot.

Reviewed-by: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c | 72 ++++++++++----------
 1 file changed, 37 insertions(+), 35 deletions(-)

diff --git a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
index d7612fb80a95..a37139a0074e 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
@@ -20,6 +20,8 @@
 
 #include "BoardBdsHook.h"
 
+#define IS_FIRST_BOOT_VAR_NAME L"IsFirstBoot"
+
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_BOOT_MODE    gBootMode;
 BOOLEAN                                        gPPRequireUIConfirm;
 extern UINTN                                   mBootMenuOptionNumber;
@@ -992,37 +994,6 @@ ConnectSequence (
   EfiBootManagerConnectAll ();
 }
 
-
-/**
-  The function is to consider the boot order which is not in our expectation.
-  In the case that we need to re-sort the boot option.
-
-  @retval  TRUE         Need to sort Boot Option.
-  @retval  FALSE        Don't need to sort Boot Option.
-**/
-BOOLEAN
-IsNeedSortBootOption (
-  VOID
-  )
-{
-  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOptions;
-  UINTN                         BootOptionCount;
-
-  BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
-
-  //
-  // If setup is the first priority in boot option, we need to sort boot option.
-  //
-  if ((BootOptionCount > 1) &&
-    (((StrnCmp (BootOptions->Description, L"Enter Setup", StrLen (L"Enter Setup"))) == 0) ||
-    ((StrnCmp (BootOptions->Description, L"BootManagerMenuApp", StrLen (L"BootManagerMenuApp"))) == 0))) {
-    return TRUE;
-  }
-
-  return FALSE;
-}
-
-
 /**
   Connects Root Bridge
  **/
@@ -1332,6 +1303,9 @@ BdsAfterConsoleReadyBeforeBootOptionCallback (
   )
 {
   EFI_BOOT_MODE                 LocalBootMode;
+  EFI_STATUS                    Status;
+  BOOLEAN                       IsFirstBoot;
+  UINTN                         DataSize;
 
   DEBUG ((DEBUG_INFO, "Event gBdsAfterConsoleReadyBeforeBootOptionEvent callback starts\n"));
   //
@@ -1376,14 +1350,42 @@ BdsAfterConsoleReadyBeforeBootOptionCallback (
       //
       // PXE boot option may appear after boot option enumeration
       //
+
+      EfiBootManagerRefreshAllBootOption ();
+      DataSize = sizeof (BOOLEAN);
+      Status = gRT->GetVariable (
+                      IS_FIRST_BOOT_VAR_NAME,
+                      &gEfiCallerIdGuid,
+                      NULL,
+                      &DataSize,
+                      &IsFirstBoot
+                      );
+      if (EFI_ERROR (Status)) {
+        //
+        // If can't find the variable, see it as the first boot
+        //
+        IsFirstBoot = TRUE;
+      }
+
+      if (IsFirstBoot) {
+        //
+        // In the first boot, sort the boot option
+        //
+        EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
+        IsFirstBoot = FALSE;
+        Status = gRT->SetVariable (
+                        IS_FIRST_BOOT_VAR_NAME,
+                        &gEfiCallerIdGuid,
+                        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+                        sizeof (BOOLEAN),
+                        &IsFirstBoot
+                        );
+      }
+
       break;
   }
 
   Print (L"Press F7 for BootMenu!\n");
 
-  EfiBootManagerRefreshAllBootOption ();
 
-  if (IsNeedSortBootOption()) {
-    EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
-  }
 }
-- 
2.25.1


  parent reply	other threads:[~2021-03-12 11:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 11:01 [PATCH v3 00/46] Added support for FT2000/4 chip Ling Jia
2021-03-12 11:01 ` [PATCH v3 13/46] Silicon/Phytium: Added PlatformLib to FT2000/4 Ling Jia
2021-03-12 11:01 ` [PATCH v3 14/46] Silicon/Phytium: Added Acpi support " Ling Jia
2021-03-12 11:01 ` Ling Jia [this message]
2021-04-01 19:28   ` [PATCH v3 15/46] Intel/BoardModulePkg: sort load option in the first boot Nate DeSimone
2021-03-12 11:01 ` [PATCH v3 16/46] Silicon/Phytium: Added SMBIOS support to FT2000/4 Ling Jia
2021-03-12 11:01 ` [PATCH v3 17/46] Silicon/Phytium: Added PciSegmentLib " Ling Jia
2021-03-12 11:01 ` [PATCH v3 18/46] Silicon/Phytium: Added PciHostBridgeLib " Ling Jia
2021-03-12 11:01 ` [PATCH v3 19/46] Silicon/Phytium: Added Spi driver support " Ling Jia
2021-03-12 11:01 ` [PATCH v3 20/46] Silicon/Phytium: Added flash driver support to Phytium Silicon Ling Jia
2021-03-12 11:01 ` [PATCH v3 21/46] Silicon/Phytium: Added fvb driver for norflash Ling Jia
2021-03-12 11:01 ` [PATCH v3 22/46] Silicon/Phytium: Added Rtc driver to FT2000/4 Ling Jia
2021-03-12 11:01 ` [PATCH v3 23/46] Maintainers.txt: Added maintainers and reviewers for the DurianPkg Ling Jia
2021-03-12 11:01 ` [PATCH v3 37/46] Silicon/Phytium: Added PlatformLib to FT2000/4 Ling Jia
2021-03-12 11:01 ` [PATCH v3 38/46] Silicon/Phytium: Added Acpi support " Ling Jia
2021-03-12 11:01 ` [PATCH v3 39/46] Silicon/Phytium: Added SMBIOS " Ling Jia
2021-03-12 11:01 ` [PATCH v3 40/46] Silicon/Phytium: Added PciSegmentLib " Ling Jia
2021-03-12 11:01 ` [PATCH v3 41/46] Silicon/Phytium: Added PciHostBridgeLib " Ling Jia
2021-03-12 11:01 ` [PATCH v3 42/46] Silicon/Phytium: Added Spi driver support " Ling Jia
2021-03-12 11:01 ` [PATCH v3 43/46] Silicon/Phytium: Added flash driver support to Phytium Silicon Ling Jia
2021-03-12 11:01 ` [PATCH v3 44/46] Silicon/Phytium: Added fvb driver for norflash Ling Jia
2021-03-12 11:01 ` [PATCH v3 45/46] Silicon/Phytium: Added Rtc driver to FT2000/4 Ling Jia
2021-03-12 11:01 ` [PATCH v3 46/46] Maintainers.txt: Added maintainers and reviewers for the DurianPkg Ling Jia
2021-03-15 14:28 ` [PATCH v3 00/46] Added support for FT2000/4 chip Leif Lindholm

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=20210312110141.75749-4-jialing@phytium.com.cn \
    --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