From d66f1da846f8e524a6211518c46a993d563b4ffc Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Thu, 9 Jul 2015 15:07:45 -0700 Subject: libpayload: allow compression at file header level Decompression is handled transparently within cbfs_get_file_content: const char *name = "foo.bmp"; void *dst = cbfs_get_file_content(media, name, type, NULL); To keep things consistent, a couple of API changes were necessary: - cbfs_get_file_content always returns a copy of the data, even for uncompressed files. It's the callers responsibility to free the memory. - same for cbfs_load_payload and cbfs_find_file. - cbfs_load_optionrom doesn't take a "dest" argument anymore but always returns a copy of the data, for compressed and uncompressed files. Like with cbfs_get_file_content, the caller is responsible to free it. It also decompresses based on extended file attributes instead of the cbfs_optionrom subheader that libpayload specified but that (AFAIK) nobody ever used, given that there's not even tooling for that. Change-Id: If959e3dff9b93c6ae45ec7358afcc7840bc17218 Signed-off-by: Daisuke Nojiri Signed-off-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/10938 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- payloads/libpayload/include/cbfs_core.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'payloads/libpayload/include/cbfs_core.h') diff --git a/payloads/libpayload/include/cbfs_core.h b/payloads/libpayload/include/cbfs_core.h index a2ee74459b..3878e55f23 100644 --- a/payloads/libpayload/include/cbfs_core.h +++ b/payloads/libpayload/include/cbfs_core.h @@ -53,6 +53,7 @@ #include #include #include +#include /** These are standard values for the known compression alogrithms that coreboot knows about for stages and @@ -141,6 +142,7 @@ struct cbfs_file { * 0xff. Support both. */ #define CBFS_FILE_ATTR_TAG_UNUSED 0 #define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff +#define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c /* The common fields of extended cbfs file attributes. Attributes are expected to start with tag/len, then append their @@ -152,6 +154,14 @@ struct cbfs_file_attribute { uint8_t data[0]; } __attribute__((packed)); +struct cbfs_file_attr_compression { + uint32_t tag; + uint32_t len; + /* whole file compression format. 0 if no compression. */ + uint32_t compression; + uint32_t decompressed_size; +} __attribute__((packed)); + /* Given a cbfs_file, return the first file attribute, or NULL. */ struct cbfs_file_attribute *cbfs_file_first_attr(struct cbfs_file *file); @@ -237,10 +247,14 @@ struct cbfs_media { int (*close)(struct cbfs_media *media); }; -/* returns pointer to a file entry inside CBFS or NULL */ +/* returns pointer to a file entry inside CBFS or NULL on error */ struct cbfs_file *cbfs_get_file(struct cbfs_media *media, const char *name); -/* returns pointer to file content inside CBFS after if type is correct */ +/* + * Returns pointer to a copy of the file content or NULL on error. + * If the file is compressed, data will be decompressed. + * The caller owns the returned memory. + */ void *cbfs_get_file_content(struct cbfs_media *media, const char *name, int type, size_t *sz); -- cgit v1.2.3