Skip to content

Commit 6192328

Browse files
tomchynordicjm
authored andcommitted
[nrf fromtree] bootutil: Use flash base address for direct hash
Fetch the flash base address if direct hash calculation is performed. Signed-off-by: Tomasz Chyrowicz <[email protected]> (cherry picked from commit 6a178d2)
1 parent 9571f88 commit 6192328

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
@@ -92,6 +92,10 @@ bootutil_img_hash(struct boot_loader_state *state,
9292
uint32_t off;
9393
uint32_t blk_sz;
9494
#endif
95+
#ifdef MCUBOOT_HASH_STORAGE_DIRECTLY
96+
uintptr_t base = 0;
97+
int fa_ret;
98+
#endif
9599
#if defined(MCUBOOT_ENC_IMAGES)
96100
struct enc_key_data *enc_state;
97101
int image_index;
@@ -165,7 +169,12 @@ bootutil_img_hash(struct boot_loader_state *state,
165169
/* No chunk loading, storage is mapped to address space and can
166170
* be directly given to hashing function.
167171
*/
168-
bootutil_sha_update(&sha_ctx, (void *)flash_area_get_off(fap), size);
172+
fa_ret = flash_device_base(flash_area_get_device_id(fap), &base);
173+
if (fa_ret != 0) {
174+
base = 0;
175+
}
176+
177+
bootutil_sha_update(&sha_ctx, (void *)(base + flash_area_get_off(fap)), size);
169178
#else /* MCUBOOT_HASH_STORAGE_DIRECTLY */
170179
#ifdef MCUBOOT_RAM_LOAD
171180
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)