DFU: add init function with area id as parameter

This allows flash_img.c to be used outside of mcuboot scope.
Add new call to not break existing code.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
This commit is contained in:
Håkon Øye Amundsen 2020-03-03 14:18:28 +00:00 committed by Johan Hedberg
commit 64d8e65f33
3 changed files with 52 additions and 2 deletions

View file

@ -227,13 +227,27 @@ size_t flash_img_bytes_written(struct flash_img_context *ctx)
return ctx->bytes_written;
}
int flash_img_init(struct flash_img_context *ctx)
static void init_ctx(struct flash_img_context *ctx)
{
ctx->bytes_written = 0;
ctx->buf_bytes = 0U;
#ifdef CONFIG_IMG_ERASE_PROGRESSIVELY
ctx->off_last = -1;
#endif
}
int flash_img_init_id(struct flash_img_context *ctx, u8_t area_id)
{
init_ctx(ctx);
return flash_area_open(area_id,
(const struct flash_area **)&(ctx->flash_area));
}
int flash_img_init(struct flash_img_context *ctx)
{
init_ctx(ctx);
return flash_area_open(FLASH_AREA_IMAGE_SECONDARY,
(const struct flash_area **)&(ctx->flash_area));
}