Repository navigation
Conversation
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
173f29b to
8a6c433
Compare
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
8a6c433 to
6a64299
Compare
aidangarske
left a comment
There was a problem hiding this comment.
Skoll Code Review
Scan type: review
Overall recommendation: REQUEST_CHANGES
Findings: 3 total — 3 posted, 0 skipped
3 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [High] SAU data window is not constrained to physical flash —
hal/stm32_tz.c:359-365 - [Medium] New SAU validation and alias mapping lack automated tests —
hal/stm32_tz.c:343-390 - [Medium] H5 watermark calculations have only manual coverage —
tools/scripts/set-stm32-tz-option-bytes.sh:49-75
Review generated by Skoll
6a64299 to
61822c9
Compare
61822c9 to
5754efc
Compare


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 outside internal flash, or overlaps the boot, update (at its own size) or swap partition, and aPULL_LINKER_DEFINESbuild, whose partition addresses the checks cannot see, cannot use the window.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. Its.configreads use the field separator[?]=|:=|=, which mawk and busybox awk accept as well as gawk.docs/STM32-TZ.md,docs/Targets.md- the two options, the placement rules, the erase-page advice for a rewritten area, the watermark requirement and the H5 example values.tools/unit-tests/unit-stm32-tz-nsdata.c,test-stm32-tz-nsdata-config.sh,tools/scripts/test-set-stm32-tz-option-bytes.sh- region 5 with the address in either alias, without the options and for a secure application; every placement rule refusing a bad layout and accepting a good one; the option-bytes script against a stub programmer.make -C tools/unit-tests runruns all three.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. 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.