diff options
-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); } |