[coreboot] New patch to review for coreboot: f096ce1 cbfstool: Fix initial empty space in image creation.

Hung-Te Lin (hungte@chromium.org) gerrit at coreboot.org
Fri Mar 15 10:49:27 CET 2013

Hung-Te Lin (hungte at chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2731


commit f096ce19f8b454e52f04d842ee619ad1ca4cf45f
Author: Hung-Te Lin <hungte at chromium.org>
Date:   Fri Mar 15 17:40:08 2013 +0800

    cbfstool: Fix initial empty space in image creation.
    When calculating initial CBFS empty entry space, the size of header itself must
    be included (with the reserved space for entry name). This is a regression of
    old cbfstool size bug.
    Before this fix, in build process we see:
     OBJCOPY    cbfs/fallback/romstage_null.bin
     W: CBFS image was created with old cbfstool with size bug.
        Fixing size in last entry...
    And checking the output binary:
     cbfstool build/coreboot.pre1 print -v -v
     DEBUG: read_cbfs_image: build/coreboot.pre1 (262144 bytes)
     DEBUG: x86sig: 0xfffffd30, offset: 0x3fd30
     W: CBFS image was created with old cbfstool with size bug.
        Fixing size in last entry...
     DEBUG: Last entry has been changed from 0x3fd40 to 0x3fd00.
     coreboot.pre1: 256 kB, bootblksz 688, romsize 262144, offset 0x0 align: 64
     Name                           Offset     Type         Size
     (empty)                        0x0        null         261296
     DEBUG:  cbfs_file=0x0, offset=0x28, content_address=0x28+0x3fcb0
    After this fix, no longer alerts in build process.
    Verified to build successfully on x86/qemu and arm/snow configurations.
    Change-Id: I35c96f4c10a41bae671148a0e08988fa3bf6b7d3
    Signed-off-by: Hung-Te Lin <hungte at chromium.org>
 util/cbfstool/cbfs_image.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 2cdbf23..7b43e35 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -142,6 +142,7 @@ int cbfs_image_create(struct cbfs_image *image,
 	struct cbfs_header *header;
 	struct cbfs_file *entry;
 	uint32_t cbfs_len;
+	size_t entry_header_len;
 	DEBUG("cbfs_image_create: bootblock=0x%x+0x%zx, "
 	      "header=0x%x+0x%zx, entries_offset=0x%x\n",
@@ -205,9 +206,10 @@ int cbfs_image_create(struct cbfs_image *image,
 		      entries_offset, align);
 		return -1;
-	if (entries_offset + sizeof(*entry) > size) {
+	entry_header_len = cbfs_calculate_file_header_size("");
+	if (entries_offset + entry_header_len > size) {
 		ERROR("Offset (0x%x+0x%zx) exceed ROM size(0x%zx)\n",
-		      entries_offset, sizeof(*entry), size);
+		      entries_offset, entry_header_len, size);
 		return -1;
 	entry = (struct cbfs_file *)(image->buffer.data + entries_offset);
@@ -218,7 +220,8 @@ int cbfs_image_create(struct cbfs_image *image,
 		cbfs_len = bootblock_offset;
 	if (header_offset > entries_offset && header_offset < cbfs_len)
 		cbfs_len = header_offset;
-	cbfs_len -= entries_offset + align;
+	DEBUG("align: %d, entry_header_len: %d\n", align, entry_header_len);
+	cbfs_len -= entries_offset + align + entry_header_len;
 	cbfs_create_empty_entry(image, entry, cbfs_len, "");
 	LOG("Created CBFS image (capacity = %d bytes)\n", cbfs_len);
 	return 0;

More information about the coreboot mailing list