Skip to content

Commit 9efcc1d

Browse files
committed
zephyr: Add implementation of flash_area_get_sectors_fa
Variant of flash_area_get_sectors that takes flash_area object pointer instead of flash area identifier. Signed-off-by: Dominik Ermel <[email protected]>
1 parent aef9e80 commit 9efcc1d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

boot/zephyr/flash_map_extended.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,35 @@ __weak uint8_t flash_area_erased_val(const struct flash_area *fap)
135135
(void)fap;
136136
return ERASED_VAL;
137137
}
138+
139+
int flash_area_get_sectors_fa(const struct flash_area *fa, uint32_t *count,
140+
struct flash_sector *ret)
141+
{
142+
off_t fa_off = fa->fa_off;
143+
off_t offset = 0;
144+
size_t fa_size = fa->fa_size;
145+
int max_sectors = *count;
146+
int sector_idx = 0;
147+
int rc = 0;
148+
149+
printk("Getting sectprs\n");
150+
while (rc == 0 && sector_idx < max_sectors && offset < fa_size) {
151+
struct flash_pages_info fpi;
152+
153+
rc = flash_get_page_info_by_offs(fa->fa_dev, fa_off + offset, &fpi);
154+
155+
if (rc == 0) {
156+
ret[sector_idx].fs_off = fpi.start_offset - fa_off;
157+
ret[sector_idx].fs_size = fpi.size;
158+
++sector_idx;
159+
offset += fpi.size;
160+
}
161+
}
162+
163+
if (sector_idx >= max_sectors && offset >= fa_size) {
164+
printk("Faileing here\n");
165+
return -ENOENT;
166+
}
167+
168+
return rc;
169+
}

boot/zephyr/include/flash_map_backend/flash_map_backend.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ int flash_area_id_to_multi_image_slot(int image_index, int area_id);
6262
*/
6363
int flash_area_sector_from_off(off_t off, struct flash_sector *sector);
6464

65+
/* Get sectors for given flash_area object. This function is similar to
66+
* flash_area_get_sectors but takes flash_area object pointer instead
67+
* of flash area identifier.
68+
*
69+
* @param fa pointer to flash_area object.
70+
* @param count in: size of array for returned sectors, out: number
71+
* of sectors filled in.
72+
* @param ret array of sectors.
73+
*
74+
* Returns 0 on success, -ERANGE when there is not enough space in
75+
* @p ret for sector information; other negative errno code.
76+
*/
77+
int flash_area_get_sectors_fa(const struct flash_area *fa, uint32_t *count,
78+
struct flash_sector *ret);
79+
6580
static inline uint32_t flash_area_get_off(const struct flash_area *fa)
6681
{
6782
return (uint32_t)fa->fa_off;

0 commit comments

Comments
 (0)