Skip to content

Commit d7b9164

Browse files
tomchynordicjm
authored andcommitted
sdfw_services: Add SUIT invoke services handlers
Add implementation of SUIT SSF invoke services. Ref: NCSDK-29996 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent fee5bde commit d7b9164

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

include/sdfw/sdfw_services/suit_service.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,45 @@ suit_ssf_err_t suit_get_supported_manifest_roles(suit_manifest_role_t *roles, si
177177
suit_ssf_err_t suit_get_supported_manifest_info(suit_manifest_role_t role,
178178
suit_ssf_manifest_class_info_t *class_info);
179179

180+
/** @brief Read the current boot mode value.
181+
*
182+
* @param[out] mode Current boot mode.
183+
*
184+
* @retval SUIT_PLAT_SUCCESS if successful.
185+
* @retval SUIT_PLAT_ERR_INVAL if input parameter is invalid.
186+
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
187+
*/
188+
suit_ssf_err_t suit_boot_mode_read(suit_boot_mode_t *mode);
189+
190+
/** @brief Confirm that the invoke command finished.
191+
*
192+
* @param[in] ret Invoke command return code. Pass zero if successful.
193+
*
194+
* @retval SUIT_PLAT_SUCCESS if successful.
195+
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
196+
*/
197+
suit_ssf_err_t suit_invoke_confirm(int ret);
198+
199+
/** @brief Reset SUIT boot flags.
200+
*
201+
* @note After resetting the SUIT boot flags the system will be reset and a regular boot procedure
202+
* will be executed.
203+
*
204+
* @retval SUIT_PLAT_SUCCESS if successful.
205+
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
206+
*/
207+
suit_ssf_err_t suit_boot_flags_reset(void);
208+
209+
/** @brief Request a foreground DFU procedure.
210+
*
211+
* @note After setting the foreground DFU boot flag the system will be reset and a recovery image
212+
* will be booted.
213+
*
214+
* @retval SUIT_PLAT_SUCCESS if successful.
215+
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
216+
*/
217+
suit_ssf_err_t suit_foreground_dfu_required(void);
218+
180219
#ifdef __cplusplus
181220
}
182221
#endif

subsys/sdfw_services/services/suit_service/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ zephyr_library()
99
zephyr_library_sources(suit_service.c)
1010
zephyr_library_sources(suit_update.c)
1111
zephyr_library_sources(suit_mci.c)
12+
zephyr_library_sources(suit_invoke.c)
1213
zephyr_library_sources_ifdef(CONFIG_SUIT_PROCESSOR suit_auth.c)
1314

1415
zephyr_library_link_libraries(suit_utils)

subsys/sdfw_services/services/suit_service/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ menuconfig SSF_SUIT_SERVICE_ENABLED
99
depends on SDFW_SERVICES_ENABLED
1010
depends on SUIT_UTILS
1111
depends on SUIT_METADATA
12-
depends on ZCBOR_CANONICAL
1312

1413
if SSF_SUIT_SERVICE_ENABLED
1514

subsys/sdfw_services/services/suit_service/suit_auth.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
#include <zephyr/logging/log.h>
1717
LOG_MODULE_REGISTER(suit_srvc_auth, CONFIG_SSF_SUIT_SERVICE_LOG_LEVEL);
1818

19+
/* __ALIGNED macro is not defined on NATIVE POSIX. This platform uses __aligned macro. */
20+
#ifndef __ALIGNED
21+
#ifdef __aligned
22+
#define __ALIGNED __aligned
23+
#endif
24+
#endif
25+
1926
#ifdef CONFIG_DCACHE_LINE_SIZE
2027
#define CACHE_ALIGNMENT CONFIG_DCACHE_LINE_SIZE
2128
#else
@@ -39,6 +46,10 @@ int suit_plat_authenticate_manifest(struct zcbor_string *manifest_component_id,
3946
return SUIT_ERR_DECODING;
4047
}
4148

49+
if (data->len > sizeof(aligned_auth_data)) {
50+
return SUIT_ERR_DECODING;
51+
}
52+
4253
memset(&req, 0, sizeof(struct suit_req));
4354
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(authenticate_manifest);
4455

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <sdfw/sdfw_services/ssf_client.h>
8+
#include "suit_service_types.h"
9+
#include <sdfw/sdfw_services/suit_service.h>
10+
#include "suit_service_utils.h"
11+
12+
#include <zephyr/logging/log.h>
13+
LOG_MODULE_REGISTER(suit_srvc_invoke, CONFIG_SSF_SUIT_SERVICE_LOG_LEVEL);
14+
15+
extern const struct ssf_client_srvc suit_srvc;
16+
17+
suit_ssf_err_t suit_boot_mode_read(suit_boot_mode_t *mode)
18+
{
19+
int ret;
20+
struct suit_req req;
21+
struct suit_rsp rsp;
22+
struct suit_boot_mode_read_rsp *rsp_data;
23+
const uint8_t *rsp_pkt;
24+
25+
if (mode == NULL) {
26+
return SUIT_PLAT_ERR_INVAL;
27+
}
28+
29+
memset(&req, 0, sizeof(struct suit_req));
30+
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(boot_mode_read);
31+
32+
ret = ssf_client_send_request(&suit_srvc, &req, &rsp, &rsp_pkt);
33+
if (ret != 0) {
34+
ssf_client_decode_done(rsp_pkt);
35+
return SUIT_PLAT_ERR_IPC;
36+
}
37+
38+
rsp_data = &rsp.SSF_SUIT_RSP(boot_mode_read);
39+
ret = rsp_data->SSF_SUIT_RSP_ARG(boot_mode_read, ret);
40+
if (ret != SUIT_PLAT_SUCCESS) {
41+
ssf_client_decode_done(rsp_pkt);
42+
return ret;
43+
}
44+
45+
*mode = (suit_boot_mode_t)rsp_data->SSF_SUIT_RSP_ARG(boot_mode_read, boot_mode);
46+
47+
ssf_client_decode_done(rsp_pkt);
48+
49+
return ret;
50+
}
51+
52+
suit_ssf_err_t suit_invoke_confirm(int ret)
53+
{
54+
int ssf_ret;
55+
struct suit_req req;
56+
struct suit_rsp rsp;
57+
struct suit_invoke_confirm_req *req_data;
58+
59+
memset(&req, 0, sizeof(struct suit_req));
60+
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(invoke_confirm);
61+
req_data = &req.SSF_SUIT_REQ(invoke_confirm);
62+
req_data->SSF_SUIT_REQ_ARG(invoke_confirm, ret) = ret;
63+
64+
ssf_ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
65+
if (ssf_ret != 0) {
66+
return SUIT_PLAT_ERR_IPC;
67+
}
68+
69+
return rsp.SSF_SUIT_RSP(invoke_confirm).SSF_SUIT_RSP_ARG(invoke_confirm, ret);
70+
}
71+
72+
suit_ssf_err_t suit_boot_flags_reset(void)
73+
{
74+
int ret;
75+
struct suit_req req;
76+
struct suit_rsp rsp;
77+
78+
memset(&req, 0, sizeof(struct suit_req));
79+
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(boot_flags_reset);
80+
81+
ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
82+
if (ret != 0) {
83+
return SUIT_PLAT_ERR_IPC;
84+
}
85+
86+
return rsp.SSF_SUIT_RSP(boot_flags_reset).SSF_SUIT_RSP_ARG(boot_flags_reset, ret);
87+
}
88+
89+
suit_ssf_err_t suit_foreground_dfu_required(void)
90+
{
91+
int ret;
92+
struct suit_req req;
93+
struct suit_rsp rsp;
94+
95+
memset(&req, 0, sizeof(struct suit_req));
96+
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(foreground_dfu_required);
97+
98+
ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
99+
if (ret != 0) {
100+
return SUIT_PLAT_ERR_IPC;
101+
}
102+
103+
return rsp.SSF_SUIT_RSP(foreground_dfu_required)
104+
.SSF_SUIT_RSP_ARG(foreground_dfu_required, ret);
105+
}

0 commit comments

Comments
 (0)