From cae1ebf33dbc5cf00a81cc89c286f54c98dd7566 Mon Sep 17 00:00:00 2001 From: Oren Cohen Date: Thu, 24 Jan 2019 18:42:10 +0200 Subject: [PATCH] Add new ITS reset SID Only accessible from SPE --- .../psa_prot_internal_storage.cpp | 13 +++++++++++++ .../COMPONENT_PSA_SRV_IMPL/pits_impl.cpp | 10 ++++++++++ .../COMPONENT_PSA_SRV_IMPL/pits_impl.h | 1 + .../psa_prot_internal_storage.c | 16 ++++++++++++++++ .../COMPONENT_SPE/its_partition.c | 10 ++++++++++ .../psa_prot_internal_storage/pits_psa.json | 8 ++++++++ 6 files changed, 58 insertions(+) diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_EMUL/psa_prot_internal_storage.cpp b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_EMUL/psa_prot_internal_storage.cpp index 00ff6a3c3a..08f784eb43 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_EMUL/psa_prot_internal_storage.cpp +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_EMUL/psa_prot_internal_storage.cpp @@ -92,3 +92,16 @@ psa_its_status_t psa_its_remove(psa_its_uid_t uid) return psa_its_remove_impl(PSA_ITS_EMUL_PID, uid); } + +extern "C" psa_its_status_t psa_its_reset() +{ + // KVStore initiation: + // - In EMUL (non-secure single core) we do it here since we don't have another context to do it inside. + // - Repeating calls has no effect + int kv_status = kv_init_storage_config(); + if (kv_status != MBED_SUCCESS) { + return PSA_ITS_ERROR_STORAGE_FAILURE; + } + + return psa_its_reset_impl(); +} diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp index 2578e4469a..c02be144f8 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.cpp @@ -307,6 +307,16 @@ psa_its_status_t psa_its_remove_impl(int32_t pid, psa_its_uid_t uid) return convert_status(status); } +psa_its_status_t psa_its_reset_impl() +{ + if (!kvstore) { + its_init(); + } + + int status = kvstore->reset(); + return convert_status(status); +} + #ifdef __cplusplus } #endif diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h index 5424708655..090805d5c8 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IMPL/pits_impl.h @@ -33,6 +33,7 @@ psa_its_status_t psa_its_set_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_ psa_its_status_t psa_its_get_impl(int32_t pid, psa_its_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data); psa_its_status_t psa_its_get_info_impl(int32_t pid, psa_its_uid_t uid, struct psa_its_info_t *p_info); psa_its_status_t psa_its_remove_impl(int32_t pid, psa_its_uid_t uid); +psa_its_status_t psa_its_reset_impl(); #ifdef __cplusplus } diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IPC/psa_prot_internal_storage.c b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IPC/psa_prot_internal_storage.c index 10402bb80a..48c840e29b 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IPC/psa_prot_internal_storage.c +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_PSA_SRV_IPC/psa_prot_internal_storage.c @@ -114,3 +114,19 @@ psa_its_status_t psa_its_remove(psa_its_uid_t uid) psa_close(conn); return status; } + +psa_its_status_t psa_its_reset() +{ + psa_handle_t conn = psa_connect(PSA_ITS_RESET, 1); + if (conn <= PSA_NULL_HANDLE) { + return PSA_ITS_ERROR_STORAGE_FAILURE; + } + + psa_status_t status = psa_call(conn, NULL, 0, NULL, 0); + if (status == PSA_DROP_CONNECTION) { + status = PSA_ITS_ERROR_STORAGE_FAILURE; + } + + psa_close(conn); + return status; +} diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_SPE/its_partition.c b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_SPE/its_partition.c index 12f944b43f..fc203c6eaa 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_SPE/its_partition.c +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/COMPONENT_SPE/its_partition.c @@ -135,6 +135,12 @@ static psa_status_t storage_remove(psa_msg_t *msg) return psa_its_remove_impl(psa_identity(msg->handle), key); } +static psa_status_t storage_reset(psa_msg_t *msg) +{ + (void)msg; + return psa_its_reset_impl(); +} + static void message_handler(psa_msg_t *msg, SignalHandler handler) { psa_status_t status = PSA_SUCCESS; @@ -187,6 +193,10 @@ void pits_entry(void *ptr) psa_get(PSA_ITS_REMOVE_MSK, &msg); message_handler(&msg, storage_remove); } + if ((signals & PSA_ITS_RESET_MSK) != 0) { + psa_get(PSA_ITS_RESET_MSK, &msg); + message_handler(&msg, storage_reset); + } } } diff --git a/components/TARGET_PSA/services/psa_prot_internal_storage/pits_psa.json b/components/TARGET_PSA/services/psa_prot_internal_storage/pits_psa.json index 61fee6e6f3..24cc6ed66f 100644 --- a/components/TARGET_PSA/services/psa_prot_internal_storage/pits_psa.json +++ b/components/TARGET_PSA/services/psa_prot_internal_storage/pits_psa.json @@ -37,6 +37,14 @@ "non_secure_clients": true, "minor_version": 1, "minor_policy": "RELAXED" + }, + { + "name": "PSA_ITS_RESET", + "identifier": "0x00011A04", + "signal": "PSA_ITS_RESET_MSK", + "non_secure_clients": false, + "minor_version": 1, + "minor_policy": "RELAXED" } ], "source_files": [