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>
			
			
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user