Add secure storage service and demo deployments
Change-Id: Ie321a3faca1a57fbfbd7709fa3f2e983e002f0b3
Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
diff --git a/deployments/secure-storage/opteesp/.gitignore b/deployments/secure-storage/opteesp/.gitignore
new file mode 100644
index 0000000..378eac2
--- /dev/null
+++ b/deployments/secure-storage/opteesp/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/deployments/secure-storage/opteesp/CMakeLists.txt b/deployments/secure-storage/opteesp/CMakeLists.txt
new file mode 100644
index 0000000..6394bfe
--- /dev/null
+++ b/deployments/secure-storage/opteesp/CMakeLists.txt
@@ -0,0 +1,100 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the secure-storage deployment for opteesp
+#
+# Builds the secure storage service provider for running in an SEL0 secure
+# partition hosted by OPTEE in the role of SPM.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+project(trusted-services LANGUAGES C ASM)
+add_executable(secure-storage)
+target_include_directories(secure-storage PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+set(SP_UUID "dc1eef48-b17a-4ccf-ac8b-dfcff7711b14")
+
+
+# Include SP DEV KIT interface
+set(SP_DEV_KIT_INC_DIR ${CMAKE_CURRENT_LIST_DIR})
+list(APPEND CMAKE_MODULE_PATH "${TS_ROOT}/external/Spdevkit")
+find_package(Spdevkit COMPONENTS SP_HEADER interface)
+
+sp_dev_kit_configure_linking(TARGET secure-storage DEFINES ARM64=1)
+target_link_libraries(secure-storage ${SP_DEV_KIT_LIBRARIES})
+
+add_components(TARGET "secure-storage"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ components/messaging/ffa/libsp
+ components/rpc/ffarpc/endpoint
+ components/rpc/common/interface
+ components/service/common/provider
+ components/service/secure_storage/provider/secure_flash_store
+ components/service/secure_storage/provider/secure_flash_store/flash_fs
+ components/service/secure_storage/provider/secure_flash_store/flash
+ protocols/rpc/common/packed-c
+ protocols/service/secure_storage/packed-c
+ environments/opteesp
+)
+
+target_sources(secure-storage PRIVATE
+ sp.c
+)
+
+target_compile_definitions(secure-storage PRIVATE
+ ARM64=1
+)
+
+target_include_directories(secure-storage PRIVATE
+ ${TS_ROOT}
+ ${TS_ROOT}/components
+ ${TS_ROOT}/deployments/secure-storage/opteesp
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ target_compile_options(secure-storage PRIVATE
+ -fdiagnostics-show-option
+ -fpic
+ -gdwarf-2
+ -mstrict-align
+ -O0
+ -std=gnu99
+ )
+
+ # Options for GCC that control linking
+ target_link_options(secure-storage PRIVATE
+ -e __sp_entry
+ -fno-lto
+ -nostdlib
+ -pie
+ -zmax-page-size=4096
+ )
+ # Options directly for LD, these are not understood by GCC
+ target_link_options(secure-storage PRIVATE
+ -Wl,--as-needed
+ -Wl,--sort-section=alignment
+ # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
+ )
+endif()
+
+compiler_generate_stripped_elf(TARGET secure-storage NAME "${SP_UUID}.stripped.elf" RES STRIPPED_ELF)
+
+######################################## install
+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+endif()
+install(TARGETS secure-storage
+ PUBLIC_HEADER DESTINATION include
+ RUNTIME DESTINATION bin
+ )
+install(FILES ${STRIPPED_ELF} DESTINATION bin)
+
+set(EXPORT_SP_NAME "secure-storage")
+set(EXPORT_SP_UUID ${SP_UUID})
+include(${TS_ROOT}/environments/opteesp/ExportSp.cmake)
diff --git a/deployments/secure-storage/opteesp/optee_sp_user_defines.h b/deployments/secure-storage/opteesp/optee_sp_user_defines.h
new file mode 100644
index 0000000..e773055
--- /dev/null
+++ b/deployments/secure-storage/opteesp/optee_sp_user_defines.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef SP_HEADER_DEFINES_H
+#define SP_HEADER_DEFINES_H
+
+/* To get UUID definition */
+#include "sp.h"
+
+#define OPTEE_SP_FLAGS 0
+
+/* Provisioned stack size */
+#define OPTEE_SP_STACK_SIZE (64 * 1024)
+
+/* Provisioned heap size */
+#define OPTEE_SP_HEAP_SIZE (32 * 1024)
+
+#endif /* SP_HEADER_DEFINES_H */
diff --git a/deployments/secure-storage/opteesp/sp.c b/deployments/secure-storage/opteesp/sp.c
new file mode 100644
index 0000000..d04dbb2
--- /dev/null
+++ b/deployments/secure-storage/opteesp/sp.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "sp.h"
+#include <ffa_api.h>
+#include <components/rpc/common/endpoint/call_ep.h>
+#include <components/rpc/ffarpc/endpoint/ffarpc_call_ep.h>
+#include <components/service/secure_storage/provider/secure_flash_store/sfs_provider.h>
+#include <components/service/common/provider/service_provider.h>
+#include <sp_api.h>
+#include <sp_rxtx.h>
+#include <trace.h>
+
+uint16_t own_id = 0;
+static uint8_t tx_buffer[4096] __aligned(4096);
+static uint8_t rx_buffer[4096] __aligned(4096);
+
+void sp_main(struct ffa_init_info *init_info)
+{
+ ffa_result ffa_res;
+ sp_result sp_res;
+ struct call_ep *sfs_ep;
+ struct ffa_call_ep ffa_call_ep;
+ struct ffa_direct_msg req_msg;
+ struct ffa_direct_msg resp_msg;
+ struct sfs_provider sfs_provider;
+
+ /* Boot */
+ (void) init_info;
+
+ ffa_res = ffa_id_get(&own_id);
+ if (ffa_res != FFA_OK) {
+ EMSG("id get error: %d", ffa_res);
+ }
+
+ sp_res = sp_rxtx_buffer_map(tx_buffer, rx_buffer, sizeof(rx_buffer));
+ if (sp_res != SP_RESULT_OK) {
+ EMSG("rxtx map error: %d", sp_res);
+ }
+
+ sfs_ep = sfs_provider_init(&sfs_provider);
+ ffa_call_ep_init(&ffa_call_ep, sfs_ep);
+
+ /* End of boot phase */
+ ffa_msg_wait(&req_msg);
+
+ while (1) {
+ if (req_msg.function_id == FFA_MSG_SEND_DIRECT_REQ_32) {
+ ffa_call_ep_receive(&ffa_call_ep, &req_msg, &resp_msg);
+
+ ffa_msg_send_direct_resp(req_msg.destination_id,
+ req_msg.source_id, resp_msg.args[0], resp_msg.args[1],
+ resp_msg.args[2], resp_msg.args[3], resp_msg.args[4],
+ &req_msg);
+ }
+ }
+}
+
+void sp_interrupt_handler(uint32_t interrupt_id)
+{
+ (void)interrupt_id;
+}
diff --git a/deployments/secure-storage/opteesp/sp.h b/deployments/secure-storage/opteesp/sp.h
new file mode 100644
index 0000000..299c95e
--- /dev/null
+++ b/deployments/secure-storage/opteesp/sp.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef SP_H
+#define SP_H
+
+#define OPTEE_SP_UUID \
+ { 0xdc1eef48, 0xb17a, 0x4ccf, \
+ { 0xac, 0x8b, 0xdf, 0xcf, 0xf7, 0x71, 0x1b, 0x14 } }
+
+#define SP_UUID_BYTES \
+ { 0xdc, 0x1e, 0xef, 0x48, 0xb1, 0x7a, 0x4c, 0xcf, \
+ 0xac, 0x8b, 0xdf, 0xcf, 0xf7, 0x71, 0x1b, 0x14, }
+
+#endif /* SP_H */