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 10/16] bootm: support multiple entries for bootm.initrd
Date: Thu, 12 Mar 2026 15:44:53 +0100	[thread overview]
Message-ID: <20260312144505.2159816-10-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260312144505.2159816-1-a.fatoum@pengutronix.de>

Linux can extract transparently any number of concatenated CPIOs, even
if individually compressed. This can be useful if we have two CPIOs from
different sources, e.g. an rdinit and a CPIO with the kernel modules.

Teach bootm how to collect multiple initrd entries by leveraging the
loadable chaining support.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootm-fit.c       | 13 +++++++++----
 common/bootm-overrides.c | 17 +++++++----------
 common/bootm.c           |  7 ++++---
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/common/bootm-fit.c b/common/bootm-fit.c
index 089f376fd7f1..5b110ad2f19e 100644
--- a/common/bootm-fit.c
+++ b/common/bootm-fit.c
@@ -36,7 +36,7 @@ static void loadable_from_fit_os(struct image_data *data,
  * @fit:		handle of FIT image
  * @config:		config to look up kernel in
  *
- * This creates a loadable for the first initial ram disk in the config.
+ * This creates loadables for all initial ram disks in the config and chains them.
  *
  * Return: true if initrd booting is supported and a ramdisk exists or
  *         false otherwise.
@@ -45,17 +45,22 @@ static bool loadable_from_fit_initrd(struct image_data *data,
 				struct fit_handle *fit,
 				void *config)
 {
+	int nramdisks;
+
 	if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
 		return false;
 
-	if (!fit_has_image(fit, config, "ramdisk"))
+	nramdisks = fit_count_images(fit, config, "ramdisk");
+	if (nramdisks < 0)
 		return false;
 
 	loadable_release(&data->initrd);
 
-	data->initrd = loadable_from_fit(fit, config, "ramdisk", 0, LOADABLE_INITRD);
+	for (int i = 0; i < nramdisks; i++)
+		loadable_chain(&data->initrd, loadable_from_fit(fit, config, "ramdisk",
+								i, LOADABLE_INITRD));
 
-	return true;
+	return nramdisks > 0;
 }
 
 /*
diff --git a/common/bootm-overrides.c b/common/bootm-overrides.c
index c1f3ee7cade8..59ca90a58684 100644
--- a/common/bootm-overrides.c
+++ b/common/bootm-overrides.c
@@ -20,16 +20,12 @@ int bootm_apply_overrides(struct image_data *data,
 	if (bootm_signed_images_are_forced())
 		return 0;
 
-	if (overrides->initrd_file) {
-		loadable_release(&data->initrd);
-
-		/* Empty string means to mask the original initrd */
-		if (nonempty(overrides->initrd_file)) {
-			data->initrd = loadable_from_file(overrides->initrd_file,
-							   LOADABLE_INITRD);
-			if (IS_ERR(data->initrd))
-				return PTR_ERR(data->initrd);
-		}
+	if (IS_ENABLED(CONFIG_BOOTM_INITRD) && overrides->initrd_file) {
+		/* loadables_from_files() will set data->initrd on empty initrd_file */
+		int ret = loadables_from_files(&data->initrd, overrides->initrd_file, ":",
+					       LOADABLE_INITRD);
+		if (ret)
+			return ret;
 		data->is_override.initrd = true;
 	}
 
@@ -48,3 +44,4 @@ int bootm_apply_overrides(struct image_data *data,
 
 	return 0;
 }
+
diff --git a/common/bootm.c b/common/bootm.c
index 25cbce6ccb3f..ddc656fb34c8 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -463,9 +463,10 @@ static int bootm_open_files(struct image_data *data)
 	}
 
 	if (data->initrd_file) {
-		data->initrd = loadable_from_file(data->initrd_file, LOADABLE_INITRD);
-		if (IS_ERR(data->initrd))
-			return PTR_ERR(data->initrd);
+		int ret = loadables_from_files(&data->initrd, data->initrd_file, ":",
+					       LOADABLE_INITRD);
+		if (ret)
+			return ret;
 	}
 
 	if (data->tee_file) {
-- 
2.47.3




  parent reply	other threads:[~2026-03-12 14:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 14:44 [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 02/16] bootm: split preparatory step from handler invocation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 03/16] boot: add bootm_boot wrapper that takes struct bootentry Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 04/16] bootchooser: pass along " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 05/16] bootm: switch plain file names case to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 06/16] uimage: add offset parameter to uimage_load Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 07/16] bootm: uimage: switch to loadable API Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 08/16] bootm: fit: switch to new " Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 09/16] bootm: stash initial OS address/entry in image_data Ahmad Fatoum
2026-03-12 14:44 ` Ahmad Fatoum [this message]
2026-03-12 14:44 ` [PATCH 11/16] bootm: implement plain and FIT bootm.image override Ahmad Fatoum
2026-03-18  9:01   ` Sascha Hauer
2026-03-18  9:17     ` Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 12/16] bootm: overrides: add support for overlays Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 13/16] test: py: add test for initrd concatenation Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 14/16] defaultenv: base: add new devboot script Ahmad Fatoum
2026-03-18  9:50   ` Sascha Hauer
2026-03-18 10:50     ` Ahmad Fatoum
2026-03-18 14:49       ` Sascha Hauer
2026-03-12 14:44 ` [PATCH 15/16] Documentation: user: devboot: add section on forwarding build dirs Ahmad Fatoum
2026-03-12 14:44 ` [PATCH 16/16] libfile: remove file_to_sdram Ahmad Fatoum
2026-03-18 10:06 ` [PATCH 01/16] lib: add lazy loadable infrastructure for deferred boot component loading 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=20260312144505.2159816-10-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