2021-11-15 09:36:07 +01:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
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
|
|
|
|
|
|
|
#ifndef _CBFS_H_
|
|
|
|
#define _CBFS_H_
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
#include <commonlib/bsd/cb_err.h>
|
|
|
|
#include <commonlib/bsd/cbfs_mdata.h>
|
|
|
|
#include <endian.h>
|
|
|
|
#include <stdbool.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
|
|
|
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
/**********************************************************************************************
|
|
|
|
* CBFS FILE ACCESS APIs *
|
|
|
|
**********************************************************************************************/
|
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
|
|
|
/* For documentation look in src/include/cbfs.h file in the main coreboot source tree. */
|
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
|
|
|
static inline size_t cbfs_load(const char *name, void *buf, size_t size);
|
|
|
|
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size);
|
2022-01-03 16:06:21 +01:00
|
|
|
static inline size_t cbfs_unverified_area_load(const char *area, const char *name, void *buf,
|
|
|
|
size_t 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
|
|
|
static inline void *cbfs_map(const char *name, size_t *size_out);
|
|
|
|
static inline void *cbfs_ro_map(const char *name, size_t *size_out);
|
2022-01-03 16:06:21 +01:00
|
|
|
static inline void *cbfs_unverified_area_map(const char *area, const char *name,
|
|
|
|
size_t *size_out);
|
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
|
|
|
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
|
|
|
static inline size_t cbfs_get_size(const char *name);
|
|
|
|
static inline size_t cbfs_ro_get_size(const char *name);
|
|
|
|
|
|
|
|
static inline enum cbfs_type cbfs_get_type(const char *name);
|
|
|
|
static inline enum cbfs_type cbfs_ro_get_type(const char *name);
|
|
|
|
|
|
|
|
static inline bool cbfs_file_exists(const char *name);
|
|
|
|
static inline bool cbfs_ro_file_exists(const char *name);
|
|
|
|
|
|
|
|
/**********************************************************************************************
|
|
|
|
* INTERNAL HELPERS FOR INLINES, DO NOT USE. *
|
|
|
|
**********************************************************************************************/
|
|
|
|
ssize_t _cbfs_boot_lookup(const char *name, bool force_ro, union cbfs_mdata *mdata);
|
|
|
|
|
|
|
|
void *_cbfs_load(const char *name, void *buf, size_t *size_inout, bool force_ro);
|
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
void *_cbfs_unverified_area_load(const char *area, const char *name, void *buf,
|
|
|
|
size_t *size_inout);
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
/**********************************************************************************************
|
|
|
|
* INLINE IMPLEMENTATIONS *
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
static inline void *cbfs_map(const char *name, size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_load(name, NULL, size_out, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *cbfs_ro_map(const char *name, size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_load(name, NULL, size_out, true);
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
static inline void *cbfs_unverified_area_map(const char *area, const char *name,
|
|
|
|
size_t *size_out)
|
|
|
|
{
|
|
|
|
return _cbfs_unverified_area_load(area, name, NULL, size_out);
|
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
static inline size_t cbfs_load(const char *name, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
if (_cbfs_load(name, buf, &size, false))
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_ro_load(const char *name, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
if (_cbfs_load(name, buf, &size, true))
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:06:21 +01:00
|
|
|
static inline size_t cbfs_unverified_area_load(const char *area, const char *name, void *buf,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
if (_cbfs_unverified_area_load(area, name, buf, &size))
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-15 09:36:07 +01:00
|
|
|
static inline size_t cbfs_get_size(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
if (_cbfs_boot_lookup(name, false, &mdata) < 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return be32toh(mdata.h.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t cbfs_ro_get_size(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
if (_cbfs_boot_lookup(name, true, &mdata) < 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return be32toh(mdata.h.len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum cbfs_type cbfs_get_type(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
if (_cbfs_boot_lookup(name, false, &mdata) < 0)
|
|
|
|
return CBFS_TYPE_NULL;
|
|
|
|
else
|
|
|
|
return be32toh(mdata.h.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum cbfs_type cbfs_ro_get_type(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
if (_cbfs_boot_lookup(name, true, &mdata) < 0)
|
|
|
|
return CBFS_TYPE_NULL;
|
|
|
|
else
|
|
|
|
return be32toh(mdata.h.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cbfs_file_exists(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
return _cbfs_boot_lookup(name, false, &mdata) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cbfs_ro_file_exists(const char *name)
|
|
|
|
{
|
|
|
|
union cbfs_mdata mdata;
|
|
|
|
return _cbfs_boot_lookup(name, true, &mdata) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Legacy API. Designated for removal in the future. */
|
|
|
|
#include <cbfs_legacy.h>
|
2012-12-14 22:05:21 +01:00
|
|
|
|
|
|
|
#endif
|