Skip to content
Draft
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
36 changes: 36 additions & 0 deletions .github/workflows/test-configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,34 @@ 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

stm32h5_dk_pka_hash_test:
uses: ./.github/workflows/test-build-stm32cube.yml
with:
arch: arm
config-file: ./config/examples/stm32h5-dk.config
cube-repo: STMicroelectronics/STM32CubeH5
make-args: PKA=1 STM32_HASH=1 BOOT_BENCHMARK=1 STM32CUBE_H5=$GITHUB_WORKSPACE/STM32Cube

stm32h5_tz_pka_test:
uses: ./.github/workflows/test-build-stm32cube.yml
with:
arch: arm
config-file: ./config/examples/stm32h5-tz.config
cube-repo: STMicroelectronics/STM32CubeH5
make-args: PKA=1 STM32CUBE_H5=$GITHUB_WORKSPACE/STM32Cube

stm32n6_test:
uses: ./.github/workflows/test-build.yml
with:
Expand Down Expand Up @@ -1487,6 +1515,14 @@ jobs:
arch: arm
config-file: ./config/examples/stm32u5.config

stm32u5_pka_hash_test:
uses: ./.github/workflows/test-build-stm32cube.yml
with:
arch: arm
config-file: ./config/examples/stm32u5.config
cube-repo: STMicroelectronics/STM32CubeU5
make-args: PKA=1 STM32_HASH=1 BOOT_BENCHMARK=1 STM32CUBE_U5=$GITHUB_WORKSPACE/STM32Cube

stm32u5_wolfcrypt_tz:
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
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
89 changes: 89 additions & 0 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ mon reset init

The STM32U5 is a Cortex-M33 (ARMv8-M).

For PKA signature verification and HASH image digests see
[STM32H5/U5 hardware crypto](#stm32h5u5-hardware-crypto-pka-hash).

Note: We have seen issues with vector table alignment, so the default image header size (IMAGE_HEADER_SIZE) has been increased to 1024 bytes to avoid potential issues.

### Scenario 1: TrustZone enabled, staging non-secure application
Expand Down Expand Up @@ -1477,6 +1480,92 @@ 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/U5 hardware crypto (PKA, HASH)

`PKA=1` verifies the ECDSA signature on the PKA peripheral and `STM32_HASH=1`
computes the SHA-256 image digest on the HASH peripheral, both through
wolfCrypt's register-level STM32 port (`WOLFSSL_STM32_BARE`). The port needs
only the CMSIS device headers of an STM32Cube firmware package: the newest
`STM32Cube_FW_H5_V*` or `STM32Cube_FW_U5_V*` under `~/STM32Cube/Repository`
is used unless `STM32CUBE_H5` or `STM32CUBE_U5` is set. `STM32_DEVICE` selects
the device header: `STM32H563xx` by default, `STM32H573xx` with
`STM32H5_BOARD=h573i_dk`, and `STM32U585xx` on the STM32U5.

```sh
cp config/examples/stm32h5-dk.config .config
make PKA=1 STM32_HASH=1
```

- The STM32H563 PKA can only verify, which is all wolfBoot needs.
- With `PKA=1`, `hal_init()` starts HSI48: PKA initialization needs the RNG
kernel clock.
- With `STM32_HASH=1` the image is hashed in 4 KB blocks
(`STM32_HASH_BLOCK_SIZE`), because the HASH engine saves and restores its
context on every update. `WOLFBOOT_IMG_HASH_ONESHOT=1` hashes the image in
one update.
- `STM32_HASH=1` changes the layout of the wolfCrypt hash context and is not
supported with `WOLFTPM`, SPI/QSPI/OCTOSPI flash, `WOLFCRYPT_TZ_PSA`,
`WOLFCRYPT_TZ_WOLFHSM` or `WOLFCRYPT_TZ_FWTPM`. `PKA=1` works with all of
them.

Integrity check plus signature verification time, ECC256 with SHA-256,
measured with `BOOT_BENCHMARK=1` (DWT cycle counter) over 10 boots:

| Board (config) | SYSCLK | Image | Software | `PKA=1` | `PKA=1 STM32_HASH=1` |
|---|---|---|---|---|---|
| STM32H573I-DK (`stm32h5-dk`) | 250 MHz | 256 KB | 131 + 20 ms | 131 + 12 ms | 38 + 12 ms |
| NUCLEO-H563ZI (`stm32h5-tz`) | 248 MHz | 263 KB | 159 + 17 ms | 147 + 12 ms | 17 + 12 ms |
| B-U585I-IOT02A (`stm32u5-nonsecure-dualbank`) | 160 MHz | 128 KB | 56 + 19 ms | 56 + 19 ms | 27 + 19 ms |

`PKA=1` also removes the software ECC code: wolfBoot for `stm32h5-dk` is 30 KB
with software crypto, 21 KB with `PKA=1` and 17 KB with both options.

### STM32H5 Debugging


Expand Down
38 changes: 38 additions & 0 deletions hal/stm32_hwcrypto.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* stm32_hwcrypto.h
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

/* Force-included (-include) into the HAL objects by options.mk with
* STM32_HASH=1 on STM32H5/U5. wolfCrypt's STM32 port includes the CMSIS
* device header, whose register macros clash with the ones in hal/stm32h5.h
* and hal/stm32u5.h. The HAL sources do not use the port, so hide it from
* them. */

#ifndef STM32_HWCRYPTO_H
#define STM32_HWCRYPTO_H

#ifdef WOLFSSL_STM32_BARE
#undef WOLFSSL_STM32_BARE
#undef WOLFSSL_STM32H5
#undef WOLFSSL_STM32U5
#undef WOLFSSL_STM32_PKA
#endif

#endif /* STM32_HWCRYPTO_H */
Loading
Loading