diff options
author | Patrick Georgi <pgeorgi@google.com> | 2015-08-12 09:20:11 +0200 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-08-13 16:09:52 +0200 |
commit | 57edf16be5ddef5da272ff8e1a9f1d78091377d9 (patch) | |
tree | e5270e2260593920656d0d3ad0b7887b1affa3d5 | |
parent | edf25d9076de79579bafa1010bb5350c4c992158 (diff) |
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@google.com>
Reviewed-on: http://review.coreboot.org/11219
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | util/cbfstool/cbfs_image.c | 17 | ||||
-rw-r--r-- | util/cbfstool/cbfs_image.h | 5 |
2 files changed, 20 insertions, 2 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index b0c3080d80..ddc9cf5366 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,15 @@ 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)); + free(tmp); 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 ad999e357d..432ea72cea 100644 --- a/util/cbfstool/cbfs_image.h +++ b/util/cbfstool/cbfs_image.h @@ -99,6 +99,11 @@ 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. + Returns newly allocated memory that the caller needs to free after use. */ +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, |