diff --git a/.gitignore b/.gitignore index 22b08fc8..4a8c7fce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,16 @@ -cscope.* build -out -Debug -*.swp +CMakeCache.txt +CMakeFiles +cmake_install.cmake .cproject -.project +cscope.* +Debug +GPATH +GRTAGS +GTAGS /libs +Makefile /obj +out +.project +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..fcb0f738 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required (VERSION 3.4) +project (optee_client C) + +# https://cmake.org/Wiki/CMake_Useful_Variables +set (CMAKE_TOOLCHAIN_FILE CMakeToolchain.txt) + +include(GNUInstallDirs) + +################################################################################ +# Compiler flags: +# We want to use the same flags in the entire optee_client git +################################################################################ +add_compile_options ( + -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 -Wunsafe-loop-optimizations + -Wwrite-strings -Werror -fPIC +) + +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + +add_subdirectory (libteec) +add_subdirectory (tee-supplicant) +add_subdirectory (public) diff --git a/CMakeToolchain.txt b/CMakeToolchain.txt new file mode 100644 index 00000000..71eb52f5 --- /dev/null +++ b/CMakeToolchain.txt @@ -0,0 +1,3 @@ +set (CMAKE_SYSTEM_NAME Linux) + +set (CMAKE_SYSTEM_PROCESSOR arm) diff --git a/README.md b/README.md index f3c313ad..fc129906 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,33 @@ folder. $ git clone https://github.com/OP-TEE/optee_client.git ### Build - $ cd $HOME/devel/optee_client - $ make +During a transition period it will be possible to build using the plain old +makefiles, but it will also be possible to build using CMake. To build using +the old makefiles, simply run: +```bash +$ cd $HOME/devel/optee_client +$ make +``` + +If you prefer using CMake instead, then create a build folder where you run +cmake, like this for example: +```bash +$ cd $HOME/devel/optee_client +$ make build +$ cd build + +# This example uses an Armv7-A / 32bit toolchain, adjust accordingly. +$ export CC="/toolchains/aarch32/bin/arm-linux-gnueabihf-gcc" + +# cmake here take optional flags, if you for example wants to install files in +# another location than default, then one can use +# -DCMAKE_INSTALL_PREFIX= as an argument to cmake. +$ cmake .. +$ make + +# Optional +$ make install +``` For a 64-bit build: diff --git a/libteec/CMakeLists.txt b/libteec/CMakeLists.txt new file mode 100644 index 00000000..4698494a --- /dev/null +++ b/libteec/CMakeLists.txt @@ -0,0 +1,74 @@ +project(libteec C) + +set(PROJECT_VERSION "1.0.0") + +################################################################################ +# Packages +################################################################################ +find_package(Threads REQUIRED) +if(NOT THREADS_FOUND) + message(FATAL_ERROR "Threads not found") +endif() + +################################################################################ +# Configuration flags always included +################################################################################ +option (CFG_TEE_BENCHMARK "Build with benchmark support" OFF) + +set (CFG_TEE_CLIENT_LOG_LEVEL "1" CACHE STRING "libteec log level") +set (CFG_TEE_CLIENT_LOG_FILE "/data/teec.log" CACHE STRING "Location of libteec log") + +################################################################################ +# Source files +################################################################################ +set (SRC + src/tee_client_api.c + src/teec_trace.c +) + +if (CFG_TEE_BENCHMARK) + set (SRC ${SRC} src/teec_benchmark.c) +endif() + +################################################################################ +# Built library +################################################################################ +add_library (teec SHARED ${SRC}) + +set_target_properties (teec PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_NAME} +) + +################################################################################ +# Flags always set +################################################################################ +target_compile_definitions (teec + PRIVATE -D_GNU_SOURCE + PRIVATE -DCFG_TEE_CLIENT_LOG_LEVEL=${CFG_TEE_CLIENT_LOG_LEVEL} + PRIVATE -DCFG_TEE_CLIENT_LOG_FILE="${CFG_TEE_CLIENT_LOG_FILE}" + PRIVATE -DBINARY_PREFIX="LT" +) + +################################################################################ +# Optional flags +################################################################################ +if (CFG_TEE_BENCHMARK) + target_compile_definitions (teec PRIVATE -DCFG_TEE_BENCHMARK) +endif() + +################################################################################ +# Public and private header and library dependencies +################################################################################ +target_include_directories(teec PUBLIC include) + +target_link_libraries (teec + PUBLIC ${CMAKE_THREAD_LIBS_INIT} # this is pthreads + PRIVATE optee-client-headers) + +################################################################################ +# Install targets +################################################################################ +# FIXME: This should in someway harmonize with CFG_TEE_CLIENT_LOAD_PATH +# FIXME: Should we change this to /usr/local/lib? +install (TARGETS teec DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/public/CMakeLists.txt b/public/CMakeLists.txt new file mode 100644 index 00000000..8e6071cb --- /dev/null +++ b/public/CMakeLists.txt @@ -0,0 +1,17 @@ +project (optee-client-headers C) + +################################################################################ +# Built library +################################################################################ +add_library(${PROJECT_NAME} INTERFACE) + +################################################################################ +# Public and private header and library dependencies +################################################################################ +target_include_directories(teec PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +################################################################################ +# Install targets +################################################################################ +install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/tee-supplicant/CMakeLists.txt b/tee-supplicant/CMakeLists.txt new file mode 100644 index 00000000..bc32e76f --- /dev/null +++ b/tee-supplicant/CMakeLists.txt @@ -0,0 +1,84 @@ +project (tee-supplicant C) + +################################################################################ +# Configuration flags always included +################################################################################ +option (CFG_TA_TEST_PATH "Enable tee-supplicant to load from test/debug path" ON) +option (CFG_TA_GPROF_SUPPORT "Enabled tee-supplicant profiling support" OFF) + +set (CFG_TEE_SUPP_LOG_LEVEL "1" CACHE STRING "tee-supplicant log level") +set (CFG_TEE_SUPP_LOG_FILE "/data/teesupp.log" CACHE STRING "Location of tee-supplicant log") +# FIXME: Question is, is this really needed? Should just use defaults from # GNUInstallDirs? +set (CFG_TEE_CLIENT_LOAD_PATH "/lib" CACHE STRING "Location of libteec.so") +set (CFG_TEE_FS_PARENT_PATH "/data" CACHE STRING "Location of TEE filesystem (secure storage)") +# FIXME: Why do we have if defined(CFG_GP_SOCKETS) && CFG_GP_SOCKETS == 1 in the c-file? +set (CFG_GP_SOCKETS "1" CACHE STRING "Enable GlobalPlatform Socket API support") + +################################################################################ +# Source files +################################################################################ +set (SRC + src/handle.c + src/hmac_sha2.c + src/rpmb.c + src/sha2.c + src/tee_supp_fs.c + src/tee_supplicant.c + src/teec_ta_load.c +) + +if (CFG_GP_SOCKETS) + set (SRC ${SRC} src/tee_socket.c) +endif() + +if (CFG_TA_GPROF_SUPPORT) + set (SRC ${SRC} src/gprof.c) +endif() + +################################################################################ +# Built binary +################################################################################ +add_executable (${PROJECT_NAME} ${SRC}) + +################################################################################ +# Flags always set +################################################################################ +target_compile_definitions (${PROJECT_NAME} + PRIVATE -DCFG_TEE_SUPP_LOG_LEVEL=${CFG_TEE_SUPP_LOG_LEVEL} + PRIVATE -DCFG_TEE_SUPP_LOG_FILE="${CFG_TEE_SUPP_LOG_FILE}" + PRIVATE -DTEEC_LOAD_PATH="${CFG_TEE_CLIENT_LOAD_PATH}" + PRIVATE -DTEE_FS_PARENT_PATH="${CFG_TEE_FS_PARENT_PATH}" + PRIVATE -DBINARY_PREFIX="TSUP" +) + +################################################################################ +# Optional flags +################################################################################ +if (CFG_GP_SOCKETS) + target_compile_definitions (${PROJECT_NAME} + PRIVATE -DCFG_GP_SOCKETS=${CFG_GP_SOCKETS}) +endif() + +if (CFG_TA_TEST_PATH) + target_compile_definitions (${PROJECT_NAME} + PRIVATE -DCFG_TA_TEST_PATH=${CFG_TA_TEST_PATH}) +endif() + +if (CFG_TA_GPROF_SUPPORT) + target_compile_definitions (${PROJECT_NAME} + PRIVATE -DCFG_TA_GPROF_SUPPORT) +endif() + +################################################################################ +# Public and private header and library dependencies +################################################################################ +target_include_directories(${PROJECT_NAME} PRIVATE src) + +target_link_libraries (${PROJECT_NAME} + PRIVATE teec + PRIVATE optee-client-headers) + +################################################################################ +# Install targets +################################################################################ +install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_SBINDIR})