Aaron Durbin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/41448 )
Change subject: cbfs: add cbfs_boot_locate_file_get_compression_info() ......................................................................
cbfs: add cbfs_boot_locate_file_get_compression_info()
There's no current way to obtain the decompression information (algo and size) with the current API. Therefore, split cbfs_boot_load_file() up and add cbfs_boot_locate_file_get_compression_info() so other callers can obtain the same infromation.
BUG=b:155322763,b:150746858,b:152909132
Change-Id: I605b036a50ed26ad6897b5b86a37897766169e6b Signed-off-by: Aaron Durbin adurbin@chromium.org --- M src/include/cbfs.h M src/lib/cbfs.c 2 files changed, 21 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/48/41448/1
diff --git a/src/include/cbfs.h b/src/include/cbfs.h index 29621c6..172b4b1 100644 --- a/src/include/cbfs.h +++ b/src/include/cbfs.h @@ -23,6 +23,11 @@ /* 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); +/* Locate file by name filling in the cbfs_type and compression information. + Returns 0 on success, < 0 on error. */ +int cbfs_boot_locate_file_get_compression_info(struct cbfsf *fh, + const char *name, uint32_t *cbfs_type, + uint32_t *compression_algo, size_t *decompressed_size); /* Load an arbitrary type 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 diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index a3294de..c6767b0 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -189,6 +189,19 @@ return cbfs_boot_map_with_leak(name, CBFS_TYPE_OPTIONROM, NULL); }
+int cbfs_boot_locate_file_get_compression_info(struct cbfsf *fh, + const char *name, uint32_t *cbfs_type, + uint32_t *compression_algo, size_t *decompressed_size) +{ + if (cbfs_boot_locate(fh, name, cbfs_type) < 0) + return -1; + + if (cbfsf_decompression_info(fh, compression_algo, decompressed_size) < 0) + return -1; + + return 0; +} + size_t cbfs_boot_load_file(const char *name, void *buf, size_t buf_size, uint32_t type) { @@ -196,13 +209,11 @@ uint32_t compression_algo; size_t decompressed_size;
- if (cbfs_boot_locate(&fh, name, &type) < 0) + if (cbfs_boot_locate_file_get_compression_info(&fh, name, &type, + &compression_algo, &decompressed_size) < 0) return 0;
- if (cbfsf_decompression_info(&fh, &compression_algo, - &decompressed_size) - < 0 - || decompressed_size > buf_size) + if (decompressed_size > buf_size) return 0;
return cbfs_load_and_decompress(&fh.data, 0, region_device_sz(&fh.data),