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-globals=1 \ 66 --param asan-instrumentation-with-call-threshold=0 67ifneq ($(CFG_DYN_CONFIG),y) 68cflags_kasan += --param asan-stack=1 69endif 70cflags$(sm) += $(cflags_kasan) 71endif 72ifeq ($(CFG_CORE_DEBUG_CHECK_STACKS),y) 73finstrument-functions := $(call cc-option,-finstrument-functions) 74ifeq (,$(finstrument-functions)) 75$(error -finstrument-functions not supported) 76endif 77cflags$(sm) += $(finstrument-functions) 78endif 79ifeq ($(CFG_SYSCALL_FTRACE),y) 80cflags$(sm) += -pg 81endif 82aflags$(sm) += $(core-platform-aflags) 83 84cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL) 85ifeq ($(CFG_TEE_CORE_MALLOC_DEBUG),y) 86cppflags$(sm) += -DENABLE_MDBG=1 87endif 88ifneq ($(CFG_TEE_CORE_DEBUG),y) 89cppflags$(sm) += -DNDEBUG 90endif 91 92cppflags$(sm) += -Ildelf/include 93cppflags$(sm) += -Ilib/libutee/include 94 95ifeq ($(filter y, $(CFG_CORE_DYN_SHM) $(CFG_CORE_RESERVED_SHM)),) 96$(error error: No shared memory configured) 97endif 98 99# Tell all libraries and sub-directories (included below) that we have a 100# configuration file 101 102conf-file := $(out-dir)/include/generated/conf.h 103conf-mk-file := $(out-dir)/conf.mk 104conf-cmake-file := $(out-dir)/conf.cmake 105$(conf-file): $(conf-mk-file) 106 107cleanfiles += $(conf-file) 108cleanfiles += $(conf-mk-file) 109cleanfiles += $(conf-cmake-file) 110 111$(conf-file): FORCE 112 $(call check-conf-h) 113 114$(conf-mk-file): FORCE 115 $(call check-conf-mk) 116 117$(conf-cmake-file): FORCE 118 $(call check-conf-cmake) 119 120# 121# Do libraries 122# 123 124# Set a prefix to avoid conflicts with user TAs that will use the same 125# source but with different flags below 126base-prefix := $(sm)- 127libname = utils 128libdir = lib/libutils 129include mk/lib.mk 130 131# CFG_CRYPTOLIB_NAME must not be changed beyond this line 132CFG_CRYPTOLIB_NAME_$(CFG_CRYPTOLIB_NAME) := y 133 134ifeq ($(CFG_CRYPTOLIB_NAME),tomcrypt) 135# We're compiling mbedtls too, but with a limited configuration which only 136# provides the MPI routines 137libname = mbedtls 138libdir = lib/libmbedtls 139include mk/lib.mk 140endif #tomcrypt 141 142ifeq ($(CFG_CRYPTOLIB_NAME),mbedtls) 143$(call force,CFG_CRYPTO_RSASSA_NA1,n,not supported by mbedtls) 144libname = tomcrypt 145libdir = core/lib/libtomcrypt 146base-prefix := 147include mk/lib.mk 148base-prefix := $(sm)- 149endif 150 151ifeq ($(firstword $(subst /, ,$(CFG_CRYPTOLIB_DIR))),core) 152# If a library can be compiled for both core and user space a base-prefix 153# is needed in order to avoid conflicts in the output. However, if the 154# library resides under core then it can't be compiled to user space. 155base-prefix := 156endif 157 158libname = $(CFG_CRYPTOLIB_NAME) 159libdir = $(CFG_CRYPTOLIB_DIR) 160include mk/lib.mk 161 162base-prefix := 163 164libname = fdt 165libdir = core/lib/libfdt 166include mk/lib.mk 167 168ifeq ($(CFG_ZLIB),y) 169libname = zlib 170libdir = core/lib/zlib 171include mk/lib.mk 172endif 173 174ifeq ($(CFG_EFILIB),y) 175libname = efi 176libdir = core/lib/libefi 177include mk/lib.mk 178endif 179 180libname = unw 181libdir = lib/libunw 182include mk/lib.mk 183 184ifeq ($(CFG_SCMI_SCPFW),y) 185libname = scmi-server 186libdir = core/lib/scmi-server 187include mk/lib.mk 188endif 189 190ifeq ($(CFG_QCBOR),y) 191libname = qcbor 192libdir = core/lib/qcbor 193include mk/lib.mk 194endif 195 196# 197# Do main source 198# 199 200subdirs = $(core-platform-subdirs) core 201include mk/subdir.mk 202 203include mk/compile.mk 204 205include $(if $(wildcard $(platform-dir)/link.mk), \ 206 $(platform-dir)/link.mk, \ 207 core/arch/$(ARCH)/kernel/link.mk) 208