Kapil Porwal has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/85573?usp=email )
Change subject: util/cbmem: Add a new option to parse self test report ......................................................................
util/cbmem: Add a new option to parse self test report
This patch adds a new option 'cbmem -s' to parse and print the self test report to the cbmem command.
The format of self test report is as below - +---------------|--------------+ | Self Test ID | Status | | < 32bit > | < 32bit > | -------------------------------- | xx | 0 (pass) | -------------------------------- | yy | 3 (fail) | -------------------------------- | | | -------------------------------- | | | | | | | | | | | | | | | -------------------------------- | 0 | 0 | +---------------|--------------+
BUG=b:233012780 TEST=Run the 'cbmem -s' command and verify the output
Sample output: ``` $ cbmem -h usage: cbmem [-cCltTsLxVvh?]
-c | --console: print cbmem console -1 | --oneboot: print cbmem console for last boot only -2 | --2ndtolast: print cbmem console for the boot that came before the last one only -B | --loglevel: maximum loglevel to print; prefix `+` (e.g. -B +INFO) to also print lines that have no level -C | --coverage: dump coverage information -l | --list: print cbmem table of contents -x | --hexdump: print hexdump of cbmem area -r | --rawdump ID: print rawdump of specific ID (in hex) of cbtable -t | --timestamps: print timestamp information -T | --parseable-timestamps: print parseable timestamps -S | --stacked-timestamps: print stacked timestamps (e.g. for flame graph tools) -s | --self-test-report: print self test report -a | --add-timestamp ID: append timestamp with ID -L | --tcpa-log print TPM log -V | --verbose: verbose (debugging) output -v | --version: print the version -h | --help: print this help
$ cbmem -s ID Name Result 1 Intel_microcode_patch_loaded PASSED ```
Change-Id: I5f7233996cfb0b59f035811cc866475e26214739 Signed-off-by: Kapil Porwal kapilporwal@google.com --- M util/cbmem/cbmem.c 1 file changed, 70 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/85573/1
diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 15b6770..7e711c8 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -22,6 +22,7 @@ #include <commonlib/bsd/ipchksum.h> #include <commonlib/bsd/tpm_log_defs.h> #include <commonlib/loglevel.h> +#include <commonlib/self_test.h> #include <commonlib/timestamp_serialized.h> #include <commonlib/tpm_log_serialized.h> #include <commonlib/coreboot_tables.h> @@ -1436,6 +1437,63 @@ } }
+/* Function to get Test name from Test ID */ +static const char *st_get_name(uint32_t id) +{ + for (size_t i = 0; i < ARRAY_SIZE(st_ids); i++) { + if (st_ids[i].id == id) + return st_ids[i].name; + } + return NULL; +} + +static void dump_self_test_report(void) +{ + const uint8_t *table; + size_t offset; + + table = mapping_virt(&lbtable_mapping); + + if (table == NULL) + return; + + offset = 0; + + while (offset < mapping_size(&lbtable_mapping)) { + const struct lb_record *lbr; + struct lb_cbmem_entry lbe; + struct mapping st_mapping; + struct self_test_log *logs; + + lbr = (const void *)(table + offset); + offset += lbr->size; + + if (lbr->tag != LB_TAG_CBMEM_ENTRY) + continue; + + aligned_memcpy(&lbe, lbr, sizeof(lbe)); + + if (lbe.id != CBMEM_ID_SELF_TEST) + continue; + + logs = (struct self_test_log *)map_memory(&st_mapping, lbe.address, + lbe.entry_size); + if (logs == NULL) { + printf("Self test report not found!\n"); + return; + } + + printf("%-8s %-50s %-10s\n", "ID", "Name", "Result"); + while (logs->id != ST_INVALID_ID) { + printf("%-8x %-50s %-10s\n", logs->id, st_get_name(logs->id), + st_status_str[logs->status]); + logs++; + } + + unmap_memory(&st_mapping); + } +} + #define COVERAGE_MAGIC 0x584d4153 struct file { uint32_t magic; @@ -1536,7 +1594,7 @@
static void print_usage(const char *name, int exit_code) { - printf("usage: %s [-cCltTLxVvh?]\n", name); + printf("usage: %s [-cCltTsLxVvh?]\n", name); printf("\n" " -c | --console: print cbmem console\n" " -1 | --oneboot: print cbmem console for last boot only\n" @@ -1549,6 +1607,7 @@ " -t | --timestamps: print timestamp information\n" " -T | --parseable-timestamps: print parseable timestamps\n" " -S | --stacked-timestamps: print stacked timestamps (e.g. for flame graph tools)\n" + " -s | --self-test-report: print self test report\n" " -a | --add-timestamp ID: append timestamp with ID\n" " -L | --tcpa-log print TPM log\n" " -V | --verbose: verbose (debugging) output\n" @@ -1682,6 +1741,7 @@ int print_hexdump = 0; int print_rawdump = 0; int print_tcpa_log = 0; + int print_self_test_report = 0; enum timestamps_print_type timestamp_type = TIMESTAMPS_PRINT_NONE; enum console_print_type console_type = CONSOLE_PRINT_FULL; unsigned int rawdump_id = 0; @@ -1701,6 +1761,7 @@ {"timestamps", 0, 0, 't'}, {"parseable-timestamps", 0, 0, 'T'}, {"stacked-timestamps", 0, 0, 'S'}, + {"self-test-report", 0, 0, 's'}, {"add-timestamp", required_argument, 0, 'a'}, {"hexdump", 0, 0, 'x'}, {"rawdump", required_argument, 0, 'r'}, @@ -1709,7 +1770,7 @@ {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; - while ((opt = getopt_long(argc, argv, "c12B:CltTSa:LxVvh?r:", + while ((opt = getopt_long(argc, argv, "c12B:CltTSsa:LxVvh?r:", long_options, &option_index)) != EOF) { switch (opt) { case 'c': @@ -1762,6 +1823,10 @@ timestamp_type = TIMESTAMPS_PRINT_STACKED; print_defaults = 0; break; + case 's': + print_self_test_report = 1; + print_defaults = 0; + break; case 'a': print_defaults = 0; timestamp_id = timestamp_enum_name_to_id(optarg); @@ -1890,6 +1955,9 @@ if (print_tcpa_log) dump_tpm_log();
+ if (print_self_test_report) + dump_self_test_report(); + unmap_memory(&lbtable_mapping);
close(mem_fd);