Skip to content

Commit f8857a6

Browse files
committed
suit: Allow to postpone DFU initialization
Add a possibility to initialize DFU partition later than at the system initialization phase. Ref: NCSDK-NONE Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 091dcef commit f8857a6

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

subsys/suit/cache/include/suit_dfu_cache_rw.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ suit_plat_err_t suit_dfu_cache_rw_slot_drop(struct suit_cache_slot *slot);
7373
*/
7474
suit_plat_err_t suit_dfu_cache_0_resize(void);
7575

76+
/**
77+
* @brief Update characteristics of NVM device unavailable at compile time
78+
*
79+
* For some NVM devices, especially external Flash, some characteristics
80+
* like write or erase block size can be at runtime only.
81+
* The same applies to memory mapping.
82+
*
83+
* For sake of simplicity, for devices with varying erase block size
84+
* the largest erase block size is taken as reference.
85+
*
86+
* Functionality leaves NVM content intact.
87+
*
88+
*/
89+
suit_plat_err_t suit_dfu_cache_rw_init(void);
90+
7691
/**
7792
* @brief Validates content of cache partitions
7893
*

subsys/suit/cache/src/suit_dfu_cache_rw.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -719,20 +719,7 @@ suit_plat_err_t suit_dfu_cache_rw_slot_drop(struct suit_cache_slot *slot)
719719
return SUIT_PLAT_ERR_INVAL;
720720
}
721721

722-
/**
723-
* @brief Update characteristics of NVM device unavailable at compile time
724-
*
725-
* For some NVM devices, especially external Flash, some characteristics
726-
* like write or erase block size can be at runtime only.
727-
* The same applies to memory mapping.
728-
*
729-
* For sake of simplicity, for devices with varying erase block size
730-
* the largest erase block size is taken as reference.
731-
*
732-
* Functionality leaves NVM content intact.
733-
*
734-
*/
735-
static int preinitialize(void)
722+
int suit_dfu_cache_rw_init(void)
736723
{
737724
for (size_t i = 1; i < ARRAY_SIZE(dfu_partitions_ext); i++) {
738725

@@ -806,5 +793,3 @@ static int preinitialize(void)
806793
}
807794
return 0;
808795
}
809-
810-
SYS_INIT(preinitialize, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

subsys/suit/orchestrator_app/src/suit_orchestrator_app.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ int suit_dfu_initialize(void)
7878
LOG_INF("DFU partition detected, addr: %p, size %d bytes",
7979
(void *)device_info.mapped_address, device_info.partition_size);
8080

81+
#if CONFIG_SUIT_CACHE_RW
82+
suit_dfu_cache_rw_init();
83+
#endif /* CONFIG_SUIT_CACHE_RW */
84+
8185
#if CONFIG_SUIT_CLEANUP_ON_INIT
8286
suit_dfu_cleanup();
8387

tests/subsys/suit/cache_pool_digest/src/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ FAKE_VALUE_FUNC(int, suit_plat_authorize_unsigned_manifest, struct zcbor_string
5353
FAKE_VALUE_FUNC(int, suit_plat_authenticate_manifest, struct zcbor_string *, enum suit_cose_alg,
5454
struct zcbor_string *, struct zcbor_string *, struct zcbor_string *);
5555

56+
static void test_before(void *data)
57+
{
58+
suit_plat_err_t plat_ret = suit_dfu_cache_rw_init();
59+
60+
zassert_equal(plat_ret, SUIT_PLAT_SUCCESS,
61+
"Unable to initialize DFU cache module before test execution: %d", plat_ret);
62+
}
63+
5664
void clear_dfu_test_partitions(void *f)
5765
{
5866
/* Erase the area, to meet the preconditions in the next test. */
@@ -71,7 +79,7 @@ void clear_dfu_test_partitions(void *f)
7179
zassert_equal(rc, 0, "Unable to erase dfu_cache_partition_3 before test execution: %i", rc);
7280
}
7381

74-
ZTEST_SUITE(cache_pool_digest_tests, NULL, NULL, NULL, clear_dfu_test_partitions, NULL);
82+
ZTEST_SUITE(cache_pool_digest_tests, NULL, NULL, test_before, clear_dfu_test_partitions, NULL);
7583

7684
ZTEST(cache_pool_digest_tests, test_cache_get_slot_ok)
7785
{

tests/subsys/suit/cache_sink/src/main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ void setup_dfu_test_corrupted_cache(const uint8_t *corrupted_cache, size_t corru
120120
zassert_equal(res, 0, "Mem compare after write failed");
121121
}
122122

123+
static void test_before(void *data)
124+
{
125+
suit_plat_err_t plat_ret = suit_dfu_cache_rw_init();
126+
127+
zassert_equal(plat_ret, SUIT_PLAT_SUCCESS,
128+
"Unable to initialize DFU cache module before test execution: %d", plat_ret);
129+
}
130+
123131
void clear_dfu_test_partitions(void *f)
124132
{
125133
/* Erase the area, to meet the preconditions in the next test. */
@@ -153,9 +161,10 @@ bool is_cache_partition_1_empty(void)
153161
return true;
154162
}
155163

156-
ZTEST_SUITE(cache_rw_initialization_tests, NULL, NULL, NULL, clear_dfu_test_partitions, NULL);
164+
ZTEST_SUITE(cache_rw_initialization_tests, NULL, NULL, test_before, clear_dfu_test_partitions,
165+
NULL);
157166

158-
ZTEST_SUITE(cache_sink_recovery_tests, NULL, NULL, NULL, clear_dfu_test_partitions, NULL);
167+
ZTEST_SUITE(cache_sink_recovery_tests, NULL, NULL, test_before, clear_dfu_test_partitions, NULL);
159168

160169
ZTEST(cache_sink_recovery_tests, test_cache_recovery_header_ok_size_nok)
161170
{
@@ -192,7 +201,7 @@ ZTEST(cache_sink_recovery_tests, test_cache_recovery_malformed_zcbor)
192201
zassert_true(is_cache_partition_1_empty(), "Corrupted cache partition was not recovered");
193202
}
194203

195-
ZTEST_SUITE(cache_sink_tests, NULL, NULL, NULL, clear_dfu_test_partitions, NULL);
204+
ZTEST_SUITE(cache_sink_tests, NULL, NULL, test_before, clear_dfu_test_partitions, NULL);
196205

197206
ZTEST(cache_sink_tests, test_cache_drop_slot_ok)
198207
{

0 commit comments

Comments
 (0)