[coreboot-gerrit] New patch to review for coreboot: cbfstool: Allow adding file with specific alignemt requirement

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Mon Sep 7 07:50:03 CET 2015


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11525

-gerrit

commit 6f54edb63128ccfe66f498a115149c0b04d7703a
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Mon Sep 7 00:05:44 2015 -0700

    cbfstool: Allow adding file with specific alignemt requirement
    
    Whenever we want to add a file to CBFS with a specific alignment, we
    have to do two cbfstool invocations: one to find a place for the file,
    and another to actually add the file to CBFS. Get rid of this nonsense
    and allow this to be done in one step.
    
    Change-Id: I526483296b494363f15dc169f163d93a6fc71bb0
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 util/cbfstool/cbfstool.c | 98 ++++++++++++++++++++++++++++++------------------
 1 file changed, 61 insertions(+), 37 deletions(-)

diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index a91b600..d6c116a 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -328,8 +328,65 @@ static int cbfstool_convert_mkflatpayload(struct buffer *buffer,
 	return 0;
 }
 
+static int do_cbfs_locate(int32_t *cbfs_addr)
+{
+	if (!param.filename) {
+		ERROR("You need to specify -f/--filename.\n");
+		return 1;
+	}
+
+	if (!param.name) {
+		ERROR("You need to specify -n/--name.\n");
+		return 1;
+	}
+
+	struct cbfs_image image;
+	if (cbfs_image_from_buffer(&image, param.image_region,
+							param.headeroffset))
+		return 1;
+
+	if (cbfs_get_entry(&image, param.name))
+		WARN("'%s' already in CBFS.\n", param.name);
+
+	struct buffer buffer;
+	if (buffer_from_file(&buffer, param.filename) != 0) {
+		ERROR("Cannot load %s.\n", param.filename);
+		return 1;
+	}
+
+	int32_t address = cbfs_locate_entry(&image, param.name, buffer.size,
+				    param.pagesize, param.alignment);
+	buffer_delete(&buffer);
+
+	if (address == -1) {
+		ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n",
+		      param.name, param.pagesize, param.alignment);
+		return 1;
+	}
+
+	if (param.top_aligned)
+		address = -convert_to_from_top_aligned(param.image_region,
+								address);
+
+	*cbfs_addr = address;
+	return 0;
+}
+
 static int cbfs_add(void)
 {
+	int32_t address;
+
+	if (param.alignment && param.baseaddress) {
+		ERROR("Cannot specify both alignment and base address\n");
+		return 1;
+	}
+
+	if (param.alignment) {
+		if (do_cbfs_locate(&address))
+			return 1;
+		param.baseaddress = address;
+	}
+
 	return cbfs_add_component(param.filename,
 				  param.name,
 				  param.type,
@@ -494,43 +551,10 @@ static int cbfs_create(void)
 
 static int cbfs_locate(void)
 {
-	if (!param.filename) {
-		ERROR("You need to specify -f/--filename.\n");
-		return 1;
-	}
-
-	if (!param.name) {
-		ERROR("You need to specify -n/--name.\n");
-		return 1;
-	}
-
-	struct cbfs_image image;
-	if (cbfs_image_from_buffer(&image, param.image_region,
-							param.headeroffset))
-		return 1;
-
-	if (cbfs_get_entry(&image, param.name))
-		WARN("'%s' already in CBFS.\n", param.name);
+	int32_t address;
 
-	struct buffer buffer;
-	if (buffer_from_file(&buffer, param.filename) != 0) {
-		ERROR("Cannot load %s.\n", param.filename);
+	if (do_cbfs_locate(&address) != 0)
 		return 1;
-	}
-
-	int32_t address = cbfs_locate_entry(&image, param.name, buffer.size,
-				    param.pagesize, param.alignment);
-	buffer_delete(&buffer);
-
-	if (address == -1) {
-		ERROR("'%s' can't fit in CBFS for page-size %#x, align %#x.\n",
-		      param.name, param.pagesize, param.alignment);
-		return 1;
-	}
-
-	if (param.top_aligned)
-		address = -convert_to_from_top_aligned(param.image_region,
-								address);
 
 	printf("0x%x\n", address);
 	return 0;
@@ -781,7 +805,7 @@ static bool cbfs_is_legacy_format(struct buffer *buffer)
 }
 
 static const struct command commands[] = {
-	{"add", "H:r:f:n:t:c:b:vh?", cbfs_add, true, true},
+	{"add", "H:r:f:n:t:c:b:a:vh?", cbfs_add, true, true},
 	{"add-flat-binary", "H:r:f:n:l:e:c:b:vh?", cbfs_add_flat_binary, true,
 									true},
 	{"add-payload", "H:r:f:n:t:c:b:C:I:vh?", cbfs_add_payload, true, true},
@@ -896,7 +920,7 @@ static void usage(char *name)
 	     "  -h               Display this help message\n\n"
 	     "COMMANDs:\n"
 	     " add [-r image,regions] -f FILE -n NAME -t TYPE \\\n"
-	     "        [-c compression] [-b base-address]                   "
+	     "        [-c compression] [-b base-address | -a alignment]    "
 			"Add a component\n"
 	     " add-payload [-r image,regions] -f FILE -n NAME \\\n"
 	     "        [-c compression] [-b base-address]                   "



More information about the coreboot-gerrit mailing list