Skip to content

Commit

Permalink
sdfw_services: Add SUIT invoke services handlers
Browse files Browse the repository at this point in the history
Add implementation of SUIT SSF invoke services.

Ref: NCSDK-29996

Signed-off-by: Tomasz Chyrowicz <[email protected]>
  • Loading branch information
tomchy committed Nov 4, 2024
1 parent c6076a0 commit bf43985
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 2 deletions.
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
1 change: 1 addition & 0 deletions subsys/sdfw_services/services/suit_service/CMakeLists.txt
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);
}

0 comments on commit bf43985

Please sign in to comment.