From 566330eb795d213d2a771f186b68c14fd7f7f40f Mon Sep 17 00:00:00 2001 From: Shuide Chen Date: Tue, 28 May 2019 14:06:41 +0800 Subject: [PATCH] tee: integrate tee module build to android build system [1/2] 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 --- Android.mk | 87 ++++++++++++++++++++++++++------------- Kconfig | 0 Makefile | 0 include/linux/arm-smccc.h | 0 include/linux/tee.h | 0 include/linux/tee_drv.h | 0 optee/Kconfig | 0 optee/optee_msg.h | 0 optee/optee_private.h | 0 optee/optee_smc.h | 0 optee/smccc-call.S | 0 optee/supp.c | 0 tee_core.c | 0 tee_private.h | 0 tee_shm.c | 0 15 files changed, 59 insertions(+), 28 deletions(-) mode change 100755 => 100644 Android.mk mode change 100755 => 100644 Kconfig mode change 100755 => 100644 Makefile mode change 100755 => 100644 include/linux/arm-smccc.h mode change 100755 => 100644 include/linux/tee.h mode change 100755 => 100644 include/linux/tee_drv.h mode change 100755 => 100644 optee/Kconfig mode change 100755 => 100644 optee/optee_msg.h mode change 100755 => 100644 optee/optee_private.h mode change 100755 => 100644 optee/optee_smc.h mode change 100755 => 100644 optee/smccc-call.S mode change 100755 => 100644 optee/supp.c mode change 100755 => 100644 tee_core.c mode change 100755 => 100644 tee_private.h mode change 100755 => 100644 tee_shm.c diff --git a/Android.mk b/Android.mk old mode 100755 new mode 100644 index de85d75..7757047 --- a/Android.mk +++ b/Android.mk @@ -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 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h old mode 100755 new mode 100644 diff --git a/include/linux/tee.h b/include/linux/tee.h old mode 100755 new mode 100644 diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h old mode 100755 new mode 100644 diff --git a/optee/Kconfig b/optee/Kconfig old mode 100755 new mode 100644 diff --git a/optee/optee_msg.h b/optee/optee_msg.h old mode 100755 new mode 100644 diff --git a/optee/optee_private.h b/optee/optee_private.h old mode 100755 new mode 100644 diff --git a/optee/optee_smc.h b/optee/optee_smc.h old mode 100755 new mode 100644 diff --git a/optee/smccc-call.S b/optee/smccc-call.S old mode 100755 new mode 100644 diff --git a/optee/supp.c b/optee/supp.c old mode 100755 new mode 100644 diff --git a/tee_core.c b/tee_core.c old mode 100755 new mode 100644 diff --git a/tee_private.h b/tee_private.h old mode 100755 new mode 100644 diff --git a/tee_shm.c b/tee_shm.c old mode 100755 new mode 100644 -- 2.20.1