aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2016-01-04 13:56:00 -0600
committerMartin Roth <martinroth@google.com>2016-01-06 17:45:15 +0100
commitbb826ef661f7ff390e284bcae6b0b330ca48ceb3 (patch)
tree1ad335bfdb27d585792d9c79bb12d1cb3d475191
parent12c55eda11453ed1e7a24e218338831f67cd5de6 (diff)
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> Reviewed-on: https://review.coreboot.org/12825 Tested-by: build bot (Jenkins) Tested-by: Raptor Engineering Automated Test Stand <noreply@raptorengineeringinc.com> Reviewed-by: Timothy Pearson <tpearson@raptorengineeringinc.com>
-rw-r--r--util/cbfstool/cbfstool.c16
1 files 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,