Skip to content

Commit 10badb8

Browse files
committed
nuttx: 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 9efcc1d commit 10badb8

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

boot/nuttx/include/flash_map_backend/flash_map_backend.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,28 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
351351
int flash_area_get_sectors(int fa_id, uint32_t *count,
352352
struct flash_sector *sectors);
353353

354+
/****************************************************************************
355+
* Name: flash_area_get_sectors_fa
356+
*
357+
* Description:
358+
* Retrieve info about sectors within the area.
359+
*
360+
* Input Parameters:
361+
* fa - flash area object pointer.
362+
* count - On input, represents the capacity of the sectors buffer.
363+
*
364+
* Output Parameters:
365+
* count - On output, it shall contain the number of retrieved sectors.
366+
* sectors - Buffer for sectors data.
367+
*
368+
* Returned Value:
369+
* Zero on success, or negative value in case of error.
370+
*
371+
****************************************************************************/
372+
373+
int flash_area_get_sectors(const struct flash_area *fa, uint32_t *count,
374+
struct flash_sector *sectors);
375+
354376
/****************************************************************************
355377
* Name: flash_area_id_from_multi_image_slot
356378
*

boot/nuttx/src/flash_map_backend/flash_map_backend.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ uint8_t flash_area_erased_val(const struct flash_area *fa)
641641
}
642642

643643
/****************************************************************************
644-
* Name: flash_area_get_sectors
644+
* Name: flash_area_get_sectors_fa
645645
*
646646
* Description:
647647
* Retrieve info about sectors within the area.
648648
*
649649
* Input Parameters:
650-
* fa_id - ID of the flash area whose info will be retrieved.
650+
* fa - pointer to flash area object.
651651
* count - On input, represents the capacity of the sectors buffer.
652652
*
653653
* Output Parameters:
@@ -659,15 +659,9 @@ uint8_t flash_area_erased_val(const struct flash_area *fa)
659659
*
660660
****************************************************************************/
661661

662-
int flash_area_get_sectors(int fa_id, uint32_t *count,
663-
struct flash_sector *sectors)
662+
int flash_area_get_sectors_fa(const struct flash_area *fa, uint32_t *count,
663+
struct flash_sector *sectors)
664664
{
665-
size_t off;
666-
uint32_t total_count = 0;
667-
struct flash_device_s *dev = lookup_flash_device_by_id(fa_id);
668-
const size_t sector_size = dev->mtdgeo.erasesize;
669-
const struct flash_area *fa = fa = dev->fa_cfg;
670-
671665
for (off = 0; off < fa->fa_size; off += sector_size)
672666
{
673667
/* Note: Offset here is relative to flash area, not device */
@@ -686,6 +680,38 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,
686680
return OK;
687681
}
688682

683+
684+
/****************************************************************************
685+
* Name: flash_area_get_sectors
686+
*
687+
* Description:
688+
* Retrieve info about sectors within the area.
689+
*
690+
* Input Parameters:
691+
* fa_id - ID of the flash area whose info will be retrieved.
692+
* count - On input, represents the capacity of the sectors buffer.
693+
*
694+
* Output Parameters:
695+
* count - On output, it shall contain the number of retrieved sectors.
696+
* sectors - Buffer for sectors data.
697+
*
698+
* Returned Value:
699+
* Zero on success, or negative value in case of error.
700+
*
701+
****************************************************************************/
702+
703+
int flash_area_get_sectors(int fa_id, uint32_t *count,
704+
struct flash_sector *sectors)
705+
{
706+
size_t off;
707+
uint32_t total_count = 0;
708+
struct flash_device_s *dev = lookup_flash_device_by_id(fa_id);
709+
const size_t sector_size = dev->mtdgeo.erasesize;
710+
const struct flash_area *fa = fa = dev->fa_cfg;
711+
712+
return flash_area_get_sectors_fa(fa, count, sectors);
713+
}
714+
689715
/****************************************************************************
690716
* Name: flash_area_id_from_multi_image_slot
691717
*

0 commit comments

Comments
 (0)