@@ -324,24 +324,6 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
324324 uint8_t swap_type = state -> swap_type [dep -> image_id ];
325325 dep_slot = BOOT_IS_UPGRADE (swap_type ) ? BOOT_SLOT_SECONDARY
326326 : BOOT_SLOT_PRIMARY ;
327- #elif defined(MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER )
328- switch (dep -> slot ) {
329- case VERSION_DEP_SLOT_ACTIVE :
330- dep_slot = state -> slot_usage [dep -> image_id ].active_slot ;
331- break ;
332- case VERSION_DEP_SLOT_PRIMARY :
333- dep_slot = BOOT_SLOT_PRIMARY ;
334- break ;
335- case VERSION_DEP_SLOT_SECONDARY :
336- dep_slot = BOOT_SLOT_SECONDARY ;
337- break ;
338- default :
339- return -1 ;
340- }
341-
342- if (!state -> slot_usage [dep -> image_id ].slot_available [dep_slot ]) {
343- return -1 ;
344- }
345327#else
346328 dep_slot = state -> slot_usage [dep -> image_id ].active_slot ;
347329#endif
@@ -379,27 +361,7 @@ boot_verify_slot_dependency(struct boot_loader_state *state,
379361 }
380362#endif
381363
382- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
383- if (rc == 0 ) {
384- switch (dep -> slot ) {
385- case VERSION_DEP_SLOT_PRIMARY :
386- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_PRIMARY ] = true;
387- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_SECONDARY ] = false;
388- state -> slot_usage [dep -> image_id ].active_slot = BOOT_SLOT_PRIMARY ;
389- break ;
390- case VERSION_DEP_SLOT_SECONDARY :
391- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_PRIMARY ] = false;
392- state -> slot_usage [dep -> image_id ].slot_available [BOOT_SLOT_SECONDARY ] = true;
393- state -> slot_usage [dep -> image_id ].active_slot = BOOT_SLOT_SECONDARY ;
394- break ;
395- case VERSION_DEP_SLOT_ACTIVE :
396- default :
397- break ;
398- }
399- }
400- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
401-
402- return rc ;
364+ return rc ;
403365}
404366
405367#if !defined(MCUBOOT_DIRECT_XIP ) && !defined(MCUBOOT_RAM_LOAD )
@@ -544,19 +506,6 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
544506 goto done ;
545507 }
546508
547- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
548- /* Validate against possible dependency slot values. */
549- switch (dep .slot ) {
550- case VERSION_DEP_SLOT_ACTIVE :
551- case VERSION_DEP_SLOT_PRIMARY :
552- case VERSION_DEP_SLOT_SECONDARY :
553- break ;
554- default :
555- rc = BOOT_EBADARGS ;
556- goto done ;
557- }
558- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
559-
560509 /* Verify dependency and modify the swap type if not satisfied. */
561510 rc = boot_verify_slot_dependency (state , & dep );
562511 if (rc != 0 ) {
@@ -2751,124 +2700,6 @@ boot_select_or_erase(struct boot_loader_state *state)
27512700}
27522701#endif /* MCUBOOT_DIRECT_XIP && MCUBOOT_DIRECT_XIP_REVERT */
27532702
2754- #ifdef MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER
2755- /**
2756- * Tries to load a slot for all the images with validation.
2757- *
2758- * @param state Boot loader status information.
2759- *
2760- * @return 0 on success; nonzero on failure.
2761- */
2762- fih_ret
2763- boot_load_and_validate_images (struct boot_loader_state * state )
2764- {
2765- uint32_t active_slot ;
2766- int rc ;
2767- fih_ret fih_rc ;
2768- uint32_t slot ;
2769-
2770- /* Go over all the images and all slots and validate them */
2771- IMAGES_ITER (BOOT_CURR_IMG (state )) {
2772- for (slot = 0 ; slot < BOOT_NUM_SLOTS ; slot ++ ) {
2773- #if BOOT_IMAGE_NUMBER > 1
2774- if (state -> img_mask [BOOT_CURR_IMG (state )]) {
2775- continue ;
2776- }
2777- #endif
2778-
2779- /* Save the number of the active slot. */
2780- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = slot ;
2781-
2782- #ifdef MCUBOOT_DIRECT_XIP
2783- rc = boot_rom_address_check (state );
2784- if (rc != 0 ) {
2785- /* The image is placed in an unsuitable slot. */
2786- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
2787- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
2788- continue ;
2789- }
2790-
2791- #ifdef MCUBOOT_DIRECT_XIP_REVERT
2792- rc = boot_select_or_erase (state );
2793- if (rc != 0 ) {
2794- /* The selected image slot has been erased. */
2795- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
2796- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
2797- continue ;
2798- }
2799- #endif /* MCUBOOT_DIRECT_XIP_REVERT */
2800- #endif /* MCUBOOT_DIRECT_XIP */
2801-
2802- #ifdef MCUBOOT_RAM_LOAD
2803- /* Image is first loaded to RAM and authenticated there in order to
2804- * prevent TOCTOU attack during image copy. This could be applied
2805- * when loading images from external (untrusted) flash to internal
2806- * (trusted) RAM and image is authenticated before copying.
2807- */
2808- rc = boot_load_image_to_sram (state );
2809- if (rc != 0 ) {
2810- /* Image cannot be ramloaded. */
2811- boot_remove_image_from_flash (state , slot );
2812- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
2813- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
2814- continue ;
2815- }
2816- #endif /* MCUBOOT_RAM_LOAD */
2817-
2818- FIH_CALL (boot_validate_slot , fih_rc , state , slot , NULL , 0 );
2819- if (FIH_NOT_EQ (fih_rc , FIH_SUCCESS )) {
2820- /* Image is invalid. */
2821- #ifdef MCUBOOT_RAM_LOAD
2822- boot_remove_image_from_sram (state );
2823- #endif /* MCUBOOT_RAM_LOAD */
2824- state -> slot_usage [BOOT_CURR_IMG (state )].slot_available [slot ] = false;
2825- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
2826- continue ;
2827- }
2828-
2829- /* Valid image loaded from a slot, go to the next slot. */
2830- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = BOOT_SLOT_NONE ;
2831- }
2832- }
2833-
2834- /* Go over all the images and all slots and validate them */
2835- IMAGES_ITER (BOOT_CURR_IMG (state )) {
2836- /* All slots tried until a valid image found. Breaking from this loop
2837- * means that a valid image found or already loaded. If no slot is
2838- * found the function returns with error code. */
2839- while (true) {
2840- /* Go over all the slots and try to load one */
2841- active_slot = state -> slot_usage [BOOT_CURR_IMG (state )].active_slot ;
2842- if (active_slot != BOOT_SLOT_NONE ){
2843- /* A slot is already active, go to next image. */
2844- break ;
2845- }
2846-
2847- rc = BOOT_HOOK_FIND_SLOT_CALL (boot_find_next_slot_hook , BOOT_HOOK_REGULAR ,
2848- state , BOOT_CURR_IMG (state ), & active_slot );
2849- if (rc == BOOT_HOOK_REGULAR ) {
2850- active_slot = find_slot_with_highest_version (state );
2851- }
2852-
2853- if (active_slot == BOOT_SLOT_NONE ) {
2854- BOOT_LOG_INF ("No slot to load for image %d" ,
2855- BOOT_CURR_IMG (state ));
2856- FIH_RET (FIH_FAILURE );
2857- }
2858-
2859- /* Save the number of the active slot. */
2860- state -> slot_usage [BOOT_CURR_IMG (state )].active_slot = active_slot ;
2861-
2862- /* Valid image loaded from a slot, go to the next image. */
2863- break ;
2864- }
2865- }
2866-
2867- FIH_RET (FIH_SUCCESS );
2868- }
2869-
2870- #else /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
2871-
28722703/**
28732704 * Tries to load a slot for all the images with validation.
28742705 *
@@ -2971,7 +2802,6 @@ boot_load_and_validate_images(struct boot_loader_state *state)
29712802
29722803 FIH_RET (FIH_SUCCESS );
29732804}
2974- #endif /* MCUBOOT_VERSION_CMP_USE_SLOT_NUMBER */
29752805
29762806/**
29772807 * Updates the security counter for the current image.
0 commit comments