mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-25 18:55:24 +00:00
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>
This commit is contained in:
@@ -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,21 +31,28 @@ static int dump_fmap(const void* ptr) {
|
||||
const FmapHeader* fmh = (const FmapHeader*) ptr;
|
||||
const FmapAreaHeader* ah = (const FmapAreaHeader*) (ptr + sizeof(FmapHeader));
|
||||
|
||||
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_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++) {
|
||||
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);
|
||||
snprintf(buf, FMAP_NAMELEN+1, "%s", ah->area_name);
|
||||
printf("area_name: %s\n", buf);
|
||||
}
|
||||
|
||||
if (opt_extract) {
|
||||
char* s;
|
||||
@@ -63,6 +71,7 @@ static int dump_fmap(const void* ptr) {
|
||||
progname, buf, strerror(errno));
|
||||
retval = 1;
|
||||
} else {
|
||||
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,9 +127,10 @@ 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",
|
||||
"\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,6 +151,7 @@ int main(int argc, char* argv[]) {
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
if (!opt_pretty)
|
||||
printf("opened %s\n", argv[optind]);
|
||||
|
||||
base_of_rom = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
@@ -153,6 +167,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
fmap = FmapFind((char*) base_of_rom, sb.st_size);
|
||||
if (fmap) {
|
||||
if (!opt_pretty)
|
||||
printf("hit at 0x%08x\n", (uint32_t) (fmap - (char*) base_of_rom));
|
||||
retval = dump_fmap(fmap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user