mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #14007 from LDong-Arm/tdb_no_flash_simulation
Clean-up: TDBStore no longer requires BlockDevice to have flash behaviourpull/14064/head
commit
46c9cf05a5
|
@ -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<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.
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "blockdevice/HeapBlockDevice.h"
|
||||
#include "blockdevice/FlashSimBlockDevice.h"
|
||||
#include "tdbstore/TDBStore.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue