summaryrefslogtreecommitdiff
path: root/src/drivers/spi
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2016-07-31 11:19:20 -0700
committerVadim Bendebury <vbendeb@chromium.org>2016-08-03 20:07:40 +0200
commit9e561f8e8087e0dc99e05f514c291da888085165 (patch)
tree4224c1608bb78779dd172b58dffe6d2e1e70557d /src/drivers/spi
parentd1a00515ffc9ebe60994843eb3c7ef4b19e6181b (diff)
downloadcoreboot-9e561f8e8087e0dc99e05f514c291da888085165.tar.xz
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, and increase the length limit to 300 bytes to accommodate longer version strings. 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> Reviewed-on: https://review.coreboot.org/16000 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/drivers/spi')
-rw-r--r--src/drivers/spi/tpm/tpm.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c
index 4de62d95c4..9651ea8387 100644
--- a/src/drivers/spi/tpm/tpm.c
+++ b/src/drivers/spi/tpm/tpm.c
@@ -359,8 +359,14 @@ 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;
+ /*
+ * let's read 50 bytes at a time; leave room for the trailing
+ * zero.
+ */
+ char vstr[51];
+
+ chunk_size = sizeof(vstr) - 1;
printk(BIOS_INFO, "Firmware version: ");
@@ -368,21 +374,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, 1);
- /* 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");
}