From 9d0cc2aea918eced42dc3825c1ac94d0d4fbc380 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 22 Jan 2020 18:00:18 -0800 Subject: cbfs: Introduce cbfs_ro_map() and cbfs_ro_load() This patch introduces two new CBFS API functions which are equivalent to cbfs_map() and cbfs_load(), respectively, with the difference that they always operate on the read-only CBFS region ("COREBOOT" FMAP section). Use it to replace some of the simple cases that needed to use cbfs_locate_file_in_region(). Change-Id: I9c55b022b6502a333a9805ab0e4891dd7b97ef7f Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/c/coreboot/+/39306 Reviewed-by: Furquan Shaikh Reviewed-by: Patrick Georgi Tested-by: build bot (Jenkins) --- src/lib/cbfs.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 8d868a6be3..beab74ec4d 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -70,12 +70,12 @@ int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type) return 0; } -void *cbfs_map(const char *name, size_t *size_out) +static void *_cbfs_map(const char *name, size_t *size_out, bool force_ro) { struct region_device rdev; union cbfs_mdata mdata; - if (cbfs_boot_lookup(name, false, &mdata, &rdev)) + if (cbfs_boot_lookup(name, force_ro, &mdata, &rdev)) return NULL; if (size_out != NULL) @@ -84,6 +84,16 @@ void *cbfs_map(const char *name, size_t *size_out) return rdev_mmap_full(&rdev); } +void *cbfs_map(const char *name, size_t *size_out) +{ + return _cbfs_map(name, size_out, false); +} + +void *cbfs_ro_map(const char *name, size_t *size_out) +{ + return _cbfs_map(name, size_out, true); +} + int cbfs_unmap(void *mapping) { /* This works because munmap() only works on the root rdev and never @@ -281,12 +291,13 @@ void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t return cbfs_map(name, NULL); } -size_t cbfs_load(const char *name, void *buf, size_t buf_size) +static size_t _cbfs_load(const char *name, void *buf, size_t buf_size, + bool force_ro) { struct region_device rdev; union cbfs_mdata mdata; - if (cbfs_boot_lookup(name, false, &mdata, &rdev)) + if (cbfs_boot_lookup(name, force_ro, &mdata, &rdev)) return 0; uint32_t compression = CBFS_COMPRESS_NONE; @@ -302,6 +313,16 @@ size_t cbfs_load(const char *name, void *buf, size_t buf_size) buf, buf_size, compression); } +size_t cbfs_load(const char *name, void *buf, size_t buf_size) +{ + return _cbfs_load(name, buf, buf_size, false); +} + +size_t cbfs_ro_load(const char *name, void *buf, size_t buf_size) +{ + return _cbfs_load(name, buf, buf_size, true); +} + int cbfs_prog_stage_load(struct prog *pstage) { struct cbfs_stage stage; -- cgit v1.2.3