Skip to content

Commit ee9efe0

Browse files
committed
bootutil: Replace boot_write_enc_key with boot_write_enc_keys
All keys are written at once anyway. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 80a39c6 commit ee9efe0

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

boot/bootutil/src/bootutil_misc.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,25 @@ boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size)
407407

408408
#ifdef MCUBOOT_ENC_IMAGES
409409
int
410-
boot_write_enc_key(const struct flash_area *fap, uint8_t slot,
411-
const struct boot_status *bs)
410+
boot_write_enc_keys(const struct flash_area *fap, const struct boot_status *bs)
412411
{
413-
uint32_t off;
414-
int rc;
412+
int slot;
415413

416-
off = boot_enc_key_off(fap, slot);
417-
BOOT_LOG_DBG("writing enc_key; fa_id=%d off=0x%lx (0x%lx)",
418-
flash_area_get_id(fap), (unsigned long)off,
419-
(unsigned long)flash_area_get_off(fap) + off);
414+
for (slot = 0; slot < BOOT_NUM_SLOTS; ++slot) {
415+
uint32_t off = boot_enc_key_off(fap, slot);
416+
int rc;
417+
418+
BOOT_LOG_DBG("writing enc_key; fa_id=%d off=0x%lx (0x%lx)",
419+
flash_area_get_id(fap), (unsigned long)off,
420+
(unsigned long)flash_area_get_off(fap) + off);
420421
#if MCUBOOT_SWAP_SAVE_ENCTLV
421-
rc = flash_area_write(fap, off, bs->enctlv[slot], BOOT_ENC_TLV_ALIGN_SIZE);
422+
rc = flash_area_write(fap, off, bs->enctlv[slot], BOOT_ENC_TLV_ALIGN_SIZE);
422423
#else
423-
rc = flash_area_write(fap, off, bs->enckey[slot], BOOT_ENC_KEY_ALIGN_SIZE);
424+
rc = flash_area_write(fap, off, bs->enckey[slot], BOOT_ENC_KEY_ALIGN_SIZE);
424425
#endif
425-
if (rc != 0) {
426-
return BOOT_EFLASH;
426+
if (rc != 0) {
427+
return BOOT_EFLASH;
428+
}
427429
}
428430

429431
return 0;

boot/bootutil/src/bootutil_priv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ int boot_scramble_slot(const struct flash_area *fap, int slot);
371371
bool boot_status_is_reset(const struct boot_status *bs);
372372

373373
#ifdef MCUBOOT_ENC_IMAGES
374-
int boot_write_enc_key(const struct flash_area *fap, uint8_t slot,
375-
const struct boot_status *bs);
374+
int boot_write_enc_keys(const struct flash_area *fap, const struct boot_status *bs);
376375
int boot_read_enc_key(const struct flash_area *fap, uint8_t slot,
377376
struct boot_status *bs);
378377
#endif

boot/bootutil/src/swap_misc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ swap_status_init(const struct boot_loader_state *state,
137137
assert(rc == 0);
138138

139139
#ifdef MCUBOOT_ENC_IMAGES
140-
rc = boot_write_enc_key(fap, 0, bs);
141-
assert(rc == 0);
142-
143-
rc = boot_write_enc_key(fap, 1, bs);
144-
assert(rc == 0);
140+
rc = boot_write_enc_keys(fap, bs);
145141
#endif
146142

147143
rc = boot_write_magic(fap);

boot/bootutil/src/swap_scratch.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,7 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
884884
assert(rc == 0);
885885

886886
#ifdef MCUBOOT_ENC_IMAGES
887-
rc = boot_write_enc_key(fap_primary_slot, 0, bs);
888-
assert(rc == 0);
889-
890-
rc = boot_write_enc_key(fap_primary_slot, 1, bs);
891-
assert(rc == 0);
887+
rc = boot_write_enc_keys(fap_primary_slot, bs);
892888
#endif
893889
rc = boot_write_magic(fap_primary_slot);
894890
assert(rc == 0);

0 commit comments

Comments
 (0)