diff options
author | Julius Werner <jwerner@chromium.org> | 2021-01-05 18:54:19 -0800 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2021-03-08 22:31:43 +0000 |
commit | 7778cf2d30f780fc5bf867af8171a5cd6c47b835 (patch) | |
tree | 3adab3eedb175e7013f7bb8bbe537b1524cd8d65 /src/commonlib/bsd/include | |
parent | 9b1f3cc6fb129789f1dd28160a83a1ea59dd123a (diff) |
cbfs: Add cbfs_alloc() primitive and combine cbfs_load() and cbfs_map()
This patchs adds a new CBFS primitive that allows callers to pass in an
allocator function that will be called once the size of the file to load
is known, to decide on its final location. This can be useful for
loading a CBFS file straight into CBMEM, for example. The new primitive
is combined with cbfs_map() and cbfs_load() into a single underlying
function that can handle all operations, to reduce the amount of code
that needs to be duplicated (especially later when file verification is
added). Also add a new variation that allows restraining or querying the
CBFS type of a file as it is being loaded, and reorganize the
documentation/definition of all these accessors and variations in the
header file a little.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I5fe0645387c0e9053ad5c15744437940fc904392
Reviewed-on: https://review.coreboot.org/c/coreboot/+/49334
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/commonlib/bsd/include')
3 files changed, 31 insertions, 18 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_mdata.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_mdata.h new file mode 100644 index 0000000000..df13427c5f --- /dev/null +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_mdata.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */ + +#ifndef _COMMONLIB_BSD_CBFS_MDATA_H_ +#define _COMMONLIB_BSD_CBFS_MDATA_H_ + +#include <commonlib/bsd/cbfs_serialized.h> +#include <stddef.h> +#include <stdint.h> + +/* + * Helper structure to allocate space for a blob of metadata on the stack. + * NOTE: The fields in any union cbfs_mdata or any of its substructures from cbfs_serialized.h + * should always remain in the same byte order as they are stored on flash (= big endian). To + * avoid byte-order confusion, fields should always and only be converted to host byte order at + * exactly the time they are read from one of these structures into their own separate variable. + */ +union cbfs_mdata { + struct cbfs_file h; + uint8_t raw[CBFS_METADATA_MAX_SIZE]; +}; + +/* Finds a CBFS attribute in a metadata block. Attribute returned as-is (still big-endian). + If |size| is not 0, will check that it matches the length of the attribute (if found)... + else caller is responsible for checking the |len| field to avoid reading out-of-bounds. */ +const void *cbfs_find_attr(const union cbfs_mdata *mdata, uint32_t attr_tag, size_t size_check); + +#endif /* _COMMONLIB_BSD_CBFS_MDATA_H_ */ diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h index df5014355c..fc2d0d0457 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h @@ -5,7 +5,7 @@ #include <commonlib/bsd/cb_err.h> -#include <commonlib/bsd/cbfs_serialized.h> +#include <commonlib/bsd/cbfs_mdata.h> #include <commonlib/bsd/sysincludes.h> #include <stdbool.h> #include <stdint.h> @@ -41,18 +41,6 @@ */ #include <cbfs_glue.h> -/* - * Helper structure to allocate space for a blob of metadata on the stack. - * NOTE: The fields in any union cbfs_mdata or any of its substructures from cbfs_serialized.h - * should always remain in the same byte order as they are stored on flash (= big endian). To - * avoid byte-order confusion, fields should always and only be converted to host byte order at - * exactly the time they are read from one of these structures into their own separate variable. - */ -union cbfs_mdata { - struct cbfs_file h; - uint8_t raw[CBFS_METADATA_MAX_SIZE]; -}; - /* Flags that modify behavior of cbfs_walk(). */ enum cbfs_walk_flags { /* Write the calculated hash back out to |metadata_hash->hash| rather than comparing it. @@ -130,9 +118,4 @@ cb_err_t cbfs_mcache_lookup(const void *mcache, size_t mcache_size, const char * /* Returns the amount of bytes actually used by the CBFS metadata cache in |mcache|. */ size_t cbfs_mcache_real_size(const void *mcache, size_t mcache_size); -/* Finds a CBFS attribute in a metadata block. Attribute returned as-is (still big-endian). - If |size| is not 0, will check that it matches the length of the attribute (if found)... - else caller is responsible for checking the |len| field to avoid reading out-of-bounds. */ -const void *cbfs_find_attr(const union cbfs_mdata *mdata, uint32_t attr_tag, size_t size_check); - #endif /* _COMMONLIB_BSD_CBFS_PRIVATE_H_ */ diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h index dd504695b3..dc14cd5f49 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h @@ -13,6 +13,9 @@ enum cbfs_compression { }; enum cbfs_type { + /* QUERY is an alias for DELETED that can be passed to CBFS APIs to + inquire about the type of a file, rather than constrain it. */ + CBFS_TYPE_QUERY = 0, CBFS_TYPE_DELETED = 0x00000000, CBFS_TYPE_NULL = 0xffffffff, CBFS_TYPE_BOOTBLOCK = 0x01, |