drivers/tpm: Make temp test value naming consistent
Make naming convention consistent across all functions return values. BUG=b:296439237 TEST=Boot to OS on Skyrim BRANCH=None Change-Id: If86805b39048800276ab90b7687644ec2a0d4bee Signed-off-by: Jon Murphy <jpmurphy@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/77536 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com> Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
This commit is contained in:
		
				
					committed by
					
						
						Karthik Ramasubramanian
					
				
			
			
				
	
			
			
			
						parent
						
							277db94ebb
						
					
				
				
					commit
					2460481025
				
			@@ -122,14 +122,14 @@ static int tpm_get_cap(uint32_t property, uint32_t *value)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	TPMS_CAPABILITY_DATA cap_data;
 | 
						TPMS_CAPABILITY_DATA cap_data;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
	uint32_t status;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!value)
 | 
						if (!value)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = tlcl_get_capability(TPM_CAP_TPM_PROPERTIES, property, 1, &cap_data);
 | 
						rc = tlcl_get_capability(TPM_CAP_TPM_PROPERTIES, property, 1, &cap_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (status)
 | 
						if (rc)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0 ; i < cap_data.data.tpmProperties.count; i++) {
 | 
						for (i = 0 ; i < cap_data.data.tpmProperties.count; i++) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -132,7 +132,7 @@ static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
 | 
				
			|||||||
static int process_reset(void)
 | 
					static int process_reset(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct stopwatch sw;
 | 
						struct stopwatch sw;
 | 
				
			||||||
	int rv = 0;
 | 
						int rc = 0;
 | 
				
			||||||
	uint8_t access;
 | 
						uint8_t access;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
@@ -148,9 +148,9 @@ static int process_reset(void)
 | 
				
			|||||||
		const uint8_t mask =
 | 
							const uint8_t mask =
 | 
				
			||||||
			TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY;
 | 
								TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rv = cr50_i2c_read(TPM_ACCESS(0),
 | 
							rc = cr50_i2c_read(TPM_ACCESS(0),
 | 
				
			||||||
				   &access, sizeof(access));
 | 
									   &access, sizeof(access));
 | 
				
			||||||
		if (rv || ((access & mask) == mask)) {
 | 
							if (rc || ((access & mask) == mask)) {
 | 
				
			||||||
			/*
 | 
								/*
 | 
				
			||||||
			 * Don't bombard the chip with traffic, let it keep
 | 
								 * Don't bombard the chip with traffic, let it keep
 | 
				
			||||||
			 * processing the command.
 | 
								 * processing the command.
 | 
				
			||||||
@@ -165,7 +165,7 @@ static int process_reset(void)
 | 
				
			|||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	} while (!stopwatch_expired(&sw));
 | 
						} while (!stopwatch_expired(&sw));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (rv)
 | 
						if (rc)
 | 
				
			||||||
		printk(BIOS_ERR, "Failed to read TPM\n");
 | 
							printk(BIOS_ERR, "Failed to read TPM\n");
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		printk(BIOS_ERR,
 | 
							printk(BIOS_ERR,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,7 +73,7 @@ static const uint8_t crtm_version[] =
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int mb_crtm(void)
 | 
					int mb_crtm(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status = TPM_E_IOERROR;
 | 
						int rc = TPM_E_IOERROR;
 | 
				
			||||||
	TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
						TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Use FirmwareVersion string to represent CRTM version. */
 | 
						/* Use FirmwareVersion string to represent CRTM version. */
 | 
				
			||||||
@@ -84,13 +84,13 @@ int mb_crtm(void)
 | 
				
			|||||||
	tcgEventHdr.eventSize = sizeof(crtm_version);
 | 
						tcgEventHdr.eventSize = sizeof(crtm_version);
 | 
				
			||||||
	printk(BIOS_DEBUG, "%s: EventSize - %u\n", __func__, tcgEventHdr.eventSize);
 | 
						printk(BIOS_DEBUG, "%s: EventSize - %u\n", __func__, tcgEventHdr.eventSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = mboot_hash_extend_log(0, (uint8_t *)crtm_version,
 | 
						rc = mboot_hash_extend_log(0, (uint8_t *)crtm_version,
 | 
				
			||||||
				       tcgEventHdr.eventSize, &tcgEventHdr,
 | 
									       tcgEventHdr.eventSize, &tcgEventHdr,
 | 
				
			||||||
				       (uint8_t *)crtm_version);
 | 
									       (uint8_t *)crtm_version);
 | 
				
			||||||
	if (status) {
 | 
						if (rc) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", status);
 | 
							printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", rc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,11 +34,11 @@ static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
 | 
					void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
	if (ret != VB2_SUCCESS) {
 | 
						if (rc != VB2_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
 | 
							printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,11 +14,11 @@
 | 
				
			|||||||
static void mainboard_update_soc_chip_config(void)
 | 
					static void mainboard_update_soc_chip_config(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct soc_intel_jasperlake_config *cfg = config_of_soc();
 | 
						struct soc_intel_jasperlake_config *cfg = config_of_soc();
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
	if (ret != VB2_SUCCESS) {
 | 
						if (rc != VB2_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
 | 
							printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -82,7 +82,7 @@ static void mainboard_enable(struct device *dev)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
 | 
					void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
	if (!CONFIG(TPM_GOOGLE_CR50) || !CONFIG(SPI_TPM)) {
 | 
						if (!CONFIG(TPM_GOOGLE_CR50) || !CONFIG(SPI_TPM)) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Negotiation of long interrupt pulses is only supported via SPI.  I2C is only
 | 
							 * Negotiation of long interrupt pulses is only supported via SPI.  I2C is only
 | 
				
			||||||
@@ -93,9 +93,9 @@ void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
	if (ret != VB2_SUCCESS) {
 | 
						if (rc != VB2_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
 | 
							printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,11 +192,11 @@ int tspi_measure_cache_to_pcr(void)
 | 
				
			|||||||
	i = 0;
 | 
						i = 0;
 | 
				
			||||||
	while (!tpm_log_get(i++, &pcr, &digest_data, &digest_algo, &event_name)) {
 | 
						while (!tpm_log_get(i++, &pcr, &digest_data, &digest_algo, &event_name)) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "TPM: Write digest for %s into PCR %d\n", event_name, pcr);
 | 
							printk(BIOS_DEBUG, "TPM: Write digest for %s into PCR %d\n", event_name, pcr);
 | 
				
			||||||
		int result = tlcl_extend(pcr, digest_data, digest_algo);
 | 
							int rc = tlcl_extend(pcr, digest_data, digest_algo);
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR,
 | 
								printk(BIOS_ERR,
 | 
				
			||||||
			       "TPM: Writing digest of %s into PCR failed with error %d\n",
 | 
								       "TPM: Writing digest of %s into PCR failed with error %d\n",
 | 
				
			||||||
				event_name, result);
 | 
									event_name, rc);
 | 
				
			||||||
			return VB2_ERROR_UNKNOWN;
 | 
								return VB2_ERROR_UNKNOWN;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,49 +15,49 @@ static uint32_t tpm1_invoke_state_machine(void)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t disabled;
 | 
						uint8_t disabled;
 | 
				
			||||||
	uint8_t deactivated;
 | 
						uint8_t deactivated;
 | 
				
			||||||
	uint32_t result = TPM_SUCCESS;
 | 
						uint32_t rc = TPM_SUCCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check that the TPM is enabled and activated. */
 | 
						/* Check that the TPM is enabled and activated. */
 | 
				
			||||||
	result = tlcl_get_flags(&disabled, &deactivated, NULL);
 | 
						rc = tlcl_get_flags(&disabled, &deactivated, NULL);
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't read capabilities.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't read capabilities.\n");
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (disabled) {
 | 
						if (disabled) {
 | 
				
			||||||
		printk(BIOS_INFO, "TPM: is disabled. Enabling...\n");
 | 
							printk(BIOS_INFO, "TPM: is disabled. Enabling...\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		result = tlcl_set_enable();
 | 
							rc = tlcl_set_enable();
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
 | 
								printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
 | 
				
			||||||
			return result;
 | 
								return rc;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!!deactivated != CONFIG(TPM_DEACTIVATE)) {
 | 
						if (!!deactivated != CONFIG(TPM_DEACTIVATE)) {
 | 
				
			||||||
		printk(BIOS_INFO,
 | 
							printk(BIOS_INFO,
 | 
				
			||||||
		       "TPM: Unexpected TPM deactivated state. Toggling...\n");
 | 
							       "TPM: Unexpected TPM deactivated state. Toggling...\n");
 | 
				
			||||||
		result = tlcl_set_deactivated(!deactivated);
 | 
							rc = tlcl_set_deactivated(!deactivated);
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR,
 | 
								printk(BIOS_ERR,
 | 
				
			||||||
			       "TPM: Can't toggle deactivated state.\n");
 | 
								       "TPM: Can't toggle deactivated state.\n");
 | 
				
			||||||
			return result;
 | 
								return rc;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		deactivated = !deactivated;
 | 
							deactivated = !deactivated;
 | 
				
			||||||
		result = TPM_E_MUST_REBOOT;
 | 
							rc = TPM_E_MUST_REBOOT;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t tpm_setup_s3_helper(void)
 | 
					static uint32_t tpm_setup_s3_helper(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_resume();
 | 
						rc = tlcl_resume();
 | 
				
			||||||
	switch (result) {
 | 
						switch (rc) {
 | 
				
			||||||
	case TPM_SUCCESS:
 | 
						case TPM_SUCCESS:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,25 +67,25 @@ static uint32_t tpm_setup_s3_helper(void)
 | 
				
			|||||||
		 * in S3, so it's already initialized.
 | 
							 * in S3, so it's already initialized.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		printk(BIOS_INFO, "TPM: Already initialized.\n");
 | 
							printk(BIOS_INFO, "TPM: Already initialized.\n");
 | 
				
			||||||
		result = TPM_SUCCESS;
 | 
							rc = TPM_SUCCESS;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", result);
 | 
							printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", rc);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t tpm_setup_epilogue(uint32_t result)
 | 
					static uint32_t tpm_setup_epilogue(uint32_t rc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		post_code(POSTCODE_TPM_FAILURE);
 | 
							post_code(POSTCODE_TPM_FAILURE);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		printk(BIOS_INFO, "TPM: setup succeeded\n");
 | 
							printk(BIOS_INFO, "TPM: setup succeeded\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int tpm_is_setup;
 | 
					static int tpm_is_setup;
 | 
				
			||||||
@@ -135,12 +135,12 @@ static inline int tspi_tpm_is_setup(void)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
uint32_t tpm_setup(int s3flag)
 | 
					uint32_t tpm_setup(int s3flag)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't initialize.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't initialize.\n");
 | 
				
			||||||
		return tpm_setup_epilogue(result);
 | 
							return tpm_setup_epilogue(rc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Handle special init for S3 resume path */
 | 
						/* Handle special init for S3 resume path */
 | 
				
			||||||
@@ -149,69 +149,69 @@ uint32_t tpm_setup(int s3flag)
 | 
				
			|||||||
		return tpm_setup_epilogue(tpm_setup_s3_helper());
 | 
							return tpm_setup_epilogue(tpm_setup_s3_helper());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_startup();
 | 
						rc = tlcl_startup();
 | 
				
			||||||
	if (CONFIG(TPM_STARTUP_IGNORE_POSTINIT)
 | 
						if (CONFIG(TPM_STARTUP_IGNORE_POSTINIT)
 | 
				
			||||||
	    && result == TPM_E_INVALID_POSTINIT) {
 | 
						    && rc == TPM_E_INVALID_POSTINIT) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "TPM: ignoring invalid POSTINIT\n");
 | 
							printk(BIOS_DEBUG, "TPM: ignoring invalid POSTINIT\n");
 | 
				
			||||||
		result = TPM_SUCCESS;
 | 
							rc = TPM_SUCCESS;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't run startup command.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't run startup command.\n");
 | 
				
			||||||
		return tpm_setup_epilogue(result);
 | 
							return tpm_setup_epilogue(rc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_assert_physical_presence();
 | 
						rc = tlcl_assert_physical_presence();
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * It is possible that the TPM was delivered with the physical
 | 
							 * It is possible that the TPM was delivered with the physical
 | 
				
			||||||
		 * presence command disabled.  This tries enabling it, then
 | 
							 * presence command disabled.  This tries enabling it, then
 | 
				
			||||||
		 * tries asserting PP again.
 | 
							 * tries asserting PP again.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		result = tlcl_physical_presence_cmd_enable();
 | 
							rc = tlcl_physical_presence_cmd_enable();
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "TPM: Can't enable physical presence command.\n");
 | 
								printk(BIOS_ERR, "TPM: Can't enable physical presence command.\n");
 | 
				
			||||||
			return tpm_setup_epilogue(result);
 | 
								return tpm_setup_epilogue(rc);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		result = tlcl_assert_physical_presence();
 | 
							rc = tlcl_assert_physical_presence();
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "TPM: Can't assert physical presence.\n");
 | 
								printk(BIOS_ERR, "TPM: Can't assert physical presence.\n");
 | 
				
			||||||
			return tpm_setup_epilogue(result);
 | 
								return tpm_setup_epilogue(rc);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if CONFIG(TPM1)
 | 
					#if CONFIG(TPM1)
 | 
				
			||||||
	result = tpm1_invoke_state_machine();
 | 
						rc = tpm1_invoke_state_machine();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	if (CONFIG(TPM_MEASURED_BOOT))
 | 
						if (CONFIG(TPM_MEASURED_BOOT))
 | 
				
			||||||
		result = tspi_measure_cache_to_pcr();
 | 
							rc = tspi_measure_cache_to_pcr();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tpm_is_setup = 1;
 | 
						tpm_is_setup = 1;
 | 
				
			||||||
	return tpm_setup_epilogue(result);
 | 
						return tpm_setup_epilogue(rc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t tpm_clear_and_reenable(void)
 | 
					uint32_t tpm_clear_and_reenable(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	printk(BIOS_INFO, "TPM: Clear and re-enable\n");
 | 
						printk(BIOS_INFO, "TPM: Clear and re-enable\n");
 | 
				
			||||||
	result = tlcl_force_clear();
 | 
						rc = tlcl_force_clear();
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't initiate a force clear.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't initiate a force clear.\n");
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if CONFIG(TPM1)
 | 
					#if CONFIG(TPM1)
 | 
				
			||||||
	result = tlcl_set_enable();
 | 
						rc = tlcl_set_enable();
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_set_deactivated(0);
 | 
						rc = tlcl_set_deactivated(0);
 | 
				
			||||||
	if (result != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Can't set deactivated state.\n");
 | 
							printk(BIOS_ERR, "TPM: Can't set deactivated state.\n");
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -221,24 +221,24 @@ uint32_t tpm_clear_and_reenable(void)
 | 
				
			|||||||
uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo,
 | 
					uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo,
 | 
				
			||||||
			const uint8_t *digest, size_t digest_len, const char *name)
 | 
								const uint8_t *digest, size_t digest_len, const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!digest)
 | 
						if (!digest)
 | 
				
			||||||
		return TPM_E_IOERROR;
 | 
							return TPM_E_IOERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (tspi_tpm_is_setup()) {
 | 
						if (tspi_tpm_is_setup()) {
 | 
				
			||||||
		result = tlcl_lib_init();
 | 
							rc = tlcl_lib_init();
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "TPM: Can't initialize library.\n");
 | 
								printk(BIOS_ERR, "TPM: Can't initialize library.\n");
 | 
				
			||||||
			return result;
 | 
								return rc;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		printk(BIOS_DEBUG, "TPM: Extending digest for `%s` into PCR %d\n", name, pcr);
 | 
							printk(BIOS_DEBUG, "TPM: Extending digest for `%s` into PCR %d\n", name, pcr);
 | 
				
			||||||
		result = tlcl_extend(pcr, digest, digest_algo);
 | 
							rc = tlcl_extend(pcr, digest, digest_algo);
 | 
				
			||||||
		if (result != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "TPM: Extending hash for `%s` into PCR %d failed.\n",
 | 
								printk(BIOS_ERR, "TPM: Extending hash for `%s` into PCR %d failed.\n",
 | 
				
			||||||
			       name, pcr);
 | 
								       name, pcr);
 | 
				
			||||||
			return result;
 | 
								return rc;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,9 +57,9 @@ static inline int tpm_command_size(const uint8_t *buffer)
 | 
				
			|||||||
/* Gets the code field of a TPM command. */
 | 
					/* Gets the code field of a TPM command. */
 | 
				
			||||||
static inline int tpm_command_code(const uint8_t *buffer)
 | 
					static inline int tpm_command_code(const uint8_t *buffer)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t code;
 | 
						uint32_t rc;
 | 
				
			||||||
	from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
 | 
						from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &rc);
 | 
				
			||||||
	return code;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Gets the return code field of a TPM result. */
 | 
					/* Gets the return code field of a TPM result. */
 | 
				
			||||||
@@ -76,27 +76,27 @@ static uint32_t tlcl_send_receive_no_retry(const uint8_t *request,
 | 
				
			|||||||
					   uint8_t *response, int max_length)
 | 
										   uint8_t *response, int max_length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t response_length = max_length;
 | 
						uint32_t response_length = max_length;
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tpm_send_receive(request, tpm_command_size(request),
 | 
						rc = tpm_send_receive(request, tpm_command_size(request),
 | 
				
			||||||
					response, &response_length);
 | 
										response, &response_length);
 | 
				
			||||||
	if (result != 0) {
 | 
						if (rc != 0) {
 | 
				
			||||||
		/* Communication with TPM failed, so response is garbage */
 | 
							/* Communication with TPM failed, so response is garbage */
 | 
				
			||||||
		VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
 | 
							VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
 | 
				
			||||||
			tpm_command_code(request), result);
 | 
								tpm_command_code(request), rc);
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	/* Otherwise, use the result code from the response */
 | 
						/* Otherwise, use the result code from the response */
 | 
				
			||||||
	result = tpm_return_code(response);
 | 
						rc = tpm_return_code(response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* TODO: add paranoia about returned response_length vs. max_length
 | 
						/* TODO: add paranoia about returned response_length vs. max_length
 | 
				
			||||||
	 * (and possibly expected length from the response header).  See
 | 
						 * (and possibly expected length from the response header).  See
 | 
				
			||||||
	 * crosbug.com/17017 */
 | 
						 * crosbug.com/17017 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VBDEBUG("TPM: command 0x%x returned 0x%x\n",
 | 
						VBDEBUG("TPM: command 0x%x returned 0x%x\n",
 | 
				
			||||||
		tpm_command_code(request), result);
 | 
							tpm_command_code(request), rc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return result;
 | 
					return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Sends a TPM command and gets a response.  Returns 0 if success or the TPM
 | 
					/* Sends a TPM command and gets a response.  Returns 0 if success or the TPM
 | 
				
			||||||
@@ -104,17 +104,17 @@ return result;
 | 
				
			|||||||
uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
 | 
					uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
 | 
				
			||||||
			   int max_length)
 | 
								   int max_length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result = tlcl_send_receive_no_retry(request, response,
 | 
						uint32_t rc = tlcl_send_receive_no_retry(request, response,
 | 
				
			||||||
						     max_length);
 | 
											     max_length);
 | 
				
			||||||
	/* If the command fails because the self test has not completed, try it
 | 
						/* If the command fails because the self test has not completed, try it
 | 
				
			||||||
	 * again after attempting to ensure that the self test has completed. */
 | 
						 * again after attempting to ensure that the self test has completed. */
 | 
				
			||||||
	if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
 | 
						if (rc == TPM_E_NEEDS_SELFTEST || rc == TPM_E_DOING_SELFTEST) {
 | 
				
			||||||
		result = tlcl_continue_self_test();
 | 
							rc = tlcl_continue_self_test();
 | 
				
			||||||
		if (result != TPM_SUCCESS)
 | 
							if (rc != TPM_SUCCESS)
 | 
				
			||||||
			return result;
 | 
								return rc;
 | 
				
			||||||
#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
 | 
					#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
 | 
				
			||||||
		/* Retry only once */
 | 
							/* Retry only once */
 | 
				
			||||||
		result = tlcl_send_receive_no_retry(request, response,
 | 
							rc = tlcl_send_receive_no_retry(request, response,
 | 
				
			||||||
						    max_length);
 | 
											    max_length);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
		/* This needs serious testing. The TPM specification says: "iii.
 | 
							/* This needs serious testing. The TPM specification says: "iii.
 | 
				
			||||||
@@ -123,12 +123,12 @@ uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
 | 
				
			|||||||
		 * ContinueSelfTest is non-blocking, how do we know that the
 | 
							 * ContinueSelfTest is non-blocking, how do we know that the
 | 
				
			||||||
		 * actions have completed other than trying again? */
 | 
							 * actions have completed other than trying again? */
 | 
				
			||||||
		do {
 | 
							do {
 | 
				
			||||||
			result = tlcl_send_receive_no_retry(request, response,
 | 
								rc = tlcl_send_receive_no_retry(request, response,
 | 
				
			||||||
							    max_length);
 | 
												    max_length);
 | 
				
			||||||
		} while (result == TPM_E_DOING_SELFTEST);
 | 
							} while (rc == TPM_E_DOING_SELFTEST);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Sends a command and returns the error code. */
 | 
					/* Sends a command and returns the error code. */
 | 
				
			||||||
@@ -226,15 +226,15 @@ uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
 | 
				
			|||||||
	struct s_tpm_nv_read_cmd cmd;
 | 
						struct s_tpm_nv_read_cmd cmd;
 | 
				
			||||||
	uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
						uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
				
			||||||
	uint32_t result_length;
 | 
						uint32_t result_length;
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VBDEBUG("TPM: %s(0x%x, %d)\n", __func__, index, length);
 | 
						VBDEBUG("TPM: %s(0x%x, %d)\n", __func__, index, length);
 | 
				
			||||||
	memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
 | 
						memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
 | 
				
			||||||
	to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index);
 | 
						to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index);
 | 
				
			||||||
	to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length);
 | 
						to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
 | 
						rc = tlcl_send_receive(cmd.buffer, response, sizeof(response));
 | 
				
			||||||
	if (result == TPM_SUCCESS && length > 0) {
 | 
						if (rc == TPM_SUCCESS && length > 0) {
 | 
				
			||||||
		uint8_t *nv_read_cursor = response + kTpmResponseHeaderLength;
 | 
							uint8_t *nv_read_cursor = response + kTpmResponseHeaderLength;
 | 
				
			||||||
		from_tpm_uint32(nv_read_cursor, &result_length);
 | 
							from_tpm_uint32(nv_read_cursor, &result_length);
 | 
				
			||||||
		if (result_length > length)
 | 
							if (result_length > length)
 | 
				
			||||||
@@ -243,7 +243,7 @@ uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
 | 
				
			|||||||
		memcpy(data, nv_read_cursor, result_length);
 | 
							memcpy(data, nv_read_cursor, result_length);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t tlcl_assert_physical_presence(void)
 | 
					uint32_t tlcl_assert_physical_presence(void)
 | 
				
			||||||
@@ -295,24 +295,24 @@ uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
						uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
	uint32_t result = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
 | 
						uint32_t rc = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
 | 
				
			||||||
					    sizeof(response));
 | 
										    sizeof(response));
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	from_tpm_uint32(response + kTpmResponseHeaderLength, &size);
 | 
						from_tpm_uint32(response + kTpmResponseHeaderLength, &size);
 | 
				
			||||||
	if (size != sizeof(TPM_PERMANENT_FLAGS))
 | 
						if (size != sizeof(TPM_PERMANENT_FLAGS))
 | 
				
			||||||
		return TPM_E_IOERROR;
 | 
							return TPM_E_IOERROR;
 | 
				
			||||||
	memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size),
 | 
						memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size),
 | 
				
			||||||
	       sizeof(TPM_PERMANENT_FLAGS));
 | 
						       sizeof(TPM_PERMANENT_FLAGS));
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
 | 
					uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
 | 
				
			||||||
			uint8_t *nvlocked)
 | 
								uint8_t *nvlocked)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	TPM_PERMANENT_FLAGS pflags;
 | 
						TPM_PERMANENT_FLAGS pflags;
 | 
				
			||||||
	uint32_t result = tlcl_get_permanent_flags(&pflags);
 | 
						uint32_t rc = tlcl_get_permanent_flags(&pflags);
 | 
				
			||||||
	if (result == TPM_SUCCESS) {
 | 
						if (rc == TPM_SUCCESS) {
 | 
				
			||||||
		if (disable)
 | 
							if (disable)
 | 
				
			||||||
			*disable = pflags.disable;
 | 
								*disable = pflags.disable;
 | 
				
			||||||
		if (deactivated)
 | 
							if (deactivated)
 | 
				
			||||||
@@ -322,7 +322,7 @@ uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
 | 
				
			|||||||
		VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n",
 | 
							VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n",
 | 
				
			||||||
			pflags.disable, pflags.deactivated, pflags.nvLocked);
 | 
								pflags.disable, pflags.deactivated, pflags.nvLocked);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint32_t tlcl_set_global_lock(void)
 | 
					uint32_t tlcl_set_global_lock(void)
 | 
				
			||||||
@@ -352,16 +352,16 @@ uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
 | 
				
			|||||||
	struct s_tpm_getpermissions_cmd cmd;
 | 
						struct s_tpm_getpermissions_cmd cmd;
 | 
				
			||||||
	uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
						uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
 | 
				
			||||||
	uint8_t *nvdata;
 | 
						uint8_t *nvdata;
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
	uint32_t size;
 | 
						uint32_t size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd));
 | 
						memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd));
 | 
				
			||||||
	to_tpm_uint32(cmd.buffer + tpm_getpermissions_cmd.index, index);
 | 
						to_tpm_uint32(cmd.buffer + tpm_getpermissions_cmd.index, index);
 | 
				
			||||||
	result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
 | 
						rc = tlcl_send_receive(cmd.buffer, response, sizeof(response));
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	nvdata = response + kTpmResponseHeaderLength + sizeof(size);
 | 
						nvdata = response + kTpmResponseHeaderLength + sizeof(size);
 | 
				
			||||||
	from_tpm_uint32(nvdata + kNvDataPublicPermissionsOffset, permissions);
 | 
						from_tpm_uint32(nvdata + kNvDataPublicPermissionsOffset, permissions);
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,11 +18,11 @@
 | 
				
			|||||||
	printk(BIOS_INFO, "%s():%d: " format, __func__, __LINE__, ## args)
 | 
						printk(BIOS_INFO, "%s():%d: " format, __func__, __LINE__, ## args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define RETURN_ON_FAILURE(tpm_cmd) do {				\
 | 
					#define RETURN_ON_FAILURE(tpm_cmd) do {				\
 | 
				
			||||||
		uint32_t result_;					\
 | 
							uint32_t rc_;					\
 | 
				
			||||||
		if ((result_ = (tpm_cmd)) != TPM_SUCCESS) {		\
 | 
							if ((rc_ = (tpm_cmd)) != TPM_SUCCESS) {		\
 | 
				
			||||||
			VBDEBUG("Antirollback: %08x returned by " #tpm_cmd \
 | 
								VBDEBUG("Antirollback: %08x returned by " #tpm_cmd \
 | 
				
			||||||
				 "\n", (int)result_);			\
 | 
									 "\n", (int)rc_);			\
 | 
				
			||||||
			return result_;					\
 | 
								return rc_;					\
 | 
				
			||||||
		}							\
 | 
							}							\
 | 
				
			||||||
	} while (0)
 | 
						} while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,17 +51,17 @@ uint32_t antirollback_read_space_kernel(struct vb2_context *ctx)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint8_t size = VB2_SECDATA_KERNEL_SIZE;
 | 
						uint8_t size = VB2_SECDATA_KERNEL_SIZE;
 | 
				
			||||||
	uint32_t ret;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Start with the version 1.0 size used by all modern Cr50/Ti50 boards. */
 | 
						/* Start with the version 1.0 size used by all modern Cr50/Ti50 boards. */
 | 
				
			||||||
	ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
 | 
						rc = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
 | 
				
			||||||
	if (ret == TPM_E_RANGE) {
 | 
						if (rc == TPM_E_RANGE) {
 | 
				
			||||||
		/* Fallback to version 0.2(minimum) size and re-read. */
 | 
							/* Fallback to version 0.2(minimum) size and re-read. */
 | 
				
			||||||
		VBDEBUG("Antirollback: NV read out of range, trying min size\n");
 | 
							VBDEBUG("Antirollback: NV read out of range, trying min size\n");
 | 
				
			||||||
		size = VB2_SECDATA_KERNEL_MIN_SIZE;
 | 
							size = VB2_SECDATA_KERNEL_MIN_SIZE;
 | 
				
			||||||
		ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
 | 
							rc = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	RETURN_ON_FAILURE(ret);
 | 
						RETURN_ON_FAILURE(rc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (vb2api_secdata_kernel_check(ctx, &size) == VB2_ERROR_SECDATA_KERNEL_INCOMPLETE)
 | 
						if (vb2api_secdata_kernel_check(ctx, &size) == VB2_ERROR_SECDATA_KERNEL_INCOMPLETE)
 | 
				
			||||||
		/* Re-read. vboot will run the check and handle errors. */
 | 
							/* Re-read. vboot will run the check and handle errors. */
 | 
				
			||||||
@@ -206,11 +206,11 @@ static uint32_t define_space(const char *name, uint32_t index, uint32_t length,
 | 
				
			|||||||
			     const TPMA_NV nv_attributes,
 | 
								     const TPMA_NV nv_attributes,
 | 
				
			||||||
			     const uint8_t *nv_policy, size_t nv_policy_size)
 | 
								     const uint8_t *nv_policy, size_t nv_policy_size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = tlcl_define_space(index, length, nv_attributes, nv_policy,
 | 
						rc = tlcl_define_space(index, length, nv_attributes, nv_policy,
 | 
				
			||||||
			       nv_policy_size);
 | 
								       nv_policy_size);
 | 
				
			||||||
	if (rv == TPM_E_NV_DEFINED) {
 | 
						if (rc == TPM_E_NV_DEFINED) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Continue with writing: it may be defined, but not written
 | 
							 * Continue with writing: it may be defined, but not written
 | 
				
			||||||
		 * to. In that case a subsequent tlcl_read() would still return
 | 
							 * to. In that case a subsequent tlcl_read() would still return
 | 
				
			||||||
@@ -220,10 +220,10 @@ static uint32_t define_space(const char *name, uint32_t index, uint32_t length,
 | 
				
			|||||||
		 * in writing once again even if it was written already.
 | 
							 * in writing once again even if it was written already.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		VBDEBUG("%s: %s space already exists\n", __func__, name);
 | 
							VBDEBUG("%s: %s space already exists\n", __func__, name);
 | 
				
			||||||
		rv = TPM_SUCCESS;
 | 
							rc = TPM_SUCCESS;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return rv;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Nothing special in the TPM2 path yet. */
 | 
					/* Nothing special in the TPM2 path yet. */
 | 
				
			||||||
@@ -236,12 +236,12 @@ static uint32_t setup_space(const char *name, uint32_t index, const void *data,
 | 
				
			|||||||
			    uint32_t length, const TPMA_NV nv_attributes,
 | 
								    uint32_t length, const TPMA_NV nv_attributes,
 | 
				
			||||||
			    const uint8_t *nv_policy, size_t nv_policy_size)
 | 
								    const uint8_t *nv_policy, size_t nv_policy_size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = define_space(name, index, length, nv_attributes, nv_policy,
 | 
						rc = define_space(name, index, length, nv_attributes, nv_policy,
 | 
				
			||||||
			  nv_policy_size);
 | 
								  nv_policy_size);
 | 
				
			||||||
	if (rv != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return safe_write(index, data, length);
 | 
						return safe_write(index, data, length);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -291,7 +291,7 @@ static uint32_t set_mrc_hash_space(uint32_t index, const uint8_t *data)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static uint32_t setup_zte_spaces(void)
 | 
					static uint32_t setup_zte_spaces(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
	uint64_t rma_bytes_counter_default = 0;
 | 
						uint64_t rma_bytes_counter_default = 0;
 | 
				
			||||||
	uint8_t rma_sn_bits_default[16];
 | 
						uint8_t rma_sn_bits_default[16];
 | 
				
			||||||
	uint8_t board_id_default[12];
 | 
						uint8_t board_id_default[12];
 | 
				
			||||||
@@ -302,47 +302,47 @@ static uint32_t setup_zte_spaces(void)
 | 
				
			|||||||
	memset(board_id_default, 0xFF, ARRAY_SIZE(board_id_default));
 | 
						memset(board_id_default, 0xFF, ARRAY_SIZE(board_id_default));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set up RMA + SN Bits */
 | 
						/* Set up RMA + SN Bits */
 | 
				
			||||||
	rv = setup_space("RMA + SN Bits", ZTE_RMA_SN_BITS_INDEX,
 | 
						rc = setup_space("RMA + SN Bits", ZTE_RMA_SN_BITS_INDEX,
 | 
				
			||||||
			 rma_sn_bits_default, sizeof(rma_sn_bits_default),
 | 
								 rma_sn_bits_default, sizeof(rma_sn_bits_default),
 | 
				
			||||||
			 zte_attr,
 | 
								 zte_attr,
 | 
				
			||||||
			 unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
								 unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		VBDEBUG("%s: Failed to set up RMA + SN Bits space\n", __func__);
 | 
							VBDEBUG("%s: Failed to set up RMA + SN Bits space\n", __func__);
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = setup_space("Board ID", ZTE_BOARD_ID_NV_INDEX,
 | 
						rc = setup_space("Board ID", ZTE_BOARD_ID_NV_INDEX,
 | 
				
			||||||
			 board_id_default, sizeof(board_id_default),
 | 
								 board_id_default, sizeof(board_id_default),
 | 
				
			||||||
			 zte_attr,
 | 
								 zte_attr,
 | 
				
			||||||
			 unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
								 unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		VBDEBUG("%s: Failed to set up Board ID space\n", __func__);
 | 
							VBDEBUG("%s: Failed to set up Board ID space\n", __func__);
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set up RMA Bytes counter */
 | 
						/* Set up RMA Bytes counter */
 | 
				
			||||||
	rv = define_space("RMA Bytes Counter", ZTE_RMA_BYTES_COUNTER_INDEX,
 | 
						rc = define_space("RMA Bytes Counter", ZTE_RMA_BYTES_COUNTER_INDEX,
 | 
				
			||||||
			  sizeof(rma_bytes_counter_default),
 | 
								  sizeof(rma_bytes_counter_default),
 | 
				
			||||||
			  zte_rma_bytes_attr,
 | 
								  zte_rma_bytes_attr,
 | 
				
			||||||
			  unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
								  unsatisfiable_policy, sizeof(unsatisfiable_policy));
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		VBDEBUG("%s: Failed to define RMA Bytes space\n", __func__);
 | 
							VBDEBUG("%s: Failed to define RMA Bytes space\n", __func__);
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Since the RMA counter has the BITS attribute, we need to call
 | 
						 * Since the RMA counter has the BITS attribute, we need to call
 | 
				
			||||||
	 * TPM2_NV_SetBits() in order to initialize it.
 | 
						 * TPM2_NV_SetBits() in order to initialize it.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	rv = tlcl_set_bits(ZTE_RMA_BYTES_COUNTER_INDEX,
 | 
						rc = tlcl_set_bits(ZTE_RMA_BYTES_COUNTER_INDEX,
 | 
				
			||||||
			   rma_bytes_counter_default);
 | 
								   rma_bytes_counter_default);
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		VBDEBUG("%s: Failed to init RMA Bytes counter space\n",
 | 
							VBDEBUG("%s: Failed to init RMA Bytes counter space\n",
 | 
				
			||||||
			__func__);
 | 
								__func__);
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return rv;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -363,13 +363,17 @@ static uint32_t enterprise_rollback_create_space(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static uint32_t setup_widevine_counter_spaces(void)
 | 
					static uint32_t setup_widevine_counter_spaces(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t index, rv;
 | 
						uint32_t index, rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (index = 0; index < NUM_WIDEVINE_COUNTERS; index++) {
 | 
						for (index = 0; index < NUM_WIDEVINE_COUNTERS; index++) {
 | 
				
			||||||
		rv = define_space(WIDEVINE_COUNTER_NAME, WIDEVINE_COUNTER_NV_INDEX(index),
 | 
							rc = define_space(WIDEVINE_COUNTER_NAME,
 | 
				
			||||||
				WIDEVINE_COUNTER_SIZE, rw_orderly_counter_attributes, NULL, 0);
 | 
									WIDEVINE_COUNTER_NV_INDEX(index),
 | 
				
			||||||
		if (rv != TPM_SUCCESS)
 | 
									WIDEVINE_COUNTER_SIZE,
 | 
				
			||||||
			return rv;
 | 
									rw_orderly_counter_attributes,
 | 
				
			||||||
 | 
									NULL,
 | 
				
			||||||
 | 
									0);
 | 
				
			||||||
 | 
							if (rc != TPM_SUCCESS)
 | 
				
			||||||
 | 
								return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return TPM_SUCCESS;
 | 
						return TPM_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -443,7 +447,7 @@ uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_
 | 
				
			|||||||
uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, uint32_t size)
 | 
					uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, uint32_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t spc_data[HASH_NV_SIZE];
 | 
						uint8_t spc_data[HASH_NV_SIZE];
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (size != HASH_NV_SIZE) {
 | 
						if (size != HASH_NV_SIZE) {
 | 
				
			||||||
		VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
 | 
							VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
 | 
				
			||||||
@@ -452,8 +456,8 @@ uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
 | 
				
			|||||||
		return TPM_E_WRITE_FAILURE;
 | 
							return TPM_E_WRITE_FAILURE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = read_space_mrc_hash(index, spc_data);
 | 
						rc = read_space_mrc_hash(index, spc_data);
 | 
				
			||||||
	if (rv == TPM_E_BADINDEX) {
 | 
						if (rc == TPM_E_BADINDEX) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * If space is not defined already for hash, define
 | 
							 * If space is not defined already for hash, define
 | 
				
			||||||
		 * new space.
 | 
							 * new space.
 | 
				
			||||||
@@ -462,8 +466,8 @@ uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
 | 
				
			|||||||
		return set_mrc_hash_space(index, data);
 | 
							return set_mrc_hash_space(index, data);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (rv != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return safe_write(index, data, size);
 | 
						return safe_write(index, data, size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -493,7 +497,7 @@ uint32_t antirollback_read_space_vbios_hash(uint8_t *data, uint32_t size)
 | 
				
			|||||||
uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
 | 
					uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t spc_data[HASH_NV_SIZE];
 | 
						uint8_t spc_data[HASH_NV_SIZE];
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (size != HASH_NV_SIZE) {
 | 
						if (size != HASH_NV_SIZE) {
 | 
				
			||||||
		VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
 | 
							VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
 | 
				
			||||||
@@ -502,8 +506,8 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
 | 
				
			|||||||
		return TPM_E_WRITE_FAILURE;
 | 
							return TPM_E_WRITE_FAILURE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = read_space_vbios_hash(spc_data);
 | 
						rc = read_space_vbios_hash(spc_data);
 | 
				
			||||||
	if (rv == TPM_E_BADINDEX) {
 | 
						if (rc == TPM_E_BADINDEX) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * If space is not defined already for hash, define
 | 
							 * If space is not defined already for hash, define
 | 
				
			||||||
		 * new space.
 | 
							 * new space.
 | 
				
			||||||
@@ -513,8 +517,8 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
 | 
				
			|||||||
				   rw_space_attributes, NULL, 0);
 | 
									   rw_space_attributes, NULL, 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (rv != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return safe_write(VBIOS_CACHE_NV_INDEX, data, size);
 | 
						return safe_write(VBIOS_CACHE_NV_INDEX, data, size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -530,12 +534,12 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
 | 
					static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result = tlcl_write(index, data, length);
 | 
						uint32_t rc = tlcl_write(index, data, length);
 | 
				
			||||||
	if (result == TPM_E_MAXNVWRITES) {
 | 
						if (rc == TPM_E_MAXNVWRITES) {
 | 
				
			||||||
		RETURN_ON_FAILURE(tpm_clear_and_reenable());
 | 
							RETURN_ON_FAILURE(tpm_clear_and_reenable());
 | 
				
			||||||
		return tlcl_write(index, data, length);
 | 
							return tlcl_write(index, data, length);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -547,26 +551,26 @@ static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size)
 | 
					static uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result = tlcl_define_space(index, perm, size);
 | 
						uint32_t rc = tlcl_define_space(index, perm, size);
 | 
				
			||||||
	if (result == TPM_E_MAXNVWRITES) {
 | 
						if (rc == TPM_E_MAXNVWRITES) {
 | 
				
			||||||
		RETURN_ON_FAILURE(tpm_clear_and_reenable());
 | 
							RETURN_ON_FAILURE(tpm_clear_and_reenable());
 | 
				
			||||||
		return tlcl_define_space(index, perm, size);
 | 
							return tlcl_define_space(index, perm, size);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
 | 
					static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	TPM_PERMANENT_FLAGS pflags;
 | 
						TPM_PERMANENT_FLAGS pflags;
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vb2api_secdata_firmware_create(ctx);
 | 
						vb2api_secdata_firmware_create(ctx);
 | 
				
			||||||
	vb2api_secdata_kernel_create_v0(ctx);
 | 
						vb2api_secdata_kernel_create_v0(ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tlcl_get_permanent_flags(&pflags);
 | 
						rc = tlcl_get_permanent_flags(&pflags);
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * TPM may come from the factory without physical presence finalized.
 | 
						 * TPM may come from the factory without physical presence finalized.
 | 
				
			||||||
@@ -630,7 +634,7 @@ uint32_t antirollback_lock_space_firmware(void)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
 | 
					static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	VBDEBUG("TPM: factory initialization\n");
 | 
						VBDEBUG("TPM: factory initialization\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -642,13 +646,13 @@ static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
 | 
				
			|||||||
	 * test---specifically the ones that set lifetime flags, and are only
 | 
						 * test---specifically the ones that set lifetime flags, and are only
 | 
				
			||||||
	 * executed once per physical TPM.
 | 
						 * executed once per physical TPM.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	result = tlcl_self_test_full();
 | 
						rc = tlcl_self_test_full();
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = _factory_initialize_tpm(ctx);
 | 
						rc = _factory_initialize_tpm(ctx);
 | 
				
			||||||
	if (result != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		return result;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* _factory_initialize_tpm() writes initial secdata values to TPM
 | 
						/* _factory_initialize_tpm() writes initial secdata values to TPM
 | 
				
			||||||
	   immediately, so let vboot know that it's up to date now. */
 | 
						   immediately, so let vboot know that it's up to date now. */
 | 
				
			||||||
@@ -662,15 +666,15 @@ static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
uint32_t antirollback_read_space_firmware(struct vb2_context *ctx)
 | 
					uint32_t antirollback_read_space_firmware(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = tlcl_read(FIRMWARE_NV_INDEX, ctx->secdata_firmware, VB2_SECDATA_FIRMWARE_SIZE);
 | 
						rc = tlcl_read(FIRMWARE_NV_INDEX, ctx->secdata_firmware, VB2_SECDATA_FIRMWARE_SIZE);
 | 
				
			||||||
	if (rv == TPM_E_BADINDEX) {
 | 
						if (rc == TPM_E_BADINDEX) {
 | 
				
			||||||
		/* This seems the first time we've run. Initialize the TPM. */
 | 
							/* This seems the first time we've run. Initialize the TPM. */
 | 
				
			||||||
		VBDEBUG("TPM: Not initialized yet\n");
 | 
							VBDEBUG("TPM: Not initialized yet\n");
 | 
				
			||||||
		RETURN_ON_FAILURE(factory_initialize_tpm(ctx));
 | 
							RETURN_ON_FAILURE(factory_initialize_tpm(ctx));
 | 
				
			||||||
	} else if (rv != TPM_SUCCESS) {
 | 
						} else if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "TPM: Failed to read firmware space: %#x\n", rv);
 | 
							printk(BIOS_ERR, "TPM: Failed to read firmware space: %#x\n", rc);
 | 
				
			||||||
		return TPM_E_CORRUPTED_STATE;
 | 
							return TPM_E_CORRUPTED_STATE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -706,10 +710,10 @@ uint32_t antirollback_write_space_kernel(struct vb2_context *ctx)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
 | 
					vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
	printk(BIOS_INFO, "Clearing TPM owner\n");
 | 
						printk(BIOS_INFO, "Clearing TPM owner\n");
 | 
				
			||||||
	rv = tpm_clear_and_reenable();
 | 
						rc = tpm_clear_and_reenable();
 | 
				
			||||||
	if (rv)
 | 
						if (rc)
 | 
				
			||||||
		return VB2_ERROR_EX_TPM_CLEAR_OWNER;
 | 
							return VB2_ERROR_EX_TPM_CLEAR_OWNER;
 | 
				
			||||||
	return VB2_SUCCESS;
 | 
						return VB2_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,13 +10,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
uint32_t vboot_setup_tpm(struct vb2_context *ctx)
 | 
					uint32_t vboot_setup_tpm(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t result;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = tpm_setup(ctx->flags & VB2_CONTEXT_S3_RESUME);
 | 
						rc = tpm_setup(ctx->flags & VB2_CONTEXT_S3_RESUME);
 | 
				
			||||||
	if (result == TPM_E_MUST_REBOOT)
 | 
						if (rc == TPM_E_MUST_REBOOT)
 | 
				
			||||||
		ctx->flags |= VB2_CONTEXT_SECDATA_WANTS_REBOOT;
 | 
							ctx->flags |= VB2_CONTEXT_SECDATA_WANTS_REBOOT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return result;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vb2_error_t vboot_extend_pcr(struct vb2_context *ctx, int pcr,
 | 
					vb2_error_t vboot_extend_pcr(struct vb2_context *ctx, int pcr,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -127,7 +127,7 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
 | 
				
			|||||||
	const size_t hash_digest_sz = sizeof(hash_digest);
 | 
						const size_t hash_digest_sz = sizeof(hash_digest);
 | 
				
			||||||
	size_t block_size = sizeof(block);
 | 
						size_t block_size = sizeof(block);
 | 
				
			||||||
	size_t offset;
 | 
						size_t offset;
 | 
				
			||||||
	vb2_error_t rv;
 | 
						vb2_error_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Clear the full digest so that any hash digests less than the
 | 
						/* Clear the full digest so that any hash digests less than the
 | 
				
			||||||
	 * max have trailing zeros. */
 | 
						 * max have trailing zeros. */
 | 
				
			||||||
@@ -146,9 +146,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
 | 
				
			|||||||
	offset = 0;
 | 
						offset = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Start the body hash */
 | 
						/* Start the body hash */
 | 
				
			||||||
	rv = vb2api_init_hash(ctx, VB2_HASH_TAG_FW_BODY);
 | 
						rc = vb2api_init_hash(ctx, VB2_HASH_TAG_FW_BODY);
 | 
				
			||||||
	if (rv)
 | 
						if (rc)
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Extend over the body */
 | 
						/* Extend over the body */
 | 
				
			||||||
	while (remaining) {
 | 
						while (remaining) {
 | 
				
			||||||
@@ -161,9 +161,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
 | 
				
			|||||||
			return VB2_ERROR_UNKNOWN;
 | 
								return VB2_ERROR_UNKNOWN;
 | 
				
			||||||
		load_ts += timestamp_get() - temp_ts;
 | 
							load_ts += timestamp_get() - temp_ts;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rv = vb2api_extend_hash(ctx, block, block_size);
 | 
							rc = vb2api_extend_hash(ctx, block, block_size);
 | 
				
			||||||
		if (rv)
 | 
							if (rc)
 | 
				
			||||||
			return rv;
 | 
								return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		remaining -= block_size;
 | 
							remaining -= block_size;
 | 
				
			||||||
		offset += block_size;
 | 
							offset += block_size;
 | 
				
			||||||
@@ -173,9 +173,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
 | 
				
			|||||||
	timestamp_add_now(TS_HASHING_END);
 | 
						timestamp_add_now(TS_HASHING_END);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Check the result (with RSA signature verification) */
 | 
						/* Check the result (with RSA signature verification) */
 | 
				
			||||||
	rv = vb2api_check_hash_get_digest(ctx, hash_digest, hash_digest_sz);
 | 
						rc = vb2api_check_hash_get_digest(ctx, hash_digest, hash_digest_sz);
 | 
				
			||||||
	if (rv)
 | 
						if (rc)
 | 
				
			||||||
		return rv;
 | 
							return rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	timestamp_add_now(TS_HASH_BODY_END);
 | 
						timestamp_add_now(TS_HASH_BODY_END);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -210,10 +210,10 @@ static const char *get_boot_mode_string(uint8_t boot_mode)
 | 
				
			|||||||
static void check_boot_mode(struct vb2_context *ctx)
 | 
					static void check_boot_mode(struct vb2_context *ctx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8_t boot_mode;
 | 
						uint8_t boot_mode;
 | 
				
			||||||
	int rv;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = tlcl_cr50_get_boot_mode(&boot_mode);
 | 
						rc = tlcl_cr50_get_boot_mode(&boot_mode);
 | 
				
			||||||
	switch (rv) {
 | 
						switch (rc) {
 | 
				
			||||||
	case TPM_E_NO_SUCH_COMMAND:
 | 
						case TPM_E_NO_SUCH_COMMAND:
 | 
				
			||||||
		printk(BIOS_WARNING, "GSC does not support GET_BOOT_MODE.\n");
 | 
							printk(BIOS_WARNING, "GSC does not support GET_BOOT_MODE.\n");
 | 
				
			||||||
		/* Proceed to legacy boot model. */
 | 
							/* Proceed to legacy boot model. */
 | 
				
			||||||
@@ -223,7 +223,7 @@ static void check_boot_mode(struct vb2_context *ctx)
 | 
				
			|||||||
	default:
 | 
						default:
 | 
				
			||||||
		printk(BIOS_ERR,
 | 
							printk(BIOS_ERR,
 | 
				
			||||||
		       "Communication error in getting GSC boot mode.\n");
 | 
							       "Communication error in getting GSC boot mode.\n");
 | 
				
			||||||
		vb2api_fail(ctx, VB2_RECOVERY_GSC_BOOT_MODE, rv);
 | 
							vb2api_fail(ctx, VB2_RECOVERY_GSC_BOOT_MODE, rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -208,7 +208,7 @@ static uint32_t save_buffers(void)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static void psp_verstage_s0i3_resume(void)
 | 
					static void psp_verstage_s0i3_resume(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t rv;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	post_code(POSTCODE_VERSTAGE_S0I3_RESUME);
 | 
						post_code(POSTCODE_VERSTAGE_S0I3_RESUME);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -217,15 +217,15 @@ static void psp_verstage_s0i3_resume(void)
 | 
				
			|||||||
	if (!CONFIG(PSP_INIT_TPM_ON_S0I3_RESUME))
 | 
						if (!CONFIG(PSP_INIT_TPM_ON_S0I3_RESUME))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = tpm_setup(true);
 | 
						rc = tpm_setup(true);
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tpm_setup failed rv:%d\n", rv);
 | 
							printk(BIOS_ERR, "tpm_setup failed rc:%d\n", rc);
 | 
				
			||||||
		reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
 | 
							reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rv = tlcl_disable_platform_hierarchy();
 | 
						rc = tlcl_disable_platform_hierarchy();
 | 
				
			||||||
	if (rv != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_disable_platform_hierarchy failed rv:%d\n", rv);
 | 
							printk(BIOS_ERR, "tlcl_disable_platform_hierarchy failed rc:%d\n", rc);
 | 
				
			||||||
		reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
 | 
							reboot_into_recovery(vboot_get_context(), POSTCODE_INIT_TPM_FAILED);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,14 +13,14 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
EFI_TCG2_EVENT_ALGORITHM_BITMAP tpm2_get_active_pcrs(void)
 | 
					EFI_TCG2_EVENT_ALGORITHM_BITMAP tpm2_get_active_pcrs(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
	TPML_PCR_SELECTION Pcrs;
 | 
						TPML_PCR_SELECTION Pcrs;
 | 
				
			||||||
	EFI_TCG2_EVENT_ALGORITHM_BITMAP tpmHashAlgorithmBitmap = 0;
 | 
						EFI_TCG2_EVENT_ALGORITHM_BITMAP tpmHashAlgorithmBitmap = 0;
 | 
				
			||||||
	uint32_t activePcrBanks = 0;
 | 
						uint32_t activePcrBanks = 0;
 | 
				
			||||||
	uint32_t index;
 | 
						uint32_t index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = tpm2_get_capability_pcrs(&Pcrs);
 | 
						rc = tpm2_get_capability_pcrs(&Pcrs);
 | 
				
			||||||
	if (status != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		tpmHashAlgorithmBitmap = EFI_TCG2_BOOT_HASH_ALG_SHA1;
 | 
							tpmHashAlgorithmBitmap = EFI_TCG2_BOOT_HASH_ALG_SHA1;
 | 
				
			||||||
		activePcrBanks = EFI_TCG2_BOOT_HASH_ALG_SHA1;
 | 
							activePcrBanks = EFI_TCG2_BOOT_HASH_ALG_SHA1;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
@@ -78,11 +78,11 @@ EFI_TCG2_EVENT_ALGORITHM_BITMAP tpm2_get_active_pcrs(void)
 | 
				
			|||||||
int tpm2_get_capability_pcrs(TPML_PCR_SELECTION *Pcrs)
 | 
					int tpm2_get_capability_pcrs(TPML_PCR_SELECTION *Pcrs)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	TPMS_CAPABILITY_DATA TpmCap;
 | 
						TPMS_CAPABILITY_DATA TpmCap;
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
	int index;
 | 
						int index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = tlcl_get_capability(TPM_CAP_PCRS, 0, 1, &TpmCap);
 | 
						rc = tlcl_get_capability(TPM_CAP_PCRS, 0, 1, &TpmCap);
 | 
				
			||||||
	if (status == TPM_SUCCESS) {
 | 
						if (rc == TPM_SUCCESS) {
 | 
				
			||||||
		Pcrs->count = TpmCap.data.assignedPCR.count;
 | 
							Pcrs->count = TpmCap.data.assignedPCR.count;
 | 
				
			||||||
		printk(BIOS_DEBUG, "Pcrs->count = %d\n", Pcrs->count);
 | 
							printk(BIOS_DEBUG, "Pcrs->count = %d\n", Pcrs->count);
 | 
				
			||||||
		for (index = 0; index < Pcrs->count; index++) {
 | 
							for (index = 0; index < Pcrs->count; index++) {
 | 
				
			||||||
@@ -97,7 +97,7 @@ int tpm2_get_capability_pcrs(TPML_PCR_SELECTION *Pcrs)
 | 
				
			|||||||
				Pcrs->pcrSelections[index].sizeofSelect);
 | 
									Pcrs->pcrSelections[index].sizeofSelect);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -149,7 +149,7 @@ int mboot_hash_extend_log(uint64_t flags, uint8_t *hashData, uint32_t hashDataLe
 | 
				
			|||||||
void invalidate_pcrs(void)
 | 
					void invalidate_pcrs(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int pcr;
 | 
						int pcr;
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
						TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
				
			||||||
	uint8_t invalidate = 1;
 | 
						uint8_t invalidate = 1;
 | 
				
			||||||
@@ -161,12 +161,12 @@ void invalidate_pcrs(void)
 | 
				
			|||||||
		tcgEventHdr.eventType = EV_NO_ACTION;
 | 
							tcgEventHdr.eventType = EV_NO_ACTION;
 | 
				
			||||||
		tcgEventHdr.eventSize = (uint32_t) sizeof(invalidate);
 | 
							tcgEventHdr.eventSize = (uint32_t) sizeof(invalidate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		status = mboot_hash_extend_log(0, (uint8_t *)&invalidate,
 | 
							rc = mboot_hash_extend_log(0, (uint8_t *)&invalidate,
 | 
				
			||||||
					       tcgEventHdr.eventSize, &tcgEventHdr,
 | 
										       tcgEventHdr.eventSize, &tcgEventHdr,
 | 
				
			||||||
					       (uint8_t *)"Invalidate PCR");
 | 
										       (uint8_t *)"Invalidate PCR");
 | 
				
			||||||
		if (status != TPM_SUCCESS)
 | 
							if (rc != TPM_SUCCESS)
 | 
				
			||||||
			printk(BIOS_DEBUG, "%s: invalidating pcr %d returned"
 | 
								printk(BIOS_DEBUG, "%s: invalidating pcr %d returned"
 | 
				
			||||||
				" 0x%x\n", __func__, pcr, status);
 | 
									" 0x%x\n", __func__, pcr, rc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -230,7 +230,7 @@ void mboot_print_buffer(uint8_t *buffer, uint32_t bufferSize)
 | 
				
			|||||||
int mb_measure_log_worker(const char *name, uint32_t type, uint32_t pcr,
 | 
					int mb_measure_log_worker(const char *name, uint32_t type, uint32_t pcr,
 | 
				
			||||||
			  TCG_EVENTTYPE eventType, const char *event_msg)
 | 
								  TCG_EVENTTYPE eventType, const char *event_msg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
	TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
						TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
				
			||||||
	uint8_t *base;
 | 
						uint8_t *base;
 | 
				
			||||||
	size_t size;
 | 
						size_t size;
 | 
				
			||||||
@@ -250,8 +250,8 @@ int mb_measure_log_worker(const char *name, uint32_t type, uint32_t pcr,
 | 
				
			|||||||
	if (event_msg)
 | 
						if (event_msg)
 | 
				
			||||||
		tcgEventHdr.eventSize = (uint32_t) strlen(event_msg);
 | 
							tcgEventHdr.eventSize = (uint32_t) strlen(event_msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = mboot_hash_extend_log(0, base, size, &tcgEventHdr, (uint8_t *)event_msg);
 | 
						rc = mboot_hash_extend_log(0, base, size, &tcgEventHdr, (uint8_t *)event_msg);
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -273,7 +273,7 @@ int mb_measure_log_worker(const char *name, uint32_t type, uint32_t pcr,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
__weak int mb_entry(int wake_from_s3)
 | 
					__weak int mb_entry(int wake_from_s3)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Initialize TPM driver. */
 | 
						/* Initialize TPM driver. */
 | 
				
			||||||
	printk(BIOS_DEBUG, "%s: tlcl_lib_init\n", __func__);
 | 
						printk(BIOS_DEBUG, "%s: tlcl_lib_init\n", __func__);
 | 
				
			||||||
@@ -284,16 +284,16 @@ __weak int mb_entry(int wake_from_s3)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (wake_from_s3) {
 | 
						if (wake_from_s3) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "%s: tlcl_resume\n", __func__);
 | 
							printk(BIOS_DEBUG, "%s: tlcl_resume\n", __func__);
 | 
				
			||||||
		status = tlcl_resume();
 | 
							rc = tlcl_resume();
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		printk(BIOS_DEBUG, "%s: tlcl_startup\n", __func__);
 | 
							printk(BIOS_DEBUG, "%s: tlcl_startup\n", __func__);
 | 
				
			||||||
		status = tlcl_startup();
 | 
							rc = tlcl_startup();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (status)
 | 
						if (rc)
 | 
				
			||||||
		printk(BIOS_ERR, "%s: StartUp failed 0x%x!\n", __func__, status);
 | 
							printk(BIOS_ERR, "%s: StartUp failed 0x%x!\n", __func__, rc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -317,25 +317,25 @@ __weak int mb_entry(int wake_from_s3)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
__weak int mb_measure(int wake_from_s3)
 | 
					__weak int mb_measure(int wake_from_s3)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint32_t status;
 | 
						uint32_t rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = mb_entry(wake_from_s3);
 | 
						rc = mb_entry(wake_from_s3);
 | 
				
			||||||
	if (status == TPM_SUCCESS) {
 | 
						if (rc == TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "%s: StartUp, successful!\n", __func__);
 | 
							printk(BIOS_DEBUG, "%s: StartUp, successful!\n", __func__);
 | 
				
			||||||
		status = mb_measure_log_start();
 | 
							rc = mb_measure_log_start();
 | 
				
			||||||
		if (status == TPM_SUCCESS) {
 | 
							if (rc == TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_DEBUG, "%s: Measuring, successful!\n", __func__);
 | 
								printk(BIOS_DEBUG, "%s: Measuring, successful!\n", __func__);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			invalidate_pcrs();
 | 
								invalidate_pcrs();
 | 
				
			||||||
			printk(BIOS_ERR, "%s: Measuring returned 0x%x unsuccessful! PCRs invalidated.\n",
 | 
								printk(BIOS_ERR, "%s: Measuring returned 0x%x unsuccessful! PCRs invalidated.\n",
 | 
				
			||||||
			       __func__, status);
 | 
								       __func__, rc);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		invalidate_pcrs();
 | 
							invalidate_pcrs();
 | 
				
			||||||
		printk(BIOS_ERR, "%s: StartUp returned 0x%x, unsuccessful! PCRs invalidated.\n", __func__,
 | 
							printk(BIOS_ERR, "%s: StartUp returned 0x%x, unsuccessful! PCRs invalidated.\n", __func__,
 | 
				
			||||||
		       status);
 | 
							       rc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -359,7 +359,7 @@ __weak int mb_measure(int wake_from_s3)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
__weak int mb_measure_log_start(void)
 | 
					__weak int mb_measure_log_start(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
	uint32_t i;
 | 
						uint32_t i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((tpm2_get_active_pcrs() & EFI_TCG2_BOOT_HASH_ALG_SHA256) == 0x0) {
 | 
						if ((tpm2_get_active_pcrs() & EFI_TCG2_BOOT_HASH_ALG_SHA256) == 0x0) {
 | 
				
			||||||
@@ -368,32 +368,32 @@ __weak int mb_measure_log_start(void)
 | 
				
			|||||||
		return TPM_E_IOERROR;
 | 
							return TPM_E_IOERROR;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = mb_crtm();
 | 
						rc = mb_crtm();
 | 
				
			||||||
	if (status != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "%s: Fail! CRTM Version can't be measured."
 | 
							printk(BIOS_DEBUG, "%s: Fail! CRTM Version can't be measured."
 | 
				
			||||||
			" ABORTING!!!\n", __func__);
 | 
								" ABORTING!!!\n", __func__);
 | 
				
			||||||
		return status;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	printk(BIOS_DEBUG, "%s: Success! CRTM Version measured.\n", __func__);
 | 
						printk(BIOS_DEBUG, "%s: Success! CRTM Version measured.\n", __func__);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Log the items defined by the mainboard */
 | 
						/* Log the items defined by the mainboard */
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(mb_log_list); i++) {
 | 
						for (i = 0; i < ARRAY_SIZE(mb_log_list); i++) {
 | 
				
			||||||
		status = mb_measure_log_worker(
 | 
							rc = mb_measure_log_worker(
 | 
				
			||||||
				mb_log_list[i].cbfs_name,
 | 
									mb_log_list[i].cbfs_name,
 | 
				
			||||||
				mb_log_list[i].cbfs_type, mb_log_list[i].pcr,
 | 
									mb_log_list[i].cbfs_type, mb_log_list[i].pcr,
 | 
				
			||||||
				mb_log_list[i].eventType,
 | 
									mb_log_list[i].eventType,
 | 
				
			||||||
				mb_log_list[i].event_msg);
 | 
									mb_log_list[i].event_msg);
 | 
				
			||||||
		if (status != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_DEBUG, "%s: Fail! %s can't be measured."
 | 
								printk(BIOS_DEBUG, "%s: Fail! %s can't be measured."
 | 
				
			||||||
				"ABORTING!!!\n", __func__,
 | 
									"ABORTING!!!\n", __func__,
 | 
				
			||||||
				mb_log_list[i].cbfs_name);
 | 
									mb_log_list[i].cbfs_name);
 | 
				
			||||||
			return status;
 | 
								return rc;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		printk(BIOS_DEBUG, "%s: Success! %s measured to pcr"
 | 
							printk(BIOS_DEBUG, "%s: Success! %s measured to pcr"
 | 
				
			||||||
			"%d.\n", __func__, mb_log_list[i].cbfs_name,
 | 
								"%d.\n", __func__, mb_log_list[i].cbfs_name,
 | 
				
			||||||
			mb_log_list[i].pcr);
 | 
								mb_log_list[i].pcr);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const uint8_t crtm_version[] =
 | 
					static const uint8_t crtm_version[] =
 | 
				
			||||||
@@ -416,7 +416,7 @@ static const uint8_t crtm_version[] =
 | 
				
			|||||||
**/
 | 
					**/
 | 
				
			||||||
__weak int mb_crtm(void)
 | 
					__weak int mb_crtm(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int rc;
 | 
				
			||||||
	TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
						TCG_PCR_EVENT2_HDR tcgEventHdr;
 | 
				
			||||||
	uint8_t hash[VB2_SHA256_DIGEST_SIZE];
 | 
						uint8_t hash[VB2_SHA256_DIGEST_SIZE];
 | 
				
			||||||
	uint8_t *msgPtr;
 | 
						uint8_t *msgPtr;
 | 
				
			||||||
@@ -430,18 +430,18 @@ __weak int mb_crtm(void)
 | 
				
			|||||||
	printk(BIOS_DEBUG, "%s: EventSize - %u\n", __func__,
 | 
						printk(BIOS_DEBUG, "%s: EventSize - %u\n", __func__,
 | 
				
			||||||
		tcgEventHdr.eventSize);
 | 
							tcgEventHdr.eventSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = mboot_hash_extend_log(0, (uint8_t *)crtm_version, tcgEventHdr.eventSize,
 | 
						rc = mboot_hash_extend_log(0, (uint8_t *)crtm_version, tcgEventHdr.eventSize,
 | 
				
			||||||
				       &tcgEventHdr, (uint8_t *)crtm_version);
 | 
									       &tcgEventHdr, (uint8_t *)crtm_version);
 | 
				
			||||||
	if (status) {
 | 
						if (rc) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", status);
 | 
							printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", rc);
 | 
				
			||||||
		return status;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = get_intel_me_hash(hash);
 | 
						rc = get_intel_me_hash(hash);
 | 
				
			||||||
	if (status) {
 | 
						if (rc) {
 | 
				
			||||||
		printk(BIOS_DEBUG, "get_intel_me_hash returned 0x%x\n", status);
 | 
							printk(BIOS_DEBUG, "get_intel_me_hash returned 0x%x\n", rc);
 | 
				
			||||||
		status = TPM_E_IOERROR;
 | 
							rc = TPM_E_IOERROR;
 | 
				
			||||||
		return status;
 | 
							return rc;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Add the me hash */
 | 
						/* Add the me hash */
 | 
				
			||||||
@@ -453,10 +453,10 @@ __weak int mb_crtm(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	msgPtr = NULL;
 | 
						msgPtr = NULL;
 | 
				
			||||||
	tcgEventHdr.eventSize = 0;
 | 
						tcgEventHdr.eventSize = 0;
 | 
				
			||||||
	status = mboot_hash_extend_log(MBOOT_HASH_PROVIDED, hash, sizeof(hash), &tcgEventHdr,
 | 
						rc = mboot_hash_extend_log(MBOOT_HASH_PROVIDED, hash, sizeof(hash), &tcgEventHdr,
 | 
				
			||||||
				       msgPtr);
 | 
									       msgPtr);
 | 
				
			||||||
	if (status)
 | 
						if (rc)
 | 
				
			||||||
		printk(BIOS_DEBUG, "Add ME hash returned 0x%x\n", status);
 | 
							printk(BIOS_DEBUG, "Add ME hash returned 0x%x\n", rc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return status;
 | 
						return rc;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,27 +25,27 @@ void __weak mainboard_prepare_cr50_reset(void) {}
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static int cr50_is_reset_needed(void)
 | 
					static int cr50_is_reset_needed(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
	uint8_t tpm_mode;
 | 
						uint8_t tpm_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_cr50_get_tpm_mode(&tpm_mode);
 | 
						rc = tlcl_cr50_get_tpm_mode(&tpm_mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ret == TPM_E_NO_SUCH_COMMAND) {
 | 
						if (rc == TPM_E_NO_SUCH_COMMAND) {
 | 
				
			||||||
		printk(BIOS_INFO,
 | 
							printk(BIOS_INFO,
 | 
				
			||||||
		       "Cr50 does not support TPM mode command\n");
 | 
							       "Cr50 does not support TPM mode command\n");
 | 
				
			||||||
		/* Older Cr50 firmware, assume no Cr50 reset is required */
 | 
							/* Older Cr50 firmware, assume no Cr50 reset is required */
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ret == TPM_E_MUST_REBOOT) {
 | 
						if (rc == TPM_E_MUST_REBOOT) {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Cr50 indicated a reboot is required to restore TPM
 | 
							 * Cr50 indicated a reboot is required to restore TPM
 | 
				
			||||||
		 * functionality.
 | 
							 * functionality.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		return 1;
 | 
							return 1;
 | 
				
			||||||
	} else if (ret != TPM_SUCCESS)	{
 | 
						} else if (rc != TPM_SUCCESS)	{
 | 
				
			||||||
		/* TPM command failed, continue booting. */
 | 
							/* TPM command failed, continue booting. */
 | 
				
			||||||
		printk(BIOS_ERR, "Attempt to get CR50 TPM mode failed: %x\n", ret);
 | 
							printk(BIOS_ERR, "Attempt to get CR50 TPM mode failed: %x\n", rc);
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -70,7 +70,7 @@ static int cr50_is_reset_needed(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void enable_update(void *unused)
 | 
					static void enable_update(void *unused)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
	int cr50_reset_reqd = 0;
 | 
						int cr50_reset_reqd = 0;
 | 
				
			||||||
	uint8_t num_restored_headers;
 | 
						uint8_t num_restored_headers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -82,23 +82,23 @@ static void enable_update(void *unused)
 | 
				
			|||||||
	if (vboot_get_context()->flags & VB2_CONTEXT_FORCE_RECOVERY_MODE)
 | 
						if (vboot_get_context()->flags & VB2_CONTEXT_FORCE_RECOVERY_MODE)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ret != VB2_SUCCESS) {
 | 
						if (rc != VB2_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_lib_init() failed for CR50 update: %x\n",
 | 
							printk(BIOS_ERR, "tlcl_lib_init() failed for CR50 update: %x\n",
 | 
				
			||||||
		       ret);
 | 
							       rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	timestamp_add_now(TS_TPM_ENABLE_UPDATE_START);
 | 
						timestamp_add_now(TS_TPM_ENABLE_UPDATE_START);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Reboot in 1000 ms if necessary. */
 | 
						/* Reboot in 1000 ms if necessary. */
 | 
				
			||||||
	ret = tlcl_cr50_enable_update(CR50_RESET_DELAY_MS,
 | 
						rc = tlcl_cr50_enable_update(CR50_RESET_DELAY_MS,
 | 
				
			||||||
				      &num_restored_headers);
 | 
									      &num_restored_headers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ret != TPM_SUCCESS) {
 | 
						if (rc != TPM_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "Attempt to enable CR50 update failed: %x\n",
 | 
							printk(BIOS_ERR, "Attempt to enable CR50 update failed: %x\n",
 | 
				
			||||||
		       ret);
 | 
							       rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -142,16 +142,16 @@ static void enable_update(void *unused)
 | 
				
			|||||||
	 * the mainboard specific code runs.
 | 
						 * the mainboard specific code runs.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (cr50_reset_reqd) {
 | 
						if (cr50_reset_reqd) {
 | 
				
			||||||
		ret = tlcl_cr50_immediate_reset(CR50_RESET_DELAY_MS);
 | 
							rc = tlcl_cr50_immediate_reset(CR50_RESET_DELAY_MS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (ret != TPM_SUCCESS) {
 | 
							if (rc != TPM_SUCCESS) {
 | 
				
			||||||
			/*
 | 
								/*
 | 
				
			||||||
			 * Reset request failed due to TPM error, continue
 | 
								 * Reset request failed due to TPM error, continue
 | 
				
			||||||
			 * booting but the current boot will likely end up at
 | 
								 * booting but the current boot will likely end up at
 | 
				
			||||||
			 * the recovery screen.
 | 
								 * the recovery screen.
 | 
				
			||||||
			 */
 | 
								 */
 | 
				
			||||||
			printk(BIOS_ERR, "Attempt to reset CR50 failed: %x\n",
 | 
								printk(BIOS_ERR, "Attempt to reset CR50 failed: %x\n",
 | 
				
			||||||
			       ret);
 | 
								       rc);
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void cse_board_reset(void)
 | 
					void cse_board_reset(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
	struct cr50_firmware_version version;
 | 
						struct cr50_firmware_version version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (CONFIG(CSE_RESET_CLEAR_EC_AP_IDLE_FLAG))
 | 
						if (CONFIG(CSE_RESET_CLEAR_EC_AP_IDLE_FLAG))
 | 
				
			||||||
@@ -21,9 +21,9 @@ void cse_board_reset(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (CONFIG(TPM2) && CONFIG(TPM_GOOGLE_CR50)) {
 | 
						if (CONFIG(TPM2) && CONFIG(TPM_GOOGLE_CR50)) {
 | 
				
			||||||
		/* Initialize TPM and get the cr50 firmware version. */
 | 
							/* Initialize TPM and get the cr50 firmware version. */
 | 
				
			||||||
		ret = tlcl_lib_init();
 | 
							rc = tlcl_lib_init();
 | 
				
			||||||
		if (ret != VB2_SUCCESS) {
 | 
							if (rc != VB2_SUCCESS) {
 | 
				
			||||||
			printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
 | 
								printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void disable_platform_hierarchy(void *unused)
 | 
					static void disable_platform_hierarchy(void *unused)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int rc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!CONFIG(TPM2))
 | 
						if (!CONFIG(TPM2))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
@@ -15,17 +15,17 @@ static void disable_platform_hierarchy(void *unused)
 | 
				
			|||||||
	if (!CONFIG(RESUME_PATH_SAME_AS_BOOT))
 | 
						if (!CONFIG(RESUME_PATH_SAME_AS_BOOT))
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_lib_init();
 | 
						rc = tlcl_lib_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ret != VB2_SUCCESS) {
 | 
						if (rc != VB2_SUCCESS) {
 | 
				
			||||||
		printk(BIOS_ERR, "tlcl_lib_init() failed: %x\n", ret);
 | 
							printk(BIOS_ERR, "tlcl_lib_init() failed: %x\n", rc);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = tlcl_disable_platform_hierarchy();
 | 
						rc = tlcl_disable_platform_hierarchy();
 | 
				
			||||||
	if (ret != TPM_SUCCESS)
 | 
						if (rc != TPM_SUCCESS)
 | 
				
			||||||
		printk(BIOS_ERR, "Platform hierarchy disablement failed: %x\n",
 | 
							printk(BIOS_ERR, "Platform hierarchy disablement failed: %x\n",
 | 
				
			||||||
			ret);
 | 
								rc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, disable_platform_hierarchy,
 | 
					BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, disable_platform_hierarchy,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user