summaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2014-12-23 15:10:12 -0800
committerPatrick Georgi <pgeorgi@google.com>2015-04-18 08:48:05 +0200
commit458a12e52beb9dfcb1884dfad6effa8b3d98e8a4 (patch)
tree03ec1a47ffe8990aa2fd33cdbac31395294ce0b9 /util/cbfstool/cbfstool.c
parent14ecb5434b88b5620c4b4bb771a3c2b00c2efe6b (diff)
cbfstool: allow user to explicitly specify header location
There potentially could be multiple CBFS instances present in the firmware image. cbfstool should be able to operate on any of them, not just the first one present. To accomplish that, allow all CBFS commands to accept the -H parameter (which specifies the exact CBFS header location in the image). If this parameter is specified, the image is not searched for the CBFS header, only the specified location is checked for validity, If the location is valid, it is considered to be the CBFS header, if not - the tool exits with an error status. Note, that default behavior of the tool does not change. BRANCH=storm BUG=chrome-os-partner:34161, chromium:445938 TEST=run the following experiments: - examined an image with three CBFS instances, was able to print all of them. - built a rambi coreboot image and tried the following (cbfstool output abbreviated): $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000 alignment: 64 bytes, architecture: x86 Name Offset Type Size cmos_layout.bin 0x700000 cmos_layout 1164 ... (empty) 0x7ec600 null 77848 $ \od -tx4 -Ax /build/rambi/firmware/coreboot.rom | tail -2 7ffff0 fff67de9 000000ff fff6dfe9 fffff650 800000 $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff650 coreboot.rom: 8192 kB, bootblocksize 2448, romsize 8388608, offset 0x700000 alignment: 64 bytes, architecture: x86 Name Offset Type Size cmos_layout.bin 0x700000 cmos_layout 1164 ... (empty) 0x7ec600 null 77848 $ ./util/cbfstool/cbfstool /build/rambi/firmware/coreboot.rom print -H 0x7ff654 E: /build/rambi/firmware/coreboot.rom does not have CBFS master header. E: Could not load ROM image '/build/rambi/firmware/coreboot.rom'. $ Change-Id: I64cbdc79096f3c7a113762b641305542af7bbd60 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: 86b88222df6eed25bb176d653305e2e57e18b73a Original-Change-Id: I486092e222c96c65868ae7d41a9e8976ffcc93c4 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/237485 Original-Reviewed-by: David Hendricks <dhendrix@chromium.org> Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org> Original-Reviewed-by: Stefan Reinauer <reinauer@google.com> Reviewed-on: http://review.coreboot.org/9741 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 9c611197cf..20e5e0c78a 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -66,6 +66,7 @@ static struct param {
/* All variables not listed are initialized as zero. */
.arch = CBFS_ARCHITECTURE_UNKNOWN,
.algo = CBFS_COMPRESS_NONE,
+ .headeroffset = ~0,
};
typedef int (*convert_buffer_t)(struct buffer *buffer, uint32_t *offset);
@@ -73,7 +74,8 @@ typedef int (*convert_buffer_t)(struct buffer *buffer, uint32_t *offset);
static int cbfs_add_integer_component(const char *cbfs_name,
const char *name,
uint64_t u64val,
- uint32_t offset) {
+ uint32_t offset,
+ uint32_t headeroffset) {
struct cbfs_image image;
struct buffer buffer;
int i, ret = 1;
@@ -89,7 +91,7 @@ static int cbfs_add_integer_component(const char *cbfs_name,
for (i = 0; i < 8; i++)
buffer.data[i] = (u64val >> i*8) & 0xff;
- if (cbfs_image_from_file(&image, cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, cbfs_name, headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n", cbfs_name);
buffer_delete(&buffer);
return 1;
@@ -119,6 +121,7 @@ static int cbfs_add_component(const char *cbfs_name,
const char *name,
uint32_t type,
uint32_t offset,
+ uint32_t headeroffset,
convert_buffer_t convert)
{
struct cbfs_image image;
@@ -139,7 +142,7 @@ static int cbfs_add_component(const char *cbfs_name,
return 1;
}
- if (cbfs_image_from_file(&image, cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, cbfs_name, headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n", cbfs_name);
return 1;
}
@@ -249,6 +252,7 @@ static int cbfs_add(void)
param.name,
param.type,
param.baseaddress,
+ param.headeroffset,
NULL);
}
@@ -259,6 +263,7 @@ static int cbfs_add_stage(void)
param.name,
CBFS_COMPONENT_STAGE,
param.baseaddress,
+ param.headeroffset,
cbfstool_convert_mkstage);
}
@@ -269,6 +274,7 @@ static int cbfs_add_payload(void)
param.name,
CBFS_COMPONENT_PAYLOAD,
param.baseaddress,
+ param.headeroffset,
cbfstool_convert_mkpayload);
}
@@ -289,6 +295,7 @@ static int cbfs_add_flat_binary(void)
param.name,
CBFS_COMPONENT_PAYLOAD,
param.baseaddress,
+ param.headeroffset,
cbfstool_convert_mkflatpayload);
}
@@ -297,7 +304,8 @@ static int cbfs_add_integer(void)
return cbfs_add_integer_component(param.cbfs_name,
param.name,
param.u64val,
- param.baseaddress);
+ param.baseaddress,
+ param.headeroffset);
}
static int cbfs_remove(void)
@@ -309,7 +317,8 @@ static int cbfs_remove(void)
return 1;
}
- if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, param.cbfs_name,
+ param.headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
@@ -433,7 +442,8 @@ static int cbfs_locate(void)
return 1;
}
- if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, param.cbfs_name,
+ param.headeroffset) != 0) {
ERROR("Failed to load %s.\n", param.cbfs_name);
return 1;
}
@@ -469,7 +479,8 @@ static int cbfs_locate(void)
static int cbfs_print(void)
{
struct cbfs_image image;
- if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, param.cbfs_name,
+ param.headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
@@ -494,7 +505,8 @@ static int cbfs_extract(void)
return 1;
}
- if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, param.cbfs_name,
+ param.headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
result = 1;
@@ -523,7 +535,8 @@ static int cbfs_update_fit(void)
return 1;
}
- if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
+ if (cbfs_image_from_file(&image, param.cbfs_name,
+ param.headeroffset) != 0) {
ERROR("Could not load ROM image '%s'.\n",
param.cbfs_name);
return 1;
@@ -538,17 +551,17 @@ static int cbfs_update_fit(void)
}
static const struct command commands[] = {
- {"add", "f:n:t:b:vh?", cbfs_add},
- {"add-payload", "f:n:t:c:b:vh?C:I:", cbfs_add_payload},
- {"add-stage", "f:n:t:c:b:S:vh?", cbfs_add_stage},
- {"add-flat-binary", "f:n:l:e:c:b:vh?", cbfs_add_flat_binary},
- {"add-int", "i:n:b:vh?", cbfs_add_integer},
- {"remove", "n:vh?", cbfs_remove},
+ {"add", "H;f:n:t:b:vh?", cbfs_add},
+ {"add-payload", "H:f:n:t:c:b:vh?C:I:", cbfs_add_payload},
+ {"add-stage", "H:f:n:t:c:b:S:vh?", cbfs_add_stage},
+ {"add-flat-binary", "H:f:n:l:e:c:b:vh?", cbfs_add_flat_binary},
+ {"add-int", "H:i:n:b:vh?", cbfs_add_integer},
+ {"remove", "H:n:vh?", cbfs_remove},
{"create", "s:B:b:H:a:o:m:vh?", cbfs_create},
- {"locate", "f:n:P:a:Tvh?", cbfs_locate},
- {"print", "vh?", cbfs_print},
- {"extract", "n:f:vh?", cbfs_extract},
- {"update-fit", "n:x:vh?", cbfs_update_fit},
+ {"locate", "H:f:n:P:a:Tvh?", cbfs_locate},
+ {"print", "H:vh?", cbfs_print},
+ {"extract", "H:n:f:vh?", cbfs_extract},
+ {"update-fit", "H:n:x:vh?", cbfs_update_fit},
};
static struct option long_options[] = {
@@ -583,9 +596,10 @@ static void usage(char *name)
("cbfstool: Management utility for CBFS formatted ROM images\n\n"
"USAGE:\n" " %s [-h]\n"
" %s FILE COMMAND [-v] [PARAMETERS]...\n\n" "OPTIONs:\n"
- " -T Output top-aligned memory address\n"
- " -v Provide verbose output\n"
- " -h Display this help message\n\n"
+ " -H header_offset Do not search for header, use this offset\n"
+ " -T Output top-aligned memory address\n"
+ " -v Provide verbose output\n"
+ " -h Display this help message\n\n"
"COMMANDs:\n"
" add -f FILE -n NAME -t TYPE [-b base-address] "
"Add a component\n"