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 | |
parent | e192e7f6cea5f2c4556b729bf57ef1f552e0242a (diff) | |
download | vboot-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>
-rw-r--r-- | futility/cmd_dump_fmap.c | 40 | ||||
-rw-r--r-- | tests/futility/data_fmap_expect_x2.txt | 12 | ||||
-rwxr-xr-x | tests/futility/test_dump_fmap.sh | 6 |
3 files changed, 51 insertions, 7 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); } diff --git a/tests/futility/data_fmap_expect_x2.txt b/tests/futility/data_fmap_expect_x2.txt new file mode 100644 index 00000000..7226a4fd --- /dev/null +++ b/tests/futility/data_fmap_expect_x2.txt @@ -0,0 +1,12 @@ +hit at 0x00000800 +fmap_signature __FMAP__ +fmap_version: 1.0 +fmap_base: 0x0 +fmap_size: 0x00800000 (8388608) +fmap_name: FMAP +fmap_nareas: 30 +area: 2 +area_offset: 0x00000000 +area_size: 0x00001000 (4096) +area_name: SI_DESC +saved as "FOO" diff --git a/tests/futility/test_dump_fmap.sh b/tests/futility/test_dump_fmap.sh index b74c0de0..142a1540 100755 --- a/tests/futility/test_dump_fmap.sh +++ b/tests/futility/test_dump_fmap.sh @@ -28,6 +28,10 @@ if "$FUTILITY" dump_fmap -x "${SCRIPTDIR}/data_fmap.bin" FMAP; then false; fi "$FUTILITY" dump_fmap -x "${SCRIPTDIR}/data_fmap.bin" SI_DESC > "$TMP" cmp "${SCRIPTDIR}/data_fmap_expect_x.txt" "$TMP" +# Redirect dumping to a different place +"$FUTILITY" dump_fmap -x "${SCRIPTDIR}/data_fmap.bin" SI_DESC:FOO > "$TMP" +cmp "${SCRIPTDIR}/data_fmap_expect_x2.txt" "$TMP" +cmp SI_DESC FOO # This FMAP has problems, and should fail. if "$FUTILITY" dump_fmap -h "${SCRIPTDIR}/data_fmap2.bin" > "$TMP"; then false; fi @@ -41,5 +45,5 @@ cmp "${SCRIPTDIR}/data_fmap2_expect_hhH.txt" "$TMP" # cleanup -rm -f ${TMP}* FMAP SI_DESC +rm -f ${TMP}* FMAP SI_DESC FOO exit 0 |