diff --git a/src/drivers/i2c/tpm/Kconfig b/src/drivers/i2c/tpm/Kconfig index 89e4621b77..d35eb754b4 100644 --- a/src/drivers/i2c/tpm/Kconfig +++ b/src/drivers/i2c/tpm/Kconfig @@ -39,3 +39,8 @@ config DRIVER_I2C_TPM_ACPI bool "Generate I2C TPM ACPI device" default y if ARCH_X86 && I2C_TPM default n + +config DRIVER_TPM_DISPLAY_TIS_BYTES + bool "TPM: Display the TIS transactions to I2C TPM chip" + default n + depends on I2C_TPM diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c index a0d05409ef..6bb0e969e9 100644 --- a/src/drivers/i2c/tpm/tis.c +++ b/src/drivers/i2c/tpm/tis.c @@ -17,9 +17,11 @@ #include #include #include +#include #include #include #include +#include #include #include "tpm.h" #include @@ -144,11 +146,19 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, { uint8_t buf[TPM_BUFSIZE]; + ASSERT(sbuf_size >= 10); if (sizeof(buf) < sbuf_size) return -1; - memcpy(buf, sendbuf, sbuf_size); + /* Display the TPM command */ + if (IS_ENABLED(CONFIG_DRIVER_TPM_DISPLAY_TIS_BYTES)) { + printk(BIOS_DEBUG, "TPM Command: 0x%08x\n", + read_at_be32(sendbuf, sizeof(uint16_t) + + sizeof(uint32_t))); + hexdump(sendbuf, sbuf_size); + } + memcpy(buf, sendbuf, sbuf_size); int len = tpm_transmit(buf, sbuf_size); if (len < 10) { @@ -164,5 +174,13 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, memcpy(recvbuf, buf, len); *rbuf_len = len; + /* Display the TPM response */ + if (IS_ENABLED(CONFIG_DRIVER_TPM_DISPLAY_TIS_BYTES)) { + printk(BIOS_DEBUG, "TPM Response: 0x%08x\n", + read_at_be32(recvbuf, sizeof(uint16_t) + + sizeof(uint32_t))); + hexdump(recvbuf, *rbuf_len); + } + return 0; }