sim: added flash_area_sector_from_off() API implementation
Added implementation of the above API function. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
cc547a76da
commit
453b0dd790
|
@ -448,6 +448,39 @@ int flash_area_id_from_image_slot(int slot) {
|
||||||
return flash_area_id_from_multi_image_slot(0, slot);
|
return flash_area_id_from_multi_image_slot(0, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector)
|
||||||
|
{
|
||||||
|
uint32_t i, sec_off, sec_size;
|
||||||
|
struct area *slot;
|
||||||
|
struct area_desc *flash_areas;
|
||||||
|
|
||||||
|
flash_areas = sim_get_flash_areas();
|
||||||
|
for (i = 0; i < flash_areas->num_slots; i++) {
|
||||||
|
if (flash_areas->slots[i].id == FLASH_AREA_ID(image_0))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == flash_areas->num_slots) {
|
||||||
|
printf("Unsupported area\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
slot = &flash_areas->slots[i];
|
||||||
|
|
||||||
|
for (i = 0; i < slot->num_areas; i++) {
|
||||||
|
sec_off = slot->areas[i].fa_off - slot->whole.fa_off;
|
||||||
|
sec_size = slot->areas[i].fa_size;
|
||||||
|
|
||||||
|
if (off >= sec_off && off < (sec_off + sec_size)) {
|
||||||
|
sector->fs_off = sec_off;
|
||||||
|
sector->fs_size = sec_size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (i < slot->num_areas) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
void sim_assert(int x, const char *assertion, const char *file, unsigned int line, const char *function)
|
void sim_assert(int x, const char *assertion, const char *file, unsigned int line, const char *function)
|
||||||
{
|
{
|
||||||
if (!(x)) {
|
if (!(x)) {
|
||||||
|
|
|
@ -136,6 +136,13 @@ uint8_t flash_area_erased_val(const struct flash_area *);
|
||||||
int flash_area_get_sectors(int fa_id, uint32_t *count,
|
int flash_area_get_sectors(int fa_id, uint32_t *count,
|
||||||
struct flash_sector *sectors);
|
struct flash_sector *sectors);
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrieve the flash sector a given offset belongs to.
|
||||||
|
*
|
||||||
|
* Returns 0 on success, or an error code on failure.
|
||||||
|
*/
|
||||||
|
int flash_area_sector_from_off(uint32_t off, struct flash_sector *sector);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Similar to flash_area_get_sectors(), but return the values in an
|
* Similar to flash_area_get_sectors(), but return the values in an
|
||||||
* array of struct flash_area instead.
|
* array of struct flash_area instead.
|
||||||
|
|
Loading…
Reference in New Issue