commonlib: Add common cbfs parsing logic to coreboot and cbfstool.
To continue sharing more code between the tools and coreboot proper provide cbfs parsing logic in commonlib. A cbfs_for_each_file() function was added to allow one to act on each file found within a cbfs. cbfs_locate() was updated to use that logic. BUG=chrome-os-partner:48412 BUG=chromium:445938 BRANCH=None TEST=Utilized and booted on glados. Change-Id: I1f23841583e78dc3686f106de9eafe1adbef8c9f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/12783 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
@ -68,78 +68,6 @@ void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size)
|
||||
return rdev_mmap(&fh.data, 0, fsize);
|
||||
}
|
||||
|
||||
int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
|
||||
const char *name, uint32_t *type)
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
LOG("Locating '%s'\n", name);
|
||||
|
||||
/* Try to scan the entire cbfs region looking for file name. */
|
||||
while (1) {
|
||||
struct cbfs_file file;
|
||||
const size_t fsz = sizeof(file);
|
||||
char *fname;
|
||||
int name_match;
|
||||
size_t datasz;
|
||||
|
||||
DEBUG("Checking offset %zx\n", offset);
|
||||
|
||||
/* Can't read file. Nothing else to do but bail out. */
|
||||
if (rdev_readat(cbfs, &file, offset, fsz) != fsz)
|
||||
break;
|
||||
|
||||
if (memcmp(file.magic, CBFS_FILE_MAGIC, sizeof(file.magic))) {
|
||||
offset++;
|
||||
offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
|
||||
continue;
|
||||
}
|
||||
|
||||
file.len = ntohl(file.len);
|
||||
file.type = ntohl(file.type);
|
||||
file.offset = ntohl(file.offset);
|
||||
|
||||
/* See if names match. */
|
||||
fname = rdev_mmap(cbfs, offset + fsz, file.offset - fsz);
|
||||
|
||||
if (fname == NULL)
|
||||
break;
|
||||
|
||||
name_match = !strcmp(fname, name);
|
||||
rdev_munmap(cbfs, fname);
|
||||
|
||||
if (!name_match) {
|
||||
DEBUG(" Unmatched '%s' at %zx\n", fname, offset);
|
||||
offset += file.offset + file.len;
|
||||
offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type != NULL && *type != file.type) {
|
||||
DEBUG(" Unmatched type %x at %zx\n", file.type, offset);
|
||||
offset += file.offset + file.len;
|
||||
offset = ALIGN_UP(offset, CBFS_ALIGNMENT);
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG("Found @ offset %zx size %x\n", offset, file.len);
|
||||
/* File and type match. Keep track of both the metadata and
|
||||
* the data for the file. */
|
||||
if (rdev_chain(&fh->metadata, cbfs, offset, file.offset))
|
||||
break;
|
||||
offset += file.offset;
|
||||
datasz = file.len;
|
||||
if (rdev_chain(&fh->data, cbfs, offset, datasz))
|
||||
break;
|
||||
|
||||
/* Success. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG("'%s' not found.\n", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static size_t inflate(void *src, void *dst)
|
||||
{
|
||||
if (ENV_BOOTBLOCK || ENV_VERSTAGE)
|
||||
|
Reference in New Issue
Block a user