diff options
author | Patrick Georgi <pgeorgi@google.com> | 2015-08-12 09:12:06 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-08-13 16:09:33 +0200 |
commit | edf25d9076de79579bafa1010bb5350c4c992158 (patch) | |
tree | 78b816744d3ad9992a2c6a5acd3c7ed0d40262dc /util/cbfstool/cbfs_image.c | |
parent | 7fd14184fb7cf2a4a713d47b8028155f77a090fc (diff) | |
download | coreboot-edf25d9076de79579bafa1010bb5350c4c992158.tar.xz |
cbfstool: Make cbfs_create_empty_entry build a more complete header
Pass the file type into it instead of creating an entry, then modifying the
header field again after the fact.
Change-Id: I655583218f5085035b0f80efff7f91a66b5b296e
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: http://review.coreboot.org/11218
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'util/cbfstool/cbfs_image.c')
-rw-r--r-- | util/cbfstool/cbfs_image.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index b45969cf9c..b0c3080d80 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -240,7 +240,8 @@ int cbfs_image_create(struct cbfs_image *image, size_t entries_size) size_t capacity = entries_size - empty_header_len; LOG("Created CBFS (capacity = %zu bytes)\n", capacity); - return cbfs_create_empty_entry(entry_header, capacity, ""); + return cbfs_create_empty_entry(entry_header, CBFS_COMPONENT_NULL, + capacity, ""); } int cbfs_legacy_image_create(struct cbfs_image *image, @@ -436,7 +437,8 @@ int cbfs_copy_instance(struct cbfs_image *image, size_t copy_offset, if (last_entry_size < 0) WARN("No room to create the last entry!\n") else - cbfs_create_empty_entry(dst_entry, last_entry_size, ""); + cbfs_create_empty_entry(dst_entry, CBFS_COMPONENT_NULL, + last_entry_size, ""); return 0; } @@ -480,14 +482,14 @@ static int cbfs_add_entry_at(struct cbfs_image *image, if (target - addr > min_entry_size) { DEBUG("|min|...|header|content|... <create new entry>\n"); len = target - addr - min_entry_size; - cbfs_create_empty_entry(entry, len, ""); + cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, len, ""); if (verbose > 1) cbfs_print_entry_info(image, entry, stderr); entry = cbfs_find_next_entry(image, entry); addr = cbfs_get_entry_addr(image, entry); } len = size + (content_offset - addr - header_size); - cbfs_create_empty_entry(entry, len, name); + cbfs_create_empty_entry(entry, type, len, name); if (len != size) { DEBUG("|..|header|content|... <use offset to create entry>\n"); DEBUG("before: offset=0x%x, len=0x%x\n", @@ -501,7 +503,6 @@ static int cbfs_add_entry_at(struct cbfs_image *image, // Ready to fill data into entry. assert(ntohl(entry->len) == size); - entry->type = htonl(type); DEBUG("content_offset: 0x%x, entry location: %x\n", content_offset, (int)((char*)CBFS_SUBHEADER(entry) - image->buffer.data)); @@ -527,7 +528,7 @@ static int cbfs_add_entry_at(struct cbfs_image *image, } len = addr_next - addr - min_entry_size; - cbfs_create_empty_entry(entry, len, ""); + cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, len, ""); if (verbose > 1) cbfs_print_entry_info(image, entry, stderr); return 0; } @@ -583,8 +584,7 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, if (!content_offset || content_offset == addr + header_size) { DEBUG("Filling new entry data (%zd bytes).\n", buffer->size); - cbfs_create_empty_entry(entry, buffer->size, name); - entry->type = htonl(type); + 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); @@ -606,7 +606,8 @@ int cbfs_add_entry(struct cbfs_image *image, struct buffer *buffer, } new_size -= cbfs_calculate_file_header_size(""); DEBUG("new size: %d\n", new_size); - cbfs_create_empty_entry(entry, new_size, ""); + cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, + new_size, ""); if (verbose) cbfs_print_entry_info(image, entry, stderr); return 0; @@ -886,7 +887,7 @@ int cbfs_merge_empty_entry(struct cbfs_image *image, struct cbfs_file *entry, DEBUG("join_empty_entry: combine 0x%x+0x%x and 0x%x+0x%x.\n", cbfs_get_entry_addr(image, entry), ntohl(entry->len), cbfs_get_entry_addr(image, next), ntohl(next->len)); - cbfs_create_empty_entry(entry, + cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, (last_addr - addr - cbfs_calculate_file_header_size("")), ""); @@ -1019,12 +1020,12 @@ 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 cbfs_create_empty_entry(struct cbfs_file *entry, int type, size_t len, const char *name) { memset(entry, CBFS_CONTENT_DEFAULT_VALUE, sizeof(*entry)); memcpy(entry->magic, CBFS_FILE_MAGIC, sizeof(entry->magic)); - entry->type = htonl(CBFS_COMPONENT_NULL); + entry->type = htonl(type); entry->len = htonl(len); entry->attributes_offset = 0; entry->offset = htonl(cbfs_calculate_file_header_size(name)); |