From 297c88c35748ecd1f82fc96b71e10b118c587c71 Mon Sep 17 00:00:00 2001 From: Sol Boucher Date: Tue, 5 May 2015 15:35:18 -0700 Subject: cbfstool: Fix cbfs_copy_instance()'s master header endianness The function hadn't been updated to account for the fact that we now copy an endianness-corrected CBFS master header into a separate buffer from the CBFS data: it still performed pointer arithmetic accross the two buffers and wrote the copied buffer into the image without restoring the original endianness. Change-Id: Ieb2a001f253494cf3a90d7e19cd260791200c4d3 Signed-off-by: Sol Boucher Reviewed-on: http://review.coreboot.org/10122 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- util/cbfstool/cbfs_image.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'util/cbfstool') diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 8e0e9a48ab..457a87340c 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -336,17 +336,13 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset, size_t align, entry_offset; ssize_t last_entry_size; - size_t header_offset, header_end; size_t cbfs_offset, cbfs_end; size_t copy_end = copy_offset + copy_size; - align = htonl(image->header->align); + align = image->header->align; - header_offset = (char *)image->header - image->buffer.data; - header_end = header_offset + sizeof(image->header); - - cbfs_offset = htonl(image->header->offset); - cbfs_end = htonl(image->header->romsize); + cbfs_offset = image->header->offset; + cbfs_end = image->header->romsize; if (copy_end > image->buffer.size) { ERROR("Copy offset out of range: [%zx:%zx)\n", @@ -354,12 +350,7 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset, return 1; } - /* Range check requested copy region with header and source cbfs. */ - if ((copy_offset >= header_offset && copy_offset < header_end) || - (copy_end >= header_offset && copy_end <= header_end)) { - ERROR("New image would overlap old header.\n"); - } - + /* Range check requested copy region with source cbfs. */ if ((copy_offset >= cbfs_offset && copy_offset < cbfs_end) || (copy_end >= cbfs_offset && copy_end <= cbfs_end)) { ERROR("New image would overlap old one.\n"); @@ -368,7 +359,7 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset, /* This will work, let's create a copy. */ copy_header = (struct cbfs_header *)(image->buffer.data + copy_offset); - *copy_header = *image->header; + cbfs_put_header(copy_header, image->header); copy_header->bootblocksize = 0; /* Romsize is a misnomer. It's the absolute limit of cbfs content.*/ -- cgit v1.2.3