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 <reinauer@google.com> Reviewed-on: http://review.coreboot.org/2091 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: build bot (Jenkins)
This commit is contained in:
parent
2c3f2609ca
commit
1e0e55615f
|
@ -21,6 +21,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#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,12 +250,59 @@ 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 <http://www.gnu.org/licenses/>.\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 };
|
||||
|
||||
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) {
|
||||
printf("failed to gain memory access\n");
|
||||
|
|
Loading…
Reference in New Issue