[coreboot-gerrit] Patch set updated for coreboot: cbfstool: Add attributes for position and alignment constraints.

Werner Zeh (werner.zeh@siemens.com) gerrit at coreboot.org
Fri Jan 15 10:44:20 CET 2016


Werner Zeh (werner.zeh at siemens.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/12967

-gerrit

commit ce22707d27683e6cc6d557bfc291fb05f4a00adc
Author: Werner Zeh <werner.zeh at siemens.com>
Date:   Thu Jan 14 13:22:37 2016 +0100

    cbfstool: Add attributes for position and alignment constraints.
    
    Add functionality to cbfstool to generate file attributes
    for position and alignment constraints. This new feature
    can be activated with the -g option and will generate,
    once the option has been enabled, additional attributes
    for the files where position, xip or alignment was specified.
    
    Change-Id: I3db9bd2c20d26b168bc7f320362ed41be349ae3a
    Signed-off-by: Werner Zeh <werner.zeh at siemens.com>
---
 util/cbfstool/cbfs.h     | 14 ++++++++++++++
 util/cbfstool/cbfstool.c | 47 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h
index d77504a..ac4a41c 100644
--- a/util/cbfstool/cbfs.h
+++ b/util/cbfstool/cbfs.h
@@ -108,6 +108,8 @@ struct cbfs_file_attribute {
 #define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff
 #define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c
 #define CBFS_FILE_ATTR_TAG_HASH 0x68736148
+#define CBFS_FILE_ATTR_TAG_POSITION 0x42435350  /* PSCB */
+#define CBFS_FILE_ATTR_TAG_ALIGNMENT 0x42434c41 /* ALCB */
 
 struct cbfs_file_attr_compression {
 	uint32_t tag;
@@ -125,6 +127,18 @@ struct cbfs_file_attr_hash {
 	uint8_t  hash_data[];
 } __PACKED;
 
+struct cbfs_file_attr_position {
+	uint32_t tag;
+	uint32_t len;
+	uint32_t position;
+} __PACKED;
+
+struct cbfs_file_attr_align {
+	uint32_t tag;
+	uint32_t len;
+	uint32_t alignment;
+} __PACKED;
+
 struct cbfs_stage {
 	uint32_t compression;
 	uint64_t entry;
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 62edd4b..ec38504 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -70,6 +70,7 @@ static struct param {
 	bool fill_partial_downward;
 	bool show_immutable;
 	bool stage_xip;
+	bool autogen_attr;
 	int fit_empty_entries;
 	enum comp_algo compression;
 	enum vb2_hash_algorithm hash;
@@ -349,6 +350,31 @@ static int cbfs_add_component(const char *filename,
 			return 1;
 		}
 
+	if (param.autogen_attr) {
+		/* Add position attribute if assigned */
+		if (param.baseaddress_assigned || param.stage_xip) {
+			struct cbfs_file_attr_position *attrs =
+				(struct cbfs_file_attr_position *)
+				cbfs_add_file_attr(header,
+					CBFS_FILE_ATTR_TAG_POSITION,
+					sizeof(struct cbfs_file_attr_position));
+			if (attrs == NULL)
+				return -1;
+			attrs->position = htonl(offset);
+		}
+		/* Add alignment attribute if used */
+		if (param.alignment) {
+			struct cbfs_file_attr_align *attrs =
+				(struct cbfs_file_attr_align *)
+				cbfs_add_file_attr(header,
+					CBFS_FILE_ATTR_TAG_ALIGNMENT,
+					sizeof(struct cbfs_file_attr_align));
+			if (attrs == NULL)
+				return -1;
+			attrs->alignment = htonl(param.alignment);
+		}
+	}
+
 	if (IS_TOP_ALIGNED_ADDRESS(offset))
 		offset = convert_to_from_top_aligned(param.image_region,
 								-offset);
@@ -536,6 +562,8 @@ static int cbfs_add(void)
 	if (param.alignment) {
 		/* CBFS compression file attribute is unconditionally added. */
 		size_t metadata_sz = sizeof(struct cbfs_file_attr_compression);
+		if (param.autogen_attr)
+			metadata_sz += sizeof(struct cbfs_file_attr_align);
 		if (do_cbfs_locate(&address, metadata_sz))
 			return 1;
 		param.baseaddress = address;
@@ -999,12 +1027,14 @@ static int cbfs_copy(void)
 }
 
 static const struct command commands[] = {
-	{"add", "H:r:f:n:t:c:b:a:vA:h?", cbfs_add, true, true},
-	{"add-flat-binary", "H:r:f:n:l:e:c:b:vA:h?", cbfs_add_flat_binary, true,
-									true},
-	{"add-payload", "H:r:f:n:t:c:b:C:I:vA:h?", cbfs_add_payload, true, true},
-	{"add-stage", "a:H:r:f:n:t:c:b:P:S:yvA:h?", cbfs_add_stage, true, true},
-	{"add-int", "H:r:i:n:b:vh?", cbfs_add_integer, true, true},
+	{"add", "H:r:f:n:t:c:b:a:vA:gh?", cbfs_add, true, true},
+	{"add-flat-binary", "H:r:f:n:l:e:c:b:vA:gh?", cbfs_add_flat_binary,
+				true, true},
+	{"add-payload", "H:r:f:n:t:c:b:C:I:vA:gh?", cbfs_add_payload,
+				true, true},
+	{"add-stage", "a:H:r:f:n:t:c:b:P:S: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?", cbfs_add_master_header, true, true},
 	{"copy", "r:R:h?", cbfs_copy, true, true},
 	{"create", "M:r:s:B:b:H:o:m:vh?", cbfs_create, true, true},
@@ -1049,6 +1079,7 @@ static struct option long_options[] = {
 	{"verbose",       no_argument,       0, 'v' },
 	{"with-readonly", no_argument,       0, 'w' },
 	{"xip",           no_argument,       0, 'y' },
+	{"gen-attribute", no_argument,       0, 'g' },
 	{NULL,            0,                 0,  0  }
 };
 
@@ -1113,6 +1144,7 @@ static void usage(char *name)
 	     "  -T               Output top-aligned memory address\n"
 	     "  -u               Accept short data; fill upward/from bottom\n"
 	     "  -d               Accept short data; fill downward/from top\n"
+	     "  -g               Generate potition and alignment arguments\n"
 	     "  -v               Provide verbose output\n"
 	     "  -h               Display this help message\n\n"
 	     "COMMANDs:\n"
@@ -1347,6 +1379,9 @@ int main(int argc, char **argv)
 			case 'y':
 				param.stage_xip = true;
 				break;
+			case 'g':
+				param.autogen_attr = true;
+				break;
 			case 'h':
 			case '?':
 				usage(argv[0]);



More information about the coreboot-gerrit mailing list