Skip to content

Commit

Permalink
platform: Pass dependency flag
Browse files Browse the repository at this point in the history
Pass dependency flag through platform API, so it can compare it with the
component ID value.

Ref: NCSDK-28616

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
  • Loading branch information
tomchy committed Oct 22, 2024
1 parent d28bcc8 commit 7d94614
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions include/suit_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ int suit_plat_authorize_unsigned_manifest(struct zcbor_string *manifest_componen
* If so, create and return a component handle for it.
*
* @param[in] component_id The CBOR-encoded component identifier.
* @param[in] dependency True if a component is a dependency component.
* @param[out] component_handle A reference for use with other functions in
* this API, instead of always passing the
* @p parts.
*
* @returns SUIT_SUCCESS if the component handle was created, error code otherwise.
*/
int suit_plat_create_component_handle(struct zcbor_string *component_id,
suit_component_t *handle);
int suit_plat_create_component_handle(struct zcbor_string *component_id, bool dependency, suit_component_t *handle);

/** @brief Release loaded component properties and handles assigned to them.
*
Expand Down
8 changes: 4 additions & 4 deletions src/suit_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static struct suit_manifest_params *components;
static size_t components_count;


static int assign_component_index(struct zcbor_string *component_id, size_t *assigned_index)
static int assign_component_index(struct zcbor_string *component_id, size_t *assigned_index, bool dependency)
{
int ret = SUIT_ERR_OVERFLOW;

Expand All @@ -34,7 +34,7 @@ static int assign_component_index(struct zcbor_string *component_id, size_t *ass
components[i].component_id = *component_id;
*assigned_index = i;

ret = suit_plat_create_component_handle(component_id, &components[i].component_handle);
ret = suit_plat_create_component_handle(component_id, dependency, &components[i].component_handle);

if (ret == SUIT_SUCCESS) {
components[*assigned_index].ref_count++;
Expand Down Expand Up @@ -115,7 +115,7 @@ int suit_manifest_append_dependency(struct suit_manifest_state *manifest, struct
return SUIT_ERR_MANIFEST_VALIDATION;
}

int ret = assign_component_index(component_id, &index);
int ret = assign_component_index(component_id, &index, true);

if (ret == SUIT_SUCCESS) {
if (components[index].is_dependency == suit_bool_false) {
Expand Down Expand Up @@ -158,7 +158,7 @@ int suit_manifest_append_component(struct suit_manifest_state *manifest, struct
return SUIT_ERR_MANIFEST_VALIDATION;
}

int ret = assign_component_index(component_id, &index);
int ret = assign_component_index(component_id, &index, false);

if (ret == SUIT_SUCCESS) {
if (components[index].is_dependency == suit_bool_true) {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/decoder/include/suit_platform_mock_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ int __check_digest_callback(enum suit_cose_alg alg_id, struct zcbor_string *dige
}
int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id, enum suit_cose_alg alg_id, struct zcbor_string *key_id, struct zcbor_string *signature, struct zcbor_string *data, int cmock_num_calls);

#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, handle, cmock_retval) { \
#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, dependency, handle, cmock_retval) { \
extern complex_arg_q_t __get_component_handle_callback_queue; \
push_complex_arg(component_id, assert_zcbor_string, __get_component_handle_callback_queue); \
push_retval_arg(cmock_retval, __get_component_handle_callback_queue); \
__cmock_suit_plat_create_component_handle_AddCallback(__get_component_handle_callback); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, dependency, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_IgnoreArg_component_id(); \
}
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *handle, int cmock_num_calls);
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *handle, int cmock_num_calls);

#define __cmock_suit_plat_check_image_match_ExpectComplexArgsAndReturn(image_handle, alg_id, digest, cmock_retval) { \
extern complex_arg_q_t __check_image_match_callback_queue; \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/decoder/src/suit_platform_mock_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id,
}

COMPLEX_ARG_Q_DEFINE(__get_component_handle_callback_queue);
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *component_handle, int cmock_num_calls)
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *component_handle, int cmock_num_calls)
{
(void)assert_complex_arg(&__get_component_handle_callback_queue, component_id);
return assert_complex_arg(&__get_component_handle_callback_queue, NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ int __check_digest_callback(enum suit_cose_alg alg_id, struct zcbor_string *dige
}
int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id, enum suit_cose_alg alg_id, struct zcbor_string *key_id, struct zcbor_string *signature, struct zcbor_string *data, int cmock_num_calls);

#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, handle, cmock_retval) { \
#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, dependency, handle, cmock_retval) { \
extern complex_arg_q_t __get_component_handle_callback_queue; \
push_complex_arg(component_id, assert_zcbor_string, __get_component_handle_callback_queue); \
push_retval_arg(cmock_retval, __get_component_handle_callback_queue); \
__cmock_suit_plat_create_component_handle_AddCallback(__get_component_handle_callback); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, dependency, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_IgnoreArg_component_id(); \
}
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *handle, int cmock_num_calls);
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *handle, int cmock_num_calls);

#define __cmock_suit_plat_check_image_match_ExpectComplexArgsAndReturn(image_handle, alg_id, digest, cmock_retval) { \
extern complex_arg_q_t __check_image_match_callback_queue; \
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/fetch_integrated_manifests/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ void app_assert_envelope_integrity(bool installed)

/* component creation */
__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_app_manifest_id, &exp_app_fw_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_fw_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_fw_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&app_fw_component_handle);

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_app_manifest_id, &exp_fw_memptr_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&app_fw_memptr_component_handle);

Expand All @@ -181,12 +181,12 @@ void app_assert_envelope_authorization(bool installed)
void app_assert_component_creation(void)
{
__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_app_manifest_id, &exp_app_fw_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_fw_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_fw_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&app_fw_component_handle);

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_app_manifest_id, &exp_fw_memptr_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&app_fw_memptr_component_handle);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/fetch_integrated_manifests/src/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ void radio_assert_envelope_integrity(bool installed)

/* component creation */
__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, &exp_radio_fw_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_fw_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_fw_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&radio_fw_component_handle);

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, &exp_fw_memptr_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&radio_fw_memptr_component_handle);

Expand All @@ -181,12 +181,12 @@ void radio_assert_envelope_authorization(bool installed)
void radio_assert_component_creation(void)
{
__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, &exp_radio_fw_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_fw_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_fw_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&radio_fw_component_handle);

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, &exp_fw_memptr_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_fw_memptr_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&radio_fw_memptr_component_handle);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/fetch_integrated_manifests/src/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void root_assert_component_creation(void)
};

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_root_manifest_id, &exp_manifest_candidate_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_manifest_candidate_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_manifest_candidate_id, true, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&candidate_component_handle);

Expand All @@ -115,7 +115,7 @@ void root_assert_component_creation(void)
};

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_root_manifest_id, &exp_radio_manifest_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_radio_manifest_id, true, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&radio_component_handle);

Expand All @@ -133,7 +133,7 @@ void root_assert_component_creation(void)
};

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_root_manifest_id, &exp_app_manifest_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_manifest_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_app_manifest_id, true, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&app_component_handle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id,
}

COMPLEX_ARG_Q_DEFINE(__get_component_handle_callback_queue);
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *component_handle, int cmock_num_calls)
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *component_handle, int cmock_num_calls)
{
(void)assert_complex_arg(&__get_component_handle_callback_queue, component_id);
return assert_complex_arg(&__get_component_handle_callback_queue, NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ int __check_digest_callback(enum suit_cose_alg alg_id, struct zcbor_string *dige
}
int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id, enum suit_cose_alg alg_id, struct zcbor_string *key_id, struct zcbor_string *signature, struct zcbor_string *data, int cmock_num_calls);

#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, handle, cmock_retval) { \
#define __cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(component_id, dependency, handle, cmock_retval) { \
extern complex_arg_q_t __get_component_handle_callback_queue; \
push_complex_arg(component_id, assert_zcbor_string, __get_component_handle_callback_queue); \
push_retval_arg(cmock_retval, __get_component_handle_callback_queue); \
__cmock_suit_plat_create_component_handle_AddCallback(__get_component_handle_callback); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_ExpectAndReturn(component_id, dependency, handle, cmock_retval); \
__cmock_suit_plat_create_component_handle_IgnoreArg_component_id(); \
}
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *handle, int cmock_num_calls);
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *handle, int cmock_num_calls);

#define __cmock_suit_plat_check_image_match_ExpectComplexArgsAndReturn(image_handle, alg_id, digest, cmock_retval) { \
extern complex_arg_q_t __check_image_match_callback_queue; \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/fetch_integrated_payload/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void assert_component_creation(void)
};

__cmock_suit_plat_authorize_component_id_ExpectComplexArgsAndReturn(&exp_manifest_id, &exp_component_id, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_component_id, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_ExpectComplexArgsAndReturn(&exp_component_id, false, NULL, SUIT_SUCCESS);
__cmock_suit_plat_create_component_handle_IgnoreArg_handle();
__cmock_suit_plat_create_component_handle_ReturnThruPtr_handle(&component_handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int __authenticate_manifest_callback(struct zcbor_string *manifest_component_id,
}

COMPLEX_ARG_Q_DEFINE(__get_component_handle_callback_queue);
int __get_component_handle_callback(struct zcbor_string *component_id, suit_component_t *component_handle, int cmock_num_calls)
int __get_component_handle_callback(struct zcbor_string *component_id, bool dependency, suit_component_t *component_handle, int cmock_num_calls)
{
(void)assert_complex_arg(&__get_component_handle_callback_queue, component_id);
return assert_complex_arg(&__get_component_handle_callback_queue, NULL);
Expand Down
Loading

0 comments on commit 7d94614

Please sign in to comment.