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>
This commit is contained in:
parent
d1a00515ff
commit
9e561f8e80
|
@ -359,8 +359,14 @@ int tpm2_init(struct spi_slave *spi_if)
|
||||||
/* Let's report device FW version if available. */
|
/* Let's report device FW version if available. */
|
||||||
if (tpm_info.vendor_id == 0x1ae0) {
|
if (tpm_info.vendor_id == 0x1ae0) {
|
||||||
int chunk_count = 0;
|
int chunk_count = 0;
|
||||||
uint32_t chunk = 0;
|
size_t chunk_size;
|
||||||
char vstr[sizeof(chunk) + 1]; /* room for 4 chars + zero */
|
/*
|
||||||
|
* 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: ");
|
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
|
* Does not really matter what's written, this just makes sure
|
||||||
* the version is reported from the beginning.
|
* 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. */
|
/* Print it out in sizeof(vstr) - 1 byte chunks. */
|
||||||
vstr[sizeof(vstr) - 1] = 0;
|
vstr[chunk_size] = 0;
|
||||||
do {
|
do {
|
||||||
tpm2_read_reg(TPM_FW_VER, vstr, sizeof(chunk));
|
tpm2_read_reg(TPM_FW_VER, vstr, chunk_size);
|
||||||
printk(BIOS_INFO, "%s", vstr);
|
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.
|
* 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");
|
printk(BIOS_INFO, "\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue