public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hugues Morisset <morisset.hugues@gmail.com>
To: devel@edk2.groups.io
Subject: [edk2-devel] Pcd to set Boot0000 at build time
Date: Sun, 26 Nov 2023 22:54:09 +0100	[thread overview]
Message-ID: <CABQDpGVUE0R--Fei7LwEjp4zkMnhqXsPbnZjbL-LVQL0VrLsFQ@mail.gmail.com> (raw)


[-- 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


             reply	other threads:[~2023-11-28 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-26 21:54 Hugues Morisset [this message]
2024-05-22  8:18 ` [edk2-devel] Pcd to set Boot0000 at build time Hugues Morisset

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=CABQDpGVUE0R--Fei7LwEjp4zkMnhqXsPbnZjbL-LVQL0VrLsFQ@mail.gmail.com \
    --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