From 1f54a30cebe808abf1b09478b47924bb722a0ca6 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Thu, 23 Jun 2016 18:17:33 -0700 Subject: [PATCH] tpm: report firmware version Some devices allow to retrieve firmware version by reading the same 4 byte register repeatedly until the entire version string is read. Let's print out TPM firmware version when available. Just in case something goes wrong limit the version string length to 200 bytes. CQ-DEPEND=CL:355701 BRANCH=none BUG=chrome-os-partner:54723 TEST=built the new firmware and ran it on Gru, observed the following in the coreboot console log: Connected to device vid:did:rid of 1ae0:0028:00 Firmware version: cr50_v1.1.4792-7a44484 Change-Id: Idb069dabb80d34a0efdf04c3c40a42ab0c8a3f94 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/355704 Reviewed-by: Scott Collyer --- src/drivers/spi/tpm/tpm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index b02fc5fbea..1b43bfbacf 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -32,6 +32,7 @@ #define TPM_DATA_FIFO_REG (TPM_LOCALITY_0_SPI_BASE + 0x24) #define TPM_DID_VID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf00) #define TPM_RID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf04) +#define TPM_FW_VER (TPM_LOCALITY_0_SPI_BASE + 0xf90) /* SPI Interface descriptor used by the driver. */ struct tpm_spi_if { @@ -355,6 +356,35 @@ int tpm2_init(struct spi_slave *spi_if) printk(BIOS_INFO, "Connected to device vid:did:rid of %4.4x:%4.4x:%2.2x\n", tpm_info.vendor_id, tpm_info.device_id, tpm_info.revision); + /* Let's report device FW version if available. */ + if (tpm_info.vendor_id == 0x1ae0) { + int chunk_count = 0; + char vstr[sizeof(cmd) + 1]; /* room for 4 chars + zero */ + + printk(BIOS_INFO, "Firmware version: "); + + /* + * Does not really matter what's written, this just makes sure + * the version is reported from the beginning. + */ + tpm2_write_reg(TPM_FW_VER, &cmd, sizeof(cmd)); + + /* Print it out in 4 byte chunks. */ + vstr[sizeof(vstr) - 1] = 0; + do { + tpm2_read_reg(TPM_FW_VER, vstr, sizeof(cmd)); + printk(BIOS_INFO, "%s", vstr); + + /* + * While string is not over, and no more than 200 + * characters. + * This is likely result in one extra printk() + * invocation with an empty string, not a big deal. + */ + } while (vstr[0] && (chunk_count++ < (200 / sizeof(cmd)))); + + printk(BIOS_INFO, "\n"); + } return 0; }