Skip to content

Commit aba7dfe

Browse files
nvlsianpuioannisg
authored andcommitted
dfu/img_util: fix flash_sector_from_off
flash_sector_from_off fetched sector data of page in relation to the flash memory beginning instead of the flash area beginning. Issue was invisible as on most devices all sectors looks similar. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent d282513 commit aba7dfe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

subsys/dfu/img_util/flash_img.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static int flash_sector_from_off(struct flash_area const *fap, off_t off,
7575
int rc = -ENODEV;
7676

7777
flash_dev = flash_area_get_device(fap);
78+
79+
off += fap->fa_off; /* flash driver uses offset from memory beginning */
80+
7881
if (flash_dev) {
7982
rc = flash_get_page_info_by_offs(flash_dev, off, &page);
8083
if (rc == 0) {
@@ -110,7 +113,9 @@ static int flash_progressive_erase(struct flash_img_context *ctx, off_t off)
110113
ctx->off_last = sector.fs_off;
111114
LOG_INF("Erasing sector at offset 0x%08lx",
112115
(long)sector.fs_off);
113-
rc = flash_area_erase(ctx->flash_area, sector.fs_off,
116+
rc = flash_area_erase(ctx->flash_area,
117+
sector.fs_off -
118+
ctx->flash_area->fa_off,
114119
sector.fs_size);
115120
if (rc) {
116121
LOG_ERR("Error %d while erasing sector", rc);

0 commit comments

Comments
 (0)