@@ -391,24 +391,6 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
391391 uint8_t swap_type = state -> swap_type [dep -> image_id ];
392392 dep_slot = BOOT_IS_UPGRADE (swap_type ) ? BOOT_SLOT_SECONDARY
393393 : BOOT_SLOT_PRIMARY ;
394- #elif defined(MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER )
395- switch (dep -> slot ) {
396- case VERSION_DEP_SLOT_ACTIVE :
397- dep_slot = state -> slot_usage [dep -> image_id ].active_slot ;
398- break ;
399- case VERSION_DEP_SLOT_PRIMARY :
400- dep_slot = BOOT_SLOT_PRIMARY ;
401- break ;
402- case VERSION_DEP_SLOT_SECONDARY :
403- dep_slot = BOOT_SLOT_SECONDARY ;
404- break ;
405- default :
406- return -1 ;
407- }
408-
409- if (!state -> slot_usage [dep -> image_id ].slot_available [dep_slot ]) {
410- return -1 ;
411- }
412394#else
413395 dep_slot = state -> slot_usage [dep -> image_id ].active_slot ;
414396#endif
@@ -446,27 +428,7 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
446428 }
447429#endif
448430
449- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
450- if (rc == 0 ) {
451- switch (dep -> slot ) {
452- case VERSION_DEP_SLOT_PRIMARY :
453- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_PRIMARY ] = true;
454- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_SECONDARY ] = false;
455- state -> slot_usage [dep -> image_id ].active_slot = BOOT_SLOT_PRIMARY ;
456- break ;
457- case VERSION_DEP_SLOT_SECONDARY :
458- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_PRIMARY ] = false;
459- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_SECONDARY ] = true;
460- state -> slot_usage [dep -> image_id ].active_slot = BOOT_SLOT_SECONDARY ;
461- break ;
462- case VERSION_DEP_SLOT_ACTIVE :
463- default :
464- break ;
465- }
466- }
467- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
468-
469- return rc ;
431+ return rc ;
470432}
471433
472434#if !defined(MCUBOOT_DIRECT_XIP ) && !defined(MCUBOOT_RAM_LOAD )
@@ -614,19 +576,6 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
614576 goto done ;
615577 }
616578
617- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
618- /* Validate against possible dependency slot values. */
619- switch (dep .slot ) {
620- case VERSION_DEP_SLOT_ACTIVE :
621- case VERSION_DEP_SLOT_PRIMARY :
622- case VERSION_DEP_SLOT_SECONDARY :
623- break ;
624- default :
625- rc = BOOT_EBADARGS ;
626- goto done ;
627- }
628- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
629-
630579 /* Verify dependency and modify the swap type if not satisfied. */
631580 rc = boot_verify_slot_dependency (state , & dep );
632581 if (rc != 0 ) {
@@ -3281,124 +3230,6 @@ boot_select_or_erase(struct boot_loader_state *state)
32813230}
32823231#endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_DIRECT_XIP_REVERT */
32833232
3284- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
3285- /**
3286- * Tries to load a slot for all the images with validation.
3287- *
3288- * @param state Boot loader status information.
3289- *
3290- * @return 0 on success; nonzero on failure.
3291- */
3292- fih_ret
3293- boot_load_and_validate_images (struct boot_loader_state * state )
3294- {
3295- uint32_t active_slot ;
3296- int rc ;
3297- fih_ret fih_rc ;
3298- uint32_t slot ;
3299-
3300- /* Go over all the images and all slots and validate them */
3301- IMAGES_ITER (BOOT_CURR_IMG (state )) {
3302- for (slot = 0 ; slot < BOOT_NUM_SLOTS ; slot ++ ) {
3303- #if BOOT_IMAGE_NUMBER > 1
3304- if (state -> img_mask [BOOT_CURR_IMG (state )]) {
3305- continue ;
3306- }
3307- #endif
3308-
3309- /* Save the number of the active slot. */
3310- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = slot ;
3311-
3312- #ifdef MCUBOOT_DIRECT_XIP
3313- rc = boot_rom_address_check (state );
3314- if (rc != 0 ) {
3315- /* The image is placed in an unsuitable slot. */
3316- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
3317- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
3318- continue ;
3319- }
3320-
3321- #ifdef MCUBOOT_DIRECT_XIP_REVERT
3322- rc = boot_select_or_erase (state );
3323- if (rc != 0 ) {
3324- /* The selected image slot has been erased. */
3325- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
3326- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
3327- continue ;
3328- }
3329- #endif /* MCUBOOT_DIRECT_XIP_REVERT */
3330- #endif /* MCUBOOT_DIRECT_XIP */
3331-
3332- #ifdef MCUBOOT_RAM_LOAD
3333- /* Image is first loaded to RAM and authenticated there in order to
3334- * prevent TOCTOU attack during image copy. This could be applied
3335- * when loading images from external (untrusted) flash to internal
3336- * (trusted) RAM and image is authenticated before copying.
3337- */
3338- rc = boot_load_image_to_sram (state );
3339- if (rc != 0 ) {
3340- /* Image cannot be ramloaded. */
3341- boot_remove_image_from_flash (state , slot );
3342- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
3343- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
3344- continue ;
3345- }
3346- #endif /* MCUBOOT_RAM_LOAD */
3347-
3348- FIH_CALL (boot_validate_slot , fih_rc , state , slot , NULL , 0 );
3349- if (FIH_NOT_EQ (fih_rc , FIH_SUCCESS )) {
3350- /* Image is invalid. */
3351- #ifdef MCUBOOT_RAM_LOAD
3352- boot_remove_image_from_sram (state );
3353- #endif /* MCUBOOT_RAM_LOAD */
3354- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
3355- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
3356- continue ;
3357- }
3358-
3359- /* Valid image loaded from a slot, go to the next slot. */
3360- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
3361- }
3362- }
3363-
3364- /* Go over all the images and all slots and validate them */
3365- IMAGES_ITER (BOOT_CURR_IMG (state )) {
3366- /* All slots tried until a valid image found. Breaking from this loop
3367- * means that a valid image found or already loaded. If no slot is
3368- * found the function returns with error code. */
3369- while (true) {
3370- /* Go over all the slots and try to load one */
3371- active_slot = state -> slot_usage [BOOT_CURR_IMG (state )].active_slot ;
3372- if (active_slot != BOOT_SLOT_NONE ){
3373- /* A slot is already active, go to next image. */
3374- break ;
3375- }
3376-
3377- rc = BOOT_HOOK_FIND_SLOT_CALL (boot_find_next_slot_hook , BOOT_HOOK_REGULAR ,
3378- state , BOOT_CURR_IMG (state ), & active_slot );
3379- if (rc == BOOT_HOOK_REGULAR ) {
3380- active_slot = find_slot_with_highest_version (state );
3381- }
3382-
3383- if (active_slot == BOOT_SLOT_NONE ) {
3384- BOOT_LOG_INF ("No slot to load for image %d" ,
3385- BOOT_CURR_IMG (state ));
3386- FIH_RET (FIH_FAILURE );
3387- }
3388-
3389- /* Save the number of the active slot. */
3390- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = active_slot ;
3391-
3392- /* Valid image loaded from a slot, go to the next image. */
3393- break ;
3394- }
3395- }
3396-
3397- FIH_RET (FIH_SUCCESS );
3398- }
3399-
3400- #else /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
3401-
34023233/**
34033234 * Tries to load a slot for all the images with validation.
34043235 *
@@ -3501,7 +3332,6 @@ boot_load_and_validate_images(struct boot_loader_state *state)
35013332
35023333 FIH_RET (FIH_SUCCESS );
35033334}
3504- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
35053335
35063336/**
35073337 * Updates the security counter for the current image.
0 commit comments