Aaron Durbin (adurbin@chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12825
-gerrit
commit 80d3a4f555dd2a6dd1e64ee10512fc19d5f82293 Author: Aaron Durbin adurbin@chromium.org Date: Mon Jan 4 13:56:00 2016 -0600
cbfstool: correct add-master-header logic to match runtime expectations
The cbfs master header's offset and romsize fields are absolute values within the boot media proper. Therefore, when adding a master header provide the offset of the CBFS region one is operating on as well as the absolute end offset (romsize) to match expectations.
Built with and without CBFS_SIZE != ROM_SIZE on x86 and ARM device. Manually inspected the master headers within the images to confirm proper caclulations.
Change-Id: Id0623fd713ee7a481ce3326f4770c81beda20f64 Signed-off-by: Aaron Durbin adurbin@chromium.org --- util/cbfstool/cbfstool.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 2529296..4868956 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -225,6 +225,8 @@ static int cbfs_add_master_header(void) struct cbfs_file *header = NULL; struct buffer buffer; int ret = 1; + size_t offset; + size_t size;
if (cbfs_image_from_buffer(&image, param.image_region, param.headeroffset)) { @@ -243,7 +245,6 @@ static int cbfs_add_master_header(void) struct cbfs_header *h = (struct cbfs_header *)buffer.data; h->magic = htonl(CBFS_HEADER_MAGIC); h->version = htonl(CBFS_HEADER_VERSION); - h->romsize = htonl(param.image_region->size); /* The 4 bytes are left out for two reasons: * 1. the cbfs master header pointer resides there * 2. some cbfs implementations assume that an image that resides @@ -252,10 +253,17 @@ static int cbfs_add_master_header(void) */ h->bootblocksize = htonl(4); h->align = htonl(CBFS_ENTRY_ALIGNMENT); - /* offset relative to romsize above, which covers precisely the CBFS - * region. + /* The offset and romsize fields within the master header are absolute + * values within the boot media. As such, romsize needs to relfect + * the end 'offset' for a CBFS. To achieve that the current buffer + * representing the CBFS region's size is added to the offset of + * the region within a larger image. */ - h->offset = htonl(0); + offset = buffer_get(param.image_region) - + buffer_get_original_backing(param.image_region); + size = buffer_size(param.image_region); + h->romsize = htonl(size + offset); + h->offset = htonl(offset); h->architecture = htonl(CBFS_ARCHITECTURE_UNKNOWN);
header = cbfs_create_file_header(CBFS_COMPONENT_CBFSHEADER,