2011-07-21 15:43:14 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the libpayload project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 secunet Security Networks AG
|
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
|
|
|
* Copyright (C) 2013 Google, Inc.
|
2011-07-21 15:43:14 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
/* The CBFS core requires a couple of #defines or functions to adapt it to the
|
|
|
|
* target environment:
|
2011-07-21 15:43:14 +02:00
|
|
|
*
|
|
|
|
* CBFS_CORE_WITH_LZMA (must be #define)
|
|
|
|
* if defined, ulzma() must exist for decompression of data streams
|
|
|
|
*
|
2015-09-29 22:51:35 +02:00
|
|
|
* CBFS_CORE_WITH_LZ4 (must be #define)
|
|
|
|
* if defined, ulz4f() must exist for decompression of data streams
|
|
|
|
*
|
2011-07-21 15:43:14 +02:00
|
|
|
* ERROR(x...)
|
|
|
|
* print an error message x (in printf format)
|
|
|
|
*
|
|
|
|
* LOG(x...)
|
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
|
|
|
* print a message x (in printf format)
|
2011-07-21 15:43:14 +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
|
|
|
* DEBUG(x...)
|
|
|
|
* print a debug message x (in printf format)
|
2011-07-21 15:43:14 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-02-27 08:29:15 +01:00
|
|
|
#include <libpayload.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 <cbfs.h>
|
|
|
|
#include <string.h>
|
2015-09-02 19:53:13 +02:00
|
|
|
#include <sysinfo.h>
|
2011-07-21 15:43:14 +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
|
|
|
/* returns a pointer to CBFS master header, or CBFS_HEADER_INVALID_ADDRESS
|
|
|
|
* on failure */
|
|
|
|
const struct cbfs_header *cbfs_get_header(struct cbfs_media *media)
|
2011-07-21 15:43:14 +02:00
|
|
|
{
|
2014-11-10 22:14:24 +01:00
|
|
|
int32_t rel_offset;
|
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
|
|
|
const struct cbfs_header *header;
|
|
|
|
struct cbfs_media default_media;
|
|
|
|
|
|
|
|
if (media == CBFS_DEFAULT_MEDIA) {
|
|
|
|
media = &default_media;
|
|
|
|
if (init_default_cbfs_media(media) != 0) {
|
2013-02-19 17:59:21 +01:00
|
|
|
ERROR("Failed to initialize default media.\n");
|
|
|
|
return CBFS_HEADER_INVALID_ADDRESS;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
media->open(media);
|
2014-11-10 22:14:24 +01:00
|
|
|
|
|
|
|
if (!media->read(media, &rel_offset, (size_t)(0 - sizeof(int32_t)),
|
|
|
|
sizeof(int32_t))) {
|
|
|
|
ERROR("Could not read CBFS master header offset!\n");
|
|
|
|
return CBFS_HEADER_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
header = media->map(media, (size_t)rel_offset, sizeof(*header));
|
|
|
|
DEBUG("CBFS header at %#zx (-%#zx from end of image).\n",
|
|
|
|
(size_t)rel_offset, (size_t)-rel_offset);
|
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
|
|
|
media->close(media);
|
|
|
|
|
|
|
|
if (header == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
|
2014-11-10 22:14:24 +01:00
|
|
|
ERROR("Failed to load CBFS header from %#zx(-%#zx)\n",
|
|
|
|
(size_t)rel_offset, (size_t)-rel_offset);
|
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
|
|
|
return CBFS_HEADER_INVALID_ADDRESS;
|
2011-07-21 15:43:14 +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
|
|
|
|
2011-07-21 15:43:14 +02:00
|
|
|
if (CBFS_HEADER_MAGIC != ntohl(header->magic)) {
|
2014-11-10 22:14:24 +01:00
|
|
|
ERROR("Could not find valid CBFS master header at %#zx(-%#zx): "
|
|
|
|
"magic %#.8x vs %#.8x.\n", (size_t)rel_offset,
|
|
|
|
(size_t)-rel_offset, CBFS_HEADER_MAGIC,
|
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
|
|
|
ntohl(header->magic));
|
2011-07-21 15:43:14 +02:00
|
|
|
if (header->magic == 0xffffffff) {
|
|
|
|
ERROR("Maybe ROM is not mapped properly?\n");
|
|
|
|
}
|
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
|
|
|
return CBFS_HEADER_INVALID_ADDRESS;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2015-09-02 19:53:13 +02:00
|
|
|
static int get_cbfs_range(uint32_t *offset, uint32_t *cbfs_end,
|
|
|
|
struct cbfs_media *media)
|
2011-07-21 15:43:14 +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
|
|
|
const struct cbfs_header *header;
|
|
|
|
|
2015-10-23 20:25:03 +02:00
|
|
|
if (media == CBFS_DEFAULT_MEDIA &&
|
|
|
|
lib_sysinfo.cbfs_offset && lib_sysinfo.cbfs_size) {
|
2015-09-02 19:53:13 +02:00
|
|
|
*offset = lib_sysinfo.cbfs_offset;
|
|
|
|
*cbfs_end = *offset + lib_sysinfo.cbfs_size;
|
|
|
|
return 0;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2015-11-19 18:10:41 +01:00
|
|
|
/* read offset and size from cbfs master header */
|
|
|
|
DEBUG("Read CBFS offset & size from master header\n");
|
2015-09-02 19:53:13 +02:00
|
|
|
header = cbfs_get_header(media);
|
|
|
|
if (header == CBFS_HEADER_INVALID_ADDRESS)
|
|
|
|
return -1;
|
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
|
|
|
// Logical offset (for source media) of first file.
|
2015-09-02 19:53:13 +02:00
|
|
|
*offset = ntohl(header->offset);
|
|
|
|
*cbfs_end = ntohl(header->romsize);
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_ARCH_X86)
|
2013-08-14 22:55:57 +02:00
|
|
|
// resolve actual length of ROM used for CBFS components
|
|
|
|
// the bootblock size was not taken into account
|
2015-09-02 19:53:13 +02:00
|
|
|
*cbfs_end -= ntohl(header->bootblocksize);
|
2013-08-14 22:55:57 +02:00
|
|
|
|
|
|
|
// fine tune the length to handle alignment positioning.
|
|
|
|
// using (bootblock size) % align, to derive the
|
|
|
|
// number of bytes the bootblock is off from the alignment size.
|
2015-07-14 22:29:04 +02:00
|
|
|
if ((ntohl(header->bootblocksize) % CBFS_ALIGNMENT))
|
2015-09-02 19:53:13 +02:00
|
|
|
*cbfs_end -= (CBFS_ALIGNMENT -
|
2015-07-14 22:29:04 +02:00
|
|
|
(ntohl(header->bootblocksize) % CBFS_ALIGNMENT));
|
2013-08-14 22:55:57 +02:00
|
|
|
else
|
2015-09-02 19:53:13 +02:00
|
|
|
*cbfs_end -= 1;
|
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
|
|
|
#endif
|
2015-09-02 19:53:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public API starts here*/
|
2016-05-12 23:40:57 +02:00
|
|
|
struct cbfs_handle *cbfs_get_handle(struct cbfs_media *media, const char *name)
|
2015-09-02 19:53:13 +02:00
|
|
|
{
|
|
|
|
const char *vardata;
|
|
|
|
uint32_t offset, cbfs_end, vardata_len;
|
2016-05-12 23:40:57 +02:00
|
|
|
struct cbfs_file file;
|
|
|
|
struct cbfs_handle *handle = malloc(sizeof(*handle));
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
2015-09-02 19:53:13 +02:00
|
|
|
|
2015-11-19 18:10:41 +01:00
|
|
|
if (get_cbfs_range(&offset, &cbfs_end, media)) {
|
|
|
|
ERROR("Failed to find cbfs range\n");
|
2016-08-12 21:50:42 +02:00
|
|
|
free(handle);
|
2015-11-19 18:10:41 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-02 19:53:13 +02:00
|
|
|
if (media == CBFS_DEFAULT_MEDIA) {
|
2016-05-12 23:40:57 +02:00
|
|
|
media = &handle->media;
|
2015-09-02 19:53:13 +02:00
|
|
|
if (init_default_cbfs_media(media) != 0) {
|
|
|
|
ERROR("Failed to initialize default media.\n");
|
2016-08-12 21:50:42 +02:00
|
|
|
free(handle);
|
2015-09-02 19:53:13 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-05-12 23:40:57 +02:00
|
|
|
} else {
|
|
|
|
memcpy(&handle->media, media, sizeof(*media));
|
2015-09-02 19:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("CBFS location: 0x%x~0x%x\n", offset, cbfs_end);
|
2013-05-06 23:51:39 +02:00
|
|
|
DEBUG("Looking for '%s' starting from 0x%x.\n", name, offset);
|
2013-08-14 22:55:57 +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
|
|
|
media->open(media);
|
2015-09-02 19:53:13 +02:00
|
|
|
while (offset < cbfs_end &&
|
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
|
|
|
media->read(media, &file, offset, sizeof(file)) == sizeof(file)) {
|
|
|
|
if (memcmp(CBFS_FILE_MAGIC, file.magic,
|
|
|
|
sizeof(file.magic)) != 0) {
|
2015-07-14 22:29:04 +02:00
|
|
|
uint32_t new_align = CBFS_ALIGNMENT;
|
|
|
|
if (offset % CBFS_ALIGNMENT)
|
|
|
|
new_align += CBFS_ALIGNMENT -
|
|
|
|
(offset % CBFS_ALIGNMENT);
|
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
|
|
|
ERROR("ERROR: No file header found at 0x%xx - "
|
|
|
|
"try next aligned address: 0x%x.\n", offset,
|
|
|
|
offset + new_align);
|
|
|
|
offset += new_align;
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-10 00:07:45 +02:00
|
|
|
vardata_len = ntohl(file.offset) - sizeof(file);
|
|
|
|
DEBUG(" - load entry 0x%x variable data (%d bytes)...\n",
|
|
|
|
offset, vardata_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
|
|
|
|
|
|
|
// load file name (arbitrary length).
|
2015-07-10 00:07:45 +02:00
|
|
|
vardata = (const char*)media->map(
|
|
|
|
media, offset + sizeof(file), vardata_len);
|
|
|
|
if (vardata == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
|
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
|
|
|
ERROR("ERROR: Failed to get filename: 0x%x.\n", offset);
|
2015-07-10 00:07:45 +02:00
|
|
|
} else if (strcmp(vardata, name) == 0) {
|
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
|
|
|
int file_offset = ntohl(file.offset),
|
|
|
|
file_len = ntohl(file.len);
|
2013-05-06 23:51:39 +02:00
|
|
|
DEBUG("Found file (offset=0x%x, len=%d).\n",
|
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
|
|
|
offset + file_offset, file_len);
|
2015-07-10 00:07:45 +02:00
|
|
|
media->unmap(media, vardata);
|
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
|
|
|
media->close(media);
|
2016-05-12 23:40:57 +02:00
|
|
|
handle->type = ntohl(file.type);
|
|
|
|
handle->media_offset = offset;
|
|
|
|
handle->content_offset = file_offset;
|
|
|
|
handle->content_size = file_len;
|
|
|
|
handle->attribute_offset =
|
|
|
|
ntohl(file.attributes_offset);
|
|
|
|
return handle;
|
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
|
|
|
} else {
|
2013-05-01 15:40:13 +02:00
|
|
|
DEBUG(" (unmatched file @0x%x: %s)\n", offset,
|
2015-07-10 00:07:45 +02:00
|
|
|
vardata);
|
|
|
|
media->unmap(media, vardata);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Move to next file.
|
2020-03-01 05:03:54 +01:00
|
|
|
uint32_t next_offset = offset + ntohl(file.len) + ntohl(file.offset);
|
|
|
|
if (next_offset % CBFS_ALIGNMENT)
|
|
|
|
next_offset += CBFS_ALIGNMENT - (next_offset % CBFS_ALIGNMENT);
|
|
|
|
// Check that offset is strictly monotonic to prevent infinite loop
|
|
|
|
if (next_offset <= offset) {
|
|
|
|
ERROR("ERROR: corrupted CBFS file header at 0x%x.\n", offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset = next_offset;
|
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
|
|
|
}
|
|
|
|
media->close(media);
|
2013-05-06 23:51:39 +02:00
|
|
|
LOG("WARNING: '%s' not found.\n", name);
|
2016-08-12 21:50:42 +02:00
|
|
|
free(handle);
|
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
|
|
|
return NULL;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
void *cbfs_get_contents(struct cbfs_handle *handle, size_t *size, size_t limit)
|
2011-07-21 15:43:14 +02:00
|
|
|
{
|
2016-05-12 23:40:57 +02:00
|
|
|
struct cbfs_media *m = &handle->media;
|
|
|
|
size_t on_media_size = handle->content_size;
|
|
|
|
int algo = CBFS_COMPRESS_NONE;
|
|
|
|
void *ret = NULL;
|
|
|
|
size_t dummy_size;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
size = &dummy_size;
|
|
|
|
|
|
|
|
struct cbfs_file_attr_compression *comp =
|
|
|
|
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| */
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
if (algo == CBFS_COMPRESS_NONE) {
|
2019-02-26 14:41:52 +01:00
|
|
|
if (limit != 0 && limit < on_media_size)
|
2016-05-12 23:40:57 +02:00
|
|
|
on_media_size = limit;
|
2019-02-26 14:41:52 +01:00
|
|
|
*size = on_media_size;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
void *data = m->map(m, handle->media_offset + handle->content_offset,
|
|
|
|
on_media_size);
|
|
|
|
if (data == CBFS_MEDIA_INVALID_MAP_ADDRESS)
|
|
|
|
return NULL;
|
2015-07-10 00:07:45 +02:00
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
ret = malloc(*size);
|
2019-02-26 14:41:52 +01:00
|
|
|
if (ret != NULL) {
|
|
|
|
size_t final_size = cbfs_decompress(algo, data, on_media_size,
|
|
|
|
ret, *size);
|
|
|
|
if (final_size != *size) {
|
|
|
|
ERROR("Expect %zu bytes but got %zu bytes after "
|
|
|
|
"decompression.\n", *size, final_size);
|
|
|
|
free(ret);
|
|
|
|
ret = NULL;
|
|
|
|
}
|
2015-07-10 00:07:45 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
m->unmap(m, data);
|
|
|
|
return ret;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
void *cbfs_get_file_content(struct cbfs_media *media, const char *name,
|
|
|
|
int type, size_t *sz)
|
2015-09-16 18:53:40 +02:00
|
|
|
{
|
2016-05-12 23:40:57 +02:00
|
|
|
void *ret = NULL;
|
|
|
|
struct cbfs_handle *handle = cbfs_get_handle(media, name);
|
2015-09-16 18:53:40 +02:00
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
if (!handle)
|
2015-09-16 18:53:40 +02:00
|
|
|
return NULL;
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
if (handle->type == type)
|
|
|
|
ret = cbfs_get_contents(handle, sz, 0);
|
|
|
|
else
|
|
|
|
ERROR("File '%s' is of type %x, but we requested %x.\n", name,
|
|
|
|
handle->type, type);
|
|
|
|
|
|
|
|
free(handle);
|
|
|
|
return ret;
|
2015-09-16 18:53:40 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
void *cbfs_get_attr(struct cbfs_handle *handle, uint32_t tag)
|
2015-09-16 18:53:40 +02:00
|
|
|
{
|
2016-05-12 23:40:57 +02:00
|
|
|
struct cbfs_media *m = &handle->media;
|
|
|
|
uint32_t offset = handle->media_offset + handle->attribute_offset;
|
|
|
|
uint32_t end = handle->media_offset + handle->content_offset;
|
|
|
|
struct cbfs_file_attribute attr;
|
|
|
|
void *ret;
|
2015-09-16 18:53:40 +02:00
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
/* attribute_offset should be 0 when there is no attribute, but all
|
|
|
|
* values that point into the cbfs_file header are invalid, too. */
|
|
|
|
if (handle->attribute_offset <= sizeof(struct cbfs_file))
|
2015-09-16 18:53:40 +02:00
|
|
|
return NULL;
|
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
m->open(m);
|
|
|
|
while (offset + sizeof(attr) <= end) {
|
|
|
|
if (m->read(m, &attr, offset, sizeof(attr)) != sizeof(attr)) {
|
|
|
|
ERROR("Failed to read attribute header %#x\n", offset);
|
|
|
|
m->close(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ntohl(attr.tag) != tag) {
|
2020-03-01 05:03:54 +01:00
|
|
|
uint32_t next_offset = offset + ntohl(attr.len);
|
|
|
|
// Check that offset is strictly monotonic to prevent infinite loop
|
|
|
|
if (next_offset <= offset) {
|
|
|
|
ERROR("ERROR: corrupted CBFS attribute at 0x%x.\n", offset);
|
|
|
|
m->close(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
offset = next_offset;
|
2016-05-12 23:40:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret = m->map(m, offset, ntohl(attr.len));
|
|
|
|
if (ret == CBFS_MEDIA_INVALID_MAP_ADDRESS) {
|
|
|
|
ERROR("Failed to map attribute at %#x\n", offset);
|
|
|
|
m->close(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
2015-09-17 20:45:52 +02:00
|
|
|
}
|
2016-05-12 23:40:57 +02:00
|
|
|
m->close(m);
|
2015-09-17 20:45:52 +02:00
|
|
|
|
2016-05-12 23:40:57 +02:00
|
|
|
return NULL;
|
2015-09-17 20:45:52 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:29:15 +01:00
|
|
|
size_t cbfs_decompress(int algo, const void *src, size_t srcn, void *dst,
|
|
|
|
size_t dstn)
|
2011-07-21 15:43:14 +02:00
|
|
|
{
|
2019-02-27 08:29:15 +01:00
|
|
|
size_t len;
|
2011-07-21 15:43:14 +02:00
|
|
|
switch (algo) {
|
|
|
|
case CBFS_COMPRESS_NONE:
|
2019-02-27 08:29:15 +01:00
|
|
|
len = MIN(srcn, dstn);
|
2011-07-21 15:43:14 +02:00
|
|
|
memcpy(dst, src, len);
|
2013-07-01 13:57:37 +02:00
|
|
|
return len;
|
2011-07-21 15:43:14 +02:00
|
|
|
#ifdef CBFS_CORE_WITH_LZMA
|
|
|
|
case CBFS_COMPRESS_LZMA:
|
2019-02-27 08:29:15 +01:00
|
|
|
return ulzman(src, srcn, dst, dstn);
|
2015-09-29 22:51:35 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CBFS_CORE_WITH_LZ4
|
|
|
|
case CBFS_COMPRESS_LZ4:
|
2019-02-27 08:29:15 +01:00
|
|
|
return ulz4fn(src, srcn, dst, dstn);
|
2011-07-21 15:43:14 +02:00
|
|
|
#endif
|
|
|
|
default:
|
2019-02-27 08:29:15 +01:00
|
|
|
ERROR("tried to decompress %zu bytes with algorithm "
|
|
|
|
"#%x, but that algorithm id is unsupported.\n",
|
|
|
|
srcn, algo);
|
2013-07-01 13:57:37 +02:00
|
|
|
return 0;
|
2011-07-21 15:43:14 +02:00
|
|
|
}
|
|
|
|
}
|