From: Michal Simek <michal.simek@amd.com>
To: Sughosh Ganu <sughosh.ganu@linaro.org>, u-boot@lists.denx.de
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Masahisa Kojima <masahisa.kojima@linaro.org>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Patrick Delaunay <patrick.delaunay@foss.st.com>,
Yann Gautier <yann.gautier@st.com>,
Etienne Carriere <etienne.carriere@foss.st.com>,
Jassi Brar <jaswinder.singh@linaro.org>
Subject: Re: [PATCH v2 18/21] tools: mkfwumdata: add logic to append vendor data to the FWU metadata
Date: Thu, 15 Feb 2024 15:31:42 +0100 [thread overview]
Message-ID: <877195ff-1c10-4e98-b042-cdc47cbaa293@amd.com> (raw)
In-Reply-To: <20240212074712.3657076-19-sughosh.ganu@linaro.org>
On 2/12/24 08:47, Sughosh Ganu wrote:
> 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 <sughosh.ganu@linaro.org>
> ---
>
> 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 <string.h>
> #include <u-boot/crc.h>
> #include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> #include <uuid/uuid.h>
>
> /* Since we can not include fwu.h, redefine version here. */
> @@ -30,7 +32,7 @@ typedef uint64_t u64;
>
> #include <fwu_mdata.h>
>
> -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 <num> Active bank (default=0)\n"
> "\t-p, --previous-bank <num> 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));
Tested-by: Michal Simek <michal.simek@amd.com>
Thanks,
Michal
next prev parent reply other threads:[~2024-02-15 14:32 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 7:46 [PATCH v2 00/21] FWU: Migrate FWU metadata to version 2 Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 01/21] configs: fwu: remove FWU configs for metadata V2 migration Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 02/21] fwu: metadata: migrate to version 2 of the structure Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 03/21] drivers: fwu: add the size parameter to the metadata access API's Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 04/21] fwu: add helper functions for getting image description offsets Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 05/21] fwu: make changes to support version 2 of FWU metadata Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 06/21] fwu: add some API's for metadata version 2 access Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 07/21] drivers: fwu: mtd: allocate buffer for image info dynamically Sughosh Ganu
2024-02-12 7:46 ` [PATCH v2 08/21] drivers: fwu: allocate memory for metadata copies Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 09/21] fwu: add a function to put a bank in Trial State Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 10/21] capsule: accept a bank on a successful update Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 11/21] fwu: mtd: modify the DFU API's to align with metadata version 2 Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 12/21] efi_firmware: fwu: do not read FWU metadata on sandbox Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 13/21] efi_firmware: fwu: get the number of FWU banks at runtime Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 14/21] cmd: fwu: align the command with metadata version 2 Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 15/21] test: fwu: align the FWU metadata access test with " Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 16/21] fwu: remove the config symbols for number of banks and images Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 17/21] tools: mkfwumdata: migrate to metadata version 2 Sughosh Ganu
2024-02-15 14:31 ` Michal Simek
2024-02-19 11:42 ` Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 18/21] tools: mkfwumdata: add logic to append vendor data to the FWU metadata Sughosh Ganu
2024-02-15 14:31 ` Michal Simek [this message]
2024-02-12 7:47 ` [PATCH v2 19/21] tools: mkfwumdata: fix the size parameter to the fwrite call Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 20/21] configs: fwu: re-enable FWU configs Sughosh Ganu
2024-02-12 7:47 ` [PATCH v2 21/21] doc: fwu: make changes for supporting FWU Metadata version 2 Sughosh Ganu
2024-02-20 9:43 ` [PATCH v2 00/21] FWU: Migrate FWU metadata to " Etienne CARRIERE - foss
2024-02-20 11:15 ` Sughosh Ganu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877195ff-1c10-4e98-b042-cdc47cbaa293@amd.com \
--to=michal.simek@amd.com \
--cc=etienne.carriere@foss.st.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jaswinder.singh@linaro.org \
--cc=masahisa.kojima@linaro.org \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=sughosh.ganu@linaro.org \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
--cc=yann.gautier@st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox