TRUSTLET_DIR := $(KINIBI_TA_BUILD_ROOT)/kinibi_source/tz_iccc/Locals/Code

### Output binary name without path or extension
OUTPUT_NAME := tl_tz_iccc

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### MobiConvert parameters
### For more information about the different parameters, see the "MobiConvert User Manual"
### Mandatory parameters
# uuid (also used as output base file name)
TRUSTLET_UUID := ffffffff000000000000000000000041
# --servicetype <num>
TRUSTLET_SERVICE_TYPE := 3 # 1: driver; 2: service provider trustlet; 3: system trustlet
### Optional parameters
# --flags
TRUSTLET_FLAGS := 0 # 0: no flag; 1: permanent; 2: service has no WSM control interface; 3: both (permanent and service has not WSM control interface); 4: debuggable
# ---numberofinstances <num>
TRUSTLET_INSTANCES := 1 # min: 1; max: 16
# --numberofthreads <num>
TRUSTLET_NO_OF_THREADS := 1 # has to be 1 for Trustlets
# --memtype <type>
TRUSTLET_MEMTYPE := 2 # 0: internal memory prefered; 1: internal memory used; 2: external memory used
#-------------------------------------------------------------------------------
# TA_PROPERTY
# -s : service_type                  driver or TA
# -n : --numberofthreads <integer>   number of threads (1 for Trusted Applications, between 1 and 8 both included for Trusted Drivers)
# -i : --numberofinstances <integer> number of instances (1 for Trusted Drivers, between 1 and 16 both included for Trusted Applications)
# -m : --memtype <integer>           0 = internal memory prefered, 1 = internal memory used, 2 = external memory used
# -f : --flags <integer>             0 = no flag, 1 = permanent, 2 = service has no WSM control interface, 4 = debuggable, add the value of the different flags you wa
#                                    8 = use API Level=5
#-------------------------------------------------------------------------------

$(info [ICCC] Used KINIBI ver $(KINIBI_VERSION))
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Setup configure for signing
ifeq ($(TA_TARGET_SOC), exynos7885)
RUNTYPE := gd_mobicore400_trustlet # $KINIBI_VERSION == "400C"
TRUSTLET_SIGN_CONF := "-s 3 -n 1 -i 1 -m 2 -f 0"
### stack protection 
### __stack_chk_guard and __stack_chk_fail not supported (//CONFIDENTIAL/TRUSTEDAPPS/SDK/KINIBI/exynos7885/400C/t-base-dev-kit/t-sdk/TlSdk/Bin/TlEntry/TlEntry.lib)
SRC_CPP += $(TRUSTLET_DIR)/src/tz_ta_stack_protection.c
ARMCC_STACK_PROTECTION_FLAGS += --protect_stack --protect_stack_all
ARMCC_STACK_PROTECTION_FLAGS += -DTZ_STACK_PROTECTION
else ifeq ($(TA_TARGET_SOC), exynos9810)
RUNTYPE := gd_mobicore400_trustlet # $KINIBI_VERSION == "400C"
TRUSTLET_SIGN_CONF := "-s 3 -n 1 -i 1 -m 2 -f 8" # TBASE_API_LEVEL 5
API_LEVEL := 5
### stack protection 
### __stack_chk_guard and __stack_chk_fail supported (//CONFIDENTIAL/TRUSTEDAPPS/SDK/KINIBI/exynos9810/400C/t-base-dev-kit/t-sdk/TlSdk/Bin/TlEntry/TlEntry.lib)
ENABLE_STACK_PROTECTION := true
ARMCC_COMPILATION_FLAGS += -DENABLE_STACK_PROTECTION
else ifeq ($(TA_TARGET_SOC), mt6768)
RUNTYPE := gd_mobicore410_trustlet # $KINIBI_VERSION == "410A"
TRUSTLET_SIGN_CONF := "-s 3 -n 1 -i 1 -m 2 -f 8" # TBASE_API_LEVEL 5
API_LEVEL := 5
TOOLCHAIN := ARM
else
$(error [ICCC] invalid TA_TARGET_SOC $(TA_TARGET_SOC))
endif

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Build info
ARMCC_COMPILATION_FLAGS += -DTARGET_BUILD_VARIANT=\"$(TARGET_BUILD_VARIANT)\"
ARMCC_COMPILATION_FLAGS += -DKINIBI_VERSION=\"$(KINIBI_VERSION)\"
ARMCC_COMPILATION_FLAGS += -DKINIBI_BUILD_MODEL=\"$(TA_TARGET_SOC)\"

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Build mode (Release/Debug) / Debug default on
MODE := Debug

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# build environment (ARM rvct - T400A_SDK)
# default - TBASE_API_LEVEL 2, ARM rvct
# exynos9810 Q OS initial/MR - TBASE_API_LEVEL 5, ARM rvct (Above Q OS only)
#                            - tlApi_callDriverEx can be supported with FCHandler CL 17207820 (ICCC_API_LEVEL 5)
# mt6768 Q OS initial - TBASE_API_LEVEL 5, ARM rvct
# mt6768 GP TA-TA communication PoC - TBASE_API_LEVEL 11, GNU linaro
#-------------------------------------------------------------------------------
### TBASE_API_LEVEL
ifeq ($(KINIBI_VERSION), 400C)
ifeq ($(API_LEVEL), 5)
### TOOLCHAIN : ARM
TBASE_API_LEVEL := 5
ICCC_API_LEVEL := 5
endif
else ifeq ($(KINIBI_VERSION), 410A)
ifeq ($(API_LEVEL), 5)
### TOOLCHAIN : ARM
TBASE_API_LEVEL := 5
ICCC_API_LEVEL := 5
else ifeq ($(API_LEVEL), 11)
### TOOLCHAIN : GNU (PoC)
TBASE_API_LEVEL := 11
ICCC_API_LEVEL := 11
endif
else
$(error [ICCC] invalid KINIBI ver $(KINIBI_VERSION), API level $(TBASE_API_LEVEL))
endif

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# define platform for this driver
ifeq ($(findstring exynos,$(TA_TARGET_SOC)),exynos)
######## ADD Feature flags here ##########
ARMCC_COMPILATION_FLAGS += -DCONFIG_SMDK$(strip $(subst exynos, ,$(TA_TARGET_SOC)))
else ifeq ($(findstring mt,$(TA_TARGET_SOC)),mt)
######## ADD Feature flags here ##########
ARMCC_COMPILATION_FLAGS += -DCONFIG_MT$(strip $(subst mt, ,$(TA_TARGET_SOC)))
else
$(error [ICCC] invalid TA_TARGET_SOC $(TA_TARGET_SOC))
endif

#-------------------------------------------------------------------------------
# Files and include paths - Add your files here
#-------------------------------------------------------------------------------

### Add include path here
INCLUDE_DIRS += \
    $(TRUSTLET_DIR) \
    $(TRUSTLET_DIR)/inc

### Add source code files for C++ compiler here
SRC_CPP += \
    $(TRUSTLET_DIR)/src/tl_tz_iccc.c \
    $(TRUSTLET_DIR)/src/icccOperations.c \
    $(TRUSTLET_DIR)/src/tl_tz_iccc_init.c

SRC_LIB_C += \
    $(TRUSTLET_DIR)/src/icccOperations.c \
    $(TRUSTLET_DIR)/src/tl_tz_iccc_init.c

### Add source code files for C compiler here
SRC_C += # nothing

### Add source code files for assembler here
SRC_S += # nothing

### Add library files for linker here
#CUSTOMER_DRIVER_LIBS =

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# build environment (GCC linaro - T410A_V003)
# Latest TBASE_API_LEVEL is set by default (Latest level is 11)
# Address layout randomization with TA_PIE by default set to PIE
# Stack canary activated by default
# TOOLCHAIN set to GCC, using GCC 7.1.1
# Warnings as errors with -Wall -Wextra -Werror
#-------------------------------------------------------------------------------
ifneq ($(KINIBI_VERSION), 410A)
### TOOLCHAIN : ARM
### These numbers were obtained from previous warning messages. These will now be treated as errors
ARMCC_COMPILATION_FLAGS += \
    --diag_error=C167,C152,C185,C513,C1254,C1293,C546,C550,C61,C47,C191,C144,C188,C231,C111,C225 #,C223,C1461,C177
endif
ifeq ($(KINIBI_VERSION), 410A)
SRC_CPP += $(TRUSTLET_DIR)/src/snprintf.c
ARMCC_COMPILATION_FLAGS += -DT410
endif
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Use generic make file
#-------------------------------------------------------------------------------
include $(TLSDK_DIR_SRC)/trustlet.mk
