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 */
|
/* global variables */
|
||||||
static int opt_extract = 0;
|
static int opt_extract = 0;
|
||||||
|
static int opt_pretty = 0;
|
||||||
static char* progname;
|
static char* progname;
|
||||||
static void* base_of_rom;
|
static void* base_of_rom;
|
||||||
|
|
||||||
@@ -30,27 +31,34 @@ static int dump_fmap(const void* ptr) {
|
|||||||
const FmapHeader* fmh = (const FmapHeader*) ptr;
|
const FmapHeader* fmh = (const FmapHeader*) ptr;
|
||||||
const FmapAreaHeader* ah = (const FmapAreaHeader*) (ptr + sizeof(FmapHeader));
|
const FmapAreaHeader* ah = (const FmapAreaHeader*) (ptr + sizeof(FmapHeader));
|
||||||
|
|
||||||
snprintf(buf, FMAP_SIGNATURE_SIZE+1, "%s", fmh->fmap_signature);
|
if (!opt_pretty) {
|
||||||
printf("fmap_signature %s\n", buf);
|
snprintf(buf, FMAP_SIGNATURE_SIZE+1, "%s", fmh->fmap_signature);
|
||||||
printf("fmap_version: %d.%d\n", fmh->fmap_ver_major, fmh->fmap_ver_minor);
|
printf("fmap_signature %s\n", buf);
|
||||||
printf("fmap_base: 0x%" PRIx64 "\n", fmh->fmap_base);
|
printf("fmap_version: %d.%d\n",
|
||||||
printf("fmap_size: 0x%08x (%d)\n", fmh->fmap_size, fmh->fmap_size);
|
fmh->fmap_ver_major, fmh->fmap_ver_minor);
|
||||||
snprintf(buf, FMAP_NAMELEN+1, "%s", fmh->fmap_name);
|
printf("fmap_base: 0x%" PRIx64 "\n", fmh->fmap_base);
|
||||||
printf("fmap_name: %s\n", buf);
|
printf("fmap_size: 0x%08x (%d)\n", fmh->fmap_size, fmh->fmap_size);
|
||||||
printf("fmap_nareas: %d\n", fmh->fmap_nareas);
|
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++) {
|
for (i=0; i<fmh->fmap_nareas; i++) {
|
||||||
printf("area: %d\n", i+1);
|
snprintf(buf, FMAP_NAMELEN+1, "%s", ah->area_name);
|
||||||
printf("area_offset: 0x%08x\n", ah->area_offset);
|
if (opt_pretty) {
|
||||||
printf("area_size: 0x%08x (%d)\n", ah->area_size, ah->area_size);
|
printf("%s %d %d\n", buf, ah->area_offset, ah->area_size);
|
||||||
snprintf(buf, FMAP_NAMELEN+1, "%s", ah->area_name);
|
} else {
|
||||||
printf("area_name: %s\n", buf);
|
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) {
|
if (opt_extract) {
|
||||||
char* s;
|
char* s;
|
||||||
for (s=buf;* s; s++)
|
for (s=buf;* s; s++)
|
||||||
if (*s == ' ')
|
if (*s == ' ')
|
||||||
*s = '_';
|
*s = '_';
|
||||||
FILE* fp = fopen(buf,"wb");
|
FILE* fp = fopen(buf,"wb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
fprintf(stderr, "%s: can't open %s: %s\n",
|
fprintf(stderr, "%s: can't open %s: %s\n",
|
||||||
@@ -63,7 +71,8 @@ static int dump_fmap(const void* ptr) {
|
|||||||
progname, buf, strerror(errno));
|
progname, buf, strerror(errno));
|
||||||
retval = 1;
|
retval = 1;
|
||||||
} else {
|
} else {
|
||||||
printf("saved as \"%s\"\n", buf);
|
if (!opt_pretty)
|
||||||
|
printf("saved as \"%s\"\n", buf);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -91,12 +100,15 @@ int main(int argc, char* argv[]) {
|
|||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
|
|
||||||
opterr = 0; /* quiet, you */
|
opterr = 0; /* quiet, you */
|
||||||
while ((c=getopt(argc, argv, ":x")) != -1) {
|
while ((c=getopt(argc, argv, ":xp")) != -1) {
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'x':
|
case 'x':
|
||||||
opt_extract = 1;
|
opt_extract = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
opt_pretty = 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
fprintf(stderr, "%s: unrecognized switch: -%c\n",
|
fprintf(stderr, "%s: unrecognized switch: -%c\n",
|
||||||
progname, optopt);
|
progname, optopt);
|
||||||
@@ -115,10 +127,11 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
if (errorcnt || optind >= argc) {
|
if (errorcnt || optind >= argc) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\nUsage: %s [-x] FLASHIMAGE\n\n"
|
"\nUsage: %s [-x] [-p] FLASHIMAGE\n\n"
|
||||||
"Display (and extract with -x) the FMAP components from a BIOS image"
|
"Display (and extract with -x) the FMAP components from a BIOS image.\n"
|
||||||
"\n\n",
|
"The -p option makes the output easier to parse by scripts.\n"
|
||||||
progname);
|
"\n",
|
||||||
|
progname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +151,8 @@ int main(int argc, char* argv[]) {
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
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);
|
base_of_rom = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (base_of_rom == (char*)-1) {
|
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);
|
fmap = FmapFind((char*) base_of_rom, sb.st_size);
|
||||||
if (fmap) {
|
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);
|
retval = dump_fmap(fmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user