summaryrefslogtreecommitdiff
path: root/util/cbfstool/cbfstool.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2015-09-15 12:50:14 -0500
committerAaron Durbin <adurbin@chromium.org>2015-09-16 14:11:03 +0000
commitd7339411a983e562cddeba676384ad836bb56ec9 (patch)
tree74efa7d6ab2375ce4a8831b071f69a6a014295e9 /util/cbfstool/cbfstool.c
parentb39a974d75ac597b29eb83b5ce347a506e0e6015 (diff)
downloadcoreboot-d7339411a983e562cddeba676384ad836bb56ec9.tar.xz
cbfstool: provide metadata size to cbfs_locate_entry()
The cbfs_locate_entry() function had a hack in there which assumed a struct cbfs_stage data was being added in addition to the struct cbfs_file and name. Move that logic out to the callers while still maintaining the logic for consistency. The only impacted commands cbfs_add and cbfs_locate, but those are using the default 'always adding struct cbfs_stage' in addition to cbfs_file + name. Eventually those should be removed when cbfs_locate is removed as cbfs_add has no smarts related to the cbfs file type provided. BUG=chrome-os-partner:44827 BRANCH=None TEST=Built rambi. Change-Id: I2771116ea1ff439ea53b8886e1f33e0e637a79d4 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/11668 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'util/cbfstool/cbfstool.c')
-rw-r--r--util/cbfstool/cbfstool.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index d6c116af15..182fc8ebe5 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -328,7 +328,7 @@ static int cbfstool_convert_mkflatpayload(struct buffer *buffer,
return 0;
}
-static int do_cbfs_locate(int32_t *cbfs_addr)
+static int do_cbfs_locate(int32_t *cbfs_addr, size_t metadata_size)
{
if (!param.filename) {
ERROR("You need to specify -f/--filename.\n");
@@ -354,8 +354,11 @@ static int do_cbfs_locate(int32_t *cbfs_addr)
return 1;
}
- int32_t address = cbfs_locate_entry(&image, param.name, buffer.size,
- param.pagesize, param.alignment);
+ /* Include cbfs_file size along with space for with name. */
+ metadata_size += cbfs_calculate_file_header_size(param.name);
+
+ int32_t address = cbfs_locate_entry(&image, buffer.size, param.pagesize,
+ param.alignment, metadata_size);
buffer_delete(&buffer);
if (address == -1) {
@@ -372,6 +375,16 @@ static int do_cbfs_locate(int32_t *cbfs_addr)
return 0;
}
+static size_t cbfs_default_metadata_size(void)
+{
+ /* TODO Old cbfstool always assume input is a stage file (and adding
+ * sizeof(cbfs_stage) for header. We should fix that by adding "-t"
+ * (type) param in future. For right now, we assume cbfs_stage is the
+ * largest structure and add it into header size. */
+ assert(sizeof(struct cbfs_stage) >= sizeof(struct cbfs_payload));
+ return sizeof(struct cbfs_stage);
+}
+
static int cbfs_add(void)
{
int32_t address;
@@ -382,7 +395,7 @@ static int cbfs_add(void)
}
if (param.alignment) {
- if (do_cbfs_locate(&address))
+ if (do_cbfs_locate(&address, cbfs_default_metadata_size()))
return 1;
param.baseaddress = address;
}
@@ -553,7 +566,7 @@ static int cbfs_locate(void)
{
int32_t address;
- if (do_cbfs_locate(&address) != 0)
+ if (do_cbfs_locate(&address, cbfs_default_metadata_size()) != 0)
return 1;
printf("0x%x\n", address);