tee: integrate tee module build to android build system [1/2]
authorShuide Chen <shuide.chen@amlogic.com>
Tue, 28 May 2019 06:06:41 +0000 (14:06 +0800)
committerShuide Chen <shuide.chen@amlogic.com>
Mon, 17 Jun 2019 01:56:19 +0000 (18:56 -0700)
PD#SWPL-9058

Problem:
optee module build trigged at scanning Android.mk stage, it's too early
and the module not depend to kernel, which may introduce very strange
errors, and it customize toolchain and configures, which made the system
very hard to maintain.

Solution:
Rewrite the makefile and structure for the above problem
This CL also support build on Q

Verify:
locally

Change-Id: I8d883735d926c54848a4135518e4be139594a147
Signed-off-by: Shuide Chen <shuide.chen@amlogic.com>
15 files changed:
Android.mk [changed mode: 0755->0644]
Kconfig [changed mode: 0755->0644]
Makefile [changed mode: 0755->0644]
include/linux/arm-smccc.h [changed mode: 0755->0644]
include/linux/tee.h [changed mode: 0755->0644]
include/linux/tee_drv.h [changed mode: 0755->0644]
optee/Kconfig [changed mode: 0755->0644]
optee/optee_msg.h [changed mode: 0755->0644]
optee/optee_private.h [changed mode: 0755->0644]
optee/optee_smc.h [changed mode: 0755->0644]
optee/smccc-call.S [changed mode: 0755->0644]
optee/supp.c [changed mode: 0755->0644]
tee_core.c [changed mode: 0755->0644]
tee_private.h [changed mode: 0755->0644]
tee_shm.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index de85d75..7757047
@@ -1,51 +1,82 @@
 LOCAL_PATH := $(call my-dir)
-ifeq ($(BOARD_KERNEL_VERSION), 4.9)
-KERNEL_DIR := kernel/common_4.9
-else ifeq ($(BOARD_KERNEL_VERSION), 3.14)
-KERNEL_DIR := kernel/common_3.14
-else
-KERNEL_DIR := common
-endif
-KERNEL_OUT_DIR := $(PRODUCT_OUT)/obj/KERNEL_OBJ
-ifeq ($(KERNEL_A32_SUPPORT), true)
-KERNEL_ARCH := arm
-KERNEL_DRIVER_CROSS_COMPILE := /opt/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
-KERNEL_CONFIG=meson64_a32_defconfig
-else
-KERNEL_ARCH := arm64
-KERNEL_DRIVER_CROSS_COMPILE := aarch64-linux-gnu-
-KERNEL_CONFIG=meson64_defconfig
-endif
 
-OPTEE_MODULES := $(shell pwd)/$(PRODUCT_OUT)/obj/optee_modules
-include $(CLEAR_VARS)
-$(info $(shell if [ ! -d $(KERNEL_OUT_DIR) ]; then mkdir -p $(KERNEL_OUT_DIR); fi))
+ifneq ($(TARGET_KERNEL_BUILT_FROM_SOURCE), false)
 
-$(info $(shell if [ ! -e $(KERNEL_OUT_DIR)/include/generated/autoconf.h ]; then $(MAKE) -C $(KERNEL_DIR) O=../$(KERNEL_OUT_DIR) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_DRIVER_CROSS_COMPILE) $(KERNEL_CONFIG); fi))
+OPTEE_MODULES := $(shell pwd)/$(PRODUCT_OUT)/obj/optee_modules/
+OPTEE_DRIVERS := $(shell pwd)/vendor/amlogic/common/tdk/linuxdriver/
+KERNEL_OUT_DIR := $(shell pwd)/$(PRODUCT_OUT)/obj/KERNEL_OBJ/
 
+##############################################################################
+###
+###  Build tee modules for Android. Since is in Android.mk, not standalone
+###  module build script, all kernel related configurations(e.g:CROSS_COMPILE),
+###  PLEASE PLEASE extends from the build system, DO NOT customization here!
+##############################################################################
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 29 && echo OK),OK)
+define build_optee_modules
+       echo "$(1) $(2) $(3)"
+       mkdir -p $(2)/
+       cp -rfa $(1)/*  $(2)/
+       PATH=$$(cd ./$(TARGET_HOST_TOOL_PATH); pwd):$$PATH \
+         $(MAKE) -C $(KERNEL_OUT_DIR) M=$(strip $(2))  \
+         KERNEL_A32_SUPPORT=$(KERNEL_A32_SUPPORT) ARCH=$(KERNEL_ARCH) \
+         CROSS_COMPILE=$(PREFIX_CROSS_COMPILE)
+endef
+else
+define build_optee_modules
+       echo "$(1) $(2) $(3)"
+       mkdir -p $(2)/
+       cp -rfa $(1)/*  $(2)/
+       $(MAKE) -C $(KERNEL_OUT_DIR) M=$(strip $(2))  \
+         KERNEL_A32_SUPPORT=$(KERNEL_A32_SUPPORT) ARCH=$(KERNEL_ARCH) \
+         CROSS_COMPILE=$(PREFIX_CROSS_COMPILE)
+endef
+endif
 
-$(info $(shell if [ ! -e $(KERNEL_OUT_DIR)/include/generated/autoconf.h ]; then $(MAKE) -C $(KERNEL_DIR) O=../$(KERNEL_OUT_DIR) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_DRIVER_CROSS_COMPILE) modules_prepare; fi))
+$(PRODUCT_OUT)/obj/optee_modules/optee.ko: $(INSTALLED_KERNEL_TARGET)
+       $(call build_optee_modules, $(OPTEE_DRIVERS), $(OPTEE_MODULES))
 
-$(info $(shell if [ ! -d $(OPTEE_MODULES) ]; then mkdir -p $(OPTEE_MODULES); fi))
-$(info $(shell cp $(LOCAL_PATH)/* $(OPTEE_MODULES) -rfa))
-$(info $(shell $(MAKE) -C $(shell pwd)/$(KERNEL_OUT_DIR) M=$(OPTEE_MODULES) KERNEL_A32_SUPPORT=$(KERNEL_A32_SUPPORT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_DRIVER_CROSS_COMPILE) modules))
+endif
 
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := optee_armtz
-LOCAL_PREBUILT_MODULE_FILE := $(OPTEE_MODULES)/optee/optee_armtz.ko
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+ifneq ($(TARGET_KERNEL_BUILT_FROM_SOURCE), false)
+GEN_OPTEE_ARMTZ := $(local-generated-sources-dir)/optee_armtz.ko
+$(GEN_OPTEE_ARMTZ): $(PRODUCT_OUT)/obj/optee_modules/optee.ko | $(ACP)
+       cp $(PRODUCT_OUT)/obj/optee_modules/optee/optee_armtz.ko $(GEN_OPTEE_ARMTZ)
+
+LOCAL_PREBUILT_MODULE_FILE := $(GEN_OPTEE_ARMTZ)
+else
+# TARGET_BOOTLOADER_BOARD_NAME currently defined the same as platform device name
+LOCAL_SRC_FILES := device/amlogic/$(TARGET_BOOTLOADER_BOARD_NAME)-kernel/optee_armtz.ko
+endif
+
 LOCAL_MODULE_SUFFIX := .ko
 LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib
 LOCAL_STRIP_MODULE := false
 include $(BUILD_PREBUILT)
 
+
 include $(CLEAR_VARS)
 LOCAL_MODULE := optee
-LOCAL_PREBUILT_MODULE_FILE := $(OPTEE_MODULES)/optee.ko
-LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+ifneq ($(TARGET_KERNEL_BUILT_FROM_SOURCE), false)
+GEN_OPTEE := $(local-generated-sources-dir)/optee.ko
+$(GEN_OPTEE): $(PRODUCT_OUT)/obj/optee_modules/optee.ko | $(ACP)
+       cp $(PRODUCT_OUT)/obj/optee_modules/optee.ko $(GEN_OPTEE)
+
+LOCAL_PREBUILT_MODULE_FILE := $(GEN_OPTEE)
+else
+LOCAL_SRC_FILES  :=  \
+    device/amlogic/$(TARGET_BOOTLOADER_BOARD_NAME)-kernel/optee.ko
+
+endif
+LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_SUFFIX := .ko
 LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib
 LOCAL_STRIP_MODULE := false
diff --git a/Kconfig b/Kconfig
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)