Nico Huber has submitted this change. ( https://review.coreboot.org/c/coreboot/+/41832 )
Change subject: util/cbfstool: Add option --pow2page ......................................................................
util/cbfstool: Add option --pow2page
For add-stage command, --pow2page is equivalent of passing -P log2ceil(sizeof stage). The sizeof stage can be hard to determine in Makefile to be passed on the commandline.
Change-Id: If4b5329c1df5afe49d27ab10220095d747024ad6 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/41832 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Nico Huber nico.h@gmx.de --- M util/cbfstool/cbfstool.c 1 file changed, 20 insertions(+), 2 deletions(-)
Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index decbd05..d2df1cc 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -65,6 +65,7 @@ bool fill_partial_downward; bool show_immutable; bool stage_xip; + bool force_pow2_pagesize; bool autogen_attr; bool machine_parseable; bool unprocessed; @@ -169,6 +170,18 @@
DEBUG("File size is %zd (0x%zx)\n", data_size, data_size);
+ /* Use a page size that can fit the entire file and is no smaller than + optionally provided with -P parameter. */ + if (param.force_pow2_pagesize) { + uint32_t pagesize = 1; + while (pagesize < data_size) + pagesize <<= 1; + while (pagesize < param.pagesize) + pagesize <<= 1; + param.pagesize = pagesize; + DEBUG("Page size is %d (0x%x)\n", param.pagesize, param.pagesize); + } + /* Include cbfs_file size along with space for with name. */ metadata_size += cbfs_calculate_file_header_size(param.name); /* Adjust metadata_size if additional attributes were added */ @@ -1256,7 +1269,7 @@ true, true}, {"add-payload", "H:r:f:n:c:b:C:I:p:vA:gh?", cbfs_add_payload, true, true}, - {"add-stage", "a:H:r:f:n:t:c:b:P:S:p:yvA:gh?", cbfs_add_stage, + {"add-stage", "a:H:r:f:n:t:c:b:P:QS:p:yvA:gh?", cbfs_add_stage, true, true}, {"add-int", "H:r:i:n:b:vgh?", cbfs_add_integer, true, true}, {"add-master-header", "H:r:vh?j:", cbfs_add_master_header, true, true}, @@ -1308,6 +1321,7 @@ {"offset", required_argument, 0, 'o' }, {"padding", required_argument, 0, 'p' }, {"page-size", required_argument, 0, 'P' }, + {"pow2page", no_argument, 0, 'Q' }, {"ucode-region", required_argument, 0, 'q' }, {"size", required_argument, 0, 's' }, {"top-aligned", required_argument, 0, 'T' }, @@ -1402,7 +1416,8 @@ "Add a payload to the ROM\n" " add-stage [-r image,regions] -f FILE -n NAME [-A hash] \\n" " [-c compression] [-b base] [-S section-to-ignore] \\n" - " [-a alignment] [-y|--xip] [-P page-size] [--ibb] " + " [-a alignment] [-P page-size] [-Q|--pow2page] \\n" + " [-y|--xip] [--ibb] " "Add a stage to the ROM\n" " add-flat-binary [-r image,regions] -f FILE -n NAME \\n" " [-A hash] -l load-address -e entry-point \\n" @@ -1661,6 +1676,9 @@ return 1; } break; + case 'Q': + param.force_pow2_pagesize = 1; + break; case 'o': param.cbfsoffset = strtoul(optarg, &suffix, 0); if (!*optarg || (suffix && *suffix)) {