Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/40376 )
Change subject: util/cbfstool: Add support for filling ID region using FMAP ......................................................................
util/cbfstool: Add support for filling ID region using FMAP
This change adds a new command add-id which takes as input the following parameters: 1. ID_FMAP_REGION: Name of the FMAP region used for storing ID (coreboot build details) 2. VERSION: Coreboot version provided by the build system. 3. VENDOR: Vendor name provided by the build system. 4. PART_NUM: Part number provided by the build system.
Using the above parameters, this new command finds the fmap region using ID_FMAP_REGION and copies version, vendor and part number strings into the ID region.
This allows us to get rid of all the id.ld and id.S files that are currently added in coreboot to supply build details into the bootblock or decompressor binary.
This command makes use of non-ASCII longopts since we are running out of good opt characters to use.
Signed-off-by: Furquan Shaikh furquan@google.com Change-Id: Ic5c55a49025508ff1f27c6f48d8e420f19d88ec2 --- M util/cbfstool/cbfstool.c 1 file changed, 60 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/76/40376/1
diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index f15c65b..224672c 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -93,6 +93,9 @@ char *initrd; char *cmdline; int force; + const char *id_version; + const char *id_vendor; + const char *id_part_num; } param = { /* All variables not listed are initialized as zero. */ .arch = CBFS_ARCHITECTURE_UNKNOWN, @@ -1270,6 +1273,44 @@ return result; }
+static int id_str_write(struct buffer *buff, const char *str) +{ + size_t len = strlen(str) + 1; + if (buffer_size(buff) < len) { + ERROR("Not enough space for string in %s\n", param.region_name); + return 1; + } + + strcpy(buffer_get(buff), str); + buffer_seek(buff, len); + return 0; +} + +static int cbfs_add_id(void) +{ + if (!param.id_version || !param.id_vendor || !param.id_part_num) { + ERROR("All ID params (version, vendor and part_num) are mandatory\n"); + return 1; + } + + printf("FUR: %s %s %s\n", param.id_version, param.id_vendor, param.id_part_num); + + struct buffer id_buffer; + + buffer_clone(&id_buffer, param.image_region); + + if (id_str_write(&id_buffer, param.id_version)) + return 1; + + if (id_str_write(&id_buffer, param.id_vendor)) + return 1; + + if (id_str_write(&id_buffer, param.id_part_num)) + return 1; + + return 0; +} + static const struct command commands[] = { {"add", "H:r:f:n:t:c:b:a:p:yvA:j:gh?", cbfs_add, true, true}, {"add-flat-binary", "H:r:f:n:l:e:c:b:p:vA:gh?", cbfs_add_flat_binary, @@ -1280,6 +1321,7 @@ 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}, + {"add-id", "r:h?", cbfs_add_id, true, true}, {"compact", "r:h?", cbfs_compact, true, true}, {"copy", "r:R:h?", cbfs_copy, true, true}, {"create", "M:r:s:B:b:H:o:m:vh?", cbfs_create, true, true}, @@ -1297,6 +1339,9 @@ /* begin after ASCII characters */ LONGOPT_START = 256, LONGOPT_IBB = LONGOPT_START, + LONGOPT_ID_VERSION, + LONGOPT_ID_VENDOR, + LONGOPT_ID_PART_NUM, LONGOPT_END, };
@@ -1339,6 +1384,9 @@ {"mach-parseable",no_argument, 0, 'k' }, {"unprocessed", no_argument, 0, 'U' }, {"ibb", no_argument, 0, LONGOPT_IBB }, + {"id-version", required_argument, 0, LONGOPT_ID_VERSION }, + {"id-vendor", required_argument, 0, LONGOPT_ID_VENDOR }, + {"id-part-num", required_argument, 0, LONGOPT_ID_PART_NUM }, {NULL, 0, 0, 0 } };
@@ -1433,6 +1481,9 @@ " add-master-header [-r image,regions] \ \n" " [-j topswap-size] (Intel CPUs only) " "Add a legacy CBFS master header\n" + " add-id -r ID_FMAP_REGION --id-version VERSION \\n" + " --id-vendor VENDOR --id-part-num PART_NUM " + "Add build details to ID FMAP region\n" " remove [-r image,regions] -n NAME " "Remove a component\n" " compact -r image,regions " @@ -1752,6 +1803,15 @@ case LONGOPT_IBB: param.ibb = true; break; + case LONGOPT_ID_VERSION: + param.id_version = optarg; + break; + case LONGOPT_ID_VENDOR: + param.id_vendor = optarg; + break; + case LONGOPT_ID_PART_NUM: + param.id_part_num = optarg; + break; case 'h': case '?': usage(argv[0]);