public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] Pcd to set Boot0000 at build time
@ 2023-11-26 21:54 Hugues Morisset
  2024-05-22  8:18 ` Hugues Morisset
  0 siblings, 1 reply; 2+ messages in thread
From: Hugues Morisset @ 2023-11-26 21:54 UTC (permalink / raw)
  To: devel


[-- Attachment #1.1: Type: text/plain, Size: 647 bytes --]

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/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #1.2: Type: text/html, Size: 1172 bytes --]

[-- Attachment #2: 0001-BdsDxe-Add-at-build-user-provided-Boot0000-entry.patch --]
[-- Type: text/x-patch, Size: 3988 bytes --]

From e987ac0881d4a5587e445edf1ddeda87bb2ffc03 Mon Sep 17 00:00:00 2001
From: Hugues Morisset <morisset.hugues@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.hugues@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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-22 21:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-26 21:54 [edk2-devel] Pcd to set Boot0000 at build time Hugues Morisset
2024-05-22  8:18 ` Hugues Morisset

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox