Add macro to get TLVs offset from header
TLV offset was determined by manually adding the header and image
size in many places; this makes the addition into a macro receiving
a image_header to ease future changes.
Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index 01efbcb..a496bc4 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -69,6 +69,7 @@
#if (BOOT_IMAGE_NUMBER == 1) || !defined(MCUBOOT_ENC_IMAGES)
(void)enc_state;
(void)image_index;
+ (void)hdr_size;
#endif
bootutil_sha256_init(&sha256_ctx);
@@ -89,7 +90,7 @@
/* Hash is computed over image header and image itself. */
hdr_size = hdr->ih_hdr_size;
- size = hdr->ih_img_size + hdr_size;
+ size = BOOT_TLV_OFF(hdr);
#if (MCUBOOT_IMAGE_NUMBER > 1)
/* If dependency TLVs are present then the TLV info header and the
@@ -231,7 +232,7 @@
}
/* The TLVs come after the image. */
- off = hdr->ih_img_size + hdr->ih_hdr_size;
+ off = BOOT_TLV_OFF(hdr);
rc = flash_area_read(fap, off, &info, sizeof(info));
if (rc) {