Skip to content

Commit 6a178d2

Browse files
tomchynordicjm
authored andcommitted
bootutil: Use flash base address for direct hash
Fetch the flash base address if direct hash calculation is performed. Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
1 parent 3430520 commit 6a178d2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

boot/bootutil/src/image_validate.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ bootutil_img_hash(struct boot_loader_state *state,
8484
uint32_t off;
8585
uint32_t blk_sz;
8686
#endif
87+
#ifdef MCUBOOT_HASH_STORAGE_DIRECTLY
88+
uintptr_t base = 0;
89+
int fa_ret;
90+
#endif
8791
#if defined(MCUBOOT_ENC_IMAGES)
8892
struct enc_key_data *enc_state;
8993
int image_index;
@@ -153,7 +157,12 @@ bootutil_img_hash(struct boot_loader_state *state,
153157
/* No chunk loading, storage is mapped to address space and can
154158
* be directly given to hashing function.
155159
*/
156-
bootutil_sha_update(&sha_ctx, (void *)flash_area_get_off(fap), size);
160+
fa_ret = flash_device_base(flash_area_get_device_id(fap), &base);
161+
if (fa_ret != 0) {
162+
base = 0;
163+
}
164+
165+
bootutil_sha_update(&sha_ctx, (void *)(base + flash_area_get_off(fap)), size);
157166
#else /* MCUBOOT_HASH_STORAGE_DIRECTLY */
158167
#ifdef MCUBOOT_RAM_LOAD
159168
bootutil_sha_update(&sha_ctx,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Fixed issue in image_validate when `MCUBOOT_HASH_STORAGE_DIRECTLY` is enabled
2+
for platforms with NVM memory that does not start at 0x00.

0 commit comments

Comments
 (0)