2020-04-02 23:48:27 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-04-14 09:40:01 +02:00
|
|
|
|
|
|
|
#ifndef _CBFS_H_
|
|
|
|
#define _CBFS_H_
|
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
#include <cbmem.h>
|
2021-01-06 03:54:19 +01:00
|
|
|
#include <commonlib/bsd/cbfs_mdata.h>
|
2015-12-15 20:33:51 +01:00
|
|
|
#include <commonlib/cbfs.h>
|
2020-12-31 02:30:12 +01:00
|
|
|
#include <commonlib/mem_pool.h>
|
2021-11-15 19:13:37 +01:00
|
|
|
#include <commonlib/region.h>
|
2015-05-16 06:39:23 +02:00
|
|
|
#include <program_loading.h>
|
2019-12-12 02:09:39 +01:00
|
|
|
#include <types.h>
|
2020-05-07 02:06:35 +02:00
|
|
|
#include <vb2_sha.h>
|
2009-04-14 09:40:01 +02:00
|
|
|
|
Extend CBFS to support arbitrary ROM source media.
Summary:
Isolate CBFS underlying I/O to board/arch-specific implementations as
"media stream", to allow loading and booting romstage on non-x86.
CBFS functions now all take a new "media source" parameter; use
CBFS_DEFAULT_MEDIA if you simply want to load from main firmware.
API Changes:
cbfs_find => cbfs_get_file.
cbfs_find_file => cbfs_get_file_content.
cbfs_get_file => cbfs_get_file_content with correct type.
CBFS used to work only on memory-mapped ROM (all x86). For platforms like ARM,
the ROM may come from USB, UART, or SPI -- any serial devices and not available
for memory mapping.
To support these devices (and allowing CBFS to read from multiple source
at the same time), CBFS operations are now virtual-ized into "cbfs_media". To
simplify porting existing code, every media source must support both "reading
into pre-allocated memory (read)" and "read and return an allocated buffer
(map)". For devices without native memory-mapped ROM, "cbfs_simple_buffer*"
provides simple memory mapping simulation.
Every CBFS function now takes a cbfs_media* as parameter. CBFS_DEFAULT_MEDIA
is defined for CBFS functions to automatically initialize a per-board default
media (CBFS will internally calls init_default_cbfs_media). Also revised CBFS
function names relying on memory mapped backend (ex, "cbfs_find" => actually
loads files). Now we only have two getters:
struct cbfs_file *entry = cbfs_get_file(media, name);
void *data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
Test results:
- Verified to work on x86/qemu.
- Compiles on ARM, and follow up commit will provide working SPI driver.
Change-Id: Iac911ded25a6f2feffbf3101a81364625bb07746
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2182
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-01-22 11:57:56 +01:00
|
|
|
|
2020-12-30 02:51:04 +01:00
|
|
|
/**********************************************************************************************
|
|
|
|
* CBFS FILE ACCESS APIs *
|
|
|
|
**********************************************************************************************/
|
2020-12-30 02:33:30 +01:00
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
/*
|
|
|
|
* These are the APIs used to access files in CBFS. In order to keep the calls simple and free
|
|
|
|
* of clutter in the common cases, but still offer all advanced functionality when needed, there
|
|
|
|
* are many different variations that are implemented by wrapping the same underlying API with
|
|
|
|
* static inlines. All accessors have in common that they look up files by name, and will
|
|
|
|
* transparently decompress files that are compressed.
|
|
|
|
*
|
|
|
|
* There are three main flavors of CBFS accessors:
|
|
|
|
*
|
|
|
|
* size_t cbfs_load(char *name, void *buf, size_t size): Loads the contents of a CBFS file into
|
|
|
|
* a buffer provided by the caller (by providing pointer and size to it). Will return the
|
|
|
|
* amount of bytes loaded on success, or 0 on error.
|
|
|
|
*
|
|
|
|
* void *cbfs_map(char *name, size_t *size_out): Maps a file into the address space. If the file
|
|
|
|
* is not compressed and the platform supports direct memory-mapping for the boot medium,
|
|
|
|
* a pointer to the platform mapping is returned directly. In all other cases, memory will
|
|
|
|
* be allocated from the cbfs_cache and file data will be loaded into there. Returns a
|
|
|
|
* pointer to the mapping on success, or NULL on error. If an optional size_out parameter
|
|
|
|
* is passed in, it will be filled out with the size of the mapped data. Caller should call
|
|
|
|
* cbfs_unmap() after it is done using the mapping to free up the cbfs_cache if possible.
|
|
|
|
*
|
|
|
|
* void *cbfs_alloc(char *name, cbfs_allocator_t allocator, void *arg, size_t *size_out): Loads
|
|
|
|
* file data into memory provided by a custom allocator function that the caller passes in.
|
|
|
|
* The caller may pass an argument that is passed through verbatim to the allocator.
|
|
|
|
* Returns the pointer returned by the allocator (where the file data was loaded to) on
|
|
|
|
* success, or NULL on error. If an optional size_out parameter is passed in, it will be
|
|
|
|
* filled out with the size of the loaded data.
|
|
|
|
*
|
|
|
|
* void *cbfs_cbmem_alloc(char *name, uint32_t cbmem_id, size_t *size_out): Wrapper around
|
|
|
|
* cbfs_alloc() that will provide an allocator function for allocating space for the file
|
|
|
|
* data in CBMEM, with the provided CBMEM ID.
|
|
|
|
*
|
|
|
|
* All of these flavors have variations with any of the following optional parameters added:
|
|
|
|
*
|
|
|
|
* ..._ro_...: Will force looking up the CBFS file in the read-only CBFS (the "COREBOOT" FMAP
|
|
|
|
* section), even when running in an RW stage from one of the RW CBFSs. Only relevant if
|
|
|
|
* CONFIG(VBOOT) is set.
|
|
|
|
*
|
2021-04-16 08:25:44 +02:00
|
|
|
* ..._unverified_area_...: Will look for the CBFS file in the named FMAP area, rather than
|
|
|
|
* any of the default (RO or RW) CBFSs. Files accessed this way are *not* verified in any
|
|
|
|
* way (even if CONFIG(CBFS_VERIFICATION) is enabled) and should always be treated as
|
|
|
|
* untrusted (potentially malicious) data. Mutually exclusive with the ..._ro_... variant.
|
|
|
|
*
|
2021-01-06 03:54:19 +01:00
|
|
|
* ..._type_...: May pass in an extra enum cbfs_type *type parameter. If the value it points to
|
|
|
|
* is CBFS_TYPE_QUERY, it will be replaced with the actual CBFS type of the found file. If
|
|
|
|
* it is anything else, the type will be compared with the actually found type, and the
|
|
|
|
* operation will fail if they don't match.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An allocator function for passing to cbfs_alloc(). Takes the argument that was originally
|
|
|
|
* passed to cbfs_alloc(), the size of the file to be loaded, and a pointer to the already
|
|
|
|
* loaded and verified file metadata (for rare cases where the allocator needs to check custom
|
|
|
|
* attributes). Must return a pointer to space of the requested size where the file data should
|
|
|
|
* be loaded, or NULL to make the operation fail.
|
|
|
|
*/
|
2021-03-11 01:52:14 +01:00
|
|
|
typedef void *(*cbfs_allocator_t)(void *arg, size_t size, const union cbfs_mdata *mdata);
|
2021-01-06 03:54:19 +01:00
|
|
|
|
|
|
|
static inline size_t cbfs_load(const char *name, void *buf, size_t size);
|
|
|
|
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size);
|
|
|
|
static inline size_t cbfs_type_load(const char *name, void *buf, size_t size,
|
|
|
|
enum cbfs_type *type);
|
|
|
|
static inline size_t cbfs_ro_type_load(const char *name, void *buf, size_t size,
|
|
|
|
enum cbfs_type *type);
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline size_t cbfs_unverified_area_load(const char *area, const char *name,
|
|
|
|
void *buf, size_t size);
|
2020-12-30 02:51:04 +01:00
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_map(const char *name, size_t *size_out);
|
2020-12-30 02:51:04 +01:00
|
|
|
static inline void *cbfs_ro_map(const char *name, size_t *size_out);
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_type_map(const char *name, size_t *size_out, enum cbfs_type *type);
|
|
|
|
static inline void *cbfs_ro_type_map(const char *name, size_t *size_out, enum cbfs_type *type);
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_map(const char *area, const char *name,
|
|
|
|
size_t *size_out);
|
2021-01-06 03:54:19 +01:00
|
|
|
|
|
|
|
static inline void *cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out);
|
|
|
|
static inline void *cbfs_ro_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out);
|
|
|
|
static inline void *cbfs_type_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out, enum cbfs_type *type);
|
|
|
|
static inline void *cbfs_ro_type_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out, enum cbfs_type *type);
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_alloc(const char *area, const char *name,
|
|
|
|
cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out);
|
2021-01-06 03:54:19 +01:00
|
|
|
|
|
|
|
static inline void *cbfs_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out);
|
|
|
|
static inline void *cbfs_ro_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out);
|
|
|
|
static inline void *cbfs_type_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out,
|
|
|
|
enum cbfs_type *type);
|
|
|
|
static inline void *cbfs_ro_type_cbmem_alloc(const char *name, uint32_t cbmem_id,
|
|
|
|
size_t *size_out, enum cbfs_type *type);
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_cbmem_alloc(const char *area, const char *name,
|
|
|
|
uint32_t cbmem_id, size_t *size_out);
|
2020-12-30 02:51:04 +01:00
|
|
|
|
lib/cbfs: Add cbfs_preload()
This API will hide all the complexity of preloading a CBFS file. It
makes it so the callers simply specify the file to preload and CBFS
takes care of the rest. It will start a new thread to read the file into
the cbfs_cache. When the file is actually required (i.e., cbfs_load,
etc) it will wait for the preload thread to complete (if it hasn't
already) and perform verification/decompression using the preloaded
buffer. This design allows decompression/verification to happen in the
main BSP thread so that timestamps are correctly reflected.
BUG=b:179699789
TEST=Test with whole CL chain, verify VGA bios was preloaded and boot
time was reduced by 12ms.
Logs:
Preloading VGA ROM
CBFS DEBUG: _cbfs_preload(name='pci1002,1638.rom', force_ro=false)
CBFS: Found 'pci1002,1638.rom' @0x20ac40 size 0xd800 in mcache @0xcb7dd0f0
spi_dma_readat_dma: start: dest: 0x021c0000, source: 0x51cc80, size: 55296
took 0 us to acquire mutex
start_spi_dma_transaction: dest: 0x021c0000, source: 0x51cc80, remaining: 55296
...
spi_dma_readat_dma: end: dest: 0x021c0000, source: 0x51cc80, remaining: 0
...
CBFS DEBUG: _cbfs_alloc(name='pci1002,1638.rom', alloc=0x00000000(0x00000000), force_ro=false, type=-1)
CBFS: Found 'pci1002,1638.rom' @0x20ac40 size 0xd800 in mcache @0xcb7dd0f0
waiting for thread
took 0 us
CBFS DEBUG: get_preload_rdev(name='pci1002,1638.rom', force_ro=false) preload successful
In CBFS, ROM address for PCI: 03:00.0 = 0x021c0000
PCI expansion ROM, signature 0xaa55, INIT size 0xd800, data ptr 0x01b0
PCI ROM image, vendor ID 1002, device ID 1638,
PCI ROM image, Class Code 030000, Code Type 00
Copying VGA ROM Image from 0x021c0000 to 0xc0000, 0xd800 bytes
$ cbmem
...
40:device configuration 5,399,404 (8,575)
65:Option ROM initialization 5,403,474 (4,070)
66:Option ROM copy done 5,403,488 (14)
...
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: I879fc1316f97417a4b82483d353abdbd02b98a31
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56491
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2021-11-01 20:40:14 +01:00
|
|
|
/*
|
|
|
|
* Starts the processes of preloading a file into RAM.
|
|
|
|
*
|
|
|
|
* This method depends on COOP_MULTITASKING to parallelize the loading. This method is only
|
|
|
|
* effective when the underlying rdev supports DMA operations.
|
|
|
|
*
|
|
|
|
* When `cbfs_load`, `cbfs_alloc`, or `cbfs_map` are called after a preload has been started,
|
|
|
|
* they will wait for the preload to complete (if it hasn't already) and then perform
|
|
|
|
* verification and/or decompression.
|
|
|
|
*
|
|
|
|
* This method does not have a return value because the system should boot regardless if this
|
|
|
|
* method succeeds or fails.
|
|
|
|
*/
|
|
|
|
void cbfs_preload(const char *name);
|
|
|
|
|
2020-12-30 02:33:30 +01:00
|
|
|
/* Removes a previously allocated CBFS mapping. Should try to unmap mappings in strict LIFO
|
|
|
|
order where possible, since mapping backends often don't support more complicated cases. */
|
2020-12-31 02:30:12 +01:00
|
|
|
void cbfs_unmap(void *mapping);
|
2020-12-30 02:33:30 +01:00
|
|
|
|
2015-05-16 06:39:23 +02:00
|
|
|
/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
|
|
|
|
int cbfs_prog_stage_load(struct prog *prog);
|
2014-12-02 00:30:01 +01:00
|
|
|
|
2021-11-15 19:13:37 +01:00
|
|
|
/* Returns the size of a CBFS file, or 0 on error. Avoid using this function to allocate space,
|
|
|
|
and instead use cbfs_alloc() so the file only needs to be looked up once. */
|
|
|
|
static inline size_t cbfs_get_size(const char *name);
|
|
|
|
static inline size_t cbfs_ro_get_size(const char *name);
|
|
|
|
|
|
|
|
/* Returns the type of a CBFS file, or CBFS_TYPE_NULL on error. Use cbfs_type_load() instead of
|
|
|
|
this where possible to avoid looking up the file more than once. */
|
|
|
|
static inline enum cbfs_type cbfs_get_type(const char *name);
|
|
|
|
static inline enum cbfs_type cbfs_ro_get_type(const char *name);
|
|
|
|
|
|
|
|
/* Check whether a CBFS file exists. */
|
|
|
|
static inline bool cbfs_file_exists(const char *name);
|
|
|
|
static inline bool cbfs_ro_file_exists(const char *name);
|
|
|
|
|
2020-12-31 02:30:12 +01:00
|
|
|
|
2020-12-30 02:51:04 +01:00
|
|
|
/**********************************************************************************************
|
|
|
|
* BOOT DEVICE HELPER APIs *
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
2020-12-31 02:30:12 +01:00
|
|
|
/*
|
|
|
|
* The shared memory pool for backing mapped CBFS files, and other CBFS allocation needs.
|
|
|
|
*/
|
|
|
|
extern struct mem_pool cbfs_cache;
|
|
|
|
|
2020-03-05 21:51:08 +01:00
|
|
|
/*
|
2020-12-30 02:33:30 +01:00
|
|
|
* Data structure that represents "a" CBFS boot device, with optional metadata cache. Generally
|
|
|
|
* we only have one of these, or two (RO and RW) when CONFIG(VBOOT) is set. The region device
|
|
|
|
* stored here must always be a subregion of boot_device_ro().
|
2020-03-05 21:51:08 +01:00
|
|
|
*/
|
2019-12-12 02:09:39 +01:00
|
|
|
struct cbfs_boot_device {
|
|
|
|
struct region_device rdev;
|
|
|
|
void *mcache;
|
|
|
|
size_t mcache_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Helper to fill out |mcache| and |mcache_size| in a cbfs_boot_device. */
|
|
|
|
void cbfs_boot_device_find_mcache(struct cbfs_boot_device *cbd, uint32_t id);
|
|
|
|
|
|
|
|
/*
|
2020-12-30 02:33:30 +01:00
|
|
|
* Retrieves the currently active CBFS boot device. If |force_ro| is set, will always return the
|
|
|
|
* read-only CBFS instead (this only makes a difference when CONFIG(VBOOT) is enabled). May
|
|
|
|
* perform certain CBFS initialization tasks. Returns NULL on error (e.g. boot device IO error).
|
2019-12-12 02:09:39 +01:00
|
|
|
*/
|
|
|
|
const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro);
|
Extend CBFS to support arbitrary ROM source media.
Summary:
Isolate CBFS underlying I/O to board/arch-specific implementations as
"media stream", to allow loading and booting romstage on non-x86.
CBFS functions now all take a new "media source" parameter; use
CBFS_DEFAULT_MEDIA if you simply want to load from main firmware.
API Changes:
cbfs_find => cbfs_get_file.
cbfs_find_file => cbfs_get_file_content.
cbfs_get_file => cbfs_get_file_content with correct type.
CBFS used to work only on memory-mapped ROM (all x86). For platforms like ARM,
the ROM may come from USB, UART, or SPI -- any serial devices and not available
for memory mapping.
To support these devices (and allowing CBFS to read from multiple source
at the same time), CBFS operations are now virtual-ized into "cbfs_media". To
simplify porting existing code, every media source must support both "reading
into pre-allocated memory (read)" and "read and return an allocated buffer
(map)". For devices without native memory-mapped ROM, "cbfs_simple_buffer*"
provides simple memory mapping simulation.
Every CBFS function now takes a cbfs_media* as parameter. CBFS_DEFAULT_MEDIA
is defined for CBFS functions to automatically initialize a per-board default
media (CBFS will internally calls init_default_cbfs_media). Also revised CBFS
function names relying on memory mapped backend (ex, "cbfs_find" => actually
loads files). Now we only have two getters:
struct cbfs_file *entry = cbfs_get_file(media, name);
void *data = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type);
Test results:
- Verified to work on x86/qemu.
- Compiles on ARM, and follow up commit will provide working SPI driver.
Change-Id: Iac911ded25a6f2feffbf3101a81364625bb07746
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2182
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
2013-01-22 11:57:56 +01:00
|
|
|
|
2020-05-07 02:06:35 +02:00
|
|
|
/*
|
2020-12-30 02:33:30 +01:00
|
|
|
* Builds the mcache (if |cbd->mcache| is set) and verifies |metadata_hash| (if it is not NULL).
|
|
|
|
* If CB_CBFS_CACHE_FULL is returned, the mcache is incomplete but still valid and the metadata
|
|
|
|
* hash was still verified. Should be called once per *boot* (not once per stage) before the
|
|
|
|
* first CBFS access.
|
2020-05-07 02:06:35 +02:00
|
|
|
*/
|
|
|
|
cb_err_t cbfs_init_boot_device(const struct cbfs_boot_device *cbd,
|
|
|
|
struct vb2_hash *metadata_hash);
|
|
|
|
|
2020-12-30 02:51:04 +01:00
|
|
|
|
|
|
|
/**********************************************************************************************
|
|
|
|
* LEGACY APIs, TO BE DEPRECATED/REPLACED *
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
|
|
|
|
int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
|
|
|
|
/* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/
|
|
|
|
int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
|
|
|
|
const char *name, uint32_t *type);
|
|
|
|
|
|
|
|
/**********************************************************************************************
|
|
|
|
* INTERNAL HELPERS FOR INLINES, DO NOT USE. *
|
|
|
|
**********************************************************************************************/
|
2021-11-15 19:13:37 +01:00
|
|
|
cb_err_t _cbfs_boot_lookup(const char *name, bool force_ro,
|
|
|
|
union cbfs_mdata *mdata, struct region_device *rdev);
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out, bool force_ro, enum cbfs_type *type);
|
|
|
|
|
2021-04-16 08:25:44 +02:00
|
|
|
void *_cbfs_unverified_area_alloc(const char *area, const char *name,
|
|
|
|
cbfs_allocator_t allocator, void *arg, size_t *size_out);
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
struct _cbfs_default_allocator_arg {
|
|
|
|
void *buf;
|
|
|
|
size_t buf_size;
|
|
|
|
};
|
2021-03-11 01:52:14 +01:00
|
|
|
void *_cbfs_default_allocator(void *arg, size_t size, const union cbfs_mdata *unused);
|
2020-12-30 02:51:04 +01:00
|
|
|
|
2021-03-11 01:52:14 +01:00
|
|
|
void *_cbfs_cbmem_allocator(void *arg, size_t size, const union cbfs_mdata *unused);
|
2020-12-30 02:51:04 +01:00
|
|
|
|
|
|
|
/**********************************************************************************************
|
|
|
|
* INLINE IMPLEMENTATIONS *
|
|
|
|
**********************************************************************************************/
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out)
|
|
|
|
{
|
|
|
|
return cbfs_type_alloc(name, allocator, arg, size_out, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out)
|
|
|
|
{
|
|
|
|
return cbfs_ro_type_alloc(name, allocator, arg, size_out, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_type_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out, enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return _cbfs_alloc(name, allocator, arg, size_out, false, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_type_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out, enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return _cbfs_alloc(name, allocator, arg, size_out, true, type);
|
|
|
|
}
|
|
|
|
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_alloc(const char *area, const char *name,
|
|
|
|
cbfs_allocator_t allocator, void *arg,
|
|
|
|
size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_unverified_area_alloc(area, name, allocator, arg, size_out);
|
|
|
|
}
|
|
|
|
|
2020-12-30 02:51:04 +01:00
|
|
|
static inline void *cbfs_map(const char *name, size_t *size_out)
|
|
|
|
{
|
2021-01-06 03:54:19 +01:00
|
|
|
return cbfs_type_map(name, size_out, NULL);
|
2020-12-30 02:51:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_map(const char *name, size_t *size_out)
|
|
|
|
{
|
2021-01-06 03:54:19 +01:00
|
|
|
return cbfs_ro_type_map(name, size_out, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_type_map(const char *name, size_t *size_out, enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return cbfs_type_alloc(name, NULL, NULL, size_out, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_type_map(const char *name, size_t *size_out, enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return cbfs_ro_type_alloc(name, NULL, NULL, size_out, type);
|
|
|
|
}
|
|
|
|
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_map(const char *area, const char *name,
|
|
|
|
size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_unverified_area_alloc(area, name, NULL, NULL, size_out);
|
|
|
|
}
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline size_t _cbfs_load(const char *name, void *buf, size_t size, bool force_ro,
|
|
|
|
enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
struct _cbfs_default_allocator_arg arg = { .buf = buf, .buf_size = size };
|
|
|
|
if (_cbfs_alloc(name, _cbfs_default_allocator, &arg, &size, force_ro, type))
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_load(const char *name, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
return cbfs_type_load(name, buf, size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_type_load(const char *name, void *buf, size_t size,
|
|
|
|
enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return _cbfs_load(name, buf, size, false, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
return cbfs_ro_type_load(name, buf, size, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_ro_type_load(const char *name, void *buf, size_t size,
|
|
|
|
enum cbfs_type *type)
|
|
|
|
{
|
|
|
|
return _cbfs_load(name, buf, size, true, type);
|
|
|
|
}
|
|
|
|
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline size_t cbfs_unverified_area_load(const char *area, const char *name,
|
|
|
|
void *buf, size_t size)
|
|
|
|
{
|
|
|
|
struct _cbfs_default_allocator_arg arg = { .buf = buf, .buf_size = size };
|
|
|
|
if (_cbfs_unverified_area_alloc(area, name, _cbfs_default_allocator, &arg, &size))
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out)
|
|
|
|
{
|
|
|
|
return cbfs_type_cbmem_alloc(name, cbmem_id, size_out, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out)
|
|
|
|
{
|
|
|
|
return cbfs_ro_type_cbmem_alloc(name, cbmem_id, size_out, NULL);
|
2020-12-30 02:51:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_type_cbmem_alloc(const char *name, uint32_t cbmem_id, size_t *size_out,
|
|
|
|
enum cbfs_type *type)
|
2020-12-30 02:51:04 +01:00
|
|
|
{
|
2021-01-06 03:54:19 +01:00
|
|
|
return cbfs_type_alloc(name, _cbfs_cbmem_allocator, (void *)(uintptr_t)cbmem_id,
|
|
|
|
size_out, type);
|
2020-12-30 02:51:04 +01:00
|
|
|
}
|
|
|
|
|
2021-01-06 03:54:19 +01:00
|
|
|
static inline void *cbfs_ro_type_cbmem_alloc(const char *name, uint32_t cbmem_id,
|
|
|
|
size_t *size_out, enum cbfs_type *type)
|
2020-12-30 02:51:04 +01:00
|
|
|
{
|
2021-01-06 03:54:19 +01:00
|
|
|
return cbfs_ro_type_alloc(name, _cbfs_cbmem_allocator, (void *)(uintptr_t)cbmem_id,
|
|
|
|
size_out, type);
|
2020-12-30 02:51:04 +01:00
|
|
|
}
|
|
|
|
|
2021-04-16 08:25:44 +02:00
|
|
|
static inline void *cbfs_unverified_area_cbmem_alloc(const char *area, const char *name,
|
|
|
|
uint32_t cbmem_id, size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_unverified_area_alloc(area, name, _cbfs_cbmem_allocator,
|
|
|
|
(void *)(uintptr_t)cbmem_id, size_out);
|
|
|
|
}
|
|
|
|
|
2021-11-15 19:13:37 +01:00
|
|
|
static inline size_t cbfs_get_size(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, false, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
return be32toh(mdata.h.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_ro_get_size(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, true, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
return be32toh(mdata.h.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum cbfs_type cbfs_get_type(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, false, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return CBFS_TYPE_NULL;
|
|
|
|
return be32toh(mdata.h.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum cbfs_type cbfs_ro_get_type(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, true, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return CBFS_TYPE_NULL;
|
|
|
|
return be32toh(mdata.h.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cbfs_file_exists(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, false, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cbfs_ro_file_exists(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
struct region_device rdev;
|
|
|
|
if (_cbfs_boot_lookup(name, true, &mdata, &rdev) != CB_SUCCESS)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-14 09:40:01 +02:00
|
|
|
#endif
|