Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/suit/ncsdk 29996 extend ipc services #18525

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions include/sdfw/sdfw_services/suit_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <suit_plat_err.h>
#include <suit_mreg.h>
#include <suit_metadata.h>
#ifdef CONFIG_SUIT_EXECUTION_MODE
#include <suit_execution_mode.h>
#endif /* CONFIG_SUIT_EXECUTION_MODE */

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -177,6 +180,47 @@ suit_ssf_err_t suit_get_supported_manifest_roles(suit_manifest_role_t *roles, si
suit_ssf_err_t suit_get_supported_manifest_info(suit_manifest_role_t role,
suit_ssf_manifest_class_info_t *class_info);

#ifdef CONFIG_SUIT_EXECUTION_MODE
/** @brief Read the current execution mode value.
*
* @param[out] mode Current execution mode.
*
* @retval SUIT_PLAT_SUCCESS if successful.
* @retval SUIT_PLAT_ERR_INVAL if input parameter is invalid.
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
*/
suit_ssf_err_t suit_execution_mode_read(suit_execution_mode_t *mode);
#endif /* CONFIG_SUIT_EXECUTION_MODE */

/** @brief Confirm that the invoke command finished.
*
* @param[in] ret Invoke command return code.
*
* @retval SUIT_PLAT_SUCCESS if successful.
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
*/
suit_ssf_err_t suit_invoke_confirm(int ret);

/** @brief Reset SUIT boot flags.
*
* @note After resetting the SUIT boot flags the system will be reset and a regular boot procedure
* will be executed.
*
* @retval SUIT_PLAT_SUCCESS if successful.
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
*/
suit_ssf_err_t suit_boot_flags_reset(void);

/** @brief Request a foreground DFU procedure.
*
* @note After setting the foreground DFU boot flag the system will be reset and a recovery image
* will be booted.
*
* @retval SUIT_PLAT_SUCCESS if successful.
* @retval SUIT_PLAT_ERR_IPC in case of SSF protocol error.
*/
suit_ssf_err_t suit_foreground_dfu_required(void);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ zephyr_library()
zephyr_library_sources(suit_service.c)
zephyr_library_sources(suit_update.c)
zephyr_library_sources(suit_mci.c)
zephyr_library_sources(suit_invoke.c)
zephyr_library_sources_ifdef(CONFIG_SUIT_PROCESSOR suit_auth.c)

zephyr_library_link_libraries(suit_utils)
Expand Down
1 change: 0 additions & 1 deletion subsys/sdfw_services/services/suit_service/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ menuconfig SSF_SUIT_SERVICE_ENABLED
depends on SDFW_SERVICES_ENABLED
depends on SUIT_UTILS
depends on SUIT_METADATA
depends on ZCBOR_CANONICAL

if SSF_SUIT_SERVICE_ENABLED

Expand Down
13 changes: 12 additions & 1 deletion subsys/sdfw_services/services/suit_service/suit_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(suit_srvc_auth, CONFIG_SSF_SUIT_SERVICE_LOG_LEVEL);

/* __ALIGNED macro is not defines on NATIVE POSIX. This platform uses __aligned macro. */
#ifndef __ALIGNED
#ifdef __aligned
#define __ALIGNED __aligned
#endif
#endif

#ifdef CONFIG_DCACHE_LINE_SIZE
#define CACHE_ALIGNMENT CONFIG_DCACHE_LINE_SIZE
#else
Expand All @@ -33,12 +40,16 @@ int suit_plat_authenticate_manifest(struct zcbor_string *manifest_component_id,
struct suit_rsp rsp;
struct suit_authenticate_manifest_req *req_data;
uint8_t aligned_auth_data[ROUND_UP(SUIT_SUIT_SIG_STRUCTURE1_MAX_LENGTH,
CACHE_ALIGNMENT)] __ALIGNED(CACHE_ALIGNMENT) = {0};
CACHE_ALIGNMENT)] __ALIGNED(CACHE_ALIGNMENT) = { 0 };

if (manifest_component_id == NULL || key_id == NULL || signature == NULL || data == NULL) {
return SUIT_ERR_DECODING;
}

if (data->len > sizeof(aligned_auth_data)) {
return SUIT_ERR_DECODING;
}

memset(&req, 0, sizeof(struct suit_req));
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(authenticate_manifest);

Expand Down
106 changes: 106 additions & 0 deletions subsys/sdfw_services/services/suit_service/suit_invoke.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <sdfw/sdfw_services/ssf_client.h>
#include "suit_service_types.h"
#include <sdfw/sdfw_services/suit_service.h>
#include "suit_service_utils.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(suit_srvc_invoke, CONFIG_SSF_SUIT_SERVICE_LOG_LEVEL);

extern const struct ssf_client_srvc suit_srvc;

suit_ssf_err_t suit_execution_mode_read(suit_execution_mode_t *mode)
{
int ret;
struct suit_req req;
struct suit_rsp rsp;
struct suit_execution_mode_read_rsp *rsp_data;
const uint8_t *rsp_pkt;

if (mode == NULL) {
return SUIT_PLAT_ERR_INVAL;
}

memset(&req, 0, sizeof(struct suit_req));
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(execution_mode_read);

ret = ssf_client_send_request(&suit_srvc, &req, &rsp, &rsp_pkt);
if (ret != 0) {
ssf_client_decode_done(rsp_pkt);
return SUIT_PLAT_ERR_IPC;
}

rsp_data = &rsp.SSF_SUIT_RSP(execution_mode_read);
ret = rsp_data->SSF_SUIT_RSP_ARG(execution_mode_read, ret);
if (ret != SUIT_PLAT_SUCCESS) {
ssf_client_decode_done(rsp_pkt);
return ret;
}

*mode = (suit_execution_mode_t)rsp_data->SSF_SUIT_RSP_ARG(execution_mode_read,
execution_mode);

ssf_client_decode_done(rsp_pkt);

return ret;
}

suit_ssf_err_t suit_invoke_confirm(int ret);
{
int ret;
struct suit_req req;
struct suit_rsp rsp;
struct suit_invoke_confirm_req *req_data;

memset(&req, 0, sizeof(struct suit_req));
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(invoke_confirm);
req_data = &req.SSF_SUIT_REQ(invoke_confirm);
req_data->SSF_SUIT_REQ_ARG(invoke_confirm, ret) = ret;

ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
if (ret != 0) {
return SUIT_PLAT_ERR_IPC;
}

return rsp.SSF_SUIT_RSP(invoke_confirm).SSF_SUIT_RSP_ARG(invoke_confirm, ret);
}

suit_ssf_err_t suit_boot_flags_reset(void)
{
int ret;
struct suit_req req;
struct suit_rsp rsp;

memset(&req, 0, sizeof(struct suit_req));
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(boot_flags_reset);

ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
if (ret != 0) {
return SUIT_PLAT_ERR_IPC;
}

return rsp.SSF_SUIT_RSP(boot_flags_reset).SSF_SUIT_RSP_ARG(boot_flags_reset, ret);
}

suit_ssf_err_t suit_foreground_dfu_required(void)
{
int ret;
struct suit_req req;
struct suit_rsp rsp;

memset(&req, 0, sizeof(struct suit_req));
req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(foreground_dfu_required);

ret = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL);
if (ret != 0) {
return SUIT_PLAT_ERR_IPC;
}

return rsp.SSF_SUIT_RSP(foreground_dfu_required)
.SSF_SUIT_RSP_ARG(foreground_dfu_required, ret);
}
66 changes: 64 additions & 2 deletions subsys/sdfw_services/services/suit_service/suit_service.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,58 @@ suit_chunk_status_rsp = (
chunk_info: [ 0*3 suit_chunk_info_entry],
)

; Read the current execution mode.
; This service is used to provide an execution context for the companion app.
suit_execution_mode_read_req = (
50,
)

; See suit_execution_mode_t for execution_mode field possible values.
suit_execution_mode_read_rsp = (
50,
ret: int,
execution_mode: uint,
)

; Confirm that the image was booted.
; This service is use by the companion app to release SUIT orchestrator in case
; of synchronous invocation.
suit_invoke_confirm_req = (
51,
ret: int,
)

suit_invoke_confirm_rsp = (
51,
ret: int,
)

; Reset all SUIT boot flags.
; This API will reboot the SDFW and attempt to boot the system from installed
; manifests.
suit_boot_flags_reset_req = (
52,
)

suit_boot_flags_reset_rsp = (
52,
ret: int,
)

; Reboot the system into a forground DFU mode.
; In this mode the SUIT orchestrator boots the application recovery image.
; The recovery image should check the context of invocation through
; the suit_execution_mode_read_req service.
; The foreground DFU may be left by providing update candidate or through
; the suit_boot_flags_reset_req service.
suit_foreground_dfu_required_req = (
53,
)

suit_foreground_dfu_required_rsp = (
53,
ret: int,
)

suit_req = [
; Union of different requests
Expand All @@ -321,7 +373,12 @@ suit_req = [

suit_evt_sub_req /
suit_chunk_enqueue_req /
suit_chunk_status_req
suit_chunk_status_req /

suit_execution_mode_read_req /
suit_invoke_confirm_req /
suit_boot_flags_reset_req /
suit_foreground_dfu_required_req
),
]

Expand All @@ -344,7 +401,12 @@ suit_rsp = [

suit_evt_sub_rsp /
suit_chunk_enqueue_rsp /
suit_chunk_status_rsp
suit_chunk_status_rsp /

suit_execution_mode_read_rsp /
suit_invoke_confirm_rsp /
suit_boot_flags_reset_rsp /
suit_foreground_dfu_required_rsp
),
]

Expand Down
Loading
Loading