Skip to content

Commit

Permalink
suit: Pass dependency flag to platform
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 <[email protected]>
  • Loading branch information
tomchy authored and rlubos committed Oct 22, 2024
1 parent 3f01503 commit 9bef74e
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 68 deletions.
8 changes: 7 additions & 1 deletion subsys/suit/platform/src/suit_plat_components.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int suit_plat_release_component_handle(suit_component_t handle)
return SUIT_SUCCESS;
}

int suit_plat_create_component_handle(struct zcbor_string *component_id,
int suit_plat_create_component_handle(struct zcbor_string *component_id, bool dependency,
suit_component_t *component_handle)
{
suit_memptr_storage_err_t err;
Expand Down Expand Up @@ -130,6 +130,12 @@ int suit_plat_create_component_handle(struct zcbor_string *component_id,
return SUIT_ERR_UNSUPPORTED_COMPONENT_ID;
}

if (dependency && (component_type != SUIT_COMPONENT_TYPE_CAND_MFST) &&
(component_type != SUIT_COMPONENT_TYPE_INSTLD_MFST)) {
LOG_ERR("Unsupported dependency component type: %d", component_type);
return SUIT_ERR_UNAUTHORIZED_COMPONENT;
}

if ((component_type == SUIT_COMPONENT_TYPE_CAND_IMG) ||
(component_type == SUIT_COMPONENT_TYPE_CAND_MFST)) {
err = suit_memptr_storage_get(&component->impl_data);
Expand Down
3 changes: 2 additions & 1 deletion tests/subsys/suit/cache_pool_digest/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ ZTEST(cache_pool_digest_tests, test_cache_get_slot_ok)

suit_component_t dst_component;

ret = suit_plat_create_component_handle(&valid_cand_img_component_id, &dst_component);
ret = suit_plat_create_component_handle(&valid_cand_img_component_id, false,
&dst_component);
zassert_equal(SUIT_SUCCESS, ret, "test error - create_component_handle failed: %d", ret);

struct zcbor_string src_uri = {
Expand Down
7 changes: 4 additions & 3 deletions tests/subsys/suit/check_content/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ZTEST(suit_check_content_tests, test_mem_matching)
};

suit_component_t component;
int err = suit_plat_create_component_handle(&matching_src_component_id, &component);
int err = suit_plat_create_component_handle(&matching_src_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -88,7 +88,7 @@ ZTEST(suit_check_content_tests, test_mem_different_size)
};

suit_component_t component;
int err = suit_plat_create_component_handle(&valid_src_component_id, &component);
int err = suit_plat_create_component_handle(&valid_src_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -127,7 +127,8 @@ ZTEST(suit_check_content_tests, test_mem_not_matching)
};

suit_component_t component;
int err = suit_plat_create_component_handle(&not_matching_src_component_id, &component);
int err = suit_plat_create_component_handle(&not_matching_src_component_id, false,
&component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down
24 changes: 13 additions & 11 deletions tests/subsys/suit/check_image_match/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ZTEST(check_image_match_tests, test_mem_valid)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_src_component_id, &component);
int err = suit_plat_create_component_handle(&valid_src_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -96,7 +96,7 @@ ZTEST(check_image_match_tests, test_mem_wrong_size)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_src_component_id, &component);
int err = suit_plat_create_component_handle(&valid_src_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -134,7 +134,7 @@ ZTEST(check_image_match_tests, test_mem_wrong_digest)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_src_component_id, &component);
int err = suit_plat_create_component_handle(&valid_src_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -171,7 +171,7 @@ ZTEST(check_image_match_tests, test_mem_invalid_component)
suit_component_t component;

/* WHEN a component handle is created */
int err = suit_plat_create_component_handle(&invalid_src_component_id, &component);
int err = suit_plat_create_component_handle(&invalid_src_component_id, false, &component);

/* THEN it is not supported */
zassert_equal(SUIT_ERR_UNSUPPORTED_COMPONENT_ID, err,
Expand All @@ -185,7 +185,8 @@ ZTEST(check_image_match_tests, test_cand_img_match)
/* GIVEN CAND_IMG component pointing to the data */
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_cand_img_component_id, &component);
int err =
suit_plat_create_component_handle(&valid_cand_img_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -215,7 +216,8 @@ ZTEST(check_image_match_tests, test_cand_img_mismatch)
/* GIVEN CAND_IMG component pointing to the data */
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_cand_img_component_id, &component);
int err =
suit_plat_create_component_handle(&valid_cand_img_component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -252,7 +254,7 @@ ZTEST(check_image_match_tests, test_soc_spec_1)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&component_id, &component);
int err = suit_plat_create_component_handle(&component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -284,7 +286,7 @@ ZTEST(check_image_match_tests, test_soc_spec_2)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&component_id, &component);
int err = suit_plat_create_component_handle(&component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -317,7 +319,7 @@ ZTEST(check_image_match_tests, test_soc_spec_3)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&component_id, &component);
int err = suit_plat_create_component_handle(&component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -348,7 +350,7 @@ ZTEST(check_image_match_tests, test_soc_spec_none)
void *impl_data = NULL;
suit_component_t component;

int err = suit_plat_create_component_handle(&component_id, &component);
int err = suit_plat_create_component_handle(&component_id, false, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down Expand Up @@ -387,7 +389,7 @@ ZTEST(check_image_match_tests, test_unhandled_component)
};
suit_component_t component;

int err = suit_plat_create_component_handle(&valid_src_component_id, &component);
int err = suit_plat_create_component_handle(&valid_src_component_id, true, &component);

zassert_equal(SUIT_SUCCESS, err, "test error - create_component_handle failed: %d", err);

Expand Down
16 changes: 8 additions & 8 deletions tests/subsys/suit/copy/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_OK)
.len = sizeof(valid_src_value),
};

int ret = suit_plat_create_component_handle(&valid_src_component_id, &src_handle);
int ret = suit_plat_create_component_handle(&valid_src_component_id, false, &src_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -80,7 +80,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_OK)
.len = sizeof(valid_dst_value),
};

ret = suit_plat_create_component_handle(&valid_dst_component_id, &dst_handle);
ret = suit_plat_create_component_handle(&valid_dst_component_id, false, &dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

arbiter_mem_access_check_fake.return_val = ARBITER_STATUS_OK;
Expand Down Expand Up @@ -132,7 +132,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_dst_hand
.len = sizeof(valid_src_value),
};

int ret = suit_plat_create_component_handle(&valid_src_component_id, &src_handle);
int ret = suit_plat_create_component_handle(&valid_src_component_id, false, &src_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -167,7 +167,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_dst_hand
.len = sizeof(valid_dst_value),
};

ret = suit_plat_create_component_handle(&valid_dst_component_id, &dst_handle);
ret = suit_plat_create_component_handle(&valid_dst_component_id, false, &dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

ret = suit_plat_release_component_handle(dst_handle);
Expand Down Expand Up @@ -203,7 +203,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_src_hand
.len = sizeof(valid_src_value),
};

int ret = suit_plat_create_component_handle(&valid_src_component_id, &src_handle);
int ret = suit_plat_create_component_handle(&valid_src_component_id, false, &src_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -238,7 +238,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_src_hand
.len = sizeof(valid_dst_value),
};

ret = suit_plat_create_component_handle(&valid_dst_component_id, &dst_handle);
ret = suit_plat_create_component_handle(&valid_dst_component_id, false, &dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

ret = suit_plat_release_component_handle(src_handle);
Expand Down Expand Up @@ -271,7 +271,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_memptr_e
.len = sizeof(valid_src_value),
};

int ret = suit_plat_create_component_handle(&valid_src_component_id, &src_handle);
int ret = suit_plat_create_component_handle(&valid_src_component_id, false, &src_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -286,7 +286,7 @@ ZTEST(copy_tests, test_integrated_fetch_to_memptr_and_copy_to_msink_NOK_memptr_e
.len = sizeof(valid_dst_value),
};

ret = suit_plat_create_component_handle(&valid_dst_component_id, &dst_handle);
ret = suit_plat_create_component_handle(&valid_dst_component_id, false, &dst_handle);
zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

ret = suit_plat_copy(dst_handle, src_handle, NULL);
Expand Down
16 changes: 8 additions & 8 deletions tests/subsys/suit/fetch/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ZTEST(fetch_tests, test_integrated_fetch_to_msink_OK)
.len = sizeof(valid_dst_value),
};

int ret = suit_plat_create_component_handle(&valid_dst_component_id, &dst_handle);
int ret = suit_plat_create_component_handle(&valid_dst_component_id, false, &dst_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -145,7 +145,7 @@ ZTEST(fetch_tests, test_integrated_fetch_to_memptr_OK)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -187,7 +187,7 @@ ZTEST(fetch_tests, test_fetch_to_memptr_OK)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -219,7 +219,7 @@ ZTEST(fetch_tests, test_fetch_to_memptr_NOK_uri_not_in_cache)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -252,7 +252,7 @@ ZTEST(fetch_tests, test_fetch_to_memptr_NOK_invalid_component_id)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -284,7 +284,7 @@ ZTEST(fetch_tests, test_integrated_fetch_to_memptr_NOK_data_ptr_NULL)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down Expand Up @@ -312,7 +312,7 @@ ZTEST(fetch_tests, test_integrated_fetch_to_memptr_NOK_data_size_zero)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -339,7 +339,7 @@ ZTEST(fetch_tests, test_integrated_fetch_to_memptr_NOK_handle_NULL)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &component_handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &component_handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down
6 changes: 3 additions & 3 deletions tests/subsys/suit/invoke/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ZTEST(invoke_tests, test_invoke_OK)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -52,7 +52,7 @@ ZTEST(invoke_tests, test_invoke_NOK_unsupported_component_type)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -73,7 +73,7 @@ ZTEST(invoke_tests, test_invoke_NOK_unsupported_cpu_id)
.len = sizeof(valid_value),
};

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down
12 changes: 6 additions & 6 deletions tests/subsys/suit/sink_selector/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ZTEST(sink_selector_tests, test_select_memptr_sink_OK)
};
struct stream_sink sink;

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -56,7 +56,7 @@ ZTEST(sink_selector_tests, test_select_flash_sink_OK)
};
struct stream_sink sink;

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -80,7 +80,7 @@ ZTEST(sink_selector_tests, test_select_ram_sink_OK)
};
struct stream_sink sink;

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -103,7 +103,7 @@ ZTEST(sink_selector_tests, test_select_sdfw_sink_OK)
};
struct stream_sink sink;

int ret = suit_plat_create_component_handle(&valid_component_id, &handle);
int ret = suit_plat_create_component_handle(&valid_component_id, false, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand All @@ -126,7 +126,7 @@ ZTEST(sink_selector_tests, test_select_invalid_component_id)
.len = sizeof(invalid_value),
};

int ret = suit_plat_create_component_handle(&invalid_component_id, &handle);
int ret = suit_plat_create_component_handle(&invalid_component_id, false, &handle);

zassert_equal(ret, SUIT_ERR_UNSUPPORTED_COMPONENT_ID,
"create_component_handle unexpected error %i", ret);
Expand All @@ -146,7 +146,7 @@ ZTEST(sink_selector_tests, test_select_unsupported_component)
};
struct stream_sink sink;

int ret = suit_plat_create_component_handle(&invalid_component_id, &handle);
int ret = suit_plat_create_component_handle(&invalid_component_id, true, &handle);

zassert_equal(ret, SUIT_SUCCESS, "create_component_handle failed - error %i", ret);

Expand Down
3 changes: 2 additions & 1 deletion tests/subsys/suit/unit/mocks/include/mock_suit_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ FAKE_VALUE_FUNC(int, suit_plat_check_digest, enum suit_cose_alg, struct zcbor_st
FAKE_VALUE_FUNC(int, suit_plat_authenticate_manifest, struct zcbor_string *, enum suit_cose_alg,
struct zcbor_string *, struct zcbor_string *, struct zcbor_string *);
FAKE_VALUE_FUNC(int, suit_plat_authorize_unsigned_manifest, struct zcbor_string *);
FAKE_VALUE_FUNC(int, suit_plat_create_component_handle, struct zcbor_string *, suit_component_t *);
FAKE_VALUE_FUNC(int, suit_plat_create_component_handle, struct zcbor_string *, bool,
suit_component_t *);
FAKE_VALUE_FUNC(int, suit_plat_release_component_handle, suit_component_t);

#ifdef CONFIG_CHECK_IMAGE_MATCH_TEST
Expand Down
Loading

0 comments on commit 9bef74e

Please sign in to comment.