From 295d58bda85ce30724a3fff87d60b323373f6e5f Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 15 Dec 2015 13:33:51 -0600 Subject: 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 Reviewed-on: https://review.coreboot.org/12783 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth Reviewed-by: Patrick Georgi --- src/lib/cbfs.c | 72 ---------------------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'src/lib') diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index d68aa39cc5..55a8536a36 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -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) -- cgit v1.2.3