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 <jwerner@chromium.org> Change-Id: Ic7fd428acb03d3830f66f807cd1d7cdbd652f409 Reviewed-on: https://review.coreboot.org/c/coreboot/+/61061 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
This commit is contained in:
parent
f04e83abbf
commit
db29b3765b
|
@ -46,7 +46,6 @@
|
||||||
#define _CBFS_LEGACY_H_
|
#define _CBFS_LEGACY_H_
|
||||||
|
|
||||||
#include <cbfs_core.h>
|
#include <cbfs_core.h>
|
||||||
#include <libpayload.h>
|
|
||||||
|
|
||||||
/* legacy APIs */
|
/* legacy APIs */
|
||||||
const struct cbfs_header *get_cbfs_header(void);
|
const struct cbfs_header *get_cbfs_header(void);
|
||||||
|
|
|
@ -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);
|
cbfs_get_attr(handle, CBFS_FILE_ATTR_TAG_COMPRESSION);
|
||||||
if (comp) {
|
if (comp) {
|
||||||
algo = ntohl(comp->compression);
|
algo = ntohl(comp->compression);
|
||||||
|
DEBUG("File '%s' is compressed (alg=%d)\n", name, algo);
|
||||||
*size = ntohl(comp->decompressed_size);
|
*size = ntohl(comp->decompressed_size);
|
||||||
/* TODO: Implement partial decompression with |limit| */
|
/* TODO: Implement partial decompression with |limit| */
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,28 +26,49 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
#define LIBPAYLOAD
|
||||||
|
|
||||||
|
#ifdef LIBPAYLOAD
|
||||||
# include <libpayload-config.h>
|
# include <libpayload-config.h>
|
||||||
# if CONFIG(LP_LZMA)
|
# if CONFIG(LP_LZMA)
|
||||||
# include <lzma.h>
|
# include <lzma.h>
|
||||||
# define CB_CBFS_CORE_WITH_LZMA
|
# define CBFS_CORE_WITH_LZMA
|
||||||
# endif
|
# endif
|
||||||
# if CONFIG(LP_LZ4)
|
# if CONFIG(LP_LZ4)
|
||||||
# include <lz4.h>
|
# include <lz4.h>
|
||||||
# define CB_CBFS_CORE_WITH_LZ4
|
# 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 <lib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cbfs_legacy.h>
|
#include <cbfs.h>
|
||||||
#include <stdio.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef LIBPAYLOAD
|
||||||
|
# include <stdio.h>
|
||||||
# define DEBUG(x...)
|
# define DEBUG(x...)
|
||||||
# define LOG(x...)
|
# define LOG(x...)
|
||||||
# define ERROR(x...) printf(x)
|
# define ERROR(x...) printf(x)
|
||||||
|
#else
|
||||||
#ifndef __SMM__
|
# include <console/console.h>
|
||||||
|
# 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"
|
#include "cbfs_core.c"
|
||||||
|
|
||||||
|
#ifndef __SMM__
|
||||||
static inline int tohex4(unsigned int c)
|
static inline int tohex4(unsigned int c)
|
||||||
{
|
{
|
||||||
return (c <= 9) ? (c + '0') : (c - 10 + 'a');
|
return (c <= 9) ? (c + '0') : (c - 10 + 'a');
|
||||||
|
@ -84,8 +105,10 @@ void *cbfs_load_stage(struct cbfs_media *media, const char *name)
|
||||||
if (stage == NULL)
|
if (stage == NULL)
|
||||||
return (void *) -1;
|
return (void *) -1;
|
||||||
|
|
||||||
LOG("loading stage %s @ %p (%d bytes), entry @ 0x%llx\n", name,
|
LOG("loading stage %s @ %p (%d bytes), entry @ 0x%llx\n",
|
||||||
(void *)(uintptr_t)stage->load, stage->memlen, stage->entry);
|
name,
|
||||||
|
(void*)(uintptr_t) stage->load, stage->memlen,
|
||||||
|
stage->entry);
|
||||||
|
|
||||||
final_size = cbfs_decompress(stage->compression,
|
final_size = cbfs_decompress(stage->compression,
|
||||||
((unsigned char *) stage) +
|
((unsigned char *) stage) +
|
||||||
|
@ -138,8 +161,7 @@ void *cbfs_load_payload(struct cbfs_media *media, const char *name)
|
||||||
media, name, CBFS_TYPE_SELF, NULL);
|
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_handle *handle = cbfs_get_handle(CBFS_DEFAULT_MEDIA, name);
|
||||||
struct cbfs_media *m = &handle->media;
|
struct cbfs_media *m = &handle->media;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
@ -158,21 +180,19 @@ struct cbfs_file *cbfs_find(const char *name)
|
||||||
return ret;
|
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);
|
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);
|
return cbfs_get_header(CBFS_DEFAULT_MEDIA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simple buffer */
|
/* Simple buffer */
|
||||||
|
|
||||||
void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer, struct cbfs_media *media,
|
void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer,
|
||||||
size_t offset, size_t count)
|
struct cbfs_media *media,
|
||||||
{
|
size_t offset, size_t count) {
|
||||||
void *address = buffer->buffer + buffer->allocated;
|
void *address = buffer->buffer + buffer->allocated;
|
||||||
DEBUG("simple_buffer_map(offset=%zu, count=%zu): "
|
DEBUG("simple_buffer_map(offset=%zu, count=%zu): "
|
||||||
"allocated=%zu, size=%zu, last_allocate=%zu\n",
|
"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;
|
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
|
// TODO Add simple buffer management so we can free more than last
|
||||||
// allocated one.
|
// allocated one.
|
||||||
DEBUG("simple_buffer_unmap(address=%p): "
|
DEBUG("simple_buffer_unmap(address=%p): "
|
||||||
|
@ -220,4 +240,4 @@ int run_address(void *f)
|
||||||
return v();
|
return v();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __SMM__ */
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue