diff options
author | Alexandru Gagniuc <mr.nuke.me@gmail.com> | 2015-09-07 00:05:44 -0700 |
---|---|---|
committer | Alexandru Gagniuc <mr.nuke.me@gmail.com> | 2015-09-07 08:44:06 +0000 |
commit | 38bc916def3a95f2a32309c5437ac0f868455a94 (patch) | |
tree | a8390ca4002222bf9ff771604cb0eab1346b9abf | |
parent | 3ed0d85d527e929d862b4846625261e4189a9dce (diff) |
cbfstool: Allow adding file with specific alignment requirement
Whenever we want to add a file to CBFS with a specific alignment, we
have to do two cbfstool invocations: one to find a place for the file,
and another to actually add the file to CBFS. Get rid of this nonsense
and allow this to be done in one step.
Change-Id: I526483296b494363f15dc169f163d93a6fc71bb0
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-on: http://review.coreboot.org/11525
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
-rw-r--r-- | util/cbfstool/cbfstool.c | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index a91b600e4d..d6c116af15 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -328,8 +328,65 @@ static int cbfstool_convert_mkflatpayload(struct buffer *buffer, return 0; } +static int do_cbfs_locate(int32_t *cbfs_addr) +{ + if (!param.filename) { + ERROR("You need to specify -f/--filename.\n"); + return 1; + } + + if (!param.name) { + ERROR("You need to specify -n/--name.\n"); + return 1; + } + + struct cbfs_image image; + if (cbfs_image_from_buffer(&image, param.image_region, + param.headeroffset)) + return 1; + + if (cbfs_get_entry(&image, param.name)) + WARN("'%s' already in CBFS.\n", param.name); + + struct buffer buffer; + if (buffer_from_file(&buffer, param.filename) != 0) { + ERROR("Cannot load %s.\n", param.filename); + return 1; + } + + int32_t address = cbfs_locate_entry(&image, param.name, buffer.size, + param.pagesize, param.alignment); + buffer_delete(&buffer); + + if (address == -1) { + ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n", + param.name, param.pagesize, param.alignment); + return 1; + } + + if (param.top_aligned) + address = -convert_to_from_top_aligned(param.image_region, + address); + + *cbfs_addr = address; + return 0; +} + static int cbfs_add(void) { + int32_t address; + + if (param.alignment && param.baseaddress) { + ERROR("Cannot specify both alignment and base address\n"); + return 1; + } + + if (param.alignment) { + if (do_cbfs_locate(&address)) + return 1; + param.baseaddress = address; + } + return cbfs_add_component(param.filename, param.name, param.type, @@ -494,43 +551,10 @@ static int cbfs_create(void) static int cbfs_locate(void) { - if (!param.filename) { - ERROR("You need to specify -f/--filename.\n"); - return 1; - } - - if (!param.name) { - ERROR("You need to specify -n/--name.\n"); - return 1; - } - - struct cbfs_image image; - if (cbfs_image_from_buffer(&image, param.image_region, - param.headeroffset)) - return 1; - - if (cbfs_get_entry(&image, param.name)) - WARN("'%s' already in CBFS.\n", param.name); + int32_t address; - struct buffer buffer; - if (buffer_from_file(&buffer, param.filename) != 0) { - ERROR("Cannot load %s.\n", param.filename); + if (do_cbfs_locate(&address) != 0) return 1; - } - - int32_t address = cbfs_locate_entry(&image, param.name, buffer.size, - param.pagesize, param.alignment); - buffer_delete(&buffer); - - if (address == -1) { - ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n", - param.name, param.pagesize, param.alignment); - return 1; - } - - if (param.top_aligned) - address = -convert_to_from_top_aligned(param.image_region, - address); printf("0x%x\n", address); return 0; @@ -781,7 +805,7 @@ static bool cbfs_is_legacy_format(struct buffer *buffer) } static const struct command commands[] = { - {"add", "H:r:f:n:t:c:b:vh?", cbfs_add, true, true}, + {"add", "H:r:f:n:t:c:b:a:vh?", cbfs_add, true, true}, {"add-flat-binary", "H:r:f:n:l:e:c:b:vh?", cbfs_add_flat_binary, true, true}, {"add-payload", "H:r:f:n:t:c:b:C:I:vh?", cbfs_add_payload, true, true}, @@ -896,7 +920,7 @@ static void usage(char *name) " -h Display this help message\n\n" "COMMANDs:\n" " add [-r image,regions] -f FILE -n NAME -t TYPE \\\n" - " [-c compression] [-b base-address] " + " [-c compression] [-b base-address | -a alignment] " "Add a component\n" " add-payload [-r image,regions] -f FILE -n NAME \\\n" " [-c compression] [-b base-address] " |