All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2] Makefile: fix generating environment file
Date: Thu, 22 Apr 2021 09:34:34 +0300	[thread overview]
Message-ID: <CAGgjyvFrZf9pRKvPbLtrpJomz521Agi3HpgkRBJuZmKxBR==FQ@mail.gmail.com> (raw)
In-Reply-To: <e3e60a10-d775-0ec8-31af-8e9036e1c64a@prevas.dk>

On Wed, Apr 21, 2021 at 11:56 PM Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> On 21/04/2021 17.21, Oleksandr Suvorov wrote:
> > Hi Rasmus,
> >
> > On Wed, Apr 21, 2021 at 12:34 AM Rasmus Villemoes
> > <rasmus.villemoes@prevas.dk> wrote:
> >>
> >> On 20/04/2021 23.10, Oleksandr Suvorov wrote:
> >>> Hi Rasmus,
> >>>
> >>> Thanks for your feedback!
> >>> Yes, I noted that there were no possible situations with the trailing
> >>> code != 0x00, but simply removing the additional trailing 0x00
> >>> gives us an empty array default_environment[] for the empty defaultenv file.
> >>> I need to test whether this case is handled in u-boot properly and
> >>> then prepare the next patch version :P
> >>
> >> No, I'm not suggesting removing the trailing nul byte, it very much has
> >> to be there - the binary format of the environment is a sequence of
> >> nul-terminated C strings of the key=value form, concatenated
> >> back-to-back, terminated by an empty string.
> >
> > (/me saying: never answer at night, never answer at night, never
> > answer at night  :-D)
> >
> >>
> >> What I'm suggesting is to take the input file
> >>
> >> ===
> >> foo=bar
> >>
> >> # Set our IP address
> >> ip=1.2.3.4
> >> ===
> >>
> >> do the comment- and empty-line stripping (the two first greps), and then
> >> after that add an extra empty line
> >>
> >> ===
> >> foo=bar
> >> ip=1.2.3.4
> >>
> >> ===
> >>
> >> and then feed that to the 'replace \n by nul bytes' | 'delete
> >> backslash+nul+whitespace' | xxd pipe. That way there's always that
> >> trailing nul on the input to xxd, i.e. in the example above, we would
> >> feed foo=bar\0ip-1.2.3.4\0\0 into xxd, while with an initially empty
> >> file xxd would just receive that single nul byte.
> >>
> >> It's just that I think terminating the sequence of key=value lines by an
> >> empty line more exactly matches the binary format.
> >
> > Sure, now I see. Your solution is more straight and clear.
> > Unfortunately, it doesn't work :)
>
> Yeah, I didn't really expect it to. Ah, it's because "set -e" is in
> effect, so in
>
>         ( { grep -v '^#' | grep -v '^$$' ; echo '' ; } | \
>
> the return value of the  grep -v '^#' | grep -v '^$$' pipeline is that
> of the second grep, and when there's no input lines that match (such as,
> with an empty input file), that's an EXIT_FAILURE. So the whole subshell
> exits at that point, and nothing gets written to defaultenv_autogenerated.h.
>
> Doing
>
> define filechk_defaultenv.h
>         ( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \
>          tr '\n' '\0' | \
>          sed -e 's/\\\x0\s*//g' | \
>          xxd -i ; )
> endef
>
> seems to work.

So will you post your own patch?

> Rasmus


-- 
Best regards
Oleksandr Suvorov

Toradex AG
Ebenaustrasse 10 | 6048 Horw | Switzerland | T: +41 41 500 48 00

  reply	other threads:[~2021-04-22  6:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 14:43 [PATCH v2] Makefile: fix generating environment file Oleksandr Suvorov
2021-04-20 19:33 ` Rasmus Villemoes
2021-04-20 21:10   ` Oleksandr Suvorov
2021-04-20 21:33     ` Rasmus Villemoes
2021-04-21 15:21       ` Oleksandr Suvorov
2021-04-21 20:55         ` Rasmus Villemoes
2021-04-22  6:34           ` Oleksandr Suvorov [this message]
2021-04-22  7:44             ` [PATCH] Makefile: fix generation of defaultenv.h from empty initial file Rasmus Villemoes
2021-04-22  9:26               ` Oleksandr Suvorov
2021-04-27 16:46               ` Tom Rini

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='CAGgjyvFrZf9pRKvPbLtrpJomz521Agi3HpgkRBJuZmKxBR==FQ@mail.gmail.com' \
    --to=oleksandr.suvorov@toradex.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.