Vadim Bendebury (vbendeb@chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16000
-gerrit
commit 393781e43c8f3f4f073f009a04437b0fd25268c7 Author: Vadim Bendebury vbendeb@chromium.org Date: Sun Jul 31 11:19:20 2016 -0700
spi/tpm: read TPM version in larger chunks
The TPM version string has become much longer recently, and the TPM_FW_VER register available on VID 1ae0 devices supports reading in arbitrary size quantities.
Let's read 50 bytes at a time to reduce the SPI register read wrapper overhead.
TEST=verified on the Kevin device: localhost ~ # grep cr50 /sys/firmware/log Firmware version: RO_A: 0.0.1/84e2dde7 RO_B:* 0.0.2/13eda43f RW_A:* cr50_v1.1.5005-444ddb7 RW_B: cr50_v1.1.5005-5aac83c cr50_v1.1.5005-444ddb7 private-cr51:v0.0.66-bd9a0fe tpm2:v0.0.259-8f3d735 cryptoc:v0.0.4-5319e83 2016-07-31 10:58:05 vbendeb@kvasha
Change-Id: Ifaf28c1a9a3990372a9cec108c098edbe50d3243 Signed-off-by: Vadim Bendebury vbendeb@chromium.org --- src/drivers/spi/tpm/tpm.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index 4de62d9..b038eda 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -359,8 +359,10 @@ int tpm2_init(struct spi_slave *spi_if) /* Let's report device FW version if available. */ if (tpm_info.vendor_id == 0x1ae0) { int chunk_count = 0; - uint32_t chunk = 0; - char vstr[sizeof(chunk) + 1]; /* room for 4 chars + zero */ + size_t chunk_size; + char vstr[51]; /* let's read 50 bytes at a time, leave room for the trailing zero. */ + + chunk_size = sizeof(vstr) - 1;
printk(BIOS_INFO, "Firmware version: ");
@@ -368,21 +370,20 @@ int tpm2_init(struct spi_slave *spi_if) * Does not really matter what's written, this just makes sure * the version is reported from the beginning. */ - tpm2_write_reg(TPM_FW_VER, &chunk, sizeof(chunk)); + tpm2_write_reg(TPM_FW_VER, &chunk_size, sizeof(chunk_size));
- /* Print it out in 4 byte chunks. */ - vstr[sizeof(vstr) - 1] = 0; + /* Print it out in sizeof(vstr) - 1 byte chunks. */ + vstr[chunk_size] = 0; do { - tpm2_read_reg(TPM_FW_VER, vstr, sizeof(chunk)); + tpm2_read_reg(TPM_FW_VER, vstr, chunk_size); printk(BIOS_INFO, "%s", vstr);
/* - * While string is not over, and no more than 200 + * While string is not over, and is no longer than 300 * 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(chunk)))); + } while (vstr[chunk_size - 1] && + (chunk_count++ < (300 / chunk_size)));
printk(BIOS_INFO, "\n"); }