[coreboot] New patch to review for coreboot: 63ea128 cbfstool: Add file alignment for add operations

Stefan Reinauer (stefan.reinauer@coreboot.org) gerrit at coreboot.org
Wed Mar 13 01:09:16 CET 2013


Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2685

-gerrit

commit 63ea12810584e94927a38b86c289d3c64f81a4bd
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Fri Dec 14 16:54:34 2012 -0600

    cbfstool: Add file alignment for add operations
    
    Some CBFS files have alignment requirements because of
    how that data is used at runtime. For example, microcode updates
    need to be 16 byte aligned. Therefore, an alignment option is
    needed. Instead of adding another option for data alignment the
    -b (base address) option is utilizied to provide the alignment.
    If a base address is supplied for a file and the address <= 1024
    the address is treated as an alignment requirement. The data is
    then aligned accordingly.
    
    Since this alignment requirement is not carried through into picking
    the final location it is possible that a large alignment requirement
    may add unnecessary padding between the header and the data.
    
    Change-Id: I84075f2cf90794b0a97f0d0e5dbf7633925c21aa
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 util/cbfstool/common.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index aa98696..3c8dca5 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -632,17 +632,31 @@ void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
 {
 	uint32_t filename_len = ALIGN(strlen(filename) + 1, 16);
 	uint32_t headersize = sizeof(struct cbfs_file) + filename_len;
-	if ((location != 0) && (*location != 0)) {
-		uint32_t offset = *location % align;
-		/* If offset >= (headersize % align), we can stuff the header into the offset.
-		   Otherwise the header has to be aligned itself, and put before the offset data */
-		if (offset >= (headersize % align)) {
-			offset -= (headersize % align);
+
+	if (location != NULL && *location != 0) {
+		/*
+		 * A location of less than or equal 1024 is considered the data
+		 * alignement. The location is then zero'd out so that cbfs
+		 * can place it where ever it finds.
+		 */
+		if (*location <= 1024) {
+			uint32_t data_start = (headersize + align - 1) % align;
+			uint32_t alignment = *location;
+			if ((data_start % alignment) != 0)
+				headersize += (data_start % alignment);
+			*location = 0;
 		} else {
-			offset += align - (headersize % align);
+			uint32_t offset = *location % align;
+			/* If offset >= (headersize % align), we can stuff the header into the offset.
+			   Otherwise the header has to be aligned itself, and put before the offset data */
+			if (offset >= (headersize % align)) {
+				offset -= (headersize % align);
+			} else {
+				offset += align - (headersize % align);
+			}
+			headersize += offset;
+			*location -= headersize;
 		}
-		headersize += offset;
-		*location -= headersize;
 	}
 	void *newdata = malloc(*datasize + headersize);
 	if (!newdata) {



More information about the coreboot mailing list