security/tpm: Drop CAR_GLOBAL_MIGRATION support

Change-Id: I1c09eda6164efb390de4626f52aafba59962f9c4
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37029
Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Arthur Heymans 2019-11-20 19:51:06 +01:00 committed by Patrick Georgi
commit 0ca944b16f
14 changed files with 144 additions and 188 deletions

View file

@ -15,7 +15,6 @@
#include <console/console.h>
#include <security/tpm/tspi.h>
#include <arch/early_variables.h>
#include <region_file.h>
#include <string.h>
#include <security/vboot/symbols.h>

View file

@ -14,7 +14,6 @@
* time.
*/
#include <arch/early_variables.h>
#include <assert.h>
#include <string.h>
#include <security/tpm/tis.h>
@ -148,12 +147,11 @@ static uint32_t send(const uint8_t *command)
/* Exported functions. */
static uint8_t tlcl_init_done CAR_GLOBAL;
static uint8_t tlcl_init_done;
uint32_t tlcl_lib_init(void)
{
uint8_t done = car_get_var(tlcl_init_done);
if (done)
if (tlcl_init_done)
return VB2_SUCCESS;
if (tis_init())
@ -161,7 +159,7 @@ uint32_t tlcl_lib_init(void)
if (tis_open())
return VB2_ERROR_UNKNOWN;
car_set_var(tlcl_init_done, 1);
tlcl_init_done = 1;
return VB2_SUCCESS;
}

View file

@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
#include <arch/early_variables.h>
#include <console/console.h>
#include <endian.h>
#include <string.h>
@ -30,11 +29,9 @@ void *tpm_process_command(TPM_CC command, void *command_body)
size_t in_size;
const uint8_t *sendb;
/* Command/response buffer. */
static uint8_t cr_buffer[TPM_BUFFER_SIZE] CAR_GLOBAL;
static uint8_t cr_buffer[TPM_BUFFER_SIZE];
uint8_t *cr_buffer_ptr = car_get_var_ptr(cr_buffer);
obuf_init(&ob, cr_buffer_ptr, sizeof(cr_buffer));
obuf_init(&ob, cr_buffer, sizeof(cr_buffer));
if (tpm_marshal_command(command, command_body, &ob) < 0) {
printk(BIOS_ERR, "command %#x\n", command);
@ -44,12 +41,12 @@ void *tpm_process_command(TPM_CC command, void *command_body)
sendb = obuf_contents(&ob, &out_size);
in_size = sizeof(cr_buffer);
if (tis_sendrecv(sendb, out_size, cr_buffer_ptr, &in_size)) {
if (tis_sendrecv(sendb, out_size, cr_buffer, &in_size)) {
printk(BIOS_ERR, "tpm transaction failed\n");
return NULL;
}
ibuf_init(&ib, cr_buffer_ptr, in_size);
ibuf_init(&ib, cr_buffer, in_size);
return tpm_unmarshal_response(command, &ib);
}
@ -173,13 +170,12 @@ uint32_t tlcl_force_clear(void)
return TPM_SUCCESS;
}
static uint8_t tlcl_init_done CAR_GLOBAL;
static uint8_t tlcl_init_done;
/* This function is called directly by vboot, uses vboot return types. */
uint32_t tlcl_lib_init(void)
{
uint8_t done = car_get_var(tlcl_init_done);
if (done)
if (tlcl_init_done)
return VB2_SUCCESS;
if (tis_init()) {
@ -192,7 +188,7 @@ uint32_t tlcl_lib_init(void)
return VB2_ERROR_UNKNOWN;
}
car_set_var(tlcl_init_done, 1);
tlcl_init_done = 1;
return VB2_SUCCESS;
}

View file

@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
#include <arch/early_variables.h>
#include <commonlib/iobuf.h>
#include <console/console.h>
#include <stdlib.h>
@ -15,7 +14,7 @@
#include <security/tpm/tss/vendor/cr50/cr50.h>
#include <security/tpm/tss.h>
static uint16_t tpm_tag CAR_GLOBAL; /* Depends on the command type. */
static uint16_t tpm_tag; /* Depends on the command type. */
#define unmarshal_TPM_CAP(a, b) ibuf_read_be32(a, b)
#define unmarshal_TPM_CC(a, b) ibuf_read_be32(a, b)
@ -165,7 +164,7 @@ static int marshal_common_session_header(struct obuf *ob,
struct tpm2_session_header session_header;
int rc = 0;
car_set_var(tpm_tag, TPM_ST_SESSIONS);
tpm_tag = TPM_ST_SESSIONS;
for (i = 0; i < handle_count; i++)
rc |= marshal_TPM_HANDLE(ob, handles[i]);
@ -270,7 +269,7 @@ static int marshal_hierarchy_control(struct obuf *ob,
int rc = 0;
struct tpm2_session_header session_header;
car_set_var(tpm_tag, TPM_ST_SESSIONS);
tpm_tag = TPM_ST_SESSIONS;
rc |= marshal_TPM_HANDLE(ob, TPM_RH_PLATFORM);
memset(&session_header, 0, sizeof(session_header));
@ -335,7 +334,7 @@ int tpm_marshal_command(TPM_CC command, void *tpm_command_body, struct obuf *ob)
const size_t hdr_sz = sizeof(uint16_t) + 2 * sizeof(uint32_t);
int rc = 0;
car_set_var(tpm_tag, TPM_ST_NO_SESSIONS);
tpm_tag = TPM_ST_NO_SESSIONS;
if (obuf_splice_current(ob, &ob_hdr, hdr_sz) < 0)
return -1;
@ -407,7 +406,7 @@ int tpm_marshal_command(TPM_CC command, void *tpm_command_body, struct obuf *ob)
return rc;
/* Fix up the command header with known values. */
rc |= obuf_write_be16(&ob_hdr, car_get_var(tpm_tag));
rc |= obuf_write_be16(&ob_hdr, tpm_tag);
rc |= obuf_write_be32(&ob_hdr, obuf_nr_written(ob));
return rc;
@ -552,23 +551,22 @@ static int unmarshal_vendor_command(struct ibuf *ib,
struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
{
static struct tpm2_response tpm2_static_resp CAR_GLOBAL;
struct tpm2_response *tpm2_resp = car_get_var_ptr(&tpm2_static_resp);
static struct tpm2_response tpm2_static_resp;
int rc = 0;
rc |= ibuf_read_be16(ib, &tpm2_resp->hdr.tpm_tag);
rc |= ibuf_read_be32(ib, &tpm2_resp->hdr.tpm_size);
rc |= unmarshal_TPM_CC(ib, &tpm2_resp->hdr.tpm_code);
rc |= ibuf_read_be16(ib, &tpm2_static_resp.hdr.tpm_tag);
rc |= ibuf_read_be32(ib, &tpm2_static_resp.hdr.tpm_size);
rc |= unmarshal_TPM_CC(ib, &tpm2_static_resp.hdr.tpm_code);
if (rc != 0)
return NULL;
if (ibuf_remaining(ib) == 0) {
if (tpm2_resp->hdr.tpm_size != ibuf_nr_read(ib))
if (tpm2_static_resp.hdr.tpm_size != ibuf_nr_read(ib))
printk(BIOS_ERR,
"%s: size mismatch in response to command %#x\n",
__func__, command);
return tpm2_resp;
return &tpm2_static_resp;
}
switch (command) {
@ -577,11 +575,11 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
break;
case TPM2_GetCapability:
rc |= unmarshal_get_capability(ib, &tpm2_resp->gc);
rc |= unmarshal_get_capability(ib, &tpm2_static_resp.gc);
break;
case TPM2_NV_Read:
rc |= unmarshal_nv_read(ib, &tpm2_resp->nvr);
rc |= unmarshal_nv_read(ib, &tpm2_static_resp.nvr);
break;
case TPM2_Hierarchy_Control:
@ -595,7 +593,7 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
break;
case TPM2_CR50_VENDOR_COMMAND:
rc |= unmarshal_vendor_command(ib, &tpm2_resp->vcr);
rc |= unmarshal_vendor_command(ib, &tpm2_static_resp.vcr);
break;
default:
@ -608,7 +606,7 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
"Request to unmarshal unexpected command %#x,"
" code %#x",
__func__, __LINE__, command,
tpm2_resp->hdr.tpm_code);
tpm2_static_resp.hdr.tpm_code);
sz_left = ibuf_remaining(ib);
data = ibuf_oob_drain(ib, sz_left);
@ -627,7 +625,7 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
printk(BIOS_INFO,
"%s:%d got %d bytes back in response to %#x,"
" failed to parse (%zd)\n",
__func__, __LINE__, tpm2_resp->hdr.tpm_size,
__func__, __LINE__, tpm2_static_resp.hdr.tpm_size,
command, ibuf_remaining(ib));
return NULL;
}
@ -636,5 +634,5 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
__func__);
/* The entire message have been parsed. */
return tpm2_resp;
return &tpm2_static_resp;
}

View file

@ -4,7 +4,6 @@
* found in the LICENSE file.
*/
#include <arch/early_variables.h>
#include <console/console.h>
#include <endian.h>
#include <vb2_api.h>