Subrata Banik has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/79736?usp=email )
Change subject: security/tpm: Retrieve factory configuration for TI50 devices ......................................................................
security/tpm: Retrieve factory configuration for TI50 devices
This patch enables retrieval of factory configuration data from TI50 TPM devices.
This patch utilizes vendor-specific command TPM2_TI50_SUB_CMD_GET_FACTORY_CONFIG.
The factory config space is a 64-bit, one-time programmable. For the unprovisioned one, the read will be 0x0.
BUG=b:317880956 TEST=Able to retrieve the factory config from google/screebo.
Change-Id: Ifd0e850770152a03aa46d7f8bbb76f7520a59081 Signed-off-by: Subrata Banik subratabanik@google.com --- M src/security/tpm/tss/tcg-2.0/tss_marshaling.c M src/security/tpm/tss/tcg-2.0/tss_structures.h M src/security/tpm/tss/vendor/cr50/cr50.c M src/security/tpm/tss/vendor/cr50/cr50.h 4 files changed, 61 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/36/79736/1
diff --git a/src/security/tpm/tss/tcg-2.0/tss_marshaling.c b/src/security/tpm/tss/tcg-2.0/tss_marshaling.c index f1b9522..bf2b932 100644 --- a/src/security/tpm/tss/tcg-2.0/tss_marshaling.c +++ b/src/security/tpm/tss/tcg-2.0/tss_marshaling.c @@ -348,6 +348,9 @@ case TPM2_CR50_SUB_CMD_RESET_EC: rc |= obuf_write_be16(ob, *sub_command); break; + case TPM2_TI50_SUB_CMD_GET_FACTORY_CONFIG: + rc |= obuf_write_be16(ob, *sub_command); + break; default: /* Unsupported subcommand. */ printk(BIOS_WARNING, "Unsupported cr50 subcommand: 0x%04x\n", @@ -581,6 +584,11 @@ return ibuf_read_be8(ib, &vcr->boot_mode); case TPM2_CR50_SUB_CMD_RESET_EC: break; + case TPM2_TI50_SUB_CMD_GET_FACTORY_CONFIG: + uint64_t factory_config; + ibuf_read_be64(ib, &factory_config); + vcr->factory_config = factory_config & 0xff; + return vcr->factory_config; default: printk(BIOS_ERR, "%s:%d - unsupported vendor command %#04x!\n", diff --git a/src/security/tpm/tss/tcg-2.0/tss_structures.h b/src/security/tpm/tss/tcg-2.0/tss_structures.h index a73f4c4..d755ac7 100644 --- a/src/security/tpm/tss/tcg-2.0/tss_structures.h +++ b/src/security/tpm/tss/tcg-2.0/tss_structures.h @@ -352,6 +352,11 @@ uint8_t recovery_button_state; uint8_t tpm_mode; uint8_t boot_mode; + /* + * bits 63..8 : reserved + * bits 7..0 : factory config + */ + uint8_t factory_config; }; };
diff --git a/src/security/tpm/tss/vendor/cr50/cr50.c b/src/security/tpm/tss/vendor/cr50/cr50.c index 87889d1..5be9098 100644 --- a/src/security/tpm/tss/vendor/cr50/cr50.c +++ b/src/security/tpm/tss/vendor/cr50/cr50.c @@ -176,3 +176,41 @@
return TPM_SUCCESS; } + +tpm_result_t tlcl_ti50_get_factory_config(uint64_t *factory_config) +{ + struct tpm2_response *response; + uint16_t factory_config_command = TPM2_TI50_SUB_CMD_GET_FACTORY_CONFIG; + *factory_config = 0; + + printk(BIOS_INFO, "Reading Ti50 factory config\n"); + + response = tpm_process_command(TPM2_CR50_VENDOR_COMMAND, &factory_config_command); + + if (!response) + return TPM_IOERROR; + + /* + * The Ti50 returns VENDOR_RC_INTERNAL_ERROR if the key ladder + * is disabled. The Ti50 requires a reboot to re-enable the key + * ladder. + */ + if (response->hdr.tpm_code == VENDOR_RC_INTERNAL_ERROR) + return TPM_CB_MUST_REBOOT; + + /* + * Explicitly inform caller when command is not supported + */ + if (response->hdr.tpm_code == VENDOR_RC_NO_SUCH_COMMAND || + response->hdr.tpm_code == VENDOR_RC_NO_SUCH_SUBCOMMAND) + return TPM_CB_NO_SUCH_COMMAND; + + /* Unexpected return code from Ti50 */ + if (response->hdr.tpm_code) + return TPM_IOERROR; + + /* TPM command completed without error */ + *factory_config = response->vcr.factory_config; + + return TPM_SUCCESS; +} diff --git a/src/security/tpm/tss/vendor/cr50/cr50.h b/src/security/tpm/tss/vendor/cr50/cr50.h index edd5083..8bf1425 100644 --- a/src/security/tpm/tss/vendor/cr50/cr50.h +++ b/src/security/tpm/tss/vendor/cr50/cr50.h @@ -17,6 +17,8 @@ #define TPM2_CR50_SUB_CMD_TPM_MODE (40) #define TPM2_CR50_SUB_CMD_GET_BOOT_MODE (52) #define TPM2_CR50_SUB_CMD_RESET_EC (53) +/* Ti50 only. */ +#define TPM2_TI50_SUB_CMD_GET_FACTORY_CONFIG (68)
/* Cr50 vendor-specific error codes. */ #define VENDOR_RC_ERR 0x00000500 @@ -105,4 +107,12 @@ */ tpm_result_t tlcl_cr50_reset_ec(void);
+/** + * TI50 specific TPM command sequence to get the factory config. + * + * Returns TPM_* for errors. + * On Success, TPM_SUCCESS if factory config is successfully retrieved. + */ +tpm_result_t tlcl_ti50_get_factory_config(uint64_t *factory_config); + #endif /* CR50_TSS_STRUCTURES_H_ */