Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,18 @@ jobs:
arch: arm
config-file: ./config/examples/stm32h5-dualbank.config

stm32h5_dk_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/stm32h5-dk.config

stm32h5_dk_tz_test:
uses: ./.github/workflows/test-build.yml
with:
arch: arm
config-file: ./config/examples/stm32h5-dk-tz.config

stm32n6_test:
uses: ./.github/workflows/test-build.yml
with:
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ if(ARCH STREQUAL "ARM")

if(${WOLFBOOT_TARGET} STREQUAL "stm32h5")
set(ARCH_FLASH_OFFSET 0x08000000)
if(STM32H5_BOARD STREQUAL "h573i_dk")
list(APPEND WOLFBOOT_DEFS STM32H573I_DK)
endif()
if(TZEN)
set(WOLFBOOT_ORIGIN 0x0C000000)
else()
Expand Down
3 changes: 3 additions & 0 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ ifeq ($(ARCH),ARM)
$(call LSCRIPT_IN_DEFAULT,hal/$(TARGET)-ns.ld)
endif
SPI_TARGET=stm32
ifeq ($(STM32H5_BOARD),h573i_dk)
CFLAGS+=-DSTM32H573I_DK
endif
Comment thread
dgarske marked this conversation as resolved.
Resolved
ifneq ($(DEBUG),0)
CFLAGS+=-DPKCS11_SMALL
endif
Expand Down
36 changes: 36 additions & 0 deletions config/examples/stm32h5-dk-tz.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARCH?=ARM
TZEN?=1
STM32H5_BOARD?=h573i_dk
TARGET?=stm32h5
SIGN?=ECC256
HASH?=SHA256
DEBUG?=0
VTOR?=1
CORTEX_M0?=0
CORTEX_M33?=1
NO_ASM?=0
NO_MPU=1
EXT_FLASH?=0
SPI_FLASH?=0
ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=1
WOLFBOOT_VERSION?=1
V?=0
SPMATH?=1
RAM_CODE?=1
DUALBANK_SWAP?=0
WOLFBOOT_PARTITION_SIZE?=0xA0000
WOLFBOOT_SECTOR_SIZE?=0x2000
WOLFBOOT_KEYVAULT_ADDRESS?=0x0C040000
WOLFBOOT_KEYVAULT_SIZE?=0x1C000
WOLFBOOT_NSC_ADDRESS?=0x0C05C000
WOLFBOOT_NSC_SIZE?=0x4000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08060000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x0C100000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x0C1A0000
FLAGS_HOME=0
DISABLE_BACKUP=0
WOLFCRYPT_TZ=1
WOLFCRYPT_TZ_PKCS11=1
IMAGE_HEADER_SIZE?=1024
ARMORED=1
35 changes: 35 additions & 0 deletions config/examples/stm32h5-dk.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ARCH?=ARM
TZEN?=0
STM32H5_BOARD?=h573i_dk
TARGET?=stm32h5
SIGN?=ECC256
HASH?=SHA256
DEBUG?=0
VTOR?=1
CORTEX_M0?=0
CORTEX_M33?=1
NO_ASM?=0
NO_MPU=1
EXT_FLASH?=0
SPI_FLASH?=0
ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=1
WOLFBOOT_VERSION?=1
V?=0
SPMATH?=1
RAM_CODE?=0
DUALBANK_SWAP?=0
WOLFBOOT_PARTITION_SIZE?=0xA0000
#Double sector size to fit header in ML-DSA-87
WOLFBOOT_SECTOR_SIZE?=0x4000
WOLFBOOT_KEYVAULT_ADDRESS?=0x0C040000
WOLFBOOT_KEYVAULT_SIZE?=0x1C000
WOLFBOOT_NSC_ADDRESS?=0x0C05C000
WOLFBOOT_NSC_SIZE?=0x4000
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x08060000
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x08100000
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x081A0000
FLAGS_HOME=0
DISABLE_BACKUP=0
IMAGE_HEADER_SIZE?=1024
ARMORED=1
46 changes: 46 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,52 @@ Any version except the first one will also turn on the orange LED.
For a full Zephyr integration walkthrough (build + flash), see:
[/zephyr/README.md](/zephyr/README.md)

### STM32H573I-DK

The STM32H573I-DK Discovery kit is selected with `STM32H5_BOARD=h573i_dk`, which
builds wolfBoot and the test application with `-DSTM32H573I_DK`. Without this
option the NUCLEO-H563ZI settings are used.

Board settings:

- HSE is a 25 MHz digital clock (`HSEBYP` and `HSEEXT`); PLL1 uses M=5, N=100,
P=2 for a 250 MHz system clock.
- The console is USART1 on PA9 (TX) / PA10 (RX), 115200 8N1, routed to the
ST-LINK virtual COM port.
- LEDs are active low: PI8 (orange) is the boot LED, PI9 (green) the user LED
and PF4 (blue) the extra LED.
- With TrustZone enabled, wolfBoot releases USART1, its interrupt and ports
GPIOF/GPIOI to the non-secure domain before staging the application.

Example configurations:

- `config/examples/stm32h5-dk.config`: TrustZone disabled (`TZEN=0`), swap
update with the same partition layout as `stm32h5-no-tz.config`. Tested on
the STM32H573I-DK (boot, update, confirm and rollback).
- `config/examples/stm32h5-dk-tz.config`: TrustZone enabled, same layout as
`stm32h5-tz.config`, with the option bytes and flashing steps of Scenario 1
above. Tested on the STM32H573I-DK (boot, update, confirm and rollback).

```sh
cp config/examples/stm32h5-dk.config .config
make DEBUG_UART=1
STM32_Programmer_CLI -c port=swd -d factory.bin 0x08000000
```

To test an update, sign a new version, write it to the update partition and
set the update trigger at the end of the partition, then reset the board:

```sh
IMAGE_HEADER_SIZE=1024 WOLFBOOT_PARTITION_SIZE=0xA0000 WOLFBOOT_SECTOR_SIZE=0x4000 \
tools/keytools/sign --ecc256 --sha256 test-app/image.bin wolfboot_signing_private_key.der 2
printf 'pBOOT' > trigger_magic.bin
STM32_Programmer_CLI -c port=swd -d test-app/image_v2_signed.bin 0x08100000
STM32_Programmer_CLI -c port=swd -d trigger_magic.bin 0x0819FFFB -hardRst
```

The `success` command of the test application confirms the new version. An
update that is not confirmed is rolled back on the next reset.

### STM32H5 Debugging


Expand Down
51 changes: 49 additions & 2 deletions hal/stm32h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,16 +452,21 @@ static void clock_pll_off(void)
}

/* If PLL_SRC_HSE is set then HSE (8MHz) is used otherwise HSI 64 MHz is used
* and system clock is 250MHz */
* and system clock is 250MHz. The STM32H573I-DK HSE is 25MHz. */

static void clock_pll_on(void)
{
uint32_t reg32;
uint32_t plln, pllm, pllq, pllp, pllr, hpre, apb1pre, apb2pre, apb3pre, flash_waitstates;

#if PLL_SRC_HSE
#ifdef STM32H573I_DK
pllm = 5;
plln = 100;
#else
pllm = 1;
plln = 62;
#endif
pllp = 2; /* 250Mhz */
pllq = 5; /* 100Mhz */
pllr = 2;
Expand Down Expand Up @@ -494,6 +499,10 @@ static void clock_pll_on(void)

#if PLL_SRC_HSE
/* PLL Oscillator configuration */
#ifdef STM32H573I_DK
/* Digital clock on OSC_IN: select before turning HSE on */
RCC_CR |= RCC_CR_HSEBYP | RCC_CR_HSEEXT;
#endif
RCC_CR |= RCC_CR_HSEON | RCC_CR_HSEBYP;

/* Wait until HSE is Ready */
Expand Down Expand Up @@ -546,7 +555,11 @@ static void clock_pll_on(void)
DMB();

/* Select PLL1 Input frequency range: VCI */
#ifdef STM32H573I_DK
RCC_PLL1CFGR |= RCC_PLLCFGR_RGE_4_8 << RCC_PLLCFGR_PLLRGE_SHIFT;
#else
RCC_PLL1CFGR |= RCC_PLLCFGR_RGE_2_4 << RCC_PLLCFGR_PLLRGE_SHIFT;
#endif

/* Select PLL1 Output frequency range: VCO = 0 */
RCC_PLL1CFGR &= ~RCC_PLLCFGR_PLLVCOSEL;
Expand Down Expand Up @@ -599,6 +612,7 @@ static void clock_pll_on(void)
#define NVIC_ICER_BASE (0xE000E180)
#define NVIC_IPRI_BASE (0xE000E400)
#define NVIC_USART3_IRQ 60
#define NVIC_USART1_IRQ 58

/* Cortex M-33 has an extra register to set up non-secure interrupts */
#define NVIC_ITNS_BASE (0xE000E380)
Expand All @@ -621,17 +635,23 @@ static void periph_unsecure(void)
RCC_AHB2_CLOCK_ER |= GPIOD_AHB2_CLOCK_ER;

/* Enable clock for LPUART1 */
RCC_APB2_CLOCK_ER |= UART1_APB2_CLOCK_ER_VAL;
RCC_APB3_CLOCK_ER |= UART1_APB3_CLOCK_ER_VAL;

/* Enable clock for USART3 */
RCC_APB1L_CLOCK_ER |= UART3_APB1L_CLOCK_ER_VAL;


PWR_CR2 |= PWR_CR2_IOSV;
/* Un-secure User LED GPIO pins */
#ifdef STM32H573I_DK
GPIO_SECCFGR(GPIOI_BASE) &= ~(1 << LED_BOOT_PIN); /* PI8 - Discovery board - Orange Led */
GPIO_SECCFGR(GPIOI_BASE) &= ~(1 << LED_USR_PIN); /* PI9 - Discovery board - Green Led */
GPIO_SECCFGR(GPIOF_BASE) &= ~(1 << LED_EXTRA_PIN); /* PF4 - Discovery board - Blue Led */
#else
GPIO_SECCFGR(GPIOG_BASE) &= ~(1 << LED_BOOT_PIN); /* PG4 - Nucleo board - Orange Led */
GPIO_SECCFGR(GPIOB_BASE) &= ~(1 << LED_USR_PIN); /* PB0 - Nucleo board - Green Led */
GPIO_SECCFGR(GPIOF_BASE) &= ~(1 << LED_EXTRA_PIN); /* PF4 - Nucleo board - Blue Led */
#endif

/* Unsecure LPUART1 */
GPIO_SECCFGR(GPIOB_BASE) &= ~(1<<UART1_TX_PIN);
Expand All @@ -658,6 +678,25 @@ static void periph_unsecure(void)
nvic_itns = ((volatile uint32_t *)(NVIC_ITNS_BASE + 4 * nvic_reg_pos));
*nvic_itns |= (1 << nvic_reg_off);

#ifdef STM32H573I_DK
/* Unsecure USART1 */
RCC_APB2_CLOCK_ER |= USART1_APB2_CLOCK_ER_VAL;
GPIO_SECCFGR(GPIOA_BASE) &= ~(1<<USART1_TX_PIN);
GPIO_SECCFGR(GPIOA_BASE) &= ~(1<<USART1_RX_PIN);
reg = TZSC_SECCFGR2;
if (reg & TZSC_SECCFGR2_USART1SEC) {
reg &= (~TZSC_SECCFGR2_USART1SEC);
DMB();
TZSC_SECCFGR2 = reg;
}

/* Set USART1 interrupt as non-secure */
nvic_reg_pos = NVIC_USART1_IRQ / 32;
nvic_reg_off = NVIC_USART1_IRQ % 32;
nvic_itns = ((volatile uint32_t *)(NVIC_ITNS_BASE + 4 * nvic_reg_pos));
*nvic_itns |= (1 << nvic_reg_off);
#endif

/* H5 product state with TZEN=1 defaults every GPIO pin to secure
* via GPIOx_SECCFGR (offset 0x30 in each GPIO block, all 16 bits
* = 0xFFFF at reset). Until those bits are cleared, NS code can't
Expand All @@ -674,6 +713,10 @@ static void periph_unsecure(void)
GPIO_SECCFGR(GPIOD_BASE) = 0u;
GPIO_SECCFGR(GPIOG_BASE) = 0u;
RCC_AHB2_CLOCK_ER |= GPIOG_AHB2_CLOCK_ER;
#ifdef STM32H573I_DK
GPIO_SECCFGR(GPIOF_BASE) = 0u;
GPIO_SECCFGR(GPIOI_BASE) = 0u;
#endif
}
#endif /* TZ_SECURE() */

Expand Down Expand Up @@ -795,6 +838,10 @@ void hal_prepare_boot(void)
#endif
#else
#ifdef WOLFBOOT_RESTORE_CLOCK
#ifdef DEBUG_UART
while ((UART_ISR(USE_UART) & UART_ISR_TC) == 0)
;
#endif
clock_pll_off();
#endif
#endif
Expand Down
Loading
Loading