payloads/U-Boot: Tidy up the U-Boot build

This doesn't work at present, merely printing an error when U-Boot is
selected as a payload. This is because it adds a file into the U-Boot
tree which makes U-Boot's build system think that the tree is unclean.

Update the rules to put the tag file outside the source tree. Use an
out-of-tree build for U-Boot to avoid changing the source tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: I24d6545b54f97afeefaca3ffed79eec2e7afacb4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/59600
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/payloads/external/Makefile.inc b/payloads/external/Makefile.inc
index 6db1720..151a27c 100644
--- a/payloads/external/Makefile.inc
+++ b/payloads/external/Makefile.inc
@@ -197,7 +197,7 @@
 
 # U-Boot
 
-payloads/external/U-Boot/u-boot/u-boot-dtb.bin u-boot: $(DOTCONFIG)
+payloads/external/U-Boot/build/u-boot/u-boot-dtb.bin u-boot: $(DOTCONFIG)
 	$(MAKE) -C payloads/external/U-Boot \
 			CONFIG_UBOOT_MASTER=$(CONFIG_UBOOT_MASTER) \
 			CONFIG_UBOOT_STABLE=$(CONFIG_UBOOT_STABLE)
diff --git a/payloads/external/U-Boot/Kconfig b/payloads/external/U-Boot/Kconfig
index 9e51ae1..b635bbb 100644
--- a/payloads/external/U-Boot/Kconfig
+++ b/payloads/external/U-Boot/Kconfig
@@ -32,7 +32,7 @@
 	  from the U-Boot config directory
 
 config PAYLOAD_FILE
-	default "payloads/external/U-Boot/u-boot/u-boot-dtb.bin"
+	default "payloads/external/U-Boot/build/u-boot/u-boot-dtb.bin"
 
 config PAYLOAD_OPTIONS
 	default "-l 0x1110000 -e 0x1110015"
diff --git a/payloads/external/U-Boot/Makefile b/payloads/external/U-Boot/Makefile
index 38dfe99..1d1d332 100644
--- a/payloads/external/U-Boot/Makefile
+++ b/payloads/external/U-Boot/Makefile
@@ -9,7 +9,10 @@
 project_name=U-Boot
 project_dir=u-boot
 project_git_repo=http://git.denx.de/u-boot.git
-project_config_file=$(project_dir)/.config
+project_build_dir=build
+project_config_file=$(project_build_dir)/.config
+
+make_args=-C $(project_dir) O=../build
 
 unexport KCONFIG_AUTOHEADER
 unexport KCONFIG_AUTOCONFIG
@@ -31,11 +34,11 @@
 	git fetch
 
 	#master doesn't get a file, so it's continuously updated
-	rm -f $(project_dir)/$(STABLE_COMMIT_ID)
+	rm -f $(STABLE_COMMIT_ID)
 else
 	cd $(project_dir); git show $(TAG-y) >/dev/null 2>&1 ;	if [ $$? -ne 0 ]; \
 	then echo "    Fetching new commits from the $(project_name) git repo"; git fetch; fi
-	touch $(project_dir)/$(STABLE_COMMIT_ID)
+	touch $(STABLE_COMMIT_ID)
 endif
 
 checkout: fetch
@@ -43,26 +46,26 @@
 	cd $(project_dir); git checkout master; git branch -D coreboot 2>/dev/null; git checkout -b coreboot $(TAG-y)
 
 config: checkout
+	mkdir -p $(project_build_dir)
 	rm -f $(project_config_file)
 ifneq ($(CONFIG_PAYLOAD_CONFIGFILE),)
 ifneq ("$(wildcard $(CONFIG_PAYLOAD_CONFIGFILE))","")
 	cat $(CONFIG_PAYLOAD_CONFIGFILE)" > tag-$(project_config_file)
+	$(MAKE) $(make_args) olddefconfig
 else
 	echo "Error: File $(CONFIG_PAYLOAD_CONFIGFILE) does not exist"
 	false
 endif
 else
-	cat $(project_dir)/configs/coreboot_defconfig >> $(project_config_file)
+	$(MAKE) $(make_args) coreboot_defconfig
 endif
 
-	$(MAKE) -C $(project_dir) olddefconfig
-
 build: config
 	echo "    MAKE       $(project_name) $(TAG-y)"
-	$(MAKE) -C $(project_dir)
+	$(MAKE) $(make_args)
 
 clean:
-	test -d $(project_dir) && $(MAKE) -C $(project_dir) clean || exit 0
+	test -d $(project_dir) && $(MAKE) $(make_args) clean || exit 0
 
 distclean:
 	rm -rf $(project_dir)