summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPatrick Georgi <pgeorgi@chromium.org>2015-07-15 16:42:38 +0200
committerPatrick Georgi <pgeorgi@google.com>2015-07-16 17:38:38 +0200
commitc569b8bfdc012be61118bc92e86ddbbf2f804b78 (patch)
treea0d129467fa8cc6715e6de416825a1621b643ab3 /util
parent5dc01ac5067abe6da340d8eadcb3b2aed8ab6fa7 (diff)
cbfstool: use variable length array to model cbfs_file's filename
Change-Id: Ib056983630b2899d7e6cbcb43f6b7153f0f8e282 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-on: http://review.coreboot.org/10928 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'util')
-rw-r--r--util/cbfstool/cbfs.h2
-rw-r--r--util/cbfstool/cbfs_image.c12
2 files changed, 7 insertions, 7 deletions
diff --git a/util/cbfstool/cbfs.h b/util/cbfstool/cbfs.h
index 6286effb10..1996b1c658 100644
--- a/util/cbfstool/cbfs.h
+++ b/util/cbfstool/cbfs.h
@@ -77,6 +77,7 @@ struct cbfs_file {
uint32_t checksum;
/* length of header incl. variable data */
uint32_t offset;
+ char filename[];
} __PACKED;
_Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch");
@@ -140,7 +141,6 @@ struct cbfs_payload {
*/
#define CBFS_COMPONENT_NULL 0xFFFFFFFF
-#define CBFS_NAME(_c) (((char *) (_c)) + sizeof(struct cbfs_file))
#define CBFS_SUBHEADER(_p) ( (void *) ((((uint8_t *) (_p)) + ntohl((_p)->offset))) )
/* cbfs_image.c */
uint32_t get_cbfs_entry_type(const char *name, uint32_t default_value);
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 2ce4bdd572..783999ce9b 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -641,7 +641,7 @@ struct cbfs_file *cbfs_get_entry(struct cbfs_image *image, const char *name)
for (entry = cbfs_find_first_entry(image);
entry && cbfs_is_valid_entry(image, entry);
entry = cbfs_find_next_entry(image, entry)) {
- if (strcasecmp(CBFS_NAME(entry), name) == 0) {
+ if (strcasecmp(entry->filename, name) == 0) {
DEBUG("cbfs_get_entry: found %s\n", name);
return entry;
}
@@ -692,13 +692,13 @@ int cbfs_remove_entry(struct cbfs_image *image, const char *name)
next = cbfs_find_next_entry(image, entry);
assert(next);
DEBUG("cbfs_remove_entry: Removed %s @ 0x%x\n",
- CBFS_NAME(entry), cbfs_get_entry_addr(image, entry));
+ entry->filename, cbfs_get_entry_addr(image, entry));
entry->type = htonl(CBFS_COMPONENT_DELETED);
len = (cbfs_get_entry_addr(image, next) -
cbfs_get_entry_addr(image, entry));
entry->offset = htonl(cbfs_calculate_file_header_size(""));
entry->len = htonl(len - ntohl(entry->offset));
- memset(CBFS_NAME(entry), 0, ntohl(entry->offset) - sizeof(*entry));
+ memset(entry->filename, 0, ntohl(entry->offset) - sizeof(*entry));
memset(CBFS_SUBHEADER(entry), CBFS_CONTENT_DEFAULT_VALUE,
ntohl(entry->len));
return 0;
@@ -787,7 +787,7 @@ static int cbfs_print_decoded_payload_segment_info(
int cbfs_print_entry_info(struct cbfs_image *image, struct cbfs_file *entry,
void *arg)
{
- const char *name = CBFS_NAME(entry);
+ const char *name = entry->filename;
struct cbfs_payload_segment *payload;
FILE *fp = (FILE *)arg;
@@ -1025,8 +1025,8 @@ int cbfs_create_empty_entry(struct cbfs_file *entry,
entry->len = htonl(len);
entry->checksum = 0; // TODO Build a checksum algorithm.
entry->offset = htonl(cbfs_calculate_file_header_size(name));
- memset(CBFS_NAME(entry), 0, ntohl(entry->offset) - sizeof(*entry));
- strcpy(CBFS_NAME(entry), name);
+ memset(entry->filename, 0, ntohl(entry->offset) - sizeof(*entry));
+ strcpy(entry->filename, name);
memset(CBFS_SUBHEADER(entry), CBFS_CONTENT_DEFAULT_VALUE, len);
return 0;
}