@@ -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;
@@ -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
@@ -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
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@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(-)