payloads/tianocore: Enable UEFIPayload

corebootpayload package in upstream TianoCore was replaced with
UEFIPayload, add external payload build option for UEFIPayload.

BUG=N/A
TEST=Select TianoCore payload as UEFIPayload, build and able to boot up on
QEMU q35 after PCIE_BASE set.

Change-Id: I0b7785fde9f4113b2cd91323ac0358b229c5a6e6
Signed-off-by: Lijian Zhao <lijian.zhao@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34459
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/payloads/external/tianocore/Kconfig b/payloads/external/tianocore/Kconfig
index d8b7d92..7717917 100644
--- a/payloads/external/tianocore/Kconfig
+++ b/payloads/external/tianocore/Kconfig
@@ -7,38 +7,32 @@
 	  The result of a corebootPkg build
 
 choice
-	prompt "Tianocore version"
-	default TIANOCORE_STABLE
+	prompt "Tianocore payload"
+	default TIANOCORE_COREBOOTPAYLOAD
 	help
-	  Select which version of Tianocore to build (default is to build stable)
-	  stable: MrChromebox's customized version of Tianocore which works on most
+	  Select which type of payload Tianocore will build (default is CorebootPayload)
+	  CorebootPayload: MrChromebox's customized version of Tianocore which works on most
 	  (all?) x86_64 devices
-	  revision: use specific commit or branch to build Tianocore (specified by user)
+	  UEFIPayload: Use upstream Tianocore payload from https://github.com/tianocore/edk2
 
-config TIANOCORE_STABLE
-	bool "stable"
+config TIANOCORE_COREBOOTPAYLOAD
+	bool "CorebootPayload"
 	help
 	  Select this option to build using MrChromebox's custom Tianocore tree
 	  i.e. a version of Tianocore that builds without any errors and just works.
 
-config TIANOCORE_REVISION
-	bool "git revision"
+config TIANOCORE_UEFIPAYLOAD
+	bool "UEFIPayload"
 	help
-	  Select this option if you have a specific commit or branch
-	  that you want to use from either MrChromebox's tree or upstream
-	  EDK2 from which to build Tianocore.
-
-	  You will be able to specify the name of a branch or a commit id
-	  later.
+	  Select this option if you want to use upstream EDK2 to build Tianocore.
 
 endchoice
 
 config TIANOCORE_REVISION_ID
 	string "Insert a commit's SHA-1 or a branch name"
-	depends on TIANOCORE_REVISION
-	default "upstream/master"
 	help
-	   The commit's SHA-1 or branch name of the revision to use.
+	   The commit's SHA-1 or branch name of the revision to use. Choose "upstream/master"
+	   for master branch of Tianocore release on github.
 
 choice
 	prompt "Target architecture"
@@ -89,7 +83,7 @@
 
 config TIANOCORE_BOOTSPLASH_IMAGE
 	bool "Use a custom bootsplash image"
-	depends on TIANOCORE_STABLE
+	depends on TIANOCORE_COREBOOTPAYLOAD
 	help
 	  Select this option if you have a bootsplash image that you would
 	  like to be used. If this option is not selected, the default
@@ -98,6 +92,7 @@
 config TIANOCORE_BOOTSPLASH_FILE
 	string "Tianocore Bootsplash path and filename"
 	depends on TIANOCORE_BOOTSPLASH_IMAGE
+	depends on TIANOCORE_COREBOOTPAYLOAD
 	default "bootsplash.bmp"
 	help
 	  The path and filename of the file to use as graphical bootsplash
diff --git a/payloads/external/tianocore/Kconfig.name b/payloads/external/tianocore/Kconfig.name
index a56d248..7b0b300 100644
--- a/payloads/external/tianocore/Kconfig.name
+++ b/payloads/external/tianocore/Kconfig.name
@@ -1,5 +1,5 @@
 config PAYLOAD_TIANOCORE
-	bool "Tianocore coreboot payload package"
+	bool "Tianocore payload"
 	depends on ARCH_X86
 	help
 	  Select this option if you want to build a coreboot image
diff --git a/payloads/external/tianocore/Makefile b/payloads/external/tianocore/Makefile
index f208e59..7adb700 100644
--- a/payloads/external/tianocore/Makefile
+++ b/payloads/external/tianocore/Makefile
@@ -22,9 +22,19 @@
 project_git_branch=coreboot_fb
 upstream_git_repo=https://github.com/tianocore/edk2
 
+ifeq ($(CONFIG_TIANOCORE_UEFIPAYLOAD),y)
+bootloader=UefiPayloadPkg
+build_flavor=-D BOOTLOADER=COREBOOT -D PCIE_BASE=$(CONFIG_MMCONF_BASE_ADDRESS)
+TAG=upstream/master
+else
+bootloader=CorebootPayloadPkg
 # STABLE revision is MrChromebox's coreboot framebuffer (coreboot_fb) branch
-TAG-$(CONFIG_TIANOCORE_STABLE)=origin/$(project_git_branch)
-TAG-$(CONFIG_TIANOCORE_REVISION)=$(CONFIG_TIANOCORE_REVISION_ID)
+TAG=origin/$(project_git_branch)
+endif
+
+ifneq ($(CONFIG_TIANOCORE_REVISION_ID),)
+TAG=$(CONFIG_TIANOCORE_REVISION_ID)
+endif
 
 export EDK_TOOLS_PATH=$(project_dir)/BaseTools
 
@@ -39,9 +49,9 @@
 endif
 
 ifeq ($(CONFIG_TIANOCORE_TARGET_IA32), y)
-	BUILD_STR=-a IA32 -t COREBOOT -p CorebootPayloadPkg/CorebootPayloadPkgIa32.dsc -b $(BUILD_TYPE) $(TIMER)
+	BUILD_STR=-a IA32 -t COREBOOT -p $(bootloader)/$(bootloader)Ia32.dsc -b $(BUILD_TYPE) $(TIMER) $(build_flavor)
 else
-	BUILD_STR=-a IA32 -a X64 -t COREBOOT -p CorebootPayloadPkg/CorebootPayloadPkgIa32X64.dsc -b $(BUILD_TYPE) $(TIMER)
+	BUILD_STR=-a IA32 -a X64 -t COREBOOT -p $(bootloader)/$(bootloader)Ia32X64.dsc -b $(BUILD_TYPE) $(TIMER) $(build_flavor)
 endif
 
 all: clean build
@@ -56,13 +66,13 @@
 	cd  $(project_dir); \
 		echo "    Fetching new commits from the $(project_name) repo"; \
 		git fetch --multiple origin upstream 2>/dev/null; \
-		if ! git rev-parse --verify -q $(TAG-y) >/dev/null; then \
-			echo "    $(TAG-y) is not a valid git reference"; \
+		if ! git rev-parse --verify -q $(TAG) >/dev/null; then \
+			echo "    $(TAG) is not a valid git reference"; \
 			exit 1; \
 		fi; \
 		if git describe --all --dirty | grep -qv dirty; then \
-			echo "    Checking out $(project_name) revision $(TAG-y)"; \
-			git checkout --detach $(TAG-y); \
+			echo "    Checking out $(project_name) revision $(TAG)"; \
+			git checkout --detach $(TAG); \
 		else \
 			echo "    Working directory not clean; will not overwrite"; \
 		fi
@@ -80,7 +90,7 @@
 
 build: update checktools
 	unset CC; $(MAKE) -C $(project_dir)/BaseTools
-	echo " build $(project_name) $(TAG-y)"
+	echo " build $(project_name) $(TAG)"
 	if [ -n $(CONFIG_TIANOCORE_BOOTSPLASH_FILE) ]; then \
 		echo "    Copying custom bootsplash image"; \
 		case "$(CONFIG_TIANOCORE_BOOTSPLASH_FILE)" in \
@@ -99,7 +109,7 @@
 			cat ../tools_def.txt >> $(project_dir)/Conf/tools_def.txt; \
 		fi; \
 		build $(BUILD_STR); \
-		mv $(project_dir)/Build/CorebootPayloadPkg*/*/FV/UEFIPAYLOAD.fd $(project_dir)/Build/UEFIPAYLOAD.fd; \
+		mv $(project_dir)/Build/$(bootloader)*/*/FV/UEFIPAYLOAD.fd $(project_dir)/Build/UEFIPAYLOAD.fd; \
 		git checkout CorebootPayloadPkg/Logo/Logo.bmp > /dev/null 2>&1 || true
 
 clean: