[coreboot-gerrit] Change in coreboot[master]: util/cbmem: Add CBMEM TCPA log support

Philipp Deppenwiese (Code Review) gerrit at coreboot.org
Sun May 13 12:43:44 CEST 2018


Philipp Deppenwiese has uploaded this change for review. ( https://review.coreboot.org/26244


Change subject: util/cbmem: Add CBMEM TCPA log support
......................................................................

util/cbmem: Add CBMEM TCPA log support

* Read and print the TCPA ACPI log.

Change-Id: Ie2253d86cfc675d45b0a728794cc784215401f4a
Signed-off-by: Philipp Deppenwiese <zaolin at das-labor.org>
---
M src/commonlib/include/commonlib/coreboot_tables.h
M src/lib/coreboot_table.c
M util/cbmem/cbmem.c
3 files changed, 71 insertions(+), 7 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/44/26244/1

diff --git a/src/commonlib/include/commonlib/coreboot_tables.h b/src/commonlib/include/commonlib/coreboot_tables.h
index f411ff2..c350cda 100644
--- a/src/commonlib/include/commonlib/coreboot_tables.h
+++ b/src/commonlib/include/commonlib/coreboot_tables.h
@@ -310,6 +310,7 @@
 #define LB_TAG_CBMEM_CONSOLE	0x0017
 #define LB_TAG_MRC_CACHE	0x0018
 #define LB_TAG_ACPI_GNVS	0x0024
+#define LB_TAG_TCPA_LOG   0x0034
 #define LB_TAG_WIFI_CALIBRATION	0x0027
 #define LB_TAG_VPD		0x002c
 struct lb_cbmem_ref {
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index d03b771..43af395 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -342,7 +342,8 @@
 		{CBMEM_ID_CONSOLE, LB_TAG_CBMEM_CONSOLE},
 		{CBMEM_ID_ACPI_GNVS, LB_TAG_ACPI_GNVS},
 		{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;
 
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index eae5da3..f91bb6f 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -34,6 +34,7 @@
 #include <regex.h>
 #include <commonlib/cbmem_id.h>
 #include <commonlib/timestamp_serialized.h>
+#include <commonlib/tcpa_log_serialized.h>
 #include <commonlib/coreboot_tables.h>
 
 #ifdef __OpenBSD__
@@ -264,6 +265,7 @@
 
 static struct lb_cbmem_ref timestamps;
 static struct lb_cbmem_ref console;
+static struct lb_cbmem_ref tcpa_log;
 static struct lb_memory_range cbmem;
 
 /* This is a work-around for a nasty problem introduced by initially having
@@ -308,7 +310,7 @@
 static int parse_cbtable_entries(const struct mapping *table_mapping)
 {
 	size_t i;
-	const struct lb_record* lbr_p;
+	const struct lb_record *lbr_p;
 	size_t table_size = mapping_size(table_mapping);
 	const void *lbtable = mapping_virt(table_mapping);
 	int forwarding_table_found = 0;
@@ -323,12 +325,19 @@
 			continue;
 		case LB_TAG_TIMESTAMPS: {
 			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;
 		}
 		case LB_TAG_CBMEM_CONSOLE: {
 			debug("    Found cbmem console.\n");
-			console = parse_cbmem_ref((struct lb_cbmem_ref *) lbr_p);
+			console = parse_cbmem_ref((struct lb_cbmem_ref *)lbr_p);
+			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: {
@@ -338,7 +347,7 @@
 			 * search at the new address.
 			 */
 			struct lb_forward lbf_p =
-				*(const struct lb_forward *) lbr_p;
+			    *(const struct lb_forward *)lbr_p;
 			debug("    Found forwarding entry.\n");
 			ret = parse_cbtable(lbf_p.forward, 0);
 
@@ -651,6 +660,49 @@
 	unmap_memory(&timestamp_mapping);
 }
 
+/* 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");
+
+	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 {
 	u32 size;
 	u32 cursor;
@@ -1028,7 +1080,7 @@
 
 static void print_usage(const char *name, int exit_code)
 {
-	printf("usage: %s [-cCltTxVvh?]\n", name);
+	printf("usage: %s [-cCltTLxVvh?]\n", name);
 	printf("\n"
 	     "   -c | --console:                   print cbmem console\n"
 	     "   -1 | --oneboot:                   print cbmem console for last boot only\n"
@@ -1038,6 +1090,7 @@
 	     "   -r | --rawdump ID:                print rawdump of specific ID (in hex) of cbtable\n"
 	     "   -t | --timestamps:                print timestamp information\n"
 	     "   -T | --parseable-timestamps:      print parseable timestamps\n"
+	     "   -L | --tcpa-log                   print TCPA log\n"
 	     "   -V | --verbose:                   verbose (debugging) output\n"
 	     "   -v | --version:                   print the version\n"
 	     "   -h | --help:                      print this help\n"
@@ -1169,6 +1222,7 @@
 	int print_hexdump = 0;
 	int print_rawdump = 0;
 	int print_timestamps = 0;
+	int print_tcpa_log = 0;
 	int machine_readable_timestamps = 0;
 	int one_boot_only = 0;
 	unsigned int rawdump_id = 0;
@@ -1181,6 +1235,7 @@
 		{"list", 0, 0, 'l'},
 		{"timestamps", 0, 0, 't'},
 		{"parseable-timestamps", 0, 0, 'T'},
+		{"tcpa-log", 0, 0, 'L'},
 		{"hexdump", 0, 0, 'x'},
 		{"rawdump", required_argument, 0, 'r'},
 		{"verbose", 0, 0, 'V'},
@@ -1188,7 +1243,7 @@
 		{"help", 0, 0, 'h'},
 		{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) {
 		switch (opt) {
 		case 'c':
@@ -1226,6 +1281,10 @@
 			machine_readable_timestamps = 1;
 			print_defaults = 0;
 			break;
+		case 'L':
+			print_tcpa_log = 1;
+			print_defaults = 0;
+			break;
 		case 'V':
 			verbose = 1;
 			break;
@@ -1334,6 +1393,9 @@
 	if (print_defaults || print_timestamps)
 		dump_timestamps(machine_readable_timestamps);
 
+	if (print_defaults || print_tcpa_log)
+		dump_tcpa_log();
+
 	unmap_memory(&lbtable_mapping);
 
 	close(mem_fd);

-- 
To view, visit https://review.coreboot.org/26244
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2253d86cfc675d45b0a728794cc784215401f4a
Gerrit-Change-Number: 26244
Gerrit-PatchSet: 1
Gerrit-Owner: Philipp Deppenwiese <zaolin.daisuki at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180513/158cfb8b/attachment.html>


More information about the coreboot-gerrit mailing list