Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11222
-gerrit
commit 25c5e0cb6f858f79a8d365eaaea9bd83843a1204
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Wed Aug 12 12:29:20 2015 +0200
cbfstool: unify actual file creation
After the preparation in earlier commits, it is now possible to handle the
more general case of position independent files using the special code path
for fixed location files.
This leads to a single place where non-empty cbfs file headers are actually
written into the image, allowing us to move it up the chain more easily.
Change-Id: I8c1fca5e4e81c20971b2960c87690e982aa3e274
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfs_image.c | 37 +++++--------------------------------
1 file changed, 5 insertions(+), 32 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 168c966..51cfd03 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -546,7 +546,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
uint32_t entry_type;
uint32_t addr, addr_next;
struct cbfs_file *entry, *next;
- uint32_t need_size, new_size;
+ uint32_t need_size;
if (header_size == 0)
header_size = cbfs_calculate_file_header_size(name);
@@ -600,37 +600,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
// TODO there are more few tricky cases that we may
// want to fit by altering offset.
- // Can we simply put object here?
- if (!content_offset || content_offset == addr + header_size) {
- DEBUG("Filling new entry data (%zd bytes).\n",
- buffer->size);
- cbfs_create_empty_entry(entry, type, buffer->size, name);
- memcpy(CBFS_SUBHEADER(entry), buffer->data, buffer->size);
- if (verbose)
- cbfs_print_entry_info(image, entry, stderr);
-
- // setup new entry
- DEBUG("Setting new empty entry.\n");
- entry = cbfs_find_next_entry(image, entry);
- new_size = (cbfs_get_entry_addr(image, next) -
- cbfs_get_entry_addr(image, entry));
-
- /* Entry was added and no space for new "empty" entry */
- if (new_size < cbfs_calculate_file_header_size("")) {
- DEBUG("No need for new \"empty\" entry\n");
- /* No need to increase the size of the just
- * stored file to extend to next file. Alignment
- * of next file takes care of this.
- */
- return 0;
- }
- new_size -= cbfs_calculate_file_header_size("");
- DEBUG("new size: %d\n", new_size);
- cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL,
- new_size, "");
- if (verbose)
- cbfs_print_entry_info(image, entry, stderr);
- return 0;
+ if (content_offset == 0) {
+ // we tested every condition earlier under which
+ // placing the file there might fail
+ content_offset = addr + header_size;
}
DEBUG("section 0x%x+0x%x for content_offset 0x%x.\n",
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11221
-gerrit
commit 0ee6581ca97e8a3786447be060a166e7a0d6a1b4
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Wed Aug 12 12:05:21 2015 +0200
cbfstool: move tests for fixed-location files earlier
... and the assert is gone.
The actual action of adding a just-right file can be moved after the tests
since it's exactly the condition those tests don't continue or break on.
Change-Id: I6d0e829e0158198301136ada9a0de2f168ceee3f
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfs_image.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index d7d4acf..168c966 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -580,6 +580,26 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
if (addr + need_size > addr_next)
continue;
+ // Test for complicated cases
+ if (content_offset > 0) {
+ if (addr_next < content_offset) {
+ DEBUG("Not for specified offset yet");
+ continue;
+ } else if (addr > content_offset) {
+ DEBUG("Exceed specified content_offset.");
+ break;
+ } else if (addr + header_size > content_offset) {
+ ERROR("Not enough space for header.\n");
+ break;
+ } else if (content_offset + buffer->size > addr_next) {
+ ERROR("Not enough space for content.\n");
+ break;
+ }
+ }
+
+ // TODO there are more few tricky cases that we may
+ // want to fit by altering offset.
+
// Can we simply put object here?
if (!content_offset || content_offset == addr + header_size) {
DEBUG("Filling new entry data (%zd bytes).\n",
@@ -613,27 +633,6 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
return 0;
}
- // We need to put content here, and the case is really
- // complicated...
- assert(content_offset);
- if (content_offset > 0) {
- if (addr_next < content_offset) {
- DEBUG("Not for specified offset yet");
- continue;
- } else if (addr > content_offset) {
- DEBUG("Exceed specified content_offset.");
- break;
- } else if (addr + header_size > content_offset) {
- ERROR("Not enough space for header.\n");
- break;
- } else if (content_offset + buffer->size > addr_next) {
- ERROR("Not enough space for content.\n");
- break;
- }
- }
-
- // TODO there are more few tricky cases that we may
- // want to fit by altering offset.
DEBUG("section 0x%x+0x%x for content_offset 0x%x.\n",
addr, addr_next - addr, content_offset);
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11220
-gerrit
commit 70c582240dc083136fb86024dfd9b00d49ad146b
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Wed Aug 12 12:01:01 2015 +0200
cbfstool: prepare moving tests earlier
The assert() makes sure the if() holds true. But that assert won't survive for
long.
Change-Id: Iab7d2bc7bfebb3f3b3ce70dc5bd041902e14bd7a
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfs_image.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 077f20f..d7d4acf 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -616,18 +616,20 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
// We need to put content here, and the case is really
// complicated...
assert(content_offset);
- if (addr_next < content_offset) {
- DEBUG("Not for specified offset yet");
- continue;
- } else if (addr > content_offset) {
- DEBUG("Exceed specified content_offset.");
- break;
- } else if (addr + header_size > content_offset) {
- ERROR("Not enough space for header.\n");
- break;
- } else if (content_offset + buffer->size > addr_next) {
- ERROR("Not enough space for content.\n");
- break;
+ if (content_offset > 0) {
+ if (addr_next < content_offset) {
+ DEBUG("Not for specified offset yet");
+ continue;
+ } else if (addr > content_offset) {
+ DEBUG("Exceed specified content_offset.");
+ break;
+ } else if (addr + header_size > content_offset) {
+ ERROR("Not enough space for header.\n");
+ break;
+ } else if (content_offset + buffer->size > addr_next) {
+ ERROR("Not enough space for content.\n");
+ break;
+ }
}
// TODO there are more few tricky cases that we may
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11219
-gerrit
commit 936c8dcb4e3d3f95f783a90ccf497fe3153e5211
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Wed Aug 12 09:20:11 2015 +0200
cbfstool: factor out creating a cbfs file header
We will want to create headers that live outside the final image at some point
(eg. to build the file before we even know where to place it).
Change-Id: Ie4c0323df8d5be955aec3621b75309e8f11fae49
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfs_image.c | 16 ++++++++++++++--
util/cbfstool/cbfs_image.h | 4 ++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index b0c3080..077f20f 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -1020,10 +1020,14 @@ int cbfs_is_valid_entry(struct cbfs_image *image, struct cbfs_file *entry)
strlen(CBFS_FILE_MAGIC));
}
-int cbfs_create_empty_entry(struct cbfs_file *entry, int type,
+struct cbfs_file *cbfs_create_file_header(int type,
size_t len, const char *name)
{
- memset(entry, CBFS_CONTENT_DEFAULT_VALUE, sizeof(*entry));
+ // assume that there won't be file names of ~1000 bytes
+ const int bufsize = 1024;
+
+ struct cbfs_file *entry = malloc(bufsize);
+ memset(entry, CBFS_CONTENT_DEFAULT_VALUE, bufsize);
memcpy(entry->magic, CBFS_FILE_MAGIC, sizeof(entry->magic));
entry->type = htonl(type);
entry->len = htonl(len);
@@ -1031,6 +1035,14 @@ int cbfs_create_empty_entry(struct cbfs_file *entry, int type,
entry->offset = htonl(cbfs_calculate_file_header_size(name));
memset(entry->filename, 0, ntohl(entry->offset) - sizeof(*entry));
strcpy(entry->filename, name);
+ return entry;
+}
+
+int cbfs_create_empty_entry(struct cbfs_file *entry, int type,
+ size_t len, const char *name)
+{
+ struct cbfs_file *tmp = cbfs_create_file_header(type, len, name);
+ memcpy(entry, tmp, ntohl(tmp->offset));
memset(CBFS_SUBHEADER(entry), CBFS_CONTENT_DEFAULT_VALUE, len);
return 0;
}
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index ad999e3..5b27234 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -99,6 +99,10 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer,
/* Removes an entry from CBFS image. Returns 0 on success, otherwise non-zero. */
int cbfs_remove_entry(struct cbfs_image *image, const char *name);
+/* Create a new cbfs file header structure to work with */
+struct cbfs_file *cbfs_create_file_header(int type, size_t len,
+ const char *name);
+
/* Initializes a new empty (type = NULL) entry with size and name in CBFS image.
* Returns 0 on success, otherwise (ex, not found) non-zero. */
int cbfs_create_empty_entry(struct cbfs_file *entry, int type,
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11215
-gerrit
commit 034691130db1e4d89d8f50b3992cd37689bb7769
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Tue Aug 11 15:10:33 2015 +0200
cbfstool: calculate header size in cbfs_add_component()
It will at some point create the header, and pass it with its size. We can
start with the size already.
Change-Id: I8f26b2335ffab99a664d1ff7bc88e33ed62cf9ca
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfstool.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index 80e3895..57db97c 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -201,6 +201,8 @@ static int cbfs_add_component(const char *filename,
return 1;
}
+ uint32_t header_size = cbfs_calculate_file_header_size(name);
+
if (convert && convert(&buffer, &offset) != 0) {
ERROR("Failed to parse file '%s'.\n", filename);
buffer_delete(&buffer);
@@ -211,7 +213,8 @@ static int cbfs_add_component(const char *filename,
offset = convert_to_from_top_aligned(param.image_region,
-offset);
- if (cbfs_add_entry(&image, &buffer, name, type, offset, 0) != 0) {
+ if (cbfs_add_entry(&image, &buffer, name, type, offset, header_size)
+ != 0) {
ERROR("Failed to add '%s' into ROM image.\n", filename);
buffer_delete(&buffer);
return 1;
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/11214
-gerrit
commit fc8df329ffff04b7f393044c37d723f639892743
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Tue Aug 11 15:10:02 2015 +0200
cbfstool: expose cbfs_calculate_file_header_size()
Headers vary in size soon, and more places need to be able to calculate their
size.
Change-Id: I30761bb9da0756418993dee21d8fa18cf3174c40
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
util/cbfstool/cbfs_image.c | 2 +-
util/cbfstool/cbfs_image.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index e78ee40..ed065b0 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -112,7 +112,7 @@ int cbfs_parse_comp_algo(const char *name)
/* CBFS image */
-static size_t cbfs_calculate_file_header_size(const char *name)
+size_t cbfs_calculate_file_header_size(const char *name)
{
return (sizeof(struct cbfs_file) +
align_up(strlen(name) + 1, CBFS_FILENAME_ALIGN));
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 907be61..ecd7db7 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -164,4 +164,6 @@ int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry,
void *arg);
+/* Returns the size of a cbfs file header with no extensions */
+size_t cbfs_calculate_file_header_size(const char *name);
#endif