From f975e55dcdbeb31e39449d22a9c04ff861dae8dd Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 19 Aug 2016 15:43:06 -0700 Subject: cbfs: Add "struct" file type and associated helpers This patch adds functionality to compile a C data structure into a raw binary file, add it to CBFS and allow coreboot to load it at runtime. This is useful in all cases where we need to be able to have several larger data sets available in an image, but will only require a small subset of them at boot (a classic example would be DRAM parameters) or only require it in certain boot modes. This allows us to load less data from flash and increase boot speed compared to solutions that compile all data sets into a stage. Each structure has to be defined in a separate .c file which contains no functions and only a single global variable. The data type must be serialization safe (composed of only fixed-width types, paying attention to padding). It must be added to CBFS in a Makefile with the 'struct' file processor. Change-Id: Iab65c0b6ebea235089f741eaa8098743e54d6ccc Signed-off-by: Julius Werner Reviewed-on: https://review.coreboot.org/16272 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/lib/cbfs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/lib') diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 7318c87937..5a2f63f95d 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -79,6 +79,8 @@ size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, switch (compression) { case CBFS_COMPRESS_NONE: + if (buffer_size < in_size) + return 0; if (rdev_readat(rdev, buffer, offset, in_size) != in_size) return 0; return in_size; @@ -166,6 +168,25 @@ void *cbfs_boot_load_stage_by_name(const char *name) return prog_entry(&stage); } +size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size) +{ + struct cbfsf fh; + uint32_t compression_algo; + size_t decompressed_size; + uint32_t type = CBFS_TYPE_STRUCT; + + if (cbfs_boot_locate(&fh, name, &type) < 0) + return 0; + + if (cbfsf_decompression_info(&fh, &compression_algo, + &decompressed_size) < 0 + || decompressed_size > buf_size) + return 0; + + return cbfs_load_and_decompress(&fh.data, 0, region_device_sz(&fh.data), + buf, buf_size, compression_algo); +} + int cbfs_prog_stage_load(struct prog *pstage) { struct cbfs_stage stage; -- cgit v1.2.3