mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-24 02:05:01 +00:00
It doesn't yet handle block devices, but it can display normal files containing a entire BIOS image, a GBB, a VBLOCK, a .vbpubk, a .vblock, and a firmware preamble (VbFirmwarePreambleHeader). The command-line options are not well-documented. BUG=chromium:224734 BRANCH=ToT TEST=make runtests Change-Id: I181f6331ae23599302bbaee3f270e8af9586cf06 Reviewed-on: https://chromium-review.googlesource.com/216032 Commit-Queue: Bill Richardson <wfrichar@chromium.org> Tested-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
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"
|
|
|
|
/* Find and point to the FMAP header within the buffer */
|
|
FmapHeader *fmap_find(uint8_t *ptr, size_t size)
|
|
{
|
|
size_t i;
|
|
FmapHeader *fmap_header;
|
|
size_t lim = size - sizeof(FmapHeader);
|
|
for (i = 0;
|
|
i <= lim;
|
|
i += FMAP_SEARCH_STRIDE, ptr += FMAP_SEARCH_STRIDE) {
|
|
if (0 != memcmp(ptr, FMAP_SIGNATURE, FMAP_SIGNATURE_SIZE))
|
|
continue;
|
|
fmap_header = (FmapHeader *)ptr;
|
|
if (fmap_header->fmap_ver_major == FMAP_VER_MAJOR)
|
|
return fmap_header;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/* Search for an area by name, return pointer to its beginning */
|
|
uint8_t *fmap_find_by_name(uint8_t *ptr, size_t size, FmapHeader *fmap,
|
|
const char *name, FmapAreaHeader **ah_ptr)
|
|
{
|
|
int i;
|
|
FmapAreaHeader *ah;
|
|
|
|
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;
|
|
}
|
|
|