[coreboot-gerrit] New patch to review for coreboot: 31db268 cbfstool: Fix architecture check when adding payload

Isaac Christensen (isaac.christensen@se-eng.com) gerrit at coreboot.org
Thu Sep 11 21:13:04 CEST 2014


Isaac Christensen (isaac.christensen at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6879

-gerrit

commit 31db2687b6b6152142a27b691bccdf7cb24a9cb3
Author: Stefan Reinauer <reinauer at chromium.org>
Date:   Wed Nov 13 14:34:57 2013 -0800

    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.
    
    Change-Id: I37ee65a467d9658d0846c2cf43b582e285f1a8f8
    Signed-off-by: Stefan Reinauer <reinauer at google.com>
    Reviewed-on: https://chromium-review.googlesource.com/176711
    Reviewed-by: Hung-Te Lin <hungte at chromium.org>
    Commit-Queue: Stefan Reinauer <reinauer at chromium.org>
    Tested-by: Stefan Reinauer <reinauer at chromium.org>
    (cherry picked from commit 8f74f3f5227e440ae46b59f8fd692f679f3ada2d)
    Signed-off-by: Isaac Christensen <isaac.christensen at se-eng.com>
---
 util/cbfstool/cbfs_image.c |  5 +++--
 util/cbfstool/cbfstool.c   | 13 +++++++------
 util/cbfstool/common.c     | 15 +++++++++++++++
 util/cbfstool/common.h     |  1 +
 4 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index afe1298..1a522bd 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -570,13 +570,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,
 	       image->header->bootblocksize,
 	       image->header->romsize,
 	       image->header->offset,
-	       image->header->align);
+	       image->header->align,
+	       arch_to_string(image->header->architecture));
 	free(name);
 	return 0;
 }
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 937b610..33aac88 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -136,20 +136,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;
 	}
 
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index a28e741..6081949 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -150,6 +150,21 @@ uint32_t string_to_arch(const char *arch_string)
 	return ret;
 }
 
+const char *arch_to_string(uint32_t a)
+{
+	int i;
+	const char *ret = NULL;
+
+	for (i = 0; i < ARRAY_SIZE(arch_names); i++) {
+		if (a == arch_names[i].arch) {
+			ret = arch_names[i].name;
+			break;
+		}
+	}
+
+	return ret;
+}
+
 static struct filetypes_t {
 	uint32_t type;
 	const char *name;
diff --git a/util/cbfstool/common.h b/util/cbfstool/common.h
index b1f25d0..455fb8b 100644
--- a/util/cbfstool/common.h
+++ b/util/cbfstool/common.h
@@ -112,6 +112,7 @@ int buffer_write_file(struct buffer *buffer, const char *filename);
 /* Destroys a memory buffer. */
 void buffer_delete(struct buffer *buffer);
 
+const char *arch_to_string(uint32_t a);
 uint32_t string_to_arch(const char *arch_string);
 
 #define ALIGN(val, by) (((val) + (by)-1)&~((by)-1))



More information about the coreboot-gerrit mailing list