@@ -1216,13 +1216,14 @@ boot_copy_region(struct boot_loader_state *state,
1216
1216
uint32_t off ;
1217
1217
uint32_t tlv_off ;
1218
1218
size_t blk_off ;
1219
- int enc_area_id ;
1220
1219
struct image_header * hdr ;
1221
1220
uint16_t idx ;
1222
1221
uint32_t blk_sz ;
1223
1222
uint8_t image_index ;
1224
1223
bool encrypted_src ;
1225
1224
bool encrypted_dst ;
1225
+ /* Assuming the secondary slot is source and needs decryption */
1226
+ int source_slot = 1 ;
1226
1227
#endif
1227
1228
1228
1229
TARGET_STATIC uint8_t buf [BUF_SZ ] __attribute__((aligned (4 )));
@@ -1255,11 +1256,11 @@ boot_copy_region(struct boot_loader_state *state,
1255
1256
if (encrypted_dst ) {
1256
1257
/* Need encryption, metadata from the primary slot */
1257
1258
hdr = boot_img_hdr (state , BOOT_PRIMARY_SLOT );
1258
- enc_area_id = FLASH_AREA_IMAGE_PRIMARY ( image_index ) ;
1259
+ source_slot = 0 ;
1259
1260
} else {
1260
1261
/* Need decryption, metadata from the secondary slot */
1261
1262
hdr = boot_img_hdr (state , BOOT_SECONDARY_SLOT );
1262
- enc_area_id = FLASH_AREA_IMAGE_SECONDARY ( image_index ) ;
1263
+ source_slot = 1 ;
1263
1264
}
1264
1265
1265
1266
if (IS_ENCRYPTED (hdr )) {
@@ -1291,7 +1292,7 @@ boot_copy_region(struct boot_loader_state *state,
1291
1292
blk_sz = tlv_off - abs_off ;
1292
1293
}
1293
1294
}
1294
- boot_encrypt (BOOT_CURR_ENC (state ), image_index , enc_area_id ,
1295
+ boot_encrypt (BOOT_CURR_ENC (state ), source_slot ,
1295
1296
(abs_off + idx ) - hdr -> ih_hdr_size , blk_sz ,
1296
1297
blk_off , & buf [idx ]);
1297
1298
}
@@ -2726,13 +2727,11 @@ boot_decrypt_and_copy_image_to_sram(struct boot_loader_state *state,
2726
2727
uint32_t chunk_sz ;
2727
2728
uint32_t max_sz = 1024 ;
2728
2729
uint16_t idx ;
2729
- uint8_t image_index ;
2730
2730
uint8_t * cur_dst ;
2731
2731
int area_id ;
2732
2732
int rc ;
2733
2733
uint8_t * ram_dst = (void * )(IMAGE_RAM_BASE + img_dst );
2734
2734
2735
- image_index = BOOT_CURR_IMG (state );
2736
2735
area_id = flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), slot );
2737
2736
rc = flash_area_open (area_id , & fap_src );
2738
2737
if (rc != 0 ){
@@ -2774,7 +2773,7 @@ boot_decrypt_and_copy_image_to_sram(struct boot_loader_state *state,
2774
2773
* Part of the chunk is encrypted payload */
2775
2774
blk_sz = tlv_off - (bytes_copied );
2776
2775
}
2777
- boot_encrypt (BOOT_CURR_ENC (state ), image_index , area_id ,
2776
+ boot_encrypt (BOOT_CURR_ENC (state ), slot ,
2778
2777
(bytes_copied + idx ) - hdr -> ih_hdr_size , blk_sz ,
2779
2778
blk_off , cur_dst );
2780
2779
0 commit comments