From 3111537e7b66d8507b6608ef665e4cde76403818 Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Mon, 27 Jun 2016 19:05:41 -0700 Subject: [PATCH] tpm: use 4 byte quantities when retrieving firmware version The CR50 device is capable of reporting its firmware version in 4 byte quantities, but the recently introduced code retrieves the version one byte at a time. With this fix the version is retrieved in 4 byte chunks. BRANCH=none BUG=none TEST=the version is still reported properly, as reported by the AP firmware console log: localhost ~ # grep cr50 /sys/firmware/log Firmware version: cr50_v1.1.4804-c64cf24 localhost ~ # Change-Id: I04116881a30001e35e989e51ec1567263f9149a6 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/356542 Reviewed-by: Andrey Pronin --- src/drivers/spi/tpm/tpm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index 1b43bfbacf..4de62d95c4 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -359,7 +359,8 @@ 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; - char vstr[sizeof(cmd) + 1]; /* room for 4 chars + zero */ + uint32_t chunk = 0; + char vstr[sizeof(chunk) + 1]; /* room for 4 chars + zero */ printk(BIOS_INFO, "Firmware version: "); @@ -367,12 +368,12 @@ 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, &cmd, sizeof(cmd)); + tpm2_write_reg(TPM_FW_VER, &chunk, sizeof(chunk)); /* Print it out in 4 byte chunks. */ vstr[sizeof(vstr) - 1] = 0; do { - tpm2_read_reg(TPM_FW_VER, vstr, sizeof(cmd)); + tpm2_read_reg(TPM_FW_VER, vstr, sizeof(chunk)); printk(BIOS_INFO, "%s", vstr); /* @@ -381,7 +382,7 @@ int tpm2_init(struct spi_slave *spi_if) * 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)))); + } while (vstr[0] && (chunk_count++ < (200 / sizeof(chunk)))); printk(BIOS_INFO, "\n"); }