cbmem: Add new command line flag to dump console for one boot only
Even though the persistent CBMEM console is obviously awesome, there may be cases where we only want to look at console output from the last boot. It's easy to tell where one boot ends and another begins from the banner message that coreboot prints at the start of every stage, but in order to make it easier to find that point (especially for external tools), let's put that functionality straight into the cbmem utility with a new command line flag. Use the POSIX/libc regular expression API to find the banner string for maximum compatilibity, even though it's kinda icky. Change-Id: Ic17383507a884d84de9a2a880380cb15b25708a1 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/19497 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com> Reviewed-by: Sumeet R Pawnikar <sumeet.r.pawnikar@intel.com>
This commit is contained in:
parent
e70142c9c2
commit
b7b64a9f68
|
@ -31,6 +31,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <assert.h>
|
#include <assert.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/coreboot_tables.h>
|
#include <commonlib/coreboot_tables.h>
|
||||||
|
@ -611,7 +612,7 @@ struct cbmem_console {
|
||||||
#define CBMC_OVERFLOW (1 << 31)
|
#define CBMC_OVERFLOW (1 << 31)
|
||||||
|
|
||||||
/* dump the cbmem console */
|
/* dump the cbmem console */
|
||||||
static void dump_console(void)
|
static void dump_console(int one_boot_only)
|
||||||
{
|
{
|
||||||
struct cbmem_console *console_p;
|
struct cbmem_console *console_p;
|
||||||
char *console_c;
|
char *console_c;
|
||||||
|
@ -659,8 +660,32 @@ static void dump_console(void)
|
||||||
for (cursor = 0; cursor < size; cursor++)
|
for (cursor = 0; cursor < size; cursor++)
|
||||||
if (!isprint(console_c[cursor]) && !isspace(console_c[cursor]))
|
if (!isprint(console_c[cursor]) && !isspace(console_c[cursor]))
|
||||||
console_c[cursor] = '?';
|
console_c[cursor] = '?';
|
||||||
printf("%s\n", console_c);
|
|
||||||
|
|
||||||
|
/* We detect the last boot by looking for a bootblock, romstage or
|
||||||
|
ramstage banner, in that order (to account for platforms without
|
||||||
|
CONFIG_BOOTBLOCK_CONSOLE and/or CONFIG_EARLY_CONSOLE). Once we find
|
||||||
|
a banner, store the last match for that stage in cursor and stop. */
|
||||||
|
cursor = 0;
|
||||||
|
if (one_boot_only) {
|
||||||
|
#define BANNER_REGEX(stage) "\n\ncoreboot-[^\n]* " stage " starting\\.\\.\\.\n"
|
||||||
|
const char *regex[] = { BANNER_REGEX("bootblock"),
|
||||||
|
BANNER_REGEX("romstage"),
|
||||||
|
BANNER_REGEX("ramstage")};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; !cursor && i < ARRAY_SIZE(regex); i++) {
|
||||||
|
regex_t re;
|
||||||
|
regmatch_t match;
|
||||||
|
assert(!regcomp(&re, regex[i], 0));
|
||||||
|
|
||||||
|
/* Keep looking for matches so we find the last one. */
|
||||||
|
while (!regexec(&re, console_c + cursor, 1, &match, 0))
|
||||||
|
cursor += match.rm_so + 1;
|
||||||
|
regfree(&re);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts(console_c + cursor);
|
||||||
free(console_c);
|
free(console_c);
|
||||||
unmap_memory();
|
unmap_memory();
|
||||||
}
|
}
|
||||||
|
@ -936,6 +961,7 @@ static void print_usage(const char *name, int exit_code)
|
||||||
printf("usage: %s [-cCltTxVvh?]\n", name);
|
printf("usage: %s [-cCltTxVvh?]\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"
|
||||||
" -C | --coverage: dump coverage information\n"
|
" -C | --coverage: dump coverage information\n"
|
||||||
" -l | --list: print cbmem table of contents\n"
|
" -l | --list: print cbmem table of contents\n"
|
||||||
" -x | --hexdump: print hexdump of cbmem area\n"
|
" -x | --hexdump: print hexdump of cbmem area\n"
|
||||||
|
@ -1074,11 +1100,13 @@ int main(int argc, char** argv)
|
||||||
int print_rawdump = 0;
|
int print_rawdump = 0;
|
||||||
int print_timestamps = 0;
|
int print_timestamps = 0;
|
||||||
int machine_readable_timestamps = 0;
|
int machine_readable_timestamps = 0;
|
||||||
|
int one_boot_only = 0;
|
||||||
unsigned int rawdump_id = 0;
|
unsigned int rawdump_id = 0;
|
||||||
|
|
||||||
int opt, option_index = 0;
|
int opt, option_index = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"console", 0, 0, 'c'},
|
{"console", 0, 0, 'c'},
|
||||||
|
{"oneboot", 0, 0, '1'},
|
||||||
{"coverage", 0, 0, 'C'},
|
{"coverage", 0, 0, 'C'},
|
||||||
{"list", 0, 0, 'l'},
|
{"list", 0, 0, 'l'},
|
||||||
{"timestamps", 0, 0, 't'},
|
{"timestamps", 0, 0, 't'},
|
||||||
|
@ -1090,13 +1118,18 @@ 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, "cCltTxVvh?r:",
|
while ((opt = getopt_long(argc, argv, "c1CltTxVvh?r:",
|
||||||
long_options, &option_index)) != EOF) {
|
long_options, &option_index)) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
print_console = 1;
|
print_console = 1;
|
||||||
print_defaults = 0;
|
print_defaults = 0;
|
||||||
break;
|
break;
|
||||||
|
case '1':
|
||||||
|
print_console = 1;
|
||||||
|
one_boot_only = 1;
|
||||||
|
print_defaults = 0;
|
||||||
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
print_coverage = 1;
|
print_coverage = 1;
|
||||||
print_defaults = 0;
|
print_defaults = 0;
|
||||||
|
@ -1211,7 +1244,7 @@ int main(int argc, char** argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (print_console)
|
if (print_console)
|
||||||
dump_console();
|
dump_console(one_boot_only);
|
||||||
|
|
||||||
if (print_coverage)
|
if (print_coverage)
|
||||||
dump_coverage();
|
dump_coverage();
|
||||||
|
|
Loading…
Reference in New Issue