From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zg8tmja2lje4os4yms4ymjma.icoremail.net (zg8tmja2lje4os4yms4ymjma.icoremail.net [206.189.21.223]) by mx.groups.io with SMTP id smtpd.web08.6562.1615546922417489224 for ; Fri, 12 Mar 2021 03:02:02 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: phytium.com.cn, ip: 206.189.21.223, mailfrom: jialing@phytium.com.cn) Received: from localhost.localdomain (unknown [223.104.131.160]) by c1app4 (Coremail) with SMTP id BAINCgC3mwEVSktgMY01BQ--.34795S5; Fri, 12 Mar 2021 19:01:59 +0800 (CST) From: Ling Jia To: devel@edk2.groups.io Cc: Leif Lindholm , Peng Xie , Yiqi Shu , "Liu, Zhiguang" , Eric Dong , Liming Gao , Nate DeSimone , Prince Agyeman , Ray Ni , Zhichao Gao Subject: [PATCH v3 15/46] Intel/BoardModulePkg: sort load option in the first boot Date: Fri, 12 Mar 2021 19:01:23 +0800 Message-Id: <20210312110141.75749-4-jialing@phytium.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210312110141.75749-1-jialing@phytium.com.cn> References: <20210312110141.75749-1-jialing@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: BAINCgC3mwEVSktgMY01BQ--.34795S5 X-Coremail-Antispam: 1UD129KBjvJXoWxXr1rXF4kXFy7Jw43Ary5Arb_yoWrXF15pr s7Za9FqrykGrWSvw1rWa40vF45Ka4rtrZ5KFs3Ar45uw1FgF1vyryFyrn5t34UZr1xAFyU ZF12yw47uF1DArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPqb7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI 8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK0II2c7xJM28CjxkF 64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcV CY1x0267AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280 aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzV Aqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S 6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7Mx kIecxEwVAFwVW8KwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw 0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x 07jxo7tUUUUU= X-Originating-IP: [223.104.131.160] X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ Content-Transfer-Encoding: quoted-printable From: "Liu, Zhiguang" 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. Reviewed-by: Eric Dong Cc: Liming Gao Cc: Nate DeSimone Cc: Prince Agyeman Reviewed-by: Ray Ni Cc: Zhichao Gao Signed-off-by: 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 d7612fb80a95..a37139a0074e 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.25.1