Skip to content

Commit 4f1ab9e

Browse files
committed
bootutil: Add missing images to get maximum image size details
Adds support for getting the maximum image size of multiple images and adding this data to the shared data area Signed-off-by: Jamie McCrae <[email protected]>
1 parent 4baa6d3 commit 4f1ab9e

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

boot/bootutil/include/bootutil/boot_record.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ int boot_save_boot_status(uint8_t sw_module,
7272
* @param[in] hdr Pointer to the image header stored in RAM.
7373
* @param[in] fap Pointer to the flash area where image is stored.
7474
* @param[in] slot The currently active slot being booted.
75-
* @param[in] max_app_size The maximum size of an image that can be loaded.
75+
* @param[in] max_app_sizes The maximum sizes of images that can be loaded.
7676
*
7777
* @return 0 on success; nonzero on failure.
7878
*/
7979
int boot_save_shared_data(const struct image_header *hdr,
8080
const struct flash_area *fap,
8181
const uint8_t active_slot,
82-
const int max_app_size);
82+
const struct image_max_size *max_app_sizes);
8383

8484
#ifdef __cplusplus
8585
}

boot/bootutil/include/bootutil/boot_status.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ extern "C" {
113113
#define BLINFO_RECOVERY 0x02
114114
#define BLINFO_RUNNING_SLOT 0x03
115115
#define BLINFO_BOOTLOADER_VERSION 0x04
116-
#define BLINFO_MAX_APPLICATION_SIZE 0x05
116+
#define BLINFO_MAX_APPLICATION_SIZE 0x05 /* Same as BLINFO_MAX_APPLICATION_SIZE_IMAGE_0, legacy name */
117+
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_0 BLINFO_MAX_APPLICATION_SIZE
118+
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_1 0x06
119+
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_2 0x07
120+
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_3 0x08
121+
#define BLINFO_MAX_APPLICATION_SIZE_IMAGE_4 0x09
117122

118123
enum mcuboot_mode {
119124
MCUBOOT_MODE_SINGLE_SLOT,

boot/bootutil/include/bootutil/bootutil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ struct image_trailer {
7777
uint8_t magic[BOOT_MAGIC_SZ];
7878
};
7979

80+
struct image_max_size {
81+
bool calculated;
82+
uint32_t max_size;
83+
};
84+
8085
/* you must have pre-allocated all the entries within this structure */
8186
fih_ret boot_go(struct boot_rsp *rsp);
8287
fih_ret boot_go_for_image_id(struct boot_rsp *rsp, uint32_t image_id);
8388

8489
struct boot_loader_state;
8590
void boot_state_clear(struct boot_loader_state *state);
8691
fih_ret context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);
92+
const struct image_max_size *boot_get_max_app_size(void);
8793

8894
#define SPLIT_GO_OK (0)
8995
#define SPLIT_GO_NON_MATCHING (-1)

boot/bootutil/src/boot_record.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ boot_save_boot_status(uint8_t sw_module,
230230

231231
#ifdef MCUBOOT_DATA_SHARING_BOOTINFO
232232
int boot_save_shared_data(const struct image_header *hdr, const struct flash_area *fap,
233-
const uint8_t slot, const int max_app_size)
233+
const uint8_t slot, const struct image_max_size *max_app_sizes)
234234
{
235235
int rc;
236+
uint8_t image = 0;
236237

237238
#if defined(MCUBOOT_SINGLE_APPLICATION_SLOT)
238239
uint8_t mode = MCUBOOT_MODE_SINGLE_SLOT;
@@ -325,11 +326,16 @@ int boot_save_shared_data(const struct image_header *hdr, const struct flash_are
325326
}
326327
#endif
327328

328-
if (!rc) {
329-
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
330-
BLINFO_MAX_APPLICATION_SIZE,
331-
sizeof(max_app_size),
332-
(void *)&max_app_size);
329+
while (image < BOOT_IMAGE_NUMBER && !rc) {
330+
if (max_app_sizes[image].calculated == true) {
331+
rc = boot_add_data_to_shared_area(TLV_MAJOR_BLINFO,
332+
(BLINFO_MAX_APPLICATION_SIZE + image),
333+
sizeof(max_app_sizes[image].max_size),
334+
(void *)&max_app_sizes[image].max_size);
335+
336+
}
337+
338+
++image;
333339
}
334340

335341
return rc;

boot/bootutil/src/loader.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
6363

6464
static struct boot_loader_state boot_data;
6565

66+
#if defined(MCUBOOT_DATA_SHARING)
67+
static struct image_max_size image_max_sizes[BOOT_IMAGE_NUMBER] = {0};
68+
#endif
69+
6670
#if (BOOT_IMAGE_NUMBER > 1)
6771
#define IMAGES_ITER(x) for ((x) = 0; (x) < BOOT_IMAGE_NUMBER; ++(x))
6872
#else
@@ -137,10 +141,6 @@ boot_add_shared_data(struct boot_loader_state *state,
137141
#if defined(MCUBOOT_MEASURED_BOOT) || defined(MCUBOOT_DATA_SHARING)
138142
int rc;
139143

140-
#ifdef MCUBOOT_DATA_SHARING
141-
int max_app_size;
142-
#endif
143-
144144
#ifdef MCUBOOT_MEASURED_BOOT
145145
rc = boot_save_boot_status(BOOT_CURR_IMG(state),
146146
boot_img_hdr(state, active_slot),
@@ -152,10 +152,9 @@ boot_add_shared_data(struct boot_loader_state *state,
152152
#endif /* MCUBOOT_MEASURED_BOOT */
153153

154154
#ifdef MCUBOOT_DATA_SHARING
155-
max_app_size = app_max_size(state);
156155
rc = boot_save_shared_data(boot_img_hdr(state, active_slot),
157156
BOOT_IMG_AREA(state, active_slot),
158-
active_slot, max_app_size);
157+
active_slot, image_max_sizes);
159158
if (rc != 0) {
160159
BOOT_LOG_ERR("Failed to add data to shared memory area.");
161160
return rc;
@@ -1841,6 +1840,10 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
18411840
int rc;
18421841
FIH_DECLARE(fih_rc, FIH_FAILURE);
18431842

1843+
#if defined(MCUBOOT_DATA_SHARING)
1844+
int max_size;
1845+
#endif
1846+
18441847
/* Determine the sector layout of the image slots and scratch area. */
18451848
rc = boot_read_sectors(state);
18461849
if (rc != 0) {
@@ -1867,6 +1870,16 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
18671870
return;
18681871
}
18691872

1873+
#if defined(MCUBOOT_DATA_SHARING)
1874+
/* Fetch information on maximum sizes for later usage, if needed */
1875+
max_size = app_max_size(state);
1876+
1877+
if (max_size > 0) {
1878+
image_max_sizes[BOOT_CURR_IMG(state)].calculated = true;
1879+
image_max_sizes[BOOT_CURR_IMG(state)].max_size = max_size;
1880+
}
1881+
#endif
1882+
18701883
/* If the current image's slots aren't compatible, no swap is possible.
18711884
* Just boot into primary slot.
18721885
*/
@@ -3323,3 +3336,13 @@ void boot_state_clear(struct boot_loader_state *state)
33233336
memset(&boot_data, 0, sizeof(struct boot_loader_state));
33243337
}
33253338
}
3339+
3340+
#if defined(MCUBOOT_DATA_SHARING)
3341+
/**
3342+
* Fetches the maximum allowed size of the image
3343+
*/
3344+
const struct image_max_size *boot_get_max_app_size(void)
3345+
{
3346+
return image_max_sizes;
3347+
}
3348+
#endif

0 commit comments

Comments
 (0)