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>
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user