From db29b3765b1d760c4fff4e21b27a4aabe218f4ab Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 12 Jan 2022 15:42:49 -0800 Subject: libpayload: Fix legacy CBFS code after recent refactoring The goal when adding the new CBFS API in CB:59497 was that the old CBFS code would be left completely untouched and just moved to the side a bit, so that it could continue to work for the payloads that use it until they all have time to transition to the new CBFS API. Unfortunately, between the different iterations of the patch something went wrong with that and the final committed version of cbfs_legacy.c does differ in some parts from the original code, including a changed macro definition that breaks decompression support. This patch restores all the legacy CBFS files to exactly what they used to be (other than the necessary changes in cbfs_core.h to avoid double definition clashes). Signed-off-by: Julius Werner Change-Id: Ic7fd428acb03d3830f66f807cd1d7cdbd652f409 Reviewed-on: https://review.coreboot.org/c/coreboot/+/61061 Tested-by: build bot (Jenkins) Reviewed-by: Jakub Czapiga --- payloads/libpayload/include/cbfs_legacy.h | 1 - payloads/libpayload/libcbfs/cbfs_core.c | 1 + payloads/libpayload/libcbfs/cbfs_legacy.c | 88 +++++++++++++++++++------------ 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/payloads/libpayload/include/cbfs_legacy.h b/payloads/libpayload/include/cbfs_legacy.h index c1b896cea443..c98da0c112cc 100644 --- a/payloads/libpayload/include/cbfs_legacy.h +++ b/payloads/libpayload/include/cbfs_legacy.h @@ -46,7 +46,6 @@ #define _CBFS_LEGACY_H_ #include -#include /* legacy APIs */ const struct cbfs_header *get_cbfs_header(void); diff --git a/payloads/libpayload/libcbfs/cbfs_core.c b/payloads/libpayload/libcbfs/cbfs_core.c index bc513682c9eb..82c28460545a 100644 --- a/payloads/libpayload/libcbfs/cbfs_core.c +++ b/payloads/libpayload/libcbfs/cbfs_core.c @@ -242,6 +242,7 @@ void *cbfs_get_contents(struct cbfs_handle *handle, size_t *size, size_t limit) cbfs_get_attr(handle, CBFS_FILE_ATTR_TAG_COMPRESSION); if (comp) { algo = ntohl(comp->compression); + DEBUG("File '%s' is compressed (alg=%d)\n", name, algo); *size = ntohl(comp->decompressed_size); /* TODO: Implement partial decompression with |limit| */ } diff --git a/payloads/libpayload/libcbfs/cbfs_legacy.c b/payloads/libpayload/libcbfs/cbfs_legacy.c index 8249196d9a7d..d24b528dedff 100644 --- a/payloads/libpayload/libcbfs/cbfs_legacy.c +++ b/payloads/libpayload/libcbfs/cbfs_legacy.c @@ -26,34 +26,55 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - -#include -#if CONFIG(LP_LZMA) -# include -# define CB_CBFS_CORE_WITH_LZMA -#endif -#if CONFIG(LP_LZ4) -# include -# define CB_CBFS_CORE_WITH_LZ4 +#define LIBPAYLOAD + +#ifdef LIBPAYLOAD +# include +# if CONFIG(LP_LZMA) +# include +# define CBFS_CORE_WITH_LZMA +# endif +# if CONFIG(LP_LZ4) +# include +# define CBFS_CORE_WITH_LZ4 +# endif +# define CBFS_MINI_BUILD +#elif defined(__SMM__) +# define CBFS_MINI_BUILD +#else +# define CBFS_CORE_WITH_LZMA +# define CBFS_CORE_WITH_LZ4 +# include #endif -#include -#include - -#define DEBUG(x...) -#define LOG(x...) -#define ERROR(x...) printf(x) - -#ifndef __SMM__ +#include +#include + +#ifdef LIBPAYLOAD +# include +# define DEBUG(x...) +# define LOG(x...) +# define ERROR(x...) printf(x) +#else +# include +# define ERROR(x...) printk(BIOS_ERR, "CBFS: " x) +# define LOG(x...) printk(BIOS_INFO, "CBFS: " x) +# if CONFIG_LP_DEBUG_CBFS +# define DEBUG(x...) printk(BIOS_SPEW, "CBFS: " x) +# else +# define DEBUG(x...) +# endif +#endif #include "cbfs_core.c" +#ifndef __SMM__ static inline int tohex4(unsigned int c) { return (c <= 9) ? (c + '0') : (c - 10 + 'a'); } -static void tohex16(unsigned int val, char *dest) +static void tohex16(unsigned int val, char* dest) { dest[0] = tohex4(val>>12); dest[1] = tohex4((val>>8) & 0xf); @@ -72,7 +93,7 @@ void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor, return cbfs_get_file_content(media, name, CBFS_TYPE_OPTIONROM, NULL); } -void *cbfs_load_stage(struct cbfs_media *media, const char *name) +void * cbfs_load_stage(struct cbfs_media *media, const char *name) { struct cbfs_stage *stage = (struct cbfs_stage *) cbfs_get_file_content(media, name, CBFS_TYPE_STAGE, NULL); @@ -84,8 +105,10 @@ void *cbfs_load_stage(struct cbfs_media *media, const char *name) if (stage == NULL) return (void *) -1; - LOG("loading stage %s @ %p (%d bytes), entry @ 0x%llx\n", name, - (void *)(uintptr_t)stage->load, stage->memlen, stage->entry); + LOG("loading stage %s @ %p (%d bytes), entry @ 0x%llx\n", + name, + (void*)(uintptr_t) stage->load, stage->memlen, + stage->entry); final_size = cbfs_decompress(stage->compression, ((unsigned char *) stage) + @@ -138,8 +161,7 @@ void *cbfs_load_payload(struct cbfs_media *media, const char *name) media, name, CBFS_TYPE_SELF, NULL); } -struct cbfs_file *cbfs_find(const char *name) -{ +struct cbfs_file *cbfs_find(const char *name) { struct cbfs_handle *handle = cbfs_get_handle(CBFS_DEFAULT_MEDIA, name); struct cbfs_media *m = &handle->media; void *ret; @@ -158,21 +180,19 @@ struct cbfs_file *cbfs_find(const char *name) return ret; } -void *cbfs_find_file(const char *name, int type) -{ +void *cbfs_find_file(const char *name, int type) { return cbfs_get_file_content(CBFS_DEFAULT_MEDIA, name, type, NULL); } -const struct cbfs_header *get_cbfs_header(void) -{ +const struct cbfs_header *get_cbfs_header(void) { return cbfs_get_header(CBFS_DEFAULT_MEDIA); } /* Simple buffer */ -void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer, struct cbfs_media *media, - size_t offset, size_t count) -{ +void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer, + struct cbfs_media *media, + size_t offset, size_t count) { void *address = buffer->buffer + buffer->allocated; DEBUG("simple_buffer_map(offset=%zu, count=%zu): " "allocated=%zu, size=%zu, last_allocate=%zu\n", @@ -190,8 +210,8 @@ void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer, struct cbfs_medi return address; } -void *cbfs_simple_buffer_unmap(struct cbfs_simple_buffer *buffer, const void *address) -{ +void *cbfs_simple_buffer_unmap(struct cbfs_simple_buffer *buffer, + const void *address) { // TODO Add simple buffer management so we can free more than last // allocated one. DEBUG("simple_buffer_unmap(address=%p): " @@ -215,9 +235,9 @@ void *cbfs_simple_buffer_unmap(struct cbfs_simple_buffer *buffer, const void *ad int run_address(void *f) { - int (*v)(void); + int (*v) (void); v = f; return v(); } -#endif /* __SMM__ */ +#endif -- cgit v1.2.3