From 215d1d7c9b8fdd94582bdec711e98111d1db5bb7 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Tue, 29 Jan 2013 03:46:02 +0800 Subject: cbfstool: Use cbfs_image API for "locate" command. To support platforms without top-aligned address mapping like ARM, "locate" command now outputs platform independent ROM offset by default. To retrieve x86 style top-aligned virtual address, add "-T". To test: cbfstool coreboot.rom locate -f stage -n stage -a 0x100000 -T # Example output: 0xffffdc10 Change-Id: I474703c4197b36524b75407a91faab1194edc64d Signed-off-by: Hung-Te Lin Reviewed-on: http://review.coreboot.org/2213 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- util/cbfstool/cbfstool.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'util/cbfstool/cbfstool.c') diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index e653a33bd5..98f6b62ee7 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -48,6 +48,7 @@ static struct param { uint32_t size; uint32_t alignment; uint32_t offset; + uint32_t top_aligned; comp_algo algo; } param = { /* All variables not listed are initialized as zero. */ @@ -363,7 +364,9 @@ static int cbfs_create(void) static int cbfs_locate(void) { - uint32_t filesize, location; + struct cbfs_image image; + struct buffer buffer; + int32_t address; if (!param.filename) { ERROR("You need to specify -f/--filename.\n"); @@ -375,13 +378,37 @@ static int cbfs_locate(void) return 1; } - filesize = getfilesize(param.filename); + if (cbfs_image_from_file(&image, param.cbfs_name) != 0) { + ERROR("Failed to load %s.\n", param.cbfs_name); + return 1; + } + + if (cbfs_get_entry(&image, param.name)) + WARN("'%s' already in CBFS.\n", param.name); + + if (buffer_from_file(&buffer, param.filename) != 0) { + ERROR("Cannot load %s.\n", param.filename); + cbfs_image_delete(&image); + return 1; + } - location = cbfs_find_location(param.cbfs_name, filesize, - param.name, param.alignment); + address = cbfs_locate_entry(&image, param.name, buffer.size, + param.alignment); + buffer_delete(&buffer); - printf("0x%x\n", location); - return location == 0 ? 1 : 0; + if (address == -1) { + ERROR("'%s' can't fit in CBFS for align 0x%x.\n", + param.name, param.alignment); + cbfs_image_delete(&image); + return 1; + } + + if (param.top_aligned) + address = address - ntohl(image.header->romsize); + + cbfs_image_delete(&image); + printf("0x%x\n", address); + return 0; } static int cbfs_print(void) @@ -432,7 +459,7 @@ static const struct command commands[] = { {"add-flat-binary", "f:n:l:e:c:b:vh?", cbfs_add_flat_binary}, {"remove", "n:vh?", cbfs_remove}, {"create", "s:B:a:o:m:vh?", cbfs_create}, - {"locate", "f:n:a:vh?", cbfs_locate}, + {"locate", "f:n:a:Tvh?", cbfs_locate}, {"print", "vh?", cbfs_print}, {"extract", "n:f:vh?", cbfs_extract}, }; @@ -443,6 +470,7 @@ static struct option long_options[] = { {"compression", required_argument, 0, 'c' }, {"base-address", required_argument, 0, 'b' }, {"load-address", required_argument, 0, 'l' }, + {"top-aligned", required_argument, 0, 'T' }, {"entry-point", required_argument, 0, 'e' }, {"size", required_argument, 0, 's' }, {"bootblock", required_argument, 0, 'B' }, @@ -461,6 +489,7 @@ 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" "COMMANDs:\n" @@ -477,7 +506,7 @@ static void usage(char *name) "Remove a component\n" " create -s size -B bootblock -m ARCH [-a align] [-o offset] " "Create a ROM file\n" - " locate -f FILE -n NAME -a align " + " locate -f FILE -n NAME [-a align] [-T] " "Find a place for a file of that size\n" " print " "Show the contents of the ROM\n" @@ -578,6 +607,9 @@ int main(int argc, char **argv) case 'f': param.filename = optarg; break; + case 'T': + param.top_aligned = 1; + break; case 'v': verbose++; break; -- cgit v1.2.3