diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commonlib/include/commonlib/cbfs_serialized.h | 1 | ||||
-rw-r--r-- | src/include/cbfs.h | 4 | ||||
-rw-r--r-- | src/lib/cbfs.c | 21 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/commonlib/include/commonlib/cbfs_serialized.h b/src/commonlib/include/commonlib/cbfs_serialized.h index 1e394d280f..706f175268 100644 --- a/src/commonlib/include/commonlib/cbfs_serialized.h +++ b/src/commonlib/include/commonlib/cbfs_serialized.h @@ -77,6 +77,7 @@ #define CBFS_TYPE_MRC 0x61 #define CBFS_TYPE_MMA 0x62 #define CBFS_TYPE_EFI 0x63 +#define CBFS_TYPE_STRUCT 0x70 #define CBFS_COMPONENT_CMOS_DEFAULT 0xaa #define CBFS_TYPE_SPD 0xab #define CBFS_TYPE_MRC_CACHE 0xac diff --git a/src/include/cbfs.h b/src/include/cbfs.h index 6d9dd42d72..6063dd6f9e 100644 --- a/src/include/cbfs.h +++ b/src/include/cbfs.h @@ -34,6 +34,10 @@ int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type); * leaking mappings are a no-op. Returns NULL on error, else returns * the mapping and sets the size of the file. */ void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size); +/* Load a struct file from CBFS into a buffer. Returns amount of loaded + * bytes on success or 0 on error. File will get decompressed as necessary. + * Same decompression requirements as cbfs_load_and_decompress(). */ +size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size); /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes * large |buffer|, decompressing it according to |compression| in the process. 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; |