cbfstool: add offset parameter to create command

CBFS allows coreboot rom images that are only partially covered
by the filesystem itself. The intention of this feature was to
allow EC / ME / IMC firmware to be inserted easily at the beginning
of the image. However, this was never implemented in cbfstool.

This patch implements an additional parameter for cbfstool.

If you call cbfstool like this:
cbfstool coreboot.rom create 8192K bootblock.bin 64 0x700000
it will now create an 8M image with CBFS covering the last 1M of
that image.

Test:
     cbfstool coreboot.rom create 8192K bootblock.bin 64 0x700000
     creates an 8M image that is 7M of 0xff and 1M of CBFS.

Change-Id: I5c016b4bf32433f160b43f4df2dd768276f4c70b
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/1708
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Stefan Reinauer 2012-08-15 16:05:50 -07:00 committed by Stefan Reinauer
parent 86bf3f518f
commit a90bd527d9
3 changed files with 19 additions and 14 deletions

View File

@ -245,7 +245,11 @@ static int cbfs_create(int argc, char **argv)
if (argc > 5) if (argc > 5)
align = strtoul(argv[5], NULL, 0); align = strtoul(argv[5], NULL, 0);
return create_cbfs_image(romname, size, bootblock, align); uint32_t offs = 0;
if (argc > 6)
offs = strtoul(argv[6], NULL, 0);
return create_cbfs_image(romname, size, bootblock, align, offs);
} }
static int cbfs_locate(int argc, char **argv) static int cbfs_locate(int argc, char **argv)
@ -318,14 +322,14 @@ static void usage(void)
" cbfstool FILE COMMAND [PARAMETERS]...\n\n" "OPTIONs:\n" " cbfstool FILE COMMAND [PARAMETERS]...\n\n" "OPTIONs:\n"
" -h Display this help message\n\n" " -h Display this help message\n\n"
"COMMANDs:\n" "COMMANDs:\n"
" add FILE NAME TYPE [base address] Add a component\n" " add FILE NAME TYPE [base address] Add a component\n"
" add-payload FILE NAME [COMP] [base] Add a payload to the ROM\n" " add-payload FILE NAME [COMP] [base] Add a payload to the ROM\n"
" add-stage FILE NAME [COMP] [base] Add a stage to the ROM\n" " add-stage FILE NAME [COMP] [base] Add a stage to the ROM\n"
" remove FILE NAME Remove a component\n" " remove FILE NAME Remove a component\n"
" create SIZE BOOTBLOCK [ALIGN] Create a ROM file\n" " create SIZE BOOTBLOCK [ALIGN] [offset] Create a ROM file\n"
" locate FILE NAME ALIGN Find a place for a file of that size\n" " locate FILE NAME ALIGN Find a place for a file of that size\n"
" print Show the contents of the ROM\n" " print Show the contents of the ROM\n"
" extract NAME FILE Extracts a raw payload from ROM\n" " extract NAME FILE Extracts a raw payload from ROM\n"
"\n" "\n"
"TYPEs:\n" "TYPEs:\n"
); );

View File

@ -446,7 +446,7 @@ void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
} }
int create_cbfs_image(const char *romfile, uint32_t _romsize, int create_cbfs_image(const char *romfile, uint32_t _romsize,
const char *bootblock, uint32_t align) const char *bootblock, uint32_t align, uint32_t offs)
{ {
romsize = _romsize; romsize = _romsize;
unsigned char *romarea = malloc(romsize); unsigned char *romarea = malloc(romsize);
@ -473,14 +473,14 @@ int create_cbfs_image(const char *romfile, uint32_t _romsize,
master_header->romsize = htonl(romsize); master_header->romsize = htonl(romsize);
master_header->bootblocksize = htonl(bootblocksize); master_header->bootblocksize = htonl(bootblocksize);
master_header->align = htonl(align); master_header->align = htonl(align);
master_header->offset = htonl(0); master_header->offset = htonl(offs);
((uint32_t *) phys_to_virt(0xfffffffc))[0] = ((uint32_t *) phys_to_virt(0xfffffffc))[0] =
virt_to_phys(master_header); virt_to_phys(master_header);
recalculate_rom_geometry(romarea); recalculate_rom_geometry(romarea);
cbfs_create_empty_file((0 - romsize) & 0xffffffff, cbfs_create_empty_file((0 - romsize + offs) & 0xffffffff,
romsize - bootblocksize - romsize - offs - bootblocksize -
sizeof(struct cbfs_header) - sizeof(struct cbfs_header) -
sizeof(struct cbfs_file) - 16); sizeof(struct cbfs_file) - 16);

View File

@ -64,9 +64,10 @@ void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
uint32_t type, uint32_t * location); uint32_t type, uint32_t * location);
int create_cbfs_image(const char *romfile, uint32_t romsize, int create_cbfs_image(const char *romfile, uint32_t romsize,
const char *bootblock, uint32_t align); const char *bootblock, uint32_t align, uint32_t offs);
int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location); int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location);
int remove_file_from_cbfs(const char *filename);
void print_cbfs_directory(const char *filename); void print_cbfs_directory(const char *filename);
int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath); int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath);
int remove_file_from_cbfs(const char *filename); int remove_file_from_cbfs(const char *filename);