Skip to content

Commit e67e6d5

Browse files
Guillaume Lagercarlescufi
authored andcommitted
mcuboot: Remove public dependency on bootutil
BOOT_MAGIC_SZ and BOOT_MAX_ALIGN were used in the header without including bootutil/bootutil_public.h. This change remove the need of the inclusion by making the dependency private. Fixes #52095 Signed-off-by: Guillaume Lager <[email protected]>
1 parent 551f8c4 commit e67e6d5

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

include/zephyr/dfu/mcuboot.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <stdbool.h>
2020
#include <stddef.h>
21+
#include <sys/types.h>
2122

2223
#include <zephyr/types.h>
2324

@@ -79,9 +80,7 @@ extern "C" {
7980

8081
#define BOOT_IMG_VER_STRLEN_MAX 25 /* 255.255.65535.4294967295\0 */
8182

82-
#define BOOT_TRAILER_IMG_STATUS_OFFS(bank_area) ((bank_area)->fa_size -\
83-
BOOT_MAGIC_SZ -\
84-
BOOT_MAX_ALIGN * 2)
83+
8584
/**
8685
* @brief MCUboot image header representation for image version
8786
*
@@ -263,6 +262,23 @@ int boot_request_upgrade_multi(int image_index, int permanent);
263262
*/
264263
int boot_erase_img_bank(uint8_t area_id);
265264

265+
/**
266+
* @brief Get the offset of the status in the image bank
267+
*
268+
* @param area_id flash_area ID of image bank to get the status offset
269+
* @return a positive offset on success, negative errno code on fail
270+
*/
271+
ssize_t boot_get_area_trailer_status_offset(uint8_t area_id);
272+
273+
/**
274+
* @brief Get the offset of the status from an image bank size
275+
*
276+
* @param area_size size of image bank
277+
* @return offset of the status. When negative the status will not fit
278+
* the given size
279+
*/
280+
ssize_t boot_get_trailer_status_offset(size_t area_size);
281+
266282
#ifdef __cplusplus
267283
}
268284
#endif

subsys/dfu/boot/mcuboot.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,30 @@ int boot_erase_img_bank(uint8_t area_id)
251251

252252
return rc;
253253
}
254+
255+
ssize_t boot_get_trailer_status_offset(size_t area_size)
256+
{
257+
return (ssize_t)area_size - BOOT_MAGIC_SZ - BOOT_MAX_ALIGN * 2;
258+
}
259+
260+
ssize_t boot_get_area_trailer_status_offset(uint8_t area_id)
261+
{
262+
int rc;
263+
const struct flash_area *fa;
264+
ssize_t offset;
265+
266+
rc = flash_area_open(area_id, &fa);
267+
if (rc) {
268+
return rc;
269+
}
270+
271+
offset = boot_get_trailer_status_offset(fa->fa_size);
272+
273+
flash_area_close(fa);
274+
275+
if (offset < 0) {
276+
return -EFAULT;
277+
}
278+
279+
return offset;
280+
}

subsys/dfu/img_util/flash_img.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ int flash_img_buffered_write(struct flash_img_context *ctx, const uint8_t *data,
5454
}
5555

5656
#ifdef CONFIG_IMG_ERASE_PROGRESSIVELY
57+
ssize_t status_offset = boot_get_trailer_status_offset(
58+
ctx->flash_area->fa_size);
5759
rc = stream_flash_erase_page(&ctx->stream,
5860
ctx->flash_area->fa_off +
59-
BOOT_TRAILER_IMG_STATUS_OFFS(ctx->flash_area));
61+
status_offset);
6062
if (rc) {
6163
return rc;
6264
}

subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
466466
*/
467467

468468
/* erase the image trailer area if it was not erased */
469-
off = BOOT_TRAILER_IMG_STATUS_OFFS(fa);
469+
off = boot_get_trailer_status_offset(fa->fa_size);
470470
if (off >= erase_size) {
471471
rc = flash_get_page_info_by_offs(dev, fa->fa_off + off, &page);
472472

0 commit comments

Comments
 (0)