Commit 35d31b40 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Add flash_area_read_is_empty to sim

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 08b8058b
Loading
Loading
Loading
Loading
+8
Changes for sim/mcuboot-sys/csupport/flash_map.h: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -130,6 +130,14 @@ uint8_t flash_area_align(const struct flash_area *);
 */
uint8_t flash_area_erased_val(const struct flash_area *);

/*
 * Reads len bytes from off, and checks if the read data is erased.
 *
 * Returns 1 if erased, 0 if non-erased, and -1 on failure.
 */
int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
        void *dst, uint32_t len);

/*
 * Given flash area ID, return info about sectors within the area.
 */
+23
Changes for sim/mcuboot-sys/csupport/run.c: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -200,6 +200,29 @@ int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
                           len);
}

int flash_area_read_is_empty(const struct flash_area *area, uint32_t off,
        void *dst, uint32_t len)
{
    uint8_t i;
    uint8_t *u8dst;
    int rc;

    BOOT_LOG_DBG("%s: area=%d, off=%x, len=%x", __func__, area->fa_id, off, len);

    rc = hal_flash_read(area->fa_device_id, area->fa_off + off, dst, len);
    if (rc) {
        return -1;
    }

    for (i = 0, u8dst = (uint8_t *)dst; i < len; i++) {
        if (u8dst[i] != sim_flash_erased_val) {
            return 0;
        }
    }

    return 1;
}

int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
{
    uint32_t i;