Skip to content

Commit 2dd1fc2

Browse files
committed
cypress: 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 ccc0f82 commit 2dd1fc2

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

boot/cypress/cy_flash_pal/cy_flash_map.c

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -481,67 +481,73 @@ int flash_area_read_is_empty(const struct flash_area *fa, uint32_t off,
481481
}
482482

483483
#ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS
484-
int flash_area_get_sectors(int idx, uint32_t *cnt, struct flash_sector *ret)
484+
int flash_area_get_sectors_fa(const struct flash_area *fa, uint32_t *cnt, struct flash_sector *ret)
485485
{
486486
int rc = 0;
487487
uint32_t i = 0;
488488
struct flash_area *fa = NULL;
489489

490-
while(NULL != boot_area_descs[i])
490+
size_t sector_size = 0;
491+
492+
if(fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH)
491493
{
492-
if(idx == boot_area_descs[i]->fa_id)
493-
{
494-
fa = boot_area_descs[i];
495-
break;
496-
}
497-
i++;
494+
sector_size = CY_FLASH_SIZEOF_ROW;
495+
}
496+
#ifdef CY_BOOT_USE_EXTERNAL_FLASH
497+
else if((fa->fa_device_id & FLASH_DEVICE_EXTERNAL_FLAG) == FLASH_DEVICE_EXTERNAL_FLAG)
498+
{
499+
/* implement for SMIF */
500+
/* lets assume they are equal */
501+
sector_size = CY_FLASH_SIZEOF_ROW;
502+
}
503+
#endif
504+
else
505+
{
506+
rc = -1;
498507
}
499508

500-
if(NULL != boot_area_descs[i])
509+
if(0 == rc)
501510
{
502-
size_t sector_size = 0;
511+
uint32_t addr = 0;
512+
size_t sectors_n = 0;
503513

504-
if(fa->fa_device_id == FLASH_DEVICE_INTERNAL_FLASH)
505-
{
506-
sector_size = CY_FLASH_SIZEOF_ROW;
507-
}
508-
#ifdef CY_BOOT_USE_EXTERNAL_FLASH
509-
else if((fa->fa_device_id & FLASH_DEVICE_EXTERNAL_FLAG) == FLASH_DEVICE_EXTERNAL_FLAG)
510-
{
511-
/* implement for SMIF */
512-
/* lets assume they are equal */
513-
sector_size = CY_FLASH_SIZEOF_ROW;
514-
}
515-
#endif
516-
else
517-
{
518-
rc = -1;
519-
}
514+
sectors_n = (fa->fa_size + (sector_size - 1)) / sector_size;
515+
assert(sectors_n <= *cnt);
520516

521-
if(0 == rc)
517+
addr = fa->fa_off;
518+
for(i = 0; i < sectors_n; i++)
522519
{
523-
uint32_t addr = 0;
524-
size_t sectors_n = 0;
520+
ret[i].fs_size = sector_size ;
521+
ret[i].fs_off = addr ;
522+
addr += sector_size ;
523+
}
525524

526-
sectors_n = (fa->fa_size + (sector_size - 1)) / sector_size;
527-
assert(sectors_n <= *cnt);
525+
*cnt = sectors_n;
526+
}
527+
return rc;
528+
}
528529

529-
addr = fa->fa_off;
530-
for(i = 0; i < sectors_n; i++)
531-
{
532-
ret[i].fs_size = sector_size ;
533-
ret[i].fs_off = addr ;
534-
addr += sector_size ;
535-
}
530+
int flash_area_get_sectors(int idx, uint32_t *cnt, struct flash_sector *ret)
531+
{
532+
int rc = -1;
533+
uint32_t i = 0;
534+
struct flash_area *fa = NULL;
536535

537-
*cnt = sectors_n;
536+
while(NULL != boot_area_descs[i])
537+
{
538+
if(idx == boot_area_descs[i]->fa_id)
539+
{
540+
fa = boot_area_descs[i];
541+
break;
538542
}
543+
i++;
539544
}
540-
else
545+
546+
if(NULL != fa)
541547
{
542-
rc = -1;
548+
flash_area_get_sectors_fa(fa, cnt, ret);
543549
}
544-
545550
return rc;
546551
}
552+
547553
#endif

boot/cypress/cy_flash_pal/include/flash_map_backend/flash_map_backend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ int flash_area_id_from_multi_image_slot(int image_index, int slot);
177177
int flash_area_id_to_multi_image_slot(int image_index, int area_id);
178178
#ifdef MCUBOOT_USE_FLASH_AREA_GET_SECTORS
179179
int flash_area_get_sectors(int idx, uint32_t *cnt, struct flash_sector *ret);
180+
int flash_area_get_sectors_fa(const struct flash_area *fa, uint32_t *cnt,
181+
struct flash_sector *ret);
180182
#endif
181183
/*
182184
* Returns the value expected to be read when accesing any erased

0 commit comments

Comments
 (0)