Commit 2fe9cd4b authored by Jamie McCrae's avatar Jamie McCrae Committed by Jamie
Browse files

boot: bootutil: Refactor some functions to have state



Refactors some functions so that the state variable is present in it

Signed-off-by: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent 9668469f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ bs_list(char *buf, int len)
                        }
#endif

                        FIH_CALL(bootutil_img_validate, fih_rc, NULL, 0, &hdr,
                        FIH_CALL(bootutil_img_validate, fih_rc, NULL, &hdr,
                                 fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL);
#if defined(MCUBOOT_ENC_IMAGES) && !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
                    }
@@ -522,7 +522,7 @@ bs_set(char *buf, int len)
                                 &hdr, tmpbuf, sizeof(tmpbuf));
                    } else {
#endif
                        FIH_CALL(bootutil_img_validate, fih_rc, NULL, 0, &hdr,
                        FIH_CALL(bootutil_img_validate, fih_rc, NULL, &hdr,
                                 fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL);
#ifdef MCUBOOT_ENC_IMAGES
                    }
+4 −6
Original line number Diff line number Diff line
@@ -30,22 +30,20 @@ boot_image_validate_encrypted(const struct flash_area *fa_p,
    struct boot_loader_state *state = &boot_data;
    struct boot_status _bs;
    struct boot_status *bs = &_bs;
    uint8_t image_index;
    int rc;

    memset(&boot_data, 0, sizeof(struct boot_loader_state));
    image_index = BOOT_CURR_IMG(state);
    if(IS_ENCRYPTED(hdr)) {
        rc = boot_enc_load(BOOT_CURR_ENC(state), 1, hdr, fa_p, bs);
        rc = boot_enc_load(state, 1, hdr, fa_p, bs);
        if (rc < 0) {
            FIH_RET(fih_rc);
        }
        rc = boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs);
        rc = boot_enc_set_key(state, 1, bs);
        if (rc < 0) {
            FIH_RET(fih_rc);
        }
    }
    FIH_CALL(bootutil_img_validate, fih_rc, BOOT_CURR_ENC(state), image_index,
    FIH_CALL(bootutil_img_validate, fih_rc, state,
             hdr, fa_p, buf, buf_size, NULL, 0, NULL);

    FIH_RET(fih_rc);
@@ -238,7 +236,7 @@ decrypt_image_inplace(const struct flash_area *fa_p,
#endif
        memset(&boot_data, 0, sizeof(struct boot_loader_state));
        /* Load the encryption keys into cache */
        rc = boot_enc_load(BOOT_CURR_ENC(state), 0, hdr, fa_p, bs);
        rc = boot_enc_load(state, 0, hdr, fa_p, bs);
        if (rc < 0) {
            FIH_RET(fih_rc);
        }
+2 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ struct enc_key_data {
int boot_enc_retrieve_private_key(struct bootutil_key **private_key);

struct boot_status;
struct boot_loader_state;

/* Decrypt random, symmetric encryption key */
int boot_decrypt_key(const uint8_t *buf, uint8_t *enckey);
@@ -66,7 +67,7 @@ int boot_enc_init(struct enc_key_data *enc_state, uint8_t slot);
int boot_enc_drop(struct enc_key_data *enc_state, uint8_t slot);
int boot_enc_set_key(struct enc_key_data *enc_state, uint8_t slot,
        const struct boot_status *bs);
int boot_enc_load(struct enc_key_data *enc_state, int slot,
int boot_enc_load(struct boot_loader_state *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 slot);
+4 −3
Original line number Diff line number Diff line
@@ -196,7 +196,8 @@ _Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
               "struct image_header not required size");

struct enc_key_data;
fih_ret bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
struct boot_loader_state;
fih_ret bootutil_img_validate(struct boot_loader_state *state,
                              struct image_header *hdr,
                              const struct flash_area *fap,
                              uint8_t *tmp_buf, uint32_t tmp_buf_sz,
@@ -220,9 +221,9 @@ int bootutil_tlv_iter_next(struct image_tlv_iter *it, uint32_t *off,
                           uint16_t *len, uint16_t *type);
int bootutil_tlv_iter_is_prot(struct image_tlv_iter *it, uint32_t off);

int32_t bootutil_get_img_security_cnt(struct image_header *hdr,
int32_t bootutil_get_img_security_cnt(struct boot_loader_state *state, int slot,
                                      const struct flash_area *fap,
                                      uint32_t *security_cnt);
                                      uint32_t *img_security_cnt);

#ifdef __cplusplus
}
+2 −1
Original line number Diff line number Diff line
@@ -632,10 +632,11 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
 * Load encryption key.
 */
int
boot_enc_load(struct enc_key_data *enc_state, int slot,
boot_enc_load(struct boot_loader_state *state, int slot,
        const struct image_header *hdr, const struct flash_area *fap,
        struct boot_status *bs)
{
    struct enc_key_data *enc_state = BOOT_CURR_ENC(state);
    uint32_t off;
    uint16_t len;
    struct image_tlv_iter it;
Loading