Add a "remove" command to cbfstool

This command removes the first file it finds with the given name by changing
its type to CBFS_COMPONENT_NULL and setting the first character of its name to
a null terminator. If the "files" immediately before or after the target file
are already marked as empty, they're all merged together into one large file.

Change-Id: Idc6b2a4c355c3f039c2ccae81866e3ed6035539b
Signed-off-by: Gabe Black <gabeblack@google.com>
Reviewed-by: Ronald G. Minnich <rminnich@google.com>
Reviewed-on: http://review.coreboot.org/814
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Gabe Black
2012-01-27 00:33:47 -08:00
committed by Stefan Reinauer
parent dd30acdd59
commit e1bb49e2ec
2 changed files with 86 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ typedef enum {
CMD_ADD,
CMD_ADD_PAYLOAD,
CMD_ADD_STAGE,
CMD_REMOVE,
CMD_CREATE,
CMD_LOCATE,
CMD_PRINT,
@@ -195,6 +196,33 @@ static int cbfs_add_stage(int argc, char **argv)
return 0;
}
static int cbfs_remove(int argc, char **argv)
{
char *romname = argv[1];
char *cmd = argv[2];
void *rom = loadrom(romname);
if (rom == NULL) {
printf("Could not load ROM image '%s'.\n", romname);
return 1;
}
if (argc < 4) {
printf("not enough arguments to '%s'.\n", cmd);
return 1;
}
char *cbfsname = argv[3];
if (remove_file_from_cbfs(cbfsname)) {
printf("Removing file '%s' failed.\n", cbfsname);
return 1;
}
if (writerom(romname, rom, romsize))
return 1;
return 0;
}
static int cbfs_create(int argc, char **argv)
{
char *romname = argv[1];
@@ -275,6 +303,7 @@ static const struct command commands[] = {
{CMD_ADD, "add", cbfs_add},
{CMD_ADD_PAYLOAD, "add-payload", cbfs_add_payload},
{CMD_ADD_STAGE, "add-stage", cbfs_add_stage},
{CMD_REMOVE, "remove", cbfs_remove},
{CMD_CREATE, "create", cbfs_create},
{CMD_LOCATE, "locate", cbfs_locate},
{CMD_PRINT, "print", cbfs_print},
@@ -292,6 +321,7 @@ static void usage(void)
" add FILE NAME TYPE [base address] Add a component\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"
" remove FILE NAME Remove a component\n"
" create SIZE BOOTBLOCK [ALIGN] Create a ROM file\n"
" locate FILE NAME ALIGN Find a place for a file of that size\n"
" print Show the contents of the ROM\n"