[coreboot-gerrit] Patch set updated for coreboot: util/cbfstool: Make cbfstool build without vboot (optionally)

Damien Zammit (damien@zamaudio.com) gerrit at coreboot.org
Fri Nov 18 15:29:48 CET 2016


Damien Zammit (damien at zamaudio.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17469

-gerrit

commit 84fa1f7f38536acc635f47bd0073b77233adcdc7
Author: Damien Zammit <damien at zamaudio.com>
Date:   Sat Nov 19 01:08:59 2016 +1100

    util/cbfstool: Make cbfstool build without vboot (optionally)
    
    Previously, cbfstool required the vboot repository in all cases
    to compile correctly with the hashing features.
    
    This patch separates the vboot dependency to an environment
    variable option WITH_VBOOT.  While cbfstool is still built with
    vboot hashing support on by default, it can now be built without it
    by not specifying any extra parameters to "make".
    
    Change-Id: I96e739d7384d7b584328c557bd5d8f993befb012
    Signed-off-by: Damien Zammit <damien at zamaudio.com>
---
 Makefile.inc               |  3 +++
 util/cbfstool/Makefile.inc |  8 +++++++-
 util/cbfstool/cbfs.h       |  6 +++++-
 util/cbfstool/cbfs_image.c |  8 ++++++++
 util/cbfstool/cbfs_image.h |  2 ++
 util/cbfstool/cbfstool.c   | 32 ++++++++++++++++++++++++++++----
 6 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index cb0b21c..153eab6 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -442,6 +442,9 @@ build-dirs:
 #######################################################################
 # Build the tools
 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
+$(CBFSTOOL):
+	@printf "    Compile CBFSTOOL (with VBOOT support)\n"
+	$(MAKE) -C $(top)/util/cbfstool WITH_VBOOT=y
 FMAPTOOL:=$(objutil)/cbfstool/fmaptool
 RMODTOOL:=$(objutil)/cbfstool/rmodtool
 IFWITOOL:=$(objutil)/cbfstool/ifwitool
diff --git a/util/cbfstool/Makefile.inc b/util/cbfstool/Makefile.inc
index d666f6a..4243d46 100644
--- a/util/cbfstool/Makefile.inc
+++ b/util/cbfstool/Makefile.inc
@@ -11,7 +11,6 @@ cbfsobj += xdr.o
 cbfsobj += fit.o
 cbfsobj += partitioned_file.o
 # COMMONLIB
-cbfsobj += cbfs.o
 cbfsobj += fsp_relocate.o
 cbfsobj += lz4_wrapper.o
 cbfsobj += mem_pool.o
@@ -21,11 +20,13 @@ cbfsobj += lzma.o
 cbfsobj += LzFind.o
 cbfsobj += LzmaDec.o
 cbfsobj += LzmaEnc.o
+ifeq ($(WITH_VBOOT), y)
 # CRYPTOLIB
 cbfsobj += 2sha_utility.o
 cbfsobj += 2sha1.o
 cbfsobj += 2sha256.o
 cbfsobj += 2sha512.o
+endif
 # LZ4
 cbfsobj += lz4.o
 cbfsobj += lz4hc.o
@@ -62,6 +63,7 @@ ifwiobj :=
 ifwiobj += ifwitool.o
 ifwiobj += common.o
 
+
 TOOLCFLAGS ?= -Werror -Wall -Wextra
 TOOLCFLAGS += -Wcast-qual -Wmissing-prototypes -Wredundant-decls -Wshadow
 TOOLCFLAGS += -Wstrict-prototypes -Wwrite-strings
@@ -71,9 +73,13 @@ TOOLCPPFLAGS += -I$(top)/util/cbfstool/flashmap
 TOOLCPPFLAGS += -I$(top)/util/cbfstool
 TOOLCPPFLAGS += -I$(objutil)/cbfstool
 TOOLCPPFLAGS += -I$(top)/src/commonlib/include
+ifeq ($(WITH_VBOOT), y)
+TOOLCFLAGS += -DWITH_VBOOT
+TOOLCPPFLAGS += -DWITH_VBOOT
 TOOLCPPFLAGS += -DNEED_VB2_SHA_LIBRARY
 TOOLCPPFLAGS += -I$(VBOOT_SOURCE)/firmware/include
 TOOLCPPFLAGS += -I$(VBOOT_SOURCE)/firmware/2lib/include
+endif
 # UEFI header file support. It's not pretty, but that's what we currently
 # have right now.
 TOOLCPPFLAGS += -I$(top)/src
diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h
index f1ae09d..ee7ee41 100644
--- a/util/cbfstool/cbfs.h
+++ b/util/cbfstool/cbfs.h
@@ -19,7 +19,9 @@
 #include "common.h"
 #include <stdint.h>
 
-#include <vb2_api.h>
+#if defined(WITH_VBOOT)
+# include <vb2_api.h>
+#endif
 
 /* cbfstool will fail when trying to build a cbfs_file header that's larger
  * than MAX_CBFS_FILE_HEADER_BUFFER. 1K should give plenty of room. */
@@ -233,6 +235,7 @@ static struct typedesc_t filetypes[] unused = {
 	{CBFS_COMPONENT_NULL, "null"}
 };
 
+#if defined(WITH_VBOOT)
 static const struct typedesc_t types_cbfs_hash[] unused = {
 	{VB2_HASH_INVALID, "none"},
 	{VB2_HASH_SHA1, "sha1"},
@@ -249,6 +252,7 @@ static size_t widths_cbfs_hash[] unused = {
 };
 
 #define CBFS_NUM_SUPPORTED_HASHES ARRAY_SIZE(widths_cbfs_hash)
+#endif /* WITH_VBOOT */
 
 #define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
 
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 6dc47c7..f6982e6 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -86,6 +86,7 @@ int cbfs_parse_comp_algo(const char *name)
 	return lookup_type_by_name(types_cbfs_compression, name);
 }
 
+#if defined(WITH_VBOOT)
 static const char *get_hash_attr_name(uint16_t hash_type)
 {
 	return lookup_name_by_type(types_cbfs_hash, hash_type, "(invalid)");
@@ -95,6 +96,7 @@ int cbfs_parse_hash_algo(const char *name)
 {
 	return lookup_type_by_name(types_cbfs_hash, name);
 }
+#endif
 
 /* CBFS image */
 
@@ -191,6 +193,7 @@ static int cbfs_file_get_compression_info(struct cbfs_file *entry,
 	return compression;
 }
 
+#if defined (WITH_VBOOT)
 static struct cbfs_file_attr_hash *cbfs_file_get_next_hash(
 	struct cbfs_file *entry, struct cbfs_file_attr_hash *cur)
 {
@@ -208,6 +211,7 @@ static struct cbfs_file_attr_hash *cbfs_file_get_next_hash(
 	};
 	return NULL;
 }
+#endif
 
 void cbfs_get_header(struct cbfs_header *header, void *src)
 {
@@ -1396,6 +1400,7 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
 			);
 	}
 
+#if defined(WITH_VBOOT)
 	struct cbfs_file_attr_hash *hash = NULL;
 	while ((hash = cbfs_file_get_next_hash(entry, hash)) != NULL) {
 		unsigned int hash_type = ntohl(hash->hash_type);
@@ -1420,6 +1425,7 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
 			hash_str, valid_str);
 		free(hash_str);
 	}
+#endif
 
 	if (!verbose)
 		return 0;
@@ -1801,6 +1807,7 @@ struct cbfs_file_attribute *cbfs_add_file_attr(struct cbfs_file *header,
 	return attr;
 }
 
+#if defined(WITH_VBOOT)
 int cbfs_add_file_hash(struct cbfs_file *header, struct buffer *buffer,
 	enum vb2_hash_algorithm hash_type)
 {
@@ -1828,6 +1835,7 @@ int cbfs_add_file_hash(struct cbfs_file *header, struct buffer *buffer,
 
 	return 0;
 }
+#endif
 
 /* Finds a place to hold whole data in same memory page. */
 static int is_in_same_page(uint32_t start, uint32_t size, uint32_t page)
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 0d7877a..8642c98 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -189,9 +189,11 @@ struct cbfs_file_attribute *cbfs_add_file_attr(struct cbfs_file *header,
 					       uint32_t tag,
 					       uint32_t size);
 
+#if defined(WITH_VBOOT)
 /* Adds an extended attribute to header, containing a hash of buffer's data of
  * the type specified by hash_type.
  * Returns 0 on success, -1 on error. */
 int cbfs_add_file_hash(struct cbfs_file *header, struct buffer *buffer,
 	enum vb2_hash_algorithm hash_type);
+#endif /* WITH_VBOOT */
 #endif
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index c823dc8..78c3a6b 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -78,7 +78,9 @@ static struct param {
 	bool machine_parseable;
 	int fit_empty_entries;
 	enum comp_algo compression;
+#if defined(WITH_VBOOT)
 	enum vb2_hash_algorithm hash;
+#endif
 	/* for linux payloads */
 	char *initrd;
 	char *cmdline;
@@ -87,7 +89,9 @@ static struct param {
 	/* All variables not listed are initialized as zero. */
 	.arch = CBFS_ARCHITECTURE_UNKNOWN,
 	.compression = CBFS_COMPRESS_NONE,
+#if defined(WITH_VBOOT)
 	.hash = VB2_HASH_INVALID,
+#endif
 	.headeroffset = ~0,
 	.region_name = SECTION_NAME_PRIMARY_CBFS,
 };
@@ -178,10 +182,11 @@ static int do_cbfs_locate(int32_t *cbfs_addr, size_t metadata_size)
 			metadata_size += sizeof(struct cbfs_file_attr_position);
 	}
 
+#if defined(WITH_VBOOT)
 	/* Take care of the hash attribute if it is used */
 	if (param.hash != VB2_HASH_INVALID)
 		metadata_size += sizeof(struct cbfs_file_attr_hash);
-
+#endif
 	int32_t address = cbfs_locate_entry(&image, buffer.size, param.pagesize,
 						param.alignment, metadata_size);
 	buffer_delete(&buffer);
@@ -372,7 +377,7 @@ static int cbfs_add_component(const char *filename,
 		buffer_delete(&buffer);
 		return 1;
 	}
-
+#if defined(WITH_VBOOT)
 	if (param.hash != VB2_HASH_INVALID)
 		if (cbfs_add_file_hash(header, &buffer, param.hash) == -1) {
 			ERROR("couldn't add hash for '%s'\n", name);
@@ -380,7 +385,7 @@ static int cbfs_add_component(const char *filename,
 			buffer_delete(&buffer);
 			return 1;
 		}
-
+#endif
 	if (param.autogen_attr) {
 		/* Add position attribute if assigned */
 		if (param.baseaddress_assigned || param.stage_xip) {
@@ -634,7 +639,6 @@ static int cbfs_add(void)
 	}
 
 	convert = cbfstool_convert_raw;
-
 	/* Set the alignment to 4KiB minimum for FSP blobs when no base address
 	 * is provided so that relocation can occur. */
 	if (param.type == CBFS_COMPONENT_FSP) {
@@ -1107,7 +1111,9 @@ static struct option long_options[] = {
 	{"fmap-regions",  required_argument, 0, 'r' },
 	{"force",         no_argument,       0, 'F' },
 	{"source-region", required_argument, 0, 'R' },
+#if defined(WITH_VBOOT)
 	{"hash-algorithm",required_argument, 0, 'A' },
+#endif
 	{"header-offset", required_argument, 0, 'H' },
 	{"help",          no_argument,       0, 'h' },
 	{"ignore-sec",    required_argument, 0, 'S' },
@@ -1195,20 +1201,36 @@ static void usage(char *name)
 	     "  -v               Provide verbose output\n"
 	     "  -h               Display this help message\n\n"
 	     "COMMANDs:\n"
+#if defined(WITH_VBOOT)
 	     " add [-r image,regions] -f FILE -n NAME -t TYPE [-A hash] \\\n"
+#else
+	     " add [-r image,regions] -f FILE -n NAME -t TYPE           \\\n"
+#endif
 	     "        [-c compression] [-b base-address | -a alignment] \\\n"
 	     "        [-y|--xip if TYPE is FSP]                            "
 			"Add a component\n"
+#if defined(WITH_VBOOT)
 	     " add-payload [-r image,regions] -f FILE -n NAME [-A hash] \\\n"
+#else
+	     " add-payload [-r image,regions] -f FILE -n NAME           \\\n"
+#endif
 	     "        [-c compression] [-b base-address] \\\n"
 	     "        (linux specific: [-C cmdline] [-I initrd])           "
 			"Add a payload to the ROM\n"
+#if defined(WITH_VBOOT)
 	     " add-stage [-r image,regions] -f FILE -n NAME [-A hash] \\\n"
+#else
+	     " add-stage [-r image,regions] -f FILE -n NAME           \\\n"
+#endif
 	     "        [-c compression] [-b base] [-S section-to-ignore] \\\n"
 	     "        [-a alignment] [-y|--xip] [-P page-size]             "
 			"Add a stage to the ROM\n"
 	     " add-flat-binary [-r image,regions] -f FILE -n NAME \\\n"
+#if defined(WITH_VBOOT)
 	     "        [-A hash] -l load-address -e entry-point \\\n"
+#else
+	     "        -l load-address -e entry-point           \\\n"
+#endif
 	     "        [-c compression] [-b base]                           "
 			"Add a 32bit flat mode binary\n"
 	     " add-int [-r image,regions] -i INTEGER -n NAME [-b base]     "
@@ -1338,6 +1360,7 @@ int main(int argc, char **argv)
 									optarg);
 				break;
 			}
+#if defined(WITH_VBOOT)
 			case 'A': {
 				int algo = cbfs_parse_hash_algo(optarg);
 				if (algo >= 0)
@@ -1349,6 +1372,7 @@ int main(int argc, char **argv)
 				}
 				break;
 			}
+#endif
 			case 'M':
 				param.fmap = optarg;
 				break;



More information about the coreboot-gerrit mailing list