2021-11-15 09:36:07 +01:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2011-07-21 15:43:14 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
#include <libpayload-config.h>
|
|
|
|
#include <arch/virtual.h>
|
|
|
|
#include <assert.h>
|
2011-07-21 15:43:14 +02:00
|
|
|
#include <cbfs.h>
|
2022-01-03 16:06:21 +01:00
|
|
|
#include <cbfs_glue.h>
|
2021-11-15 09:36:07 +01:00
|
|
|
#include <commonlib/bsd/cbfs_private.h>
|
|
|
|
#include <commonlib/bsd/fmap_serialized.h>
|
|
|
|
#include <libpayload.h>
|
|
|
|
#include <lz4.h>
|
|
|
|
#include <lzma.h>
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
#include <string.h>
|
2021-11-15 09:36:07 +01:00
|
|
|
#include <sysinfo.h>
|
2011-07-21 15:43:14 +02:00
|
|
|
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
static const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro)
|
2013-01-14 19:20:15 +01:00
|
|
|
{
|
2021-11-15 09:36:07 +01:00
|
|
|
static struct cbfs_boot_device ro;
|
|
|
|
static struct cbfs_boot_device rw;
|
|
|
|
|
|
|
|
if (!force_ro) {
|
|
|
|
if (!rw.dev.size) {
|
|
|
|
rw.dev.offset = lib_sysinfo.cbfs_offset;
|
|
|
|
rw.dev.size = lib_sysinfo.cbfs_size;
|
|
|
|
rw.mcache = phys_to_virt(lib_sysinfo.cbfs_rw_mcache_offset);
|
|
|
|
rw.mcache_size = lib_sysinfo.cbfs_rw_mcache_size;
|
|
|
|
}
|
|
|
|
return &rw;
|
|
|
|
}
|
2011-07-21 15:43:14 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
if (ro.dev.size)
|
|
|
|
return &ro;
|
2011-07-21 15:43:14 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
if (fmap_locate_area("COREBOOT", &ro.dev.offset, &ro.dev.size))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ro.mcache = phys_to_virt(lib_sysinfo.cbfs_ro_mcache_offset);
|
|
|
|
ro.mcache_size = lib_sysinfo.cbfs_ro_mcache_size;
|
2011-07-21 15:43:14 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
return &ro;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
ssize_t _cbfs_boot_lookup(const char *name, bool force_ro, union cbfs_mdata *mdata)
|
2011-07-21 15:43:14 +02:00
|
|
|
{
|
2021-11-15 09:36:07 +01:00
|
|
|
const struct cbfs_boot_device *cbd = cbfs_get_boot_device(force_ro);
|
|
|
|
if (!cbd)
|
|
|
|
return CB_ERR;
|
|
|
|
|
|
|
|
size_t data_offset;
|
2022-03-05 02:49:56 +01:00
|
|
|
enum cb_err err = CB_CBFS_CACHE_FULL;
|
2021-11-15 09:36:07 +01:00
|
|
|
if (cbd->mcache_size)
|
|
|
|
err = cbfs_mcache_lookup(cbd->mcache, cbd->mcache_size, name, mdata,
|
|
|
|
&data_offset);
|
|
|
|
|
|
|
|
if (err == CB_CBFS_CACHE_FULL)
|
|
|
|
err = cbfs_lookup(&cbd->dev, name, mdata, &data_offset, NULL);
|
|
|
|
|
|
|
|
/* Fallback to RO if possible. */
|
|
|
|
if (CONFIG(LP_ENABLE_CBFS_FALLBACK) && !force_ro && err == CB_CBFS_NOT_FOUND) {
|
|
|
|
LOG("Fall back to RO region for '%s'\n", name);
|
|
|
|
return _cbfs_boot_lookup(name, true, mdata);
|
2016-07-29 16:36:23 +02:00
|
|
|
}
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
if (err) {
|
|
|
|
if (err == CB_CBFS_NOT_FOUND)
|
|
|
|
LOG("'%s' not found.\n", name);
|
|
|
|
else
|
|
|
|
ERROR("Error %d when looking up '%s'\n", err, name);
|
|
|
|
return err;
|
|
|
|
}
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
return cbd->dev.offset + data_offset;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
void cbfs_unmap(void *mapping)
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
{
|
2021-11-15 09:36:07 +01:00
|
|
|
free(mapping);
|
|
|
|
}
|
2011-07-21 15:43:14 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
static bool cbfs_file_hash_mismatch(const void *buffer, size_t size,
|
2022-01-03 16:06:21 +01:00
|
|
|
const union cbfs_mdata *mdata, bool skip_verification)
|
2021-11-15 09:36:07 +01:00
|
|
|
{
|
2022-01-03 16:06:21 +01:00
|
|
|
if (!CONFIG(LP_CBFS_VERIFICATION) || skip_verification)
|
2021-11-15 09:36:07 +01:00
|
|
|
return false;
|
2012-01-17 15:52:05 +01:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
const struct vb2_hash *hash = cbfs_file_hash(mdata);
|
|
|
|
if (!hash) {
|
|
|
|
ERROR("'%s' does not have a file hash!\n", mdata->h.filename);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (vb2_hash_verify(buffer, size, hash) != VB2_SUCCESS) {
|
|
|
|
ERROR("'%s' file hash mismatch!\n", mdata->h.filename);
|
|
|
|
return true;
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
return false;
|
2012-01-17 15:52:05 +01:00
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
static size_t cbfs_load_and_decompress(size_t offset, size_t in_size, void *buffer,
|
|
|
|
size_t buffer_size, uint32_t compression,
|
2022-01-03 16:06:21 +01:00
|
|
|
const union cbfs_mdata *mdata, bool skip_verification)
|
2013-01-14 19:20:15 +01:00
|
|
|
{
|
2021-11-15 09:36:07 +01:00
|
|
|
void *load = buffer;
|
|
|
|
size_t out_size = 0;
|
|
|
|
|
|
|
|
DEBUG("Decompressing %zu bytes from '%s' to %p with algo %d\n", in_size,
|
|
|
|
mdata->h.filename, buffer, compression);
|
|
|
|
|
|
|
|
if (compression != CBFS_COMPRESS_NONE) {
|
|
|
|
load = malloc(in_size);
|
|
|
|
if (!load) {
|
|
|
|
ERROR("'%s' buffer allocation failed\n", mdata->h.filename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-01-17 15:52:05 +01:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
if (boot_device_read(load, offset, in_size) != in_size) {
|
|
|
|
ERROR("'%s' failed to read contents of file\n", mdata->h.filename);
|
|
|
|
goto out;
|
|
|
|
}
|
2016-05-12 23:40:57 +02:00
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
if (cbfs_file_hash_mismatch(buffer, in_size, mdata, skip_verification))
|
2021-11-15 09:36:07 +01:00
|
|
|
goto out;
|
2016-05-12 23:40:57 +02:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
switch (compression) {
|
|
|
|
case CBFS_COMPRESS_NONE:
|
|
|
|
out_size = in_size;
|
|
|
|
break;
|
|
|
|
case CBFS_COMPRESS_LZ4:
|
|
|
|
if (!CONFIG(LP_LZ4))
|
|
|
|
goto out;
|
|
|
|
out_size = ulz4fn(load, in_size, buffer, buffer_size);
|
|
|
|
break;
|
|
|
|
case CBFS_COMPRESS_LZMA:
|
|
|
|
if (!CONFIG(LP_LZMA))
|
|
|
|
goto out;
|
|
|
|
out_size = ulzman(load, in_size, buffer, buffer_size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR("'%s' decompression algo %d not supported\n", mdata->h.filename,
|
|
|
|
compression);
|
2016-05-12 23:40:57 +02:00
|
|
|
}
|
2021-11-15 09:36:07 +01:00
|
|
|
out:
|
|
|
|
if (load != buffer)
|
|
|
|
free(load);
|
|
|
|
return out_size;
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
static void *do_load(union cbfs_mdata *mdata, ssize_t offset, void *buf, size_t *size_inout,
|
|
|
|
bool skip_verification)
|
2021-11-15 09:36:07 +01:00
|
|
|
{
|
|
|
|
bool malloced = false;
|
2022-01-03 16:06:21 +01:00
|
|
|
size_t out_size;
|
2021-11-15 09:36:07 +01:00
|
|
|
uint32_t compression = CBFS_COMPRESS_NONE;
|
|
|
|
const struct cbfs_file_attr_compression *cattr =
|
2022-01-03 16:06:21 +01:00
|
|
|
cbfs_find_attr(mdata, CBFS_FILE_ATTR_TAG_COMPRESSION, sizeof(*cattr));
|
2021-11-15 09:36:07 +01:00
|
|
|
if (cattr) {
|
|
|
|
compression = be32toh(cattr->compression);
|
|
|
|
out_size = be32toh(cattr->decompressed_size);
|
|
|
|
} else {
|
2022-01-03 16:06:21 +01:00
|
|
|
out_size = be32toh(mdata->h.len);
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
if (buf) {
|
|
|
|
if (!size_inout || *size_inout < out_size) {
|
2022-02-17 15:03:25 +01:00
|
|
|
ERROR("'%s' buffer too small\n", mdata->h.filename);
|
2021-11-15 09:36:07 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buf = malloc(out_size);
|
|
|
|
if (!buf) {
|
2022-02-17 15:03:25 +01:00
|
|
|
ERROR("'%s' allocation failure\n", mdata->h.filename);
|
2021-11-15 09:36:07 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
malloced = true;
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
if (cbfs_load_and_decompress(offset, be32toh(mdata->h.len), buf, out_size, compression,
|
|
|
|
mdata, skip_verification)
|
2021-11-15 09:36:07 +01:00
|
|
|
!= out_size) {
|
|
|
|
if (malloced)
|
|
|
|
free(buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (size_inout)
|
|
|
|
*size_inout = out_size;
|
libpayload: New CBFS to support multiple firmware media sources.
Upgrade CBFS in libpayload to use new media-based implementation from coreboot
( http://review.coreboot.org/#/c/2182/ ).
Old CBFS functions (cbfs_find, cbfs_find_file, get_cbfs_header) are still
supported, although the recommended way is to use new CBFS API.
To migrate your existing x86 payload source:
- Change cbfs_find to cbfs_get_file
- Change cbfs_find_file to cbfs_get_file_content
- Prefix every CBFS call with a CBFS_DEFAULT_MEDIA argument.
Ex, char *jpeg_data = cbfs_find_file("splash.jpg", CBFS_TYPE_BOOTSPLASH);
=> char *jpeg_data = cbfs_get_file_content(
CBFS_DEFAULT_MEDIA, "splash.jpg", CBFS_TYPE_BOOTSPLASH);
The legacy setup_cbfs_from_{ram,flash} is also supported, although the better
equivalent is to make a new media instance:
struct cbfs_media ram_media;
init_cbfs_ram_media(&ram_media, start, size);
char *data = cbfs_get_file_content(&ram_media, "myfile", my_type);
Verified by being successfully linked with filo.
Change-Id: If797bc7e3ba975d7e3be905c59424f7a93b8ce11
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: http://review.coreboot.org/2191
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Anton Kochkov <anton.kochkov@gmail.com>
2013-01-25 05:42:40 +01:00
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
return buf;
|
2012-01-17 15:52:05 +01:00
|
|
|
}
|
2022-01-03 16:06:21 +01:00
|
|
|
|
|
|
|
void *_cbfs_load(const char *name, void *buf, size_t *size_inout, bool force_ro)
|
|
|
|
{
|
|
|
|
ssize_t offset;
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
|
|
|
|
DEBUG("%s(name='%s', buf=%p, force_ro=%s)\n", __func__, name, buf,
|
|
|
|
force_ro ? "true" : "false");
|
|
|
|
|
|
|
|
offset = _cbfs_boot_lookup(name, force_ro, &mdata);
|
|
|
|
if (offset < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return do_load(&mdata, offset, buf, size_inout, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *_cbfs_unverified_area_load(const char *area, const char *name, void *buf,
|
|
|
|
size_t *size_inout)
|
|
|
|
{
|
|
|
|
struct cbfs_dev dev;
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
size_t data_offset;
|
|
|
|
|
|
|
|
DEBUG("%s(area='%s', name='%s', buf=%p)\n", __func__, area, name, buf);
|
|
|
|
|
|
|
|
if (fmap_locate_area(area, &dev.offset, &dev.size) != CB_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (cbfs_lookup(&dev, name, &mdata, &data_offset, NULL)) {
|
|
|
|
ERROR("'%s' not found in '%s'\n", name, area);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return do_load(&mdata, dev.offset + data_offset, buf, size_inout, true);
|
|
|
|
}
|