From patchwork Mon Feb 12 07:47:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 772040 Delivered-To: patch@linaro.org Received: by 2002:adf:9dca:0:b0:33b:4db1:f5b3 with SMTP id q10csp2000925wre; Sun, 11 Feb 2024 23:50:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGY7FR6xkNvX0SUmy3hdfBY+Dii4kntrhfN1pPuQMS75+x46TIMpqUhJlS562sFOYG/rzil X-Received: by 2002:a05:6402:3118:b0:561:8452:3634 with SMTP id dc24-20020a056402311800b0056184523634mr2709762edb.36.1707724239247; Sun, 11 Feb 2024 23:50:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707724239; cv=none; d=google.com; s=arc-20160816; b=M8VPiEioY9uCSXFUwUTMW/DBKOjbl6trxcnCxNvwK/DqyE9ZDMwuE9V/D4rBOyTHqx r0jwpL8SiQkvcapsJlVjiBlX/Eq5qNNl2qF5TIo9vDBkgbjCntXQps4+eoSxID/D7+m8 S9ayWLBxGtL2zG1F83J2Ii3+W2hfhZkLfYiU0zkFzWEuoFSVe3ixZx4myjcU9QqggNTG DT5wCY4P8gkw4YKG9Ycx/AVZeiS0H1pWKBd1dnNlvFskQq+whF+vMB7VWwq+yo7wdsBv ue73t1EXABuJmoiY9rrRMKZNtFKdt9Hf62YNvRq3ZAB1ztDmwMHZyQbqCPT9UrsHCs7e Kj2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=dp203O8EndYo+Zs7a9rRbaZIAbCKOmpbXXqzCxcDwJ0=; fh=6d7uZNGxCDYKtszZs2IIDnmbLiCE2GbDjDyd8931oJE=; b=yQPQxqfM6pWEMGmRKIKvk8M9Odt4gESfQaLSnDb+zCUiTj1O/6KHotkBlfdSDVBDDf pj6yPl9R6rsB+0h9uwTRnPJa9QqC1X7c4x9Uk9sGDcZ/8vzFktyyN5TvHGTLXBksJpQk 40C2C5llhHBROb25vELOzm/6v1K/NIR0k2EU0nYuOOUqYXeIJtU/Qp5IKZikpqOrmvKU 9naueZqta/6UHokkiYwA44ha82Sixj2NLRV0lUsbe6tE2ZggZJBdQ8Jy5Oo4lkH4/Pv3 jpuFuC0AtUcySBtTMtC3o6SKuu0bJnm6/yg1SkduzauqEUsnL0RRXJBAvDuWKMlQi6aG 9YAA==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCXn9dEhWZYXYCQAgI3rly50PXR9f4JvmD3Y8nfWmgTLVmoH9XYXyAQWDPuej/hNiFRcjSHCCPWURuK4Mq2khtaWp0VnXq6iv1SH8sAo6Tw3G3jlxj5tUDS7S8txqRgalRAxObWY72quvT/DjPhcJqm5zp7KX6bYJOfimQGaBzHg8L4bC77NSZvWUN+hAHDIGck8sZDZwxHhUB1pakb+5MSBppsnkDxLRmAbfOyt1zqtq1MXNiJ+9b6vA1yxa9c2IhUA9UozP/HUKTFyA3+Be2qFYrIXS+EcJicLhXrkxMbkYY8N7hKwRZnsr9WDfRH0Md9QbO2DJxERvHKwsnasLFO6Ic3gNGcpXImJfVzJ12rsVc6HJKapjsVcF1c86FCx7NJI6FBsYn7DiLQj65YluZmkV1jmaK7GoXymKmTo71bwlI9kdgh0LXP5oM9NRrV9J9UlNt6C/P2b+8lIr9t/afftYoWHGgVCCp17QA1OktWxQg0SOQ+x5uHDc0oW6Tb9eOqiS3oxBgAqtWgtkIpCCXJUcRoYeZV30Wr95jclHrYndEeoOcOCwpP92oL8lKzEHu9mD6Qa3WIHijFp4CeMjyfG/N83dH69BRRMnNGV1UJHFlcUgQ+xJTzyZqXrC9iZBDqNZCHrEEtqVwgiHUxvK7HnofVP7aXKMvRYoLfidYZcnRuMp2x661gy7ZxxXqSUzWuh6XXk8/Hks/b4b/UOC9ST4yYVZn7B/SdEAURgmY/sYuHjryuoccVO7RMlhn3qGmeT27GzbKdT1ZidDJKIU8mAPvjpZjRZctW8wniMu8LyVM7j5FIoALV/Tmbfqj33bYefPwklAuySGFsl2RHCas5dSlxHGLNsh84nQieRC0O+n2w= Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id cz21-20020a0564021cb500b00560a8f116cfsi2585023edb.154.2024.02.11.23.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:50:39 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C57487F14; Mon, 12 Feb 2024 08:48:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 3D31F87F0C; Mon, 12 Feb 2024 08:48:44 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 0C4C487EF9 for ; Mon, 12 Feb 2024 08:48:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 18F2EDA7; Sun, 11 Feb 2024 23:49:23 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C23E3F762; Sun, 11 Feb 2024 23:48:38 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Patrice Chotard , Patrick Delaunay , Yann Gautier , Etienne Carriere , Michal Simek , Jassi Brar , Sughosh Ganu Subject: [PATCH v2 18/21] tools: mkfwumdata: add logic to append vendor data to the FWU metadata Date: Mon, 12 Feb 2024 13:17:09 +0530 Message-Id: <20240212074712.3657076-19-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212074712.3657076-1-sughosh.ganu@linaro.org> References: <20240212074712.3657076-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The version 2 of the FWU metadata allows for appending opaque vendor specific data to the metadata structure. Add support for appending this data to the metadata. The vendor specific data needs to be provided through a file, passed through a command-line parameter. Signed-off-by: Sughosh Ganu Tested-by: Michal Simek --- Changes since V1: New patch tools/mkfwumdata.c | 85 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/tools/mkfwumdata.c b/tools/mkfwumdata.c index fb847e3a78..ab07623e25 100644 --- a/tools/mkfwumdata.c +++ b/tools/mkfwumdata.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include /* Since we can not include fwu.h, redefine version here. */ @@ -30,7 +32,7 @@ typedef uint64_t u64; #include -static const char *opts_short = "b:i:a:p:gh"; +static const char *opts_short = "b:i:a:p:v:gh"; static struct option options[] = { {"banks", required_argument, NULL, 'b'}, @@ -38,6 +40,7 @@ static struct option options[] = { {"guid", required_argument, NULL, 'g'}, {"active-bank", required_argument, NULL, 'a'}, {"previous-bank", required_argument, NULL, 'p'}, + {"vendor-file", required_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}, }; @@ -51,6 +54,7 @@ static void print_usage(void) "\t-a, --active-bank Active bank (default=0)\n" "\t-p, --previous-bank Previous active bank (default=active_bank - 1)\n" "\t-g, --guid Use GUID instead of UUID\n" + "\t-v, --vendor-file Vendor data file to append to the metadata\n" "\t-h, --help print a help message\n" ); fprintf(stderr, " UUIDs list syntax:\n" @@ -69,13 +73,16 @@ struct fwu_mdata_object { size_t images; size_t banks; size_t size; + size_t vsize; + void *vbuf; struct fwu_mdata *mdata; }; static int previous_bank, active_bank; static bool __use_guid; -static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks) +static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks, + size_t vendor_size) { struct fwu_mdata_object *mobj; @@ -87,16 +94,28 @@ static struct fwu_mdata_object *fwu_alloc_mdata(size_t images, size_t banks) sizeof(struct fwu_fw_store_desc) + (sizeof(struct fwu_image_entry) + sizeof(struct fwu_image_bank_info) * banks) * images; + + mobj->size += vendor_size; + mobj->vsize = vendor_size; mobj->images = images; mobj->banks = banks; mobj->mdata = calloc(1, mobj->size); - if (!mobj->mdata) { - free(mobj); - return NULL; + if (!mobj->mdata) + goto alloc_err; + + if (vendor_size) { + mobj->vbuf = calloc(1, mobj->vsize); + if (!mobj->vbuf) + goto alloc_err; } return mobj; + +alloc_err: + free(mobj->mdata); + free(mobj); + return NULL; } static struct fwu_image_entry * @@ -223,6 +242,7 @@ static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) { struct fwu_mdata *mdata = mobj->mdata; struct fwu_fw_store_desc *fw_desc; + char *vdata; int i, ret; mdata->version = FWU_MDATA_VERSION; @@ -249,23 +269,65 @@ static int fwu_parse_fill_uuids(struct fwu_mdata_object *mobj, char *uuids[]) return ret; } + if (mobj->vsize) { + vdata = (char *)mobj->mdata + (mobj->size - mobj->vsize); + memcpy(vdata, mobj->vbuf, mobj->vsize); + } + mdata->crc32 = crc32(0, (const unsigned char *)&mdata->version, mobj->size - sizeof(uint32_t)); return 0; } +static int fwu_read_vendor_data(struct fwu_mdata_object *mobj, + const char *vendor_file) +{ + int ret = 0; + FILE *vfile = NULL; + + vfile = fopen(vendor_file, "r"); + if (!vfile) { + ret = -1; + goto out; + } + + if (fread(mobj->vbuf, 1, mobj->vsize, vfile) != mobj->vsize) + ret = -1; + +out: + fclose(vfile); + return ret; +} + static int -fwu_make_mdata(size_t images, size_t banks, char *uuids[], char *output) +fwu_make_mdata(size_t images, size_t banks, const char *vendor_file, + char *uuids[], char *output) { struct fwu_mdata_object *mobj; FILE *file; + struct stat sbuf; + size_t vendor_size = 0; int ret; - mobj = fwu_alloc_mdata(images, banks); + if (vendor_file) { + ret = stat(vendor_file, &sbuf); + if (ret) + return -errno; + + vendor_size = sbuf.st_size; + } + + mobj = fwu_alloc_mdata(images, banks, vendor_size); if (!mobj) return -ENOMEM; + if (vendor_file) { + ret = fwu_read_vendor_data(mobj, vendor_file); + if (ret) + goto done_make; + } + ret = fwu_parse_fill_uuids(mobj, uuids); if (ret < 0) goto done_make; @@ -286,6 +348,7 @@ fwu_make_mdata(size_t images, size_t banks, char *uuids[], char *output) done_make: free(mobj->mdata); + free(mobj->vbuf); free(mobj); return ret; @@ -295,11 +358,13 @@ int main(int argc, char *argv[]) { unsigned long banks = 0, images = 0; int c, ret; + const char *vendor_file; /* Explicitly initialize defaults */ active_bank = 0; __use_guid = false; previous_bank = INT_MAX; + vendor_file = NULL; do { c = getopt_long(argc, argv, opts_short, options, NULL); @@ -322,6 +387,9 @@ int main(int argc, char *argv[]) case 'a': active_bank = strtoul(optarg, NULL, 0); break; + case 'v': + vendor_file = optarg; + break; } } while (c != -1); @@ -348,7 +416,8 @@ int main(int argc, char *argv[]) previous_bank = active_bank > 0 ? active_bank - 1 : banks - 1; } - ret = fwu_make_mdata(images, banks, argv + optind, argv[argc - 1]); + ret = fwu_make_mdata(images, banks, vendor_file, argv + optind, + argv[argc - 1]); if (ret < 0) fprintf(stderr, "Error: Failed to parse and write image: %s\n", strerror(-ret));