summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-09-23 13:49:14 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-06 01:16:09 +0000
commit60cd28e237cb2f426b9a46d4f72e749693db7232 (patch)
treeb0fccd643306ff50a9a7beef2765dd21124895b4
parente69fb32aa10f87a085a18d4b2b967238fa9b2956 (diff)
downloadvboot-60cd28e237cb2f426b9a46d4f72e749693db7232.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> Reviewed-on: https://chromium-review.googlesource.com/227878 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--futility/cmd_dump_fmap.c40
-rw-r--r--tests/futility/data_fmap_expect_x2.txt12
-rwxr-xr-xtests/futility/test_dump_fmap.sh6
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