summaryrefslogtreecommitdiff
path: root/util/cbfstool
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool')
-rw-r--r--util/cbfstool/cbfs_image.c38
-rw-r--r--util/cbfstool/cbfs_image.h4
-rw-r--r--util/cbfstool/cbfstool.c17
3 files changed, 59 insertions, 0 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 1f4b49a48d..92815f5f06 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -442,6 +442,44 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
return 0;
}
+int cbfs_expand_to_region(struct buffer *region)
+{
+ if (buffer_get(region) == NULL)
+ return 1;
+
+ struct cbfs_image image;
+ memset(&image, 0, sizeof(image));
+ if (cbfs_image_from_buffer(&image, region, 0)) {
+ ERROR("reading CBFS failed!\n");
+ return 1;
+ }
+
+ uint32_t region_sz = buffer_size(region);
+
+ struct cbfs_file *entry;
+ for (entry = buffer_get(region);
+ cbfs_is_valid_entry(&image, entry);
+ entry = cbfs_find_next_entry(&image, entry)) {
+ /* just iterate through */
+ }
+
+ /* entry now points to the first aligned address after the last valid
+ * file header. That's either outside the image or exactly the place
+ * where we need to create a new file.
+ */
+ int last_entry_size = region_sz - ((void *)entry - buffer_get(region))
+ - cbfs_calculate_file_header_size("") - sizeof(int32_t);
+
+ if (last_entry_size > 0) {
+ cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL,
+ last_entry_size, "");
+ /* If the last entry was an empty file, merge them. */
+ cbfs_walk(&image, cbfs_merge_empty_entry, NULL);
+ }
+
+ return 0;
+}
+
static size_t cbfs_file_entry_metadata_size(const struct cbfs_file *f)
{
return ntohl(f->offset);
diff --git a/util/cbfstool/cbfs_image.h b/util/cbfstool/cbfs_image.h
index 0d7877a7cc..1bd74cedd1 100644
--- a/util/cbfstool/cbfs_image.h
+++ b/util/cbfstool/cbfs_image.h
@@ -80,6 +80,10 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst);
* beginning of the image. Returns 0 on success, otherwise non-zero. */
int cbfs_compact_instance(struct cbfs_image *image);
+/* Expand a CBFS image inside an fmap region to the entire region's space.
+ Returns 0 on success, otherwise non-zero. */
+int cbfs_expand_to_region(struct buffer *region);
+
/* Releases the CBFS image. Returns 0 on success, otherwise non-zero. */
int cbfs_image_delete(struct cbfs_image *image);
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c
index cc317515f7..5e7d904151 100644
--- a/util/cbfstool/cbfstool.c
+++ b/util/cbfstool/cbfstool.c
@@ -1107,6 +1107,20 @@ static int cbfs_compact(void)
return cbfs_compact_instance(&image);
}
+static int cbfs_expand(void)
+{
+ struct buffer src_buf;
+
+ /* Obtain the source region. */
+ if (!partitioned_file_read_region(&src_buf, param.image_file,
+ param.region_name)) {
+ ERROR("Region not found in image: %s\n", param.source_region);
+ return 1;
+ }
+
+ return cbfs_expand_to_region(param.image_region);
+}
+
static const struct command commands[] = {
{"add", "H:r:f:n:t:c:b:a:yvA:gh?", cbfs_add, true, true},
{"add-flat-binary", "H:r:f:n:l:e:c:b:vA:gh?", cbfs_add_flat_binary,
@@ -1127,6 +1141,7 @@ static const struct command commands[] = {
{"remove", "H:r:n:vh?", cbfs_remove, true, true},
{"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, true},
{"write", "r:f:i:Fudvh?", cbfs_write, true, true},
+ {"expand", "r:h?", cbfs_expand, true, true},
};
static struct option long_options[] = {
@@ -1276,6 +1291,8 @@ static void usage(char *name)
"Write file into same-size [or larger] raw region\n"
" read [-r fmap-region] -f file "
"Extract raw region contents into binary file\n"
+ " expand [-r fmap-region] "
+ "Expand CBFS to span entire region\n"
" update-fit [-r image,regions] -n MICROCODE_BLOB_NAME \\\n"
" -x EMTPY_FIT_ENTRIES "
"Updates the FIT table with microcode entries\n"