Skip to content

Commit 9caa201

Browse files
committed
Phase 4: docs/wolfHSM.md TZ section + CI lane for stm32h5-tz-wolfhsm
- docs/wolfHSM.md: append a STM32H5 TrustZone Engine section alongside the simulator section. Covers build (incl. WOLFBOOT_TZ_TEST_NO_BKPT for hardware), flashing via set-stm32-tz-option-bytes.sh + STM32_Programmer_CLI, expected UART output for both boots, and notes the H5 quad-word ECC handling shared with psa_store / pkcs11_store. Existing client/server content untouched. - .github/workflows/trustzone-emulator-tests.yml: add a wolfHSM step that mirrors the PKCS11 first/second-boot pattern -- one m33mu --persist run with --expect-bkpt 0x7d after the first boot path, committing key to NVM message, then a second --persist run with --expect-bkpt 0x7f after the restored persisted key message.
1 parent 0902d9a commit 9caa201

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

.github/workflows/trustzone-emulator-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,52 @@ jobs:
119119
grep -q "\\[BKPT\\] imm=0x7f" /tmp/m33mu-fwtpm.log
120120
grep -q "\\[EXPECT BKPT\\] Success" /tmp/m33mu-fwtpm.log
121121
122+
- name: Clean and build test with wolfHSM (stm32h5)
123+
run: |
124+
make clean distclean
125+
cp config/examples/stm32h5-tz-wolfhsm.config .config
126+
make
127+
128+
- name: Prepare wolfHSM persistence directory
129+
run: |
130+
rm -rf /tmp/m33mu-wolfhsm-persist
131+
mkdir -p /tmp/m33mu-wolfhsm-persist
132+
rm -f /tmp/m33mu-wolfhsm-first.log /tmp/m33mu-wolfhsm-second.log
133+
134+
- name: Run wolfHSM first boot (stm32h5)
135+
run: |
136+
cd /tmp/m33mu-wolfhsm-persist
137+
m33mu "$GITHUB_WORKSPACE/wolfboot.bin" \
138+
"$GITHUB_WORKSPACE/test-app/image_v1_signed.bin:0x60000" \
139+
--persist --uart-stdout --timeout 120 --expect-bkpt 0x7d \
140+
| tee /tmp/m33mu-wolfhsm-first.log
141+
142+
- name: Verify wolfHSM first boot (stm32h5)
143+
run: |
144+
grep -q "wolfHSM CommInit ok" /tmp/m33mu-wolfhsm-first.log
145+
grep -q "wolfHSM RNG ok:" /tmp/m33mu-wolfhsm-first.log
146+
grep -q "wolfHSM SHA256 ok" /tmp/m33mu-wolfhsm-first.log
147+
grep -q "wolfHSM AES ok" /tmp/m33mu-wolfhsm-first.log
148+
grep -q "wolfHSM first boot path, committing key to NVM" /tmp/m33mu-wolfhsm-first.log
149+
grep -q "wolfHSM NSC tests passed" /tmp/m33mu-wolfhsm-first.log
150+
grep -q "\\[BKPT\\] imm=0x7d" /tmp/m33mu-wolfhsm-first.log
151+
grep -q "\\[EXPECT BKPT\\] Success" /tmp/m33mu-wolfhsm-first.log
152+
153+
- name: Run wolfHSM second boot (stm32h5)
154+
run: |
155+
cd /tmp/m33mu-wolfhsm-persist
156+
m33mu "$GITHUB_WORKSPACE/wolfboot.bin" \
157+
"$GITHUB_WORKSPACE/test-app/image_v1_signed.bin:0x60000" \
158+
--persist --uart-stdout --timeout 120 --expect-bkpt 0x7f \
159+
| tee /tmp/m33mu-wolfhsm-second.log
160+
161+
- name: Verify wolfHSM second boot (stm32h5)
162+
run: |
163+
grep -q "wolfHSM second boot path, restored persisted key" /tmp/m33mu-wolfhsm-second.log
164+
grep -q "wolfHSM NSC tests passed" /tmp/m33mu-wolfhsm-second.log
165+
grep -q "\\[BKPT\\] imm=0x7f" /tmp/m33mu-wolfhsm-second.log
166+
grep -q "\\[EXPECT BKPT\\] Success" /tmp/m33mu-wolfhsm-second.log
167+
122168
- name: Clean and build test with DICE attestation + OTP (stm32h5)
123169
run: |
124170
make clean distclean

docs/wolfHSM.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ wolfBoot supports using wolfHSM on the following platforms:
2121

2222
- wolfBoot simulator (using wolfHSM POSIX TCP transport)
2323
- AURIX TC3xx (shared memory transport)
24+
- STM32H5 TrustZone (the secure-side wolfBoot hosts a wolfHSM server and exposes it to the non-secure application through a single NSC veneer; see [STM32H5 TrustZone Engine](#stm32h5-trustzone-engine) below)
2425

2526
Details on configuring wolfBoot to use wolfHSM on each of these platforms can be found in the wolfBoot (and wolfHSM) documentation specific to that target, with the exception of the simulator, which is documented here. The remainder of this document focuses on the generic wolfHSM-related configuration options.
2627

@@ -238,3 +239,51 @@ When using wolfHSM server mode, no external server is required. wolfBoot include
238239
```
239240

240241
The embedded wolfHSM server will automatically handle all cryptographic operations and key management using the file-based NVM storage(`wolfBoot_wolfHSM_NVM.bin`) that was generated above.
242+
243+
## STM32H5 TrustZone Engine
244+
245+
On STM32H5, wolfBoot can host a wolfHSM server in the secure TrustZone image and expose it to the non-secure application through a single non-secure-callable veneer (`wcs_wolfhsm_transmit`). The non-secure side runs the standard wolfHSM client API, which auto-registers a wolfCrypt cryptocb under `WH_DEV_ID`, so application-level wolfCrypt calls that pass that device ID transparently round-trip to the secure server.
246+
247+
This is a separate deployment shape from the wolfHSM client/server modes documented above; it does not use `WOLFBOOT_ENABLE_WOLFHSM_CLIENT/SERVER` or the `hsmClientCtx`/`hsmServerCtx` HAL hooks, and is mutually exclusive with the other STM32H5 TrustZone engines (`WOLFCRYPT_TZ_PKCS11`, `WOLFCRYPT_TZ_PSA`, `WOLFCRYPT_TZ_FWTPM`).
248+
249+
### Build
250+
251+
```sh
252+
cp config/examples/stm32h5-tz-wolfhsm.config .config
253+
make
254+
```
255+
256+
For on-board hardware testing, add `WOLFBOOT_TZ_TEST_NO_BKPT=1` so the auto-test prints a UART pass/fail line and idles in `while (1)` instead of issuing `bkpt #0x7f` (which HardFaults on real silicon without a debugger):
257+
258+
```sh
259+
make WOLFBOOT_TZ_TEST_NO_BKPT=1
260+
```
261+
262+
### Flash
263+
264+
The wolfBoot helper programs the option bytes the secure boot path requires (`TZEN`, `SECBOOTADD`, `SECWM1`/`SECWM2`); see [STM32-TZ.md](STM32-TZ.md) for the option-byte details:
265+
266+
```sh
267+
./tools/scripts/set-stm32-tz-option-bytes.sh
268+
STM32_Programmer_CLI -c port=swd -d wolfboot.bin 0x0C000000
269+
STM32_Programmer_CLI -c port=swd -d test-app/image_v1_signed.bin 0x08060000
270+
```
271+
272+
### Test
273+
274+
The non-secure test application runs the wolfHSM auto-test at startup. A successful first boot ends with:
275+
276+
```text
277+
wolfHSM CommInit ok (client=1 server=...)
278+
wolfHSM RNG ok: <16 random bytes>
279+
wolfHSM SHA256 ok
280+
wolfHSM AES ok
281+
wolfHSM first boot path, committing key to NVM
282+
wolfHSM NSC tests passed
283+
```
284+
285+
The default build raises `bkpt #0x7d` on first-boot success and `bkpt #0x7f` on second-boot success (after the persisted key is reloaded from flash on reset). The `WOLFBOOT_TZ_TEST_NO_BKPT=1` build prints a final `WOLFHSM_TZ_TEST_PASS` UART line instead. Reset the board (no re-flash) to verify persistence; the second boot prints `wolfHSM second boot path, restored persisted key`.
286+
287+
### Notes
288+
289+
The wolfHSM NVM lives in the existing `FLASH_KEYVAULT` region (112 KiB at `0x0C040000`) shared with the other STM32H5 TrustZone engines. The flash adapter (`src/wolfhsm_flash_hal.c`) caches the affected sector, modifies it, and rewrites the whole 8 KiB sector in one erase + program cycle, mirroring `psa_store.c` / `pkcs11_store.c`. This satisfies the H5 quad-word ECC rule that each 16-byte unit may be programmed exactly once between erases, which wolfHSM's 8-byte-unit writes would otherwise violate.

0 commit comments

Comments
 (0)