Skip to contentSkip to conversation

spl: return header size to spl_load in os boot

PATCH In review Anshul Dalal 2 participants 2 messages Mar 11, 2025 – Mar 31, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 spl: return header size to spl_load in os boot

During linux build process the header size is computed including the BSS whereas it's removed when creating the uncompressed image. Therefore the size of the uncompressed image on filesystem will be smaller than the size specified in the header.

This causes issues when loading the kernel image from the SPL (as in falcon boot) with spl_load since it compares the read file size from the FS to the header size form the image. Which leads to the following check in include/spl_load.h failing to -EIO when loading kernel image:

return read < spl_image->size ? -EIO : 0;

Therefore we should return the header size back to spl_load instead of the file size in falcon boot when not loading a FIT image.

Bug report:
https://lore.kernel.org/u-boot/[email protected]/

Fixes 775074165d97 ("spl: Add generic spl_load function")

---
Changes in v3:
* Added header check for FIT image instead of using CMD_BOOTI
v2: https://lore.kernel.org/u-boot/[email protected]/
Changes in v2:
* Add R-by and fixes tags
* Expanded commit description with more information
v1: https://lore.kernel.org/u-boot/[email protected]/

---
 common/spl/spl_ext.c | 8 ++++++++
 common/spl/spl_fat.c | 7 +++++++
 2 files changed, 15 insertions(+)
common/spl/spl_ext.c +8 -0
index c5478820a9b..7e0274a3058 100644
@@ -11,12 +11,20 @@
 static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
 {
+	struct legacy_img_hdr *header;
 	int ret;
 	loff_t actlen;
 
 	ret = ext4fs_read(buf, file_offset, size, &actlen);
 	if (ret)
 		return ret;
+
+	if (CONFIG_IS_ENABLED(OS_BOOT)) {
+		header = (struct legacy_img_hdr *)buf;
+		if (image_get_magic(header) != FDT_MAGIC)
+			return size;
+	}
+
 	return actlen;
 }
 
common/spl/spl_fat.c +7 -0
index fce451b7664..f426a068ff9 100644
@@ -47,6 +47,7 @@ static int spl_register_fat_device(struct blk_desc *block_dev, int partition)
 static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
 {
+	struct legacy_img_hdr *header;
 	loff_t actread;
 	int ret;
 	char *filename = load->priv;
@@ -55,6 +56,12 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
 	if (ret)
 		return ret;
 
+	if (CONFIG_IS_ENABLED(OS_BOOT)) {
+		header = (struct legacy_img_hdr *)buf;
+		if (image_get_magic(header) != FDT_MAGIC)
+			return size;
+	}
+
 	return actread;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 11 lines · Anshul Dalal

During linux build process the header size is computed including the BSS whereas it's removed when creating the uncompressed image. Therefore the size of the uncompressed image on filesystem will be smaller than the size specified in the header.

This causes issues when loading the kernel image from the SPL (as in falcon boot) with spl_load since it compares the read file size from the FS to the header size form the image. Which leads to the following check in include/spl_load.h failing to -EIO when loading kernel image:

[...]

Applied to u-boot/next, thanks!

[1/1] spl: return header size to spl_load in os boot

      commit: fd2bccec19d399b4a445009b3d514d2419cfbc95
Signature · 1 line
Tom