From 19f8756f0008cf74a472177642cc44f00c05934f Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Mon, 7 Jan 2013 13:37:12 -0800 Subject: cbmem utility: Add option to dump cbmem console This adds an option to the cbmem utility to dump the cbmem console. To keep the utility backwards compatible, specifying -c disables printing of time stamps. To print both console and time stamps, run the utility with -ct Change-Id: Idd2dbf32c3c44f857c2f41e6c817c5ab13155d6f Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/2114 Tested-by: build bot (Jenkins) Reviewed-by: Vadim Bendebury --- util/cbmem/cbmem.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'util/cbmem/cbmem.c') diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index df00684730..4c0bd6837f 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -283,6 +283,43 @@ static void dump_timestamps(void) unmap_memory(); } +/* dump the cbmem console */ +static void dump_console(void) +{ + void *console_p; + char *console_c; + uint32_t size; + + if (console.tag != LB_TAG_CBMEM_CONSOLE) { + fprintf(stderr, "No console found in coreboot table.\n"); + return; + } + + console_p = map_memory((unsigned long)console.cbmem_addr); + /* The in-memory format of the console area is: + * u32 size + * u32 cursor + * char console[size] + * Hence we have to add 8 to get to the actual console string. + */ + size = *(uint32_t *)console_p; + console_c = malloc(size + 1); + if (!console_c) { + fprintf(stderr, "Not enough memory for console.\n"); + exit(1); + } + + memcpy(console_c, console_p + 8, size); + console_c[size] = 0; + + printf("%s", console_c); + + free(console_c); + + unmap_memory(); +} + + void print_version(void) { printf("cbmem v%s -- ", CBMEM_VERSION); @@ -303,6 +340,9 @@ void print_usage(const char *name) { printf("usage: %s [-vh?]\n", name); printf("\n" + " -c | --console: print cbmem console\n" + " -t | --timestamps: print timestamp information\n" + " -V | --verbose: verbose (debugging) output\n" " -v | --version: print the version\n" " -h | --help: print this help\n" "\n"); @@ -314,18 +354,30 @@ int main(int argc, char** argv) int j; static const int possible_base_addresses[] = { 0, 0xf0000 }; - int print_timestamps = 1; + int print_defaults = 1; + int print_console = 0; + int print_timestamps = 0; int opt, option_index = 0; static struct option long_options[] = { + {"console", 0, 0, 'c'}, + {"timestamps", 0, 0, 't'}, {"verbose", 0, 0, 'V'}, {"version", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; - while ((opt = getopt_long(argc, argv, "Vvh?", + while ((opt = getopt_long(argc, argv, "ctVvh?", long_options, &option_index)) != EOF) { switch (opt) { + case 'c': + print_console = 1; + print_defaults = 0; + break; + case 't': + print_timestamps = 1; + print_defaults = 0; + break; case 'V': verbose = 1; break; @@ -355,7 +407,10 @@ int main(int argc, char** argv) break; } - if (print_timestamps) + if (print_console) + dump_console(); + + if (print_defaults || print_timestamps) dump_timestamps(); close(fd); -- cgit v1.2.3