Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/63306 )
Change subject: cbfs_image.c: Drop compatibility for old images ......................................................................
cbfs_image.c: Drop compatibility for old images
This has long been fixed. Old images should use an old cbfstool.
Change-Id: I3c612c5d50948502609e5031b660f7519eabff0a Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M util/cbfstool/cbfs_image.c M util/cbfstool/cbfstool.c 2 files changed, 0 insertions(+), 160 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/06/63306/1
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 5f30877..a258a81 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -69,40 +69,6 @@ align_up(strlen(name) + 1, CBFS_ATTRIBUTE_ALIGN)); }
-/* Only call on legacy CBFSes possessing a master header. */ -static int cbfs_fix_legacy_size(struct cbfs_image *image, char *hdr_loc) -{ - assert(image); - assert(cbfs_is_legacy_cbfs(image)); - // A bug in old cbfstool may produce extra few bytes (by alignment) and - // cause cbfstool to overwrite things after free space -- which is - // usually CBFS header on x86. We need to workaround that. - // Except when we run across a file that contains the actual header, - // in which case this image is a safe, new-style - // `cbfstool add-master-header` based image. - - struct cbfs_file *entry, *first = NULL, *last = NULL; - for (first = entry = cbfs_find_first_entry(image); - entry && cbfs_is_valid_entry(image, entry); - entry = cbfs_find_next_entry(image, entry)) { - /* Is the header guarded by a CBFS file entry? Then exit */ - if (((char *)entry) + be32toh(entry->offset) == hdr_loc) - return 0; - last = entry; - } - if ((char *)first < (char *)hdr_loc && - (char *)entry > (char *)hdr_loc) { - WARN("CBFS image was created with old cbfstool with size bug. " - "Fixing size in last entry...\n"); - last->len = htobe32(be32toh(last->len) - image->header.align); - DEBUG("Last entry has been changed from 0x%x to 0x%x.\n", - cbfs_get_entry_addr(image, entry), - cbfs_get_entry_addr(image, - cbfs_find_next_entry(image, last))); - } - return 0; -} - void cbfs_put_header(void *dest, const struct cbfs_header *header) { struct buffer outheader; @@ -344,7 +310,6 @@ if (header_loc) { cbfs_get_header(&out->header, header_loc); out->has_header = true; - cbfs_fix_legacy_size(out, header_loc); return 0; } else if (offset != ~0u) { ERROR("The -H switch is only valid on legacy images having CBFS master headers.\n"); diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index cebfef6..95e0bbf 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -642,127 +642,6 @@ return 1; }
-static void fill_header_offset(void *location, uint32_t offset) -{ - // TODO: When we have a BE target, we'll need to store this as BE - write_le32(location, offset); -} - -static int update_master_header_loc_topswap(struct cbfs_image *image, - void *h_loc, uint32_t header_offset) -{ - struct cbfs_file *entry; - void *ts_h_loc = h_loc; - - entry = cbfs_get_entry(image, "bootblock"); - if (entry == NULL) { - ERROR("Bootblock not in ROM image?!?\n"); - return 1; - } - - /* - * Check if the existing topswap boundary matches with - * the one provided. - */ - if (param.topswap_size != be32toh(entry->len)/2) { - ERROR("Top swap boundary does not match\n"); - return 1; - } - - ts_h_loc -= param.topswap_size; - fill_header_offset(ts_h_loc, header_offset); - - return 0; -} - -static int cbfs_add_master_header(void) -{ - const char * const name = "cbfs master header"; - struct cbfs_image image; - struct cbfs_file *header = NULL; - struct buffer buffer; - int ret = 1; - size_t offset; - size_t size; - void *h_loc; - - if (cbfs_image_from_buffer(&image, param.image_region, - param.headeroffset)) { - ERROR("Selected image region is not a CBFS.\n"); - return 1; - } - - if (cbfs_get_entry(&image, name)) { - ERROR("'%s' already in ROM image.\n", name); - return 1; - } - - if (buffer_create(&buffer, sizeof(struct cbfs_header), name) != 0) - return 1; - - struct cbfs_header *h = (struct cbfs_header *)buffer.data; - h->magic = htobe32(CBFS_HEADER_MAGIC); - h->version = htobe32(CBFS_HEADER_VERSION); - /* 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 - * below 4GB has a bootblock and get confused when the end of the - * image is at 4GB == 0. - */ - h->bootblocksize = htobe32(4); - h->align = htobe32(CBFS_ALIGNMENT); - /* 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. - */ - offset = buffer_get(param.image_region) - - buffer_get_original_backing(param.image_region); - size = buffer_size(param.image_region); - h->romsize = htobe32(size + offset); - h->offset = htobe32(offset); - h->architecture = htobe32(CBFS_ARCHITECTURE_UNKNOWN); - - /* Never add a hash attribute to the master header. */ - header = cbfs_create_file_header(CBFS_TYPE_CBFSHEADER, - buffer_size(&buffer), name); - if (cbfs_add_entry(&image, &buffer, 0, header, 0) != 0) { - ERROR("Failed to add cbfs master header into ROM image.\n"); - goto done; - } - - struct cbfs_file *entry; - if ((entry = cbfs_get_entry(&image, name)) == NULL) { - ERROR("'%s' not in ROM image?!?\n", name); - goto done; - } - - uint32_t header_offset = CBFS_SUBHEADER(entry) - - buffer_get(&image.buffer); - header_offset = -(buffer_size(&image.buffer) - header_offset); - - h_loc = (void *)(buffer_get(&image.buffer) + - buffer_size(&image.buffer) - 4); - fill_header_offset(h_loc, header_offset); - /* - * If top swap present, update the header - * location in secondary bootblock - */ - if (param.topswap_size) { - if (update_master_header_loc_topswap(&image, h_loc, - header_offset)) - return 1; - } - - ret = maybe_update_metadata_hash(&image); - -done: - free(header); - buffer_delete(&buffer); - return ret; -} - static int add_topswap_bootblock(struct buffer *buffer, uint32_t *offset) { size_t bb_buf_size = buffer_size(buffer); @@ -1718,7 +1597,6 @@ {"add-stage", "a:H:r:f:n:t:c:b:P:QS:p:yvA:gh?", cbfs_add_stage, true, true}, {"add-int", "H:r:i:n:b:vgh?", cbfs_add_integer, true, true}, - {"add-master-header", "H:r:vh?j:", cbfs_add_master_header, true, true}, {"compact", "r:h?", cbfs_compact, true, true}, {"copy", "r:R:h?", cbfs_copy, true, true}, {"create", "M:r:s:B:b:H:o:m:vh?", cbfs_create, true, true}, @@ -1912,9 +1790,6 @@ "Add a 32bit flat mode binary\n" " add-int [-r image,regions] -i INTEGER -n NAME [-b base] " "Add a raw 64-bit integer value\n" - " add-master-header [-r image,regions] \ \n" - " [-j topswap-size] (Intel CPUs only) " - "Add a legacy CBFS master header\n" " remove [-r image,regions] -n NAME " "Remove a component\n" " compact -r image,regions "