Skip to content

Commit 714ed07

Browse files
committed
bootutil: Rework boot_validate_slot
Little bit of rework with additional log info. Signed-off-by: Dominik Ermel <[email protected]>
1 parent aed3fb9 commit 714ed07

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

boot/bootutil/src/loader.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,17 +1009,24 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
10091009
* This feature is only supported by ARM platforms.
10101010
*/
10111011
if (fap == BOOT_IMG_AREA(state, BOOT_SLOT_SECONDARY)) {
1012-
const struct flash_area *pri_fa = BOOT_IMG_AREA(state, BOOT_SLOT_PRIMARY);
10131012
struct image_header *secondary_hdr = boot_img_hdr(state, slot);
1014-
uint32_t reset_value = 0;
1015-
uint32_t reset_addr = secondary_hdr->ih_hdr_size + sizeof(reset_value);
1013+
uint32_t internal_img_addr = 0;
1014+
uint32_t min_addr;
1015+
uint32_t max_addr;
1016+
uint32_t offset = secondary_hdr->ih_hdr_size + sizeof(internal_img_addr);
10161017

1017-
if (flash_area_read(fap, reset_addr, &reset_value, sizeof(reset_value)) != 0) {
1018+
min_addr = flash_area_get_off(BOOT_IMG_AREA(state, BOOT_SLOT_PRIMARY));
1019+
max_addr = flash_area_get_size(BOOT_IMG_AREA(state, BOOT_SLOT_PRIMARY)) + min_addr;
1020+
1021+
if (flash_area_read(fap, offset, &internal_img_addr, sizeof(internl_img_addr)) != 0) {
10181022
fih_rc = FIH_NO_BOOTABLE_IMAGE;
10191023
goto out;
10201024
}
10211025

1022-
if (reset_value < pri_fa->fa_off || reset_value> (pri_fa->fa_off + pri_fa->fa_size)) {
1026+
BOOT_LOG_DBG("Image %d expected load address 0x%x", BOOT_CURR_IMG(state), internal_img_addr);
1027+
BOOT_LOG_DBG("Check 0x%x is within [min_addr, max_addr] = [0x%x, 0x%x)",
1028+
internal_img_addr, min_addr, max_addr);
1029+
if (internal_img_addr < min_addr || internal_img_addr >= max_addr) {
10231030
BOOT_LOG_ERR("Reset address of image in secondary slot is not in the primary slot");
10241031
BOOT_LOG_ERR("Erasing image from secondary slot");
10251032

0 commit comments

Comments
 (0)