From dd2d3f933a45a2fa48af344bd8ab50bb06c212de Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Wed, 12 Aug 2015 12:29:20 +0200 Subject: [PATCH] cbfstool: unify actual file creation After the preparation in earlier commits, it is now possible to handle the more general case of position independent files using the special code path for fixed location files. This leads to a single place where non-empty cbfs file headers are actually written into the image, allowing us to move it up the chain more easily. Change-Id: I8c1fca5e4e81c20971b2960c87690e982aa3e274 Signed-off-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/11222 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- util/cbfstool/cbfs_image.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 19281eeaaa..7d6239ac86 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -546,7 +546,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, uint32_t entry_type; uint32_t addr, addr_next; struct cbfs_file *entry, *next; - uint32_t need_size, new_size; + uint32_t need_size; if (header_size == 0) header_size = cbfs_calculate_file_header_size(name); @@ -600,37 +600,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, // TODO there are more few tricky cases that we may // want to fit by altering offset. - // Can we simply put object here? - if (!content_offset || content_offset == addr + header_size) { - DEBUG("Filling new entry data (%zd bytes).\n", - buffer->size); - cbfs_create_empty_entry(entry, type, buffer->size, name); - memcpy(CBFS_SUBHEADER(entry), buffer->data, buffer->size); - if (verbose) - cbfs_print_entry_info(image, entry, stderr); - - // setup new entry - DEBUG("Setting new empty entry.\n"); - entry = cbfs_find_next_entry(image, entry); - new_size = (cbfs_get_entry_addr(image, next) - - cbfs_get_entry_addr(image, entry)); - - /* Entry was added and no space for new "empty" entry */ - if (new_size < cbfs_calculate_file_header_size("")) { - DEBUG("No need for new \"empty\" entry\n"); - /* No need to increase the size of the just - * stored file to extend to next file. Alignment - * of next file takes care of this. - */ - return 0; - } - new_size -= cbfs_calculate_file_header_size(""); - DEBUG("new size: %d\n", new_size); - cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, - new_size, ""); - if (verbose) - cbfs_print_entry_info(image, entry, stderr); - return 0; + if (content_offset == 0) { + // we tested every condition earlier under which + // placing the file there might fail + content_offset = addr + header_size; } DEBUG("section 0x%x+0x%x for content_offset 0x%x.\n",