[PATCH v2 3/4] spl: Support loading a FIT from ext FS

Mayuresh Chitale mchitale at ventanamicro.com
Tue May 2 18:19:01 CEST 2023


Detect a FIT when loading from an ext File system and handle it using
the FIT SPL support.

Signed-off-by: Mayuresh Chitale <mchitale at ventanamicro.com>
---
 common/spl/spl_ext.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index 2bf3434439..8593aed069 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -8,6 +8,26 @@
 #include <ext4fs.h>
 #include <errno.h>
 #include <image.h>
+#include <linux/libfdt.h>
+
+static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset,
+			  ulong size, void *buf)
+{
+	loff_t filelen = (loff_t)load->priv, actlen;
+	char *filename = (char *)load->filename;
+	int ret;
+
+	ret = ext4fs_read(buf, file_offset, filelen, &actlen);
+	if (ret < 0) {
+		if (IS_ENABLED(CONFIG_SPL_LIBCOMMON_SUPPORT)) {
+			printf("%s: error reading image %s, err - %d\n",
+			       __func__, filename, ret);
+		}
+		return ret;
+	}
+
+	return actlen;
+}
 
 int spl_load_image_ext(struct spl_image_info *spl_image,
 		       struct spl_boot_device *bootdev,
@@ -47,6 +67,19 @@ int spl_load_image_ext(struct spl_image_info *spl_image,
 		goto end;
 	}
 
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+	    image_get_magic(header) == FDT_MAGIC) {
+		struct spl_load_info load;
+
+		debug("Found FIT\n");
+		load.read = spl_fit_read;
+		load.bl_len = 1;
+		load.filename = (void *)filename;
+		load.priv = (void *)filelen;
+
+		return spl_load_simple_fit(spl_image, &load, 0, header);
+	}
+
 	err = spl_parse_image_header(spl_image, bootdev, header);
 	if (err < 0) {
 		puts("spl: ext: failed to parse image header\n");
-- 
2.34.1



More information about the U-Boot mailing list