Skip to contentSkip to conversation

Makefile: rework u-boot-initial-env target

PATCH Superseded Max Krummenacher 3 participants 9 messages Oct 28, 2022 – Nov 1, 2022 Kbuild

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Makefile: rework u-boot-initial-env target

From: Max Krummenacher <[email protected]>

With CONFIG_LTO enabled the current way of extracting the configured environment no longer works, i.e. the object file content changes due to LTO.

Build a host tool which prints the configured environment instead of using objcopy and friends to achive the same.

The code and Makefile changes were mostly stolen from tools/env/ i.e. the target userspace tools to access the environment.

Changes in v2:
- reworked to build a host tool which prints the configured environment as proposed by Pali Rohár
https://lore.kernel.org/u-boot/[email protected]/
- renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled"

Max Krummenacher (1):
Makefile: rework u-boot-initial-env target

 Makefile                  |  7 ++++---
 scripts/.gitignore        |  1 +
 scripts/Makefile          |  5 +++++
 scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 scripts/printinitialenv.c
Signature · 1 line
2.35.3
#1 lore raw

PATCH v2 1/1 Makefile: rework u-boot-initial-env target

From: Max Krummenacher <[email protected]>

With LTO enabled the U-Boot initial environment is no longer stored in an easy accessible section in env/common.o. I.e. the section name changes from build to build, its content maybe compressed and it is annotated with additional data.

Drop trying to read the initial env with elf tools from the compiler specific object file in favour of adding and using a host tool with the only functionality of printing the initial env to stdout.

See also:
https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- reworked to build a host tool which prints the configured environment as proposed by Pali Rohár
https://lore.kernel.org/u-boot/[email protected]/
- renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled"

 Makefile                  |  7 ++++---
 scripts/.gitignore        |  1 +
 scripts/Makefile          |  5 +++++
 scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 scripts/printinitialenv.c
Makefile +4 -3
index 0f1174718f7..2f97d63c398 100644
@@ -2442,9 +2442,10 @@ endif
 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
 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*$$/d' $@; \
-	sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+	scripts/printinitialenv | \
+	sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \
+	sort --field-separator== -k1,1 --stable -o $@
 
 u-boot-initial-env: u-boot.bin
 	$(call if_changed,genenv)
scripts/.gitignore +1 -0
index 08cc824bac3..6068724a0d4 100644
@@ -2,3 +2,4 @@
 # Generated files
 #
 bin2c
+printinitialenv
scripts/Makefile +5 -0
index 8731e6cecd7..ba993820571 100644
@@ -5,8 +5,13 @@
 # ---------------------------------------------------------------------------
 
 hostprogs-$(CONFIG_BUILD_BIN2C)		+= bin2c
+hostprogs-y				+= printinitialenv
 
 always		:= $(hostprogs-y)
 
+HOSTCFLAGS_printinitialenv.o += \
+		$(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
+		-DUSE_HOSTCC
+
 # Let clean descend into subdirs
 subdir-	+= basic kconfig dtc
scripts/printinitialenv.c new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.35.3
#2 lore raw

Hello! This is really much better solution! Few comments are below.

Quoted 36 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

From: Max Krummenacher <[email protected]>

With LTO enabled the U-Boot initial environment is no longer stored in an easy accessible section in env/common.o. I.e. the section name changes from build to build, its content maybe compressed and it is annotated with additional data.

Drop trying to read the initial env with elf tools from the compiler specific object file in favour of adding and using a host tool with the only functionality of printing the initial env to stdout.

See also:
https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- reworked to build a host tool which prints the configured environment as proposed by Pali Rohár
https://lore.kernel.org/u-boot/[email protected]/
- renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled"

 Makefile                  |  7 ++++---
 scripts/.gitignore        |  1 +
 scripts/Makefile          |  5 +++++
 scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 scripts/printinitialenv.c
Makefile +0 -0
index 0f1174718f7..2f97d63c398 100644

Makefile endif · line 2447

Quoted 9 lines
Makefile +3 -3
@@ -2442,9 +2442,10 @@ endif
 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
 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*$$/d' $@; \
-	sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+	scripts/printinitialenv | \
+	sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Makefile endif · line 2450

Quoted 3 lines
Makefile +1 -0
+	sort --field-separator== -k1,1 --stable -o $@
 
 u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

Quoted 15 lines
Makefile +0 -0
 	$(call if_changed,genenv)
scripts/.gitignore +1 -0
index 08cc824bac3..6068724a0d4 100644
@@ -2,3 +2,4 @@
 # Generated files
 #
 bin2c
+printinitialenv
scripts/Makefile +0 -0
index 8731e6cecd7..ba993820571 100644

scripts/Makefile line 8

Quoted 4 lines
scripts/Makefile +1 -0
@@ -5,8 +5,13 @@
 # ---------------------------------------------------------------------------
 
 hostprogs-$(CONFIG_BUILD_BIN2C)		+= bin2c
+hostprogs-y				+= printinitialenv

I'm not sure if the scripts/ is the correct directory for the this tool. Maybe it should be in tools? Lets wait what maintainers or Tom say.

Quoted 62 lines
scripts/Makefile +4 -0
 always		:= $(hostprogs-y)
 
+HOSTCFLAGS_printinitialenv.o += \
+		$(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
+		-DUSE_HOSTCC
+
 # Let clean descend into subdirs
 subdir-	+= basic kconfig dtc
scripts/printinitialenv.c new file +44 -0
new file mode 100644
index 00000000000..c58b234d679
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ * Max Krummenacher, Toradex
+ *
+ * Snippets taken from tools/env/fw_env.c
+ *
+ * This prints the list of default environment variables as currently
+ * configured.
+ *
+ */
+
+#include <stdio.h>
+
+/* Pull in the current config to define the default environment */
+#include <linux/kconfig.h>
+
+#ifndef __ASSEMBLY__
+#define __ASSEMBLY__ /* get only #defines from config.h */
+#include <config.h>
+#undef	__ASSEMBLY__
+#else
+#include <config.h>
+#endif
+
+#define DEFAULT_ENV_INSTANCE_STATIC
+#include <generated/environment.h>
+#include <env_default.h>
+
+int main(void)
+{
+	char *env, *nxt;
+
+	for (env = default_environment; *env; env = nxt + 1) {
+		for (nxt = env; *nxt; ++nxt) {
+			if (nxt >= &default_environment[sizeof(default_environment)]) {
+				fprintf(stderr, "## Error: environment not terminated\n");
+				return -1;
+			}
+		}
+		printf("%s\n", env);
+	}
+	return 0;
+}
Signature · 1 line
2.35.3
#3 lore raw

Hi

Quoted 42 lines · Pali Rohár

Hello! This is really much better solution! Few comments are below.

Quoted 38 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

From: Max Krummenacher <[email protected]>

With LTO enabled the U-Boot initial environment is no longer stored in an easy accessible section in env/common.o. I.e. the section name changes from build to build, its content maybe compressed and it is annotated with additional data.

Drop trying to read the initial env with elf tools from the compiler specific object file in favour of adding and using a host tool with the only functionality of printing the initial env to stdout.

See also:
https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- reworked to build a host tool which prints the configured environment as proposed by Pali Rohár
https://lore.kernel.org/u-boot/[email protected]/
- renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled"

 Makefile                  |  7 ++++---
 scripts/.gitignore        |  1 +
 scripts/Makefile          |  5 +++++
 scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 scripts/printinitialenv.c
Makefile +0 -0
index 0f1174718f7..2f97d63c398 100644
@@ -2442,9 +2442,10 @@ endif
      $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
Quoted 10 lines

Makefile endif · line 2447

Quoted 7 lines
Makefile +3 -3
 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*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 7 lines

Makefile endif · line 2450

Quoted 4 lines
Makefile +1 -0
+     sort --field-separator== -k1,1 --stable -o $@
 
 u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

Opinions?

Quoted 18 lines
Quoted 18 lines
Makefile +0 -0
      $(call if_changed,genenv)
scripts/.gitignore +1 -0
index 08cc824bac3..6068724a0d4 100644
@@ -2,3 +2,4 @@
 # Generated files
 #
 bin2c
+printinitialenv
scripts/Makefile +0 -0
index 8731e6cecd7..ba993820571 100644
@@ -5,8 +5,13 @@
 # ---------------------------------------------------------------------------
 
Quoted 5 lines

scripts/Makefile line 8

Quoted 2 lines
scripts/Makefile +1 -0
 hostprogs-$(CONFIG_BUILD_BIN2C)              += bin2c
+hostprogs-y                          += printinitialenv

I'm not sure if the scripts/ is the correct directory for the this tool. Maybe it should be in tools? Lets wait what maintainers or Tom say.

According to tools/Makefile tools should be used for tools which are not dependent on any boards. This here is a helper during the build of a particular U-Boot configuration. That is why I put it into scripts/.

Max

Quoted 63 lines
Quoted 63 lines
scripts/Makefile +4 -0
 always               := $(hostprogs-y)
 
+HOSTCFLAGS_printinitialenv.o += \
+             $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
+             -DUSE_HOSTCC
+
 # Let clean descend into subdirs
 subdir-      += basic kconfig dtc
scripts/printinitialenv.c new file +44 -1
new file mode 100644
index 00000000000..c58b234d679
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022
+ * Max Krummenacher, Toradex
+ *
+ * Snippets taken from tools/env/fw_env.c
+ *
+ * This prints the list of default environment variables as currently
+ * configured.
+ *
+ */
+
+#include <stdio.h>
+
+/* Pull in the current config to define the default environment */
+#include <linux/kconfig.h>
+
+#ifndef __ASSEMBLY__
+#define __ASSEMBLY__ /* get only #defines from config.h */
+#include <config.h>
+#undef       __ASSEMBLY__
+#else
+#include <config.h>
+#endif
+
+#define DEFAULT_ENV_INSTANCE_STATIC
+#include <generated/environment.h>
+#include <env_default.h>
+
+int main(void)
+{
+     char *env, *nxt;
+
+     for (env = default_environment; *env; env = nxt + 1) {
+             for (nxt = env; *nxt; ++nxt) {
+                     if (nxt >= &default_environment[sizeof(default_environment)]) {
+                             fprintf(stderr, "## Error: environment not terminated\n");
+                             return -1;
+                     }
+             }
+             printf("%s\n", env);
+     }
+     return 0;
+}
--

2.35.3

#4 lore raw
Quoted 98 lines · Max Krummenacher

Hi

Quoted 42 lines · Pali Rohár

Hello! This is really much better solution! Few comments are below.

Quoted 38 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

From: Max Krummenacher <[email protected]>

With LTO enabled the U-Boot initial environment is no longer stored in an easy accessible section in env/common.o. I.e. the section name changes from build to build, its content maybe compressed and it is annotated with additional data.

Drop trying to read the initial env with elf tools from the compiler specific object file in favour of adding and using a host tool with the only functionality of printing the initial env to stdout.

See also:
https://lore.kernel.org/all/[email protected]/

---

Changes in v2:
- reworked to build a host tool which prints the configured environment as proposed by Pali Rohár
https://lore.kernel.org/u-boot/[email protected]/
- renamed patch, v1 used "Makefile: fix u-boot-initial-env target if lto is enabled"

 Makefile                  |  7 ++++---
 scripts/.gitignore        |  1 +
 scripts/Makefile          |  5 +++++
 scripts/printinitialenv.c | 44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 scripts/printinitialenv.c
Makefile +0 -0
index 0f1174718f7..2f97d63c398 100644
@@ -2442,9 +2442,10 @@ endif
      $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
Quoted 10 lines

Makefile endif · line 2447

Quoted 7 lines
Makefile +3 -3
 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*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 7 lines

Makefile endif · line 2450

Quoted 4 lines
Makefile +1 -0
+     sort --field-separator== -k1,1 --stable -o $@
 
 u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

Opinions?

Quoted 18 lines
Quoted 18 lines
Makefile +0 -0
      $(call if_changed,genenv)
scripts/.gitignore +1 -0
index 08cc824bac3..6068724a0d4 100644
@@ -2,3 +2,4 @@
 # Generated files
 #
 bin2c
+printinitialenv
scripts/Makefile +0 -0
index 8731e6cecd7..ba993820571 100644
@@ -5,8 +5,13 @@
 # ---------------------------------------------------------------------------
 
Quoted 5 lines

scripts/Makefile line 8

Quoted 2 lines
scripts/Makefile +1 -0
 hostprogs-$(CONFIG_BUILD_BIN2C)              += bin2c
+hostprogs-y                          += printinitialenv

I'm not sure if the scripts/ is the correct directory for the this tool. Maybe it should be in tools? Lets wait what maintainers or Tom say.

Quoted 4 lines

According to tools/Makefile tools should be used for tools which are not dependent on any boards. This here is a helper during the build of a particular U-Boot configuration. That is why I put it into scripts/.

I think it should go to tools/ as the comment there isn't an absolute (other env things are there too).

Signature · 1 line
Tom
#5 lore raw
In reply to Max Krummenacher
Quoted 18 lines · On Monday 31 October 2022 11:51:45 Max Krummenacher wrote:
Quoted 11 lines · Pali Rohár

Makefile endif · line 2447

Quoted 7 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

quiet_cmd_genenv = GENENV $@

Makefile +3 -3
-cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-     sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 3 lines
Quoted 3 lines

+ sort --field-separator== -k1,1 --stable -o $@

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

Yea, it was wrong too.

Quoted 2 lines

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

This is not possible to achieve with Makefile build system and is probably also against the logic of make to achieve the best parallelism during build of the project.

In _my_ opinion, Makefile targets should have correct dependencies, on which they depend. This will prevent circular dependences and also faster building as make tool can run in parallel as much jobs as possible -- and do not have to wait until main u-boot.bin is built and then call other jobs.

Tom, or do you think something different?

#6 lore raw
Quoted 36 lines · Pali Rohár
Quoted 18 lines · On Monday 31 October 2022 11:51:45 Max Krummenacher wrote:
Quoted 11 lines · Pali Rohár

Makefile endif · line 2447

Quoted 7 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

quiet_cmd_genenv = GENENV $@

Makefile +3 -3
-cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-     sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 3 lines
Quoted 3 lines

+ sort --field-separator== -k1,1 --stable -o $@

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

Yea, it was wrong too.

Quoted 2 lines

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

This is not possible to achieve with Makefile build system and is probably also against the logic of make to achieve the best parallelism during build of the project.

Quoted 7 lines

In _my_ opinion, Makefile targets should have correct dependencies, on which they depend. This will prevent circular dependences and also faster building as make tool can run in parallel as much jobs as possible -- and do not have to wait until main u-boot.bin is built and then call other jobs.

Tom, or do you think something different?

Well, this tool has the same environment requirements as tools/env does, so we should be able to use the same dependency info?

Signature · 1 line
Tom
#7 lore raw
Quoted 43 lines · On Tuesday 01 November 2022 15:48:34 Tom Rini wrote:
Quoted 42 lines · Pali Rohár
Quoted 18 lines · On Monday 31 October 2022 11:51:45 Max Krummenacher wrote:
Quoted 11 lines · Pali Rohár

Makefile endif · line 2447

Quoted 7 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

quiet_cmd_genenv = GENENV $@

Makefile +3 -3
-cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-     sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 3 lines
Quoted 3 lines

+ sort --field-separator== -k1,1 --stable -o $@

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

Yea, it was wrong too.

Quoted 2 lines

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

This is not possible to achieve with Makefile build system and is probably also against the logic of make to achieve the best parallelism during build of the project.

In _my_ opinion, Makefile targets should have correct dependencies, on which they depend. This will prevent circular dependences and also faster building as make tool can run in parallel as much jobs as possible -- and do not have to wait until main u-boot.bin is built and then call other jobs.

Quoted 4 lines
Quoted 1 line

Tom, or do you think something different?

Well, this tool has the same environment requirements as tools/env does, so we should be able to use the same dependency info?

Yes, build tool is _able_ to use it. (I think we all agree on this ability of make)

But the question is if it _should_ be used. Because Max wrote some arguments why not to use this env dependency info.

#8 lore raw
Quoted 46 lines · Pali Rohár
Quoted 45 lines · On Tuesday 01 November 2022 15:48:34 Tom Rini wrote:
Quoted 43 lines · Pali Rohár
Quoted 18 lines · On Monday 31 October 2022 11:51:45 Max Krummenacher wrote:
Quoted 11 lines · Pali Rohár

Makefile endif · line 2447

Quoted 7 lines · On Friday 28 October 2022 18:18:49 Max Krummenacher wrote:

quiet_cmd_genenv = GENENV $@

Makefile +3 -3
-cmd_genenv = $(OBJCOPY) --dump-section .rodata.default_environment=$@ env/common.o; \
-     sed --in-place -e 's/\x00/\x0A/g' $@; sed --in-place -e '/^\s*$$/d' $@; \
-     sort --field-separator== -k1,1 --stable $@ -o $@
+cmd_genenv = \
+     scripts/printinitialenv | \
+     sed -e 's/\x00/\x0A/g' -e '/^\s*$$/d' | \

I think that you do not need this sed anymore as you print newline in host tool.

Missed that one, will change in a V3.

Quoted 3 lines
Quoted 3 lines

+ sort --field-separator== -k1,1 --stable -o $@

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

u-boot-initial-env: u-boot.bin

It is needed to update dependencies for u-boot-initial-env target. Now it does not depend on u-boot.bin but rather on printinitialenv tool.

I'm unsure if that is the best way forward. The initial solution would also not need to depend on u-boot.bin but rather on env/common.o.

Yea, it was wrong too.

Quoted 2 lines

I guess that the intention was that the U-Boot binary and the u-boot-initial-env file should not be out of sync.

This is not possible to achieve with Makefile build system and is probably also against the logic of make to achieve the best parallelism during build of the project.

In _my_ opinion, Makefile targets should have correct dependencies, on which they depend. This will prevent circular dependences and also faster building as make tool can run in parallel as much jobs as possible -- and do not have to wait until main u-boot.bin is built and then call other jobs.

Tom, or do you think something different?

Quoted 8 lines
Quoted 2 lines

Well, this tool has the same environment requirements as tools/env does, so we should be able to use the same dependency info?

Yes, build tool is _able_ to use it. (I think we all agree on this ability of make)

But the question is if it _should_ be used. Because Max wrote some arguments why not to use this env dependency info.

Er, I'm lost I guess, sorry. Yes, it should not depend on env/common.o nor u-boot.bin. I guess looking again, we can't borrow just the envtools rules as we also would need to update the section that adds $(defaultenv_h) to envtools would also need to be done for this tool.

Signature · 1 line
Tom