Skip to content

Commit 3df8d8b

Browse files
committed
[nrf noup] secure_fw: platform: Add system off service
Add the tfm_platform_system_off APIs in a similar manner as the existing tfm_platform_system_reset. This API should enable implementations to allow setting the TF-M to the lowest power mode using their own HAL APIs. Right now this will work for isolation level 1 (SFN mode). In the IPC mode there is a need for better TF-M support for this. There is a discussion with the TF-M owners to add logic to TF-M so that it can inform all the partitions in order to make sure that it is safe to go to system off mode. Signed-off-by: Georgios Vasilakis <georgios.vasilakis@nordicsemi.no>
1 parent 565a30c commit 3df8d8b

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

interface/include/tfm_platform_api.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
#define TFM_PLATFORM_API_ID_NV_INCREMENT (1011)
2828
#define TFM_PLATFORM_API_ID_SYSTEM_RESET (1012)
2929
#define TFM_PLATFORM_API_ID_IOCTL (1013)
30+
#define TFM_PLATFORM_API_ID_SYSTEM_OFF (1014)
3031

3132
/*!
3233
* \enum tfm_platform_err_t
@@ -53,6 +54,14 @@ typedef int32_t tfm_platform_ioctl_req_t;
5354
*/
5455
enum tfm_platform_err_t tfm_platform_system_reset(void);
5556

57+
/*!
58+
* \brief System off function to move the system to the lowest power state
59+
*
60+
* \return On success the processor will go to system off, in case of error it returns
61+
* values as specified by the \ref tfm_platform_err_t
62+
*/
63+
enum tfm_platform_err_t tfm_platform_system_off(void);
64+
5665
/*!
5766
* \brief Performs a platform-specific service
5867
*

interface/src/tfm_platform_api.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ enum tfm_platform_err_t tfm_platform_system_reset(void)
2626

2727
}
2828

29+
enum tfm_platform_err_t tfm_platform_system_off(void)
30+
{
31+
psa_status_t status = PSA_ERROR_CONNECTION_REFUSED;
32+
33+
status = psa_call(TFM_PLATFORM_SERVICE_HANDLE,
34+
TFM_PLATFORM_API_ID_SYSTEM_OFF,
35+
NULL, 0, NULL, 0);
36+
37+
if (status < PSA_SUCCESS) {
38+
return TFM_PLATFORM_ERR_SYSTEM_ERROR;
39+
} else {
40+
return (enum tfm_platform_err_t)status;
41+
}
42+
}
43+
2944
enum tfm_platform_err_t
3045
tfm_platform_ioctl(tfm_platform_ioctl_req_t request,
3146
psa_invec *input, psa_outvec *output)

platform/ext/target/nordic_nrf/common/core/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ if(TFM_SPM_LOG_RAW_ENABLED)
158158
)
159159
endif()
160160

161+
if(TFM_NRF_SYSTEM_OFF_SERVICE)
162+
target_sources(platform_s
163+
PRIVATE
164+
${HAL_NORDIC_PATH}/nrfx/helpers/nrfx_ram_ctrl.c
165+
)
166+
167+
target_compile_definitions(platform_s
168+
PUBLIC
169+
TFM_NRF_SYSTEM_OFF_SERVICE
170+
)
171+
endif()
172+
161173
target_compile_options(platform_s
162174
PUBLIC
163175
${COMPILER_CMSE_FLAG}

platform/include/tfm_platform_system.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ extern "C" {
2828
TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_PLATFORM", "PSA-ROT")
2929
void tfm_platform_hal_system_reset(void);
3030

31+
/**
32+
* \brief Set system power state to off.
33+
*
34+
* \details Requests the system to enter a low-power state.
35+
*/
36+
TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_PLATFORM", "PSA-ROT")
37+
enum tfm_platform_err_t tfm_platform_hal_system_off(void);
38+
3139
/*!
3240
* \brief Performs a platform-specific service
3341
*

secure_fw/partitions/platform/platform_sp.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ enum tfm_platform_err_t platform_sp_system_reset(void)
3939
return TFM_PLATFORM_ERR_SUCCESS;
4040
}
4141

42+
#if TFM_NRF_SYSTEM_OFF_SERVICE
43+
enum tfm_platform_err_t platform_sp_system_off(void)
44+
{
45+
/* FIXME: The system off functionality is only supported in isolation
46+
* level 1.
47+
*/
48+
49+
return tfm_platform_hal_system_off();
50+
}
51+
52+
static psa_status_t platform_sp_system_off_psa_api(const psa_msg_t *msg)
53+
{
54+
(void)msg; /* unused parameter */
55+
56+
return platform_sp_system_off();
57+
}
58+
#endif /* TFM_NRF_SYSTEM_OFF_SERVICE */
59+
4260
static psa_status_t platform_sp_system_reset_psa_api(const psa_msg_t *msg)
4361
{
4462
(void)msg; /* unused parameter */
@@ -225,6 +243,10 @@ psa_status_t tfm_platform_service_sfn(const psa_msg_t *msg)
225243
#endif /* PLATFORM_NV_COUNTER_MODULE_DISABLED */
226244
case TFM_PLATFORM_API_ID_SYSTEM_RESET:
227245
return platform_sp_system_reset_psa_api(msg);
246+
#if TFM_NRF_SYSTEM_OFF_SERVICE
247+
case TFM_PLATFORM_API_ID_SYSTEM_OFF:
248+
return platform_sp_system_off_psa_api(msg);
249+
#endif /* TFM_NRF_SYSTEM_OFF_SERVICE */
228250
case TFM_PLATFORM_API_ID_IOCTL:
229251
return platform_sp_ioctl_psa_api(msg);
230252
default:

0 commit comments

Comments
 (0)