Skip to content

Commit be9b2ad

Browse files
committed
sim: mcuboot-sys: Add support for limited sector size information
Adds support for getting the sector size of less sectors than are in an image, which mirrors support in zephyr and allows getting just the size of the first sector in an image Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 18fee81 commit be9b2ad

File tree

1 file changed

+15
-12
lines changed
  • sim/mcuboot-sys/csupport

1 file changed

+15
-12
lines changed

sim/mcuboot-sys/csupport/run.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include <bootutil/bootutil.h>
99
#include <bootutil/image.h>
10+
#include <errno.h>
1011

1112
#include <flash_map_backend/flash_map_backend.h>
1213

@@ -369,6 +370,7 @@ int flash_area_erase(const struct flash_area *area, uint32_t off, uint32_t len)
369370

370371
int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
371372
{
373+
int rc = 0;
372374
uint32_t i;
373375
struct area *slot;
374376
struct area_desc *flash_areas;
@@ -385,20 +387,21 @@ int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
385387

386388
slot = &flash_areas->slots[i];
387389

388-
if (slot->num_areas > (uint32_t)*cnt) {
389-
printf("Too many areas in slot\n");
390-
abort();
390+
if ((uint32_t)*cnt > slot->num_areas) {
391+
*cnt = slot->num_areas;
392+
} else if (slot->num_areas > (uint32_t)*cnt) {
393+
rc = -ENOMEM;
391394
}
392395

393-
*cnt = slot->num_areas;
394-
memcpy(ret, slot->areas, slot->num_areas * sizeof(struct flash_area));
396+
memcpy(ret, slot->areas, *cnt * sizeof(struct flash_area));
395397

396-
return 0;
398+
return rc;
397399
}
398400

399401
int flash_area_get_sectors(int fa_id, uint32_t *count,
400402
struct flash_sector *sectors)
401403
{
404+
int rc = 0;
402405
uint32_t i;
403406
struct area *slot;
404407
struct area_desc *flash_areas;
@@ -415,19 +418,19 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,
415418

416419
slot = &flash_areas->slots[i];
417420

418-
if (slot->num_areas > *count) {
419-
printf("Too many areas in slot\n");
420-
abort();
421+
if (*count > slot->num_areas) {
422+
*count = slot->num_areas;
423+
} else if (slot->num_areas > *count) {
424+
rc = -ENOMEM;
421425
}
422426

423-
for (i = 0; i < slot->num_areas; i++) {
427+
for (i = 0; i < *count; i++) {
424428
sectors[i].fs_off = slot->areas[i].fa_off -
425429
slot->whole.fa_off;
426430
sectors[i].fs_size = slot->areas[i].fa_size;
427431
}
428-
*count = slot->num_areas;
429432

430-
return 0;
433+
return rc;
431434
}
432435

433436
int flash_area_id_to_multi_image_slot(int image_index, int area_id)

0 commit comments

Comments
 (0)