Daisuke Nojiri has uploaded this change for review. ( https://review.coreboot.org/28886
Change subject: cbfstool: Empty entry not followed by CBFS_COMPONENT_NULL ......................................................................
cbfstool: Empty entry not followed by CBFS_COMPONENT_NULL
Currently, an entry is cleared only if the adjacent entry is also null or deleted.
This patch ensures the entry to be removed is cleared regardless of the next entry type.
Signed-off-by: Daisuke Nojiri dnojiri@chromium.org
BUG=chromium:889716 BRANCH=none TEST=Run cbfstool bios.bin remove -n ecrw -vvv. Verify bios.bin has FF in the space of the removed entry. TEST=Run sign_official_build.sh on recovery_image.bin. Extract firmware contents from chromeos-firmwareupdate in the resigned image. Run 'futility vbutil_firmware --verify' for vblock_A's and FW_MAIN_A extracted from bios.bin. See the bug for details.
Change-Id: I62540483da6cc35d0a604ec49b2f2b7b11ba9ce5 --- M util/cbfstool/cbfs_image.c 1 file changed, 15 insertions(+), 26 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/86/28886/1
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 306fc29..18b3b49 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -1611,7 +1611,7 @@ { struct cbfs_file *next; uint8_t *name; - uint32_t type, addr, last_addr; + uint32_t type, addr, next_addr;
type = ntohl(entry->type); if (type == CBFS_COMPONENT_DELETED) { @@ -1625,32 +1625,21 @@ if (type != CBFS_COMPONENT_NULL) return 0;
- next = cbfs_find_next_entry(image, entry); - - while (next && cbfs_is_valid_entry(image, next)) { - type = ntohl(next->type); - if (type == CBFS_COMPONENT_DELETED) { - type = CBFS_COMPONENT_NULL; - next->type = htonl(type); - } - if (type != CBFS_COMPONENT_NULL) - return 0; - - addr = cbfs_get_entry_addr(image, entry); - last_addr = cbfs_get_entry_addr( - image, cbfs_find_next_entry(image, next)); - - // Now, we find two deleted/empty entries; try to merge now. - DEBUG("join_empty_entry: combine 0x%x+0x%x and 0x%x+0x%x.\n", - cbfs_get_entry_addr(image, entry), ntohl(entry->len), - cbfs_get_entry_addr(image, next), ntohl(next->len)); - cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, - (last_addr - addr - - cbfs_calculate_file_header_size("")), - ""); - DEBUG("new empty entry: length=0x%x\n", ntohl(entry->len)); - next = cbfs_find_next_entry(image, entry); + /* Loop until non-null entry is found, starting from current entry. + * After loop, next_addr should point to the adjacent non-null entry. */ + next = entry; + while (next->type == CBFS_COMPONENT_DELETED || + next->type == CBFS_COMPONENT_NULL) { + next = cbfs_find_next_entry(image, next); + next_addr = cbfs_get_entry_addr(image, next); + if (!next || !cbfs_is_valid_entry(image, next)) + break; } + + /* New we're creating one null entry for the combined empty spaces */ + addr = cbfs_get_entry_addr(image, entry); + cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, + (next_addr - addr - cbfs_calculate_file_header_size("")), ""); return 0; }