From: Sascha Hauer <sha@pengutronix.de>
To: Denis Osterland-Heim <denis.osterland@diehl.com>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH] scripts: imx: add support for additional hab Blocks
Date: Mon, 22 Mar 2021 06:50:02 +0100 [thread overview]
Message-ID: <20210322055002.GM23724@pengutronix.de> (raw)
In-Reply-To: <20210311170249.22520-1-denis.osterland@diehl.com>
Hi Denis,
On Thu, Mar 11, 2021 at 05:07:20PM +0000, Denis Osterland-Heim wrote:
> From: Denis Osterland-Heim <Denis.Osterland@diehl.com>
>
> This allows to specifiy additional singed blocks
> in the format `offset+size@address` within the imximg.
>
> It is needed by the uuu tool, which loads the image different to
> the imx-usb-loader. It loads the DCD always to 0x910000 in the OCRAM.
> So this area have to be signed as well.
>
> In my case this needs `hab_blocks 0x42c+0x1f0@0x910000`.
>
> It supports to remove quotes to support Kconfig variable here.
>
> Signed-off-by: Denis Osterland-Heim <Denis.Osterland@diehl.com>
> ---
> scripts/imx/imx.c | 62 +++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 60 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
> index 6b8dabd04..d37e200ca 100644
> --- a/scripts/imx/imx.c
> +++ b/scripts/imx/imx.c
> @@ -328,6 +328,7 @@ static int do_hab_blocks(struct config_data *data, int argc, char *argv[])
> {
> char *str;
> int ret;
> +int i;
> uint32_t signed_size = data->load_size;
> uint32_t offset = data->image_ivt_offset;
>
> @@ -352,7 +353,7 @@ static int do_hab_blocks(struct config_data *data, int argc, char *argv[])
> }
>
> if (signed_size > 0) {
> -ret = asprintf(&str, "Blocks = 0x%08x 0x%08x 0x%08x \"%s\"\n",
> +ret = asprintf(&str, "Blocks = 0x%08x 0x%08x 0x%08x \"%s\"",
> data->image_load_addr + data->image_ivt_offset, offset,
> signed_size - data->image_ivt_offset, data->outfile);
> } else {
> @@ -365,10 +366,67 @@ static int do_hab_blocks(struct config_data *data, int argc, char *argv[])
> return -ENOMEM;
>
> ret = hab_add_str(data, str);
> +free(str);
> if (ret)
> return ret;
>
> -return 0;
> +for (i = 1; i < argc; i++)
> +{
Ciding style: The open brace should be on previous line.
> +uint32_t addr;
> +uint32_t off;
> +uint32_t size;
> +char *b;
> +char *e;
> +
> +b = argv[i];
> +if (b[0] == '"') // remove qoutes
> +{
> +b++;
> +for (e = b; *e; e++)
> +/* find end of string */;
> +e--;
> +if (*e == '"')
> +*e = '\0';
To make this less efficient but better readable, how about:
e = b + strlen(b) - 1?
Note this fails when 'b' is an empty string, but your version fails
there as well. It needs an additional check.
> +else
> +fprintf(stderr, "warning: no '\"' at the end of '%s' [b=%p'%s', e=%p'%s']\n", argv[i], b, b, e, e);
> +}
> +if (!*b)
> +continue; // skip if empty
> +
> +e = strchr(b, '+');
> +if (!e)
> +{
> +fprintf(stderr, "failed to find '+' in '%s'\n", b);
> +fprintf(stderr, "format off+size@addr expected, but given: %s\n", argv[i]);
> +return -EINVAL;
> +}
> +*e = '\0';
> +off = strtoul(b, NULL, 0);
No need to set the place where the '+' is to zero. You can do it like
this:
char *plus;
off = strtoul(b, &plus, 0);
if (*plus != '+')
/* complain */
> +
> +b = e + 1;
> +e = strchr(b, '@');
> +if (!e)
> +{
> +fprintf(stderr, "failed to find '@' in '%s'\n", b);
> +fprintf(stderr, "format off+size@addr expected, but given: %s", argv[i]);
> +return -EINVAL;
> +}
> +*e = '\0';
> +size = strtoul(b, NULL, 0);
Same here.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-03-22 5:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 17:07 Denis Osterland-Heim
2021-03-22 5:50 ` Sascha Hauer [this message]
2021-03-22 6:26 ` Denis Osterland-Heim
2021-03-22 12:05 Denis Osterland-Heim
2021-03-22 12:06 ` Denis Osterland-Heim
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=20210322055002.GM23724@pengutronix.de \
--to=sha@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=denis.osterland@diehl.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