mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-27 03:33:50 +00:00
cleanup: add some easier-to-use FMAP parsing functions.
The functions that look for the FMAP and its entries should return more useful values. BUG=none BRANCH=ToT TEST=make runtests No functional changes. Change-Id: I4b62ea0de972bceb3d58f4ee8eb82ad065ddcbae Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/214630 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
f16ed87879
commit
c0777be638
@@ -30,13 +30,12 @@ static size_t size_of_rom;
|
|||||||
static int opt_gaps = 0;
|
static int opt_gaps = 0;
|
||||||
|
|
||||||
/* Return 0 if successful */
|
/* Return 0 if successful */
|
||||||
static int dump_fmap(const void *ptr, int argc, char *argv[])
|
static int dump_fmap(const FmapHeader *fmh, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, retval = 0;
|
int i, retval = 0;
|
||||||
char buf[80]; /* DWR: magic number */
|
char buf[80]; /* DWR: magic number */
|
||||||
const FmapHeader *fmh = (const FmapHeader *)ptr;
|
const FmapAreaHeader *ah;
|
||||||
const FmapAreaHeader *ah =
|
ah = (const FmapAreaHeader *) (fmh + 1);
|
||||||
(const FmapAreaHeader *)(ptr + sizeof(FmapHeader));
|
|
||||||
|
|
||||||
if (FMT_NORMAL == opt_format) {
|
if (FMT_NORMAL == opt_format) {
|
||||||
snprintf(buf, FMAP_SIGNATURE_SIZE + 1, "%s",
|
snprintf(buf, FMAP_SIGNATURE_SIZE + 1, "%s",
|
||||||
@@ -260,14 +259,12 @@ static void add_child(node_t * p, int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int human_fmap(void *p)
|
static int human_fmap(const FmapHeader *fmh)
|
||||||
{
|
{
|
||||||
FmapHeader *fmh;
|
|
||||||
FmapAreaHeader *ah;
|
FmapAreaHeader *ah;
|
||||||
int i, j, errorcnt = 0;
|
int i, j, errorcnt = 0;
|
||||||
int numnodes;
|
int numnodes;
|
||||||
|
|
||||||
fmh = (FmapHeader *) p;
|
|
||||||
ah = (FmapAreaHeader *) (fmh + 1);
|
ah = (FmapAreaHeader *) (fmh + 1);
|
||||||
|
|
||||||
/* The challenge here is to generate a directed graph from the
|
/* The challenge here is to generate a directed graph from the
|
||||||
@@ -384,7 +381,7 @@ static int do_dump_fmap(int argc, char *argv[])
|
|||||||
int errorcnt = 0;
|
int errorcnt = 0;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int fd;
|
int fd;
|
||||||
const char *fmap;
|
const FmapHeader *fmap;
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
|
|
||||||
progname = strrchr(argv[0], '/');
|
progname = strrchr(argv[0], '/');
|
||||||
@@ -457,15 +454,15 @@ static int do_dump_fmap(int argc, char *argv[])
|
|||||||
close(fd); /* done with this now */
|
close(fd); /* done with this now */
|
||||||
size_of_rom = sb.st_size;
|
size_of_rom = sb.st_size;
|
||||||
|
|
||||||
fmap = FmapFind((char *)base_of_rom, size_of_rom);
|
fmap = fmap_find(base_of_rom, size_of_rom);
|
||||||
if (fmap) {
|
if (fmap) {
|
||||||
switch (opt_format) {
|
switch (opt_format) {
|
||||||
case FMT_HUMAN:
|
case FMT_HUMAN:
|
||||||
retval = human_fmap((void *)fmap);
|
retval = human_fmap(fmap);
|
||||||
break;
|
break;
|
||||||
case FMT_NORMAL:
|
case FMT_NORMAL:
|
||||||
printf("hit at 0x%08x\n",
|
printf("hit at 0x%08x\n",
|
||||||
(uint32_t) (fmap - (char *)base_of_rom));
|
(uint32_t) ((char *)fmap - (char *)base_of_rom));
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
default:
|
default:
|
||||||
retval =
|
retval =
|
||||||
|
|||||||
@@ -9,27 +9,41 @@
|
|||||||
|
|
||||||
#include "fmap.h"
|
#include "fmap.h"
|
||||||
|
|
||||||
const char* FmapFind(const char* ptr, size_t size)
|
/* Find and point to the FMAP header within the buffer */
|
||||||
|
FmapHeader *fmap_find(uint8_t *ptr, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
FmapHeader *fmap_header;
|
FmapHeader *fmap_header;
|
||||||
for (i=0; i<size; i += FMAP_SEARCH_STRIDE, ptr += FMAP_SEARCH_STRIDE) {
|
for (i=0; i<size; i += FMAP_SEARCH_STRIDE, ptr += FMAP_SEARCH_STRIDE) {
|
||||||
if (0 != strncmp(ptr, FMAP_SIGNATURE, FMAP_SIGNATURE_SIZE))
|
if (0 != memcmp(ptr, FMAP_SIGNATURE, FMAP_SIGNATURE_SIZE))
|
||||||
continue;
|
continue;
|
||||||
// Image may have multiple signatures (ex, in code that handles FMAP itself)
|
fmap_header = (FmapHeader *)ptr;
|
||||||
// so we do want to check at least major version.
|
if (fmap_header->fmap_ver_major == FMAP_VER_MAJOR)
|
||||||
fmap_header = (FmapHeader *)ptr;
|
return fmap_header;
|
||||||
if (fmap_header->fmap_ver_major == FMAP_VER_MAJOR)
|
}
|
||||||
return ptr;
|
return NULL;
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FmapAreaIndex(const FmapHeader* fh, const FmapAreaHeader* ah,
|
/* Search for an area by name, return pointer to its beginning */
|
||||||
const char* name) {
|
uint8_t *fmap_find_by_name(uint8_t *ptr, size_t size, FmapHeader *fmap,
|
||||||
int i;
|
const char *name, FmapAreaHeader **ah_ptr)
|
||||||
for (i = 0; i < fh->fmap_nareas; i++)
|
{
|
||||||
if (!strcmp((const char*) ah[i].area_name, name))
|
int i;
|
||||||
return i;
|
FmapAreaHeader *ah;
|
||||||
return -1;
|
|
||||||
|
if (!fmap)
|
||||||
|
fmap = fmap_find(ptr, size);
|
||||||
|
if (!fmap)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ah = (FmapAreaHeader*)((void *)fmap + sizeof(FmapHeader));
|
||||||
|
for (i = 0; i < fmap->fmap_nareas; i++)
|
||||||
|
if (!strncmp(ah[i].area_name, name, FMAP_NAMELEN)) {
|
||||||
|
if (ah_ptr)
|
||||||
|
*ah_ptr = ah + i;
|
||||||
|
return ptr + ah[i].area_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,15 +34,16 @@ typedef struct _FmapAreaHeader {
|
|||||||
} __attribute__((packed)) FmapAreaHeader;
|
} __attribute__((packed)) FmapAreaHeader;
|
||||||
|
|
||||||
|
|
||||||
/* Scan firmware image, pointed by [ptr] with length [size], for fmap header.
|
/* Find and point to the FMAP header within the buffer */
|
||||||
* Return pointer to fmap header, or NULL if not found.
|
FmapHeader *fmap_find(uint8_t *ptr, size_t size);
|
||||||
*/
|
|
||||||
const char* FmapFind(const char *ptr, size_t size);
|
|
||||||
|
|
||||||
/* Look up fmap area by name, that is, strcmp(fh->fmap_name, name) == 0.
|
/* Search for an area by name, return pointer to its beginning */
|
||||||
* Return index of fmap area, that is, ah[returned_index],
|
uint8_t *fmap_find_by_name(uint8_t *ptr, size_t size,
|
||||||
* or -1 if not found. */
|
/* optional, will call fmap_find() if NULL */
|
||||||
int FmapAreaIndex(const FmapHeader* fh, const FmapAreaHeader* ah,
|
FmapHeader *fmap,
|
||||||
const char* name);
|
/* The area name to search for */
|
||||||
|
const char *name,
|
||||||
|
/* optional, return pointer to entry if not NULL */
|
||||||
|
FmapAreaHeader **ah);
|
||||||
|
|
||||||
#endif /* __FMAP_H__ */
|
#endif /* __FMAP_H__ */
|
||||||
|
|||||||
Reference in New Issue
Block a user