diff mbox series

Makefile: fix generation of defaultenv.h from empty initial file

Message ID 20210422074418.1573153-1-rasmus.villemoes@prevas.dk
State Accepted
Commit c6ecb2f81e7fdb80ef2e5e5153d60552c4ea3fda
Delegated to: Tom Rini
Headers show
Series Makefile: fix generation of defaultenv.h from empty initial file | expand

Commit Message

Rasmus Villemoes April 22, 2021, 7:44 a.m. UTC
When CONFIG_USE_DEFAULT_ENV_FILE=y and the file
CONFIG_DEFAULT_ENV_FILE is empty (or at least doesn't contain any
non-comment, non-empty lines), we end up feeding nothing into xxd,
which in turn then outputs nothing. Then blindly appending ", 0x00"
means that we end up trying to compile (roughly)

const char defaultenv[] = { , 0x00 }

which is of course broken.

To fix that, change the frobbing of the text file so that we always
end up printing an extra empty line (which gets turned into that extra
nul byte we need) - that corresponds better to the binary format
consisting of a series of key=val nul terminated strings, terminated
by an empty string.

Reported-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 Makefile | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Oleksandr Suvorov April 22, 2021, 9:26 a.m. UTC | #1
Hi Rasmus,

Thanks for the patch, I've tested it.

On Thu, Apr 22, 2021 at 10:44 AM Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> When CONFIG_USE_DEFAULT_ENV_FILE=y and the file
> CONFIG_DEFAULT_ENV_FILE is empty (or at least doesn't contain any
> non-comment, non-empty lines), we end up feeding nothing into xxd,
> which in turn then outputs nothing. Then blindly appending ", 0x00"
> means that we end up trying to compile (roughly)
>
> const char defaultenv[] = { , 0x00 }
>
> which is of course broken.
>
> To fix that, change the frobbing of the text file so that we always
> end up printing an extra empty line (which gets turned into that extra
> nul byte we need) - that corresponds better to the binary format
> consisting of a series of key=val nul terminated strings, terminated
> by an empty string.
>
> Reported-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Reviewed-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>

> ---
>  Makefile | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 3fc9777b0b..b7af2b936d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1854,11 +1854,10 @@ define filechk_timestamp.h
>  endef
>
>  define filechk_defaultenv.h
> -       (grep -v '^#' | \
> -        grep -v '^$$' | \
> +       ( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \
>          tr '\n' '\0' | \
>          sed -e 's/\\\x0\s*//g' | \
> -        xxd -i ; echo ", 0x00" ; )
> +        xxd -i ; )
>  endef
>
>  define filechk_dt.h
> --
> 2.29.2
>
Tom Rini April 27, 2021, 4:46 p.m. UTC | #2
On Thu, Apr 22, 2021 at 09:44:18AM +0200, Rasmus Villemoes wrote:

> When CONFIG_USE_DEFAULT_ENV_FILE=y and the file
> CONFIG_DEFAULT_ENV_FILE is empty (or at least doesn't contain any
> non-comment, non-empty lines), we end up feeding nothing into xxd,
> which in turn then outputs nothing. Then blindly appending ", 0x00"
> means that we end up trying to compile (roughly)
> 
> const char defaultenv[] = { , 0x00 }
> 
> which is of course broken.
> 
> To fix that, change the frobbing of the text file so that we always
> end up printing an extra empty line (which gets turned into that extra
> nul byte we need) - that corresponds better to the binary format
> consisting of a series of key=val nul terminated strings, terminated
> by an empty string.
> 
> Reported-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Reviewed-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 3fc9777b0b..b7af2b936d 100644
--- a/Makefile
+++ b/Makefile
@@ -1854,11 +1854,10 @@  define filechk_timestamp.h
 endef
 
 define filechk_defaultenv.h
-	(grep -v '^#' | \
-	 grep -v '^$$' | \
+	( { grep -v '^#' | grep -v '^$$' || true ; echo '' ; } | \
 	 tr '\n' '\0' | \
 	 sed -e 's/\\\x0\s*//g' | \
-	 xxd -i ; echo ", 0x00" ; )
+	 xxd -i ; )
 endef
 
 define filechk_dt.h