From bb826ef661f7ff390e284bcae6b0b330ca48ceb3 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Mon, 4 Jan 2016 13:56:00 -0600 Subject: 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 Reviewed-on: https://review.coreboot.org/12825 Tested-by: build bot (Jenkins) Tested-by: Raptor Engineering Automated Test Stand Reviewed-by: Timothy Pearson --- 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 95199536f8..6c130c8567 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -224,6 +224,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)) { @@ -242,7 +244,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 @@ -251,10 +252,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, -- cgit v1.2.3