Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcti-spi-helper does not tell the TPM to become ready #2671

Closed
Akuli opened this issue Aug 3, 2023 · 0 comments · Fixed by #2689
Closed

tcti-spi-helper does not tell the TPM to become ready #2671

Akuli opened this issue Aug 3, 2023 · 0 comments · Fixed by #2689
Assignees
Labels

Comments

@Akuli
Copy link

Akuli commented Aug 3, 2023

According to this spec I found, when the TPM is started it can be initially in ready or idle state.

ss

If it happens to stay in idle state, tcti-spi-helper will fail here:

// Wait up to 200ms for TPM to become ready
LOG_DEBUG("Waiting for TPM to become ready...");
uint32_t expected_status_bits = TCTI_SPI_HELPER_TPM_STS_COMMAND_READY;
rc = spi_tpm_helper_wait_for_status(ctx, expected_status_bits, expected_status_bits, 200);
if (rc != TSS2_RC_SUCCESS) {
LOG_ERROR("Failed waiting for TPM to become ready");
return rc;
}
LOG_DEBUG("TPM is ready");

This makes tcti-spi-helper unusable in the project I am working on now.

A quick and dirty fix is to just ask the TPM chip to transition to ready state and try again:

diff --git a/src/tss2-tcti/tcti-spi-helper.c b/src/tss2-tcti/tcti-spi-helper.c
index 515a5363..f2d69c0f 100644
--- a/src/tss2-tcti/tcti-spi-helper.c
+++ b/src/tss2-tcti/tcti-spi-helper.c
@@ -740,6 +740,10 @@ TSS2_RC Tss2_Tcti_Spi_Helper_Init (TSS2_TCTI_CONTEXT* tcti_context, size_t* size
     LOG_DEBUG("Waiting for TPM to become ready...");
     uint32_t expected_status_bits = TCTI_SPI_HELPER_TPM_STS_COMMAND_READY;
     rc = spi_tpm_helper_wait_for_status(ctx, expected_status_bits, expected_status_bits, 200);
+    if (rc != TSS2_RC_SUCCESS) {
+        spi_tpm_helper_write_sts_reg(ctx, TCTI_SPI_HELPER_TPM_STS_COMMAND_READY);
+        rc = spi_tpm_helper_wait_for_status(ctx, expected_status_bits, expected_status_bits, 200);
+    }
     if (rc != TSS2_RC_SUCCESS) {
         LOG_ERROR("Failed waiting for TPM to become ready");
         return rc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants