Create TEF Simulator devkit package, make helloworld use it 29/139829/6
authorLukasz Kostyra <l.kostyra@samsung.com>
Thu, 20 Jul 2017 12:49:50 +0000 (14:49 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Mon, 11 Sep 2017 14:38:13 +0000 (16:38 +0200)
tee_internal_api.h was additionally modified to fit GP API
specification.

Change-Id: Ibbf7a23b0be5548064df6b6d404fc343070b4f6e

18 files changed:
CMakeLists.txt
PackageMaker/CMakeLists.txt [new file with mode: 0644]
PackageMaker/TAPackageMaker [new file with mode: 0755]
PackageMaker/TA_PackageBuilder.sh [new file with mode: 0755]
TEECLib/CMakeLists.txt
TEEStub/CMakeLists.txt
cmake/CMakeLists.txt [new file with mode: 0644]
cmake/TEFSimulatorDevkit.cmake [new file with mode: 0644]
helloworld/CMakeLists.txt
helloworld/ta/hello_world.c
include/include/tee_internal_api.h
log/CMakeLists.txt
osal/CMakeLists.txt
packaging/tef-simulator-helloworld.spec [new file with mode: 0644]
packaging/tef-simulator.spec
pkgconfig/CMakeLists.txt [new file with mode: 0644]
pkgconfig/tef-simulator-devkit.pc.in [new file with mode: 0644]
ssflib/CMakeLists.txt

index 38e1910..53d03f6 100644 (file)
@@ -63,10 +63,6 @@ SET(TARGET_TEF_SIMULATOR_LOG ${TARGET_TEF_SIMULATOR}-log)
 SET(TARGET_TEF_SIMULATOR_OSAL ${TARGET_TEF_SIMULATOR}-osal)
 SET(TARGET_TEF_SIMULATOR_DAEMON ${TARGET_TEF_SIMULATOR}-daemon)
 SET(TARGET_TEF_SIMULATOR_SSFLIB ${TARGET_TEF_SIMULATOR}-ssflib)
-SET(TARGET_TEF_SIMULATOR_HELLO_WORLD_CA ${TARGET_TEF_SIMULATOR}-helloworld)
-
-# helloworld TA needs to be named after its UUID
-SET(TARGET_TEF_SIMULATOR_HELLO_WORLD_TA 00000000-0000-0000-0000-112233445566)
 
 # below targets need different names due to linking with CAs and TAs (libteec for client)
 SET(TARGET_TEF_SIMULATOR_TEEC_LIB teec)
@@ -84,6 +80,9 @@ SET(LOG_PATH ${TEF_SIMULATOR_ROOT_PATH}/log)
 # osal
 SET(OSAL_PATH ${TEF_SIMULATOR_ROOT_PATH}/osal)
 
+# PackageMaker
+SET(PACKAGE_MAKER_PATH ${TEF_SIMULATOR_ROOT_PATH}/PackageMaker)
+
 # ssflib
 SET(SSFLIB_PATH ${TEF_SIMULATOR_ROOT_PATH}/ssflib)
 SET(SSFLIB_DEP_PATH ${SSFLIB_PATH}/dep)
@@ -101,18 +100,14 @@ SET(TEEC_LIB_PATH ${TEF_SIMULATOR_ROOT_PATH}/TEECLib)
 # TEEStub
 SET(TEE_STUB_PATH ${TEF_SIMULATOR_ROOT_PATH}/TEEStub)
 
-# helloworld
-SET(HELLO_WORLD_PATH ${TEF_SIMULATOR_ROOT_PATH}/helloworld)
-SET(HELLO_WORLD_TA_PATH ${HELLO_WORLD_PATH}/ta)
-SET(HELLO_WORLD_CA_PATH ${HELLO_WORLD_PATH}/host)
-
-
 ############################# subdirectories ##################################
 
+ADD_SUBDIRECTORY(cmake)
 ADD_SUBDIRECTORY(log)
 ADD_SUBDIRECTORY(osal)
+ADD_SUBDIRECTORY(PackageMaker)
+ADD_SUBDIRECTORY(pkgconfig)
 ADD_SUBDIRECTORY(simulatordaemon)
 ADD_SUBDIRECTORY(ssflib)
 ADD_SUBDIRECTORY(TEECLib)
 ADD_SUBDIRECTORY(TEEStub)
-ADD_SUBDIRECTORY(helloworld)
diff --git a/PackageMaker/CMakeLists.txt b/PackageMaker/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3521d3e
--- /dev/null
@@ -0,0 +1,25 @@
+# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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.
+#
+# @file
+# @author  Lukasz Kostyra (l.kostyra@samsung.com)
+# @brief   CMakeLists for tef-simulator TA Package Maker
+#
+
+SET(PACKAGE_MAKER_BINARIES
+    ${PACKAGE_MAKER_PATH}/TA_PackageBuilder.sh
+    ${PACKAGE_MAKER_PATH}/TAPackageMaker
+    )
+
+INSTALL(PROGRAMS ${PACKAGE_MAKER_BINARIES} DESTINATION ${BIN_DIR})
diff --git a/PackageMaker/TAPackageMaker b/PackageMaker/TAPackageMaker
new file mode 100755 (executable)
index 0000000..a478dba
Binary files /dev/null and b/PackageMaker/TAPackageMaker differ
diff --git a/PackageMaker/TA_PackageBuilder.sh b/PackageMaker/TA_PackageBuilder.sh
new file mode 100755 (executable)
index 0000000..df0b5ad
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/bash
+
+TA_SYS_PASS=$1
+INPUT_IMAGE_NAME=$2
+INPUT_IMAGE_MANIFEST=$3
+
+TARGET_SHA_TYPE=sha256
+TARGET_PAGE_SIZE=2048
+
+EXE_PATH=$(readlink -f $(dirname "$0"))
+
+cookie=~/cookies.txt
+
+function func_make_package()
+{
+    echo "Making package"
+
+       if [ "$TA_LAUNCH_MODE" = "debug" ]
+       then
+               #TA Packaging
+               $TA_SYS_PASS/TAPackageMaker $INPUT_IMAGE_NAME $INPUT_IMAGE_MANIFEST $TA_CERTIFICATE $TA_PRIVATE_KEY
+       elif [ "$TA_LAUNCH_MODE" = "release" ]
+       then
+               echo "Release building unimplemented"
+               #TA Packaging
+               $TA_SYS_PASS/TAPackageMaker $INPUT_IMAGE_NAME $INPUT_IMAGE_MANIFEST $TA_CERTIFICATE $TA_PRIVATE_KEY
+       else
+               echo "LAUNCH_MODE Error.!!!"
+               exit -1
+       fi
+
+}
+
+function func_create_certificate()
+{
+       # Generate private key
+       openssl genrsa -out $TA_PRIVATE_KEY 2048
+       # Generate CSR
+       openssl req -new -key $TA_PRIVATE_KEY -out $TA_CERTIFICATE_CSR -subj "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd"
+
+       if [ "$TA_LAUNCH_MODE" = "debug" ]
+       then
+               #generate self-signed certificate
+               openssl x509 -req -days 3650 -in $TA_CERTIFICATE_CSR -extensions v3_ca -signkey $TA_PRIVATE_KEY -out $TA_CERTIFICATE
+       elif [ "$TA_LAUNCH_MODE" = "release" ]
+       then
+               echo "Need to implement.."
+               #generate self-signed certificate
+               openssl x509 -req -days 3650 -in $TA_CERTIFICATE_CSR -extensions v3_ca -signkey $TA_PRIVATE_KEY -out $TA_CERTIFICATE
+       else
+               echo "LAUNCH_MODE Error.!!!"
+               exit -1
+       fi
+}
+
+function func_package_build()
+{
+       # parse manifest
+       export TA_LAUNCH_MODE=$(grep -oP '(?<=launchMode).*(?=")' $INPUT_IMAGE_MANIFEST | grep -oP '(?<=").*(?=)')
+
+       export TA_PRIVILEGE=$(grep -oP '(?<=privilege name).*(?=/>)' $INPUT_IMAGE_MANIFEST | grep -oP '(?<=").*(?=")')
+
+       if [ "$TA_LAUNCH_MODE" = "debug" ]
+       then
+               TA_KEYFOLDER=keystore/debug/
+       elif [ "$TA_LAUNCH_MODE" = "release" ]
+       then
+               TA_KEYFOLDER=keystore/$TA_PRIVILEGE/
+       else
+               echo "LAUNCH_MODE Error.!!!"
+               exit -1
+       fi
+
+       export TA_PRIVATE_KEY=$TA_KEYFOLDER/Kaa_private.pem
+       export TA_CERTIFICATE_CSR=$TA_KEYFOLDER/Kaa_csr.pem
+       export TA_CERTIFICATE=$TA_KEYFOLDER/Kaa_cert.pem
+
+       mkdir -p $TA_KEYFOLDER
+
+       if [ -f $TA_KEYFOLDER/Kaa_cert.pem ]
+       then
+               echo "Certificate exists."
+       else
+               echo "Certificate does NOT exist."
+               func_create_certificate
+       fi
+
+    func_make_package
+}
+
+func_package_build
index 318b9da..bc1e195 100644 (file)
@@ -24,6 +24,10 @@ SET(TEEC_LIB_SOURCES
     ${TEEC_LIB_PATH}/src/teec_connection.c
     )
 
+SET(TEEC_LIB_HEADERS
+    ${TEF_SIMULATOR_INCLUDE_PATH}/include/tee_client_api.h
+    )
+
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_TEEC_LIB} SHARED
     ${TEEC_LIB_SOURCES}
     )
@@ -46,4 +50,5 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_TEEC_LIB}
     ${TARGET_TEF_SIMULATOR_LOG}
     )
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEEC_LIB} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEEC_LIB} DESTINATION ${LIB_DIR})
+INSTALL(FILES ${TEEC_LIB_HEADERS} DESTINATION ${INCLUDE_DIR})
index d63c1aa..d723930 100644 (file)
@@ -45,6 +45,10 @@ SET(TEE_STUB_SOURCES
     ${TEE_STUB_PATH}/TEEStubServer/TADebug.cpp
     )
 
+SET(TEE_STUB_HEADERS
+    ${TEF_SIMULATOR_INCLUDE_PATH}/include/tee_internal_api.h
+    )
+
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_TEE_STUB} STATIC
     ${TEE_STUB_SOURCES}
     )
@@ -65,4 +69,5 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_TEE_STUB}
     boost_system boost_thread
     )
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEE_STUB} DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEE_STUB} DESTINATION ${LIB_DIR})
+INSTALL(FILES ${TEE_STUB_HEADERS} DESTINATION ${INCLUDE_DIR})
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fba987a
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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.
+#
+# @file   CMakeLists.txt
+# @author Lukasz Kostyra (l.kostyra@samsung.com)
+# @brief  CMakeLists file for TEF Simulator CMake Devkit module
+#
+
+INSTALL(FILES
+    ${TEF_SIMULATOR_ROOT_PATH}/cmake/TEFSimulatorDevkit.cmake
+    DESTINATION
+    ${DATA_DIR}/cmake/Modules/
+    )
diff --git a/cmake/TEFSimulatorDevkit.cmake b/cmake/TEFSimulatorDevkit.cmake
new file mode 100644 (file)
index 0000000..4b70da5
--- /dev/null
@@ -0,0 +1,32 @@
+# @file
+# @author Lukasz Kostyra (l.kostyra@samsung.com)
+# @brief  CMake TA development kit module
+
+MESSAGE(STATUS "TEF Simulator Devkit included!")
+
+FIND_PROGRAM(TA_PACKAGE_MAKER TAPackageMaker PATHS /usr/bin)
+FIND_PROGRAM(TA_PACKAGE_BUILDER TA_PackageBuilder.sh PATHS /usr/bin)
+
+IF(NOT TA_PACKAGE_MAKER)
+    MESSAGE(FATAL_ERROR "TAPacakgeMaker tool not found.")
+ENDIF()
+
+IF(NOT TA_PACKAGE_BUILDER)
+    MESSAGE(FATAL_ERROR "TA_PackageBuilder.sh script not found.")
+ENDIF()
+
+MACRO(TEF_GENERATE_TA_IMAGE TargetName TAManifestFile TAImageName)
+    SET(STRIPPED_TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${TargetName}.strip)
+
+    ADD_CUSTOM_COMMAND(TARGET ${TargetName} POST_BUILD
+                       COMMAND ${CMAKE_STRIP} --strip-unneeded -o ${STRIPPED_TARGET_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${TargetName}
+                       COMMENT "Stripping image")
+
+    STRING(TOUPPER "${TargetName}" TargetOutName)
+    STRING(REPLACE "-" "" TargetImage ${TargetOutName})
+
+    SET(${TAImageName} ${TargetImage})
+    ADD_CUSTOM_COMMAND(TARGET ${TargetName} POST_BUILD
+                       COMMAND ${TA_PACKAGE_BUILDER} /usr/bin ${STRIPPED_TARGET_FILE} ${TAManifestFile}
+                       COMMENT "Signing and encrypting image ${${TAImageName}}")
+ENDMACRO()
index 5e59ea0..3c270c7 100644 (file)
 #
 # @file
 # @author  Lukasz Kostyra (l.kostyra@samsung.com)
-# @brief   CMakeLists for tef-simulator CA and TA
+# @brief   CMakeLists for hello world CA and TA
 #
 
+############# Entry defines #############
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT("tef-simulator-helloworld")
+
+INCLUDE(FindPkgConfig)
+
+PKG_CHECK_MODULES(HELLO_WORLD_TA_DEPS REQUIRED
+    tef-simulator-devkit
+    )
+
+# TODO CMake include provided by devkit to encrypt/sign TA
+INCLUDE(TEFSimulatorDevkit)
+
+SET(TARGET_HELLO_WORLD_CA tef-simulator-helloworld)
+SET(TARGET_HELLO_WORLD_TA 00000000-0000-0000-0000-112233445566)
+
+SET(HELLO_WORLD_PATH ${PROJECT_SOURCE_DIR})
+SET(HELLO_WORLD_TA_PATH ${HELLO_WORLD_PATH}/ta)
+SET(HELLO_WORLD_CA_PATH ${HELLO_WORLD_PATH}/host)
+
 ############# TA #############
 
 SET(HELLO_WORLD_TA_SOURCES
     ${HELLO_WORLD_TA_PATH}/hello_world.c
     )
 
-ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
+ADD_EXECUTABLE(${TARGET_HELLO_WORLD_TA}
     ${HELLO_WORLD_TA_SOURCES}
     )
 
-ADD_DEPENDENCIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
-    ${TARGET_TEF_SIMULATOR_TEE_STUB}
-    )
-
-INCLUDE_DIRECTORIES(
-    ${TEF_SIMULATOR_INCLUDE_PATH}/include
+# TEEStub is built in C++, so we must force linking using C++ linker
+SET_TARGET_PROPERTIES(${TARGET_HELLO_WORLD_TA} PROPERTIES
+    LINKER_LANGUAGE "CXX"
     )
 
-TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
-    ${TARGET_TEF_SIMULATOR_TEE_STUB}
+# TODO make pkgconfig to hide these deps
+TARGET_LINK_LIBRARIES(${TARGET_HELLO_WORLD_TA}
+    ${HELLO_WORLD_TA_DEPS_LIBRARIES}
     )
 
-# TODO directory for TAs
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA} DESTINATION ${TASTORE_DIR})
+TEF_GENERATE_TA_IMAGE(${TARGET_HELLO_WORLD_TA} ${HELLO_WORLD_TA_PATH}/hello_world.xml HELLO_WORLD_TA_IMAGE)
+INSTALL(FILES ${HELLO_WORLD_TA_IMAGE} DESTINATION ${TASTORE_DIR})
 
 
 ############# CA #############
@@ -49,22 +68,16 @@ SET(HELLO_WORLD_CA_SOURCES
     ${HELLO_WORLD_CA_PATH}/main.c
     )
 
-ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
+ADD_EXECUTABLE(${TARGET_HELLO_WORLD_CA}
     ${HELLO_WORLD_CA_SOURCES}
     )
 
-ADD_DEPENDENCIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
-    ${TARGET_TEF_SIMULATOR_TEEC_LIB}
-    ${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
-    )
-
 INCLUDE_DIRECTORIES(
-    ${TEF_SIMULATOR_INCLUDE_PATH}/include
     ${HELLO_WORLD_TA_PATH}
     )
 
-TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
-    ${TARGET_TEF_SIMULATOR_TEEC_LIB}
+TARGET_LINK_LIBRARIES(${TARGET_HELLO_WORLD_CA}
+    teec
     )
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA} DESTINATION ${BIN_DIR})
+INSTALL(TARGETS ${TARGET_HELLO_WORLD_CA} DESTINATION ${BIN_DIR})
index 2a6cfe2..188b97d 100644 (file)
@@ -60,7 +60,7 @@ TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types,
        return TEE_SUCCESS;
 }
 
-void TA_CloseSessionEntryPoint(const void *sess_ctx)
+void TA_CloseSessionEntryPoint(void *sess_ctx)
 {
        (void)&sess_ctx;
        LOG_FUNC();
@@ -84,7 +84,7 @@ static TEE_Result inc_value(uint32_t param_types,
        return TEE_SUCCESS;
 }
 
-TEE_Result TA_InvokeCommandEntryPoint(const void *sess_ctx,
+TEE_Result TA_InvokeCommandEntryPoint(void *sess_ctx,
                                                                        uint32_t cmd_id,
                                                                        uint32_t param_types,
                                                                        TEE_Param params[4])
index 71b349d..da84900 100644 (file)
@@ -242,7 +242,7 @@ TEE_Result TA_EXPORT TA_OpenSessionEntryPoint(uint32_t paramTypes,
  * @return his function can return no success or error code.
  *
  */
-void TA_EXPORT TA_CloseSessionEntryPoint(const void* sessionContext);
+void TA_EXPORT TA_CloseSessionEntryPoint(void* sessionContext);
 
 /**
  * Invokes a command within the given sessionContext
@@ -270,7 +270,7 @@ void TA_EXPORT TA_CloseSessionEntryPoint(const void* sessionContext);
  * itself. In any case, the Implementation reports the error code to the client
  * with the origin @ref TEEC_ORIGIN_TRUSTED_APP.
  */
-TEE_Result TA_EXPORT TA_InvokeCommandEntryPoint(const void* sessionContext,
+TEE_Result TA_EXPORT TA_InvokeCommandEntryPoint(void* sessionContext,
     uint32_t commandID,
     uint32_t paramTypes,
     TEE_Param params[4]);
index 7f7c19d..1a67c56 100644 (file)
@@ -23,4 +23,4 @@ SET(LOG_SOURCES
 
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_LOG} ${LOG_SOURCES})
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_LOG} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_LOG} DESTINATION ${LIB_DIR})
index 1ff385c..755cd04 100644 (file)
@@ -28,4 +28,4 @@ SET(OSAL_SOURCES
 
 ADD_LIBRARY(${TARGET_TEF_SIMULATOR_OSAL} ${OSAL_SOURCES})
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_OSAL} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_OSAL} DESTINATION ${LIB_DIR})
diff --git a/packaging/tef-simulator-helloworld.spec b/packaging/tef-simulator-helloworld.spec
new file mode 100644 (file)
index 0000000..ca72eb3
--- /dev/null
@@ -0,0 +1,54 @@
+Name:       tef-simulator-helloworld
+Summary:    Hello World application for TEF TrustZone simulator
+Version:    0.0.1
+Release:    1
+Group:      Security
+License:    Apache-2.0 and BSD-3-Clause
+Source0:    %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: boost-devel
+BuildRequires: pkgconfig(tef-simulator-devkit)
+BuildRequires: tef-simulator-client-devel
+Requires: tef-simulator
+
+%define bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
+%define lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir}
+%define include_dir %{?TZ_SYS_INCLUDE:%TZ_SYS_INCLUDE}%{!?TZ_SYS_INCLUDE:%_includedir}
+%define tastore_dir %{lib_dir}/tastore
+
+%define build_bin_dir %{buildroot}%{bin_dir}
+%define build_include_dir %{buildroot}%{include_dir}
+%define build_tastore_dir %{buildroot}%{tastore_dir}
+
+%description
+An example Hello World application, for TEF TrustZone simulator
+testing purposes.
+
+%prep
+%setup -q
+
+%build
+cd helloworld
+cmake . \
+        -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
+        -DBIN_DIR=%{build_bin_dir} \
+        -DINCLUDE_DIR=%{include_dir} \
+        -DTASTORE_DIR=%{build_tastore_dir}
+make %{?jobs:-j%jobs}
+
+%install
+cd helloworld
+make install
+
+%pre
+
+%post
+tef-simulator-update-uuid-list.sh 00000000000000000000112233445566
+
+%preun
+
+%postun
+
+%files -n %{name}
+%{bin_dir}/tef-simulator-helloworld
+%{tastore_dir}/00000000000000000000112233445566
index cf33c83..8be0b40 100644 (file)
@@ -14,29 +14,82 @@ BuildRequires: pkgconfig(cynara-creds-socket)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(security-manager)
 
-%global bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
-%global sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir}
-%global lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir}
-%global tastore_dir %{lib_dir}/tastore
+%define bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
+%define sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir}
+%define lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir}
+%define data_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:%_datadir}
+%define include_dir %{?TZ_SYS_INCLUDE:%TZ_SYS_INCLUDE}%{!?TZ_SYS_INCLUDE:%_includedir}
+%define tastore_dir %{lib_dir}/tastore
+
+%define build_bin_dir %{buildroot}%{bin_dir}
+%define build_sbin_dir %{buildroot}%{sbin_dir}
+%define build_lib_dir %{buildroot}%{lib_dir}
+%define build_data_dir %{buildroot}%{data_dir}
+%define build_include_dir %{buildroot}%{include_dir}
+%define build_tastore_dir %{buildroot}%{tastore_dir}
 
 %description
 TEF Simulator provides a TrustZone simulated environment
 which can be used on platforms not supporting ARM TrustZone
 environment natively (ex. on an emulator).
 
+
+%package -n %{name}-client
+Summary:   TEF TrustZone simulator client for CA compilation
+Group:     Security/Libraries
+License:   Apache-2.0 and BSD-3-Clause
+Requires: tef-simulator
+
+%description -n %{name}-client
+TEF Simulator Client contains a libteec library compatible
+with TEF Simulator, required to build Client Applications.
+
+
+%package -n %{name}-client-devel
+Summary:   TEF TrustZone simulator client development package
+Group:     Security/Libraries
+License:   Apache-2.0 and BSD-3-Clause
+
+Requires: tef-simulator-client
+
+%description -n %{name}-client-devel
+TEF Simulator Client Devel contains headers required to build
+Client Applications with TEF Simulator Client library.
+
+
+%package -n %{name}-devkit
+Summary:   TEF TrustZone simulator devkit for TA compilation
+Group:     Security/Libraries
+License:   Apache-2.0 and BSD-3-Clause
+
+Requires: tef-simulator
+
+%description -n %{name}-devkit
+TEF Simulator Devkit provides a static library required to
+build Trusted Applications, which are meant to work together
+with TEF Simulator.
+
 %prep
 %setup -q
 
 %build
-%cmake . \
+# cannot call cmake rpmbuild macro because of scripts removing libTEEStub.a, which is a part of devkit
+
+cmake . \
         -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
-        -DBIN_DIR=%{bin_dir} \
-        -DSBIN_DIR=%{sbin_dir} \
-        -DTASTORE_DIR=%{tastore_dir}
-make %{?silent:--silent} %{?jobs:-j%jobs}
+        -DBIN_DIR=%{build_bin_dir} \
+        -DSBIN_DIR=%{build_sbin_dir} \
+        -DLIB_DIR=%{build_lib_dir} \
+        -DDATA_DIR=%{build_data_dir} \
+        -DINCLUDE_DIR=%{build_include_dir} \
+        -DTASTORE_DIR=%{build_tastore_dir} \
+        -DPKGCFG_LIB_DIR=%{lib_dir} \
+        -DPKGCFG_PREFIX=/usr \
+        -DPKGCFG_VERSION=%{version}
+make %{?jobs:-j%jobs}
 
 %install
-%make_install
+make install
 
 %pre
 
@@ -46,12 +99,23 @@ make %{?silent:--silent} %{?jobs:-j%jobs}
 
 %postun
 
-%files -n tef-simulator
+%files -n %{name}
 %{bin_dir}/tef-simulator-daemon
-%{bin_dir}/tef-simulator-helloworld
-%{_libdir}/libtef-simulator-log.so
-%{_libdir}/libtef-simulator-osal.so
-%{_libdir}/libtef-simulator-ssflib.so
-%{_libdir}/libteec.so
-%{tastore_dir}/00000000-0000-0000-0000-112233445566
+%{lib_dir}/libtef-simulator-ssflib.so
 %{sbin_dir}/tef-simulator-update-uuid-list.sh
+
+%files -n %{name}-client
+%{lib_dir}/libteec.so
+
+%files -n %{name}-client-devel
+%{include_dir}/tee_client_api.h
+
+%files -n %{name}-devkit
+%{bin_dir}/TA_PackageBuilder.sh
+%{bin_dir}/TAPackageMaker
+%{lib_dir}/libTEEStub.a
+%{lib_dir}/libtef-simulator-log.a
+%{lib_dir}/libtef-simulator-osal.a
+%{include_dir}/tee_internal_api.h
+%{lib_dir}/pkgconfig/tef-simulator-devkit.pc
+%{data_dir}/cmake/Modules/TEFSimulatorDevkit.cmake
diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt
new file mode 100644 (file)
index 0000000..73dbc1e
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    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.
+#
+# @file        CMakeLists.txt
+# @author      Lukasz Kostyra (l.kostyra@samsung.com)
+# @brief
+#
+
+CONFIGURE_FILE(tef-simulator-devkit.pc.in tef-simulator-devkit.pc @ONLY)
+
+INSTALL(FILES
+    ${TEF_SIMULATOR_ROOT_PATH}/pkgconfig/tef-simulator-devkit.pc
+    DESTINATION
+    ${LIB_DIR}/pkgconfig
+    )
diff --git a/pkgconfig/tef-simulator-devkit.pc.in b/pkgconfig/tef-simulator-devkit.pc.in
new file mode 100644 (file)
index 0000000..04ee70a
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@PKGCFG_PREFIX@
+exec_prefix=${prefix}
+libdir=@PKGCFG_LIB_DIR@
+includedir=${prefix}/include
+
+Name: tef-simulator-devkit
+Description: TEF Simulator TA development kit
+Version: @PKGCFG_VERSION@
+Requires: boost dlog openssl
+Libs: -L${libdir} -lTEEStub -ltef-simulator-ssflib -ltef-simulator-log -lboost_thread -lboost_system -ldlog
+Cflags: -I${includedir}/
index 905ad01..e806c2b 100644 (file)
@@ -104,4 +104,4 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_SSFLIB}
     ${TARGET_TEF_SIMULATOR_LOG}
     )
 
-INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_SSFLIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_SSFLIB} LIBRARY DESTINATION ${LIB_DIR})