Commit 4e8113b6 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Refactor trailer offset functions

Update each function to calculate the offset based on a previous
function offset, so that if one has to be changed not all functions have
to be updated.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent df0cc505
Loading
Loading
Loading
Loading
+18 −19
Changes for boot/bootutil/src/bootutil_misc.c: 18 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -164,12 +164,6 @@ boot_trailer_sz(uint8_t min_write_sz)
           BOOT_MAGIC_SZ;
}

static uint32_t
boot_magic_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ;
}

int
boot_status_entries(int image_index, const struct flash_area *fap)
{
@@ -196,36 +190,41 @@ boot_status_off(const struct flash_area *fap)
    return fap->fa_size - off_from_end;
}

uint32_t
boot_swap_info_off(const struct flash_area *fap)
static inline uint32_t
boot_magic_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 3;
    return fap->fa_size - BOOT_MAGIC_SZ;
}

static inline uint32_t
boot_image_ok_off(const struct flash_area *fap)
{
    return boot_magic_off(fap) - BOOT_MAX_ALIGN;
}

static uint32_t
static inline uint32_t
boot_copy_done_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 2;
    return boot_image_ok_off(fap) - BOOT_MAX_ALIGN;
}

static uint32_t
boot_image_ok_off(const struct flash_area *fap)
uint32_t
boot_swap_info_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN;
    return boot_copy_done_off(fap) - BOOT_MAX_ALIGN;
}

static uint32_t
static inline uint32_t
boot_swap_size_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 4;
    return boot_swap_info_off(fap) - BOOT_MAX_ALIGN;
}

#ifdef MCUBOOT_ENC_IMAGES
static uint32_t
static inline uint32_t
boot_enc_key_off(const struct flash_area *fap, uint8_t slot)
{
    return fap->fa_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 4 -
                          ((slot + 1) * BOOT_ENC_KEY_SIZE);
    return boot_swap_size_off(fap) - ((slot + 1) * BOOT_ENC_KEY_SIZE);
}
#endif