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