[RFC PATCH] imx: hab: Support FIT images with external data
Ariel D'Alessandro
ariel.dalessandro at collabora.com
Wed Apr 20 17:18:31 CEST 2022
The IVT table is located right after the FIT image. If the FIT image is
generated using external data, the total size needs to be computed
including the FIT struct and external data lengths.
Signed-off-by: Ariel D'Alessandro <ariel.dalessandro at collabora.com>
---
arch/arm/mach-imx/hab.c | 3 ++-
boot/image-fit.c | 44 +++++++++++++++++++++++++++++++++++++++++
include/image.h | 9 +++++++++
3 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index 55317abba23..d0bee716772 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -593,7 +593,8 @@ static ulong get_image_ivt_offset(ulong img_addr)
#endif
#if CONFIG_IS_ENABLED(FIT)
case IMAGE_FORMAT_FIT:
- return (fit_get_size(buf) + 0x1000 - 1) & ~(0x1000 - 1);
+ return (fit_get_size_external(buf)
+ + 0x1000 - 1) & ~(0x1000 - 1);
#endif
default:
return 0;
diff --git a/boot/image-fit.c b/boot/image-fit.c
index 6610035d0ad..7a9b6b6c71d 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -1168,6 +1168,50 @@ ulong fit_get_end(const void *fit)
return map_to_sysmem((void *)(fit + fdt_totalsize(fit)));
}
+ulong fit_get_size_external(const void *fit)
+{
+ int images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
+ unsigned int ret = fit_get_size(fit);
+ int noffset, ndepth, offset;
+ const void *data;
+ size_t size;
+
+ /* Find images parent node offset */
+ if (images_noffset < 0) {
+ printf("Can't find images parent node '%s' (%s)\n",
+ FIT_IMAGES_PATH, fdt_strerror(images_noffset));
+ return 0;
+ }
+
+ /* Process its subnodes, print out component images details */
+ for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth);
+ (noffset >= 0) && (ndepth > 0);
+ noffset = fdt_next_node(fit, noffset, &ndepth)) {
+ /*
+ * Omit indirect child nodes of the images parent node, as it's
+ * not a component image node.
+ */
+ if (ndepth != 1)
+ continue;
+
+ /* Omit images that are not external, as its size is already
+ * included in the FIT image.
+ */
+ if (fit_image_get_data_position(fit, noffset, &offset) &&
+ fit_image_get_data_offset(fit, noffset, &offset))
+ continue;
+
+ if (fit_image_get_data_and_size(fit, noffset, &data, &size)) {
+ printf("Couldn't get image data/size (noffset=%d)\n",
+ noffset);
+ return 0;
+ }
+ ret += size;
+ }
+
+ return ret;
+}
+
/**
* fit_set_timestamp - set node timestamp property
* @fit: pointer to the FIT format image header
diff --git a/include/image.h b/include/image.h
index e4c6a50b885..012ea28ba1b 100644
--- a/include/image.h
+++ b/include/image.h
@@ -979,6 +979,15 @@ static inline ulong fit_get_size(const void *fit)
*/
ulong fit_get_end(const void *fit);
+/**
+ * fit_get_size_external - get FIT image size including external data
+ * @fit: pointer to the FIT format image header
+ *
+ * returns:
+ * size of the FIT image (including external data) in memory
+ */
+ulong fit_get_size_external(const void *fit);
+
/**
* fit_get_name - get FIT node name
* @fit: pointer to the FIT format image header
--
2.34.1
More information about the U-Boot
mailing list