Test: Add SST test partition
Adds an SST test partition, which can be used to call the
sst_system_prepare() function from the SST test partition's
context.
Change-Id: Ib07a88e5f05fc181da2b9276279e57618fb059e4
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
diff --git a/test/suites/sst/secure/sst_rollback_protection_testsuite.c b/test/suites/sst/secure/sst_rollback_protection_testsuite.c
index 3194b91..de96fdb 100644
--- a/test/suites/sst/secure/sst_rollback_protection_testsuite.c
+++ b/test/suites/sst/secure/sst_rollback_protection_testsuite.c
@@ -15,11 +15,11 @@
#include "tfm_memory_utils.h"
#include "s_test_helpers.h"
-/* This include is required to expose the sst_system_prepare function to
- * simulate a reboot in the system by calling sst_system_prepare().
+/* This include is required to expose the sst_system_prepare function, via the
+ * tfm_sst_test_system_prepare API, to simulate a reboot in the system.
* sst_system_prepare is called when the SST service is initialized.
*/
-#include "secure_fw/services/secure_storage/sst_object_system.h"
+#include "test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.h"
#include "test/framework/test_framework_helpers.h"
@@ -184,7 +184,7 @@
* Prepare should not fail as the NV counters has the same values and
* the SST area authentication is aligned with those values.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("AM prepare should not fail");
return;
@@ -258,7 +258,7 @@
* Prepare should fail as the SST area version does not match the
* NV counters values.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_ERROR_OPERATION_FAILED) {
TEST_FAIL("SST system prepare should fail as version is old");
return;
@@ -294,7 +294,7 @@
}
/* Calls sst_system_prepare to mark the SST area as a valid image */
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -348,7 +348,7 @@
* Prepare should not fail as the SST area version match NV counters 1 and
* 2 values.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -417,7 +417,7 @@
* Prepare should not fail as the SST area version match the NV counter 2
* and 3 values.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -491,7 +491,7 @@
*
* Prepare should not fail as the SST area version match the NV counter 1.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -568,7 +568,7 @@
*
* Prepare should not fail as the SST area version match the NV counter 1.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -638,7 +638,7 @@
* Prepare should fail as the SST area version match the NV counter 2 and
* the other counters are different.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_ERROR_OPERATION_FAILED) {
TEST_FAIL("SST system prepare should fail");
return;
@@ -668,7 +668,7 @@
}
/* Calls sst_system_prepare to mark the SST area as a valid image */
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
@@ -730,7 +730,7 @@
* Prepare should fail as the SST area version match the NV counter 2 and
* the other counters are different.
*/
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_ERROR_OPERATION_FAILED) {
TEST_FAIL("AM prepare should fail");
return;
@@ -766,7 +766,7 @@
}
/* Calls sst_system_prepare to mark the SST area as a valid image */
- status = sst_system_prepare();
+ status = tfm_sst_test_system_prepare();
if (status != PSA_PS_SUCCESS) {
TEST_FAIL("SST system prepare should not fail");
return;
diff --git a/test/test_services/CMakeLists.inc b/test/test_services/CMakeLists.inc
index 33d66e9..6523292 100644
--- a/test/test_services/CMakeLists.inc
+++ b/test/test_services/CMakeLists.inc
@@ -61,6 +61,13 @@
)
endif()
+if (NOT DEFINED TFM_PARTITION_TEST_SST)
+ message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined.")
+elseif (TFM_PARTITION_TEST_SST)
+ list(APPEND ALL_SRC_C_S "${CORE_TEST_DIR}/tfm_sst_test_service/tfm_sst_test_service.c"
+ "${CORE_TEST_DIR}/tfm_sst_test_service/tfm_sst_test_service_api.c")
+endif()
+
embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
embedded_include_directories(PATH ${TFM_ROOT_DIR}/platform/include ABSOLUTE)
diff --git a/test/test_services/tfm_sst_test_service/psa_manifest/tfm_sst_test_service.h b/test/test_services/tfm_sst_test_service/psa_manifest/tfm_sst_test_service.h
new file mode 100644
index 0000000..d7f1a70
--- /dev/null
+++ b/test/test_services/tfm_sst_test_service/psa_manifest/tfm_sst_test_service.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
+
+#ifndef __PSA_MANIFEST_TFM_SST_TEST_SERVICE_H__
+#define __PSA_MANIFEST_TFM_SST_TEST_SERVICE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TFM_SST_TEST_PREPARE_SIGNAL (1U << (0 + 4))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __PSA_MANIFEST_TFM_SST_TEST_SERVICE_H__ */
diff --git a/test/test_services/tfm_sst_test_service/tfm_sst_test_service.c b/test/test_services/tfm_sst_test_service/tfm_sst_test_service.c
new file mode 100644
index 0000000..bd29085
--- /dev/null
+++ b/test/test_services/tfm_sst_test_service/tfm_sst_test_service.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifdef TFM_PSA_API
+#include "psa/service.h"
+#include "psa_manifest/tfm_sst_test_service.h"
+#else
+#include "psa/client.h"
+#endif
+
+#include "secure_fw/services/secure_storage/sst_object_system.h"
+
+psa_status_t tfm_sst_test_prepare(psa_invec *in_vec, size_t in_len,
+ psa_outvec *out_vec, size_t out_len)
+{
+ (void)in_vec;
+ (void)in_len;
+ (void)out_vec;
+ (void)out_len;
+
+ return sst_system_prepare();
+}
+
+psa_status_t tfm_sst_test_init(void)
+{
+#ifdef TFM_PSA_API
+ psa_msg_t msg;
+
+ while (1) {
+ (void)psa_wait(TFM_SST_TEST_PREPARE_SIGNAL, PSA_BLOCK);
+ (void)psa_get(TFM_SST_TEST_PREPARE_SIGNAL, &msg);
+ switch (msg.type) {
+ case PSA_IPC_CONNECT:
+ case PSA_IPC_DISCONNECT:
+ psa_reply(msg.handle, PSA_SUCCESS);
+ break;
+ case PSA_IPC_CALL:
+ psa_reply(msg.handle, sst_system_prepare());
+ break;
+ }
+ }
+#endif
+ return PSA_SUCCESS;
+}
diff --git a/test/test_services/tfm_sst_test_service/tfm_sst_test_service.yaml b/test/test_services/tfm_sst_test_service/tfm_sst_test_service.yaml
new file mode 100644
index 0000000..b69d0c6
--- /dev/null
+++ b/test/test_services/tfm_sst_test_service/tfm_sst_test_service.yaml
@@ -0,0 +1,39 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+{
+ "psa_framework_version": 1.0,
+ "name": "TFM_SP_SST_TEST",
+ "type": "PSA-ROT",
+ "priority": "NORMAL",
+ "entry_point": "tfm_sst_test_init",
+ "stack_size": "0x400",
+ "heap_size": "0",
+ "secure_functions": [
+ {
+ "name": "TFM_SST_TEST_PREPARE",
+ "signal": "TFM_SST_TEST_PREPARE",
+ "non_secure_clients": false,
+ "version": 1,
+ "version_policy": "STRICT"
+ },
+ ],
+ "services": [
+ {
+ "name": "TFM_SST_TEST_PREPARE",
+ "sid": "0x0000F0C0",
+ "non_secure_clients": false,
+ "version": 1,
+ "version_policy": "STRICT"
+ }
+ ],
+ "linker_pattern": {
+ "object_list": [
+ "*tfm_sst_test_service.*",
+ ]
+ }
+}
diff --git a/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.c b/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.c
new file mode 100644
index 0000000..a50b490
--- /dev/null
+++ b/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_sst_test_service_api.h"
+
+#ifdef TFM_PSA_API
+#include "psa/client.h"
+#include "psa_manifest/sid.h"
+#else
+#include "tfm_veneers.h"
+#endif
+
+__attribute__((section("SFN")))
+psa_status_t tfm_sst_test_system_prepare(void)
+{
+#ifdef TFM_PSA_API
+ psa_handle_t handle;
+ psa_status_t status;
+
+ handle = psa_connect(TFM_SST_TEST_PREPARE_SID,
+ TFM_SST_TEST_PREPARE_VERSION);
+ if (!PSA_HANDLE_IS_VALID(handle)) {
+ return PSA_ERROR_GENERIC_ERROR;
+ }
+
+ status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0);
+ psa_close(handle);
+
+ return status;
+#else
+ return tfm_tfm_sst_test_prepare_veneer(NULL, 0, NULL, 0);
+#endif
+}
diff --git a/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.h b/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.h
new file mode 100644
index 0000000..5fb558a
--- /dev/null
+++ b/test/test_services/tfm_sst_test_service/tfm_sst_test_service_api.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_SST_TEST_SERVICE_API_H__
+#define __TFM_SST_TEST_SERVICE_API_H__
+
+#include "psa/error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Requests the SST Test Service to call sst_system_prepare().
+ *
+ * \return Returns error code as specified in \ref psa_status_t
+ */
+psa_status_t tfm_sst_test_system_prepare(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_SST_TEST_SERVICE_API_H__ */