payloads/edk2: Separate the tasks required to build edk2

Separate the tasks that are required to be completed prior to building
edk2 into a prep recipe. This allows this to be used for building
different targets.

This also ensures that the COREBOOT toolchain is used.

Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Change-Id: Ic4ae8ac4118a5747f38297d0fbf4cb53aa3b6d6d
Reviewed-on: https://review.coreboot.org/c/coreboot/+/66359
Reviewed-by: Lean Sheng Tan <sheng.tan@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martin.roth@amd.corp-partner.google.com>
diff --git a/payloads/external/edk2/Makefile b/payloads/external/edk2/Makefile
index 8191a58..7711e72 100644
--- a/payloads/external/edk2/Makefile
+++ b/payloads/external/edk2/Makefile
@@ -170,14 +170,18 @@
 		-e 's/s /Build:          Silent/' \
 		-e 's/t /Toolchain:      /'
 
-build: update print logo checktools
-	unset CC; $(MAKE) -C $(EDK2_PATH)/BaseTools 2>&1
+prep: clean checktools logo update
 	cd $(WORKSPACE); \
-		source $(EDK2_PATH)/edksetup.sh BaseTools; \
+		source $(EDK2_PATH)/edksetup.sh; \
+		unset CC; $(MAKE) -C $(EDK2_PATH)/BaseTools 2>&1; \
 		grep -q "COREBOOT" $(EDK2_PATH)/Conf/tools_def.txt; \
 		if [ $$? -ne 0 ]; then \
 			cat ../tools_def.txt >> $(EDK2_PATH)/Conf/tools_def.txt; \
 		fi; \
+
+build: prep print
+	cd $(WORKSPACE); \
+		source $(EDK2_PATH)/edksetup.sh; \
 		build -b $(RELEASE_STR) $(BUILD_STR); \
 		mkdir -p $(WORKSPACE)/output; \
 		mv $(WORKSPACE)/Build/UefiPayloadPkgX64/$(RELEASE_STR)_COREBOOT/FV/UEFIPAYLOAD.fd $(WORKSPACE)/output