Skip to contentSkip to conversation

common: bootm: only use initrd override if non-empty

PATCH In review [email protected] 2 participants 2 messages Aug 26, 2025 – Aug 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common: bootm: only use initrd override if non-empty

From: Chali Anis <[email protected]>

OSTree integration in Yocto generates an empty initramfs file and references it in the boot configuration (under /boot/loader/ostree-1.conf) to suppress init= kernel arguments. This caused Barebox to always prefer the override, even when the initramfs was empty, preventing booting of FIT images that already contain an embedded initramfs.

---
 common/bootm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/bootm.c +6 -2
index 3a2eb262b26a..f31ef546d92c 100644
@@ -279,14 +279,18 @@ static int bootm_open_initrd_uimage(struct image_data *data)
 const struct resource *
 bootm_load_initrd(struct image_data *data, unsigned long load_address)
 {
+	struct stat st;
 	enum filetype type;
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
 		return NULL;
 
-	if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file))
-		goto initrd_file;
+	if (bootm_get_override(&data->initrd_file,
+			       bootm_overrides.initrd_file)) {
+		if (!stat(data->initrd_file, &st) && st.st_size > 0)
+			goto initrd_file;
+	}
 
 	if (data->initrd_res)
 		return data->initrd_res;
Signature · 1 line
2.34.1
#1 lore raw

Hi,

I have some trouble understanding this patch.

Quoted 8 lines · On Tue, Aug 26, 2025 at 02:11:08AM -0400, [email protected] wrote:

From: Chali Anis <[email protected]>

OSTree integration in Yocto generates an empty initramfs file and references it in the boot configuration (under /boot/loader/ostree-1.conf) to suppress init= kernel arguments. This caused Barebox to always prefer the override, even when the initramfs was empty, preventing booting of FIT images that already contain an embedded initramfs.

So you have one initrd specified in /boot/loader/ostree-1.conf and another one in your FIT image, right?

By default and without this patch I would assume the initrd from the FIT image takes precedence, right?

Quoted 15 lines
---
 common/bootm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/bootm.c +1 -0
index 3a2eb262b26a..f31ef546d92c 100644
@@ -279,14 +279,18 @@ static int bootm_open_initrd_uimage(struct image_data *data)
 const struct resource *
 bootm_load_initrd(struct image_data *data, unsigned long load_address)
 {
+	struct stat st;

common/bootm.c static int bootm_open_initrd_uimage(struct image_data *data) · line 290

Quoted 10 lines
common/bootm.c +2 -2
 	enum filetype type;
 	int ret;
 
 	if (!IS_ENABLED(CONFIG_BOOTM_INITRD))
 		return NULL;
 
-	if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file))
-		goto initrd_file;
+	if (bootm_get_override(&data->initrd_file,
+			       bootm_overrides.initrd_file)) {

This path is only taken when bootm_overrides.initrd_file is non empty, so it seems you are booting with boot -o bootm.initrd=/some/initrd

Without this patch you would then end up using /some/initrd as initrd

common/bootm.c static int bootm_open_initrd_uimage(struct image_data *data) · line 292

Quoted 2 lines
common/bootm.c +2 -0
+		if (!stat(data->initrd_file, &st) && st.st_size > 0)
+			goto initrd_file;

Now with this patch you use /some/initrd only when it exists and is non empty. Otherwise you would end up using the initrd from the FIT image, the same initrd which would be used if you had not set -o bootm.initrd=/some/initrd.

I think I am misunderstanding something.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |