Skip to content

Commit 80a39c6

Browse files
committed
bootutil: Replace literal slot indexes with identifiers
Use BOOT_SLOT_PRIMARY/BOOT_SLOT_SECONDARY instead of 0/1. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 48b0f6d commit 80a39c6

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

boot/boot_serial/src/boot_serial_encryption.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ boot_image_validate_encrypted(struct boot_loader_state *state,
3131
int rc;
3232

3333
if (MUST_DECRYPT(fa_p, BOOT_CURR_IMG(state), hdr)) {
34-
rc = boot_enc_load(state, 1, hdr, fa_p, bs);
34+
rc = boot_enc_load(state, BOOT_SLOT_SECONDARY, hdr, fa_p, bs);
3535
if (rc < 0) {
3636
FIH_RET(fih_rc);
3737
}
38-
rc = boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs);
38+
rc = boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_SECONDARY, bs);
3939
if (rc < 0) {
4040
FIH_RET(fih_rc);
4141
}
@@ -235,11 +235,11 @@ decrypt_image_inplace(const struct flash_area *fa_p,
235235
#endif
236236
memset(&boot_data, 0, sizeof(struct boot_loader_state));
237237
/* Load the encryption keys into cache */
238-
rc = boot_enc_load(state, 0, hdr, fa_p, bs);
238+
rc = boot_enc_load(state, BOOT_SLOT_PRIMARY, hdr, fa_p, bs);
239239
if (rc < 0) {
240240
FIH_RET(fih_rc);
241241
}
242-
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), 0, bs)) {
242+
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_PRIMARY, bs)) {
243243
FIH_RET(fih_rc);
244244
}
245245
}

boot/bootutil/src/loader.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,11 @@ boot_image_check(struct boot_loader_state *state, struct image_header *hdr,
692692
*/
693693
#if defined(MCUBOOT_ENC_IMAGES) && !defined(MCUBOOT_RAM_LOAD)
694694
if (MUST_DECRYPT(fap, BOOT_CURR_IMG(state), hdr)) {
695-
rc = boot_enc_load(state, 1, hdr, fap, bs);
695+
rc = boot_enc_load(state, BOOT_SLOT_SECONDARY, hdr, fap, bs);
696696
if (rc < 0) {
697697
FIH_RET(fih_rc);
698698
}
699-
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs)) {
699+
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_SECONDARY, bs)) {
700700
FIH_RET(fih_rc);
701701
}
702702
}
@@ -1547,7 +1547,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
15471547
if (rc < 0) {
15481548
return BOOT_EBADIMAGE;
15491549
}
1550-
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs)) {
1550+
if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_SECONDARY, bs)) {
15511551
return BOOT_EBADIMAGE;
15521552
}
15531553
}
@@ -1665,17 +1665,17 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
16651665
#ifdef MCUBOOT_ENC_IMAGES
16661666
if (IS_ENCRYPTED(hdr)) {
16671667
fap = BOOT_IMG_AREA(state, BOOT_SLOT_PRIMARY);
1668-
rc = boot_enc_load(state, 0, hdr, fap, bs);
1668+
rc = boot_enc_load(state, BOOT_SLOT_PRIMARY, hdr, fap, bs);
16691669
assert(rc >= 0);
16701670

16711671
if (rc == 0) {
1672-
rc = boot_enc_set_key(BOOT_CURR_ENC(state), 0, bs);
1672+
rc = boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_PRIMARY, bs);
16731673
assert(rc == 0);
16741674
} else {
16751675
rc = 0;
16761676
}
16771677
} else {
1678-
memset(bs->enckey[0], 0xff, BOOT_ENC_KEY_ALIGN_SIZE);
1678+
memset(bs->enckey[BOOT_SLOT_PRIMARY], 0xff, BOOT_ENC_KEY_ALIGN_SIZE);
16791679
}
16801680
#endif
16811681

@@ -1689,17 +1689,17 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
16891689
hdr = boot_img_hdr(state, BOOT_SLOT_SECONDARY);
16901690
if (IS_ENCRYPTED(hdr)) {
16911691
fap = BOOT_IMG_AREA(state, BOOT_SLOT_SECONDARY);
1692-
rc = boot_enc_load(state, 1, hdr, fap, bs);
1692+
rc = boot_enc_load(state, BOOT_SLOT_SECONDARY, hdr, fap, bs);
16931693
assert(rc >= 0);
16941694

16951695
if (rc == 0) {
1696-
rc = boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs);
1696+
rc = boot_enc_set_key(BOOT_CURR_ENC(state), BOOT_SLOT_SECONDARY, bs);
16971697
assert(rc == 0);
16981698
} else {
16991699
rc = 0;
17001700
}
17011701
} else {
1702-
memset(bs->enckey[1], 0xff, BOOT_ENC_KEY_ALIGN_SIZE);
1702+
memset(bs->enckey[BOOT_SLOT_SECONDARY], 0xff, BOOT_ENC_KEY_ALIGN_SIZE);
17031703
}
17041704
#endif
17051705

0 commit comments

Comments
 (0)