Hello,

I wrote a patch that make it possible to set Boot0000 at build time using a
pcd.

For example with build option
`--pcd=gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootBoot0000=Lshell.efi`,
I can make sure that efi shell will boot first for a newly build firmware
image.

Thanks,
Hugues


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111811): https://edk2.groups.io/g/devel/message/111811
Mute This Topic: https://groups.io/mt/102851815/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


From e987ac0881d4a5587e445edf1ddeda87bb2ffc03 Mon Sep 17 00:00:00 2001
From: Hugues Morisset <morisset.hug...@gmail.com>
Date: Sun, 26 Nov 2023 22:46:21 +0100
Subject: [PATCH] BdsDxe: Add at build user provided Boot0000 entry

When building existing platforms descriptions, it is hard for a user
to choose a default boot option at build time.
This patch adds a Pcd that set Boot0000 entry at boot.

Signed-off-by: Hugues Morisset <morisset.hug...@gmai.com>
---
 MdeModulePkg/MdeModulePkg.dec            |  4 +++
 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf |  1 +
 MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 32 ++++++++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
index 0ff058b..2202b9e 100644
--- MdeModulePkg/MdeModulePkg.dec
+++ MdeModulePkg/MdeModulePkg.dec
@@ -2151,6 +2151,10 @@
   # @Prompt The value is use for Usb Network rate limiting supported.
   gEfiMdeModulePkgTokenSpaceGuid.PcdUsbNetworkRateLimitingFactor|100|UINT32|0x10000028
 
+  ## Indicate the first boot entry, does not set bootorder
+  # @Prompt First boot entry.
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootBoot0000|""|VOID*|0x0000012e
+
 [PcdsPatchableInModule]
   ## Specify memory size with page number for PEI code when
   #  Loading Module at Fixed Address feature is enabled.
diff --git MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
index 5bac635..557c236 100644
--- MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+++ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
@@ -98,6 +98,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                       ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport              ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport           ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformBootBoot0000              ## CONSUMES
 
 [Depex]
   TRUE
diff --git MdeModulePkg/Universal/BdsDxe/BdsEntry.c MdeModulePkg/Universal/BdsDxe/BdsEntry.c
index 72de8d3..70fd1e2 100644
--- MdeModulePkg/Universal/BdsDxe/BdsEntry.c
+++ MdeModulePkg/Universal/BdsDxe/BdsEntry.c
@@ -692,6 +692,9 @@ BdsEntry (
   EFI_STATUS                      BootManagerMenuStatus;
   EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBootOption;
   BOOLEAN                         PlatformDefaultBootOptionValid;
+  EFI_BOOT_MANAGER_LOAD_OPTION    PlatformDefaultBoot0000;
+  BOOLEAN                         PlatformDefaultBoot0000Valid;
+  CONST CHAR16                    *Boot0000;
 
   HotkeyTriggered = NULL;
   Status          = EFI_SUCCESS;
@@ -799,6 +802,35 @@ BdsEntry (
     BootNext = NULL;
   }
 
+
+  Boot0000 = ((CONST CHAR16 *) PcdGetPtr (PcdPlatformBootBoot0000));
+  if (Boot0000 && Boot0000[0]) {
+    FilePath = ConvertTextToDevicePath(Boot0000);
+    if (FilePath == NULL) {
+      DEBUG ((DEBUG_ERROR, "Fail to allocate memory for default boot file path. Unable to boot.\n"));
+      CpuDeadLoop ();
+    }
+
+    PlatformDefaultBoot0000Valid = EfiBootManagerInitializeLoadOption (
+                                      &PlatformDefaultBoot0000,
+                                      0,
+                                      LoadOptionTypeBoot,
+                                      LOAD_OPTION_ACTIVE,
+                                      L"Default PlatformBoot",
+                                      FilePath,
+                                      NULL,
+                                      0
+                                      ) == EFI_SUCCESS;
+
+    DEBUG ((DEBUG_ERROR, "%d\n", PlatformDefaultBoot0000Valid));
+    ASSERT (PlatformDefaultBoot0000Valid == TRUE);
+    if (PlatformDefaultBoot0000Valid) {
+      EfiBootManagerLoadOptionToVariable(&PlatformDefaultBoot0000);
+      EfiBootManagerFreeLoadOption (&PlatformDefaultBoot0000);
+    }
+    FreePool (FilePath);
+  }
+
   //
   // Initialize the platform language variables
   //
-- 
2.43.0

Reply via email to