From d9edb18037cc5bf986d4353f4c014334b2136439 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Tue, 6 Dec 2016 18:55:26 +0100 Subject: [PATCH] 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 Original-Commit-Id: baf378c5f2afdae9946600ef6ff07408a3668fe0 Original-Change-Id: I3752f731f8e6592b1a390ab565aa56e6b7de6765 Original-Signed-off-by: Patrick Georgi Original-Reviewed-on: https://chromium-review.googlesource.com/417319 Original-Commit-Ready: Patrick Georgi Original-Tested-by: Patrick Georgi Original-Reviewed-by: Stefan Reinauer Reviewed-on: https://review.coreboot.org/17787 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- util/cbfstool/cbfstool.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index 2d8483ba0b..7a714275f7 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -91,6 +91,7 @@ static struct param { .hash = VB2_HASH_INVALID, .headeroffset = ~0, .region_name = SECTION_NAME_PRIMARY_CBFS, + .u64val = -1, }; static bool region_is_flashmap(const char *region) @@ -985,8 +986,18 @@ static int cbfs_write(void) buffer_delete(&new_content); return 1; } - WARN("Written area will abut %s of target region: any unused space will keep its current contents\n", - param.fill_partial_upward ? "bottom" : "top"); + if (param.u64val == (uint64_t)-1) { + 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) 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}, {"remove", "H:r:n:vh?", cbfs_remove, 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[] = { @@ -1240,7 +1251,7 @@ static void usage(char *name) "Show the contents of the ROM\n" " extract [-r image,regions] [-m ARCH] -n NAME -f FILE " "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" " read [-r fmap-region] -f file " "Extract raw region contents into binary file\n"