util/cbfstool: Enable filling fmap regions with a given value

So far, cbfstool write, when used with the -u/-d options (to "fill
upwards/downwards") left the parts of the region alone for which there
was no new data to write.

When adding -i [0..255], these parts are overwritten with the given
value.

BUG=chromium:595715
BRANCH=none
TEST=cbfstool write -u -i 0 ... does the right thing (fill the unused
space with zeroes)

Change-Id: I1b1c0eeed2862bc9fe5f66caae93b08fe21f465c
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: baf378c5f2afdae9946600ef6ff07408a3668fe0
Original-Change-Id: I3752f731f8e6592b1a390ab565aa56e6b7de6765
Original-Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/417319
Original-Commit-Ready: Patrick Georgi <pgeorgi@chromium.org>
Original-Tested-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
Reviewed-on: https://review.coreboot.org/17787
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
This commit is contained in:
Patrick Georgi 2016-12-06 18:55:26 +01:00
parent 2c34e743a1
commit d9edb18037
1 changed files with 15 additions and 4 deletions

View File

@ -91,6 +91,7 @@ static struct param {
.hash = VB2_HASH_INVALID, .hash = VB2_HASH_INVALID,
.headeroffset = ~0, .headeroffset = ~0,
.region_name = SECTION_NAME_PRIMARY_CBFS, .region_name = SECTION_NAME_PRIMARY_CBFS,
.u64val = -1,
}; };
static bool region_is_flashmap(const char *region) static bool region_is_flashmap(const char *region)
@ -985,8 +986,18 @@ static int cbfs_write(void)
buffer_delete(&new_content); buffer_delete(&new_content);
return 1; return 1;
} }
WARN("Written area will abut %s of target region: any unused space will keep its current contents\n", if (param.u64val == (uint64_t)-1) {
param.fill_partial_upward ? "bottom" : "top"); WARN("Written area will abut %s of target region: any unused space will keep its current contents\n",
param.fill_partial_upward ? "bottom" : "top");
} else if (param.u64val > 0xff) {
ERROR("given fill value (%x) is larger than a byte\n", (unsigned)(param.u64val & 0xff));
buffer_delete(&new_content);
return 1;
} else {
memset(buffer_get(param.image_region),
param.u64val & 0xff,
buffer_size(param.image_region));
}
if (param.fill_partial_downward) if (param.fill_partial_downward)
offset = param.image_region->size - new_content.size; offset = param.image_region->size - new_content.size;
} }
@ -1094,7 +1105,7 @@ static const struct command commands[] = {
{"read", "r:f:vh?", cbfs_read, true, false}, {"read", "r:f:vh?", cbfs_read, true, false},
{"remove", "H:r:n:vh?", cbfs_remove, true, true}, {"remove", "H:r:n:vh?", cbfs_remove, true, true},
{"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, true}, {"update-fit", "H:r:n:x:vh?", cbfs_update_fit, true, true},
{"write", "r:f:Fudvh?", cbfs_write, true, true}, {"write", "r:f:i:Fudvh?", cbfs_write, true, true},
}; };
static struct option long_options[] = { static struct option long_options[] = {
@ -1240,7 +1251,7 @@ static void usage(char *name)
"Show the contents of the ROM\n" "Show the contents of the ROM\n"
" extract [-r image,regions] [-m ARCH] -n NAME -f FILE " " extract [-r image,regions] [-m ARCH] -n NAME -f FILE "
"Extracts a raw payload from ROM\n" "Extracts a raw payload from ROM\n"
" write [-F] -r image,regions -f file [-u | -d] " " write [-F] -r image,regions -f file [-u | -d] [-i int] "
"Write file into same-size [or larger] raw region\n" "Write file into same-size [or larger] raw region\n"
" read [-r fmap-region] -f file " " read [-r fmap-region] -f file "
"Extract raw region contents into binary file\n" "Extract raw region contents into binary file\n"