From 68a25e0bfeecea461852ceef12b7534eefa44a16 Mon Sep 17 00:00:00 2001
From: Jens Wiklander <jens.wiklander@linaro.org>
Date: Tue, 23 Jun 2020 15:09:20 +0200
Subject: [PATCH] Add support for gp-suite in optee_test

By passing GP_PACKAGE=<path to GP-suite archive> optee_test is
configured to compile with the GlobalPlatform test suite. The test suite
is unpacked and patched in the build directory as part of the buildroot
process when building optee_test.

Acked-by: Joakim Bech <joakim.bech@linaro.org>
Acked-by: Jerome Forissier <jerome@forissier.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
---
 br-ext/package/optee_test_ext/Config.in       | 13 ++++++++
 .../package/optee_test_ext/optee_test_ext.mk  | 30 +++++++++++++++++++
 common.mk                                     |  1 +
 3 files changed, 44 insertions(+)

diff --git a/br-ext/package/optee_test_ext/Config.in b/br-ext/package/optee_test_ext/Config.in
index d80abdd..d3fa2a7 100644
--- a/br-ext/package/optee_test_ext/Config.in
+++ b/br-ext/package/optee_test_ext/Config.in
@@ -24,4 +24,17 @@ config BR2_PACKAGE_OPTEE_TEST_EXT_CROSS_COMPILE
 	help
 	  some help
 
+config BR2_PACKAGE_OPTEE_TEST_EXT_GP_PACKAGE
+	string "GP package"
+	default ""
+	help
+	  Path to the GlobalPlatform package containing description files
+	  and TAs needed to build the complete GP test suite. The package
+	  is free for GP members, but can be acquired directly from
+	  GlobalPlatform for non-members. See
+	  https://globalplatform.org/test-suites/tee-initial-configuration-test-suite-with-excluded-tests-list/
+	  The name of the package is currently "TEE Initial Configuration
+	  Test Suite with Excluded Tests List v2.0.0.2" with the file name
+	  TEE_Initial_Configuration-Test_Suite_v2_0_0_2-2017_06_09.7z
+
 endif
diff --git a/br-ext/package/optee_test_ext/optee_test_ext.mk b/br-ext/package/optee_test_ext/optee_test_ext.mk
index c8f73ef..ef12718 100644
--- a/br-ext/package/optee_test_ext/optee_test_ext.mk
+++ b/br-ext/package/optee_test_ext/optee_test_ext.mk
@@ -10,6 +10,16 @@ OPTEE_TEST_EXT_CONF_OPTS = -DOPTEE_TEST_SDK=$(OPTEE_TEST_EXT_SDK)
 OPTEE_TEST_EXT_TAS = os_test_lib os_test_lib_dl os_test *
 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 
+ifneq ($(BR2_PACKAGE_OPTEE_TEST_EXT_GP_PACKAGE),"")
+OPTEE_TEST_EXT_CONF_OPTS += -DWITH_GP_TESTS=1
+OPTEE_TEST_EXT_PRE_CONFIGURE_HOOKS += OPTEE_TEST_EXT_PREPARE_GP_SUITE
+endif
+
+define OPTEE_TEST_EXT_PREPARE_GP_SUITE
+	sh $(@D)/host/xtest/gp/prepare_suite.sh $(@D) \
+		$(BR2_PACKAGE_OPTEE_TEST_EXT_GP_PACKAGE)
+endef
+
 define OPTEE_TEST_EXT_BUILD_TAS
 	@$(foreach f,$(call uniq,$(foreach t,$(OPTEE_TEST_EXT_TAS),$(wildcard $(@D)/ta/$(t)/Makefile))), \
 		echo Building $f && \
@@ -27,7 +37,27 @@ define OPTEE_TEST_EXT_INSTALL_TAS
 			&&) true
 endef
 
+
+define OPTEE_TEST_EXT_BUILD_GP_TAS
+	@$(foreach f,$(wildcard $(shell echo $(@D)/host/xtest/gp-suite/TTAs_Internal_API_1_1_1/*/*/{*/,}code_files/Makefile)), \
+		echo Building $f && \
+			$(MAKE) CROSS_COMPILE="$(shell echo $(BR2_PACKAGE_OPTEE_TEST_EXT_CROSS_COMPILE))" \
+			O=out TA_DEV_KIT_DIR=$(OPTEE_TEST_EXT_SDK) \
+			$(TARGET_CONFIGURE_OPTS) -C $(dir $f) all &&) true
+
+endef
+
+define OPTEE_TEST_EXT_INSTALL_GP_TAS
+	@$(foreach f,$(wildcard $(shell echo $(@D)/host/xtest/gp-suite/TTAs_Internal_API_1_1_1/*/*/{*/,}code_files/out/*.ta)), \
+		mkdir -p $(TARGET_DIR)/lib/optee_armtz && \
+		$(INSTALL) -v -p  --mode=444 \
+			--target-directory=$(TARGET_DIR)/lib/optee_armtz $f \
+			&&) true
+endef
+
 OPTEE_TEST_EXT_POST_BUILD_HOOKS += OPTEE_TEST_EXT_BUILD_TAS
+OPTEE_TEST_EXT_POST_BUILD_HOOKS += OPTEE_TEST_EXT_BUILD_GP_TAS
 OPTEE_TEST_EXT_POST_INSTALL_TARGET_HOOKS += OPTEE_TEST_EXT_INSTALL_TAS
+OPTEE_TEST_EXT_POST_INSTALL_TARGET_HOOKS += OPTEE_TEST_EXT_INSTALL_GP_TAS
 
 $(eval $(cmake-package))
diff --git a/common.mk b/common.mk
index 225521a..169b99c 100644
--- a/common.mk
+++ b/common.mk
@@ -265,6 +265,7 @@ BR2_PACKAGE_OPTEE_TEST_EXT ?= y
 BR2_PACKAGE_OPTEE_TEST_EXT_CROSS_COMPILE ?= $(CROSS_COMPILE_S_USER)
 BR2_PACKAGE_OPTEE_TEST_EXT_SDK ?= $(OPTEE_OS_TA_DEV_KIT_DIR)
 BR2_PACKAGE_OPTEE_TEST_EXT_SITE ?= $(OPTEE_TEST_PATH)
+BR2_PACKAGE_OPTEE_TEST_EXT_GP_PACKAGE := $(GP_PACKAGE)
 BR2_PACKAGE_STRACE ?= y
 BR2_TARGET_GENERIC_GETTY_PORT ?= $(if $(CFG_NW_CONSOLE_UART),ttyAMA$(CFG_NW_CONSOLE_UART),ttyAMA0)
 
-- 
GitLab