diff options
author | Aaron Durbin <adurbin@chromium.org> | 2015-09-17 16:09:30 -0500 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-10-07 10:46:11 +0000 |
commit | 37a5d15da92a9fb8a682a32ef1eaf37734fcc5ad (patch) | |
tree | 8f37c1712f44789501a830fdaaaf22012972738c /src/lib | |
parent | 72bb66eb9cecf94b66a4aca3586165d5495fcfdb (diff) | |
download | coreboot-37a5d15da92a9fb8a682a32ef1eaf37734fcc5ad.tar.xz |
cbfs: add struct cbfsf
Now that cbfs is adding more metadata in the cbfs file
header one needs to access that metadata. Therefore,
add struct cbfsf which tracks the metadata and data
of the file separately. Note that stage and payload
metadata specific to itself is still contained within
the 'data' portion of a cbfs file. Update the cbfs
API to use struct cbfsf. Additionally, remove struct
cbfsd as there's nothing else associated with a cbfs
region aside from offset and size which tracked
by a region_device (thanks, CBFS_ALIGNMENT!).
BUG=None
BRANCH=None
TEST=Built and booted through end of ramstage on qemu armv7.
Built and booted glados using Chrome OS.
Change-Id: I05486c6cf6cfcafa5c64b36324833b2374f763c2
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/11679
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/assets.c | 9 | ||||
-rw-r--r-- | src/lib/cbfs.c | 43 |
2 files changed, 29 insertions, 23 deletions
diff --git a/src/lib/assets.c b/src/lib/assets.c index 656f0b1e2b..0115243b22 100644 --- a/src/lib/assets.c +++ b/src/lib/assets.c @@ -31,7 +31,14 @@ #if DEFAULT_CBFS_PROVIDER_PRESENT static int cbfs_boot_asset_locate(struct asset *asset) { - return cbfs_boot_locate(&asset->rdev, asset->name, NULL); + struct cbfsf file; + + if (cbfs_boot_locate(&file, asset_name(asset), NULL)) + return -1; + + cbfs_file_data(asset_rdev(asset), &file); + + return 0; } static const struct asset_provider cbfs_default_provider = { diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index abc40770af..05b939cdfe 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -35,9 +35,8 @@ #define DEBUG(x...) #endif -int cbfs_boot_locate(struct region_device *fh, const char *name, uint32_t *type) +int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type) { - struct cbfsd cbfs; struct region_device rdev; const struct region_device *boot_dev; struct cbfs_props props; @@ -56,35 +55,29 @@ int cbfs_boot_locate(struct region_device *fh, const char *name, uint32_t *type) if (rdev_chain(&rdev, boot_dev, props.offset, props.size)) return -1; - cbfs.rdev = &rdev; - - return cbfs_locate(fh, &cbfs, name, type); + return cbfs_locate(fh, &rdev, name, type); } void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size) { - struct region_device fh; + struct cbfsf fh; size_t fsize; if (cbfs_boot_locate(&fh, name, &type)) return NULL; - fsize = region_device_sz(&fh); + fsize = region_device_sz(&fh.data); if (size != NULL) *size = fsize; - return rdev_mmap(&fh, 0, fsize); + return rdev_mmap(&fh.data, 0, fsize); } -int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs, +int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, const char *name, uint32_t *type) { - size_t offset; - const struct region_device *rd; - - offset = 0; - rd = cbfs->rdev; + size_t offset = 0; LOG("Locating '%s'\n", name); @@ -99,7 +92,7 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs, DEBUG("Checking offset %zx\n", offset); /* Can't read file. Nothing else to do but bail out. */ - if (rdev_readat(rd, &file, offset, fsz) != fsz) + if (rdev_readat(cbfs, &file, offset, fsz) != fsz) break; if (memcmp(file.magic, CBFS_FILE_MAGIC, sizeof(file.magic))) { @@ -113,13 +106,13 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs, file.offset = ntohl(file.offset); /* See if names match. */ - fname = rdev_mmap(rd, offset + fsz, file.offset - fsz); + fname = rdev_mmap(cbfs, offset + fsz, file.offset - fsz); if (fname == NULL) break; name_match = !strcmp(fname, name); - rdev_munmap(rd, fname); + rdev_munmap(cbfs, fname); if (!name_match) { DEBUG(" Unmatched '%s' at %zx\n", fname, offset); @@ -136,11 +129,13 @@ int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs, } LOG("Found @ offset %zx size %x\n", offset, file.len); - /* File and type match. Create a chained region_device to - * represent the cbfs file. */ + /* 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, rd, offset, datasz)) + if (rdev_chain(&fh->data, cbfs, offset, datasz)) break; /* Success. */ @@ -185,12 +180,16 @@ void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device) void *cbfs_boot_load_stage_by_name(const char *name) { + struct cbfsf fh; struct prog stage = PROG_INIT(ASSET_UNKNOWN, name); uint32_t type = CBFS_TYPE_STAGE; - if (cbfs_boot_locate(&stage.asset.rdev, name, &type)) + if (cbfs_boot_locate(&fh, name, &type)) return NULL; + /* Chain data portion in the prog. */ + cbfs_file_data(prog_rdev(&stage), &fh); + if (cbfs_prog_stage_load(&stage)) return NULL; @@ -204,7 +203,7 @@ int cbfs_prog_stage_load(struct prog *pstage) void *entry; size_t fsize; size_t foffset; - const struct region_device *fh = &pstage->asset.rdev; + const struct region_device *fh = prog_rdev(pstage); if (rdev_readat(fh, &stage, 0, sizeof(stage)) != sizeof(stage)) return 0; |