Skip to content

Commit cc80965

Browse files
authored
Merge pull request #619 from mattia-moffa/20251030-h5-dualbank
Fix STM32H5 dualbank update
2 parents c6776bc + f453a68 commit cc80965

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

.github/workflows/test-configs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ jobs:
320320
arch: arm
321321
config-file: ./config/examples/stm32h5-tz.config
322322

323+
stm32h5_tz_dualbank_test:
324+
uses: ./.github/workflows/test-build.yml
325+
with:
326+
arch: arm
327+
config-file: ./config/examples/stm32h5-tz-dualbank.config
328+
323329
stm32h5_tz_dualbank_otp_test:
324330
uses: ./.github/workflows/test-build.yml
325331
with:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARCH?=ARM
2+
TZEN?=1
3+
TARGET?=stm32h5
4+
SIGN?=ECC256
5+
HASH?=SHA256
6+
DEBUG?=0
7+
VTOR?=1
8+
CORTEX_M0?=0
9+
CORTEX_M33?=1
10+
NO_ASM?=0
11+
NO_MPU=1
12+
EXT_FLASH?=0
13+
SPI_FLASH?=0
14+
ALLOW_DOWNGRADE?=0
15+
NVM_FLASH_WRITEONCE?=1
16+
WOLFBOOT_VERSION?=1
17+
V?=0
18+
SPMATH?=1
19+
RAM_CODE?=1
20+
DUALBANK_SWAP?=1
21+
WOLFBOOT_PARTITION_SIZE?=0xA0000
22+
WOLFBOOT_SECTOR_SIZE?=0x2000
23+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08060000
24+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x0C160000
25+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xFFFFFFFF
26+
FLAGS_HOME=0
27+
DISABLE_BACKUP=0
28+
WOLFCRYPT_TZ=1
29+
WOLFCRYPT_TZ_PKCS11=1
30+
ARMORED=1
31+
IMAGE_HEADER_SIZE?=1024

hal/stm32h5.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,30 @@ static void RAMFUNCTION stm32h5_reboot(void)
510510
void RAMFUNCTION hal_flash_dualbank_swap(void)
511511
{
512512
uint32_t cur_opts;
513+
#ifdef WOLFCRYPT_SECURE_MODE
514+
uint8_t wolfboot_final_sector =
515+
(WOLFBOOT_PARTITION_BOOT_ADDRESS - FLASHMEM_ADDRESS_SPACE) / WOLFBOOT_SECTOR_SIZE - 1;
516+
uint8_t partition_final_sector =
517+
wolfboot_final_sector + (WOLFBOOT_PARTITION_SIZE / WOLFBOOT_SECTOR_SIZE);
518+
#endif
513519
cur_opts = (FLASH_OPTSR_CUR & FLASH_OPTSR_SWAP_BANK) >> 31;
514520
hal_flash_clear_errors(0);
515521
hal_flash_unlock();
516522
hal_flash_opt_unlock();
517-
if (cur_opts)
523+
if (cur_opts) {
518524
FLASH_OPTSR_PRG &= ~(FLASH_OPTSR_SWAP_BANK);
519-
else
525+
#ifdef WOLFCRYPT_SECURE_MODE
526+
FLASH_SECWM1R_PRG = wolfboot_final_sector << FLASH_SECWM_END_SHIFT;
527+
FLASH_SECWM2R_PRG = partition_final_sector << FLASH_SECWM_END_SHIFT;
528+
#endif
529+
}
530+
else {
520531
FLASH_OPTSR_PRG |= FLASH_OPTSR_SWAP_BANK;
532+
#ifdef WOLFCRYPT_SECURE_MODE
533+
FLASH_SECWM1R_PRG = partition_final_sector << FLASH_SECWM_END_SHIFT;
534+
FLASH_SECWM2R_PRG = wolfboot_final_sector << FLASH_SECWM_END_SHIFT;
535+
#endif
536+
}
521537

522538
FLASH_OPTCR |= FLASH_OPTCR_OPTSTRT;
523539
DMB();

hal/stm32h5.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@
212212
#define FLASH_SECBB2 ((volatile uint32_t *)(FLASH_BASE + 0x1A0)) /* Array */
213213
#define FLASH_SECBB_NREGS 4 /* Array length for the two above */
214214

215+
#define FLASH_SECWM1R_CUR (*(volatile uint32_t *)(FLASH_BASE + 0x0E0))
216+
#define FLASH_SECWM1R_PRG (*(volatile uint32_t *)(FLASH_BASE + 0x0E4))
217+
#define FLASH_SECWM2R_CUR (*(volatile uint32_t *)(FLASH_BASE + 0x1E0))
218+
#define FLASH_SECWM2R_PRG (*(volatile uint32_t *)(FLASH_BASE + 0x1E4))
219+
220+
#define FLASH_SECWM_STRT_SHIFT 0
221+
#define FLASH_SECWM_END_SHIFT 16
222+
215223
#define FLASH_NS_BASE (0x40022000) //RM0481 - Table 3
216224
#define FLASH_NS_KEYR (*(volatile uint32_t *)(FLASH_NS_BASE + 0x08))
217225
#define FLASH_NS_OPTKEYR (*(volatile uint32_t *)(FLASH_NS_BASE + 0x0C))

test-app/app_stm32h5.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ static int cmd_update_xmodem(const char *args)
373373
if (dst_offset >= t_size) {
374374
eot_expected = 1;
375375
}
376-
/*uart_tx(XACK);*/
377376
} else {
378377
uart_tx(XNAK);
379378
}

0 commit comments

Comments
 (0)