Skip to content

Commit ba8dcee

Browse files
authored
Merge pull request #489 from aidangarske/fix-nations-spdm-test
Normalize NS350 chip state at entry/exit of nations SPDM tests
2 parents c8d51e9 + d7cc386 commit ba8dcee

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

examples/spdm/spdm_test.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ gpio_reset() {
4848
sleep 2
4949
}
5050

51+
# normalize_nations_chip: bring NS350 to canonical clean state
52+
# (identity-key=1, no PSK). Idempotent — safe to call multiple times.
53+
# NS350 IdentityKeySet returns TPM_RC_VALUE when setting to current value,
54+
# so "already in target state" is indistinguishable from real errors; we
55+
# probe by trying both transitions rather than trusting a single call.
56+
normalize_nations_chip() {
57+
echo "--- Normalizing NS350 to clean state (identity-key=1, no PSK) ---"
58+
gpio_reset
59+
# Clear PSK if set. PSKNotSet (0xffA3) means already clean — that's fine.
60+
# Any other failure is also non-fatal here; the identity-key-set below
61+
# will surface the real problem if state is unrecoverable.
62+
"$SPDM_DEMO" --psk-clear "$NATIONS_CLEARAUTH" >/dev/null 2>&1 || true
63+
# Now try to set identity key. Succeeds if at 0, benign-fails with
64+
# TPM_RC_VALUE if already at 1. Either outcome = state is 1.
65+
"$SPDM_DEMO" --identity-key-set >/dev/null 2>&1 || true
66+
echo "--- Normalization complete ---"
67+
echo ""
68+
}
69+
5170
run_test() {
5271
local name="$1"; shift
5372
TOTAL=$((TOTAL + 1))
@@ -132,7 +151,12 @@ if [ "$VENDOR" = "nuvoton" ]; then
132151

133152
elif [ "$VENDOR" = "nations" ]; then
134153
# Nations NS350 identity key mode — full lifecycle test
135-
# Note: GPIO 4 is NOT wired to TPM_RST on NS350 daughter boards.
154+
# GPIO 4 is wired to TPM_RST on NS350 and clears volatile state, but
155+
# identity-key/PSK are NV-persistent across reset. The entry/exit
156+
# normalization ensures the chip is always at a known starting state
157+
# and always left clean, regardless of prior runs or mid-test failures.
158+
normalize_nations_chip
159+
trap 'normalize_nations_chip' EXIT
136160

137161
run_test_no_reset "Unset identity key" "$SPDM_DEMO" --identity-key-unset
138162
run_test_no_reset "Set identity key" "$SPDM_DEMO" --identity-key-set
@@ -156,8 +180,10 @@ elif [ "$VENDOR" = "nations-psk" ]; then
156180
# Uses NSING reference test data (PSK_DEMO_3 from Vision's traces).
157181
# ClearAuth is always exactly 32 bytes per TCG spec.
158182

159-
# Note: GPIO 4 is NOT wired to TPM_RST on NS350 daughter boards.
160-
# Use run_test_no_reset instead of run_test.
183+
# Entry/exit normalization: always start clean (identity-key=1, no PSK)
184+
# and always end clean, regardless of prior state or mid-test failures.
185+
normalize_nations_chip
186+
trap 'normalize_nations_chip' EXIT
161187

162188
# Step 1: Ensure identity key is unset (required for PSK mode)
163189
run_test_no_reset "Unset identity key" "$SPDM_DEMO" --identity-key-unset

0 commit comments

Comments
 (0)