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