Skip to content

Commit 854b355

Browse files
nordicjmbjarki-andreasen
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 3a195f2) Signed-off-by: Dominik Ermel <[email protected]>
1 parent 14e2d56 commit 854b355

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
@@ -87,17 +87,22 @@ static bool owner_nsib[BOOT_IMAGE_NUMBER] = {false};
8787
static struct image_max_size image_max_sizes[BOOT_IMAGE_NUMBER] = {0};
8888
#endif
8989

90+
#if (!defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)) || \
91+
defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
9092
#if !defined(__BOOTSIM__)
9193
/* Used for holding static buffers in multiple functions to work around issues
9294
* in older versions of gcc (e.g. 4.8.4)
9395
*/
9496
struct sector_buffer_t {
95-
boot_sector_t *primary;
96-
boot_sector_t *secondary;
97+
boot_sector_t primary[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
98+
boot_sector_t secondary[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
9799
#if MCUBOOT_SWAP_USING_SCRATCH
98-
boot_sector_t *scratch;
100+
boot_sector_t scratch[BOOT_MAX_IMG_SECTORS];
99101
#endif
100102
};
103+
104+
static struct sector_buffer_t sector_buffers;
105+
#endif
101106
#endif
102107

103108
#if (BOOT_IMAGE_NUMBER > 1)
@@ -332,28 +337,6 @@ boot_version_cmp(const struct image_version *ver1,
332337

333338
#if (!defined(MCUBOOT_DIRECT_XIP) && !defined(MCUBOOT_RAM_LOAD)) || \
334339
defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
335-
#if !defined(__BOOTSIM__)
336-
static void boot_get_sector_buffers(struct sector_buffer_t *buffers)
337-
{
338-
/* The array of slot sectors are defined here (as opposed to file scope) so
339-
* that they don't get allocated for non-boot-loader apps. This is
340-
* necessary because the gcc option "-fdata-sections" doesn't seem to have
341-
* any effect in older gcc versions (e.g., 4.8.4).
342-
*/
343-
static boot_sector_t primary_slot_sectors[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
344-
static boot_sector_t secondary_slot_sectors[BOOT_IMAGE_NUMBER][BOOT_MAX_IMG_SECTORS];
345-
#if MCUBOOT_SWAP_USING_SCRATCH
346-
static boot_sector_t scratch_sectors[BOOT_MAX_IMG_SECTORS];
347-
#endif
348-
349-
buffers->primary = (boot_sector_t *)&primary_slot_sectors;
350-
buffers->secondary = (boot_sector_t *)&secondary_slot_sectors;
351-
#if MCUBOOT_SWAP_USING_SCRATCH
352-
buffers->scratch = (boot_sector_t *)&scratch_sectors;
353-
#endif
354-
}
355-
#endif
356-
357340
static int
358341
boot_initialize_area(struct boot_loader_state *state, int flash_area)
359342
{
@@ -2550,9 +2533,6 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
25502533
{
25512534
size_t slot;
25522535
struct boot_status bs;
2553-
#if !defined(__BOOTSIM__)
2554-
struct sector_buffer_t sector_buffers;
2555-
#endif
25562536
int rc = -1;
25572537
FIH_DECLARE(fih_rc, FIH_FAILURE);
25582538
int fa_id;
@@ -2579,10 +2559,6 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
25792559
(void)has_upgrade;
25802560
#endif
25812561

2582-
#if !defined(__BOOTSIM__)
2583-
boot_get_sector_buffers(&sector_buffers);
2584-
#endif
2585-
25862562
/* Iterate over all the images. By the end of the loop the swap type has
25872563
* to be determined for each image and all aborted swaps have to be
25882564
* completed.
@@ -2605,9 +2581,9 @@ context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp)
26052581

26062582
#if !defined(__BOOTSIM__)
26072583
BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors =
2608-
&sector_buffers.primary[image_index];
2584+
sector_buffers.primary[image_index];
26092585
BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors =
2610-
&sector_buffers.secondary[image_index];
2586+
sector_buffers.secondary[image_index];
26112587
#if MCUBOOT_SWAP_USING_SCRATCH
26122588
state->scratch.sectors = sector_buffers.scratch;
26132589
#endif
@@ -3827,30 +3803,27 @@ void boot_state_clear(struct boot_loader_state *state)
38273803
#if defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO)
38283804
/**
38293805
* Reads image data to find out the maximum application sizes. Only needs to
3830-
* be called in serial recovery mode, as the state informatio is unpopulated
3806+
* be called in serial recovery mode, as the state information is unpopulated
38313807
* at that time
38323808
*/
38333809
static void boot_fetch_slot_state_sizes(void)
38343810
{
3835-
struct sector_buffer_t sector_buffers;
38363811
size_t slot;
38373812
int rc = -1;
38383813
int fa_id;
38393814
int image_index;
38403815

3841-
boot_get_sector_buffers(&sector_buffers);
3842-
38433816
IMAGES_ITER(BOOT_CURR_IMG(&boot_data)) {
38443817
int max_size = 0;
38453818

38463819
image_index = BOOT_CURR_IMG(&boot_data);
38473820

38483821
BOOT_IMG(&boot_data, BOOT_PRIMARY_SLOT).sectors =
3849-
&sector_buffers.primary[image_index];
3822+
sector_buffers.primary[image_index];
38503823
BOOT_IMG(&boot_data, BOOT_SECONDARY_SLOT).sectors =
3851-
&sector_buffers.secondary[image_index];
3824+
sector_buffers.secondary[image_index];
38523825
#if MCUBOOT_SWAP_USING_SCRATCH
3853-
boot_data.scratch.sectors = sector_buffers.scratch;;
3826+
boot_data.scratch.sectors = sector_buffers.scratch;
38543827
#endif
38553828

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

0 commit comments

Comments
 (0)