summaryrefslogtreecommitdiff
path: root/util/cbfstool
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2014-01-21 15:28:38 -0600
committerAlexandru Gagniuc <mr.nuke.me@gmail.com>2014-01-24 04:48:05 +0100
commit1ebc7e943b1e48ed0b2c385d64cbe1c88693ac37 (patch)
tree0017e82aad06fbc0b7ffb99cb3ec323e81615810 /util/cbfstool
parent9c70adf26d810405f22ea9f07a10d4f56fee3cb8 (diff)
cbfstool: correct size left calculation for "empty" entries
After removing a file sandwiched between two other files, that file could no longer be re-added at the same location. cbfstool tried to add the file, and a new "empty" entry, which, together, would no longer fit, so it continued checking for the next available space. Change the behavior to add the file if there is enough space for the file alone, then only add the "empty" entry if there is enough space for it. Change-Id: Iad3897dd28cf12f12ae877cfd83e1990fa7d2f0f Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/4772 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com>
Diffstat (limited to 'util/cbfstool')
-rw-r--r--util/cbfstool/cbfs_image.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index eb9d574a26..401654e999 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -380,6 +380,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
DEBUG("cbfs_add_entry: space at 0x%x+0x%x(%d) bytes\n",
addr, addr_next - addr, addr_next - addr);
+
+ /* Will the file fit? Don't yet worry if we have space for a new
+ * "empty" entry. We take care of that later.
+ */
if (addr + need_size > addr_next)
continue;
@@ -399,6 +403,16 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
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(image, entry, new_size, "");