Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Cross-boundary flash writes can silently leave data unwritten while returning success, and make config drops the 4 MB flash setting, causing partition-layout checks to fail.
2 open issues
What changed in this PR
Adds 4 MB STM32U5 support and enables TrustZone with hardware bank swapping in wolfBoot.
Changes:
- Makes flash geometry configurable and validates dual-bank layouts.
- Updates secure flash routing, bootloader copying, and TrustZone mappings.
- Adds example configurations, routing tests, documentation, and CI builds.
| File | Description |
|---|---|
| tools/unit-tests/unit-stm32u5-tz-dualbank.c | Tests flash routing for both device sizes. |
| tools/unit-tests/Makefile | Builds the new routing tests. |
| hal/stm32u5.h | Defines configurable flash geometry and copy size. |
| hal/stm32u5.c | Updates routing, layout checks, and bootloader copying. |
| hal/stm32_tz.c | Handles U5 swap state and UPDATE mapping. |
| docs/Targets.md | Documents 4 MB devices and TrustZone bank swapping. |
| config/examples/stm32u5a5-tz-dualbank.config | Adds a TrustZone dual-bank example. |
| config/examples/stm32u5a5-nonsecure-dualbank.config | Adds a non-secure dual-bank example. |
| arch.mk | Passes flash-size configuration to compilation. |
| .gitignore | Excludes generated test artifacts. |
| .github/workflows/test-configs.yml | Adds builds for both examples. |
| .github/workflows/test-build.yml | Includes both examples in STM32 build setup. |
Review effort: Balanced
dgarske
force-pushed
the
stm32u5_tz_dualbank
branch
from
December 2, 2026 21:30
b2070fd to
b199ecb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Adds support for the 4 MB STM32U5 parts (STM32U59x/U5Ax/U5Fx/U5Gx) and makes
TZEN=1withDUALBANK_SWAP=1build and work on STM32U5.1. 4 MB devices
The HAL assumed the 2 MB geometry of the U575/U585, with bank 2 at
0x08100000. On a 4 MB part bank 2 is at0x08200000, so the dual-bank copy of the bootloader and every bank 2 erase or write went to the wrong address.STM32U5_FLASH_SIZE_MB(default 2) now sets the bank 2 base, the flash top and the number of block-based security registers.2. TrustZone with dual-bank
hal_tz_release_nonsecure_area()read the swap state fromFLASH_OPTSR_CUR, which only exists on STM32H5, so this combination did not compile. On STM32U5 it now readsFLASH_OPTR, and the claim path takes the swap into account the same way.hal_flash_write()andhal_flash_erase()treated all of bank 1 as secure and all of bank 2 as non-secure. Both banks have the same layout, so the flash interface is now chosen from the offset inside the bank, and an erase that crosses from one interface to the other clears the page-erase bit on the one it leaves.fork_bootloader()copied a fixed 32 KB, less than the TrustZone secure area and, in the non-TrustZone configurations, less than the space reserved below BOOT. It now copies everything below the BOOT partition one page at a time, skipping pages that already match.The build now stops with an error when
STM32U5_FLASH_SIZE_MBis not 2 or 4, when the BOOT and UPDATE partitions are not at the same offset in their banks, do not start on a page boundary or do not fit in them, and whenWOLFCRYPT_TZis combined with this layout. On STM32L5 TrustZone withDUALBANK_SWAPis still not supported, now with an explicit error.Adds a host unit test for the secure and non-secure flash routing (4 MB and 2 MB layouts),
stm32u5a5-nonsecure-dualbank.configandstm32u5a5-tz-dualbank.config, a "4 MB devices" subsection and a TrustZone dual-bank scenario indocs/Targets.md, and build jobs for both configurations.wolfboot.binfor the existing STM32L5, STM32H5 and non-dual-bank STM32U5 configurations is byte-identical before and after.Hardware / test status
Validated on a NUCLEO-U5A5ZJ-Q with both new configurations, TrustZone off and on: first boot, the bootloader copy to bank 2, update with bank swap, rejection and erase of an invalid update image, and a further update with the banks swapped. The STM32U5 emulator tests, including the dual-bank fallback test on a 2 MB part, pass. The same four cases pass with TrustZone on a 2 MB B-U585I-IOT02A.
Scope
WOLFCRYPT_TZis rejected with dual-bank because the keyvault in the secure area is only mirrored to bank 2 while the banks are not swapped. The secure watermarks must be the same for both banks; they are not rewritten on a swap.