Skip to content

Conversation

@tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Mar 2, 2022

Makefile: have HEADS_GAWK depend on locally built HEADS_MAKE if make and gawk are not found in expected 4.2.1 versions locally.

This will be the case on debian-11 and other newer OSes.

@tlaurion tlaurion changed the title Makefile: have HEADS_GAWK depend on locally built HEADS_MAKE if make … Makefile: have HEADS_GAWK depend on locally built HEADS_MAKE Mar 2, 2022
@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 2, 2022

~ @SergiiDmytruk @MrChromebox : I didn't find how to have "all" depend on "bootstrap" which would have been the cleaner option.~ EDIT: 4e57d3f works. Thanks @SergiiDmytruk for the insight!

Before, we were having locally built gawk sha256sum in hashes.txt. Now we have make.


Todo (make fu insights needed) @SergiiDmytruk @MrChromebox:

We still have lost sha256sum of the coreboot roms in hashes.txt, which I have no clue why up until now.

Any ideas?

Traces:

  • It broke from this commit: 7ce12fe, where build happened here and where rom hashes are absent as seen here.

    • This commit replaced rom hashes with locally built gawk hashes.
  • Where hashes.txt contained firmware sha256sum in parent c096a1f, where build happened here and where hashes.txt contained rom sha256sum as seen here

Makefile Outdated
# Once we have a proper Make, we can just pass arguments into it
all linux cpio run: $(HEADS_MAKE)
LANG=C MAKE=$(HEADS_MAKE) $(HEADS_MAKE) $(MAKE_JOBS) $@
LANG=C MAKE=$(HEADS_MAKE) $(MAKE_JOBS) $@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? I think you might have removed wrong part of the string ($(HEADS_MAKE) instead of MAKE=$(HEADS_MAKE)).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergiiDmytruk the line 94 shows LANG=C MAKE=$(HEADS_MAKE) $(MAKE_JOBS) $@
I basically changed:
LANG=C MAKE=$(HEADS_MAKE) $(HEADS_MAKE) $(MAKE_JOBS) $@
for
LANG=C MAKE=$(HEADS_MAKE) $(MAKE_JOBS) $@

Since originally there was two $(HEADS_MAKE) $(HEADS_MAKE) passed. No harm, but make logs under build/logs/* were showing that double /build/make-4.2.1/make everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlaurion I probably miss something. It's just that LANG/MAKE=... sets environment variables and $(MAKE_JOBS) expands to -j... which is what should be interpreted as a command in this case, I just don't see how it can execute make at the end.

Copy link
Collaborator Author

@tlaurion tlaurion Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergiiDmytruk : Now I see your point. Actually, I do not even understand why it was put there. Was removed under 790671f and commented at #1128 (comment)

@SergiiDmytruk
Copy link
Contributor

@tlaurion

I didn't find how to have "all" depend on "bootstrap" which would have been the cleaner option.

Probably like this:

bootstrap: ;
all: bootstrap

Before, we were having locally built gawk sha256sum in hashes.txt. Now we have make.

Don't see anything obvious, would need to reduce Makefile to debug this.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 2, 2022

bootstrap: ;
all: bootstrap

@SergiiDmytruk :Some attempts. As said, this is my make fu that is probably the problem. I have to miss a concept.

In master: bootstrap is currently defined under HEADS_GAWK and HEADS_MAKE targets. So as said previously, I tried to have all call the bootstrap target, since calling make bootstrap works correctly (this is what CircleCI is doing right now):

user@heads-tests:~/heads$ rm -rf build/make-4.2.1/ build/gawk-4.2.1/
user@heads-tests:~/heads$ make BOARD=x230-hotp-maximized bootstrap
2022-03-02 14:35:01-05:00 Wrong OS deployed make detected: 4.3. Building and using 4.2.1...
2022-03-02 14:35:01-05:00 Wrong OS deployed gawk detected: 5.1.0. Building and using 4.2.1...
2022-03-02 14:35:01-05:00 Local built HEADS_GAWK only if different then provided by OS: /home/user/heads/build/gawk-4.2.1/gawk
2022-03-02 14:35:01-05:00 Local built HEADS_MAKE only if different then provided by OS: /home/user/heads/build/make-4.2.1/make
2022-03-02 14:35:01-05:00 Heads build system will call make from now on as: MAKE: /home/user/heads/build/make-4.2.1/make.
Makefile:264: warning: overriding recipe for target 'all'
Makefile:141: warning: ignoring old recipe for target 'all'
tar xf "/home/user/heads/packages/make-4.2.1.tar.bz2" -C "/home/user/heads/build"
touch "/home/user/heads/build/make-4.2.1/.extract"
( cd "/home/user/heads/build/make-4.2.1/" ; patch -p1 ) < "patches/make-4.2.1.patch"
patching file glob/glob.c
Hunk #1 succeeded at 208 with fuzz 2.
touch "/home/user/heads/build/make-4.2.1/.patch"
cd "/home/user/heads/build/make-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/make.configure.log" \
> /dev/null
touch "/home/user/heads/build/make-4.2.1/.configured"
make -C "/home/user/heads/build/make-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/make.log" \
	> /dev/null
tar xf "/home/user/heads/packages/gawk-4.2.1.tar.xz" -C "/home/user/heads/build"
touch "/home/user/heads/build/gawk-4.2.1/.extract"
touch "/home/user/heads/build/gawk-4.2.1/.patch"
cd "/home/user/heads/build/gawk-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/gawk.configure.log" \
> /dev/null
touch "/home/user/heads/build/gawk-4.2.1/.configured"
/home/user/heads/build/make-4.2.1/make -C "/home/user/heads/build/gawk-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/gawk.log" \
	> /dev/null
user@heads-tests:~/heads$ 

So adding an all: bootstrap target early:

diff --git a/Makefile b/Makefile
index 6ac87a37..71a8fbd7 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,8 @@ ifeq "" "$(filter $(LOCAL_GAWK_MAJOR_VERSION)%,$(gawk_version))"
 $(eval $(shell echo >&2 "$(DATE) Wrong OS deployed gawk detected: $(LOCAL_GAWK_VERSION). Building and using $(gawk_version)..."))
 HEADS_GAWK := $(build)/$(gawk_dir)/gawk
 
+all: bootstrap
+
 # How to download and build the correct version of gawk
 $(packages)/$(gawk_tar):
        $(WGET) -O "[email protected]" "$(gawk_url)"

user@heads-tests:~/heads$ rm -rf build/make-4.2.1/ build/gawk-4.2.1/
user@heads-tests:~/heads$ make BOARD=x230-hotp-maximized
2022-03-02 14:30:22-05:00 Wrong OS deployed make detected: 4.3. Building and using 4.2.1...
2022-03-02 14:30:22-05:00 Wrong OS deployed gawk detected: 5.1.0. Building and using 4.2.1...
2022-03-02 14:30:22-05:00 Local built HEADS_GAWK only if different then provided by OS: /home/user/heads/build/gawk-4.2.1/gawk
2022-03-02 14:30:22-05:00 Local built HEADS_MAKE only if different then provided by OS: /home/user/heads/build/make-4.2.1/make
2022-03-02 14:30:22-05:00 Heads build system will call make from now on as: MAKE: /home/user/heads/build/make-4.2.1/make.
Makefile:264: warning: overriding recipe for target 'all'
Makefile:141: warning: ignoring old recipe for target 'all'
tar xf "/home/user/heads/packages/gawk-4.2.1.tar.xz" -C "/home/user/heads/build"
touch "/home/user/heads/build/gawk-4.2.1/.extract"
touch "/home/user/heads/build/gawk-4.2.1/.patch"
cd "/home/user/heads/build/gawk-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/gawk.configure.log" \
> /dev/null
touch "/home/user/heads/build/gawk-4.2.1/.configured"
/home/user/heads/build/make-4.2.1/make -C "/home/user/heads/build/gawk-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/gawk.log" \
	> /dev/null
make: *** [Makefile:134: /home/user/heads/build/gawk-4.2.1/gawk] Error 127

Applying all: bootstrap target late:

user@heads-tests:~/heads$ git diff
diff --git a/Makefile b/Makefile
index 6ac87a37..71aa7f6e 100644
--- a/Makefile
+++ b/Makefile
@@ -705,3 +705,5 @@ real.clean:
                fi; \
        done
        cd install && rm -rf -- *
+
+all: bootstrap
user@heads-tests:~/heads$ rm -rf build/make-4.2.1/ build/gawk-4.2.1/
user@heads-tests:~/heads$ make BOARD=x230-hotp-maximized
2022-03-02 14:38:07-05:00 Wrong OS deployed make detected: 4.3. Building and using 4.2.1...
2022-03-02 14:38:07-05:00 Wrong OS deployed gawk detected: 5.1.0. Building and using 4.2.1...
2022-03-02 14:38:07-05:00 Local built HEADS_GAWK only if different then provided by OS: /home/user/heads/build/gawk-4.2.1/gawk
2022-03-02 14:38:07-05:00 Local built HEADS_MAKE only if different then provided by OS: /home/user/heads/build/make-4.2.1/make
2022-03-02 14:38:07-05:00 Heads build system will call make from now on as: MAKE: /home/user/heads/build/make-4.2.1/make.
Makefile:262: warning: overriding recipe for target 'all'
Makefile:139: warning: ignoring old recipe for target 'all'
tar xf "/home/user/heads/packages/gawk-4.2.1.tar.xz" -C "/home/user/heads/build"
touch "/home/user/heads/build/gawk-4.2.1/.extract"
touch "/home/user/heads/build/gawk-4.2.1/.patch"
cd "/home/user/heads/build/gawk-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/gawk.configure.log" \
> /dev/null
touch "/home/user/heads/build/gawk-4.2.1/.configured"
/home/user/heads/build/make-4.2.1/make -C "/home/user/heads/build/gawk-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/gawk.log" \
	> /dev/null
make: *** [Makefile:132: /home/user/heads/build/gawk-4.2.1/gawk] Error 127

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 2, 2022

@SergiiDmytruk :
Haaaaaaa.

So all: bootstrap; it is. Thanks for the lesson! Really appreciated!

user@heads-tests:~/heads$ git diff

diff --git a/Makefile b/Makefile
index 6ac87a37..1344adb5 100644
--- a/Makefile
+++ b/Makefile
@@ -143,6 +143,9 @@ all linux cpio run: $(HEADS_GAWK)
 bootstrap: $(HEADS_GAWK)
 endif
 
+#We want to make sure we build bootstrap if needed in all cases.
+all: bootstrap;
+
 BOARD          ?= qemu-coreboot
 CONFIG         := $(pwd)/boards/$(BOARD)/$(BOARD).config
 
user@heads-tests:~/heads$ rm -rf build/make-4.2.1/ build/gawk-4.2.1/
user@heads-tests:~/heads$ make BOARD=x230-hotp-maximized
2022-03-02 14:43:56-05:00 Wrong OS deployed make detected: 4.3. Building and using 4.2.1...
2022-03-02 14:43:56-05:00 Wrong OS deployed gawk detected: 5.1.0. Building and using 4.2.1...
Makefile:147: warning: overriding recipe for target 'all'
Makefile:139: warning: ignoring old recipe for target 'all'
2022-03-02 14:43:56-05:00 Local built HEADS_GAWK only if different then provided by OS: /home/user/heads/build/gawk-4.2.1/gawk
2022-03-02 14:43:56-05:00 Local built HEADS_MAKE only if different then provided by OS: /home/user/heads/build/make-4.2.1/make
2022-03-02 14:43:56-05:00 Heads build system will call make from now on as: MAKE: /home/user/heads/build/make-4.2.1/make.
Makefile:265: warning: overriding recipe for target 'all'
Makefile:147: warning: ignoring old recipe for target 'all'
tar xf "/home/user/heads/packages/make-4.2.1.tar.bz2" -C "/home/user/heads/build"
touch "/home/user/heads/build/make-4.2.1/.extract"
( cd "/home/user/heads/build/make-4.2.1/" ; patch -p1 ) < "patches/make-4.2.1.patch"
patching file glob/glob.c
Hunk #1 succeeded at 208 with fuzz 2.
touch "/home/user/heads/build/make-4.2.1/.patch"
cd "/home/user/heads/build/make-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/make.configure.log" \
> /dev/null
touch "/home/user/heads/build/make-4.2.1/.configured"
make -C "/home/user/heads/build/make-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/make.log" \
	> /dev/null
tar xf "/home/user/heads/packages/gawk-4.2.1.tar.xz" -C "/home/user/heads/build"
touch "/home/user/heads/build/gawk-4.2.1/.extract"
touch "/home/user/heads/build/gawk-4.2.1/.patch"
cd "/home/user/heads/build/gawk-4.2.1/" ; \
./configure 2>&1 \
| tee "/home/user/heads/build/log/gawk.configure.log" \
> /dev/null
touch "/home/user/heads/build/gawk-4.2.1/.configured"
/home/user/heads/build/make-4.2.1/make -C "/home/user/heads/build/gawk-4.2.1/" -j2 --max-load 16 \
	2>&1 \
	| tee "/home/user/heads/build/log/gawk.log" \
	> /dev/null
/home/user/heads/build/make-4.2.1/make -C "/home/user/heads/build/coreboot-4.13" CPUS=2 crossgcc-i386
make[1]: Entering directory '/home/user/heads/build/coreboot-4.13'
Welcome to the coreboot cross toolchain builder v ()

Building toolchain using 2 thread(s).

Target architecture is i386-elf

Found compatible Ada compiler, enabling Ada support by default.

Downloading and verifying tarballs ...
 * gmp-6.2.0.tar.xz (cached)... hash verified (052a5411dc74054240eec58132d2cf41211d0ff6)
 * mpfr-4.1.0.tar.xz (cached)... hash verified (159c3a58705662bfde4dc93f2617f3660855ead6)
 * mpc-1.2.0.tar.gz (cached)... hash verified (0abdc94acab0c9bfdaa391347cdfd7bbdb1cf017)
 * binutils-2.35.tar.xz (cached)... hash verified (6bdd090ce268b6d6c3442516021c4e4b5019e303)
 * gcc-8.3.0.tar.xz (cached)... hash verified (c27f4499dd263fe4fb01bcc5565917f3698583b2)
Downloaded tarballs ... ok
Unpacking and patching ...
 * gmp-6.2.0.tar.xz
   o gmp-6.2.0_generic-build.patch
 * mpfr-4.1.0.tar.xz
 * mpc-1.2.0.tar.gz
 * binutils-2.35.tar.xz
^CStop
make[3]: *** [Makefile:26: build_gcc] Error 1
make[2]: *** [Makefile:51: build-i386] Interrupt
make[1]: *** [util/crossgcc/Makefile.inc:34: crossgcc-i386] Interrupt
make: *** [modules/coreboot:85: "/home/user/heads/build/coreboot-4.13/.xcompile"] Interrupt

@tlaurion tlaurion force-pushed the fix_gawk_dependency_on_local_make branch from 9f062ae to 4e57d3f Compare March 2, 2022 20:00
@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 2, 2022

@SergiiDmytruk

Before, we were having locally built gawk sha256sum in hashes.txt. Now we have make.

What i'm looking for is what went wrong under 7ce12fe causing rom sha256sum output to not be part of generated hashes.txt anymore. This is now replaced by gawk/make in hashes.txt as of now and since that commit.

Don't see anything obvious, would need to reduce Makefile to debug this.

This is the change that was applied between parent commit c096a1f (generates rom sha256sum under hashes.txt correctly) and culprit commit 7ce12fe (which doesn't and generated gawk sha256sum instead):

user@heads-tests:~/heads$ git diff c096a1f54d828022a6b8b845b276345316fda63e 7ce12fe621fe95a460c2c5b0038ab12ad6b3b7b0  > diff
user@heads-tests:~/heads$ cat diff
diff --git a/Makefile b/Makefile
index 10faebf7..fd76b057 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,58 @@ DATE=`date --rfc-3339=seconds`
 
 # This is the correct version of Make
 
+# Check we have a suitable version of gawk
+# that's at least the same major version
+LOCAL_GAWK_VERSION := $(shell gawk --version 2>/dev/null | head -1 | cut -d' ' -f3 | cut -d, -f1)
+LOCAL_GAWK_MAJOR_VERSION := $(patsubst .%,.,$(LOCAL_GAWK_VERSION))
+include modules/gawk
+
+# Wrong version
+ifeq "" "$(filter $(LOCAL_GAWK_MAJOR_VERSION).%,$(gawk_version))"
+# Wrong gawk version detected -- build our local version
+# and re-invoke the Makefile with it instead.
+$(eval $(shell echo >&2 "$(DATE) Wrong gawk detected: $(LOCAL_GAWK_VERSION)"))
+HEADS_GAWK := $(build)/$(gawk_dir)/gawk
+
+# Once we have a suitable version of gawk, we can rerun make
+all linux cpio run: $(HEADS_GAWK)
+	LANG=C HEADS_GAWK=$(HEADS_GAWK) $(MAKE) $(MAKE_JOBS) $@
+%.clean %.vol %.menuconfig: $(HEADS_GAWK)
+	LANG=C HEADS_GAWK=$(HEADS_GAWK) $(MAKE) $@
+
+bootstrap: $(HEADS_GAWK)
+
+# How to download and build the correct version of gawk
+$(packages)/$(gawk_tar):
+	$(WGET) -O "[email protected]" "$(gawk_url)"
+	if ! echo "$(gawk_hash)  [email protected]" | sha256sum --check -; then \
+		exit 1 ; \
+	fi
+	mv "[email protected]" "$@"
+
+$(build)/$(gawk_dir)/.extract: $(packages)/$(gawk_tar)
+	tar xf "$<" -C "$(build)"
+	touch "$@"
+
+$(build)/$(gawk_dir)/.patch: $(build)/$(gawk_dir)/.extract
+#	( cd "$(dir $@)" ; patch -p1 ) < "patches/gawk-$(gawk_version).patch"
+	touch "$@"
+
+$(build)/$(gawk_dir)/.configured: $(build)/$(gawk_dir)/.patch
+	cd "$(dir $@)" ; \
+	./configure 2>&1 \
+	| tee "$(log_dir)/gawk.configure.log" \
+	$(VERBOSE_REDIRECT)
+	touch "$@"
+
+$(HEADS_GAWK): $(build)/$(gawk_dir)/.configured
+	$(MAKE) -C "$(dir $@)" $(MAKE_JOBS) \
+		2>&1 \
+		| tee "$(log_dir)/gawk.log" \
+		$(VERBOSE_REDIRECT)
+endif
+
+
 BOARD		?= qemu-coreboot
 CONFIG		:= $(pwd)/boards/$(BOARD)/$(BOARD).config
 
@@ -124,6 +176,10 @@ CROSS_TOOLS_NOCC := \
 	PKG_CONFIG_PATH="$(INSTALL)/lib/pkgconfig" \
 	PKG_CONFIG_SYSROOT_DIR="$(INSTALL)" \
 
+ifneq "$(HEADS_GAWK)" ""
+CROSS_TOOLS_NOCC += AWK=$(HEADS_GAWK)
+endif
+
 CROSS_TOOLS := \
 	CC="$(heads_cc)" \
 	$(CROSS_TOOLS_NOCC) \
diff --git a/modules/gawk b/modules/gawk
new file mode 100644
index 00000000..e51b8ab5
--- /dev/null
+++ b/modules/gawk
@@ -0,0 +1,14 @@
+# This is not added to the module list since it is a special case
+# of things that need to be built for the host system, instead of the
+# target platform.
+#modules += gawk
+
+gawk_version := 4.2.1
+gawk_dir := gawk-$(gawk_version)
+gawk_tar := gawk-$(gawk_version).tar.xz
+
+gawk_url := http://gnu.mirror.constant.com/gawk/$(gawk_tar)
+gawk_hash := d1119785e746d46a8209d28b2de404a57f983aa48670f4e225531d3bdc175551
+
+# This is built for the local machine, not the target, so it doesn't have any
+# of the build instructions.

@SergiiDmytruk any insight on what happened to this all target :

all:
        @sha256sum $< | tee -a "$(HASHES)"

Which for some reason doesn't apply to coreboot produced rom since that culprit commit?

@SergiiDmytruk : this comment #1128 (comment) (section Traces) gives direct hashes.txt output for the same before/after commits.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 2, 2022

@SergiiDmytruk : unfortunately 4e57d3f, implementing:
all: bootstrap;

Also hits the all: sha256sum target and fails with:

# Use coreboot.rom, because custom output files might not be processed by cbfstool
"/home/user/heads/build/coreboot-4.13/x230-hotp-maximized/cbfstool" "/home/user/heads/build/coreboot-4.13/x230-hotp-maximized/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           85100 none
cpu_microcode_blob.bin         0x14d80    microcode       26624 none
fallback/ramstage              0x1b600    stage           97721 none
config                         0x33400    raw               790 none
revision                       0x33780    raw               695 none
fallback/dsdt.aml              0x33a80    raw             14615 none
vbt.bin                        0x37400    raw              1433 LZMA (4281 decompressed)
cmos_layout.bin                0x37a00    cmos_layout      1884 none
fallback/postcar               0x381c0    stage           25816 none
fallback/payload               0x3e700    simple elf    7293383 none
(empty)                        0x733100   null          4377752 none
bootblock                      0xb5fdc0   bootblock       65536 none
2022-03-02 15:36:23-05:00 INSTALL   build/coreboot-4.13/x230-hotp-maximized/coreboot.rom => build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1.rom
2022-03-02 15:36:23-05:00 UNCHANGED build/coreboot-4.13/x230-hotp-maximized/coreboot.rom
f7c008454519babb3c6b33ea697044f47fcb0f81454fdf4b52b64613d7a53fbc  build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1.rom
2022-03-02 15:36:23-05:00 DD 8MB build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1-bottom.rom
cb6eae73ec126dac1ec1546cdb16444e086673cb85e5fb1900b6ed56f28d321d  /home/user/heads/build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1-bottom.rom
2022-03-02 15:36:23-05:00 DD 4MB build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1-top.rom
ed97a0541c421cac32de6b82b295943cc3c67d654f544b1094ac5a3629a5d8ca  /home/user/heads/build/x230-hotp-maximized/heads-x230-hotp-maximized-v0.2.1.bis2-38-g4e57d3f1-top.rom
sha256sum: bootstrap: No such file or directory
make: *** [Makefile:265: all] Error 1

So it seems that 9f062ae was a better implementation, or that all: bootstrap; should be written differently?

@SergiiDmytruk
Copy link
Contributor

@tlaurion Try making it an order-only prerequisite like this:

all: | bootstrap;

This way it won't appear in automatic variables $< or $^. That trailing ; isn't necessary in most cases, unless you have whitespace on the next line or the target comes from a rule like %.o: %.c, or you want to make absence of recipe explicit.

@SergiiDmytruk
Copy link
Contributor

SergiiDmytruk commented Mar 2, 2022

What i'm looking for is what went wrong under 7ce12fe causing rom sha256sum output to not be part of generated hashes.txt anymore. This is now replaced by gawk/make in hashes.txt as of now and since that commit.

@tlaurion Same problem, probably should be:

all linux cpio run: | $(HEADS_GAWK)

Mind that this prevents targets from being rebuilt when gawk is updated.

Probably a better alternative for both issues would be to use normal prerequisites and specify rom file as a variable rather than abusing prerequisites:

ifeq ($(CONFIG_COREBOOT), y)
all: $(build)/$(BOARD)/$(CB_OUTPUT_FILE)
else ifeq ($(CONFIG_LINUXBOOT), y)
all: $(build)/$(BOARD)/$(LB_OUTPUT_FILE)

Then use it instead of $< for sha256sum, this should prevent this issue reappearing in the future.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 4, 2022

As of now, I can't implement correctly any suggestions of @SergiiDmytruk, ordering not being respected. I get the same result of having only gawk attempted to be built(which should require make built first), unless 9f062ae is implemented. But we still have lost ROM hash under hashes.txt doing that.

My current intuition to improve further then 9f062ae would be to move make and gawk build instructions to their individual modules files and have their install/ path hardcoded (instead of their current build/ counterpart) and passed to the rest of the builds from the global Makefile.

Modules binaries and libraries are hashed and outputted under hashes.txt when deployed to their final directories (./bin ./lib etc), and for those to happen, then need to be referred in boards, added in Makefile explicit inclusion statements from boards specified variables. I think adding gawk (for libgpg-error if I recall well) was added in Makefile because it might have been the easiest thing to do, but it broke other things, like removing board final ROMs hashes under hashes.txt.

Tinkering with the actual Make file makes my eyes and brain bleed and is not properly understood by anyone who seem to dare looking at it or improving it without having other things breaking. We are, as @SergiiDmytruk said, really abusing prerequisites as if now and understanding what is going on is really not easy to do, making Heads hard to maintain. I separated gawk from make version test condition since having make at version 4.2.1 was not a guarantee that gawk would also be in version 4.2.1. Then after moving away from Debian-10 to debian-11 docker image, I realized that gawk version test was flawed, and passed as good even if gawk was not installed on host. Then recently, a user reported that building from a clean commit was not working, since gawk was built without make having been locally built. This is what 9f062ae is fixing, while not fixing the whole problem. It also seems that LANG C is not filled correctly, @SergiiDmytruk is right, MAKE_OPTIONS is not filled correctly, and the path to make local binary is passed twice. This has no intended good effect since perl is rolling back to default LANG statement...

It would need a rewrite by someone having the right qualifications or at least have the current process properly documented. Otherwise, its not maintained, because its not currently maintainable.

…pected version.

Maximized boards: have rom hashes outputted under hashes.txt. Still not clear why the Makefile "all" target is not doing that for each target.

- Fixes a bug where "make BOARD=xyz bootstrap" was needed prior of being able to build anything else otherwise HEADS_GAWK was expecting HEADS_MAKE to be built already, which was not the case.
(fixes linuxboot#1126)

- As of now, I do not see any OS make/gawk being used anymore. All modules except coreboot (which uses coreboot buildstack), including musl-cross-make, are being built with local make and local gawk.
Improves linuxboot#936 (comment) which showed that local make (/usb/bin/make, /usr/local/bin/make, /usr/sbin/make, /usr/local/sbin/make and /usr/bin/gawk were called locally. To redo)
@tlaurion tlaurion force-pushed the fix_gawk_dependency_on_local_make branch from 4e57d3f to 790671f Compare March 4, 2022 20:10
@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 4, 2022

@SergiiDmytruk @MrChromebox :
790671f

  • This patch on top of master fixes the mess, outputing hashes correctly under hashes.txt for x230-maximized board, taken as an example. This would mean that all other boards generating multiple roms would also need to be modified, if that is the way to do so.

    • Not sure, here again, why past "all" targets that were defined under board config were not generating the hashes by themselves; only for board generic target or the first all target defined under board config. This is why I had to add the @sha256sum statement in board configs in the past.... and I just realized it was only outputting on console and not in hashes.txt. @SergiiDmytruk any insights on why? From my understanding, https://github.com/osresearch/heads/blob/790671f1259e288f771233105c973b70c090c3ac/Makefile#L259-L260 should produce hashes under hashes.txt for all boards produced roms under board's config all targets? Is there anything i'm missing?
  • I am not clear either on what was attempted by attempting to set LANG = "C MAKE=/home/user/heads/build/make-4.2.1/make" GAWK=/home/user/heads/build/gawk-4.2.1/gawk and $(MAKE_JOBS), which was not passed correctly, while $@ is referring to either heads.cpio or tools.cpio which doesn;t make any sense... Which is why I removed them.

Comments? Recommendations?

@SergiiDmytruk
Copy link
Contributor

@tlaurion

I think you want to add

ifneq "$(HEADS_MAKE)" ""
$(HEADS_GAWK): | $(HEADS_MAKE)
endif

to make local gawk actually depend on local make, otherwise they can be built in parallel.

$@ is what passes target name to the nested make command, without it, default target will probably be used every time.

$< expands to only the first prerequisite.

Another cause of the trouble is that recipes are actually redefined (that warning: overriding recipe for target 'all'), which is a problem because earlier definitions are ignored, so those LANG=C HEADS_GAWK=$(HEADS_GAWK) ... commands are probably never executed.

I think (but not sure) it might help to split Makefile into two files:

  1. Makefile, which ensures correct environment and then invokes the second one. I think the invocation should look something like the following:
    export HEADS_GAWK
    ifneq "$(HEADS_MAKE)" ""
        MAKE=$(HEADS_MAKE)
    endif
    
    %: bootstrap
        LANG=C $(MAKE) -f Makefile.main $@
    bootstrap: ;
  2. Makefile.main, which assumes correct environment and just uses it.

This should help avoid redefining targets.

tlaurion added 2 commits March 7, 2022 13:51
…e hashes outputted into hashes.txt

Makefile: make sure of precedence, even if parallelized builds of local make prior of local gawk
… not found.

Weird: If we remove the target CB_OUTPUT target on maximized boards, gawk and make are built, but there are missing hashes under hashes.txt
If we add CB_OUTPUT in boards, then make and gawk are not built.

Here, without having time to dig that problem more, we choose to warn user to bootstrap first if there is an error, and have hashes under hashes.txt.
Again folks. Your make fu is needed. I think I won't be able to bring that any further.
@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 7, 2022

@SergiiDmytruk @MrChromebox :
As of now, I can only have all the rom hashes outputted under hashes.txt OR have make and gawk automatically built as prerequisites.

So I now invite the user to build bootstrap first if there is discrepancy between deployed gawk and make from OS and expected local built ones, so we keep rom hashes under hashes.txt which is now added statements in all maximized boards configs so they output the hashes themselves into hashes.txt.

My attempts to separate Makefile to Makefile.inc as suggested under #1128 (comment) didn't resolve the issue. And I have spent way too much time here, I am not the right resource to resolve this issue.

I am not sure I can bring this farther then c8cf23f.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 28, 2022

https://github.com/osresearch/heads/blob/182bd6bd7517c8e322bc4712db01906b41cce58c/Makefile#L580-L591

Seems to show guideline on having precedence. Why make and gawk IN the Makefile and not outside as all other modules seems to be problematic.

Single ROM boards do not need to generate the checksums themselves; the ones having multiple ones need to create those hashes manually in the board config.

@tlaurion
Copy link
Collaborator Author

Replaced by #1178

@tlaurion tlaurion closed this Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error 1 and Error 127 on Build (make bootstrap needed prior of building anything else)

2 participants