Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unvalidated flash ranges can expose adjacent memory or remove protection from update and swap areas, while STM32L5 provisioning rejects valid addresses and configuration regeneration drops both settings.
4 open issues
What changed in this PR
Adds an optional non-secure flash data window to wolfBoot’s STM32 TrustZone support, allowing applications to access persistent data outside firmware partitions.
Changes:
- Adds configurable SAU region 5 for STM32L5/U5/H5, excluding secure-app builds.
- Exposes settings through Make and CMake and adjusts H5 watermark provisioning.
- Documents data placement and security requirements.
| File | Description |
|---|---|
| tools/scripts/set-stm32-tz-option-bytes.sh | Adjusts the bank-2 watermark before the data area. |
| options.mk | Adds TrustZone data-window compiler definitions. |
| hal/stm32_tz.c | Configures the optional non-secure SAU window. |
| docs/Targets.md | Links to data-window configuration guidance. |
| docs/STM32-TZ.md | Documents settings, placement, and watermark requirements. |
| CMakeLists.txt | Adds equivalent CMake configuration support. |
Review effort: Balanced
dgarske
force-pushed
the
stm32_tz_ns_data
branch
from
December 2, 2026 21:16
173f29b to
8a6c433
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
UPDATE boundary checks incorrectly use the BOOT size, allowing layouts where update erasure destroys application data and provisioning leaves part of UPDATE unprotected.
3 open issues
4 resolved since last review
Review effort: Balanced
dgarske
force-pushed
the
stm32_tz_ns_data
branch
from
December 2, 2026 23:45
8a6c433 to
6a64299
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.


On STM32L5, STM32U5 and STM32H5 with TrustZone enabled, wolfBoot opens SAU windows for the boot partition, the non-secure RAM, the peripherals and the NSC area, and nothing else. A non-secure application that keeps data in flash outside the partitions (device credentials, settings, a key blob) cannot reach it: the access raises a SecureFault even when the option bytes already leave those pages non-secure.
What it adds
hal/stm32_tz.c-WOLFBOOT_NS_DATA_ADDRESSandWOLFBOOT_NS_DATA_SIZEadd SAU region 5 over that area inhal_tz_sau_initon all three targets, in the non-secure alias whichever alias the address is given in. Nothing changes when the two are not defined, and aWOLFBOOT_SECURE_APPbuild, which has no non-secure side, gets no window. The build stops when the area isn't a non-zero multiple of 32 bytes (the SAU granularity), lies below the boot partition, or overlaps the boot, update (at its own size) or swap partition.options.mk,CMakeLists.txt,tools/config.mk- the two.config(or CMake) variables become the defines underTZEN=1and survivemake config; an address without a size is an error.tools/scripts/set-stm32-tz-option-bytes.sh- on STM32H5 the bank 2 watermark (SECWM2_END) stops at the sector before the data area, which must start on a sector boundary above the update and swap partitions and end inside bank 2; on L5 and U5 bank 2 is already non-secure and the script leaves it alone.docs/STM32-TZ.md,docs/Targets.md- the two options, the placement rules, the watermark requirement and the H5 example values.Hardware / test status
Validated on a NUCLEO-H563ZI (
stm32h5.configwith the area at 0x081A2000, 0x6000 bytes,SECWM2_END0x50): the non-secure application reads its device key and credential from the area after a reset, programs it through the non-secure flash registers, and completes a network onboarding that depends on them. That run used this change on an earlier master. On current master it builds with and without the options forstm32h5-tz,stm32h5-tz-wolftrust,stm32l5-wolfcrypt-tz,stm32l5-tz-wolftrustandstm32u5-wolfcrypt-tz. Each placement check stops a build that violates it, and the option-bytes script, run against a stub programmer, gives the expected watermarks and refusals. Not run on L5 or U5 hardware.Scope
The pages must be non-secure in the SECWM option bytes; wolfBoot does not change the watermarks at run time and this PR keeps it that way. Region 5 leaves region 4 to the STM32U5 dual-bank update window in #1021, so the two PRs do not overlap.