Commit 260ae090 authored by Dominik Ermel's avatar Dominik Ermel Committed by David Brown
Browse files

boot: Modify common code access for flash_area objects

The commit changes direct access to flash_area, and flash_structure,
objects via filed names to access via getter functions
Purpose of this change is to make common code agnostic to internal
implementation of flash_area, and flash_sector, objects.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent c304a7f8
Loading
Loading
Loading
Loading
+12 −9
Changes for boot/boot_serial/src/boot_serial.c: 12 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -282,11 +282,11 @@ bs_upload(char *buf, int len)

    if (off == 0) {
        curr_off = 0;
        if (data_len > fap->fa_size) {
        if (data_len > flash_area_get_size(fap)) {
            goto out_invalid_data;
        }
#ifndef CONFIG_BOOT_ERASE_PROGRESSIVELY
        rc = flash_area_erase(fap, 0, fap->fa_size);
        rc = flash_area_erase(fap, 0, flash_area_get_size(fap));
        if (rc) {
            goto out_invalid_data;
        }
@@ -316,10 +316,11 @@ bs_upload(char *buf, int len)
        BOOT_LOG_ERR("Unable to determine flash sector size");
        goto out;
    }
    if (off_last != sector.fs_off) {
        off_last = sector.fs_off;
        BOOT_LOG_INF("Erasing sector at offset 0x%x", sector.fs_off);
        rc = flash_area_erase(fap, sector.fs_off, sector.fs_size);
    if (off_last != flash_sector_get_off(&sector)) {
        off_last = flash_sector_get_off(&sector);
        BOOT_LOG_INF("Erasing sector at offset 0x%x", flash_sector_get_off(&sector));
        rc = flash_area_erase(fap, flash_sector_get_off(&sector),
                              flash_sector_get_size(&sector));
        if (rc) {
            BOOT_LOG_ERR("Error %d while erasing sector", rc);
            goto out;
@@ -367,9 +368,11 @@ bs_upload(char *buf, int len)
            }
            /* Assure that sector for image trailer was erased. */
            /* Check whether it was erased during previous upload. */
            if (off_last < sector.fs_off) {
                BOOT_LOG_INF("Erasing sector at offset 0x%x", sector.fs_off);
                rc = flash_area_erase(fap, sector.fs_off, sector.fs_size);
            if (off_last < flash_sector_get_off(&sector)) {
                BOOT_LOG_INF("Erasing sector at offset 0x%x",
                             flash_sector_get_off(&sector));
                rc = flash_area_erase(fap, flash_sector_get_off(&sector),
                                      flash_sector_get_size(&sector));
                if (rc) {
                    BOOT_LOG_ERR("Error %d while erasing sector", rc);
                    goto out;
+1 −1
Changes for boot/bootutil/include/bootutil/image.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ struct image_tlv {
#define IS_ENCRYPTED(hdr) (((hdr)->ih_flags && IMAGE_F_ENCRYPTED_AES128) \
                        || ((hdr)->ih_flags && IMAGE_F_ENCRYPTED_AES256))
#define MUST_DECRYPT(fap, idx, hdr) \
    ((fap)->fa_id == FLASH_AREA_IMAGE_SECONDARY(idx) && IS_ENCRYPTED(hdr))
    (flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(idx) && IS_ENCRYPTED(hdr))

_Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
               "struct image_header not required size");
+12 −12
Changes for boot/bootutil/src/bootutil_misc.c: 12 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -123,12 +123,12 @@ int
boot_status_entries(int image_index, const struct flash_area *fap)
{
#if MCUBOOT_SWAP_USING_SCRATCH
    if (fap->fa_id == FLASH_AREA_IMAGE_SCRATCH) {
    if (flash_area_get_id(fap) == FLASH_AREA_IMAGE_SCRATCH) {
        return BOOT_STATUS_STATE_COUNT;
    } else
#endif
    if (fap->fa_id == FLASH_AREA_IMAGE_PRIMARY(image_index) ||
               fap->fa_id == FLASH_AREA_IMAGE_SECONDARY(image_index)) {
    if (flash_area_get_id(fap) == FLASH_AREA_IMAGE_PRIMARY(image_index) ||
        flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(image_index)) {
        return BOOT_STATUS_STATE_COUNT * BOOT_STATUS_MAX_ENTRIES;
    }
    return -1;
@@ -144,14 +144,14 @@ boot_status_off(const struct flash_area *fap)

    off_from_end = boot_trailer_sz(elem_sz);

    assert(off_from_end <= fap->fa_size);
    return fap->fa_size - off_from_end;
    assert(off_from_end <= flash_area_get_size(fap));
    return flash_area_get_size(fap) - off_from_end;
}

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

static inline uint32_t
@@ -301,8 +301,8 @@ boot_write_copy_done(const struct flash_area *fap)

    off = boot_copy_done_off(fap);
    BOOT_LOG_DBG("writing copy_done; fa_id=%d off=0x%lx (0x%lx)",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)(fap->fa_off + off));
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off));
    return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
}

@@ -313,8 +313,8 @@ boot_write_swap_size(const struct flash_area *fap, uint32_t swap_size)

    off = boot_swap_size_off(fap);
    BOOT_LOG_DBG("writing swap_size; fa_id=%d off=0x%lx (0x%lx)",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)fap->fa_off + off);
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)flash_area_get_off(fap) + off);
    return boot_write_trailer(fap, off, (const uint8_t *) &swap_size, 4);
}

@@ -328,8 +328,8 @@ boot_write_enc_key(const struct flash_area *fap, uint8_t slot,

    off = boot_enc_key_off(fap, slot);
    BOOT_LOG_DBG("writing enc_key; fa_id=%d off=0x%lx (0x%lx)",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)fap->fa_off + off);
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)flash_area_get_off(fap) + off);
#if MCUBOOT_SWAP_SAVE_ENCTLV
    rc = flash_area_write(fap, off, bs->enctlv[slot], BOOT_ENC_TLV_ALIGN_SIZE);
#else
+7 −7
Changes for boot/bootutil/src/bootutil_priv.h: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -359,7 +359,7 @@ boot_img_num_sectors(const struct boot_loader_state *state, size_t slot)
static inline uint32_t
boot_img_slot_off(struct boot_loader_state *state, size_t slot)
{
    return BOOT_IMG(state, slot).area->fa_off;
    return flash_area_get_off(BOOT_IMG(state, slot).area);
}

#ifndef MCUBOOT_USE_FLASH_AREA_GET_SECTORS
@@ -368,7 +368,7 @@ static inline size_t
boot_img_sector_size(const struct boot_loader_state *state,
                     size_t slot, size_t sector)
{
    return BOOT_IMG(state, slot).sectors[sector].fa_size;
    return flash_area_get_size(&BOOT_IMG(state, slot).sectors[sector]);
}

/*
@@ -379,8 +379,8 @@ static inline uint32_t
boot_img_sector_off(const struct boot_loader_state *state, size_t slot,
                    size_t sector)
{
    return BOOT_IMG(state, slot).sectors[sector].fa_off -
           BOOT_IMG(state, slot).sectors[0].fa_off;
    return flash_area_get_off(&BOOT_IMG(state, slot).sectors[sector]) -
           flash_area_get_off(&BOOT_IMG(state, slot).sectors[0]);
}

#else  /* defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */
@@ -389,15 +389,15 @@ static inline size_t
boot_img_sector_size(const struct boot_loader_state *state,
                     size_t slot, size_t sector)
{
    return BOOT_IMG(state, slot).sectors[sector].fs_size;
    return flash_sector_get_size(&BOOT_IMG(state, slot).sectors[sector]);
}

static inline uint32_t
boot_img_sector_off(const struct boot_loader_state *state, size_t slot,
                    size_t sector)
{
    return BOOT_IMG(state, slot).sectors[sector].fs_off -
           BOOT_IMG(state, slot).sectors[0].fs_off;
    return flash_sector_get_off(&BOOT_IMG(state, slot).sectors[sector]) -
           flash_sector_get_off(&BOOT_IMG(state, slot).sectors[0]);
}

#endif  /* !defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */
+9 −8
Changes for boot/bootutil/src/bootutil_public.c: 9 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ boot_flag_decode(uint8_t flag)
static inline uint32_t
boot_magic_off(const struct flash_area *fap)
{
    return fap->fa_size - BOOT_MAGIC_SZ;
    return flash_area_get_size(fap) - BOOT_MAGIC_SZ;
}

static inline uint32_t
@@ -319,8 +319,8 @@ boot_write_magic(const struct flash_area *fap)
    off = boot_magic_off(fap);

    BOOT_LOG_DBG("writing magic; fa_id=%d off=0x%lx (0x%lx)",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)(fap->fa_off + off));
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off));
    rc = flash_area_write(fap, off, boot_img_magic, BOOT_MAGIC_SZ);
    if (rc != 0) {
        return BOOT_EFLASH;
@@ -376,8 +376,8 @@ boot_write_image_ok(const struct flash_area *fap)

    off = boot_image_ok_off(fap);
    BOOT_LOG_DBG("writing image_ok; fa_id=%d off=0x%lx (0x%lx)",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)(fap->fa_off + off));
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off));
    return boot_write_trailer_flag(fap, off, BOOT_FLAG_SET);
}

@@ -403,8 +403,9 @@ boot_write_swap_info(const struct flash_area *fap, uint8_t swap_type,
    off = boot_swap_info_off(fap);
    BOOT_LOG_DBG("writing swap_info; fa_id=%d off=0x%lx (0x%lx), swap_type=0x%x"
                 " image_num=0x%x",
                 fap->fa_id, (unsigned long)off,
                 (unsigned long)(fap->fa_off + off), swap_type, image_num);
                 flash_area_get_id(fap), (unsigned long)off,
                 (unsigned long)(flash_area_get_off(fap) + off),
                 swap_type, image_num);
    return boot_write_trailer(fap, off, (const uint8_t *) &swap_info, 1);
}

@@ -537,7 +538,7 @@ boot_set_pending_multi(int image_index, int permanent)
        /* The image slot is corrupt.  There is no way to recover, so erase the
         * slot to allow future upgrades.
         */
        flash_area_erase(fap, 0, fap->fa_size);
        flash_area_erase(fap, 0, flash_area_get_size(fap));
        rc = BOOT_EBADIMAGE;
        break;

Loading