[Patch edk2-platforms V3] Intel/BoardModulePkg: sort load option in the first boot


Zhiguang Liu
 

Currently, load option is only sorted when setup is the first priority in b=
oot
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 opti=
on
in first boot.

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

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

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


Ni, Ray
 

Reviewed-by: Ray Ni <ray.ni@...>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Zhiguang Liu
Sent: Thursday, March 11, 2021 9:22 AM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>; Liming Gao <gaoliming@...>; Desimone, Nathaniel L
<nathaniel.l.desimone@...>; Agyeman, Prince <prince.agyeman@...>; Ni, Ray <ray.ni@...>; Gao, Zhichao
<zhichao.gao@...>
Subject: [edk2-devel] [Patch edk2-platforms V3] Intel/BoardModulePkg: sort load option in the first boot

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.

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

Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
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 d7612fb80a..a37139a007 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.30.0.windows.2



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#72653): https://edk2.groups.io/g/devel/message/72653
Mute This Topic: https://groups.io/mt/81243873/1712937
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray.ni@...]
-=-=-=-=-=-=


Dong, Eric
 

Reviewed-by: Eric Dong <eric.dong@...>

-----Original Message-----
From: Liu, Zhiguang <zhiguang.liu@...>
Sent: Thursday, March 11, 2021 9:22 AM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@...>; Liming Gao <gaoliming@...>; Desimone, Nathaniel L <nathaniel.l.desimone@...>; Agyeman, Prince <prince.agyeman@...>; Ni, Ray <ray.ni@...>; Gao, Zhichao <zhichao.gao@...>
Subject: [Patch edk2-platforms V3] Intel/BoardModulePkg: sort load option in the first boot

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.

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

Signed-off-by: Zhiguang Liu <zhiguang.liu@...>
---
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 d7612fb80a..a37139a007 100644
--- a/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHookLib.c
+++ b/Platform/Intel/BoardModulePkg/Library/BoardBdsHookLib/BoardBdsHook
+++ Lib.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.30.0.windows.2