[PATCH 10/16] bootm: support multiple entries for bootm.initrd

Ahmad Fatoum
2026-03-12T14:45:50Z

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