Skip to content

Add stm32H5 TrustZone wolfHSM Port#348

Draft
aidangarske wants to merge 7 commits into
wolfSSL:mainfrom
aidangarske:wolfhsm-h5-port
Draft

Add stm32H5 TrustZone wolfHSM Port#348
aidangarske wants to merge 7 commits into
wolfSSL:mainfrom
aidangarske:wolfhsm-h5-port

Conversation

@aidangarske
Copy link
Copy Markdown
Member

Description

  • Adds port/stmicro/stm32-tz/wh_transport_nsc.{c,h}: a portable
    synchronous TrustZone non-secure-callable bridge transport for
    ARMv8-M Cortex-M targets. Client Send invokes a host-supplied
    veneer (wcs_wolfhsm_transmit) inline and caches the response;
    client Recv consumes the cached response on the first call.
    Server-side callbacks consume the request the host's veneer parked
    in a static context and write the response back into the non-secure
    caller's buffer.
  • Target-agnostic. The STM32H5-specific glue (NSC veneer, flash
    adapter, secure-side server init, NS test exerciser) lives in the
    matching wolfBoot PR.
  • New STM32_TZ_NSC=1 build flag in test/Makefile compiles the
    transport into the host test build and pulls in a new unit test
    test/wh_test_transport_nsc.c covering BADARGS, NOTREADY, happy-
    path round trip, and the request_pending / rsp_size state
    machine for both callback tables.
  • New CI lane in .github/workflows/build-and-test.yml:
    STM32_TZ_NSC=1 ASAN=1 build + run.
  • Docs: new "STM32 TrustZone (STM32H5 / NSC bridge)" section in
    docs/src/chapter08.md.

Notes

  • Companion wolfBoot PR adds WOLFCRYPT_TZ_WOLFHSM=1 for STM32H5,
    which is the first consumer of this transport. here

Test plan

  • STM32_TZ_NSC=1 ASAN=1 build + make run (CI)
  • Existing CI matrix unaffected (no changes outside the new port)
  • End-to-end on STM32H5 NUCLEO-H563ZI via the wolfBoot PR

Copilot AI review requested due to automatic review settings May 1, 2026 23:30
@aidangarske aidangarske self-assigned this May 1, 2026

This comment was marked as resolved.

  New port/stmicro/stm32-tz/wh_transport_nsc.{c,h} implementing both
  client and server callbacks for a synchronous TrustZone NSC bridge.
  The non-secure (client) side calls a single cmse_nonsecure_entry
  veneer (wcs_wolfhsm_transmit, provided by the host) which hands the
  request to the secure-side server context, runs
  wh_Server_HandleRequestMessage once inline, and returns the response
  in the same call -- no polling, notify counter, or async
  producer/consumer.

  Send delivers; Recv returns the cached response. Server-side Recv
  hands the request the host's NSC veneer parked in the static context;
  Send writes the response back into the NS buffer and stores its size
  for the veneer to read.

  Used by wolfBoot's WOLFCRYPT_TZ_WOLFHSM=1 lane on STM32H5 (separate
  PR against wolfBoot). Gated by WOLFHSM_CFG_PORT_STM32_TZ_NSC so the
  file is safe to ship in the wolfHSM tree without forcing every
  consumer to link the unresolved wcs_wolfhsm_transmit extern.
The field name is self-describing; the comment was duplicating it.
Add a port section describing the new port/stmicro/stm32-tz NSC bridge
transport: synchronous single-call client Send/Recv, server-side static
context, target-agnostic transport with the STM32H5 glue (NSC veneer,
whFlashCb adapter, secure-side server init, NS test exerciser) living in
the wolfBoot port.
  Transport (port/stmicro/stm32-tz/wh_transport_nsc):
  - _NscServerSend returns WH_ERROR_BADARGS for size validation
    (only ABORTED when rsp_buf is NULL), matching the contract.
  - _NscClientSend / _NscClientRecv reject calls on an
    uninitialized context, giving ctx->initialized a purpose.
  - _NscServerRecv clears request_pending on the oversize path
    and resets rsp_size on entry to prevent stale-value leaks.
  - Drop the redundant cmd_buf staging copy on the client side,
    saving WH_COMM_MTU bytes of NS BSS plus a per-request memcpy.

  Test:
  - New test/wh_test_transport_nsc.c covering BADARGS, NOTREADY,
    happy path, and the request_pending / rsp_size state machine
    for both callback tables. Wired into whTest_Unit; new
    STM32_TZ_NSC=1 build flag compiles the transport source.

  Docs:
  - chapter08: client Recv consumes the cached response on the
    first call (subsequent calls return WH_ERROR_NOTREADY).
wolfSSL-Fenrir-bot

This comment was marked as low quality.

@aidangarske aidangarske marked this pull request as ready for review May 12, 2026 01:43
@aidangarske aidangarske requested a review from danielinux May 12, 2026 01:43
@bigbrett bigbrett self-assigned this May 12, 2026
Copy link
Copy Markdown
Contributor

@bigbrett bigbrett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidangarske thanks for this! I'm little unclear whether any of this stm32H5 specific or is just a generic TZ-M compatible transport? In the docs you say

The transport itself is target-agnostic; the STM32H5-specific glue (NSC veneer, whFlashCb flash adapter, secure-side server init, NS test exerciser) lives in the wolfBoot port.

If this is the case then I don't think you need any mention of STM32H5 in any of this? Unless I'm misunderstanding. If this is meant to be a generic trustzone M transport then I think having under port/tzm or something like that is better, with no mentions of STM32H5 at all.

LMK if I'm misunderstanding

@bigbrett bigbrett removed their assignment May 12, 2026
Rename port/stmicro/stm32-tz to port/armv8m-tz to reflect that the
transport is target-agnostic across ARMv8-M parts (Cortex-M23/M33/
M35P/M55/M85). The target-specific NSC veneer is provided by the
host; the only ARM-flavored thing in the transport is the documented
expectation that the extern wcs_wolfhsm_transmit symbol is a
cmse_nonsecure_entry on the secure side.

Config define renamed WOLFHSM_CFG_PORT_STM32_TZ_NSC ->
WOLFHSM_CFG_PORT_ARMV8M_TZ_NSC and make flag STM32_TZ_NSC=1 ->
ARMV8M_TZ_NSC=1. wh_settings.h doc, chapter08 port docs, and the
CI step name all updated to drop STM32-specific wording.

Review fixes folded in:

- _NscServerRecv clears ctx->rsp_size up-front so error paths leave
  no stale response state behind.
- _NscClientRecv rejects too-small caller buffers with WH_ERROR_BADARGS
  instead of WH_ERROR_ABORTED; cached response is preserved for retry.
- _NscClientSend returns WH_ERROR_NOTREADY if a prior response has not
  been consumed; propagates known WH_ERROR_* codes from the veneer.
- _NscServerCleanup zeroes the context so stale NS pointers cannot
  survive a reinit.
- Reorder whTransportNscServerContext fields to satisfy -Wpadded.
- Cover the new behaviors in wh_test_transport_nsc and add the NSC
  contexts to the struct padding check.
@bigbrett bigbrett marked this pull request as draft May 13, 2026 14:49
@bigbrett
Copy link
Copy Markdown
Contributor

@aidangarske reverting to draft after our conversation yesterday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants