TRUSTLET_DIR := $(KINIBI_TA_BUILD_ROOT)/kinibi_source/tz_driver/Locals/Code

### this is our home dir
DRIVER_DIR ?= $(KINIBI_TA_BUILD_ROOT)/kinibi_source/tz_driver/Locals/Code
DRLIB_DIR := $(TRUSTLET_DIR)/Api


#-------------------------------------------------------------------------------
# Output
#-------------------------------------------------------------------------------
### output name without path or extension
OUTPUT_NAME := drTima


#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Mobiconvert parameters
DRIVER_UUID := ffffffffd0000000000000000000000a
DRIVER_MEMTYPE := 2 # 0: iram preferred; 1: iram; 2: eram
DRIVER_NO_OF_THREADS := 2 # min =1; max =8
DRIVER_SERVICE_TYPE := 1 # 1: driver; 2: service provider trustlet; 3: system trustlet
DRIVER_KEYFILE := $(TRUSTLET_DIR)/build/pairVendorTltSig.pem
DRIVER_FLAGS:= 0 # 0: no flag; 1: permanent; 2: service has no WSM control interface; 3: both (permanent and service has not WSM control interface)
DRIVER_VENDOR_ID :=0 # Trustonic
DRIVER_NUMBER := 0x40003 # TZ driver
DRIVER_ID := $(shell echo $$(($(DRIVER_VENDOR_ID)<<16|$(DRIVER_NUMBER))))
DRIVER_INTERFACE_VERSION := 1.0

#-------------------------------------------------------------------------------
# DCI handler and trustlet APIs are enabled as default
#-------------------------------------------------------------------------------
USE_DCI_HANDLER ?= YES
USE_TL_API ?= YES

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# 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 [TimaDriver] invalid TA_TARGET_SOC $(TA_TARGET_SOC))
endif



$(info [TimaDriver] Used KINIBI ver $(KINIBI_VERSION))
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Setup configure for signing
ifeq ($(TA_TARGET_SOC), exynos7885)
RUNTYPE := gd_mobicore400_trustlet # $KINIBI_VERSION == "400C"
TRUSTLET_DRV_SIGN_CONF := -conf_str "-s 1 -n 2 -m 2 -f 8 -sh 8192 -mh 65536 -d 262147 -iv 0.0"
TBASE_API_LEVEL := 5
else ifeq ($(TA_TARGET_SOC), exynos9810)
RUNTYPE := gd_mobicore400_trustlet # $KINIBI_VERSION == "400C"
TRUSTLET_DRV_SIGN_CONF := -conf_str "-s 1 -n 2 -m 2 -f 8 -sh 8192 -mh 65536 -d 262147 -iv 0.0"
TBASE_API_LEVEL := 8
else ifeq ($(TA_TARGET_SOC), mt6768)
RUNTYPE := gd_mobicore410_trustlet # $KINIBI_VERSION == "410A"
TRUSTLET_DRV_SIGN_CONF := -conf_str "-s 1 -n 2 -m 2 -f 8 -sh 8192 -mh 65536 -d 262147 -iv 0.0"
TBASE_API_LEVEL := 11
ARMCC_COMPILATION_FLAGS += -W
TOOLCHAIN := ARM
else
$(error [TimaDriver] invalid TA_TARGET_SOC $(TA_TARGET_SOC))
endif
HW_FLOATING_POINT:= Y
HEAP_SIZE_INIT := 8192
HEAP_SIZE_MAX := 65536


ARMCC_COMPILATION_FLAGS += -DTIMA_ADDRESS_CHECK
ARMCC_COMPILATION_FLAGS += -DCONFIG_PKM_SHA256


#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### Build mode (Release/Debug) / Debug default on
MODE := Debug


#-------------------------------------------------------------------------------
# Files and include paths - Add your files here
#-------------------------------------------------------------------------------


ifneq ($(filter smdk7885, $(SEC_PRODUCT)), )
INCLUDE_DIRS += \
		$(KINIBI_TA_BUILD_ROOT)/sdk/scrypto/scrypto_v2.2

ARMCC_COMPILATION_FLAGS +=\
               -DMOBICORE \
               -DTL_DEBUG \
               -DTEST_IN_SWD \
               -DOPENSSL_FIPS \
               -DOPENSSL_NO_LOCKING \
               -DNO_SYS_TYPES_H \
               -DOPENSSL_NO_STDIO \
               -DGETPID_IS_MEANINGLESS \
               -DOPENSSL_EXPORT_VAR_AS_FUNCTION \
			   -DDES_DEFAULT_OPTIONS \
	           -DUSE_SCRYPTO

EXTRA_LIBS += $(TRUSTLET_DIR)/fips/lib/mc_scrypto_drv_exynos8895.lib

SRC_CPP +=\
		  $(TRUSTLET_DIR)/src/process_scrypto.c
endif
ifeq ($(TA_TARGET_SOC), exynos9810)
INCLUDE_DIRS += \
		$(KINIBI_TA_BUILD_ROOT)/sdk/scrypto/scrypto_v2.2/include

SCRYPTO_FIPS_SCRIPT := $(TRUSTLET_DIR)/fips/tools/run_fips_tools.sh

ARMCC_COMPILATION_FLAGS +=\
               -DMOBICORE \
               -DTL_DEBUG \
               -DTEST_IN_SWD \
               -DOPENSSL_FIPS \
               -DOPENSSL_NO_LOCKING \
               -DNO_SYS_TYPES_H \
               -DOPENSSL_NO_STDIO \
               -DGETPID_IS_MEANINGLESS \
               -DOPENSSL_EXPORT_VAR_AS_FUNCTION \
			   -DDES_DEFAULT_OPTIONS \
	           -DUSE_SCRYPTO

EXTRA_LIBS += $(TRUSTLET_DIR)/fips/lib/mc_scrypto_drv_exynos9810.lib

SRC_CPP +=\
		  $(TRUSTLET_DIR)/src/process_scrypto.c

endif


### Add include path here
INCLUDE_DIRS += \
    $(TRUSTLET_DIR) \
    $(TRUSTLET_DIR)/include \
    $(TRUSTLET_DIR)/Api \
    $(TRUSTLET_DIR)/../../../tz_common/FcHandler/inc

SRC_LIB_C += \
        $(TRUSTLET_DIR)/Api/TlApiDrTima.c \

### Add source code files for C++ compiler here
SRC_CPP += \
		   $(TRUSTLET_DIR)/src/drTima.c \
		   $(TRUSTLET_DIR)/src/sha1.c \
		   $(TRUSTLET_DIR)/src/drMobicore.c \
		   $(TRUSTLET_DIR)/src/log.c \
		   $(TRUSTLET_DIR)/src/dashboard.c \
		   $(TRUSTLET_DIR)/src/allowlist.c \
		   $(TRUSTLET_DIR)/src/mst_secdrv.c
ifneq ($(KINIBI_VERSION), 410A)
SRC_CPP += \
		   $(TRUSTLET_DIR)/src/tzasc.c \
		   $(TRUSTLET_DIR)/src/rtic_secdrv.c \
		   $(TRUSTLET_DIR)/src/rt_ks_skip.c
endif

### Add source code files for C compiler here
SRC_C += #nothing

### Add source code files for assembler here
SRC_ASM += # nothing


#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#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


#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
### following flag is required for header files from fc_handler
ifeq ($(TA_TARGET_SOC), exynos7885)
ARMCC_COMPILATION_FLAGS += \
	-DCONFIG_EXYNOS7885
else ifeq ($(TA_TARGET_SOC), mt6768)
ARMCC_COMPILATION_FLAGS += \
	-DCONFIG_MT6768
else ifeq ($(TA_TARGET_SOC), exynos9810)
ARMCC_COMPILATION_FLAGS += \
	-DCONFIG_EXYNOS9810
endif

#-------------------------------------------------------------------------------
# use generic make file
include $(DRSDK_DIR_SRC)/driver.mk

ifneq ($(filter exynos9810, $(TA_TARGET_SOC)), )
scrypto_fips: $(DR_AXF)
	$(SCRYPTO_FIPS_SCRIPT) $<

all: scrypto_fips
	# Build Done. Do not remove this line

endif
