diff --git a/Android.bp b/Android.bp new file mode 100644 index 00000000..115e9143 --- /dev/null +++ b/Android.bp @@ -0,0 +1,305 @@ +// +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +soong_config_module_type { + name: "optee_client_cflags_cc_defaults", + module_type: "cc_defaults", + config_namespace: "optee_client", + bool_variables: [ + "cfg_debug", + "cfg_werror", + ], + properties: ["cflags"], +} + +optee_client_cflags_cc_defaults { + name: "optee_client_cflags_defaults", + cflags: [ + "-c", + "-fPIC", + "-Wall", + "-Wbad-function-cast", + "-Wcast-align", + "-Werror-implicit-function-declaration", + "-Wextra", + "-Wfloat-equal", + "-Wformat-nonliteral", + "-Wformat-security", + "-Wformat=2", + "-Winit-self", + "-Wmissing-declarations", + "-Wmissing-format-attribute", + "-Wmissing-include-dirs", + "-Wmissing-noreturn", + "-Wmissing-prototypes", + "-Wnested-externs", + "-Wpointer-arith", + "-Wshadow", + "-Wstrict-prototypes", + "-Wswitch-default", + "-Wwrite-strings", + ], + soong_config_variables: { + cfg_debug: { + cflags: [ + "-DDEBUG", + "-O0", + "-g", + ], + }, + cfg_werror: { + cflags: ["-Werror"], + }, + }, +} + +soong_config_module_type { + name: "optee_client_libteec_cc_defaults", + module_type: "cc_defaults", + config_namespace: "optee_client", + bool_variables: [ + "cfg_tee_benchmark", + ], + value_variables: [ + "cfg_tee_client_log_level", + "cfg_tee_client_log_file", + "cfg_tee_fs_parent_path", + ], + properties: [ + "cflags", + "defaults", + "srcs", + ], +} + +optee_client_libteec_cc_defaults { + name: "optee_client_libteec_log_file_defaults", + soong_config_variables: { + cfg_tee_fs_parent_path: { + cflags: ["-DTEEC_LOG_FILE=\"%s/teec.log\""], + conditions_default: { + cflags: ["-DTEEC_LOG_FILE=\"/data/vendor/tee/teec.log\""], + }, + }, + }, +} + +optee_client_libteec_cc_defaults { + name: "optee_client_libteec_defaults", + soong_config_variables: { + cfg_tee_benchmark: { + cflags: ["-DCFG_TEE_BENCHMARK"], + srcs: ["teec_benchmark.c"], + }, + cfg_tee_client_log_level: { + cflags: ["-DDEBUGLEVEL_%s"], + conditions_default: { + cflags: ["-DDEBUGLEVEL_2"], + }, + }, + cfg_tee_client_log_file: { + cflags: ["-DTEEC_LOG_FILE=\"%s\""], + conditions_default: { + defaults: ["optee_client_libteec_log_file_defaults"], + }, + }, + cfg_tee_fs_parent_path: { + cflags: ["-DTEE_FS_PARENT_PATH=\"%s\""], + conditions_default: { + cflags: ["-DTEE_FS_PARENT_PATH=\"/data/vendor/tee\""], + }, + }, + }, +} + +cc_library_shared { + name: "libteec", + vendor: true, + compile_multilib: "both", + defaults: [ + "optee_client_cflags_defaults", + "optee_client_libteec_defaults", + ], + cflags: [ + "-DBINARY_PREFIX=\"TEEC\"", + ], + srcs: [ + "libteec/src/tee_client_api.c", + "libteec/src/teec_trace.c", + ], + local_include_dirs: [ + "libteec/include", + "libteec/src", + ], + export_include_dirs: ["libteec/include"], +} + +cc_library_shared { + name: "libckteec", + vendor: true, + compile_multilib: "both", + defaults: ["optee_client_cflags_defaults"], + srcs: [ + "libckteec/src/ck_debug.c", + "libckteec/src/ck_helpers.c", + "libckteec/src/invoke_ta.c", + "libckteec/src/pkcs11_api.c", + "libckteec/src/pkcs11_processing.c", + "libckteec/src/pkcs11_token.c", + "libckteec/src/serialize_ck.c", + "libckteec/src/serializer.c", + ], + shared_libs: ["libteec"], + local_include_dirs: [ + "libckteec/include", + "libteec/include", + ], + export_include_dirs: ["libckteec/include"], +} + +soong_config_module_type { + name: "optee_client_tee_supplicant_cc_defaults", + module_type: "cc_defaults", + config_namespace: "optee_client", + bool_variables: [ + "cfg_ftrace_support", + "cfg_gp_sockets", + "cfg_ta_gprof_support", + "cfg_tee_supp_plugins", + "rpmb_emu", + ], + value_variables: [ + "cfg_tee_client_load_path", + "cfg_tee_fs_parent_path", + "cfg_tee_plugin_load_path", + "cfg_tee_supp_log_level", + ], + properties: [ + "cflags", + "defaults", + "ldflags", + "srcs", + ], +} + +optee_client_tee_supplicant_cc_defaults { + name: "optee_client_tee_supplicant_plugin_load_path_defaults", + multilib: { + lib32: { + cflags: ["-DTEE_PLUGIN_LOAD_PATH=\"/vendor/lib/tee-supplicant/plugins/\""], + ldflags: ["-Wl,-rpath=/vendor/lib/tee-supplicant/plugins/"], + }, + lib64: { + cflags: ["-DTEE_PLUGIN_LOAD_PATH=\"/vendor/lib64/tee-supplicant/plugins/\""], + ldflags: ["-Wl,-rpath=/vendor/lib64/tee-supplicant/plugins/"], + }, + }, +} + +optee_client_tee_supplicant_cc_defaults { + name: "optee_client_tee_supplicant_plugin_defaults", + soong_config_variables: { + cfg_tee_plugin_load_path: { + cflags: ["-DTEE_PLUGIN_LOAD_PATH=\"%s\""], + ldflags: ["-Wl,-rpath=%s"], + conditions_default: { + defaults: ["optee_client_tee_supplicant_plugin_load_path_defaults"], + }, + }, + }, +} + +optee_client_tee_supplicant_cc_defaults { + name: "optee_client_tee_supplicant_prof_defaults", + srcs: ["tee-supplicant/src/prof.c"], +} + +optee_client_tee_supplicant_cc_defaults { + name: "optee_client_tee_supplicant_defaults", + soong_config_variables: { + cfg_ftrace_support: { + cflags: ["-DCFG_FTRACE_SUPPORT"], + defaults: ["optee_client_tee_supplicant_prof_defaults"], + }, + cfg_gp_sockets: { + cflags: ["-DCFG_GP_SOCKETS=1"], + srcs: ["tee-supplicant/src/tee_socket.c"], + }, + cfg_ta_gprof_support: { + cflags: ["-DCFG_TA_GPROF_SUPPORT"], + defaults: ["optee_client_tee_supplicant_prof_defaults"], + }, + cfg_tee_client_load_path: { + cflags: ["-DTEEC_LOAD_PATH=\"%s\""], + conditions_default: { + cflags: ["-DTEEC_LOAD_PATH=\"/vendor/lib\""], + }, + }, + cfg_tee_fs_parent_path: { + cflags: ["-DTEE_FS_PARENT_PATH=\"%s\""], + conditions_default: { + cflags: ["-DTEE_FS_PARENT_PATH=\"/data/vendor/tee\""], + }, + }, + cfg_tee_supp_log_level: { + cflags: ["-DDEBUGLEVEL_%s"], + conditions_default: { + cflags: ["-DDEBUGLEVEL_2"], + }, + }, + cfg_tee_supp_plugins: { + srcs: ["tee-supplicant/src/plugin.c"], + cflags: ["-DTEE_SUPP_PLUGINS"], + defaults: ["optee_client_tee_supplicant_plugin_defaults"], + }, + rpmb_emu: { + cflags: ["-DRPMB_EMU=1"], + srcs: [ + "tee-supplicant/src/hmac_sha2.c", + "tee-supplicant/src/sha2.c", + ], + }, + }, +} + +cc_binary { + name: "tee-supplicant", + vendor: true, + defaults: [ + "optee_client_cflags_defaults", + "optee_client_tee_supplicant_defaults", + ], + cflags: [ + "-DBINARY_PREFIX=\"TEES\"", + "-pthread", + ], + srcs: [ + "tee-supplicant/src/handle.c", + "tee-supplicant/src/rpmb.c", + "tee-supplicant/src/tee_supp_fs.c", + "tee-supplicant/src/tee_supplicant.c", + "tee-supplicant/src/teec_ta_load.c", + ], + shared_libs: ["libteec"], + local_include_dirs: [ + "libteec/include", + "libteec/src", + "tee-supplicant/src", + ], +} diff --git a/Android.mk b/Android.mk deleted file mode 100644 index 78466d87..00000000 --- a/Android.mk +++ /dev/null @@ -1,101 +0,0 @@ -################################################################################ -# Android optee-client, libckteec and optee-supplicant makefile # -################################################################################ -LOCAL_PATH := $(call my-dir) - -# 3 (debug) is too noisy -CFG_TEE_CLIENT_LOG_LEVEL ?= 2 -CFG_TEE_SUPP_LOG_LEVEL ?= 2 - -# Define Android-specific configuration before including config.mk -CFG_TEE_CLIENT_LOAD_PATH ?= /vendor/lib -CFG_TEE_FS_PARENT_PATH ?= /data/vendor/tee -CFG_TEE_SUPP_PLUGINS ?= y -ifneq ($(strip $($(combo_2nd_arch_prefix)TARGET_TOOLS_PREFIX)),) -CFG_TEE_PLUGIN_LOAD_PATH ?= /vendor/lib64/tee-supplicant/plugins/ -else -CFG_TEE_PLUGIN_LOAD_PATH ?= /vendor/lib/tee-supplicant/plugins/ -endif - -$(info CFG_TEE_PLUGIN_LOAD_PATH = ${CFG_TEE_PLUGIN_LOAD_PATH}) - - -################################################################################ -# Include optee-client common config and flags # -################################################################################ -include $(LOCAL_PATH)/config.mk -include $(LOCAL_PATH)/android_flags.mk - -optee_CFLAGS = $(CFLAGS) - -################################################################################ -# Build libteec.so - TEE (Trusted Execution Environment) shared library # -################################################################################ -include $(CLEAR_VARS) -LOCAL_CFLAGS += $(optee_CFLAGS) - -ifneq ($(CFG_TEE_CLIENT_LOG_FILE),) -LOCAL_CFLAGS += -DTEEC_LOG_FILE=\"$(CFG_TEE_CLIENT_LOG_FILE)\" -endif - -LOCAL_CFLAGS += -DDEBUGLEVEL_$(CFG_TEE_CLIENT_LOG_LEVEL) -LOCAL_CFLAGS += -DBINARY_PREFIX=\"TEEC\" - -LOCAL_SRC_FILES := libteec/src/tee_client_api.c \ - libteec/src/teec_trace.c - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/libteec/include - -LOCAL_PRELINK_MODULE := false -LOCAL_MODULE := libteec - -LOCAL_MODULE_TAGS := optional -LOCAL_VENDOR_MODULE := true - -# Build the 32-bit and 64-bit versions. -LOCAL_MULTILIB := both -LOCAL_MODULE_TARGET_ARCH := arm arm64 - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/libteec/include - -include $(BUILD_SHARED_LIBRARY) - -################################################################################ -# Build libckteec.so # -################################################################################ -include $(CLEAR_VARS) - -LOCAL_CFLAGS += $(optee_CFLAGS) - -LOCAL_SRC_FILES := libckteec/src/pkcs11_api.c \ - libckteec/src/ck_debug.c \ - libckteec/src/ck_helpers.c \ - libckteec/src/invoke_ta.c \ - libckteec/src/pkcs11_processing.c \ - libckteec/src/pkcs11_token.c \ - libckteec/src/serializer.c \ - libckteec/src/serialize_ck.c - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/libteec/include \ - $(LOCAL_PATH)/libckteec/include - -LOCAL_SHARED_LIBRARIES := libteec - -LOCAL_PRELINK_MODULE := false -LOCAL_MODULE := libckteec - -LOCAL_MODULE_TAGS := optional -LOCAL_VENDOR_MODULE := true - -# Build the 32-bit and 64-bit versions. -LOCAL_MULTILIB := both -LOCAL_MODULE_TARGET_ARCH := arm arm64 - -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/libckteec/include - -include $(BUILD_SHARED_LIBRARY) - -################################################################################ -# Build TEE Supplicant # -################################################################################ -include $(LOCAL_PATH)/tee-supplicant/tee_supplicant_android.mk diff --git a/android_flags.mk b/android_flags.mk deleted file mode 100644 index 17c57fe4..00000000 --- a/android_flags.mk +++ /dev/null @@ -1,27 +0,0 @@ -######################################################################### -# COMMON COMPILATION FLAGS # -######################################################################### -CFLAGS := -Wall -Wbad-function-cast -Wcast-align \ - -Werror-implicit-function-declaration -Wextra \ - -Wfloat-equal -Wformat-nonliteral -Wformat-security \ - -Wformat=2 -Winit-self -Wmissing-declarations \ - -Wmissing-format-attribute -Wmissing-include-dirs \ - -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs \ - -Wpointer-arith -Wshadow -Wstrict-prototypes \ - -Wswitch-default \ - -Wwrite-strings -ifeq ($(CFG_WERROR),y) -CFLAGS += -Werror -endif -CFLAGS += -c -fPIC - -DEBUG ?= 0 -ifeq ($(DEBUG), 1) -CFLAGS += -DDEBUG -O0 -g -endif - -RM := rm -rf - -define rmdir -if [ -d "$(1)" ] ; then rmdir --ignore-fail-on-non-empty $(1) ; fi -endef diff --git a/optee_client.device.mk b/optee_client.device.mk new file mode 100644 index 00000000..2a7cd774 --- /dev/null +++ b/optee_client.device.mk @@ -0,0 +1,30 @@ +# +# Copyright 2024 The Android Open-Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Enable TEE supplicant plugin support +$(call soong_config_set,optee_client,cfg_tee_supp_plugins,true) + +# Enable Global Platform Sockets support +$(call soong_config_set,optee_client,cfg_gp_sockets,true) + +# Enable dumping gprof data +$(call soong_config_set,optee_client,cfg_ta_gprof_support,true) + +# Enable dumping ftrace data +$(call soong_config_set,optee_client,cfg_ftrace_support,true) + +# Emulate RPMB +$(call soong_config_set,optee_client,rpmb_emu,true) diff --git a/tee-supplicant/tee_supplicant_android.mk b/tee-supplicant/tee_supplicant_android.mk deleted file mode 100644 index 7bca09cf..00000000 --- a/tee-supplicant/tee_supplicant_android.mk +++ /dev/null @@ -1,66 +0,0 @@ -################################################################################ -# Build tee supplicant # -################################################################################ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_CFLAGS += $(optee_CFLAGS) - -LOCAL_CFLAGS += -DDEBUGLEVEL_$(CFG_TEE_SUPP_LOG_LEVEL) \ - -DBINARY_PREFIX=\"TEES\" \ - -DTEE_FS_PARENT_PATH=\"$(CFG_TEE_FS_PARENT_PATH)\" \ - -DTEEC_LOAD_PATH=\"$(CFG_TEE_CLIENT_LOAD_PATH)\" - -LOCAL_SRC_FILES += src/tee_supplicant.c \ - src/teec_ta_load.c \ - src/tee_supp_fs.c \ - src/rpmb.c \ - src/handle.c - -ifeq ($(CFG_GP_SOCKETS),y) -LOCAL_SRC_FILES += src/tee_socket.c -LOCAL_CFLAGS += -DCFG_GP_SOCKETS=1 -endif - -RPMB_EMU ?= 1 -ifeq ($(RPMB_EMU),1) -LOCAL_SRC_FILES += src/sha2.c src/hmac_sha2.c -LOCAL_CFLAGS += -DRPMB_EMU=1 -endif - -ifneq (,$(filter y,$(CFG_TA_GPROF_SUPPORT) $(CFG_FTRACE_SUPPORT))) -LOCAL_SRC_FILES += src/prof.c -endif - -ifeq ($(CFG_TA_GPROF_SUPPORT),y) -LOCAL_CFLAGS += -DCFG_TA_GPROF_SUPPORT -endif - -ifeq ($(CFG_TEE_SUPP_PLUGINS),y) -LOCAL_SRC_FILES += src/plugin.c - -LOCAL_CFLAGS += -DTEE_SUPP_PLUGINS \ - -DTEE_PLUGIN_LOAD_PATH=\"$(CFG_TEE_PLUGIN_LOAD_PATH)\" - -# Needed to dynamically load user plugins -LOCAL_LDFLAGS += -ldl -# Needed for dlopen() -LOCAL_LDFLAGS += -Wl,-rpath=$(CFG_TEE_PLUGIN_LOAD_PATH) -endif - -LOCAL_CFLAGS += -pthread - -ifeq ($(CFG_FTRACE_SUPPORT),y) -LOCAL_CFLAGS += -DCFG_FTRACE_SUPPORT -endif - -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libteec/src \ - $(LOCAL_PATH)/../libteec/include \ - $(LOCAL_PATH)/src - -LOCAL_SHARED_LIBRARIES := libteec - -LOCAL_MODULE := tee-supplicant -LOCAL_MODULE_TAGS := optional -LOCAL_VENDOR_MODULE := true -include $(BUILD_EXECUTABLE)