Skip to contentSkip to conversation

Makefile: Sort u-boot-initial-env output

PATCH Superseded Christoph Niedermaier 3 participants 6 messages Feb 23, 2022 – Feb 25, 2022 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Sort u-boot-initial-env output

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +2 -1
index 4b152249ca..67ed4edc1a 100644
@@ -2439,7 +2439,8 @@ endif
 
 quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-	sed --in-place -e 's/\x00/\x0A/g' $@
+	sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+	sort --field-separator== -k1,1 --stable $@ -o $@
 
 u-boot-initial-env: u-boot.bin
 	$(call if_changed,genenv)
Signature · 1 line
2.11.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 20 lines · Christoph Niedermaier

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
  Makefile | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Makefile +0 -0
index 4b152249ca..67ed4edc1a 100644

Makefile endif · line 2446

Quoted 9 lines
Makefile +2 -1
@@ -2439,7 +2439,8 @@ endif
 
  quiet_cmd_genenv = GENENV  $@
  cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-	sed --in-place -e 's/\x00/\x0A/g' $@
+	sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+	sort --field-separator== -k1,1 --stable $@ -o $@
 
  u-boot-initial-env: u-boot.bin
  	$(call if_changed,genenv)

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
#2 lore raw
In reply to Christoph Niedermaier

Hi Christoph,

Quoted 7 lines · Christoph Niedermaier

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Quoted 8 lines
Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Does this sort the text environment too?

Quoted 16 lines
Makefile +2 -2
index 4b152249ca..67ed4edc1a 100644
@@ -2439,7 +2439,8 @@ endif
 
 quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-       sed --in-place -e 's/\x00/\x0A/g' $@
+       sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+       sort --field-separator== -k1,1 --stable $@ -o $@
 
 u-boot-initial-env: u-boot.bin
        $(call if_changed,genenv)
--
Quoted 2 lines

2.11.0

Regards,
Simon

#3 lore raw

From: Simon Glass [mailto:[email protected]]
Sent: Wednesday, February 23, 2022 11:59 PM

Quoted 3 lines

Hi Christoph,

Hi Simon,

Quoted 17 lines · Christoph Niedermaier
Quoted 7 lines

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Quoted 8 lines
Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 1 line

Does this sort the text environment too?

It sorts only the generated file "u-boot-initial-env" which comes from the default environment.
What exactly do you mean by "text environment"?

Quoted 8 lines
Quoted 8 lines
Makefile +0 -0
index 4b152249ca..67ed4edc1a 100644
@@ -2439,7 +2439,8 @@ endif
 
Quoted 8 lines

Makefile endif · line 2446

Quoted 8 lines
Makefile +2 -1
 quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-       sed --in-place -e 's/\x00/\x0A/g' $@
+       sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+       sort --field-separator== -k1,1 --stable $@ -o $@
 
 u-boot-initial-env: u-boot.bin
        $(call if_changed,genenv)

Regards
Christoph

#4 lore raw

Hi Christoph,

Quoted 26 lines · Christoph Niedermaier

From: Simon Glass [mailto:[email protected]]
Sent: Wednesday, February 23, 2022 11:59 PM

Quoted 3 lines

Hi Christoph,

Hi Simon,

Quoted 17 lines · Christoph Niedermaier
Quoted 15 lines

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 1 line

Does this sort the text environment too?

It sorts only the generated file "u-boot-initial-env" which comes from the default environment.
What exactly do you mean by "text environment"?

https://u-boot.readthedocs.io/en/latest/usage/environment.html#text-based-environment

Can you please expand your commit message a bit to explain exactly what this affects? Also how about an update to the above page that describes how the env is sorted.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Makefile +0 -0
index 4b152249ca..67ed4edc1a 100644
@@ -2439,7 +2439,8 @@ endif
 
Quoted 9 lines
Quoted 8 lines

Makefile endif · line 2446

Quoted 8 lines
Makefile +2 -1
 quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-       sed --in-place -e 's/\x00/\x0A/g' $@
+       sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+       sort --field-separator== -k1,1 --stable $@ -o $@
 
 u-boot-initial-env: u-boot.bin
        $(call if_changed,genenv)

Regards,
Simon

#5 lore raw

From: Simon Glass [mailto:[email protected]]
Sent: Friday, February 25, 2022 12:54 AM

Quoted 3 lines

Hi Christoph,

Hi Simon,

Quoted 34 lines
Quoted 26 lines · Christoph Niedermaier

From: Simon Glass [mailto:[email protected]]
Sent: Wednesday, February 23, 2022 11:59 PM

Quoted 3 lines

Hi Christoph,

Hi Simon,

Quoted 17 lines · Christoph Niedermaier
Quoted 15 lines

For a better overview and better comparison sort the initial environment as the get_default_env.sh script does. We need to preserve the order of equal variable names. So only sort by the variable name, and disable the last-resort comparison. Also remove blank lines before sorting.

Cc Stefano Babic <[email protected]>
Cc Simon Glass <[email protected]>
Cc Marek Behún <[email protected]>

To: [email protected]

---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 1 line

Does this sort the text environment too?

It sorts only the generated file "u-boot-initial-env" which comes from the default environment.
What exactly do you mean by "text environment"?

Quoted 5 lines

https://u-boot.readthedocs.io/en/latest/usage/environment.html#text-based-environment

Can you please expand your commit message a bit to explain exactly what this affects? Also how about an update to the above page that describes how the env is sorted.

I will make a V2 of the patch with a better commit message.

The sorting only affects the u-boot-initial-env file for the userspace tools [1]. The environments of the bootloader are sorted if printed by printenv. I think mentioning the u-boot-initial-env file in the page above will lead to more confusion. It think it belongs more to the userspace tools [1].

[1] https://github.com/sbabic/libubootenv

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Makefile +2 -1
index 4b152249ca..67ed4edc1a 100644
@@ -2439,7 +2439,8 @@ endif
 
 quiet_cmd_genenv = GENENV  $@
 cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-       sed --in-place -e 's/\x00/\x0A/g' $@
+       sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
+       sort --field-separator== -k1,1 --stable $@ -o $@
 
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

Makefile endif · line 2446

Quoted 2 lines
Makefile +0 -0
 u-boot-initial-env: u-boot.bin
        $(call if_changed,genenv)

Regards
Christoph