1include mk/cleanvars.mk 2 3# Set current submodule (used for module specific flags compile result etc) 4sm := core 5sm-$(sm) := y 6 7arch-dir := core/arch/$(ARCH) 8platform-dir := $(arch-dir)/plat-$(PLATFORM) 9include $(platform-dir)/conf.mk 10include mk/config.mk 11# $(ARCH).mk also sets the compiler for the core module 12include core/arch/$(ARCH)/$(ARCH).mk 13 14PLATFORM_$(PLATFORM) := y 15PLATFORM_FLAVOR_$(PLATFORM_FLAVOR) := y 16 17$(eval $(call cfg-depends-all,CFG_PAGED_USER_TA,CFG_WITH_PAGER CFG_WITH_USER_TA)) 18include core/crypto.mk 19 20cppflags$(sm) += -D__KERNEL__ 21 22cppflags$(sm) += -Icore/include 23cppflags$(sm) += -include $(conf-file) 24cppflags$(sm) += -I$(out-dir)/core/include 25cppflags$(sm) += $(core-platform-cppflags) 26cflags$(sm) += $(core-platform-cflags) 27ifeq ($(CFG_CORE_SANITIZE_UNDEFINED),y) 28cflags$(sm) += -fsanitize=undefined 29endif 30ifeq ($(CFG_CORE_SANITIZE_KADDRESS),y) 31ifeq ($(CFG_ASAN_SHADOW_OFFSET),) 32$(error error: CFG_CORE_SANITIZE_KADDRESS not supported by platform (flavor)) 33endif 34ifeq ($(COMPILER),clang) 35$(error error: CFG_CORE_SANITIZE_KADDRESS not supported with Clang) 36endif 37cflags_kasan += -fsanitize=kernel-address \ 38 -fasan-shadow-offset=$(CFG_ASAN_SHADOW_OFFSET)\ 39 --param asan-stack=1 --param asan-globals=1 \ 40 --param asan-instrumentation-with-call-threshold=0 41cflags$(sm) += $(cflags_kasan) 42endif 43ifeq ($(CFG_CORE_DEBUG_CHECK_STACKS),y) 44finstrument-functions := $(call cc-option,-finstrument-functions) 45ifeq (,$(finstrument-functions)) 46$(error -finstrument-functions not supported) 47endif 48cflags$(sm) += $(finstrument-functions) 49endif 50ifeq ($(CFG_SYSCALL_FTRACE),y) 51cflags$(sm) += -pg 52endif 53aflags$(sm) += $(core-platform-aflags) 54 55cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL) 56ifeq ($(CFG_TEE_CORE_MALLOC_DEBUG),y) 57cppflags$(sm) += -DENABLE_MDBG=1 58endif 59ifneq ($(CFG_TEE_CORE_DEBUG),y) 60cppflags$(sm) += -DNDEBUG 61endif 62 63cppflags$(sm) += -Ildelf/include 64cppflags$(sm) += -Ilib/libutee/include 65 66ifeq ($(filter y, $(CFG_CORE_DYN_SHM) $(CFG_CORE_RESERVED_SHM)),) 67$(error error: No shared memory configured) 68endif 69 70# Tell all libraries and sub-directories (included below) that we have a 71# configuration file 72 73conf-file := $(out-dir)/include/generated/conf.h 74conf-mk-file := $(out-dir)/conf.mk 75conf-cmake-file := $(out-dir)/conf.cmake 76$(conf-file): $(conf-mk-file) 77 78cleanfiles += $(conf-file) 79cleanfiles += $(conf-mk-file) 80cleanfiles += $(conf-cmake-file) 81 82$(conf-file): FORCE 83 $(call check-conf-h) 84 85$(conf-mk-file): FORCE 86 $(call check-conf-mk) 87 88$(conf-cmake-file): FORCE 89 $(call check-conf-cmake) 90 91# 92# Do libraries 93# 94 95# Set a prefix to avoid conflicts with user TAs that will use the same 96# source but with different flags below 97base-prefix := $(sm)- 98libname = utils 99libdir = lib/libutils 100include mk/lib.mk 101 102# CFG_CRYPTOLIB_NAME must not be changed beyond this line 103CFG_CRYPTOLIB_NAME_$(CFG_CRYPTOLIB_NAME) := y 104 105ifeq ($(CFG_CRYPTOLIB_NAME),tomcrypt) 106# We're compiling mbedtls too, but with a limited configuration which only 107# provides the MPI routines 108libname = mbedtls 109libdir = lib/libmbedtls 110include mk/lib.mk 111endif #tomcrypt 112 113ifeq ($(CFG_CRYPTOLIB_NAME),mbedtls) 114$(call force,CFG_CRYPTO_RSASSA_NA1,n,not supported by mbedtls) 115libname = tomcrypt 116libdir = core/lib/libtomcrypt 117base-prefix := 118include mk/lib.mk 119base-prefix := $(sm)- 120endif 121 122ifeq ($(firstword $(subst /, ,$(CFG_CRYPTOLIB_DIR))),core) 123# If a library can be compiled for both core and user space a base-prefix 124# is needed in order to avoid conflicts in the output. However, if the 125# library resides under core then it can't be compiled to user space. 126base-prefix := 127endif 128 129libname = $(CFG_CRYPTOLIB_NAME) 130libdir = $(CFG_CRYPTOLIB_DIR) 131include mk/lib.mk 132 133base-prefix := 134 135libname = fdt 136libdir = core/lib/libfdt 137include mk/lib.mk 138 139ifeq ($(CFG_ZLIB),y) 140libname = zlib 141libdir = core/lib/zlib 142include mk/lib.mk 143endif 144 145libname = unw 146libdir = lib/libunw 147include mk/lib.mk 148 149# 150# Do main source 151# 152 153subdirs = $(core-platform-subdirs) core 154include mk/subdir.mk 155 156include mk/compile.mk 157 158include $(if $(wildcard $(platform-dir)/link.mk), \ 159 $(platform-dir)/link.mk, \ 160 core/arch/$(ARCH)/kernel/link.mk) 161