Repository navigation
Add a non-secure data flash window to the STM32 TrustZone HAL #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dgarske
wants to merge
1
commit into
wolfSSL:master
Choose a base branch
from
dgarske:stm32_tz_ns_data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #!/bin/bash | ||
|
|
||
| # test-set-stm32-tz-option-bytes.sh | ||
| # | ||
| # Runs set-stm32-tz-option-bytes.sh against a stub STM32_Programmer_CLI and | ||
| # checks the STM32H5 bank 2 watermark (SECWM2_END) it would program for the | ||
| # non-secure data window (WOLFBOOT_NS_DATA_ADDRESS, WOLFBOOT_NS_DATA_SIZE), | ||
| # and that the layouts it must refuse are refused. | ||
| # | ||
| # 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, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| set -eu | ||
|
|
||
| SCRIPT="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)/set-stm32-tz-option-bytes.sh" | ||
| WORK="$(mktemp -d)" | ||
| trap 'rm -rf "$WORK"' EXIT | ||
|
|
||
| mkdir -p "$WORK/bin" | ||
| cat > "$WORK/bin/STM32_Programmer_CLI" <<'EOF' | ||
| #!/bin/sh | ||
| echo "$@" > "$STUB_ARGS" | ||
| EOF | ||
| chmod +x "$WORK/bin/STM32_Programmer_CLI" | ||
| export PATH="$WORK/bin:$PATH" | ||
| export STUB_ARGS="$WORK/args" | ||
|
|
||
| # stm32h5-tz.config, partitions in the secure alias | ||
| BASE="TARGET=stm32h5 TZEN=1 WOLFBOOT_SECTOR_SIZE=0x2000 | ||
| WOLFBOOT_PARTITION_SIZE=0xA0000 WOLFBOOT_PARTITION_BOOT_ADDRESS=0x08060000 | ||
| WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x0C100000 | ||
| WOLFBOOT_PARTITION_SWAP_ADDRESS=0x0C1A0000" | ||
|
|
||
| # .config from BASE with the KEY=VALUE arguments replacing or adding keys | ||
| write_config() | ||
| { | ||
| local kv key | ||
| : > "$WORK/.config" | ||
| for kv in $BASE "$@"; do | ||
| key="${kv%%=*}" | ||
| grep -v "^$key=" "$WORK/.config" > "$WORK/.config.tmp" || true | ||
| mv "$WORK/.config.tmp" "$WORK/.config" | ||
| echo "$kv" >> "$WORK/.config" | ||
| done | ||
| } | ||
|
|
||
| run_script() | ||
| { | ||
| rm -f "$STUB_ARGS" | ||
| (cd "$WORK" && echo y | bash "$SCRIPT") > "$WORK/out" 2>&1 | ||
| } | ||
|
|
||
| expect_secwm2_end() | ||
| { | ||
| local expected="$1" actual | ||
| shift | ||
| write_config "$@" | ||
| if ! run_script; then | ||
| echo "refused, expected SECWM2_END=$expected: $*" >&2 | ||
| cat "$WORK/out" >&2 | ||
| exit 1 | ||
| fi | ||
| actual="$(grep -o 'SECWM2_END=0x[0-9a-f]*' "$STUB_ARGS" || true)" | ||
| if [ "$actual" != "SECWM2_END=$expected" ]; then | ||
| echo "expected SECWM2_END=$expected, got '$actual': $*" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| expect_refused() | ||
| { | ||
| local expected="$1" | ||
| shift | ||
| write_config "$@" | ||
| if run_script; then | ||
| echo "accepted, expected a refusal: $*" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ -f "$STUB_ARGS" ]; then | ||
| echo "programmer called for a refused layout: $*" >&2 | ||
| exit 1 | ||
| fi | ||
| if ! grep -Fq "$expected" "$WORK/out"; then | ||
| echo "expected '$expected': $*" >&2 | ||
| cat "$WORK/out" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # no window: bank 2 secure to its last sector | ||
| expect_secwm2_end 0x7f | ||
| # the window at 0x081A2000 leaves sectors 0x51 up non-secure, in either alias | ||
| expect_secwm2_end 0x50 WOLFBOOT_NS_DATA_ADDRESS=0x081A2000 \ | ||
| WOLFBOOT_NS_DATA_SIZE=0x6000 | ||
| expect_secwm2_end 0x50 WOLFBOOT_NS_DATA_ADDRESS=0x0C1A2000 \ | ||
| WOLFBOOT_NS_DATA_SIZE=0x6000 | ||
| # an update partition larger than the boot partition moves the window up | ||
| expect_secwm2_end 0x5f WOLFBOOT_PARTITION_SIZE=0x80000 \ | ||
| WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x08100000 \ | ||
| WOLFBOOT_PARTITION_UPDATE_SIZE=0xC0000 \ | ||
| WOLFBOOT_PARTITION_SWAP_ADDRESS=0x080E0000 \ | ||
| WOLFBOOT_NS_DATA_ADDRESS=0x081C0000 WOLFBOOT_NS_DATA_SIZE=0x6000 | ||
|
|
||
| expect_refused "inside flash bank 2" WOLFBOOT_NS_DATA_ADDRESS=0x081A2000 | ||
| expect_refused "inside flash bank 2" WOLFBOOT_NS_DATA_ADDRESS=0x081FE000 \ | ||
| WOLFBOOT_NS_DATA_SIZE=0x4000 | ||
| expect_refused "inside flash bank 2" WOLFBOOT_NS_DATA_ADDRESS=0x080F0000 \ | ||
| WOLFBOOT_NS_DATA_SIZE=0x2000 | ||
| expect_refused "sector boundary" WOLFBOOT_NS_DATA_ADDRESS=0x081A2020 \ | ||
| WOLFBOOT_NS_DATA_SIZE=0x6000 | ||
| expect_refused "above the update and swap" \ | ||
| WOLFBOOT_NS_DATA_ADDRESS=0x08190000 WOLFBOOT_NS_DATA_SIZE=0x2000 | ||
| expect_refused "above the update and swap" \ | ||
| WOLFBOOT_NS_DATA_ADDRESS=0x081A0000 WOLFBOOT_NS_DATA_SIZE=0x2000 | ||
| expect_refused "above the update and swap" WOLFBOOT_PARTITION_SIZE=0x80000 \ | ||
| WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x08100000 \ | ||
| WOLFBOOT_PARTITION_UPDATE_SIZE=0xC0000 \ | ||
| WOLFBOOT_PARTITION_SWAP_ADDRESS=0x080E0000 \ | ||
| WOLFBOOT_NS_DATA_ADDRESS=0x081A2000 WOLFBOOT_NS_DATA_SIZE=0x6000 | ||
|
|
||
| echo "set-stm32-tz-option-bytes.sh STM32H5 data window: ok" |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.