From 3786d3958d6429abec2b8d8c96aac5665c017b38 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:12:18 +0000 Subject: [PATCH 1/8] kv_config: TDBStore doesn't require flash simulation anymore --- .../kvstore/kv_config/source/kv_config.cpp | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/storage/kvstore/kv_config/source/kv_config.cpp b/storage/kvstore/kv_config/source/kv_config.cpp index 682535a75c..3edb34e17b 100644 --- a/storage/kvstore/kv_config/source/kv_config.cpp +++ b/storage/kvstore/kv_config/source/kv_config.cpp @@ -26,7 +26,6 @@ #include "tdbstore/TDBStore.h" #include "mbed_error.h" #include "drivers/FlashIAP.h" -#include "blockdevice/FlashSimBlockDevice.h" #include "mbed_trace.h" #include "securestore/SecureStore.h" #define TRACE_GROUP "KVCFG" @@ -738,21 +737,7 @@ int _storage_config_TDB_EXTERNAL() return MBED_ERROR_FAILED_OPERATION ; } - //TDBStore needs a block device base on flash. So if this is non-flash type block device, - //add FlashSimBlockDevice on top of it. - if (bd->get_erase_value() == -1) { - //TDBStore needs FlashSimBlockDevice when working with non-flash type block device - if (bd->init() != MBED_SUCCESS) { - tr_error("KV Config: Fail to init external BlockDevice."); - return MBED_ERROR_FAILED_OPERATION ; - } - - static FlashSimBlockDevice flash_bd(bd); - kvstore_config.external_bd = &flash_bd; - } else { - kvstore_config.external_bd = bd; - } - + kvstore_config.external_bd = bd; kvstore_config.flags_mask = ~(0); return _storage_config_tdb_external_common(); @@ -778,20 +763,7 @@ int _storage_config_TDB_EXTERNAL_NO_RBP() return MBED_ERROR_FAILED_OPERATION ; } - //TDBStore needs a block device base on flash. So if this is non-flash type block device, - //add FlashSimBlockDevice on top of the SDBlockDevice - if (bd->get_erase_value() == -1) { - //TDBStore needs FlashSimBlockDevice when working with non-flash type block device - if (bd->init() != MBED_SUCCESS) { - tr_error("KV Config: Fail to init external BlockDevice."); - return MBED_ERROR_FAILED_OPERATION ; - } - - static FlashSimBlockDevice flash_bd(bd); - kvstore_config.external_bd = &flash_bd; - } else { - kvstore_config.external_bd = bd; - } + kvstore_config.external_bd = bd; //Masking flag - Actually used to remove any KVStore flag which is not supported //in the chosen KVStore profile. From 15e582fc270110cb7d16e108575ad301f50c5e1b Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:18:34 +0000 Subject: [PATCH 2/8] TDBStore unit test: flash simulation no longer required --- .../tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp | 10 ++++------ .../tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp index 1fab776f91..b0a4e9925c 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp @@ -16,7 +16,6 @@ #include "gtest/gtest.h" #include "blockdevice/HeapBlockDevice.h" -#include "blockdevice/FlashSimBlockDevice.h" #include "tdbstore/TDBStore.h" #include @@ -28,8 +27,7 @@ using namespace mbed; class TDBStoreModuleTest : public testing::Test { protected: HeapBlockDevice heap{DEVICE_SIZE, BLOCK_SIZE}; - FlashSimBlockDevice flash{&heap}; - TDBStore tdb{&flash}; + TDBStore tdb{&heap}; virtual void SetUp() { @@ -63,9 +61,9 @@ TEST_F(TDBStoreModuleTest, set_get) TEST_F(TDBStoreModuleTest, erased_set_get) { EXPECT_EQ(tdb.deinit(), MBED_SUCCESS); - EXPECT_EQ(flash.init(), MBED_SUCCESS); - EXPECT_EQ(flash.erase(0, flash.size()), MBED_SUCCESS); - EXPECT_EQ(flash.deinit(), MBED_SUCCESS); + EXPECT_EQ(heap.init(), MBED_SUCCESS); + EXPECT_EQ(heap.erase(0, heap.size()), MBED_SUCCESS); + EXPECT_EQ(heap.deinit(), MBED_SUCCESS); EXPECT_EQ(tdb.init(), MBED_SUCCESS); char buf[100]; size_t size; diff --git a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake index e11382cd33..5d1a3a5081 100644 --- a/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake +++ b/storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake @@ -10,7 +10,6 @@ set(unittest-includes ${unittest-includes} ) set(unittest-sources - ../storage/blockdevice/source/FlashSimBlockDevice.cpp ../storage/blockdevice/source/HeapBlockDevice.cpp ../storage/blockdevice/source/BufferedBlockDevice.cpp ../storage/kvstore/tdbstore/source/TDBStore.cpp From 5880a39f1fac68965c7f2a7c381926cbbe6f8ed2 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:20:23 +0000 Subject: [PATCH 3/8] TDBStore design doc: flash simulation no longer required --- storage/docs/TDBStore/TDBStore_design.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/storage/docs/TDBStore/TDBStore_design.md b/storage/docs/TDBStore/TDBStore_design.md index 2f53b3afed..dbe81f15ac 100644 --- a/storage/docs/TDBStore/TDBStore_design.md +++ b/storage/docs/TDBStore/TDBStore_design.md @@ -40,8 +40,6 @@ Tiny Database Storage (TDBStore) is a lightweight module that stores data on fla TDBStore assumes the underlying block device is fully dedicated to it (starting offset 0). If you want to dedicate only a part of the device to TDBStore, use a sliced block device, typically with `SlicingBlockDevice`. -In addition, this feature requires a flash-based block device, such as `FlashIAPBlockDevice` or `SpifBlockDevice`. It can work on top of block devices that don't need erasing before writes, such as `HeapBlockDevice` or `SDBlockDevice`, but requires a flash simulator layer for this purpose, such as the one `FlashSimBlockDevice` offers. - # System architecture and high-level design ## Design basics From 2d8a566718f8679b0f1604938dfa212c6b57212e Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:24:37 +0000 Subject: [PATCH 4/8] SecureStore whitebox test: flash simulation no longer required --- .../securestore/tests/TESTS/securestore/whitebox/main.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/storage/kvstore/securestore/tests/TESTS/securestore/whitebox/main.cpp b/storage/kvstore/securestore/tests/TESTS/securestore/whitebox/main.cpp index 8c10e068dc..17d4df8789 100644 --- a/storage/kvstore/securestore/tests/TESTS/securestore/whitebox/main.cpp +++ b/storage/kvstore/securestore/tests/TESTS/securestore/whitebox/main.cpp @@ -24,7 +24,6 @@ #include "mbed_error.h" #include "Timer.h" #include "HeapBlockDevice.h" -#include "FlashSimBlockDevice.h" #include "SlicingBlockDevice.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -57,8 +56,7 @@ SPIFBlockDevice flash_bd(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_S SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size); SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size); #else -HeapBlockDevice bd(ul_bd_size + rbp_bd_size, 1, 1, 4096); -FlashSimBlockDevice flash_bd(&bd); +HeapBlockDevice flash_bd(ul_bd_size + rbp_bd_size, 1, 1, 4096); SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size); SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size); #endif @@ -417,8 +415,7 @@ static void multi_set_test() timer.start(); #if !defined(TEST_SPIF) && !defined(TEST_SD) - HeapBlockDevice heap_bd(4096 * 64, 1, 1, 4096); - FlashSimBlockDevice flash_bd(&heap_bd); + HeapBlockDevice flash_bd(4096 * 64, 1, 1, 4096); #endif // TODO: Fix From cfedf1b02783c2812e78499ff3d63b256c44ad5f Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:29:04 +0000 Subject: [PATCH 5/8] TDBStore whitebox test: flash simulation no longer required --- .../tests/TESTS/tdbstore/whitebox/main.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp b/storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp index d8301aa8d0..da500b12dc 100644 --- a/storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp +++ b/storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp @@ -23,7 +23,6 @@ #include "mbed_error.h" #include "Timer.h" #include "HeapBlockDevice.h" -#include "FlashSimBlockDevice.h" #include "SlicingBlockDevice.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -50,8 +49,7 @@ SlicingBlockDevice flash_bd(&bd, 0, 16 * 4096); #include "SDBlockDevice.h" SDBlockDevice bd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS); -SlicingBlockDevice slice_bd(&bd, 0, 512 * 512); -FlashSimBlockDevice flash_bd(&slice_bd); +SlicingBlockDevice flash_bd(&bd, 0, 512 * 512); #elif defined(TEST_FLASHIAP) #include "FlashIAPBlockDevice.h" @@ -59,8 +57,7 @@ FlashIAPBlockDevice flash_bd(0xF0000, 0x10000); #else #define USE_HEAP_BD 1 -HeapBlockDevice bd(8 * 4096, 1, 1, 4096); -FlashSimBlockDevice flash_bd(&bd); +HeapBlockDevice flash_bd(8 * 4096, 1, 1, 4096); #endif static const int heap_alloc_threshold_size = 4096; @@ -129,19 +126,18 @@ static void white_box_test() printf("\n\nBD #%d: size %d, read %d, prog %d, erase %d\n", bd_num, bdp->size, bdp->read_size, bdp->prog_size, bdp->erase_size); HeapBlockDevice heap_bd(bdp->size, bdp->read_size, bdp->prog_size, bdp->erase_size); - FlashSimBlockDevice flash_sim_bd(&heap_bd); BlockDevice *test_bd; if (bd_num == num_bds - 1) { test_bd = &flash_bd; } else { - test_bd = &flash_sim_bd; + test_bd = &heap_bd; // We need to skip the test if we don't have enough memory for the heap block device. // However, this device allocates the erase units on the fly, so "erase" it via the flash // simulator. A failure here means we haven't got enough memory. - flash_sim_bd.init(); - result = flash_sim_bd.erase(0, flash_sim_bd.size()); + heap_bd.init(); + result = heap_bd.erase(0, heap_bd.size()); TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test"); - flash_sim_bd.deinit(); + heap_bd.deinit(); } delete[] dummy; From 2064adee7c8c34ef7e3ea34dcd3ff923741bf8bc Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:32:29 +0000 Subject: [PATCH 6/8] TDBStore Doxygen: flash characteristics no longer required --- storage/kvstore/tdbstore/include/tdbstore/TDBStore.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/storage/kvstore/tdbstore/include/tdbstore/TDBStore.h b/storage/kvstore/tdbstore/include/tdbstore/TDBStore.h index 5115d12675..75f68abbfa 100644 --- a/storage/kvstore/tdbstore/include/tdbstore/TDBStore.h +++ b/storage/kvstore/tdbstore/include/tdbstore/TDBStore.h @@ -40,10 +40,7 @@ public: /** * @brief Class constructor * - * @param[in] bd Underlying block device. The BlockDevice - * can be any BlockDevice with flash characteristics. - * If using a BlockDevice without flash, such as SDBlockDevice, - * please add the FlashSimBlockDevice on top of it. + * @param[in] bd Underlying block device. * * @returns none */ From bfbc18860ba2bc712a69452aa8b99a95d2423d78 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:41:38 +0000 Subject: [PATCH 7/8] KVStore general_tests_phase_1/2: flash simulation no longer required --- .../kvstore/general_tests_phase_1/main.cpp | 21 +------------------ .../kvstore/general_tests_phase_2/main.cpp | 21 +------------------ 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_1/main.cpp b/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_1/main.cpp index d225294f92..9d0cee060e 100644 --- a/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_1/main.cpp +++ b/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_1/main.cpp @@ -20,7 +20,6 @@ #include "Thread.h" #endif #include "mbed_error.h" -#include "FlashSimBlockDevice.h" #include "SlicingBlockDevice.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -53,7 +52,6 @@ KVStore::iterator_t kvstore_it; KVStore *kvstore = NULL; FileSystem *fs = NULL; BlockDevice *bd = NULL; -FlashSimBlockDevice *flash_bd = NULL; SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL; enum kv_setup { @@ -106,12 +104,7 @@ static void kvstore_init() TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS || (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF)) #endif - if (erase_val == -1) { - flash_bd = new FlashSimBlockDevice(bd); - kvstore = new TDBStore(flash_bd); - } else { - kvstore = new TDBStore(bd); - } + kvstore = new TDBStore(bd); } if (kv_setup == FSStoreSet) { fs = FileSystem::get_default_instance(); @@ -127,10 +120,6 @@ static void kvstore_init() #if SECURESTORE_ENABLED if (kv_setup == SecStoreSet) { sec_bd = bd; - if (erase_val == -1) { - flash_bd = new FlashSimBlockDevice(bd); - sec_bd = flash_bd; - } res = sec_bd->init(); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); @@ -175,11 +164,6 @@ static void kvstore_deinit() res = kvstore->deinit(); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); - if (kv_setup == TDBStoreSet) { - if (erase_val == -1) { - delete flash_bd; - } - } if (kv_setup == FSStoreSet) { fs = FileSystem::get_default_instance(); TEST_SKIP_UNLESS(fs != NULL); @@ -187,9 +171,6 @@ static void kvstore_deinit() TEST_ASSERT_EQUAL_ERROR_CODE(0, res); } if (kv_setup == SecStoreSet) { - if (erase_val == -1) { - delete flash_bd; - } delete ul_bd; delete rbp_bd; } diff --git a/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp b/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp index 275c024244..e6a407fd94 100644 --- a/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp +++ b/storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp @@ -17,7 +17,6 @@ #include "securestore/SecureStore.h" #include "tdbstore/TDBStore.h" #include "mbed_error.h" -#include "FlashSimBlockDevice.h" #include "SlicingBlockDevice.h" #include "greentea-client/test_env.h" #include "unity/unity.h" @@ -48,7 +47,6 @@ KVStore::iterator_t kvstore_it; KVStore *kvstore = NULL; FileSystem *fs = NULL; BlockDevice *bd = NULL; -FlashSimBlockDevice *flash_bd = NULL; SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL; enum kv_setup { @@ -102,12 +100,7 @@ static void kvstore_init() TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS || (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF)) #endif - if (erase_val == -1) { - flash_bd = new FlashSimBlockDevice(bd); - kvstore = new TDBStore(flash_bd); - } else { - kvstore = new TDBStore(bd); - } + kvstore = new TDBStore(bd); } if (kv_setup == FSStoreSet) { fs = FileSystem::get_default_instance(); @@ -123,10 +116,6 @@ static void kvstore_init() #if SECURESTORE_ENABLED if (kv_setup == SecStoreSet) { sec_bd = bd; - if (erase_val == -1) { - flash_bd = new FlashSimBlockDevice(bd); - sec_bd = flash_bd; - } res = sec_bd->init(); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); @@ -174,11 +163,6 @@ static void kvstore_deinit() res = kvstore->deinit(); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); - if (kv_setup == TDBStoreSet) { - if (erase_val == -1) { - delete flash_bd; - } - } if (kv_setup == FSStoreSet) { fs = FileSystem::get_default_instance(); TEST_SKIP_UNLESS(fs != NULL); @@ -186,9 +170,6 @@ static void kvstore_deinit() TEST_ASSERT_EQUAL_ERROR_CODE(0, res); } if (kv_setup == SecStoreSet) { - if (erase_val == -1) { - delete flash_bd; - } delete ul_bd; delete rbp_bd; } From b829645cc138d328bbe740db3c4e97acfd3bdb90 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Mon, 7 Dec 2020 17:49:37 +0000 Subject: [PATCH 8/8] BlockDevice design doc: TDBStore no longer requires flash simulation --- storage/docs/BlockDevices/get_type_method.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/storage/docs/BlockDevices/get_type_method.md b/storage/docs/BlockDevices/get_type_method.md index add823819d..617b174990 100644 --- a/storage/docs/BlockDevices/get_type_method.md +++ b/storage/docs/BlockDevices/get_type_method.md @@ -15,13 +15,9 @@ To address this an add-on method of getting type is proposed for BlockDevice int ## The Motivation -Below there is a list of some examples to explain the motivation and the need for the adding of get_type to BlockDevice interface. - -examples: -- TDBStore needs to know if there are flash characteristics for the block device and if there aren�t it should use - FlashSimBlockDevice to simulate a flash BlockDevice. -- When creating a file system you would prefer working with FAT on top of SD while LITTLEFS on top of any flash block device. - Those preference in favor of better performance. +An example to explain the motivation and the need for the adding of get_type to BlockDevice interface: +when creating a file system you would prefer working with FAT on top of SD while LITTLEFS on top of any flash block device. +Those preferences are in favor of better performance. To summarize the above, it may be very useful when using block device to know the type of the instance and especially, but not only, when using get_default_instace. Sometimes applications and tests would like to behave differently depending on the instance that has been created