From 8f74f3f5227e440ae46b59f8fd692f679f3ada2d Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Wed, 13 Nov 2013 14:34:57 -0800 Subject: [PATCH] cbfstool: Fix architecture check when adding payload In the process of rewriting cbfstool for ARM and using a new internal API a regression was introduced that would silently let you add an ARM payload into an x86 CBFS image and the other way around. This patch fixes cbfstool to produce an error in that case again. BRANCH=none BUG=none TEST=emerge-peach_pit with and without my other CL that fixes the cbfs image type and see it fail without that CL. Change-Id: I37ee65a467d9658d0846c2cf43b582e285f1a8f8 Signed-off-by: Stefan Reinauer Reviewed-on: https://chromium-review.googlesource.com/176711 Reviewed-by: Hung-Te Lin Commit-Queue: Stefan Reinauer Tested-by: Stefan Reinauer --- util/cbfstool/cbfs_image.c | 6 ++++-- util/cbfstool/cbfstool.c | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index f3124606a8..7c89dd752c 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -227,6 +227,7 @@ int cbfs_image_from_file(struct cbfs_image *image, const char *filename) cbfs_image_delete(image); return -1; } + arch = ntohl(image->header->architecture); cbfs_fix_legacy_size(image); return 0; @@ -493,13 +494,14 @@ int cbfs_print_header_info(struct cbfs_image *image) char *name = strdup(image->buffer.name); assert(image && image->header); printf("%s: %zd kB, bootblocksize %d, romsize %d, offset 0x%x\n" - "alignment: %d bytes\n\n", + "alignment: %d bytes, architecture: %s\n\n", basename(name), image->buffer.size / 1024, ntohl(image->header->bootblocksize), ntohl(image->header->romsize), ntohl(image->header->offset), - ntohl(image->header->align)); + ntohl(image->header->align), + arch_to_string(ntohl(image->header->architecture))); free(name); return 0; } diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 074dc5412b..dceca9f535 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -88,20 +88,21 @@ static int cbfs_add_component(const char *cbfs_name, return 1; } + if (cbfs_image_from_file(&image, cbfs_name) != 0) { + ERROR("Could not load ROM image '%s'.\n", cbfs_name); + return 1; + } + if (buffer_from_file(&buffer, filename) != 0) { ERROR("Could not load file '%s'.\n", filename); + cbfs_image_delete(&image); return 1; } if (convert && convert(&buffer, &offset) != 0) { ERROR("Failed to parse file '%s'.\n", filename); buffer_delete(&buffer); - return 1; - } - - if (cbfs_image_from_file(&image, cbfs_name) != 0) { - ERROR("Could not load ROM image '%s'.\n", cbfs_name); - buffer_delete(&buffer); + cbfs_image_delete(&image); return 1; }