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