Commit 4535ad98 authored by Dominik Ermel's avatar Dominik Ermel Committed by Jamie
Browse files

boot: Additional flash_area_open removals



Another set of flash_area_open removals where boot_loader_state
is available to provide flash_area object's pointer.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent c0bb1337
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -447,19 +447,12 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
    struct image_tlv_info info;
    uint32_t off;
    uint32_t protect_tlv_size;
    int area_id;
    int rc;

#if (BOOT_IMAGE_NUMBER == 1)
    (void)state;
#endif
    assert(slot == BOOT_PRIMARY_SLOT || slot == BOOT_SECONDARY_SLOT);

    area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
    rc = flash_area_open(area_id, &fap);
    if (rc != 0) {
        rc = BOOT_EFLASH;
        goto done;
    }
    fap = BOOT_IMG_AREA(state, slot);
    assert(fap != NULL);

    off = BOOT_TLV_OFF(boot_img_hdr(state, slot));

@@ -493,7 +486,6 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
    rc = 0;

done:
    flash_area_close(fap);
    return rc;
}
#endif /* !MCUBOOT_OVERWRITE_ONLY */
+6 −19
Original line number Diff line number Diff line
@@ -716,7 +716,6 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
{
    const struct flash_area *fap;
    uint32_t off;
    int area_id;
    int rc = 0;
    uint8_t buf[BOOT_MAX_ALIGN];
    uint32_t align;
@@ -731,20 +730,15 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
#if MCUBOOT_SWAP_USING_SCRATCH
    if (bs->use_scratch) {
        /* Write to scratch. */
        area_id = FLASH_AREA_IMAGE_SCRATCH;
        fap = state->scratch.area;
    } else {
#endif
        /* Write to the primary slot. */
        area_id = FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state));
        fap = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
#if MCUBOOT_SWAP_USING_SCRATCH
    }
#endif

    rc = flash_area_open(area_id, &fap);
    if (rc != 0) {
        return BOOT_EFLASH;
    }

    off = boot_status_off(fap) +
          boot_status_internal_off(bs, BOOT_WRITE_SZ(state));
    align = flash_area_align(fap);
@@ -761,8 +755,6 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
        rc = BOOT_EFLASH;
    }

    flash_area_close(fap);

    return rc;
}
#endif /* !MCUBOOT_RAM_LOAD */
@@ -1470,13 +1462,11 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
    BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
    BOOT_LOG_INF("Erasing the primary slot");

    rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
            &fap_primary_slot);
    assert (rc == 0);
    fap_primary_slot = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
    assert(fap_primary_slot != NULL);

    rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index),
            &fap_secondary_slot);
    assert (rc == 0);
    fap_secondary_slot = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
    assert(fap_secondary_slot != NULL);

    sect_count = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
    for (sect = 0, size = 0; sect < sect_count; sect++) {
@@ -1590,9 +1580,6 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
                               last_sector));
    assert(rc == 0);

    flash_area_close(fap_primary_slot);
    flash_area_close(fap_secondary_slot);

    /* TODO: Perhaps verify the primary slot's signature again? */

    return 0;
+3 −9
Original line number Diff line number Diff line
@@ -124,7 +124,6 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
    const struct flash_area *fap;
    uint32_t off;
    uint8_t swap_info;
    int area_id;
    int rc;

    bs->source = swap_status_source(state);
@@ -134,12 +133,12 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)

#if MCUBOOT_SWAP_USING_SCRATCH
    case BOOT_STATUS_SOURCE_SCRATCH:
        area_id = FLASH_AREA_IMAGE_SCRATCH;
        fap = state->scratch.area;
        break;
#endif

    case BOOT_STATUS_SOURCE_PRIMARY_SLOT:
        area_id = FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state));
        fap = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
        break;

    default:
@@ -147,10 +146,7 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
        return BOOT_EBADARGS;
    }

    rc = flash_area_open(area_id, &fap);
    if (rc != 0) {
        return BOOT_EFLASH;
    }
    assert(fap != NULL);

    rc = swap_read_status_bytes(fap, state, bs);
    if (rc == 0) {
@@ -171,8 +167,6 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
    }

done:
    flash_area_close(fap);

    return rc;
}

+4 −11
Original line number Diff line number Diff line
@@ -517,10 +517,8 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
    uint32_t trailer_sz;
    uint32_t first_trailer_idx;
    uint32_t last_idx;
    uint8_t image_index;
    const struct flash_area *fap_pri;
    const struct flash_area *fap_sec;
    int rc;

    BOOT_LOG_INF("Starting swap using move algorithm.");

@@ -553,13 +551,11 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
        }
    }

    image_index = BOOT_CURR_IMG(state);
    fap_pri = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
    assert(fap_pri != NULL);

    rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index), &fap_pri);
    assert (rc == 0);

    rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap_sec);
    assert (rc == 0);
    fap_sec = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
    assert(fap_sec != NULL);

    fixup_revert(state, bs, fap_sec);

@@ -583,9 +579,6 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
        }
        idx++;
    }

    flash_area_close(fap_pri);
    flash_area_close(fap_sec);
}

int app_max_size(struct boot_loader_state *state)
+6 −10
Original line number Diff line number Diff line
@@ -564,14 +564,14 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,

    image_index = BOOT_CURR_IMG(state);

    rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index), &fap_primary_slot);
    assert (rc == 0);
    fap_primary_slot = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
    assert(fap_primary_slot != NULL);

    rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap_secondary_slot);
    assert (rc == 0);
    fap_secondary_slot = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
    assert(fap_secondary_slot != NULL);

    rc = flash_area_open(FLASH_AREA_IMAGE_SCRATCH, &fap_scratch);
    assert (rc == 0);
    fap_scratch = state->scratch.area;
    assert(fap_scratch != NULL);

    /* Calculate offset from start of image area. */
    img_off = boot_img_sector_off(state, BOOT_PRIMARY_SLOT, idx);
@@ -782,10 +782,6 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
            assert(rc == 0);
        }
    }

    flash_area_close(fap_primary_slot);
    flash_area_close(fap_secondary_slot);
    flash_area_close(fap_scratch);
}

void