From 6ce41c06ccdf1c80600ef4cf8e140f928b09d754 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Mon, 8 Jun 2009 03:33:57 +0000 Subject: This is transition code for cbfs to implement cbfs files at fixed addresses. I call this transitional as the approach I am taking is to add capability to cbfstool but not change code in a way that will break existing usages. Later, once we're sure nothing has broken, we can start to smooth the edges. Right now, fixed address file are only supported via the add command. There is one additional command syntax, so, example: cbfstool add rom romstrap optionrom 0xffffd000 Will add the file to that fix location for a romstrap. The assumption is that the ROM is based at the end of a 32-bit address space. As you can see from the code, that assumption can easily be over-ridden, if we ever need to, with a command option. Here is one example output result. rminnich@xcpu2:~/src/bios/coreboot-v2/util/cbfstool$ ./cbfstool x.cbf print x.cbf: 1024 kB, bootblocksize 32768, romsize 1048576, offset 0x0 Alignment: 16 bytes Name Offset Type Size h 0x0 optionrom 251 0x130 free 917120 h3 0xdffe0 optionrom 251 0xe0110 free 97960 The way this is implemented is pretty simple. I introduce a new operator, split, that splits an unallocated area into two unallocated areas. Then, allocation merely becomes a matter of 0, 1, or 2 splits: 0 split -- the free area is the exact fit 1 splits -- need to split some off the front or back 2 splits -- need to split off BOTH the front and back I think you'll be able to see what I've done. I call this transitional because, in the end state, we only need one allocate function; for now I've left two in, to make sure I don't break compatibilty. Why I like this better than ldscript approach: I like having the ROMSTRAP located by cbfs, not linker scripts. For one thing, it makes romstrap visible as a first class object. I think I would have latched onto a problem I was having much more quickly had I remembered the ROMSTRAP. It gets lost in the linker scripts. At this point, we should be able to start removing special ROMSTRAP location code from linker scripts. Signed-off-by: Ronald G. Minnich Acked-by: Patrick Georgi git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4351 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- util/cbfstool/add.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'util/cbfstool/add.c') diff --git a/util/cbfstool/add.c b/util/cbfstool/add.c index a62a15857b..9950d5bdf9 100644 --- a/util/cbfstool/add.c +++ b/util/cbfstool/add.c @@ -76,7 +76,7 @@ static int add_from_fd(struct rom *rom, const char *name, int type, int fd) return -1; } - ret = rom_add(rom, name, buffer, size, type); + ret = rom_add(rom, name, buffer, 0, size, type); free(buffer); return ret; @@ -165,7 +165,7 @@ int fork_tool_and_add(struct rom *rom, const char *tool, const char *input, } static int add_blob(struct rom *rom, const char *filename, - const char *name, int type) + const char *name, unsigned long address, int type) { void *ptr; struct stat s; @@ -195,7 +195,7 @@ static int add_blob(struct rom *rom, const char *filename, return -1; } - ret = rom_add(rom, name, ptr, s.st_size, type); + ret = rom_add(rom, name, ptr, address, s.st_size, type); munmap(ptr, s.st_size); close(fd); @@ -205,7 +205,7 @@ static int add_blob(struct rom *rom, const char *filename, void add_usage(void) { - printf("add FILE NAME TYPE\tAdd a component\n"); + printf("add FILE NAME TYPE [base address]\tAdd a component\n"); } void add_stage_usage(void) @@ -238,12 +238,17 @@ int select_component_type(char *s) int add_handler(struct rom *rom, int argc, char **argv) { unsigned int type = CBFS_COMPONENT_NULL; + unsigned long address; - if (argc != 3) { + if ((argc < 3) || (argc > 4)) { add_usage(); return -1; } + if (argc > 3) { + address = strtoul(argv[3], 0, 0); + } + if (!rom_exists(rom)) { ERROR("You need to create the ROM before adding files to it\n"); return -1; @@ -278,7 +283,7 @@ int add_handler(struct rom *rom, int argc, char **argv) } } - return add_blob(rom, argv[0], argv[1], type); + return add_blob(rom, argv[0], argv[1], address, type); } char *find_tool(char *tool) -- cgit v1.2.3