Merge pull request #14007 from LDong-Arm/tdb_no_flash_simulation

Clean-up: TDBStore no longer requires BlockDevice to have flash behaviour
pull/14064/head
Martin Kojtal 2020-12-17 10:28:14 +00:00 committed by GitHub
commit 46c9cf05a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 105 deletions

View File

@ -15,13 +15,9 @@ To address this an add-on method of getting type is proposed for BlockDevice int
## The Motivation ## 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. 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.
examples: Those preferences are in favor of better performance.
- TDBStore needs to know if there are flash characteristics for the block device and if there aren<65>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.
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, 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 when using get_default_instace. Sometimes applications and tests would like to behave differently depending on the instance that has been created

View File

@ -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`. 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 # System architecture and high-level design
## Design basics ## Design basics

View File

@ -26,7 +26,6 @@
#include "tdbstore/TDBStore.h" #include "tdbstore/TDBStore.h"
#include "mbed_error.h" #include "mbed_error.h"
#include "drivers/FlashIAP.h" #include "drivers/FlashIAP.h"
#include "blockdevice/FlashSimBlockDevice.h"
#include "mbed_trace.h" #include "mbed_trace.h"
#include "securestore/SecureStore.h" #include "securestore/SecureStore.h"
#define TRACE_GROUP "KVCFG" #define TRACE_GROUP "KVCFG"
@ -738,21 +737,7 @@ int _storage_config_TDB_EXTERNAL()
return MBED_ERROR_FAILED_OPERATION ; return MBED_ERROR_FAILED_OPERATION ;
} }
//TDBStore needs a block device base on flash. So if this is non-flash type block device, kvstore_config.external_bd = bd;
//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.flags_mask = ~(0); kvstore_config.flags_mask = ~(0);
return _storage_config_tdb_external_common(); return _storage_config_tdb_external_common();
@ -778,20 +763,7 @@ int _storage_config_TDB_EXTERNAL_NO_RBP()
return MBED_ERROR_FAILED_OPERATION ; return MBED_ERROR_FAILED_OPERATION ;
} }
//TDBStore needs a block device base on flash. So if this is non-flash type block device, kvstore_config.external_bd = bd;
//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;
}
//Masking flag - Actually used to remove any KVStore flag which is not supported //Masking flag - Actually used to remove any KVStore flag which is not supported
//in the chosen KVStore profile. //in the chosen KVStore profile.

View File

@ -24,7 +24,6 @@
#include "mbed_error.h" #include "mbed_error.h"
#include "Timer.h" #include "Timer.h"
#include "HeapBlockDevice.h" #include "HeapBlockDevice.h"
#include "FlashSimBlockDevice.h"
#include "SlicingBlockDevice.h" #include "SlicingBlockDevice.h"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
#include "unity/unity.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 ul_bd(&flash_bd, 0, ul_bd_size);
SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size); SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
#else #else
HeapBlockDevice bd(ul_bd_size + rbp_bd_size, 1, 1, 4096); HeapBlockDevice flash_bd(ul_bd_size + rbp_bd_size, 1, 1, 4096);
FlashSimBlockDevice flash_bd(&bd);
SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size); SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size);
SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size); SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
#endif #endif
@ -417,8 +415,7 @@ static void multi_set_test()
timer.start(); timer.start();
#if !defined(TEST_SPIF) && !defined(TEST_SD) #if !defined(TEST_SPIF) && !defined(TEST_SD)
HeapBlockDevice heap_bd(4096 * 64, 1, 1, 4096); HeapBlockDevice flash_bd(4096 * 64, 1, 1, 4096);
FlashSimBlockDevice flash_bd(&heap_bd);
#endif #endif
// TODO: Fix // TODO: Fix

View File

@ -40,10 +40,7 @@ public:
/** /**
* @brief Class constructor * @brief Class constructor
* *
* @param[in] bd Underlying block device. The BlockDevice * @param[in] bd Underlying block device.
* can be any BlockDevice with flash characteristics.
* If using a BlockDevice without flash, such as SDBlockDevice,
* please add the FlashSimBlockDevice on top of it.
* *
* @returns none * @returns none
*/ */

View File

@ -23,7 +23,6 @@
#include "mbed_error.h" #include "mbed_error.h"
#include "Timer.h" #include "Timer.h"
#include "HeapBlockDevice.h" #include "HeapBlockDevice.h"
#include "FlashSimBlockDevice.h"
#include "SlicingBlockDevice.h" #include "SlicingBlockDevice.h"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
#include "unity/unity.h" #include "unity/unity.h"
@ -50,8 +49,7 @@ SlicingBlockDevice flash_bd(&bd, 0, 16 * 4096);
#include "SDBlockDevice.h" #include "SDBlockDevice.h"
SDBlockDevice bd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, SDBlockDevice bd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO,
MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS); MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
SlicingBlockDevice slice_bd(&bd, 0, 512 * 512); SlicingBlockDevice flash_bd(&bd, 0, 512 * 512);
FlashSimBlockDevice flash_bd(&slice_bd);
#elif defined(TEST_FLASHIAP) #elif defined(TEST_FLASHIAP)
#include "FlashIAPBlockDevice.h" #include "FlashIAPBlockDevice.h"
@ -59,8 +57,7 @@ FlashIAPBlockDevice flash_bd(0xF0000, 0x10000);
#else #else
#define USE_HEAP_BD 1 #define USE_HEAP_BD 1
HeapBlockDevice bd(8 * 4096, 1, 1, 4096); HeapBlockDevice flash_bd(8 * 4096, 1, 1, 4096);
FlashSimBlockDevice flash_bd(&bd);
#endif #endif
static const int heap_alloc_threshold_size = 4096; 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", 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); 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); HeapBlockDevice heap_bd(bdp->size, bdp->read_size, bdp->prog_size, bdp->erase_size);
FlashSimBlockDevice flash_sim_bd(&heap_bd);
BlockDevice *test_bd; BlockDevice *test_bd;
if (bd_num == num_bds - 1) { if (bd_num == num_bds - 1) {
test_bd = &flash_bd; test_bd = &flash_bd;
} else { } 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. // 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 // 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. // simulator. A failure here means we haven't got enough memory.
flash_sim_bd.init(); heap_bd.init();
result = flash_sim_bd.erase(0, flash_sim_bd.size()); result = heap_bd.erase(0, heap_bd.size());
TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test"); TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test");
flash_sim_bd.deinit(); heap_bd.deinit();
} }
delete[] dummy; delete[] dummy;

View File

@ -16,7 +16,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "blockdevice/HeapBlockDevice.h" #include "blockdevice/HeapBlockDevice.h"
#include "blockdevice/FlashSimBlockDevice.h"
#include "tdbstore/TDBStore.h" #include "tdbstore/TDBStore.h"
#include <stdlib.h> #include <stdlib.h>
@ -28,8 +27,7 @@ using namespace mbed;
class TDBStoreModuleTest : public testing::Test { class TDBStoreModuleTest : public testing::Test {
protected: protected:
HeapBlockDevice heap{DEVICE_SIZE, BLOCK_SIZE}; HeapBlockDevice heap{DEVICE_SIZE, BLOCK_SIZE};
FlashSimBlockDevice flash{&heap}; TDBStore tdb{&heap};
TDBStore tdb{&flash};
virtual void SetUp() virtual void SetUp()
{ {
@ -63,9 +61,9 @@ TEST_F(TDBStoreModuleTest, set_get)
TEST_F(TDBStoreModuleTest, erased_set_get) TEST_F(TDBStoreModuleTest, erased_set_get)
{ {
EXPECT_EQ(tdb.deinit(), MBED_SUCCESS); EXPECT_EQ(tdb.deinit(), MBED_SUCCESS);
EXPECT_EQ(flash.init(), MBED_SUCCESS); EXPECT_EQ(heap.init(), MBED_SUCCESS);
EXPECT_EQ(flash.erase(0, flash.size()), MBED_SUCCESS); EXPECT_EQ(heap.erase(0, heap.size()), MBED_SUCCESS);
EXPECT_EQ(flash.deinit(), MBED_SUCCESS); EXPECT_EQ(heap.deinit(), MBED_SUCCESS);
EXPECT_EQ(tdb.init(), MBED_SUCCESS); EXPECT_EQ(tdb.init(), MBED_SUCCESS);
char buf[100]; char buf[100];
size_t size; size_t size;

View File

@ -10,7 +10,6 @@ set(unittest-includes ${unittest-includes}
) )
set(unittest-sources set(unittest-sources
../storage/blockdevice/source/FlashSimBlockDevice.cpp
../storage/blockdevice/source/HeapBlockDevice.cpp ../storage/blockdevice/source/HeapBlockDevice.cpp
../storage/blockdevice/source/BufferedBlockDevice.cpp ../storage/blockdevice/source/BufferedBlockDevice.cpp
../storage/kvstore/tdbstore/source/TDBStore.cpp ../storage/kvstore/tdbstore/source/TDBStore.cpp

View File

@ -20,7 +20,6 @@
#include "Thread.h" #include "Thread.h"
#endif #endif
#include "mbed_error.h" #include "mbed_error.h"
#include "FlashSimBlockDevice.h"
#include "SlicingBlockDevice.h" #include "SlicingBlockDevice.h"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
#include "unity/unity.h" #include "unity/unity.h"
@ -53,7 +52,6 @@ KVStore::iterator_t kvstore_it;
KVStore *kvstore = NULL; KVStore *kvstore = NULL;
FileSystem *fs = NULL; FileSystem *fs = NULL;
BlockDevice *bd = NULL; BlockDevice *bd = NULL;
FlashSimBlockDevice *flash_bd = NULL;
SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL; SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL;
enum kv_setup { enum kv_setup {
@ -106,12 +104,7 @@ static void kvstore_init()
TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS || 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)) (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF))
#endif #endif
if (erase_val == -1) { kvstore = new TDBStore(bd);
flash_bd = new FlashSimBlockDevice(bd);
kvstore = new TDBStore(flash_bd);
} else {
kvstore = new TDBStore(bd);
}
} }
if (kv_setup == FSStoreSet) { if (kv_setup == FSStoreSet) {
fs = FileSystem::get_default_instance(); fs = FileSystem::get_default_instance();
@ -127,10 +120,6 @@ static void kvstore_init()
#if SECURESTORE_ENABLED #if SECURESTORE_ENABLED
if (kv_setup == SecStoreSet) { if (kv_setup == SecStoreSet) {
sec_bd = bd; sec_bd = bd;
if (erase_val == -1) {
flash_bd = new FlashSimBlockDevice(bd);
sec_bd = flash_bd;
}
res = sec_bd->init(); res = sec_bd->init();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
@ -175,11 +164,6 @@ static void kvstore_deinit()
res = kvstore->deinit(); res = kvstore->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
if (kv_setup == TDBStoreSet) {
if (erase_val == -1) {
delete flash_bd;
}
}
if (kv_setup == FSStoreSet) { if (kv_setup == FSStoreSet) {
fs = FileSystem::get_default_instance(); fs = FileSystem::get_default_instance();
TEST_SKIP_UNLESS(fs != NULL); TEST_SKIP_UNLESS(fs != NULL);
@ -187,9 +171,6 @@ static void kvstore_deinit()
TEST_ASSERT_EQUAL_ERROR_CODE(0, res); TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
} }
if (kv_setup == SecStoreSet) { if (kv_setup == SecStoreSet) {
if (erase_val == -1) {
delete flash_bd;
}
delete ul_bd; delete ul_bd;
delete rbp_bd; delete rbp_bd;
} }

View File

@ -17,7 +17,6 @@
#include "securestore/SecureStore.h" #include "securestore/SecureStore.h"
#include "tdbstore/TDBStore.h" #include "tdbstore/TDBStore.h"
#include "mbed_error.h" #include "mbed_error.h"
#include "FlashSimBlockDevice.h"
#include "SlicingBlockDevice.h" #include "SlicingBlockDevice.h"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
#include "unity/unity.h" #include "unity/unity.h"
@ -48,7 +47,6 @@ KVStore::iterator_t kvstore_it;
KVStore *kvstore = NULL; KVStore *kvstore = NULL;
FileSystem *fs = NULL; FileSystem *fs = NULL;
BlockDevice *bd = NULL; BlockDevice *bd = NULL;
FlashSimBlockDevice *flash_bd = NULL;
SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL; SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL;
enum kv_setup { enum kv_setup {
@ -102,12 +100,7 @@ static void kvstore_init()
TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS || 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)) (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF))
#endif #endif
if (erase_val == -1) { kvstore = new TDBStore(bd);
flash_bd = new FlashSimBlockDevice(bd);
kvstore = new TDBStore(flash_bd);
} else {
kvstore = new TDBStore(bd);
}
} }
if (kv_setup == FSStoreSet) { if (kv_setup == FSStoreSet) {
fs = FileSystem::get_default_instance(); fs = FileSystem::get_default_instance();
@ -123,10 +116,6 @@ static void kvstore_init()
#if SECURESTORE_ENABLED #if SECURESTORE_ENABLED
if (kv_setup == SecStoreSet) { if (kv_setup == SecStoreSet) {
sec_bd = bd; sec_bd = bd;
if (erase_val == -1) {
flash_bd = new FlashSimBlockDevice(bd);
sec_bd = flash_bd;
}
res = sec_bd->init(); res = sec_bd->init();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
@ -174,11 +163,6 @@ static void kvstore_deinit()
res = kvstore->deinit(); res = kvstore->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res); TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
if (kv_setup == TDBStoreSet) {
if (erase_val == -1) {
delete flash_bd;
}
}
if (kv_setup == FSStoreSet) { if (kv_setup == FSStoreSet) {
fs = FileSystem::get_default_instance(); fs = FileSystem::get_default_instance();
TEST_SKIP_UNLESS(fs != NULL); TEST_SKIP_UNLESS(fs != NULL);
@ -186,9 +170,6 @@ static void kvstore_deinit()
TEST_ASSERT_EQUAL_ERROR_CODE(0, res); TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
} }
if (kv_setup == SecStoreSet) { if (kv_setup == SecStoreSet) {
if (erase_val == -1) {
delete flash_bd;
}
delete ul_bd; delete ul_bd;
delete rbp_bd; delete rbp_bd;
} }