[PATCH] tools: mkenvimage: Add pure shell implementation of mkenvimage
Rasmus Villemoes
ravi at prevas.dk
Fri Feb 7 11:31:07 CET 2025
On Wed, Feb 05 2025, Marek Vasut <marex at 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 at denx.de>
> ---
> Cc: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Tom Rini <trini at 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
More information about the U-Boot
mailing list