[PATCH 4/5] spl: fit: Record loadables to spl_image->fdt_addr

Nikita Shubin <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <20260807-riscv-full-fit-support-v1-4-21a34f79c350__48197.6672237337$1786090343$gmane$org@maquefel.me>
Record lodable to FDT passed to next boot stage.

This is required for spl_invoke_opensbi(), for example, which requires
u-boot/kernel load or entry address to fill opensbi_info.next_addr
entry.

spl_load_simple_fit() does it, make spl_load_fit_image() also capable of
recording lodables.

Signed-off-by: Nikita Shubin <[email protected]>
---
 common/spl/spl_fit.c | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 4d4a96d1c4c..07e387ac7ee 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -991,7 +991,7 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 	const char *uname;
 	ulong fw_data = 0, dt_data = 0, img_data = 0;
 	ulong fw_len = 0, dt_len = 0, img_len = 0;
-	int idx, conf_noffset;
+	int idx, conf_noffset, noffset;
 	int ret;
 
 	images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE);
@@ -1048,17 +1048,43 @@ int spl_load_fit_image(struct spl_image_info *spl_image,
 	for (idx = 0;
 	     uname = fdt_stringlist_get((const void *)header, conf_noffset,
 					FIT_LOADABLE_PROP, idx,
-				NULL), uname;
+					NULL), uname;
 	     idx++) {
 		images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE);
 
-		ret = fit_image_load(&images, virt_to_phys((void *)header),
-				     &uname, &fit_uname_config,
-				     IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1,
-				     FIT_LOAD_OPTIONAL_NON_ZERO,
-				     &img_data, &img_len);
-		if (ret < 0)
-			return ret;
+		noffset = fit_image_load(&images, virt_to_phys((void *)header),
+					 &uname, &fit_uname_config,
+					 IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1,
+					 FIT_LOAD_OPTIONAL_NON_ZERO,
+					 &img_data, &img_len);
+		if (noffset < 0)
+			return noffset;
+
+		/* Record our loadables into the FDT */
+		if (spl_image->fdt_addr) {
+			ulong entry_addr = -1;
+
+			fit_image_get_entry((const void *)header, noffset, &entry_addr);
+			debug(PHASE_PROMPT "record_loadable: %s entry addr: 0x%lx\n",
+			      uname, entry_addr);
+
+			/* Try to make space, so we can inject details on the loadable */
+			ret = fdt_increase_size(spl_image->fdt_addr, 256);
+			if (ret < 0) {
+				debug(PHASE_PROMPT "record_loadable: couldn't increase space " \
+				      "for fdt: %d\n", ret);
+				continue;
+			}
+
+			ret = fdt_record_loadable(spl_image->fdt_addr, idx, uname,
+						  img_data, img_len, entry_addr,
+						  fdt_getprop((const void *)header, noffset, FIT_TYPE_PROP, NULL),
+						  fdt_getprop((const void *)header, noffset, FIT_OS_PROP, NULL),
+						  fdt_getprop((const void *)header, noffset, FIT_ARCH_PROP, NULL));
+			if (ret < 0)
+				debug(PHASE_PROMPT "record_loadable: couldn't " \
+				      "record loadable: %s\n", uname);
+		}
 	}
 	spl_image->flags |= SPL_FIT_FOUND;
 

-- 
2.52.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.