Skip to content

Commit df4dd3d

Browse files
committed
Fixed size for memcmp/copy used in fork_bootloader
1 parent 4a57fd2 commit df4dd3d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

hal/stm32h5.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ void RAMFUNCTION hal_flash_dualbank_swap(void)
376376
stm32h5_reboot();
377377
}
378378

379-
static uint8_t bootloader_copy_mem[BOOTLOADER_SIZE];
379+
380+
#define BOOTLOADER_COPY_MEM_SIZE 0x1000
381+
static uint8_t bootloader_copy_mem[BOOTLOADER_COPY_MEM_SIZE];
380382

381383
static void fork_bootloader(void)
382384
{
@@ -395,13 +397,17 @@ static void fork_bootloader(void)
395397
if (memcmp((void *)data, (const char*)dst, BOOTLOADER_SIZE) == 0)
396398
return;
397399

398-
/* Read the wolfBoot image in RAM */
399-
memcpy(bootloader_copy_mem, (void*)data, BOOTLOADER_SIZE);
400-
401-
/* Mass-erase */
402400
hal_flash_unlock();
401+
/* Mass-erase second block */
403402
hal_flash_erase(dst, BOOTLOADER_SIZE);
404-
hal_flash_write(dst, bootloader_copy_mem, BOOTLOADER_SIZE);
403+
/* Read the wolfBoot image in RAM */
404+
for (i = 0; i < BOOTLOADER_SIZE;
405+
i += BOOTLOADER_COPY_MEM_SIZE) {
406+
memcpy(bootloader_copy_mem, (void*)(data + i),
407+
BOOTLOADER_COPY_MEM_SIZE);
408+
hal_flash_write(dst + i, bootloader_copy_mem,
409+
BOOTLOADER_COPY_MEM_SIZE);
410+
}
405411
hal_flash_lock();
406412
}
407413
#endif

hal/stm32h5.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
#define FLASHMEM_ADDRESS_SPACE (0x08000000)
327327
#define FLASH_PAGE_SIZE (0x2000) /* 8KB */
328328
#define FLASH_BANK2_BASE (0x08100000) /*!< Base address of Flash Bank2 */
329-
#define BOOTLOADER_SIZE (0x8000)
329+
#define BOOTLOADER_SIZE (WOLFBOOT_PARTITION_BOOT_ADDRESS - FLASHMEM_ADDRESS_SPACE)
330330
#define FLASH_TOP (0x081FFFFF) /*!< FLASH end address (sector 127) */
331331

332332
#define FLASH_KEY1 (0x45670123U)

0 commit comments

Comments
 (0)