From 1e0e55615f86bb9237fa8f4d81158cbf25c65565 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Wed, 2 Jan 2013 15:43:56 -0800 Subject: [PATCH] cbmem utility: support command line options The tool could print much more useful information than just time stamps, for example the cbmem console on systems that don't have a kernel patched to support /sys/firmware/log. Hence, add command line option parsing to make adding such features easier in the future. Change-Id: Ib2b2584970f8a4e4187da803fcc5a95469f23a6a Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/2091 Reviewed-by: Vadim Bendebury Tested-by: build bot (Jenkins) --- util/cbmem/cbmem.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 31950e22a3..1cb7b8dd40 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "stdlib.h" #include "boot/coreboot_tables.h" @@ -32,6 +34,8 @@ typedef uint64_t u64; #include "cbmem.h" #include "timestamp.h" +#define CBMEM_VERSION "1.0" + /* File descriptor used to access /dev/mem */ static FILE* fd; @@ -246,11 +250,58 @@ static void dump_timestamps(const struct timestamp_table *tst_p) } } +void print_version(void) +{ + printf("cbmem v%s -- ", CBMEM_VERSION); + printf("Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.\n\n"); + printf( + "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, version 2 of the License.\n\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see .\n\n"); +} + +void print_usage(const char *name) +{ + printf("usage: %s [-vh?]\n", name); + printf("\n" + " -v | --version: print the version\n" + " -h | --help: print this help\n" + "\n"); + exit(1); +} int main(int argc, char** argv) { int j; - static const int possible_base_addresses[] = {0, 0xf0000}; + static const int possible_base_addresses[] = { 0, 0xf0000 }; + + int opt, option_index = 0; + static struct option long_options[] = { + {"version", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0} + }; + while ((opt = getopt_long(argc, argv, "vh?", + long_options, &option_index)) != EOF) { + switch (opt) { + case 'v': + print_version(); + exit(0); + break; + case 'h': + case '?': + default: + print_usage(argv[0]); + exit(0); + break; + } + } fd = fopen("/dev/mem", "r"); if (!fd) {