From 1b72ba7b3637b4ffa334a7455b92fdd249974c88 Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Wed, 4 Sep 2024 12:06:31 +0800 Subject: util/cbfstool: Print max empty entry size in error message Currently, cbfstool prints the following error message when the added file doesn't fit in the region: E: Could not add [file, 1024 bytes (1 KB)@0x0]; too big? It requires manual inspection to know the space left in the region. To make that easier, also print the maximum empty CBFS entry size in the error message: E: Could not add file [header 76 + content 1024 bytes (1 KB)] @0x0; Largest empty slot: 512 bytes Change-Id: I00bcc83abe8b0a33dcd7b75521e6cfccd8953661 Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/84204 Tested-by: build bot (Jenkins) Reviewed-by: Yidi Lin --- util/cbfstool/cbfs_image.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 740a3b2a1e..e9353570cb 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -743,6 +743,8 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, uint32_t entry_type; uint32_t addr, addr_next; + uint32_t entry_size; + uint32_t max_null_entry_size = 0; struct cbfs_file *entry, *next; uint32_t need_size; uint32_t header_size = be32toh(header->offset); @@ -766,9 +768,11 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, addr = cbfs_get_entry_addr(image, entry); next = cbfs_find_next_entry(image, entry); addr_next = cbfs_get_entry_addr(image, next); + entry_size = addr_next - addr; + max_null_entry_size = MAX(max_null_entry_size, entry_size); DEBUG("cbfs_add_entry: space at 0x%x+0x%x(%d) bytes\n", - addr, addr_next - addr, addr_next - addr); + addr, entry_size, entry_size); /* Will the file fit? Don't yet worry if we have space for a new * "empty" entry. We take care of that later. @@ -803,7 +807,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, } DEBUG("section 0x%x+0x%x for content_offset 0x%x.\n", - addr, addr_next - addr, content_offset); + addr, entry_size, content_offset); if (cbfs_add_entry_at(image, entry, buffer->data, content_offset, header, len_align) == 0) { @@ -812,8 +816,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, break; } - ERROR("Could not add [%s, %zd bytes (%zd KB)@0x%x]; too big?\n", - buffer->name, buffer->size, buffer->size / 1024, content_offset); + ERROR("Could not add %s [header %d + content %zd bytes (%zd KB)] @0x%x; " + "Largest empty slot: %d bytes\n", + buffer->name, header_size, buffer->size, buffer->size / 1024, content_offset, + max_null_entry_size); return -1; } -- cgit v1.2.3