summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2013-06-20 10:32:48 +0800
committerChromeBot <chrome-bot@google.com>2013-06-21 20:16:54 -0700
commit556ec4fd6089cc54dc06902d9c4e1831609332a5 (patch)
tree04a595e64f3c1fbb9bbce492056ae65d7f82928b
parenta75071c25295e392a21b8deddccaf2f3f0d0f041 (diff)
downloadvboot-556ec4fd6089cc54dc06902d9c4e1831609332a5.tar.gz
dump_fmap: Find correct FMAP structure by checking version.
Firmware images reading its own FMAP structure may have FMAP signature in code and cause dump_fmap to parse incorrectly. Since currently there is only one major version for FMAP (and the structure defined in fmap.h also applies only to current version), we can improve that by checking major version number to skip signatures in firmware code. BUG=chromium:236347 TEST=emerge vboot_reference; dump_fmap /build/daisy/firmware/image.bin # success BRANCH=none Change-Id: I1d8f49bb88357e7a3a945fbdba9d9a7c4e177ac4 Reviewed-on: https://gerrit.chromium.org/gerrit/59362 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org> Tested-by: Hung-Te Lin <hungte@chromium.org> Commit-Queue: Gabe Black <gabeblack@chromium.org>
-rw-r--r--host/lib/fmap.c11
-rw-r--r--host/lib/include/fmap.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/host/lib/fmap.c b/host/lib/fmap.c
index 3c3f340b..014c97b2 100644
--- a/host/lib/fmap.c
+++ b/host/lib/fmap.c
@@ -12,10 +12,15 @@
const char* FmapFind(const char* ptr, size_t size)
{
size_t i;
- for (i=0; i<size; i += FMAP_SEARCH_STRIDE) {
- if (0 == strncmp(ptr, FMAP_SIGNATURE, FMAP_SIGNATURE_SIZE))
+ FmapHeader *fmap_header;
+ for (i=0; i<size; i += FMAP_SEARCH_STRIDE, ptr += FMAP_SEARCH_STRIDE) {
+ if (0 != strncmp(ptr, FMAP_SIGNATURE, FMAP_SIGNATURE_SIZE))
+ continue;
+ // Image may have multiple signatures (ex, in code that handles FMAP itself)
+ // so we do want to check at least major version.
+ fmap_header = (FmapHeader *)ptr;
+ if (fmap_header->fmap_ver_major == FMAP_VER_MAJOR)
return ptr;
- ptr += FMAP_SEARCH_STRIDE;
}
return NULL;
}
diff --git a/host/lib/include/fmap.h b/host/lib/include/fmap.h
index 7da2dd90..92d74fd3 100644
--- a/host/lib/include/fmap.h
+++ b/host/lib/include/fmap.h
@@ -15,6 +15,7 @@
#define FMAP_SIGNATURE "__FMAP__"
#define FMAP_SIGNATURE_SIZE 8
#define FMAP_SEARCH_STRIDE 4
+#define FMAP_VER_MAJOR 1
typedef struct _FmapHeader {
char fmap_signature[FMAP_SIGNATURE_SIZE]; /* avoiding endian issues */
uint8_t fmap_ver_major;