Use libpsa in ts-demo
Modify the demo application to use the prebuilt PSA clients from
libpsa instead of directly building these.
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
Change-Id: Ib714c7ad901039c56ec6b021ff052b0329c79605
diff --git a/deployments/ts-demo/ts-demo.c b/deployments/ts-demo/ts-demo.c
new file mode 100644
index 0000000..c7ef52b
--- /dev/null
+++ b/deployments/ts-demo/ts-demo.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <app/ts-demo/ts-demo.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "libpsa.h"
+
+int main(int argc, char *argv[])
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ const char *service_name = "sn:trustedfirmware.org:crypto:0";
+
+ if (argc > 1)
+ service_name = argv[1];
+
+ psa_status = libpsa_init_crypto_context(service_name);
+
+ if (psa_status) {
+ printf("libpsa_init_crypto_context failed: %d\n", psa_status);
+ return psa_status;
+ }
+
+ psa_status = run_ts_demo(true);
+
+ libpsa_deinit_its_context();
+
+ if (psa_status)
+ printf("\n*** ts-demo failed ***\n\n");
+ else
+ printf("\n*** ts-demo was successful ***\n\n");
+
+ return psa_status;
+}
diff --git a/deployments/ts-demo/ts-demo.cmake b/deployments/ts-demo/ts-demo.cmake
index 0769df9..a7fda2c 100644
--- a/deployments/ts-demo/ts-demo.cmake
+++ b/deployments/ts-demo/ts-demo.cmake
@@ -12,19 +12,18 @@
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
-# Use libts for locating and accessing services. An appropriate version of
-# libts will be imported for the environment in which service tests are
-# deployed.
+# Use libpsa for locating PSA services. An appropriate version of
+# libpsa will be imported for the environment.
#-------------------------------------------------------------------------------
-include(${TS_ROOT}/deployments/libts/libts-import.cmake)
-target_link_libraries(ts-demo PRIVATE libts::ts)
+include(${TS_ROOT}/deployments/libpsa/libpsa-import.cmake)
+target_link_libraries(ts-demo PRIVATE libpsa::psa)
#-------------------------------------------------------------------------------
# Common main for all deployments
#
#-------------------------------------------------------------------------------
target_sources(ts-demo PRIVATE
- "${CMAKE_CURRENT_LIST_DIR}/ts-demo.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/ts-demo.c"
)
#-------------------------------------------------------------------------------
@@ -36,26 +35,9 @@
BASE_DIR ${TS_ROOT}
COMPONENTS
"components/app/ts-demo"
- "components/common/tlv"
- "components/service/common/include"
- "components/service/common/client"
- "components/service/crypto/client/cpp"
- "components/service/crypto/client/cpp/protocol/packed-c"
- "protocols/service/crypto/packed-c"
)
#-------------------------------------------------------------------------------
-# Components used from external projects
-#
-#-------------------------------------------------------------------------------
-
-# MbedTLS provides libmbedcrypto
-set(MBEDTLS_USER_CONFIG_FILE "${TS_ROOT}/external/MbedTLS/config/crypto_posix.h"
- CACHE STRING "Configuration file for mbedcrypto")
-include(${TS_ROOT}/external/MbedTLS/MbedTLS.cmake)
-target_link_libraries(ts-demo PRIVATE MbedTLS::mbedcrypto)
-
-#-------------------------------------------------------------------------------
# Define install content.
#
#-------------------------------------------------------------------------------
diff --git a/deployments/ts-demo/ts-demo.cpp b/deployments/ts-demo/ts-demo.cpp
deleted file mode 100644
index 55948a3..0000000
--- a/deployments/ts-demo/ts-demo.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// SPDX-License-Identifier: BSD-2-Clause
-/*
- * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
- */
-
-#include <cstdio>
-#include <service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
-#include <app/ts-demo/ts-demo.h>
-#include <service_locator.h>
-#include <rpc_caller.h>
-
-int main(int argc, char *argv[]) {
- (void) argc;
- (void) argv;
-
- int status = -1;
- struct service_context *crypto_service_context = NULL;
-
- service_locator_init();
-
- crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0");
-
- if (crypto_service_context) {
-
- struct rpc_caller_session *session = NULL;
-
- session = service_context_open(crypto_service_context);
-
- if (session) {
-
- packedc_crypto_client crypto_client(session);
-
- status = run_ts_demo(&crypto_client, true);
-
- if (status != 0) {
- printf("run_ts_demo failed\n");
- }
-
- service_context_close(crypto_service_context, session);
- }
- else {
- printf("Failed to open rpc session\n");
- }
-
- service_context_relinquish(crypto_service_context);
- }
- else {
- printf("Failed to discover crypto service\n");
- }
-
- return status;
-}