Skip to content

Commit f1afb9f

Browse files
authored
Merge pull request #487 from aidangarske/spdm-fix-swtpm-autoenable
Fix SPI and I2C behavior with SWTPM or FWTPM
2 parents 0b2a1c3 + b7ad7d8 commit f1afb9f

4 files changed

Lines changed: 169 additions & 23 deletions

File tree

.github/workflows/hw-spdm-test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ jobs:
152152
# spdm_test.sh handles vendor-specific reset (gpio_reset for nuvoton,
153153
# no-reset for nations) and SPDM-lock state internally. No pre-detect
154154
# needed: each runner is dedicated to a single known chip.
155-
set -e
155+
# pipefail so `spdm_test.sh | tee` propagates spdm_test.sh's non-zero
156+
# exit — without it, tee always returns 0 and internal test failures
157+
# silently pass CI.
158+
set -eo pipefail
156159
for mode in ${{ matrix.modes }}; do
157160
echo "=== spdm_test.sh mode=$mode ==="
158-
./examples/spdm/spdm_test.sh ./examples/spdm/spdm_ctrl "$mode" \
159-
2>&1 | tee "spdm-${{ matrix.vendor }}-${mode}.log"
161+
./examples/spdm/spdm_test.sh ./examples/spdm/spdm_ctrl "$mode" 2>&1 \
162+
| tee "spdm-${{ matrix.vendor }}-${mode}.log"
160163
done
161164
162165
- name: Post-job cleanup

.github/workflows/make-test-swtpm.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,92 @@ jobs:
112112
- name: nuvoton
113113
wolftpm_config: --enable-nuvoton --disable-fwtpm
114114

115+
# --- Auto-disable-on-HW tests: verify that hardware-path flags
116+
# (vendor/bus/autodetect) disable the swtpm + fwtpm defaults on
117+
# Linux aarch64/x86_64 without the user needing --disable-swtpm
118+
# or --disable-fwtpm. See configure.ac WOLFTPM_HW_SELECTED. ---
119+
120+
# Vendor flag alone — no --disable-fwtpm / --disable-swtpm needed.
121+
- name: nuvoton-autodisable
122+
wolftpm_config: --enable-nuvoton
123+
needs_swtpm: false
124+
- name: nations-autodisable
125+
wolftpm_config: --enable-nations
126+
needs_swtpm: false
127+
128+
# New --enable-spi intent flag.
129+
- name: spi
130+
wolftpm_config: --enable-spi
131+
needs_swtpm: false
132+
133+
# Explicit --enable-swtpm wins over the vendor auto-disable.
134+
- name: nuvoton-explicit-swtpm
135+
wolftpm_config: --enable-swtpm --enable-nuvoton --disable-fwtpm
136+
137+
# SPDM + vendor without any --disable flags (CI-path mirror of
138+
# the hw-spdm-test.yml build line).
139+
- name: spdm-nuvoton-autodisable
140+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
141+
wolftpm_config: --enable-spdm --enable-nuvoton --enable-debug
142+
needs_swtpm: false
143+
- name: spdm-nations-autodisable
144+
wolfssl_config: --enable-wolftpm --enable-ecc --enable-sha384 --enable-aesgcm --enable-hkdf --enable-sp
145+
wolftpm_config: --enable-spdm --enable-nations --enable-debug
146+
needs_swtpm: false
147+
148+
# Explicit --enable-fwtpm wins over the vendor auto-disable.
149+
- name: nuvoton-explicit-fwtpm
150+
wolftpm_config: --enable-nuvoton --enable-fwtpm
151+
needs_swtpm: false
152+
153+
# --enable-spi + explicit --enable-swtpm (explicit sw wins).
154+
- name: spi-explicit-swtpm
155+
wolftpm_config: --enable-spi --enable-swtpm --disable-fwtpm
156+
157+
# MMIO (no existing matrix entry covered this).
158+
- name: mmio
159+
wolftpm_config: --enable-mmio --disable-fwtpm
160+
needs_swtpm: false
161+
162+
# Linux kernel TPM driver (build-only; CI runner has no /dev/tpm*).
163+
- name: devtpm
164+
wolftpm_config: --enable-devtpm
165+
needs_swtpm: false
166+
test_command: "true"
167+
168+
# Negative tests: configure must error on conflicting flag combos,
169+
# and we verify the SPECIFIC error message (not just a non-zero
170+
# exit). wolfSSL is installed by the earlier `Setup wolfSSL` step,
171+
# so configure gets past its wolfSSL check and hits the real
172+
# conflict detection.
173+
- name: config-conflicts
174+
wolftpm_config: --disable-fwtpm
175+
needs_swtpm: false
176+
test_command: |-
177+
set -e
178+
check_conflict() {
179+
local flags="$1" expected_err="$2"
180+
echo "=== expect failure: ./configure $flags ==="
181+
echo " expected error substring: '$expected_err'"
182+
make distclean >/dev/null 2>&1 || true
183+
./autogen.sh >/dev/null 2>&1
184+
local out
185+
out=$(./configure $flags 2>&1 || true)
186+
if echo "$out" | grep -qF "$expected_err"; then
187+
echo " PASS"
188+
else
189+
echo " FAIL — actual output:"
190+
echo "$out" | tail -20 | sed 's/^/ /'
191+
exit 1
192+
fi
193+
}
194+
check_conflict "--enable-spi --enable-i2c" \
195+
"Cannot enable both --enable-spi and --enable-i2c"
196+
check_conflict "--enable-swtpm --enable-devtpm" \
197+
"Cannot enable both swtpm and devtpm"
198+
check_conflict "--enable-infineon=slb9673 --enable-spi" \
199+
"slb9673 is I2C-only"
200+
115201
# TIS lock
116202
- name: tislock
117203
wolftpm_config: --enable-tislock --disable-fwtpm

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ make install
207207
--enable-wrapper Enable wrapper code (default: enabled) - WOLFTPM2_NO_WRAPPER
208208
--enable-wolfcrypt Enable wolfCrypt hooks for RNG, Auth Sessions and Parameter encryption (default: enabled) - WOLFTPM2_NO_WOLFCRYPT
209209
--enable-advio Enable Advanced IO (default: disabled) - WOLFTPM_ADV_IO
210+
--enable-spi Intent signal for SPI hardware build. SPI is the default transport when --enable-i2c is not set;
211+
this flag adds no compile-time macro but disables the auto-enabled swTPM/fwTPM defaults. (default: not set)
210212
--enable-i2c Enable I2C TPM Support (default: disabled, requires advio) - WOLFTPM_I2C
213+
--enable-mmio Enable built-in MMIO callbacks (default: disabled) - WOLFTPM_MMIO
211214
--enable-checkwaitstate Enable TIS / SPI Check Wait State support (default: depends on chip) - WOLFTPM_CHECK_WAIT_STATE
212215
--enable-smallstack Enable options to reduce stack usage
213216
--enable-tislock Enable Linux Named Semaphore for locking access to SPI device for concurrent access between processes - WOLFTPM_TIS_LOCK
@@ -220,14 +223,21 @@ make install
220223
--enable-st Enable ST ST33 Support (default: disabled) - WOLFTPM_ST33
221224
--enable-microchip Enable Microchip ATTPM20 Support (default: disabled) - WOLFTPM_MICROCHIP
222225
--enable-nuvoton Enable Nuvoton NPCT65x/NPCT75x Support (default: disabled) - WOLFTPM_NUVOTON
226+
--enable-nations Enable Nations Technology NS350 Support (default: disabled) - WOLFTPM_NATIONS
223227
224228
--enable-devtpm Enable using Linux kernel driver for /dev/tpmX (default: disabled) - WOLFTPM_LINUX_DEV
225229
Note: With autodetect (default) this is no longer required on Linux;
226230
the kernel driver is tried automatically before SPI.
227-
--enable-swtpm Enable using SWTPM TCP protocol. For use with simulator. (default: disabled) - WOLFTPM_SWTPM
231+
--enable-swtpm Enable using SWTPM TCP protocol. For use with simulator. (default: enabled on Linux x86_64/aarch64,
232+
disabled elsewhere or when a hardware path is selected via any of
233+
--enable-spi/--enable-i2c/--enable-mmio/--enable-nuvoton/--enable-nations/
234+
--enable-infineon/--enable-st/--enable-microchip/--enable-devtpm/--enable-autodetect) - WOLFTPM_SWTPM
228235
--enable-swtpm=uart Enable using SWTPM protocol over UART serial. For use with fwTPM on
229236
embedded targets (e.g. STM32H5). Uses termios serial I/O instead of
230237
TCP sockets. - WOLFTPM_SWTPM + WOLFTPM_SWTPM_UART
238+
--enable-fwtpm Enable firmware TPM (fwTPM) server. Same default behavior as --enable-swtpm
239+
(auto-enabled on Linux x86_64/aarch64, auto-disabled when a hardware
240+
path is selected). - WOLFTPM_FWTPM_SERVER
231241
--enable-winapi Use Windows TBS API. (default: disabled) - WOLFTPM_WINAPI
232242
233243
WOLFTPM_USE_SYMMETRIC Enables symmetric AES/Hashing/HMAC support for TLS examples.

configure.ac

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,28 @@ fi
176176
AC_MSG_NOTICE([wolfCrypt path: ${wcpath}])
177177

178178

179+
# SPI transport — this is the default when no other bus is selected.
180+
# The flag itself is an intent signal (so hardware-builds can say
181+
# --enable-spi explicitly); no macro is needed since the SPI HAL is
182+
# compiled whenever WOLFTPM_I2C isn't set.
183+
AC_ARG_ENABLE([spi],
184+
[AS_HELP_STRING([--enable-spi],[Intent signal for SPI hardware build. SPI is the default transport when --enable-i2c is not set; this flag adds no compile-time macro but disables the auto-enabled swTPM/fwTPM defaults. (default: not set)])],
185+
[ ENABLED_SPI=$enableval ],
186+
[ ENABLED_SPI=no ]
187+
)
188+
179189
# I2C Support
180190
AC_ARG_ENABLE([i2c],
181191
[AS_HELP_STRING([--enable-i2c],[Enable I2C TPM Support (default: disabled)])],
182192
[ ENABLED_I2C=$enableval ],
183193
[ ENABLED_I2C=no ]
184194
)
185195

196+
if test "x$ENABLED_SPI" = "xyes" && test "x$ENABLED_I2C" = "xyes"
197+
then
198+
AC_MSG_ERROR([Cannot enable both --enable-spi and --enable-i2c])
199+
fi
200+
186201
if test "x$ENABLED_I2C" = "xyes"
187202
then
188203
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_I2C"
@@ -225,29 +240,43 @@ then
225240
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_LINUX_DEV"
226241
fi
227242

228-
# Native host defaults — auto-enable fwTPM and swTPM on Linux/BSD x86_64 / aarch64
229-
# so `make check` provides full coverage out of the box. Users can still
230-
# explicitly disable with --disable-fwtpm / --disable-swtpm.
243+
# If the user explicitly picked any hardware path (vendor, bus, kernel
244+
# driver, autodetect), don't default-enable the software TPMs — the SPI HAL
245+
# in hal/tpm_io_linux.c is excluded when WOLFTPM_SWTPM is defined.
246+
WOLFTPM_HW_SELECTED=no
247+
for _wt_v in "$enable_infineon" "$enable_st" "$enable_st33" \
248+
"$enable_microchip" "$enable_mchp" \
249+
"$enable_nuvoton" "$enable_nations" \
250+
"$enable_spi" "$enable_i2c" "$enable_mmio" \
251+
"$enable_devtpm" "$enable_autodetect" \
252+
"$enable_winapi" "$enable_wintbs"; do
253+
if test -n "$_wt_v" && test "x$_wt_v" != "xno"; then
254+
WOLFTPM_HW_SELECTED=yes
255+
fi
256+
done
257+
258+
# Auto-enable fwTPM + swTPM on Linux/BSD x86_64/aarch64 so `make check`
259+
# works out of the box — unless a hardware path was explicitly selected.
231260
WOLFTPM_DEFAULT_FWTPM=no
232261
WOLFTPM_DEFAULT_SWTPM=no
233-
case $host_cpu in
234-
x86_64|amd64|aarch64)
235-
# Defensive exclusion: fwtpm_server uses POSIX sockets and is not
236-
# currently portable to Windows / Darwin. Auto-enable on Linux/BSD only.
237-
case $host_os in
238-
*mingw*|*cygwin*|*msys*|*darwin*|*win32*)
239-
;;
240-
*)
241-
WOLFTPM_DEFAULT_FWTPM=yes
242-
WOLFTPM_DEFAULT_SWTPM=yes
243-
;;
244-
esac
245-
;;
246-
esac
262+
if test "x$WOLFTPM_HW_SELECTED" = "xno"; then
263+
case $host_cpu in
264+
x86_64|amd64|aarch64)
265+
case $host_os in
266+
*mingw*|*cygwin*|*msys*|*darwin*|*win32*)
267+
;;
268+
*)
269+
WOLFTPM_DEFAULT_FWTPM=yes
270+
WOLFTPM_DEFAULT_SWTPM=yes
271+
;;
272+
esac
273+
;;
274+
esac
275+
fi
247276

248277
# SW TPM device Support
249278
AC_ARG_ENABLE([swtpm],
250-
[AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: enabled on Linux x86_64/aarch64, disabled elsewhere)])],
279+
[AS_HELP_STRING([--enable-swtpm],[Enable use of TPM through the SW socket driver (default: enabled on Linux x86_64/aarch64, disabled elsewhere or when any --enable-<vendor>/--enable-spi/--enable-i2c/--enable-mmio/--enable-devtpm/--enable-autodetect is explicitly set)])],
251280
[ ENABLED_SWTPM=$enableval ],
252281
[ ENABLED_SWTPM=$WOLFTPM_DEFAULT_SWTPM ]
253282
)
@@ -299,7 +328,7 @@ AC_SUBST([DISTCHECK_SWTPM_PORT_FLAG])
299328

300329
# Firmware TPM (fwTPM) - software TPM 2.0 simulator
301330
AC_ARG_ENABLE([fwtpm],
302-
[AS_HELP_STRING([--enable-fwtpm],[Enable firmware TPM (fwTPM) server (default: enabled on Linux x86_64/aarch64, disabled elsewhere)])],
331+
[AS_HELP_STRING([--enable-fwtpm],[Enable firmware TPM (fwTPM) server (default: enabled on Linux x86_64/aarch64, disabled elsewhere or when any --enable-<vendor>/--enable-spi/--enable-i2c/--enable-mmio/--enable-devtpm/--enable-autodetect is explicitly set)])],
303332
[ ENABLED_FWTPM=$enableval ],
304333
[ ENABLED_FWTPM=$WOLFTPM_DEFAULT_FWTPM ]
305334
)
@@ -472,6 +501,11 @@ then
472501
else
473502
if test "x$ENABLED_INFINEON" = "xslb9673"
474503
then
504+
# slb9673 is I2C-only; reject combos that imply SPI.
505+
if test "x$ENABLED_SPI" = "xyes"
506+
then
507+
AC_MSG_ERROR([--enable-infineon=slb9673 is I2C-only; use --enable-i2c --enable-advio (not --enable-spi)])
508+
fi
475509
enable_i2c=yes
476510
AM_CFLAGS="$AM_CFLAGS -DWOLFTPM_SLB9673"
477511
else
@@ -787,6 +821,19 @@ echo " * Wrappers: $ENABLED_WRAPPER"
787821
echo " * Examples: $ENABLED_EXAMPLES"
788822
echo " * wolfCrypt: $ENABLED_WOLFCRYPT"
789823
echo " * Advanced IO: $ENABLED_ADVIO"
824+
825+
# SPI HAL is actually compiled when no other transport claims the bus.
826+
# Mirror the #if guards in hal/tpm_io_linux.c so the summary reflects
827+
# the real build state, matching how ENABLED_I2C is reported below.
828+
SPI_ACTUAL=yes
829+
if test "x$ENABLED_I2C" = "xyes" || \
830+
test "x$ENABLED_SWTPM" = "xyes" || test "x$ENABLED_SWTPM" = "xuart" || \
831+
test "x$ENABLED_DEVTPM" = "xyes" || \
832+
test "x$ENABLED_WINAPI" = "xyes"
833+
then
834+
SPI_ACTUAL=no
835+
fi
836+
echo " * SPI: $SPI_ACTUAL"
790837
echo " * I2C: $ENABLED_I2C"
791838
echo " * Linux kernel TPM device: $ENABLED_DEVTPM"
792839
echo " * SWTPM: $ENABLED_SWTPM"

0 commit comments

Comments
 (0)