@@ -632,6 +632,7 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
632632 }
633633#endif
634634 if (!boot_check_header_valid (state , slot )) {
635+ BOOT_LOG_DBG ("boot_validate_slot: header validation failed %d" , slot );
635636 fih_rc = FIH_FAILURE ;
636637 } else {
637638 BOOT_HOOK_CALL_FIH (boot_image_check_hook , FIH_BOOT_HOOK_REGULAR ,
@@ -644,16 +645,16 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
644645check_validity :
645646#endif
646647 if (FIH_NOT_EQ (fih_rc , FIH_SUCCESS )) {
648+ #if !defined(__BOOTSIM__ )
649+ BOOT_LOG_ERR ("Image in the %s slot is not valid!" ,
650+ (slot == BOOT_SLOT_PRIMARY ) ? "primary" : "secondary" );
651+ #endif
647652 if ((slot != BOOT_SLOT_PRIMARY ) || ARE_SLOTS_EQUIVALENT ()) {
648653 boot_scramble_slot (fap , slot );
649654 /* Image is invalid, erase it to prevent further unnecessary
650655 * attempts to validate and boot it.
651656 */
652657 }
653- #if !defined(__BOOTSIM__ )
654- BOOT_LOG_ERR ("Image in the %s slot is not valid!" ,
655- (slot == BOOT_SLOT_PRIMARY ) ? "primary" : "secondary" );
656- #endif
657658 fih_rc = FIH_NO_BOOTABLE_IMAGE ;
658659 goto out ;
659660 }
@@ -1006,9 +1007,13 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
10061007
10071008#ifdef MCUBOOT_ENC_IMAGES
10081009 if (IS_ENCRYPTED (boot_img_hdr (state , BOOT_SLOT_SECONDARY ))) {
1010+ #ifdef MCUBOOT_EMBEDDED_ENC_KEY
1011+ rc = boot_take_enc_key (bs -> enckey [BOOT_SLOT_SECONDARY ], BOOT_CURR_IMG (state ), BOOT_SLOT_SECONDARY );
1012+ #else
10091013 rc = boot_enc_load (state , BOOT_SLOT_SECONDARY ,
10101014 boot_img_hdr (state , BOOT_SLOT_SECONDARY ),
10111015 fap_secondary_slot , bs );
1016+ #endif /* MCUBOOT_EMBEDDED_ENC_KEY */
10121017
10131018 if (rc < 0 ) {
10141019 return BOOT_EBADIMAGE ;
@@ -1130,7 +1135,11 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
11301135#ifdef MCUBOOT_ENC_IMAGES
11311136 if (IS_ENCRYPTED (hdr )) {
11321137 fap = BOOT_IMG_AREA (state , BOOT_SLOT_PRIMARY );
1138+ #ifdef MCUBOOT_EMBEDDED_ENC_KEY
1139+ rc = boot_take_enc_key (bs -> enckey [BOOT_SLOT_PRIMARY ], BOOT_CURR_IMG (state ), BOOT_SLOT_PRIMARY );
1140+ #else
11331141 rc = boot_enc_load (state , BOOT_SLOT_PRIMARY , hdr , fap , bs );
1142+ #endif /* MCUBOOT_EMBEDDED_ENC_KEY */
11341143 assert (rc >= 0 );
11351144
11361145 if (rc == 0 ) {
@@ -1154,7 +1163,11 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
11541163 hdr = boot_img_hdr (state , BOOT_SLOT_SECONDARY );
11551164 if (IS_ENCRYPTED (hdr )) {
11561165 fap = BOOT_IMG_AREA (state , BOOT_SLOT_SECONDARY );
1166+ #ifdef MCUBOOT_EMBEDDED_ENC_KEY
1167+ rc = boot_take_enc_key (bs -> enckey [BOOT_SLOT_SECONDARY ], BOOT_CURR_IMG (state ), BOOT_SLOT_SECONDARY );
1168+ #else
11571169 rc = boot_enc_load (state , BOOT_SLOT_SECONDARY , hdr , fap , bs );
1170+ #endif /* MCUBOOT_EMBEDDED_ENC_KEY */
11581171 assert (rc >= 0 );
11591172
11601173 if (rc == 0 ) {
@@ -1191,15 +1204,19 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
11911204
11921205 boot_enc_init (BOOT_CURR_ENC_SLOT (state , slot ));
11931206
1207+ #ifdef MCUBOOT_EMBEDDED_ENC_KEY
1208+ rc = boot_take_enc_key (bs -> enckey [slot ], image_index , slot );
1209+ #else
11941210 rc = boot_read_enc_key (fap , slot , bs );
1211+ #endif /* MCUBOOT_EMBEDDED_ENC_KEY */
11951212 if (rc ) {
11961213 BOOT_LOG_DBG ("boot_swap_image: Failed loading key (%d, %d)" ,
11971214 image_index , slot );
11981215 } else {
11991216 boot_enc_set_key (BOOT_CURR_ENC_SLOT (state , slot ), bs -> enckey [slot ]);
12001217 }
12011218 }
1202- #endif
1219+ #endif /* MCUBOOT_ENC_IMAGES */
12031220 flash_area_close (fap );
12041221 }
12051222
0 commit comments