Skip to content

Commit b8254ba

Browse files
aidangarskedanielinux
authored andcommitted
Document the STM32H5 fwTPM secure RAM budget and stack reservation
1 parent 670280e commit b8254ba

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎docs/fwTPM.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ The current wolfBoot integration builds the secure fwTPM service with
9595
NV storage, provide a flash-backed `FWTPM_NV_HAL` implementation and remove
9696
`FWTPM_NO_NV` from the fwTPM build flags.
9797

98+
### Secure RAM footprint
99+
100+
The secure image keeps one `FWTPM_CTX` in `.bss`, and wolfTPM 4.2.0 grew it to
101+
about 93 KB with the library defaults. The STM32H5 secure RAM region is 128 KB
102+
and the stack grows down from the top of it, so the default context left under
103+
12 KB for the stack. Deep call chains then overran the tail of the context,
104+
where the auth session slots live, and `StartAuthSession` failed with
105+
`TPM_RC_SESSION_HANDLES` on a fresh TPM.
106+
107+
The build trims the NV index slots, which are dead weight under `FWTPM_NO_NV`:
108+
109+
| Flag | wolfTPM default | wolfBoot fwTPM build |
110+
| ---- | --------------- | -------------------- |
111+
| `FWTPM_MAX_NV_INDICES` | 16 | 2 |
112+
| `FWTPM_MAX_NV_DATA` | 2048 | 512 |
113+
114+
That brings the context to about 60 KB and leaves roughly 45 KB of stack.
115+
`hal/stm32h5.ld` also reserves `_min_stack` (32 KB) below the top of RAM and
116+
asserts at link time that `.bss` does not encroach on it, so an oversized
117+
context fails the build instead of corrupting memory at run time.
118+
119+
If you re-enable persistent NV, raise `FWTPM_MAX_NV_INDICES` and
120+
`FWTPM_MAX_NV_DATA` to what the deployment needs and re-check the link assert.
121+
The other `FWTPM_MAX_*` limits in `wolftpm/fwtpm/fwtpm.h` are `#ifndef`-guarded
122+
and can be tuned the same way on the compile line.
123+
98124
`WOLFCRYPT_TZ_FWTPM` is mutually exclusive with `WOLFCRYPT_TZ_PKCS11` and
99125
`WOLFCRYPT_TZ_PSA` because each option selects a different TrustZone secure
100126
service surface for the test application.

0 commit comments

Comments
 (0)