Skip to content

Commit 173dc66

Browse files
tomchydegjorva
authored andcommitted
suit: Add support for MFST_VAR in check_content
Add a possibility to check content of manifest variables from both application and SDFW platform code. Ref: NCSDK-20807 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 016b10e commit 173dc66

File tree

8 files changed

+169
-35
lines changed

8 files changed

+169
-35
lines changed

subsys/suit/platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ zephyr_library_sources(src/suit_plat_version.c)
1717
zephyr_library_sources(src/suit_plat_fetch.c)
1818
zephyr_library_sources(src/suit_plat_retrieve_manifest.c)
1919
zephyr_library_sources(src/suit_plat_write.c)
20+
zephyr_library_sources(src/suit_plat_check_content.c)
2021
zephyr_library_sources_ifdef(CONFIG_SUIT_CHECK_IMAGE_MATCH src/suit_plat_check_image_match.c)
2122
zephyr_library_sources_ifdef(CONFIG_SUIT_MEMPTR_STORAGE src/suit_plat_memptr_size_update.c)
2223
zephyr_library_sources(src/suit_plat_error_convert.c)

subsys/suit/platform/app/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ zephyr_library_sources(src/suit_plat_version_app_specific.c)
2020
zephyr_library_sources_ifdef(CONFIG_SUIT_CHECK_IMAGE_MATCH src/suit_plat_check_image_match_app_specific.c)
2121
zephyr_library_sources(src/suit_plat_authenticate.c)
2222
zephyr_library_sources(src/suit_plat_devconfig.c)
23-
zephyr_library_sources(src/suit_plat_check_content.c)
23+
zephyr_library_sources(src/suit_plat_check_content_app_specific.c)
2424
zephyr_library_sources(src/suit_plat_manifest_info.c)
2525
zephyr_library_sources(src/suit_plat_invoke.c)
2626

subsys/suit/platform/app/src/suit_plat_check_content.c

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <suit_plat_check_content_domain_specific.h>
8+
9+
bool suit_plat_check_content_domain_specific_is_type_supported(suit_component_type_t component_type)
10+
{
11+
return false;
12+
}
13+
14+
int suit_plat_check_content_domain_specific(suit_component_t component,
15+
suit_component_type_t component_type,
16+
struct zcbor_string *content)
17+
{
18+
return SUIT_ERR_UNSUPPORTED_COMMAND;
19+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef SUIT_PLAT_CHECK_CONTENT_DOMAIN_SPECIFIC_H__
8+
#define SUIT_PLAT_CHECK_CONTENT_DOMAIN_SPECIFIC_H__
9+
10+
#include <stdint.h>
11+
#include <suit_types.h>
12+
#include <suit_platform_internal.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @brief Check if component type is supported by suit_plat_check_content for the current domain.
20+
*/
21+
bool suit_plat_check_content_domain_specific_is_type_supported(
22+
suit_component_type_t component_type);
23+
24+
/**
25+
* @brief Domain specific part of the core part of the suit_plat_check_content function.
26+
*/
27+
int suit_plat_check_content_domain_specific(suit_component_t handle,
28+
suit_component_type_t component_type,
29+
struct zcbor_string *content);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif /* SUIT_PLAT_CHECK_CONTENT_DOMAIN_SPECIFIC_H__ */

subsys/suit/platform/sdfw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ zephyr_library_sources(src/suit_plat_version_sdfw_specific.c)
2020
zephyr_library_sources_ifdef(CONFIG_SUIT_DIGEST_CACHE src/suit_plat_digest_cache.c)
2121
zephyr_library_sources_ifdef(CONFIG_SUIT_IPUC src/suit_plat_ipuc.c)
2222
zephyr_library_sources_ifdef(CONFIG_SUIT_CHECK_IMAGE_MATCH src/suit_plat_check_image_match_sdfw_specific.c)
23-
zephyr_library_sources(src/suit_plat_check_content.c)
23+
zephyr_library_sources(src/suit_plat_check_content_sdfw_specific.c)
2424
zephyr_library_sources_ifdef(CONFIG_SUIT_DEVCONFIG src/suit_plat_devconfig.c)
2525
zephyr_library_sources_ifdef(CONFIG_SUIT_AUTHENTICATE src/suit_plat_authenticate.c)
2626
zephyr_library_sources_ifdef(CONFIG_SUIT_PLAT_CHECK_COMPONENT_COMPATIBILITY src/suit_plat_component_compatibility.c)

subsys/suit/platform/sdfw/src/suit_plat_check_content.c renamed to subsys/suit/platform/sdfw/src/suit_plat_check_content_sdfw_specific.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#include <suit_memptr_storage.h>
1111

1212
#include <zephyr/logging/log.h>
13-
LOG_MODULE_REGISTER(suit_plat_check_content, CONFIG_SUIT_LOG_LEVEL);
13+
LOG_MODULE_DECLARE(suit_plat_check_content, CONFIG_SUIT_LOG_LEVEL);
1414

15-
int suit_plat_check_content_mem_mapped(suit_component_t component, struct zcbor_string *content)
15+
static int suit_plat_check_content_mem_mapped(suit_component_t component,
16+
struct zcbor_string *content)
1617
{
1718
void *impl_data = NULL;
1819
int err = suit_plat_component_impl_data_get(component, &impl_data);
@@ -49,22 +50,23 @@ int suit_plat_check_content_mem_mapped(suit_component_t component, struct zcbor_
4950
return SUIT_SUCCESS;
5051
}
5152

52-
int suit_plat_check_content(suit_component_t component, struct zcbor_string *content)
53+
bool suit_plat_check_content_domain_specific_is_type_supported(suit_component_type_t component_type)
5354
{
54-
struct zcbor_string *component_id = NULL;
55-
suit_component_type_t component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
56-
57-
int err = suit_plat_component_id_get(component, &component_id);
58-
59-
if (err != SUIT_SUCCESS) {
60-
LOG_ERR("Failed to get component id: %d", err);
61-
return err;
55+
switch (component_type) {
56+
case SUIT_COMPONENT_TYPE_MEM:
57+
return true;
58+
default:
59+
break;
6260
}
6361

64-
if (suit_plat_decode_component_type(component_id, &component_type) != SUIT_PLAT_SUCCESS) {
65-
LOG_ERR("Failed to decode component type");
66-
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
67-
}
62+
return false;
63+
}
64+
65+
int suit_plat_check_content_domain_specific(suit_component_t component,
66+
suit_component_type_t component_type,
67+
struct zcbor_string *content)
68+
{
69+
int err = SUIT_ERR_CRASH;
6870

6971
switch (component_type) {
7072
case SUIT_COMPONENT_TYPE_UNSUPPORTED: {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <suit_platform.h>
8+
#include <suit_plat_check_content_domain_specific.h>
9+
#include <suit_plat_decode_util.h>
10+
#ifdef CONFIG_SUIT_MANIFEST_VARIABLES
11+
#include <suit_manifest_variables.h>
12+
#endif /* CONFIG_SUIT_MANIFEST_VARIABLES */
13+
14+
#include <zephyr/logging/log.h>
15+
LOG_MODULE_REGISTER(suit_plat_check_content, CONFIG_SUIT_LOG_LEVEL);
16+
17+
#ifdef CONFIG_SUIT_MANIFEST_VARIABLES
18+
static int suit_plat_check_content_mfst_var(suit_component_t component,
19+
struct zcbor_string *content)
20+
{
21+
struct zcbor_string *component_id = NULL;
22+
suit_plat_err_t plat_ret;
23+
uint32_t checked_val = 0;
24+
uint32_t current_val = 0;
25+
uint32_t id;
26+
int ret;
27+
28+
plat_ret = suit_plat_decode_content_uint32(content, &checked_val);
29+
if (plat_ret != SUIT_PLAT_SUCCESS) {
30+
LOG_ERR("Failed to decode content value: %d", plat_ret);
31+
return SUIT_ERR_UNSUPPORTED_PARAMETER;
32+
}
33+
34+
ret = suit_plat_component_id_get(component, &component_id);
35+
if (ret != SUIT_SUCCESS) {
36+
LOG_ERR("Failed to get component ID: %d", ret);
37+
return SUIT_ERR_CRASH;
38+
}
39+
40+
plat_ret = suit_plat_decode_component_number(component_id, &id);
41+
if (plat_ret != SUIT_PLAT_SUCCESS) {
42+
LOG_ERR("Failed to decode variable ID: %d", plat_ret);
43+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
44+
}
45+
46+
plat_ret = suit_mfst_var_get(id, &current_val);
47+
switch (plat_ret) {
48+
case SUIT_PLAT_SUCCESS:
49+
if (checked_val == current_val) {
50+
return SUIT_SUCCESS;
51+
}
52+
return SUIT_FAIL_CONDITION;
53+
case SUIT_PLAT_ERR_NOT_FOUND:
54+
LOG_ERR("Failed to get manifest variable: ID %d not supported", id);
55+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
56+
case SUIT_PLAT_ERR_INVAL:
57+
case SUIT_PLAT_ERR_IO:
58+
default:
59+
break;
60+
}
61+
62+
LOG_ERR("Failed to get manifest variable: %d", plat_ret);
63+
64+
return SUIT_ERR_CRASH;
65+
}
66+
#endif /* CONFIG_SUIT_MANIFEST_VARIABLES */
67+
68+
int suit_plat_check_content(suit_component_t component, struct zcbor_string *content)
69+
{
70+
suit_component_type_t dst_component_type = SUIT_COMPONENT_TYPE_UNSUPPORTED;
71+
int ret = SUIT_SUCCESS;
72+
73+
if (content == NULL) {
74+
return SUIT_ERR_CRASH;
75+
}
76+
77+
/* Get destination component type based on component handle. */
78+
ret = suit_plat_component_type_get(component, &dst_component_type);
79+
if (ret != SUIT_SUCCESS) {
80+
LOG_ERR("Failed to decode destination component type");
81+
return ret;
82+
}
83+
84+
#ifdef CONFIG_SUIT_MANIFEST_VARIABLES
85+
if (dst_component_type == SUIT_COMPONENT_TYPE_MFST_VAR) {
86+
return suit_plat_check_content_mfst_var(component, content);
87+
}
88+
#endif /* CONFIG_SUIT_MANIFEST_VARIABLES */
89+
if (suit_plat_check_content_domain_specific_is_type_supported(dst_component_type)) {
90+
return suit_plat_check_content_domain_specific(component, dst_component_type,
91+
content);
92+
}
93+
94+
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
95+
}

0 commit comments

Comments
 (0)