diff mbox series

[v6,22/25] spl: Convert semihosting to spl_load

Message ID 20231106022603.3405551-23-seanga2@gmail.com
State Superseded
Delegated to: Tom Rini
Headers show
Series spl: Use common function for loading/parsing images | expand

Commit Message

Sean Anderson Nov. 6, 2023, 2:26 a.m. UTC
This converts the semihosting load method to use spl_load. As a result, it
also adds support for LOAD_FIT_FULL and IMX images.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

Changes in v6:
- Explicitly initialize load_info members

Changes in v5:
- Rework to load header in spl_load

Changes in v2:
- New

 common/spl/spl_semihosting.c | 52 +++++-------------------------------
 include/spl_load.h           |  1 +
 2 files changed, 7 insertions(+), 46 deletions(-)
diff mbox series

Patch

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 9b0610b8fc8..941fa911040 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -8,18 +8,7 @@ 
 #include <log.h>
 #include <semihosting.h>
 #include <spl.h>
-
-static int smh_read_full(long fd, void *memp, size_t len)
-{
-	long read;
-
-	read = smh_read(fd, memp, len);
-	if (read < 0)
-		return read;
-	if (read != len)
-		return -EIO;
-	return 0;
-}
+#include <spl_load.h>
 
 static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
 			  ulong size, void *buf)
@@ -40,8 +29,7 @@  static int spl_smh_load_image(struct spl_image_info *spl_image,
 	const char *filename = CONFIG_SPL_FS_LOAD_PAYLOAD_NAME;
 	int ret;
 	long fd, len;
-	struct legacy_img_hdr *header =
-		spl_get_load_buffer(-sizeof(*header), sizeof(*header));
+	struct spl_load_info load;
 
 	fd = smh_open(filename, MODE_READ | MODE_BINARY);
 	if (fd < 0) {
@@ -56,38 +44,10 @@  static int spl_smh_load_image(struct spl_image_info *spl_image,
 	}
 	len = ret;
 
-	ret = smh_read_full(fd, header, sizeof(struct legacy_img_hdr));
-	if (ret) {
-		log_debug("could not read image header: %d\n", ret);
-		goto out;
-	}
-
-	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
-	    image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		debug("Found FIT\n");
-		load.read = smh_fit_read;
-		spl_set_bl_len(&load, 1);
-		load.priv = &fd;
-
-		ret = spl_load_simple_fit(spl_image, &load, 0, header);
-		goto out;
-	}
-
-	ret = spl_parse_image_header(spl_image, bootdev, header);
-	if (ret) {
-		log_debug("failed to parse image header: %d\n", ret);
-		goto out;
-	}
-
-	ret = smh_seek(fd, 0);
-	if (ret) {
-		log_debug("could not seek to start of image: %d\n", ret);
-		goto out;
-	}
-
-	ret = smh_read_full(fd, (void *)spl_image->load_addr, len);
+	load.read = smh_fit_read;
+	spl_set_bl_len(&load, 1);
+	load.priv = &fd;
+	ret = spl_load(spl_image, bootdev, &load, len, 0);
 	if (ret)
 		log_debug("could not read %s: %d\n", filename, ret);
 out:
diff --git a/include/spl_load.h b/include/spl_load.h
index 2618109cee0..2a20e866cd8 100644
--- a/include/spl_load.h
+++ b/include/spl_load.h
@@ -102,6 +102,7 @@  static inline int _spl_load(struct spl_image_info *spl_image,
 	(IS_ENABLED(CONFIG_SPL_NAND_SUPPORT) && !IS_ENABLED(CONFIG_SPL_UBI)) + \
 	IS_ENABLED(CONFIG_SPL_NET) + \
 	IS_ENABLED(CONFIG_SPL_NOR_SUPPORT) + \
+	IS_ENABLED(CONFIG_SPL_SEMIHOSTING) + \
 	0
 
 #if SPL_LOAD_USERS > 1