dfu: img_util: Add flash integrity check
Flash memory can be write but there is no way to check flash integrity. Add flash_img_check method that verify flash integrity. This is useful to avoid firmware reboot and test. Another use is ensure that firmware upgrade routines from internet server to flash slot are performing properly. This uses flash_area_check_int_sha256 method to check a SHA-256 hash. On sucess match, zero is returned, otherwise a negative errno value. Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
parent
eb0f571790
commit
4d35d3d83a
7 changed files with 131 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2020 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2017 Linaro Limited
|
||||
* Copyright (c) 2020 Gerson Fernando Budke <nandojve@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -83,3 +84,36 @@ int flash_img_init(struct flash_img_context *ctx)
|
|||
{
|
||||
return flash_img_init_id(ctx, FLASH_AREA_IMAGE_SECONDARY);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IMG_ENABLE_IMAGE_CHECK)
|
||||
int flash_img_check(struct flash_img_context *ctx,
|
||||
const struct flash_img_check *fic,
|
||||
uint8_t area_id)
|
||||
{
|
||||
struct flash_area_check fac;
|
||||
int rc;
|
||||
|
||||
if (!ctx || !fic) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rc = flash_area_open(area_id,
|
||||
(const struct flash_area **)&(ctx->flash_area));
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
fac.match = fic->match;
|
||||
fac.clen = fic->clen;
|
||||
fac.off = 0;
|
||||
fac.rbuf = ctx->buf;
|
||||
fac.rblen = sizeof(ctx->buf);
|
||||
|
||||
rc = flash_area_check_int_sha256(ctx->flash_area, &fac);
|
||||
|
||||
flash_area_close(ctx->flash_area);
|
||||
ctx->flash_area = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue