From 1c1554888875840f3d64231978aa891154b05f53 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Wed, 6 Jun 2012 09:17:06 +0000 Subject: Add logfile support Usage: flashrom --output logfile.txt Logfile output has at least dbg2 verbosity or screen verbosity, whichever is greater. Corresponding to flashrom svn r1540. Signed-off-by: Carl-Daniel Hailfinger Tested on Linux, Windows and FreeBSD. Acked-by: Idwer Vollering --- cli_classic.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'cli_classic.c') diff --git a/cli_classic.c b/cli_classic.c index edcef8e..b415076 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -106,7 +106,7 @@ static void cli_classic_usage(const char *name) "-z|" #endif "-E|-r |-w |-v ]\n" - " [-c ] [-l ]\n" + " [-c ] [-l ] [-o ]\n" " [-i ] [-p [:]]\n\n"); printf("Please note that the command line interface for flashrom has " @@ -135,6 +135,7 @@ static void cli_classic_usage(const char *name) "\n" " -i | --image only flash image " "from flash layout\n" + " -o | --output log to file \n" " -L | --list-supported print supported devices\n" #if CONFIG_PRINT_WIKI == 1 " -z | --list-supported-wiki print supported devices " @@ -189,7 +190,7 @@ int main(int argc, char *argv[]) enum programmer prog = PROGRAMMER_INVALID; int ret = 0; - static const char optstring[] = "r:Rw:v:nVEfc:l:i:p:Lzh"; + static const char optstring[] = "r:Rw:v:nVEfc:l:i:p:Lzho:"; static const struct option long_options[] = { {"read", 1, NULL, 'r'}, {"write", 1, NULL, 'w'}, @@ -206,11 +207,13 @@ int main(int argc, char *argv[]) {"programmer", 1, NULL, 'p'}, {"help", 0, NULL, 'h'}, {"version", 0, NULL, 'R'}, + {"output", 1, NULL, 'o'}, {NULL, 0, NULL, 0}, }; char *filename = NULL; char *layoutfile = NULL; + char *logfile = NULL; char *tempstr = NULL; char *pparam = NULL; @@ -272,7 +275,9 @@ int main(int argc, char *argv[]) chip_to_probe = strdup(optarg); break; case 'V': - verbose++; + verbose_screen++; + if (verbose_screen > MSG_DEBUG2) + verbose_logfile = verbose_screen; break; case 'E': if (++operation_specified > 1) { @@ -378,6 +383,18 @@ int main(int argc, char *argv[]) cli_classic_usage(argv[0]); exit(0); break; + case 'o': +#ifdef STANDALONE + fprintf(stderr, "Log file not supported in standalone mode. Aborting.\n"); + cli_classic_abort_usage(); +#else /* STANDALONE */ + logfile = strdup(optarg); + if (logfile[0] == '\0') { + fprintf(stderr, "No log filename specified.\n"); + cli_classic_abort_usage(); + } +#endif /* STANDALONE */ + break; default: cli_classic_abort_usage(); break; @@ -396,6 +413,13 @@ int main(int argc, char *argv[]) cli_classic_abort_usage(); } +#ifndef STANDALONE + if (logfile && check_filename(logfile, "log")) + cli_classic_abort_usage(); + if (logfile && open_logfile(logfile)) + return 1; +#endif /* !STANDALONE */ + #if CONFIG_PRINT_WIKI == 1 if (list_supported_wiki) { print_supported_wiki(); @@ -410,6 +434,11 @@ int main(int argc, char *argv[]) goto out; } +#ifndef STANDALONE + start_logging(); +#endif /* !STANDALONE */ + + print_buildinfo(); msg_gdbg("Command line (%i args):", argc - 1); for (i = 0; i < argc; i++) { msg_gdbg(" %s", argv[i]); @@ -552,5 +581,8 @@ int main(int argc, char *argv[]) out_shutdown: programmer_shutdown(); out: +#ifndef STANDALONE + ret |= close_logfile(); +#endif /* !STANDALONE */ return ret; } -- cgit v1.1