From 2c429d72e7d3478924ce517bd76f149314b04a75 Mon Sep 17 00:00:00 2001
From: Victor Chong <victor.chong@linaro.org>
Date: Tue, 6 Jun 2017 15:10:07 +0100
Subject: [PATCH] hikey_debian: update edk2 with newer build and instructions

Signed-off-by: Victor Chong <victor.chong@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 common.mk       |  5 ++++-
 docs/hikey.md   |  4 +---
 hikey_debian.mk | 32 ++++++++++++++++++++++----------
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/common.mk b/common.mk
index aab8e8e..c13f16c 100644
--- a/common.mk
+++ b/common.mk
@@ -195,8 +195,11 @@ edk2-common: $(EDK2_PATH)/Conf/target.txt
 edk2-clean-common:
 	set -e && cd $(EDK2_PATH) && source edksetup.sh && \
 	$(call edk2-call) clean && \
-	$(MAKE) -j1 -C $(EDK2_PATH)/BaseTools clean && \
+	$(MAKE) -j1 -C $(EDK2_PATH)/BaseTools clean
+	rm -rf $(EDK2_PATH)/Build
+	rm -f $(EDK2_PATH)/Conf/build_rule.txt
 	rm -f $(EDK2_PATH)/Conf/target.txt
+	rm -f $(EDK2_PATH)/Conf/tools_def.txt
 ################################################################################
 # QEMU / QEMUv8
 ################################################################################
diff --git a/docs/hikey.md b/docs/hikey.md
index 811cdcf..1548f38 100644
--- a/docs/hikey.md
+++ b/docs/hikey.md
@@ -61,9 +61,7 @@ flash` step will tell you how you should set the jumpers on the board.
 The intention here was to do almost the same kind of build as the regular where
 the big difference is the kernel in use and the root fs. The kernel currently
 comes from the 96Boards team, but that might change soon again. The root fs is a
-Debian based root file system. In this setup we're also using a pre-built UEFI
-binary. In the long run we would like to change that so we build UEFI from
-scratch in this setup just as we do in other OP-TEE setups.
+Debian based root file system.
 
 In the root fs there is already a couple of OP-TEE binaries included. After
 building the solution one must replace those, since they are a bit dated (see
diff --git a/hikey_debian.mk b/hikey_debian.mk
index 590daea..2043b96 100644
--- a/hikey_debian.mk
+++ b/hikey_debian.mk
@@ -59,9 +59,10 @@ else
 EDK2_BIN 			?= $(EDK2_PATH)/Build/HiKey/RELEASE_GCC49/FV/BL33_AP_UEFI.fd
 EDK2_BUILD			?= RELEASE
 endif
+OPENPLATPKG_PATH		?= $(ROOT)/OpenPlatformPkg
 
 OUT_PATH			?= $(ROOT)/out
-MCUIMAGE_BIN			?= $(EDK2_PATH)/HisiPkg/HiKeyPkg/NonFree/mcuimage.bin
+MCUIMAGE_BIN			?= $(OPENPLATPKG_PATH)/Platforms/Hisilicon/HiKey/Binary/mcuimage.bin
 BOOT_IMG			?= $(OUT_PATH)/boot-fat.uefi.img
 NVME_IMG			?= $(OUT_PATH)/nvme.img
 SYSTEM_IMG			?= $(OUT_PATH)/debian_system.img
@@ -123,26 +124,37 @@ arm-tf-clean:
 ################################################################################
 # EDK2 / Tianocore
 ################################################################################
-EDK2_VARS ?= EDK2_ARCH=AARCH64 \
-		EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
-		EDK2_TOOLCHAIN=GCC49 \
-		EDK2_BUILD=$(EDK2_BUILD)
+EDK2_ARCH ?= AARCH64
+EDK2_DSC ?= OpenPlatformPkg/Platforms/Hisilicon/HiKey/HiKey.dsc
+EDK2_TOOLCHAIN ?= GCC49
 
 EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
 ifeq ($(EDK2_CONSOLE_UART),0)
-	EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
+	EDK2_BUILDFLAGS += -DSERIAL_BASE=0xF8015000
 endif
 
 define edk2-call
 	GCC49_AARCH64_PREFIX=$(LEGACY_AARCH64_CROSS_COMPILE) \
-	$(MAKE) -j1 -C $(EDK2_PATH) \
-		-f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
+	build -n 1 -a $(EDK2_ARCH) -t $(EDK2_TOOLCHAIN) -p $(EDK2_DSC) \
+		-b $(EDK2_BUILD) $(EDK2_BUILDFLAGS)
 endef
 
-edk2: edk2-common
+.PHONY: edk2
+edk2:
+	cd $(EDK2_PATH) && rm -rf OpenPlatformPkg && \
+		ln -s $(OPENPLATPKG_PATH)
+	set -e && cd $(EDK2_PATH) && source edksetup.sh BaseTools && \
+		$(MAKE) -j1 -C $(EDK2_PATH)/BaseTools && \
+		$(call edk2-call)
 
 .PHONY: edk2-clean
-edk2-clean: edk2-clean-common
+edk2-clean:
+	set -e && cd $(EDK2_PATH) && source edksetup.sh BaseTools && \
+		$(MAKE) -j1 -C $(EDK2_PATH)/BaseTools clean
+	rm -rf $(EDK2_PATH)/Build
+	rm -f $(EDK2_PATH)/Conf/build_rule.txt
+	rm -f $(EDK2_PATH)/Conf/target.txt
+	rm -f $(EDK2_PATH)/Conf/tools_def.txt
 
 ################################################################################
 # Linux kernel
-- 
GitLab