@@ -1009,17 +1009,24 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1009
1009
* This feature is only supported by ARM platforms.
1010
1010
*/
1011
1011
if (fap == BOOT_IMG_AREA (state , BOOT_SLOT_SECONDARY )) {
1012
- const struct flash_area * pri_fa = BOOT_IMG_AREA (state , BOOT_SLOT_PRIMARY );
1013
1012
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
+ const uint32_t offset = secondary_hdr -> ih_hdr_size + sizeof (internal_img_addr );
1016
1017
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 (internal_img_addr )) != 0 ) {
1018
1022
fih_rc = FIH_NO_BOOTABLE_IMAGE ;
1019
1023
goto out ;
1020
1024
}
1021
1025
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 ) {
1023
1030
BOOT_LOG_ERR ("Reset address of image in secondary slot is not in the primary slot" );
1024
1031
BOOT_LOG_ERR ("Erasing image from secondary slot" );
1025
1032
0 commit comments