cbfstool: Use cbfs_image API for "remove" command.
To delete a component (file) from existing CBFS ROM image. To test: cbfstool coreboot.rom remove -n fallback/romstage # and compare with old cbfstool output result. Change-Id: If39ef9be0b34d8e3df77afb6c9f944e02f08bc4e Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: http://review.coreboot.org/2208 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
0f8af71f1a
commit
c03d9b0c43
|
@ -98,6 +98,13 @@ uint32_t get_cbfs_compression(const char *name, uint32_t unknown) {
|
||||||
return lookup_type_by_name(types_cbfs_compression, name, unknown);
|
return lookup_type_by_name(types_cbfs_compression, name, unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* CBFS image */
|
||||||
|
|
||||||
|
static int cbfs_calculate_file_header_size(const char *name) {
|
||||||
|
return (sizeof(struct cbfs_file) +
|
||||||
|
align_up(strlen(name) + 1, CBFS_FILENAME_ALIGN));
|
||||||
|
}
|
||||||
|
|
||||||
int cbfs_image_from_file(struct cbfs_image *image, const char *filename) {
|
int cbfs_image_from_file(struct cbfs_image *image, const char *filename) {
|
||||||
if (buffer_from_file(&image->buffer, filename) != 0)
|
if (buffer_from_file(&image->buffer, filename) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -166,6 +173,29 @@ int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cbfs_remove_entry(struct cbfs_image *image, const char *name) {
|
||||||
|
struct cbfs_file *entry, *next;
|
||||||
|
size_t len;
|
||||||
|
entry = cbfs_get_entry(image, name);
|
||||||
|
if (!entry) {
|
||||||
|
ERROR("CBFS file %s not found.\n", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
next = cbfs_find_next_entry(image, entry);
|
||||||
|
assert(next);
|
||||||
|
DEBUG("cbfs_remove_entry: Removed %s @ 0x%x\n",
|
||||||
|
CBFS_NAME(entry), cbfs_get_entry_addr(image, entry));
|
||||||
|
entry->type = htonl(CBFS_COMPONENT_DELETED);
|
||||||
|
len = (cbfs_get_entry_addr(image, next) -
|
||||||
|
cbfs_get_entry_addr(image, entry));
|
||||||
|
entry->offset = htonl(cbfs_calculate_file_header_size(""));
|
||||||
|
entry->len = htonl(len - ntohl(entry->offset));
|
||||||
|
memset(CBFS_NAME(entry), 0, ntohl(entry->offset) - sizeof(*entry));
|
||||||
|
memset(CBFS_SUBHEADER(entry), CBFS_CONTENT_DEFAULT_VALUE,
|
||||||
|
ntohl(entry->len));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int cbfs_print_header_info(struct cbfs_image *image) {
|
int cbfs_print_header_info(struct cbfs_image *image) {
|
||||||
char *name = strdup(image->buffer.name);
|
char *name = strdup(image->buffer.name);
|
||||||
assert(image && image->header);
|
assert(image && image->header);
|
||||||
|
|
|
@ -46,6 +46,9 @@ struct cbfs_file *cbfs_get_entry(struct cbfs_image *image, const char *name);
|
||||||
int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
int cbfs_export_entry(struct cbfs_image *image, const char *entry_name,
|
||||||
const char *filename);
|
const char *filename);
|
||||||
|
|
||||||
|
/* Removes an entry from CBFS image. Returns 0 on success, otherwise non-zero. */
|
||||||
|
int cbfs_remove_entry(struct cbfs_image *image, const char *name);
|
||||||
|
|
||||||
/* Callback function used by cbfs_walk.
|
/* Callback function used by cbfs_walk.
|
||||||
* Returns 0 on success, or non-zero to stop further iteration. */
|
* Returns 0 on success, or non-zero to stop further iteration. */
|
||||||
typedef int (*cbfs_entry_callback)(struct cbfs_image *image,
|
typedef int (*cbfs_entry_callback)(struct cbfs_image *image,
|
||||||
|
|
|
@ -312,33 +312,31 @@ static int cbfs_add_flat_binary(void)
|
||||||
|
|
||||||
static int cbfs_remove(void)
|
static int cbfs_remove(void)
|
||||||
{
|
{
|
||||||
void *rom;
|
struct cbfs_image image;
|
||||||
|
|
||||||
if (!param.name) {
|
if (!param.name) {
|
||||||
ERROR("You need to specify -n/--name.\n");
|
ERROR("You need to specify -n/--name.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rom = loadrom(param.cbfs_name);
|
if (cbfs_image_from_file(&image, param.cbfs_name) != 0) {
|
||||||
if (rom == NULL) {
|
|
||||||
ERROR("Could not load ROM image '%s'.\n",
|
ERROR("Could not load ROM image '%s'.\n",
|
||||||
param.cbfs_name);
|
param.cbfs_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remove_file_from_cbfs(param.name)) {
|
if (cbfs_remove_entry(&image, param.name) != 0) {
|
||||||
ERROR("Removing file '%s' failed.\n",
|
ERROR("Removing file '%s' failed.\n",
|
||||||
param.name);
|
param.name);
|
||||||
free(rom);
|
cbfs_image_delete(&image);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (cbfs_image_write_file(&image, param.cbfs_name) != 0) {
|
||||||
|
cbfs_image_delete(&image);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writerom(param.cbfs_name, rom, romsize)) {
|
cbfs_image_delete(&image);
|
||||||
free(rom);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(rom);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue