payloads/tianocore: default to MrChromebox's working branch

Rather than attempt to maintain patches against upstream Tianocore, use
MrChromebox's coreboot framebuffer branch as the default build target.

Rework the Makefile to default to MrChromebox's coreboot_fb branch, but
also allow for aribitrary commits from upstream Tianocore to be used
as build targets.

Ensure the branch is synced on each build, as long as working directory
is clean, and that switching between commits or trees is handled sanely.

Eliminate TIANOCORE_MASTER as a selectable build target, since unpatched
it is unlikely to boot on any device. It can easily be specified via
the 'revision' option if desired.

Test: build for the default stable target, for upstream/master
as the specified revision, and for an arbitrary valid commit hash.

Change-Id: I4a83db3cd64c7d5b652c6e95780d10051f143e88
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/31543
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/payloads/external/tianocore/Makefile b/payloads/external/tianocore/Makefile
index bd02f48..87c48b1 100644
--- a/payloads/external/tianocore/Makefile
+++ b/payloads/external/tianocore/Makefile
@@ -16,15 +16,15 @@
 # force the shell to bash - the edksetup.sh script doesn't work with dash
 export SHELL := env bash
 
-# STABLE_COMMIT_ID represent official edk2 release, currently UDK2018
-STABLE_COMMIT_ID=3e72ffe8afdd03f1f89eba65c921cbdcb004cfee
-TAG-$(CONFIG_TIANOCORE_MASTER)=origin/master
-TAG-$(CONFIG_TIANOCORE_STABLE)=$(STABLE_COMMIT_ID)
-TAG-$(CONFIG_TIANOCORE_REVISION)=$(CONFIG_TIANOCORE_REVISION_ID)
-
 project_name=Tianocore
 project_dir=$(CURDIR)/tianocore
-project_git_repo=https://github.com/tianocore/edk2
+project_git_repo=https://github.com/mrchromebox/edk2
+project_git_branch=coreboot_fb
+upstream_git_repo=https://github.com/tianocore/edk2
+
+# 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)
 
 export EDK_TOOLS_PATH=$(project_dir)/BaseTools
 
@@ -44,39 +44,28 @@
 	BUILD_STR=-a IA32 -a X64 -t COREBOOT -p CorebootPayloadPkg/CorebootPayloadPkgIa32X64.dsc -b $(BUILD_TYPE) $(TIMER)
 endif
 
-all: build
+all: clean build
 
 $(project_dir):
 	echo "    Cloning $(project_name) from Git"
-	git clone $(project_git_repo) $(project_dir)
+	git clone --single-branch --branch $(project_git_branch) $(project_git_repo) $(project_dir); \
+		cd $(project_dir); \
+		git remote add upstream $(upstream_git_repo)
 
-fetch: $(project_dir)
-	cd $(project_dir); \
-		git show $(TAG-y) >/dev/null 2>&1 ; \
-		if [ $$? -ne 0 ] || [ "$(TAG-y)" = "origin/master" ]; then \
-			echo "    Fetching new commits from the $(project_name) repo"; \
-			git fetch; \
-		fi
-
-$(project_dir)/.version_$(TAG-y): fetch
-	if  ! [[ -e $(project_dir)/.version_$(STABLE_COMMIT_ID) ]] || \
-		[ "$(TAG-y)" = "origin/master" ] ; then \
-		rm -f .version_*; \
-		echo "    Checking out $(project_name) revision $(TAG-y)"; \
-		cd  $(project_dir); \
-			git checkout master; \
-			git branch -D coreboot 2>/dev/null; \
-			git checkout -b coreboot $(TAG-y); \
-		for patch in $(CURDIR)/patches/*.patch; do \
-			echo "Applying $$patch"; \
-			cd $(project_dir); \
-			git am --keep-cr --ignore-space-change $$patch || \
-				( echo " Error when applying patches.\n"; git am --abort; exit 1; ); \
-		done; \
-		if ! [ "$(TAG-y)" = "origin/master" ] ; then \
-			touch $(project_dir)/.version_$(STABLE_COMMIT_ID); \
+update: $(project_dir)
+	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"; \
+			exit 1; \
 		fi; \
-	fi; \
+		if git describe --all --dirty | grep -qv dirty; then \
+			echo "    Checking out $(project_name) revision $(TAG-y)"; \
+			git checkout --detach $(TAG-y); \
+		else \
+			echo "    Working directory not clean; will not overwrite"; \
+		fi
 
 checktools:
 	echo "Checking uuid-dev..."
@@ -89,7 +78,7 @@
 	type nasm > /dev/null 2>&1 && echo " found nasm." || \
 		( echo " Not found."; echo "Error: Please install nasm."; exit 1 )
 
-build: $(project_dir)/.version_$(TAG-y) checktools
+build: update checktools
 	unset CC; $(MAKE) -C $(project_dir)/BaseTools
 	echo " build $(project_name) $(TAG-y)"
 	cd $(project_dir); \
@@ -109,4 +98,4 @@
 distclean:
 	rm -rf $(project_dir)
 
-.PHONY: all fetch checkout checktools config build clean distclean
+.PHONY: all update checktools config build clean distclean