Skip to content

Commit 2866e21

Browse files
authored
Merge pull request #2701 from simonqhughes/master
CFSTORE Integration with Storage-Volume-Manager and Flash-Journal API update to the latest versions
2 parents e4a40cd + 655a37a commit 2866e21

File tree

31 files changed

+4053
-394
lines changed

31 files changed

+4053
-394
lines changed

TESTS/storage_abstraction/basicAPI/basicAPI.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
using namespace utest::v1;
3434

35-
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0);
36-
ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0);
35+
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
36+
ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F;
3737

3838
/* temporary buffer to hold data for testing. */
3939
static const unsigned BUFFER_SIZE = 16384;
@@ -112,6 +112,7 @@ void test_getInfo()
112112

113113
TEST_ASSERT_EQUAL(0, info.security.reserved1);
114114
TEST_ASSERT_EQUAL(0, info.security.reserved2);
115+
TEST_ASSERT((info.program_cycles == ARM_STORAGE_PROGRAM_CYCLES_INFINITE) || (info.program_cycles > 0));
115116
TEST_ASSERT(info.total_storage > 0);
116117
}
117118

@@ -373,7 +374,7 @@ control_t test_programDataUsingProgramUnit(const size_t call_count)
373374
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200);
374375
} else {
375376
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
376-
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
377+
verifyBytePattern(addr, firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0);
377378

378379
static const uint32_t BYTE_PATTERN = 0xAA551122;
379380
size_t sizeofData = info.program_unit;
@@ -495,7 +496,7 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count)
495496
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200);
496497
} else {
497498
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
498-
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
499+
verifyBytePattern(addr, firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0);
499500

500501
static const uint8_t BYTE_PATTERN = 0xAA;
501502
size_t sizeofData = info.optimal_program_unit;
@@ -579,10 +580,12 @@ void eraseCompleteCallback(int32_t status, ARM_STORAGE_OPERATION operation)
579580
const uint64_t addr = firstBlock.addr + eraseIteration * ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit;
580581
++eraseIteration;
581582

582-
#ifndef __CC_ARM
583-
printf("testing erased sector at addr %lu\n", (uint32_t)addr);
584-
#endif
585-
verifyBytePattern(addr, ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit, (uint8_t)0xFF);
583+
ARM_STORAGE_INFO info;
584+
int32_t rc = drv->GetInfo(&info);
585+
TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc);
586+
587+
//printf("testing erased sector at addr %lu", (uint32_t)addr);
588+
verifyBytePattern(addr, ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0);
586589

587590
Harness::validate_callback();
588591
}
@@ -628,6 +631,10 @@ control_t test_erase(const size_t call_count)
628631
} else {
629632
TEST_ASSERT_EQUAL(ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit, rc);
630633

634+
ARM_STORAGE_INFO info;
635+
rc = drv->GetInfo(&info);
636+
TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc);
637+
631638
/* test that the actual sector has been erased */
632639
printf("testing erased sector at addr %lu\n", (uint32_t)addr);
633640
verifyBytePattern(addr, ERASE_UNITS_PER_ITERATION * firstBlock.attributes.erase_unit, (uint8_t)0xFF);
@@ -708,8 +715,12 @@ control_t test_eraseAll(const size_t call_count)
708715
unsigned index = 0;
709716
static const unsigned MAX_VERIFY_ITERATIONS = 5;
710717
while ((index < MAX_VERIFY_ITERATIONS) && (addr < (firstBlock.addr + firstBlock.size))) {
711-
printf("testing erased chip at addr %lu\n", (uint32_t)addr);
712-
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
718+
//printf("testing erased chip at addr %lu", (uint32_t)addr);
719+
ARM_STORAGE_INFO info;
720+
rc = drv->GetInfo(&info);
721+
TEST_ASSERT_EQUAL(ARM_DRIVER_OK, rc);
722+
723+
verifyBytePattern(addr, firstBlock.attributes.erase_unit, info.erased_value ? (uint8_t)0xFF : (uint8_t)0);
713724

714725
index++;
715726
addr += firstBlock.attributes.erase_unit;

features/storage/FEATURE_STORAGE/TESTS/cfstore/add_del/add_del.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ control_t cfstore_add_del_test_04(const size_t call_count)
279279
return CaseNext;
280280
}
281281

282-
/** @brief Delete and attribute after an internal realloc of the cfstore memory area
282+
/** @brief Delete an attribute after an internal realloc of the cfstore memory area
283283
*
284284
* This test case goes through the following steps:
285285
* 1. Creates attribute att_1 of size x, and write some data. This causes an internal

features/storage/FEATURE_STORAGE/TESTS/cfstore/example1/example1.cpp

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ typedef enum cfstore_ex_state_t {
234234
CFSTORE_EX_STATE_UNINIT_DONE
235235
} cfstore_ex_state_t;
236236

237-
238237
typedef struct cfstore_example1_ctx_t
239238
{
240239
ARM_CFSTORE_CAPABILITIES caps;
@@ -263,7 +262,87 @@ static void cfstore_ex_fms_update(cfstore_example1_ctx_t* ctx);
263262
/// @endcond
264263

265264

266-
/* @brief test startup code to reset flash
265+
#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
266+
267+
#define CFSTORE_FLASH_START_FORMAT (FLASH_JOURNAL_OPCODE_RESET + 0x00010000)
268+
269+
typedef enum cfstore_ex_flash_state_t {
270+
CFSTORE_EX_FLASH_STATE_STARTING = 1,
271+
CFSTORE_EX_FLASH_STATE_FORMATTING,
272+
CFSTORE_EX_FLASH_STATE_INITIALIZING,
273+
CFSTORE_EX_FLASH_STATE_RESETTING,
274+
CFSTORE_EX_FLASH_STATE_READY,
275+
} cfstore_ex_flash_state_t;
276+
277+
typedef struct cfstore_example1_flash_ctx_t
278+
{
279+
volatile cfstore_ex_flash_state_t state;
280+
} cfstore_example1_flash_ctx_t;
281+
282+
static cfstore_example1_flash_ctx_t cfstore_example1_flash_ctx_g;
283+
284+
285+
static void cfstore_ex_flash_journal_callback(int32_t status, FlashJournal_OpCode_t cmd_code)
286+
{
287+
static FlashJournal_t jrnl;
288+
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
289+
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F;
290+
291+
292+
if(cmd_code == (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT) {
293+
CFSTORE_EX1_LOG("FORMATTING%s", "\n");
294+
status = flashJournalStrategySequential_format(drv, 4, cfstore_ex_flash_journal_callback);
295+
CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status);
296+
if(status == 0) {
297+
/* async completion pending */
298+
return;
299+
}
300+
/* status > 0 implies operation completed synchronously
301+
* intentional fall through */
302+
}
303+
304+
switch(cmd_code)
305+
{
306+
case FLASH_JOURNAL_OPCODE_FORMAT:
307+
/* format done */
308+
CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_format() failed (status=%d)\r\n", __func__, (int) status);
309+
cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_INITIALIZING;
310+
311+
CFSTORE_EX1_LOG("FLASH INITIALIZING%s", "\n");
312+
status = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL);
313+
CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status);
314+
if(status == 0) {
315+
/* async completion pending */
316+
break;
317+
}
318+
/* status > 0 implies operation completed synchronously
319+
* intentional fall through */
320+
case FLASH_JOURNAL_OPCODE_INITIALIZE:
321+
/* initialize done */
322+
CFSTORE_EX1_TEST_ASSERT_MSG(status > JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (status=%d)\r\n", __func__, (int) status);
323+
cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_RESETTING;
324+
325+
CFSTORE_EX1_LOG("FLASH RESETTING%s", "\n");
326+
status = FlashJournal_reset(&jrnl);
327+
CFSTORE_EX1_TEST_ASSERT_MSG(status >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (status=%d)\r\n", __func__, (int) status);
328+
/* intentional fall through */
329+
case FLASH_JOURNAL_OPCODE_RESET:
330+
/* reset done */
331+
CFSTORE_EX1_LOG("FLASH RESET DONE%s", "\n");
332+
cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_READY;
333+
break;
334+
335+
default:
336+
CFSTORE_EX1_LOG("%s:Error: notification of unsupported cmd_code event (status=%d, cmd_code=%d)\n", __func__, (int) status, (int) cmd_code);
337+
return;
338+
}
339+
return;
340+
}
341+
#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
342+
343+
344+
345+
/* @brief test startup code to reset flash for testing purposes.
267346
*/
268347
static int32_t cfstore_test_startup(void)
269348
{
@@ -272,16 +351,13 @@ static int32_t cfstore_test_startup(void)
272351

273352
#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
274353

275-
int32_t ret = ARM_DRIVER_ERROR;
276-
static FlashJournal_t jrnl;
277-
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0);
278-
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0);
279-
280-
ret = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL);
281-
CFSTORE_EX1_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (ret=%d)\r\n", __func__, (int) ret);
354+
memset(&cfstore_example1_flash_ctx_g, 0, sizeof(cfstore_example1_flash_ctx_g));
355+
cfstore_example1_flash_ctx_g.state = CFSTORE_EX_FLASH_STATE_STARTING;
356+
cfstore_ex_flash_journal_callback(JOURNAL_STATUS_OK, (FlashJournal_OpCode_t) CFSTORE_FLASH_START_FORMAT);
357+
while(cfstore_example1_flash_ctx_g.state != CFSTORE_EX_FLASH_STATE_READY) {
358+
/* spin */
359+
}
282360

283-
ret = FlashJournal_reset(&jrnl);
284-
CFSTORE_EX1_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_reset() failed (ret=%d)\r\n", __func__, (int) ret);
285361
#endif /* CFSTORE_CONFIG_BACKEND_FLASH_ENABLED */
286362

287363
return ARM_DRIVER_OK;

features/storage/FEATURE_STORAGE/TESTS/cfstore/example3/example3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static control_t cfstore_example3_app_start(const size_t call_count)
268268
ctx->hkey_prev = ctx->hkey_prev_buf;
269269
ctx->caps = cfstore_drv->GetCapabilities();
270270
CFSTORE_EX1_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops);
271-
if(ctx->caps.asynchronous_ops == true){
271+
if(ctx->caps.asynchronous_ops == 1){
272272
/* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
273273
* This means the test will conveniently pass when run in CI as part of async mode testing */
274274
CFSTORE_EX1_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");

features/storage/FEATURE_STORAGE/TESTS/cfstore/example4/example4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static control_t cfstore_example4_test_00(const size_t call_count)
7474
/* initialise the context */
7575
caps = gCfStoreDriver->GetCapabilities();
7676
CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, caps.asynchronous_ops);
77-
if(caps.asynchronous_ops == true){
77+
if(caps.asynchronous_ops == 1){
7878
/* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
7979
* This means the test will conveniently pass when run in CI as part of async mode testing */
8080
CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");

features/storage/FEATURE_STORAGE/TESTS/cfstore/example5/example5.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ int32_t cfstore_test_startup(void)
167167
#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
168168
int32_t ret = ARM_DRIVER_ERROR;
169169
static FlashJournal_t jrnl;
170-
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0);
171-
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0);
170+
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
171+
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F;
172172

173173
ret = FlashJournal_initialize(&jrnl, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, NULL);
174174
CFSTORE_EX5_TEST_ASSERT_MSG(ret >= JOURNAL_STATUS_OK, "%s:Error: FlashJournal_initialize() failed (ret=%d)\r\n", __func__, (int) ret);
@@ -278,7 +278,7 @@ static control_t cfstore_EXAMPLE5_app_start(const size_t call_count)
278278
ctx->hkey_prev = ctx->hkey_prev_buf;
279279
ctx->caps = cfstore_drv->GetCapabilities();
280280
CFSTORE_EX5_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops);
281-
if(ctx->caps.asynchronous_ops == true){
281+
if(ctx->caps.asynchronous_ops){
282282
/* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
283283
* This means the test will conveniently pass when run in CI as part of async mode testing */
284284
CFSTORE_EX5_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");

features/storage/FEATURE_STORAGE/TESTS/cfstore/flash/flash.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ char cfstore_flash_utest_msg_g[CFSTORE_FLASH_UTEST_MSG_BUF_SIZE];
8888

8989
#ifdef CFSTORE_CONFIG_BACKEND_FLASH_ENABLED
9090
uint16_t cfstore_flash_mtd_async_ops_g = 0;
91-
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_(0);
91+
extern ARM_DRIVER_STORAGE ARM_Driver_Storage_MTD_K64F;
92+
9293

9394
/* KV data for test_01 */
9495
static cfstore_kv_data_t cfstore_flush_test_01_kv_data[] = {
@@ -279,7 +280,7 @@ void cfstore_flash_test_01_callback(int32_t status, FlashJournal_OpCode_t cmd_co
279280
static void cfstore_flash_fsm_init_on_entry(void* context)
280281
{
281282
/* round up cfstore_flash_data_blob_t to nearest k64f program unit size */
282-
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_(0);
283+
const ARM_DRIVER_STORAGE *drv = &ARM_Driver_Storage_MTD_K64F;
283284
FlashJournal_Info_t info;
284285
FlashJournal_Status_t status = JOURNAL_STATUS_ERROR;
285286
cfstore_flash_ctx_t* ctx = (cfstore_flash_ctx_t*) context;

features/storage/FEATURE_STORAGE/TESTS/cfstore/flush3/flush3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ static control_t cfstore_flush3_test_00(const size_t call_count)
844844
/* initialise the context */
845845
caps = drv->GetCapabilities();
846846
CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, caps.asynchronous_ops);
847-
if(caps.asynchronous_ops == true){
847+
if(caps.asynchronous_ops == 1){
848848
/* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
849849
* This means the test will conveniently pass when run in CI as part of async mode testing */
850850
CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");

features/storage/FEATURE_STORAGE/TESTS/cfstore/init/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static control_t cfstore_init_app_start(const size_t call_count)
103103
memset(ctx, 0, sizeof(cfstore_init_ctx_t));
104104
ctx->caps = cfstore_drv->GetCapabilities();
105105
CFSTORE_LOG("%s:INITIALIZING: caps.asynchronous_ops=%lu\n", __func__, ctx->caps.asynchronous_ops);
106-
if(ctx->caps.asynchronous_ops == true){
106+
if(ctx->caps.asynchronous_ops == 1){
107107
/* This is a sync mode only test. If this test is not built for sync mode, then skip testing return true
108108
* This means the test will conveniently pass when run in CI as part of async mode testing */
109109
CFSTORE_LOG("*** Skipping test as binary built for flash journal async mode, and this test is sync-only%s", "\n");

features/storage/FEATURE_STORAGE/TESTS/cfstore/misc/misc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ control_t cfstore_misc_test_04_start(const size_t call_count)
272272

273273
status = drv->GetStatus();
274274
CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() before initialisation should have reported error, but reported no error.\r\n", __func__);
275-
TEST_ASSERT_MESSAGE(status.error == true, cfstore_misc_utest_msg_g);
275+
TEST_ASSERT_MESSAGE(status.error == 1, cfstore_misc_utest_msg_g);
276276

277277
ret = drv->Initialize(cfstore_utest_default_callback, NULL);
278278
CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: failed to initialize CFSTORE (ret=%d)\n", __func__, (int) ret);
@@ -295,10 +295,10 @@ control_t cfstore_misc_test_04_end(const size_t call_count)
295295

296296
status = drv->GetStatus();
297297
CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() but reported error.\r\n", __func__);
298-
TEST_ASSERT_MESSAGE(status.error == false, cfstore_misc_utest_msg_g);
298+
TEST_ASSERT_MESSAGE(status.error == 0, cfstore_misc_utest_msg_g);
299299

300300
CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: GetStatus() reported operation in progress.\r\n", __func__);
301-
TEST_ASSERT_MESSAGE(status.in_progress == false, cfstore_misc_utest_msg_g);
301+
TEST_ASSERT_MESSAGE(status.in_progress == 0, cfstore_misc_utest_msg_g);
302302

303303
ret = drv->Uninitialize();
304304
CFSTORE_TEST_UTEST_MESSAGE(cfstore_misc_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, "%s:Error: Uninitialize() call failed.\n", __func__);

0 commit comments

Comments
 (0)