Skip to content

Commit 3a195f2

Browse files
committed
boot: bootutil: loader: Fix issue with using pointers
Fixes an issue whereby static buffers were changed into pointers, whereby they are then assumed to be the size of a pointer rather than the size of the actual buffers Signed-off-by: Jamie McCrae <[email protected]>
1 parent 3b38056 commit 3a195f2

File tree

1 file changed

+14
-41
lines changed

1 file changed

+14
-41
lines changed

boot/bootutil/src/loader.c

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,22 @@ static struct boot_loader_state boot_data;
6767
static struct image_max_size image_max_sizes[BOOT_IMAGE_NUMBER] = {0};
6868
#endif
6969

70+
#if (!defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)) || \
71+
defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
7072
#if !defined(__BOOTSIM__)
7173
/* Used for holding static buffers in multiple functions to work around issues
7274
* in older versions of gcc (e.g. 4.8.4)
7375
*/
7476
struct sector_buffer_t {
75-
boot_sector_t *primary;
76-
boot_sector_t *secondary;
77+
boot_sector_t primary[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
78+
boot_sector_t secondary[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
7779
#if MCUBOOT_SWAP_USING_SCRATCH
78-
boot_sector_t *scratch;
80+
boot_sector_t scratch[BOOT_MAX_IMG_SECTORS];
7981
#endif
8082
};
83+
84+
static struct sector_buffer_t sector_buffers;
85+
#endif
8186
#endif
8287

8388
#if (BOOT_IMAGE_NUMBER > 1)
@@ -303,28 +308,6 @@ boot_version_cmp(const struct image_version *ver1,
303308

304309
#if (!defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)) || \
305310
defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
306-
#if !defined(__BOOTSIM__)
307-
static void boot_get_sector_buffers(struct sector_buffer_t *buffers)
308-
{
309-
/* The array of slot sectors are defined here (as opposed to file scope) so
310-
* that they don't get allocated for non-boot-loader apps. This is
311-
* necessary because the gcc option "-fdata-sections" doesn't seem to have
312-
* any effect in older gcc versions (e.g., 4.8.4).
313-
*/
314-
static boot_sector_t primary_slot_sectors[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
315-
static boot_sector_t secondary_slot_sectors[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
316-
#if MCUBOOT_SWAP_USING_SCRATCH
317-
static boot_sector_t scratch_sectors[BOOT_MAX_IMG_SECTORS];
318-
#endif
319-
320-
buffers->primary = (boot_sector_t *)&primary_slot_sectors;
321-
buffers->secondary = (boot_sector_t *)&secondary_slot_sectors;
322-
#if MCUBOOT_SWAP_USING_SCRATCH
323-
buffers->scratch = (boot_sector_t *)&scratch_sectors;
324-
#endif
325-
}
326-
#endif
327-
328311
static int
329312
boot_initialize_area(struct boot_loader_state *state, int flash_area)
330313
{
@@ -2209,9 +2192,6 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
22092192
{
22102193
size_t slot;
22112194
struct boot_status bs;
2212-
#if !defined(__BOOTSIM__)
2213-
struct sector_buffer_t sector_buffers;
2214-
#endif
22152195
int rc = -1;
22162196
FIH_DECLARE(fih_rc, FIH_FAILURE);
22172197
int fa_id;
@@ -2238,10 +2218,6 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
22382218
(void)has_upgrade;
22392219
#endif
22402220

2241-
#if !defined(__BOOTSIM__)
2242-
boot_get_sector_buffers(&sector_buffers);
2243-
#endif
2244-
22452221
/* Iterate over all the images. By the end of the loop the swap type has
22462222
* to be determined for each image and all aborted swaps have to be
22472223
* completed.
@@ -2264,9 +2240,9 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
22642240

22652241
#if !defined(__BOOTSIM__)
22662242
BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors =
2267-
&sector_buffers.primary[image_index];
2243+
sector_buffers.primary[image_index];
22682244
BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors =
2269-
&sector_buffers.secondary[image_index];
2245+
sector_buffers.secondary[image_index];
22702246
#if MCUBOOT_SWAP_USING_SCRATCH
22712247
state->scratch.sectors = sector_buffers.scratch;
22722248
#endif
@@ -3463,30 +3439,27 @@ void boot_state_clear(struct boot_loader_state *state)
34633439
#if defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
34643440
/**
34653441
* Reads image data to find out the maximum application sizes. Only needs to
3466-
* be called in serial recovery mode, as the state informatio is unpopulated
3442+
* be called in serial recovery mode, as the state information is unpopulated
34673443
* at that time
34683444
*/
34693445
static void boot_fetch_slot_state_sizes(void)
34703446
{
3471-
struct sector_buffer_t sector_buffers;
34723447
size_t slot;
34733448
int rc = -1;
34743449
int fa_id;
34753450
int image_index;
34763451

3477-
boot_get_sector_buffers(&sector_buffers);
3478-
34793452
IMAGES_ITER(BOOT_CURR_IMG(&boot_data)) {
34803453
int max_size = 0;
34813454

34823455
image_index = BOOT_CURR_IMG(&boot_data);
34833456

34843457
BOOT_IMG(&boot_data, BOOT_PRIMARY_SLOT).sectors =
3485-
&sector_buffers.primary[image_index];
3458+
sector_buffers.primary[image_index];
34863459
BOOT_IMG(&boot_data, BOOT_SECONDARY_SLOT).sectors =
3487-
&sector_buffers.secondary[image_index];
3460+
sector_buffers.secondary[image_index];
34883461
#if MCUBOOT_SWAP_USING_SCRATCH
3489-
boot_data.scratch.sectors = sector_buffers.scratch;;
3462+
boot_data.scratch.sectors = sector_buffers.scratch;
34903463
#endif
34913464

34923465
/* Open primary and secondary image areas for the duration

0 commit comments

Comments
 (0)