summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2020-01-22 18:00:18 -0800
committerJulius Werner <jwerner@chromium.org>2020-12-03 00:00:19 +0000
commit9d0cc2aea918eced42dc3825c1ac94d0d4fbc380 (patch)
tree9be158e3f76a533bb95e93fe2f4ef3aa4bb25189 /src/lib
parent8c99c27df10f6c5a120e41ffb0948e357f5a2d20 (diff)
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 <jwerner@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/39306 Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cbfs.c29
1 files changed, 25 insertions, 4 deletions
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;