Skip to content

Commit dd03cf1

Browse files
dgarskedanielinux
authored andcommitted
Disabled wolfBoot_swap_and_final_erase with CUSTOM_PARTITION_TRAILER (not compatible). Added a few more uint8_t alignments.
1 parent 79cef5f commit dd03cf1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ static int copy_flash_buffered(uintptr_t src_addr, uintptr_t dst_addr,
14191419

14201420
#ifndef BUFFER_DECLARED
14211421
#define BUFFER_DECLARED
1422-
static uint8_t buffer[FLASHBUFFER_SIZE];
1422+
static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED_STACK(4);
14231423
#endif
14241424

14251425
#ifdef WOLFBOOT_FLASH_MULTI_SECTOR_ERASE

src/update_flash.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static volatile const uint32_t __attribute__((used)) wolfboot_version = WOLFBOOT
5050
#ifdef EXT_FLASH
5151
# ifndef BUFFER_DECLARED
5252
# define BUFFER_DECLARED
53-
static uint8_t buffer[FLASHBUFFER_SIZE];
53+
static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED(4);
5454
# endif
5555
#endif
5656

@@ -166,13 +166,13 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
166166
if (PART_IS_EXT(src)) {
167167
#ifndef BUFFER_DECLARED
168168
#define BUFFER_DECLARED
169-
static uint8_t buffer[FLASHBUFFER_SIZE];
169+
static uint8_t buffer[FLASHBUFFER_SIZE] XALIGNED_STACK(4);
170170
#endif
171171
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
172172
while (pos < WOLFBOOT_SECTOR_SIZE) {
173173
if (src_sector_offset + pos <
174174
(src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
175-
/* bypass decryption, copy encrypted data into swap (and its external) */
175+
/* bypass decryption, copy encrypted data into swap if its external */
176176
if (dst->part == PART_SWAP && SWAP_EXT) {
177177
ext_flash_read((uintptr_t)(src->hdr) + src_sector_offset + pos,
178178
(void *)buffer, FLASHBUFFER_SIZE);
@@ -202,7 +202,7 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
202202
return pos;
203203
}
204204

205-
#ifndef DISABLE_BACKUP
205+
#if !defined(DISABLE_BACKUP) && !defined(CUSTOM_PARTITION_TRAILER)
206206

207207
#ifdef EXT_ENCRYPTED
208208
# define TRAILER_OFFSET_WORDS \
@@ -214,7 +214,7 @@ static int RAMFUNCTION wolfBoot_copy_sector(struct wolfBoot_image *src,
214214
/**
215215
* @brief Performs the final swap and erase operations during a secure update,
216216
* ensuring that if power is lost during the update, the process can be resumed
217-
* on next boot.
217+
* on next boot. Not supported with CUSTOM_PARTITION_TRAILER
218218
*
219219
* This function handles the final phase of the three-way swap update process.
220220
* It ensures that the update is atomic and power-fail safe by:
@@ -341,7 +341,7 @@ static int wolfBoot_swap_and_final_erase(int resume)
341341

342342
return 0;
343343
}
344-
#endif
344+
#endif /* !DISABLE_BACKUP && !CUSTOM_PARTITION_TRAILER */
345345

346346
#ifdef DELTA_UPDATES
347347

@@ -541,9 +541,10 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
541541
ext_flash_lock();
542542
#endif
543543
hal_flash_lock();
544+
545+
#if !defined(DISABLE_BACKUP) && !defined(CUSTOM_PARTITION_TRAILER)
544546
/* start re-entrant final erase, return code is only for resumption in
545547
* wolfBoot_start */
546-
#ifndef DISABLE_BACKUP
547548
if (ret == 0) {
548549
wolfBoot_swap_and_final_erase(0);
549550
}
@@ -817,9 +818,15 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed)
817818
ext_flash_lock();
818819
#endif
819820
hal_flash_lock();
821+
822+
#if !defined(CUSTOM_PARTITION_TRAILER)
820823
/* start re-entrant final erase, return code is only for resumption in
821-
* wolfBoot_start*/
824+
* wolfBoot_start */
822825
wolfBoot_swap_and_final_erase(0);
826+
#else
827+
/* Mark boot partition as TESTING - this tells bootloader to fallback if update fails */
828+
wolfBoot_set_partition_state(PART_BOOT, IMG_STATE_TESTING);
829+
#endif
823830

824831
#else /* DISABLE_BACKUP */
825832
#ifdef WOLFBOOT_ELF_FLASH_SCATTER
@@ -1033,7 +1040,7 @@ void RAMFUNCTION wolfBoot_start(void)
10331040
#endif
10341041
#endif
10351042

1036-
#if !defined(DISABLE_BACKUP)
1043+
#if !defined(DISABLE_BACKUP) && !defined(CUSTOM_PARTITION_TRAILER)
10371044
/* resume the final erase in case the power failed before it finished */
10381045
resumedFinalErase = wolfBoot_swap_and_final_erase(1);
10391046
if (resumedFinalErase != 0)

0 commit comments

Comments
 (0)