mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 15/16] efi: payload: initrd: move into common efi code
Date: Thu, 11 Dec 2025 21:30:06 +0100	[thread overview]
Message-ID: <20251211203056.2014710-16-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251211203056.2014710-1-a.fatoum@pengutronix.de>

This code will be equally useful for barebox running as EFI loader, so
move it to a common location and touch it up to be reusable.

While at it, drop unneeded headers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/Makefile                           |  1 +
 efi/{payload/efi-initrd.c => initrd.c} | 20 +++++++++++++-------
 efi/payload/Makefile                   |  1 -
 3 files changed, 14 insertions(+), 8 deletions(-)
 rename efi/{payload/efi-initrd.c => initrd.c} (87%)

diff --git a/efi/Makefile b/efi/Makefile
index 6693564f7071..4c35917475c0 100644
--- a/efi/Makefile
+++ b/efi/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_EFI_PAYLOAD)	+= payload/
 obj-$(CONFIG_EFI_GUID)		+= guid.o
 obj-$(CONFIG_EFI_DEVICEPATH)	+= devicepath.o
 obj-y				+= errno.o handle.o efivar.o efivar-filename.o
+obj-y				+= initrd.o
diff --git a/efi/payload/efi-initrd.c b/efi/initrd.c
similarity index 87%
rename from efi/payload/efi-initrd.c
rename to efi/initrd.c
index 708418da62b7..7fd8e021f353 100644
--- a/efi/payload/efi-initrd.c
+++ b/efi/initrd.c
@@ -5,15 +5,14 @@
  * Copyright (c) 2025 Anis Chali <chalianis1@gmail.com>
  * Copyright (C) 2025 Ahmad Fatoum <a.fatoum@pengutronix.de>
  */
-#include <common.h>
-#include <driver.h>
 #include <init.h>
 #include <linux/hw_random.h>
 #include <efi/devicepath.h>
+#include <efi/mode.h>
+#include <efi/services.h>
 #include <efi/protocol/file.h>
-#include <efi/protocol/initrd.h>
+#include <efi/initrd.h>
 #include <efi/guid.h>
-#include <efi/payload.h>
 #include <efi/error.h>
 
 static efi_status_t EFIAPI efi_initrd_load_file2(
@@ -73,6 +72,7 @@ static efi_status_t EFIAPI efi_initrd_load_file2(
 
 int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 {
+	struct efi_boot_services *bs;
 	efi_status_t efiret;
 	int ret;
 
@@ -80,7 +80,11 @@ int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 	initrd.start = initrd_base;
 	initrd.size = initrd_sz;
 
-	efiret = BS->install_multiple_protocol_interfaces(
+	bs = efi_get_boot_services();
+	if (!bs)
+		return -EOPNOTSUPP;
+
+	efiret = bs->install_multiple_protocol_interfaces(
 		&initrd.lf2_handle, &efi_load_file2_protocol_guid, &initrd.base,
 		&efi_device_path_protocol_guid, &initrd_dev_path, NULL);
 	if (EFI_ERROR(efiret)) {
@@ -95,10 +99,12 @@ int efi_initrd_register(void *initrd_base, size_t initrd_sz)
 
 void efi_initrd_unregister(void)
 {
-	if (!initrd.base.load_file)
+	struct efi_boot_services *bs = efi_get_boot_services();
+
+	if (!bs || !initrd.base.load_file)
 		return;
 
-	BS->uninstall_multiple_protocol_interfaces(
+	bs->uninstall_multiple_protocol_interfaces(
 		initrd.lf2_handle, &efi_device_path_protocol_guid, &initrd_dev_path,
 		&efi_load_file2_protocol_guid, &initrd.base, NULL);
 
diff --git a/efi/payload/Makefile b/efi/payload/Makefile
index 34efe6105d22..6306540ab595 100644
--- a/efi/payload/Makefile
+++ b/efi/payload/Makefile
@@ -4,7 +4,6 @@ obj-y += init.o
 obj-y += image.o
 obj-$(CONFIG_EFI_HANDOVER_PROTOCOL) += handover.o
 obj-y += bootm.o
-obj-y += efi-initrd.o
 obj-$(CONFIG_OFTREE) += fdt.o
 bbenv-y += env-efi
 obj-$(CONFIG_CMD_IOMEM) += iomem.o
-- 
2.47.3




  parent reply	other threads:[~2025-12-11 20:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 20:29 [PATCH 00/16] efi: restructure for reuse from loader code Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 01/16] efi: payload: restructure Kconfig Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 02/16] efi: payload: populate $global.efi.payload variable Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 03/16] efi: mode: add efi_get_runtime_services helper Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 04/16] efi: payload: make EFI variable helpers usable for loader as well Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 05/16] fs: efivarfs: prepare for use with barebox as EFI loader Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 06/16] efi: handle: build for both EFI payload and loader Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 07/16] efi: provide populate $efi.payload_default_path depending on arch Ahmad Fatoum
2025-12-11 20:29 ` [PATCH 08/16] efi: tidy up header includes for reuse Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 09/16] efi: types: add efi_intn_t/efi_uintn_t definition Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 10/16] efi: devicepath: make fully usable for loader Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 11/16] efi: guid: don't interleave protocol and event GUIDs Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 12/16] efi: guid: add some more GUIDs Ahmad Fatoum
2025-12-15  8:30   ` [PATCH] fixup! " Ahmad Fatoum
2025-12-15  9:03     ` Sascha Hauer
2025-12-11 20:30 ` [PATCH 13/16] efi: guid: move static GUIDs out of drivers Ahmad Fatoum
2025-12-11 20:30 ` [PATCH 14/16] efi: gop: flesh out efi_graphics_output_protocol::blt definition Ahmad Fatoum
2025-12-11 20:30 ` Ahmad Fatoum [this message]
2025-12-11 20:30 ` [PATCH 16/16] efi: add missing EFIAPI to functions Ahmad Fatoum
2025-12-13 10:42 ` [PATCH] fixup! efi: payload: restructure Kconfig Ahmad Fatoum
2025-12-15  9:03   ` (subset) " Sascha Hauer
2025-12-15  9:03 ` [PATCH 00/16] efi: restructure for reuse from loader code Sascha Hauer

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-all 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=20251211203056.2014710-16-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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