From 25322f1070e8d993580731add27e0087baf9bfb6 Mon Sep 17 00:00:00 2001 From: Dominik Ermel Date: Fri, 12 Jul 2024 19:53:24 +0000 Subject: [PATCH] [nrf fromlist] boot: Make boot_enc_valid take slot instead of image index There is no point for boot_enc_valid to take image index and flash area and use these to figure out slot number. Upstream PR: https://github.com/mcu-tools/mcuboot/pull/2006 Signed-off-by: Dominik Ermel --- boot/bootutil/include/bootutil/enc_key.h | 3 +-- boot/bootutil/src/encrypted.c | 14 ++------------ boot/bootutil/src/image_validate.c | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/boot/bootutil/include/bootutil/enc_key.h b/boot/bootutil/include/bootutil/enc_key.h index 8db6e72c8..9ffeb8036 100644 --- a/boot/bootutil/include/bootutil/enc_key.h +++ b/boot/bootutil/include/bootutil/enc_key.h @@ -58,8 +58,7 @@ int boot_enc_set_key(struct enc_key_data *enc_state, uint8_t slot, int boot_enc_load(struct enc_key_data *enc_state, int slot, const struct image_header *hdr, const struct flash_area *fap, struct boot_status *bs); -bool boot_enc_valid(struct enc_key_data *enc_state, int image_index, - const struct flash_area *fap); +bool boot_enc_valid(struct enc_key_data *enc_state, int slot); void boot_encrypt(struct enc_key_data *enc_state, int image_index, int fa_id, uint32_t off, uint32_t sz, uint32_t blk_off, uint8_t *buf); diff --git a/boot/bootutil/src/encrypted.c b/boot/bootutil/src/encrypted.c index f3516ac74..6a0128bc0 100644 --- a/boot/bootutil/src/encrypted.c +++ b/boot/bootutil/src/encrypted.c @@ -657,19 +657,9 @@ boot_enc_load(struct enc_key_data *enc_state, int slot, } bool -boot_enc_valid(struct enc_key_data *enc_state, int image_index, - const struct flash_area *fap) +boot_enc_valid(struct enc_key_data *enc_state, int slot) { - int rc; - - rc = flash_area_id_to_multi_image_slot(image_index, flash_area_get_id(fap)); - if (rc < 0) { - /* can't get proper slot number - skip encryption, */ - /* postpone the error for a upper layer */ - return false; - } - - return enc_state[rc].valid; + return enc_state[slot].valid; } void diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c index b4e8b7983..785120831 100644 --- a/boot/bootutil/src/image_validate.c +++ b/boot/bootutil/src/image_validate.c @@ -96,7 +96,7 @@ bootutil_img_hash(struct enc_key_data *enc_state, int image_index, #ifdef MCUBOOT_ENC_IMAGES /* Encrypted images only exist in the secondary slot */ if (MUST_DECRYPT(fap, image_index, hdr) && - !boot_enc_valid(enc_state, image_index, fap)) { + !boot_enc_valid(enc_state, 1)) { return -1; } #endif