Skip to content

Commit

Permalink
Add support to generate multiple TA dev kits
Browse files Browse the repository at this point in the history
Adds support to generate multiple TA dev kits, one for each word in the
variable "ta-targets". ta/ta.mk is included once for each word in
"ta-targets" with the word assigned to "ta-target". This word is the
assigned the variable "sm" to allow each "ta-target" to be built as a
separate sub-module.

Reviewed-by: Jerome Forissier <[email protected]>
Reviewed-by: Pascal Brand <[email protected]>
Signed-off-by: Jens Wiklander <[email protected]>
  • Loading branch information
jenswi-linaro committed Dec 3, 2015
1 parent 4175ef9 commit bc33bbd
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 31 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ endif

include core/core.mk

# Platform config is supposed to assign the targets
ta-targets ?= user_ta

define build-ta-target
ta-target := $(1)
include ta/ta.mk
endef
$(foreach t, $(ta-targets), $(eval $(call build-ta-target, $(t))))

.PHONY: clean
clean:
Expand Down
4 changes: 2 additions & 2 deletions lib/libutee/arch/arm/sub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ cppflags-y += -I$(sub-dir)/../..

srcs-y += user_ta_entry.c
srcs-y += utee_misc.c
srcs-$(CFG_ARM32_user_ta) += utee_syscalls_a32.S
srcs-$(CFG_ARM64_user_ta) += utee_syscalls_a64.S
srcs-$(CFG_ARM32_$(sm)) += utee_syscalls_a32.S
srcs-$(CFG_ARM64_$(sm)) += utee_syscalls_a64.S
8 changes: 4 additions & 4 deletions ta/arch/arm/arm.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifeq ($(CFG_ARM64_user_ta),y)
user_ta-platform-cppflags += -DARM64=1 -D__LP64__=1
ifeq ($(CFG_ARM64_$(sm)),y)
$(sm)-platform-cppflags += -DARM64=1 -D__LP64__=1
endif
ifeq ($(CFG_ARM32_user_ta),y)
user_ta-platform-cppflags += -DARM32=1 -D__ILP32__=1
ifeq ($(CFG_ARM32_$(sm)),y)
$(sm)-platform-cppflags += -DARM32=1 -D__ILP32__=1
endif
17 changes: 14 additions & 3 deletions ta/arch/arm/link.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
link-out-dir = $(out-dir)

link-script = $(TA_DEV_KIT_DIR)/src/user_ta_elf_arm.lds
link-script = $(TA_DEV_KIT_DIR)/src/ta.ld.S
link-script-pp = $(link-out-dir)/ta.lds
link-script-dep = $(link-out-dir)/.ta.ld.d

SIGN = $(TA_DEV_KIT_DIR)/scripts/sign.py
TA_SIGN_KEY ?= $(TA_DEV_KIT_DIR)/keys/default_ta.pem
Expand All @@ -27,10 +28,20 @@ link-ldadd += $(addprefix -L,$(libdirs))
link-ldadd += $(addprefix -l,$(call reverse,$(libnames)))
ldargs-$(binary).elf := $(link-ldflags) $(objs) $(link-ldadd)


link-script-cppflags-$(sm) := -DASM=1 \
$(filter-out $(CPPFLAGS_REMOVE) $(cppflags-remove), \
$(nostdinc$(sm)) $(CPPFLAGS) \
$(addprefix -I,$(incdirs$(sm)) $(link-out-dir)) \
$(cppflags$(sm)))

-include $(link-script-dep)

$(link-script-pp): $(link-script) $(MAKEFILE_LIST)
@$(cmd-echo-silent) ' CP $@'
@$(cmd-echo-silent) ' CPP $@'
$(q)mkdir -p $(dir $@)
$(q)cp $< $@
$(q)$(CPP$(sm)) -Wp,-P,-MT,$@,-MD,$(link-script-dep) \
$(link-script-cppflags-$(sm)) $< > $@

$(link-out-dir)/$(binary).elf: $(objs) $(libdeps) $(link-script-pp)
@$(cmd-echo-silent) ' LD $@'
Expand Down
6 changes: 6 additions & 0 deletions ta/arch/arm/user_ta_elf_arm.lds → ta/arch/arm/ta.ld.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#ifdef ARM32
OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
#endif
#ifdef ARM64
OUTPUT_FORMAT("elf64-littleaarch64")
OUTPUT_ARCH(aarch64)
#endif

PHDRS {
rodata PT_LOAD;
Expand Down
12 changes: 5 additions & 7 deletions ta/mk/ta_dev_kit.mk
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@


# Get the dir of the ta-dev-kit, requires make version 3.81 or later
ta-dev-kit-dir := $(patsubst %/,%,$(abspath $(dir $(lastword $(MAKEFILE_LIST)))..))


.PHONY: all
all:

sm := user_ta
sm-$(ta) := y
include $(ta-dev-kit-dir)/mk/conf.mk

binary := $(BINARY)

CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE)
Expand Down Expand Up @@ -43,9 +41,9 @@ endif
include $(ta-dev-kit-dir)/mk/arch.mk
-include $(ta-dev-kit-dir)/mk/platform_flags.mk

cppflags$(sm) += $(platform-cppflags) $(user_ta-platform-cppflags)
aflags$(sm) += $(platform-aflags) $(user_ta-platform-aflags)
cflags$(sm) += $(platform-cflags) $(user_ta-platform-cflags)
cppflags$(sm) := $(platform-cppflags) $($(sm)-platform-cppflags)
aflags$(sm) := $(platform-aflags) $($(sm)-platform-aflags)
cflags$(sm) := $(platform-cflags) $($(sm)-platform-cflags)

CFG_TEE_TA_LOG_LEVEL ?= 2
cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
Expand Down
46 changes: 31 additions & 15 deletions ta/ta.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include mk/cleanvars.mk

# Set current submodule (used for module specific flags compile result etc)
sm := user_ta
sm := $(ta-target)
sm-$(sm) := y

# Setup compiler for this sub module
Expand All @@ -11,16 +11,17 @@ include mk/$(COMPILER_$(sm)).mk

include ta/arch/$(ARCH)/$(ARCH).mk

cppflags$(sm) += $(platform-cppflags) $(user_ta-platform-cppflags)
cflags$(sm) += $(platform-cflags) $(user_ta-platform-cflags)
aflags$(sm) += $(platform-aflags) $(user_ta-platform-aflags)
# Expand platform flags here as $(sm) will change if we have several TA
# targets. Platform flags should not change after inclusion of ta/ta.mk.
cppflags$(sm) := $(platform-cppflags) $($(sm)-platform-cppflags)
cflags$(sm) := $(platform-cflags) $($(sm)-platform-cflags)
aflags$(sm) := $(platform-aflags) $($(sm)-platform-aflags)

# Config flags from mk/config.mk
cppflags$(sm) += -DTRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL)
cppflags$(sm) += -DCFG_TEE_CORE_USER_MEM_DEBUG=$(CFG_TEE_CORE_USER_MEM_DEBUG)
cppflags$(sm) += -DENABLE_MDBG=$(CFG_TEE_TA_MALLOC_DEBUG)


base-prefix := $(sm)-

libname = utils
Expand Down Expand Up @@ -62,7 +63,7 @@ endef

# Copy the .a files
$(foreach f, $(libfiles), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/lib)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/lib)))

# Copy .mk files
ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk \
Expand All @@ -71,10 +72,10 @@ ta-mkfiles = mk/compile.mk mk/subdir.mk mk/gcc.mk \
ta/mk/ta_dev_kit.mk

$(foreach f, $(ta-mkfiles), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/mk)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/mk)))

# Special treatment for ta/arch/$(ARCH)/$(ARCH).mk
arch-arch-mk := $(out-dir)/export-user_ta/mk/arch.mk
arch-arch-mk := $(out-dir)/export-$(sm)/mk/arch.mk
$(arch-arch-mk): ta/arch/$(ARCH)/$(ARCH).mk
@set -e; \
mkdir -p $(dir $@) ; \
Expand All @@ -91,26 +92,41 @@ $$(foreach h, $$(sf), $$(eval $$(call copy-file, $1/$$(h), \
$$(patsubst %/,%,$$(subst /./,/,$2/$$(dir $$(h)))))))
endef
$(foreach d, $(incdirs$(sm)), \
$(eval $(call copy-incdir, $(d), $(out-dir)/export-user_ta/include)))
$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/include)))

# Copy the .h files needed by host
$(foreach d, $(incdirs-host), \
$(eval $(call copy-incdir, $(d), $(out-dir)/export-user_ta/host_include)))
$(eval $(call copy-incdir, $(d), $(out-dir)/export-$(sm)/host_include)))
$(foreach f, $(incfiles-extra-host), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/host_include)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/host_include)))

# Copy the src files
ta-srcfiles = ta/arch/$(ARCH)/user_ta_header.c \
$(wildcard ta/arch/$(ARCH)/user_ta_elf_arm.lds)
$(wildcard ta/arch/$(ARCH)/ta.ld.S)
$(foreach f, $(ta-srcfiles), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/src)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/src)))

# Copy keys
ta-keys = keys/default_ta.pem
$(foreach f, $(ta-keys), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/keys)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/keys)))

# Copy the scripts
ta-scripts = $(wildcard scripts/sign.py)
$(foreach f, $(ta-scripts), \
$(eval $(call copy-file, $(f), $(out-dir)/export-user_ta/scripts)))
$(eval $(call copy-file, $(f), $(out-dir)/export-$(sm)/scripts)))

# Create config file
conf-file := $(out-dir)/export-$(sm)/mk/conf.mk
sm-$(conf-file) := $(sm)
# The file is only created if it doesn't exist, this is currently OK as the
# content of the file is static for a given TA dev kit.
$(conf-file):
@$(cmd-echo-silent) ' GEN ' $@
$(q)echo sm := $(sm-$(@)) > $@
$(q)echo sm-$(sm-$(@)) := y >> $@
$(q)echo CFG_ARM32_$(sm-$(@)) := $(CFG_ARM32_$(sm-$(@))) >> $@
$(q)echo CFG_ARM64_$(sm-$(@)) := $(CFG_ARM64_$(sm-$(@))) >> $@

cleanfiles := $(cleanfiles) $(conf-file)
all: $(conf-file)

0 comments on commit bc33bbd

Please sign in to comment.