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 <solb@chromium.org>
Reviewed-on: http://review.coreboot.org/10122
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Sol Boucher 2015-05-05 15:35:18 -07:00 committed by Patrick Georgi
parent c5269007c9
commit 297c88c357
1 changed files with 5 additions and 14 deletions

View File

@ -336,17 +336,13 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset,
size_t align, entry_offset; size_t align, entry_offset;
ssize_t last_entry_size; ssize_t last_entry_size;
size_t header_offset, header_end;
size_t cbfs_offset, cbfs_end; size_t cbfs_offset, cbfs_end;
size_t copy_end = copy_offset + copy_size; 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; cbfs_offset = image->header->offset;
header_end = header_offset + sizeof(image->header); cbfs_end = image->header->romsize;
cbfs_offset = htonl(image->header->offset);
cbfs_end = htonl(image->header->romsize);
if (copy_end > image->buffer.size) { if (copy_end > image->buffer.size) {
ERROR("Copy offset out of range: [%zx:%zx)\n", 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; return 1;
} }
/* Range check requested copy region with header and source cbfs. */ /* Range check requested copy region with 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");
}
if ((copy_offset >= cbfs_offset && copy_offset < cbfs_end) || if ((copy_offset >= cbfs_offset && copy_offset < cbfs_end) ||
(copy_end >= cbfs_offset && copy_end <= cbfs_end)) { (copy_end >= cbfs_offset && copy_end <= cbfs_end)) {
ERROR("New image would overlap old one.\n"); 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. */ /* This will work, let's create a copy. */
copy_header = (struct cbfs_header *)(image->buffer.data + copy_offset); 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; copy_header->bootblocksize = 0;
/* Romsize is a misnomer. It's the absolute limit of cbfs content.*/ /* Romsize is a misnomer. It's the absolute limit of cbfs content.*/