Commit 069aea48 authored by Dominik Ermel's avatar Dominik Ermel Committed by David Brown
Browse files

zephry: Add flash_area_get_sector

Commits adds implementation of flash_area_get_sector that
is supposed to replace flash_area_sector_from_off.
The flash_area_get_sector gets additional parameter of flash_area
type, while flash_area_sector_from_off uses hardcoded flash_area.

Signed-off-by: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent 9551b6ef
Loading
Loading
Loading
Loading
+21 −0
Changes for boot/zephyr/flash_map_extended.c: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -135,3 +135,24 @@ __weak uint8_t flash_area_erased_val(const struct flash_area *fap)
    (void)fap;
    return ERASED_VAL;
}

int flash_area_get_sector(const struct flash_area *fap, off_t off,
                          struct flash_sector *fsp)
{
    struct flash_pages_info fpi;
    int rc;

    if (off >= fap->fa_size) {
        return -ERANGE;
    }

    rc = flash_get_page_info_by_offs(fap->fa_dev, fap->fa_off + off,
            &fpi);

    if (rc == 0) {
        fsp->fs_off = fpi.start_offset - fap->fa_off;
        fsp->fs_size = fpi.size;
    }

    return rc;
}
+11 −0
Changes for boot/zephyr/include/flash_map_backend/flash_map_backend.h: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -95,6 +95,17 @@ static inline uint32_t flash_sector_get_size(const struct flash_sector *fs)
	return fs->fs_size;
}

/* Retrieve the flash sector withing given flash area, at a given offset.
 *
 * @param fa        flash area where the sector is taken from.
 * @param off       offset within flash area.
 * @param sector    structure of sector information.
 * Returns 0 on success, -ERANGE if @p off is beyond flash area size,
 *         other negative errno code on failure.
 */
int flash_area_get_sector(const struct flash_area *fa, off_t off,
                          struct flash_sector *fs);

#ifdef __cplusplus
}
#endif