diff options
author | Bill Richardson <wfrichar@chromium.org> | 2014-09-23 13:49:14 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-09-25 20:26:57 +0000 |
commit | d5aa5bdb292b64f259f55319fd83bd4a4d548a12 (patch) | |
tree | b0fccd643306ff50a9a7beef2765dd21124895b4 /futility | |
parent | e192e7f6cea5f2c4556b729bf57ef1f552e0242a (diff) | |
download | vboot_reference-d5aa5bdb292b64f259f55319fd83bd4a4d548a12.tar.gz |
futility: allow dump_fmap to specify where to extract area
Previously, you could extract FMAP areas like so:
futility dump_fmap -x bios.bin FW_MAIN_A VBLOCK_A ...
This lets you decide what to name each area as it's extracted:
futility dump_fmap -x bios.bin FW_MAIN_A:/tmp/rw_a ../vblock
BUG=none
BRANCH=ToT
TEST=make runtests
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Change-Id: If02b57e03294b0b0b1dbc216ef57afdd3bdf2960
Reviewed-on: https://chromium-review.googlesource.com/219646
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'futility')
-rw-r--r-- | futility/cmd_dump_fmap.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c index 482cf23d..4bc4bd26 100644 --- a/futility/cmd_dump_fmap.c +++ b/futility/cmd_dump_fmap.c @@ -36,6 +36,29 @@ static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[]) char buf[80]; /* DWR: magic number */ const FmapAreaHeader *ah; ah = (const FmapAreaHeader *) (fmh + 1); + char *extract_names[argc]; + char *outname = 0; + + if (opt_extract) { + /* prepare the filenames to write areas to */ + memset(extract_names, 0, sizeof(extract_names)); + for (i = 0; i < argc; i++) { + char *a = argv[i]; + char *f = strchr(a, ':'); + if (!f) + continue; + if (a == f || *(f+1) == '\0') { + fprintf(stderr, + "argument \"%s\" is bogus\n", a); + retval = 1; + continue; + } + *f++ = '\0'; + extract_names[i] = f; + } + if (retval) + return retval; + } if (FMT_NORMAL == opt_format) { snprintf(buf, FMAP_SIGNATURE_SIZE + 1, "%s", @@ -56,9 +79,11 @@ static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[]) if (argc) { int j, found = 0; + outname = NULL; for (j = 0; j < argc; j++) if (!strcmp(argv[j], buf)) { found = 1; + outname = extract_names[j]; break; } if (!found) @@ -86,13 +111,16 @@ static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[]) if (opt_extract) { char *s; - for (s = buf; *s; s++) - if (*s == ' ') - *s = '_'; - FILE *fp = fopen(buf, "wb"); + if (!outname) { + for (s = buf; *s; s++) + if (*s == ' ') + *s = '_'; + outname = buf; + } + FILE *fp = fopen(outname, "wb"); if (!fp) { fprintf(stderr, "%s: can't open %s: %s\n", - progname, buf, strerror(errno)); + progname, outname, strerror(errno)); retval = 1; } else if (!ah->area_size) { fprintf(stderr, @@ -110,7 +138,7 @@ static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[]) retval = 1; } else { if (FMT_NORMAL == opt_format) - printf("saved as \"%s\"\n", buf); + printf("saved as \"%s\"\n", outname); } fclose(fp); } |