bootutil: Keep image encrypted in scratch area
Currently, when swap using scratch is used with encrypted images,
MCUboot is decrypting the images during the copy from the secondary slot
to the scratch area. This means the scratch area contains plaintext
image data and therefore that the scratch area must be placed in the
MCU's internal flash memory. This commit makes the necessary changes to
perform the decryption when copying from the scratch area to the primary
slot instead, making possible to place the scratch area in an external
flash memory since the scratch area is now encrypted.
Note that BOOT_SWAP_SAVE_ENCTLV must be enabled if the scratch area is
placed in external flash memory.
Signed-off-by: Thomas Altenbach <thomas.altenbach@legrand.com>
diff --git a/boot/bootutil/src/encrypted.c b/boot/bootutil/src/encrypted.c
index 212774e..44975cc 100644
--- a/boot/bootutil/src/encrypted.c
+++ b/boot/bootutil/src/encrypted.c
@@ -681,7 +681,7 @@
void
boot_encrypt(struct enc_key_data *enc_state, int image_index,
- const struct flash_area *fap, uint32_t off, uint32_t sz,
+ int fa_id, uint32_t off, uint32_t sz,
uint32_t blk_off, uint8_t *buf)
{
struct enc_key_data *enc;
@@ -701,7 +701,7 @@
nonce[14] = (uint8_t)(off >> 8);
nonce[15] = (uint8_t)off;
- rc = flash_area_id_to_multi_image_slot(image_index, flash_area_get_id(fap));
+ rc = flash_area_id_to_multi_image_slot(image_index, fa_id);
if (rc < 0) {
assert(0);
return;