Commit a18f635a authored by Thomas Altenbach's avatar Thomas Altenbach Committed by Jamie
Browse files

boot: Remove now superfluous start_off parameters



When swap-offset is used, multiple routines called directly or
indirectly by bs_list or bs_set needed to know the start offset of the
image in the secondary slot. When a valid bootloader state is available,
this value is simply retrieved from the state. Since bs_list and bs_set
had no valid state, a start_off parameter was added to all those
routines to obtain the start offset without using the bootloader state.

This is no longer needed, and since the start_off parameters were used
only by bs_list and bs_set, they can be removed, which make the code
simpler and easier to read in numerous places.

Signed-off-by: default avatarThomas Altenbach <thomas.altenbach@legrand.com>
parent c62c19db
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@ fih_ret
boot_image_validate_encrypted(const struct flash_area *fa_p,
                              struct image_header *hdr, uint8_t *buf,
                              uint16_t buf_size
#ifdef MCUBOOT_SWAP_USING_OFFSET
                              , uint32_t start_off
#endif
);

/**
+2 −21
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
#ifdef MCUBOOT_SWAP_USING_OFFSET
            if (slot == BOOT_SECONDARY_SLOT && swap_status != BOOT_SWAP_TYPE_REVERT) {
                start_off = boot_img_sector_size(state, slot, 0);
                state->secondary_offset[image_index] = start_off;
            }
#endif

@@ -351,13 +352,8 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
#if defined(MCUBOOT_ENC_IMAGES)
#if !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
                    if (IS_ENCRYPTED(&hdr) && MUST_DECRYPT(fap, image_index, &hdr)) {
#ifdef MCUBOOT_SWAP_USING_OFFSET
                        FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
                                 &hdr, tmpbuf, sizeof(tmpbuf), start_off);
#else
                        FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
                                 &hdr, tmpbuf, sizeof(tmpbuf));
#endif
                    } else {
#endif
                        if (IS_ENCRYPTED(&hdr)) {
@@ -369,14 +365,8 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
                            hdr.ih_flags &= ~ENCRYPTIONFLAGS;
                        }
#endif

#ifdef MCUBOOT_SWAP_USING_OFFSET
                        FIH_CALL(bootutil_img_validate, fih_rc, state, &hdr,
                                 fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL, start_off);
#else
                        FIH_CALL(bootutil_img_validate, fih_rc, state, &hdr,
                                 fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL);
#endif
#if defined(MCUBOOT_ENC_IMAGES) && !defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
                    }
#endif
@@ -557,6 +547,7 @@ bs_set(struct boot_loader_state *state, char *buf, int len)
#ifdef MCUBOOT_SWAP_USING_OFFSET
                if (slot == BOOT_SECONDARY_SLOT && swap_status != BOOT_SWAP_TYPE_REVERT) {
                    start_off = boot_img_sector_size(state, slot, 0);
                    state->secondary_offset[image_index] = start_off;
                }
#endif

@@ -582,22 +573,12 @@ bs_set(struct boot_loader_state *state, char *buf, int len)
                    {
#ifdef MCUBOOT_ENC_IMAGES
                        if (IS_ENCRYPTED(&hdr)) {
#ifdef MCUBOOT_SWAP_USING_OFFSET
                            FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
                                     &hdr, tmpbuf, sizeof(tmpbuf), start_off);
#else
                            FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
                                     &hdr, tmpbuf, sizeof(tmpbuf));
#endif
                        } else {
#endif
#ifdef MCUBOOT_SWAP_USING_OFFSET
                            FIH_CALL(bootutil_img_validate, fih_rc, state, &hdr,
                                     fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL, start_off);
#else
                            FIH_CALL(bootutil_img_validate, fih_rc, state, &hdr,
                                     fap, tmpbuf, sizeof(tmpbuf), NULL, 0, NULL);
#endif
#ifdef MCUBOOT_ENC_IMAGES
                        }
#endif
+1 −18
Original line number Diff line number Diff line
@@ -21,11 +21,7 @@ BOOT_LOG_MODULE_DECLARE(serial_encryption);
fih_ret
boot_image_validate_encrypted(const struct flash_area *fa_p,
                              struct image_header *hdr, uint8_t *buf,
                              uint16_t buf_size
#ifdef MCUBOOT_SWAP_USING_OFFSET
                              , uint32_t start_off
#endif
                             )
                              uint16_t buf_size)
{
    FIH_DECLARE(fih_rc, FIH_FAILURE);

@@ -37,11 +33,7 @@ boot_image_validate_encrypted(const struct flash_area *fa_p,

    memset(&boot_data, 0, sizeof(struct boot_loader_state));
    if(IS_ENCRYPTED(hdr)) {
#ifdef MCUBOOT_SWAP_USING_OFFSET
        rc = boot_enc_load(state, 1, hdr, fa_p, bs, start_off);
#else
        rc = boot_enc_load(state, 1, hdr, fa_p, bs);
#endif
        if (rc < 0) {
            FIH_RET(fih_rc);
        }
@@ -51,13 +43,8 @@ boot_image_validate_encrypted(const struct flash_area *fa_p,
        }
    }

#ifdef MCUBOOT_SWAP_USING_OFFSET
    FIH_CALL(bootutil_img_validate, fih_rc, state,
             hdr, fa_p, buf, buf_size, NULL, 0, NULL, start_off);
#else
    FIH_CALL(bootutil_img_validate, fih_rc, state,
             hdr, fa_p, buf, buf_size, NULL, 0, NULL);
#endif

    FIH_RET(fih_rc);
}
@@ -248,11 +235,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 */
#ifdef MCUBOOT_SWAP_USING_OFFSET
        rc = boot_enc_load(state, 0, hdr, fa_p, bs, 0);
#else
        rc = boot_enc_load(state, 0, hdr, fa_p, bs);
#endif
        if (rc < 0) {
            FIH_RET(fih_rc);
        }
+1 −5
Original line number Diff line number Diff line
@@ -67,11 +67,7 @@ int boot_enc_set_key(struct enc_key_data *enc_state, uint8_t slot,
                     const struct boot_status *bs);
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
#if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
                  , uint32_t start_off
#endif
                 );
                  struct boot_status *bs);
bool boot_enc_valid(struct enc_key_data *enc_state, int slot);
void boot_enc_encrypt(struct enc_key_data *enc_state, int slot,
        uint32_t off, uint32_t sz, uint32_t blk_off, uint8_t *buf);
+0 −3
Original line number Diff line number Diff line
@@ -208,9 +208,6 @@ fih_ret bootutil_img_validate(struct boot_loader_state *state,
                              const struct flash_area *fap,
                              uint8_t *tmp_buf, uint32_t tmp_buf_sz,
                              uint8_t *seed, int seed_len, uint8_t *out_hash
#if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
                              , uint32_t start_off
#endif
);

struct image_tlv_iter {
Loading