util/cbmem: Add cbmem TCPA log support

* Read and print the TCPA ACPI log.

Change-Id: Ie2253d86cfc675d45b0a728794cc784215401f4a
Signed-off-by: Philipp Deppenwiese <zaolin@das-labor.org>
Reviewed-on: https://review.coreboot.org/26244
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
This commit is contained in:
Philipp Deppenwiese 2018-05-13 12:42:42 +02:00 committed by Philipp Deppenwiese
parent f18dc5c72c
commit fa1f6ff09e
3 changed files with 73 additions and 7 deletions

View File

@ -310,6 +310,7 @@ void lb_ramoops(struct lb_header *header);
#define LB_TAG_CBMEM_CONSOLE 0x0017 #define LB_TAG_CBMEM_CONSOLE 0x0017
#define LB_TAG_MRC_CACHE 0x0018 #define LB_TAG_MRC_CACHE 0x0018
#define LB_TAG_ACPI_GNVS 0x0024 #define LB_TAG_ACPI_GNVS 0x0024
#define LB_TAG_TCPA_LOG 0x0034
#define LB_TAG_WIFI_CALIBRATION 0x0027 #define LB_TAG_WIFI_CALIBRATION 0x0027
#define LB_TAG_VPD 0x002c #define LB_TAG_VPD 0x002c
struct lb_cbmem_ref { struct lb_cbmem_ref {

View File

@ -339,7 +339,8 @@ static void add_cbmem_pointers(struct lb_header *header)
{CBMEM_ID_CONSOLE, LB_TAG_CBMEM_CONSOLE}, {CBMEM_ID_CONSOLE, LB_TAG_CBMEM_CONSOLE},
{CBMEM_ID_ACPI_GNVS, LB_TAG_ACPI_GNVS}, {CBMEM_ID_ACPI_GNVS, LB_TAG_ACPI_GNVS},
{CBMEM_ID_VPD, LB_TAG_VPD}, {CBMEM_ID_VPD, LB_TAG_VPD},
{CBMEM_ID_WIFI_CALIBRATION, LB_TAG_WIFI_CALIBRATION} {CBMEM_ID_WIFI_CALIBRATION, LB_TAG_WIFI_CALIBRATION},
{CBMEM_ID_TCPA_LOG, LB_TAG_TCPA_LOG}
}; };
int i; int i;

View File

@ -34,6 +34,7 @@
#include <regex.h> #include <regex.h>
#include <commonlib/cbmem_id.h> #include <commonlib/cbmem_id.h>
#include <commonlib/timestamp_serialized.h> #include <commonlib/timestamp_serialized.h>
#include <commonlib/tcpa_log_serialized.h>
#include <commonlib/coreboot_tables.h> #include <commonlib/coreboot_tables.h>
#ifdef __OpenBSD__ #ifdef __OpenBSD__
@ -264,6 +265,7 @@ static int find_cbmem_entry(uint32_t id, uint64_t *addr, size_t *size)
static struct lb_cbmem_ref timestamps; static struct lb_cbmem_ref timestamps;
static struct lb_cbmem_ref console; static struct lb_cbmem_ref console;
static struct lb_cbmem_ref tcpa_log;
static struct lb_memory_range cbmem; static struct lb_memory_range cbmem;
/* This is a work-around for a nasty problem introduced by initially having /* This is a work-around for a nasty problem introduced by initially having
@ -323,7 +325,8 @@ static int parse_cbtable_entries(const struct mapping *table_mapping)
continue; continue;
case LB_TAG_TIMESTAMPS: { case LB_TAG_TIMESTAMPS: {
debug(" Found timestamp table.\n"); debug(" Found timestamp table.\n");
timestamps = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p); timestamps =
parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
continue; continue;
} }
case LB_TAG_CBMEM_CONSOLE: { case LB_TAG_CBMEM_CONSOLE: {
@ -331,6 +334,12 @@ static int parse_cbtable_entries(const struct mapping *table_mapping)
console = parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p); console = parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
continue; continue;
} }
case LB_TAG_TCPA_LOG: {
debug(" Found tcpa log table.\n");
tcpa_log =
parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
continue;
}
case LB_TAG_FORWARD: { case LB_TAG_FORWARD: {
int ret; int ret;
/* /*
@ -674,6 +683,51 @@ static void dump_timestamps(int mach_readable)
free(sorted_tst_p); free(sorted_tst_p);
} }
/* dump the tcpa log table */
static void dump_tcpa_log(void)
{
int i, j;
const struct tcpa_table *tclt_p;
size_t size;
struct mapping tcpa_mapping;
char log_string[TCPA_LOG_STRING_LENGTH];
char hash[TCPA_FORMAT_HASH_LENGTH];
if (tcpa_log.tag != LB_TAG_TCPA_LOG) {
fprintf(stderr, "No tcpa log found in coreboot table.\n");
return;
}
size = sizeof(*tclt_p);
tclt_p = map_memory(&tcpa_mapping, tcpa_log.cbmem_addr, size);
if (!tclt_p)
die("Unable to map tcpa log header\n");
size += tclt_p->num_entries * sizeof(tclt_p->entries[0]);
unmap_memory(&tcpa_mapping);
tclt_p = map_memory(&tcpa_mapping, tcpa_log.cbmem_addr, size);
if (!tclt_p)
die("Unable to map full tcpa log table\n");
printf("coreboot TCPA log:\n\n");
for (i = 0; i < tclt_p->num_entries; i++) {
const struct tcpa_entry *tce = &tclt_p->entries[i];
memset(log_string, 0, TCPA_LOG_STRING_LENGTH);
for (j = 0; j < tce->digest_length; j++)
sprintf((char *)&(hash[j * 2]), "%02x", tce->digest[j]);
snprintf(log_string, TCPA_LOG_STRING_LENGTH, "%u %s 00 [%s]\n",
tce->pcr, hash, tce->name);
printf("%s", log_string);
}
unmap_memory(&tcpa_mapping);
}
struct cbmem_console { struct cbmem_console {
u32 size; u32 size;
u32 cursor; u32 cursor;
@ -1051,7 +1105,7 @@ static void print_version(void)
static void print_usage(const char *name, int exit_code) static void print_usage(const char *name, int exit_code)
{ {
printf("usage: %s [-cCltTxVvh?]\n", name); printf("usage: %s [-cCltTLxVvh?]\n", name);
printf("\n" printf("\n"
" -c | --console: print cbmem console\n" " -c | --console: print cbmem console\n"
" -1 | --oneboot: print cbmem console for last boot only\n" " -1 | --oneboot: print cbmem console for last boot only\n"
@ -1061,6 +1115,7 @@ static void print_usage(const char *name, int exit_code)
" -r | --rawdump ID: print rawdump of specific ID (in hex) of cbtable\n" " -r | --rawdump ID: print rawdump of specific ID (in hex) of cbtable\n"
" -t | --timestamps: print timestamp information\n" " -t | --timestamps: print timestamp information\n"
" -T | --parseable-timestamps: print parseable timestamps\n" " -T | --parseable-timestamps: print parseable timestamps\n"
" -L | --tcpa-log print TCPA log\n"
" -V | --verbose: verbose (debugging) output\n" " -V | --verbose: verbose (debugging) output\n"
" -v | --version: print the version\n" " -v | --version: print the version\n"
" -h | --help: print this help\n" " -h | --help: print this help\n"
@ -1192,6 +1247,7 @@ int main(int argc, char** argv)
int print_hexdump = 0; int print_hexdump = 0;
int print_rawdump = 0; int print_rawdump = 0;
int print_timestamps = 0; int print_timestamps = 0;
int print_tcpa_log = 0;
int machine_readable_timestamps = 0; int machine_readable_timestamps = 0;
int one_boot_only = 0; int one_boot_only = 0;
unsigned int rawdump_id = 0; unsigned int rawdump_id = 0;
@ -1202,6 +1258,7 @@ int main(int argc, char** argv)
{"oneboot", 0, 0, '1'}, {"oneboot", 0, 0, '1'},
{"coverage", 0, 0, 'C'}, {"coverage", 0, 0, 'C'},
{"list", 0, 0, 'l'}, {"list", 0, 0, 'l'},
{"tcpa-log", 0, 0, 'L'},
{"timestamps", 0, 0, 't'}, {"timestamps", 0, 0, 't'},
{"parseable-timestamps", 0, 0, 'T'}, {"parseable-timestamps", 0, 0, 'T'},
{"hexdump", 0, 0, 'x'}, {"hexdump", 0, 0, 'x'},
@ -1211,7 +1268,7 @@ int main(int argc, char** argv)
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
while ((opt = getopt_long(argc, argv, "c1CltTxVvh?r:", while ((opt = getopt_long(argc, argv, "c1CltTLxVvh?r:",
long_options, &option_index)) != EOF) { long_options, &option_index)) != EOF) {
switch (opt) { switch (opt) {
case 'c': case 'c':
@ -1231,6 +1288,10 @@ int main(int argc, char** argv)
print_list = 1; print_list = 1;
print_defaults = 0; print_defaults = 0;
break; break;
case 'L':
print_tcpa_log = 1;
print_defaults = 0;
break;
case 'x': case 'x':
print_hexdump = 1; print_hexdump = 1;
print_defaults = 0; print_defaults = 0;
@ -1357,6 +1418,9 @@ int main(int argc, char** argv)
if (print_defaults || print_timestamps) if (print_defaults || print_timestamps)
dump_timestamps(machine_readable_timestamps); dump_timestamps(machine_readable_timestamps);
if (print_tcpa_log)
dump_tcpa_log();
unmap_memory(&lbtable_mapping); unmap_memory(&lbtable_mapping);
close(mem_fd); close(mem_fd);