diff options
author | Bill Richardson <wfrichar@chromium.org> | 2011-06-13 12:45:24 -0700 |
---|---|---|
committer | Bill Richardson <wfrichar@chromium.org> | 2011-06-13 13:02:45 -0700 |
commit | 9a2c3b25fd91b9448ff7af036a456d24b65ebe51 (patch) | |
tree | ac6e85201e191760b62067c4fd1266c9e6d51311 | |
parent | 53306d984f20b5e08834dc955a0d3fe1af6a340e (diff) | |
download | vboot-9a2c3b25fd91b9448ff7af036a456d24b65ebe51.tar.gz |
Add -p option to dump_fmap to make output prettier.
BUG=chromium-os:16456
TEST=manual
To test: run dump_fmap with and without the '-p' option.
Without -p, the output looks like this:
area: 14
area_offset: 0x00110000
area_size: 0x000f0000 (983040)
area_name: RW_SECTION_B
area: 15
area_offset: 0x00110000
area_size: 0x00010000 (65536)
area_name: VBLOCK_B
With -p, the output looks like this:
RW_SECTION_B 1114112 983040
VBLOCK_B 1114112 65536
Change-Id: I53a3527fa92d22fef16563b0a950366a3a3db8a4
Reviewed-on: http://gerrit.chromium.org/gerrit/2545
Tested-by: Rajesh Chenna <rchenna@google.com>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | utility/dump_fmap.c | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/utility/dump_fmap.c b/utility/dump_fmap.c index ab2043c8..7f2f53a0 100644 --- a/utility/dump_fmap.c +++ b/utility/dump_fmap.c @@ -19,6 +19,7 @@ /* global variables */ static int opt_extract = 0; +static int opt_pretty = 0; static char* progname; static void* base_of_rom; @@ -30,27 +31,34 @@ static int dump_fmap(const void* ptr) { const FmapHeader* fmh = (const FmapHeader*) ptr; const FmapAreaHeader* ah = (const FmapAreaHeader*) (ptr + sizeof(FmapHeader)); - snprintf(buf, FMAP_SIGNATURE_SIZE+1, "%s", fmh->fmap_signature); - printf("fmap_signature %s\n", buf); - printf("fmap_version: %d.%d\n", fmh->fmap_ver_major, fmh->fmap_ver_minor); - printf("fmap_base: 0x%" PRIx64 "\n", fmh->fmap_base); - printf("fmap_size: 0x%08x (%d)\n", fmh->fmap_size, fmh->fmap_size); - snprintf(buf, FMAP_NAMELEN+1, "%s", fmh->fmap_name); - printf("fmap_name: %s\n", buf); - printf("fmap_nareas: %d\n", fmh->fmap_nareas); + if (!opt_pretty) { + snprintf(buf, FMAP_SIGNATURE_SIZE+1, "%s", fmh->fmap_signature); + printf("fmap_signature %s\n", buf); + printf("fmap_version: %d.%d\n", + fmh->fmap_ver_major, fmh->fmap_ver_minor); + printf("fmap_base: 0x%" PRIx64 "\n", fmh->fmap_base); + printf("fmap_size: 0x%08x (%d)\n", fmh->fmap_size, fmh->fmap_size); + snprintf(buf, FMAP_NAMELEN+1, "%s", fmh->fmap_name); + printf("fmap_name: %s\n", buf); + printf("fmap_nareas: %d\n", fmh->fmap_nareas); + } for (i=0; i<fmh->fmap_nareas; i++) { - printf("area: %d\n", i+1); - printf("area_offset: 0x%08x\n", ah->area_offset); - printf("area_size: 0x%08x (%d)\n", ah->area_size, ah->area_size); - snprintf(buf, FMAP_NAMELEN+1, "%s", ah->area_name); - printf("area_name: %s\n", buf); + snprintf(buf, FMAP_NAMELEN+1, "%s", ah->area_name); + if (opt_pretty) { + printf("%s %d %d\n", buf, ah->area_offset, ah->area_size); + } else { + printf("area: %d\n", i+1); + printf("area_offset: 0x%08x\n", ah->area_offset); + printf("area_size: 0x%08x (%d)\n", ah->area_size, ah->area_size); + printf("area_name: %s\n", buf); + } if (opt_extract) { char* s; for (s=buf;* s; s++) if (*s == ' ') - *s = '_'; + *s = '_'; FILE* fp = fopen(buf,"wb"); if (!fp) { fprintf(stderr, "%s: can't open %s: %s\n", @@ -63,7 +71,8 @@ static int dump_fmap(const void* ptr) { progname, buf, strerror(errno)); retval = 1; } else { - printf("saved as \"%s\"\n", buf); + if (!opt_pretty) + printf("saved as \"%s\"\n", buf); } fclose(fp); } @@ -91,12 +100,15 @@ int main(int argc, char* argv[]) { progname = argv[0]; opterr = 0; /* quiet, you */ - while ((c=getopt(argc, argv, ":x")) != -1) { + while ((c=getopt(argc, argv, ":xp")) != -1) { switch (c) { case 'x': opt_extract = 1; break; + case 'p': + opt_pretty = 1; + break; case '?': fprintf(stderr, "%s: unrecognized switch: -%c\n", progname, optopt); @@ -115,10 +127,11 @@ int main(int argc, char* argv[]) { if (errorcnt || optind >= argc) { fprintf(stderr, - "\nUsage: %s [-x] FLASHIMAGE\n\n" - "Display (and extract with -x) the FMAP components from a BIOS image" - "\n\n", - progname); + "\nUsage: %s [-x] [-p] FLASHIMAGE\n\n" + "Display (and extract with -x) the FMAP components from a BIOS image.\n" + "The -p option makes the output easier to parse by scripts.\n" + "\n", + progname); return 1; } @@ -138,7 +151,8 @@ int main(int argc, char* argv[]) { strerror(errno)); return 1; } - printf("opened %s\n", argv[optind]); + if (!opt_pretty) + printf("opened %s\n", argv[optind]); base_of_rom = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (base_of_rom == (char*)-1) { @@ -153,7 +167,8 @@ int main(int argc, char* argv[]) { fmap = FmapFind((char*) base_of_rom, sb.st_size); if (fmap) { - printf("hit at 0x%08x\n", (uint32_t) (fmap - (char*) base_of_rom)); + if (!opt_pretty) + printf("hit at 0x%08x\n", (uint32_t) (fmap - (char*) base_of_rom)); retval = dump_fmap(fmap); } |