Files
OpenCellular/host/lib/fmap.c
Hung-Te Lin 556ec4fd60 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>
2013-06-21 20:16:54 -07:00

36 lines
974 B
C

/*
* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <string.h>
#include "fmap.h"
const char* FmapFind(const char* ptr, size_t size)
{
size_t i;
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;
}
return NULL;
}
int FmapAreaIndex(const FmapHeader* fh, const FmapAreaHeader* ah,
const char* name) {
int i;
for (i = 0; i < fh->fmap_nareas; i++)
if (!strcmp((const char*) ah[i].area_name, name))
return i;
return -1;
}