All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: Marek Vasut <marex@denx.de>
Cc: u-boot@lists.denx.de,  Joe Hershberger <joe.hershberger@ni.com>,
	 Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH] tools: mkenvimage: Add pure shell implementation of mkenvimage
Date: Fri, 07 Feb 2025 11:31:07 +0100	[thread overview]
Message-ID: <877c62rqqc.fsf@prevas.dk> (raw)
In-Reply-To: <20250205143641.65430-1-marex@denx.de> (Marek Vasut's message of "Wed, 5 Feb 2025 15:35:52 +0100")

On Wed, Feb 05 2025, Marek Vasut <marex@denx.de> wrote:

> Add implementation of mkenvimage written purely in bourne shell.
>
> This is not a replacement for mkenvimage tool, but rather a simple
> implementation which can be used in environments where mkenvimage
> itself cannot be deployed due to various constraints, like hardware
> manufacturing plants, but where bourne shell and basic tool are
> already available.
>
> The external dependencies which are not shell built-ins are gzip
> and grep.
>

Eh, and cat, sort, dd, tr, mktemp, head, tail, mv and rm ?

> All mkenvimage parameters are implemented and compatible with the
> C implementation of mkenvimage.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  tools/mkenvimage.sh | 126 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 126 insertions(+)
>  create mode 100755 tools/mkenvimage.sh
>
> diff --git a/tools/mkenvimage.sh b/tools/mkenvimage.sh
> new file mode 100755
> index 00000000000..f83fac92e5d
> --- /dev/null
> +++ b/tools/mkenvimage.sh
> @@ -0,0 +1,126 @@
> +#!/bin/sh
> +
> +print_help() {
> +	echo "mkenvimage [-h] [-V] [-r] [-b] [-p <byte>] -s <environment partition size> -o <output> <input file>"

Nit: you included a .sh extension in the filename, probably this output
should reflect that.

> +
> +(
> +# Read input environment file, make sure there is a trailing newline,
> +# sort the result and remove empty and commented out lines.
> +( cat "${INFILE}" ; echo ) | sort -u "${INFILE}" | grep -v '^#' | grep -v '^[ \t]*$' | tr '\n' '\0'

Doesn't sort ignore stdin when given file(s) via argv? Also, the newline
added by that echo would probably by removed by the grep, and you
manually insert a \0 right after, so probably the first cat;echo should
just be removed.

I'm also wondering why you even do that sort; AFAIK, mkenvimage doesn't
do that. And it would make a difference if the input fx had two
definitions for the same variable

foo=Y
foo=X

because when loaded on target, the last occurring value takes
precedence.

Are you handling escaping of newlines, in order to allow values to
contain newline characters?

Rasmus

  parent reply	other threads:[~2025-02-07 10:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05 14:35 [PATCH] tools: mkenvimage: Add pure shell implementation of mkenvimage Marek Vasut
2025-02-06 12:38 ` Simon Glass
2025-02-06 20:38   ` Marek Vasut
2025-02-07  0:49     ` Simon Glass
2025-02-08 21:25       ` Marek Vasut
2025-02-07  7:40     ` Alexander Dahl
2025-02-08 21:26       ` Marek Vasut
2025-02-07 10:31 ` Rasmus Villemoes [this message]
2025-02-08 21:16   ` Marek Vasut

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=877c62rqqc.fsf@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=joe.hershberger@ni.com \
    --cc=marex@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.