Skip to content

Commit b8c7971

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 917e4aa commit b8c7971

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ 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+
}
44+
2945
enum tfm_platform_err_t
3046
tfm_platform_ioctl(tfm_platform_ioctl_req_t request,
3147
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+
void 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,34 @@ 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+
tfm_platform_hal_system_off();
50+
51+
return TFM_PLATFORM_ERR_SUCCESS;
52+
}
53+
54+
static psa_status_t platform_sp_system_off_psa_api(const psa_msg_t *msg)
55+
{
56+
(void)msg; /* unused parameter */
57+
58+
return platform_sp_system_off();
59+
}
60+
#endif /* TFM_NRF_SYSTEM_OFF_SERVICE */
61+
4262
static psa_status_t platform_sp_system_reset_psa_api(const psa_msg_t *msg)
4363
{
4464
(void)msg; /* unused parameter */
4565

4666
return platform_sp_system_reset();
4767
}
4868

69+
4970
#if !PLATFORM_NV_COUNTER_MODULE_DISABLED
5071
static psa_status_t platform_sp_nv_read_psa_api(const psa_msg_t *msg)
5172
{
@@ -225,6 +246,10 @@ psa_status_t tfm_platform_service_sfn(const psa_msg_t *msg)
225246
#endif /* PLATFORM_NV_COUNTER_MODULE_DISABLED */
226247
case TFM_PLATFORM_API_ID_SYSTEM_RESET:
227248
return platform_sp_system_reset_psa_api(msg);
249+
#if TFM_NRF_SYSTEM_OFF_SERVICE
250+
case TFM_PLATFORM_API_ID_SYSTEM_OFF:
251+
return platform_sp_system_off_psa_api(msg);
252+
#endif /* TFM_NRF_SYSTEM_OFF_SERVICE */
228253
case TFM_PLATFORM_API_ID_IOCTL:
229254
return platform_sp_ioctl_psa_api(msg);
230255
default:

0 commit comments

Comments
 (0)