Skip to content

Commit 46c9cf0

Browse files
authored
Merge pull request #14007 from LDong-Arm/tdb_no_flash_simulation
Clean-up: TDBStore no longer requires BlockDevice to have flash behaviour
2 parents a41823a + b829645 commit 46c9cf0

File tree

10 files changed

+20
-105
lines changed

10 files changed

+20
-105
lines changed

storage/docs/BlockDevices/get_type_method.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ To address this an add-on method of getting type is proposed for BlockDevice int
1515

1616
## The Motivation
1717

18-
Below there is a list of some examples to explain the motivation and the need for the adding of get_type to BlockDevice interface.
19-
20-
examples:
21-
- TDBStore needs to know if there are flash characteristics for the block device and if there aren�t it should use
22-
FlashSimBlockDevice to simulate a flash BlockDevice.
23-
- When creating a file system you would prefer working with FAT on top of SD while LITTLEFS on top of any flash block device.
24-
Those preference in favor of better performance.
18+
An example to explain the motivation and the need for the adding of get_type to BlockDevice interface:
19+
when creating a file system you would prefer working with FAT on top of SD while LITTLEFS on top of any flash block device.
20+
Those preferences are in favor of better performance.
2521

2622
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,
2723
when using get_default_instace. Sometimes applications and tests would like to behave differently depending on the instance that has been created

storage/docs/TDBStore/TDBStore_design.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ Tiny Database Storage (TDBStore) is a lightweight module that stores data on fla
4040

4141
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`.
4242

43-
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.
44-
4543
# System architecture and high-level design
4644

4745
## Design basics

storage/kvstore/kv_config/source/kv_config.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "tdbstore/TDBStore.h"
2727
#include "mbed_error.h"
2828
#include "drivers/FlashIAP.h"
29-
#include "blockdevice/FlashSimBlockDevice.h"
3029
#include "mbed_trace.h"
3130
#include "securestore/SecureStore.h"
3231
#define TRACE_GROUP "KVCFG"
@@ -738,21 +737,7 @@ int _storage_config_TDB_EXTERNAL()
738737
return MBED_ERROR_FAILED_OPERATION ;
739738
}
740739

741-
//TDBStore needs a block device base on flash. So if this is non-flash type block device,
742-
//add FlashSimBlockDevice on top of it.
743-
if (bd->get_erase_value() == -1) {
744-
//TDBStore needs FlashSimBlockDevice when working with non-flash type block device
745-
if (bd->init() != MBED_SUCCESS) {
746-
tr_error("KV Config: Fail to init external BlockDevice.");
747-
return MBED_ERROR_FAILED_OPERATION ;
748-
}
749-
750-
static FlashSimBlockDevice flash_bd(bd);
751-
kvstore_config.external_bd = &flash_bd;
752-
} else {
753-
kvstore_config.external_bd = bd;
754-
}
755-
740+
kvstore_config.external_bd = bd;
756741
kvstore_config.flags_mask = ~(0);
757742

758743
return _storage_config_tdb_external_common();
@@ -778,20 +763,7 @@ int _storage_config_TDB_EXTERNAL_NO_RBP()
778763
return MBED_ERROR_FAILED_OPERATION ;
779764
}
780765

781-
//TDBStore needs a block device base on flash. So if this is non-flash type block device,
782-
//add FlashSimBlockDevice on top of the SDBlockDevice
783-
if (bd->get_erase_value() == -1) {
784-
//TDBStore needs FlashSimBlockDevice when working with non-flash type block device
785-
if (bd->init() != MBED_SUCCESS) {
786-
tr_error("KV Config: Fail to init external BlockDevice.");
787-
return MBED_ERROR_FAILED_OPERATION ;
788-
}
789-
790-
static FlashSimBlockDevice flash_bd(bd);
791-
kvstore_config.external_bd = &flash_bd;
792-
} else {
793-
kvstore_config.external_bd = bd;
794-
}
766+
kvstore_config.external_bd = bd;
795767

796768
//Masking flag - Actually used to remove any KVStore flag which is not supported
797769
//in the chosen KVStore profile.

storage/kvstore/securestore/tests/TESTS/securestore/whitebox/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "mbed_error.h"
2525
#include "Timer.h"
2626
#include "HeapBlockDevice.h"
27-
#include "FlashSimBlockDevice.h"
2827
#include "SlicingBlockDevice.h"
2928
#include "greentea-client/test_env.h"
3029
#include "unity/unity.h"
@@ -57,8 +56,7 @@ SPIFBlockDevice flash_bd(MBED_CONF_SPIF_DRIVER_SPI_MOSI, MBED_CONF_SPIF_DRIVER_S
5756
SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size);
5857
SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
5958
#else
60-
HeapBlockDevice bd(ul_bd_size + rbp_bd_size, 1, 1, 4096);
61-
FlashSimBlockDevice flash_bd(&bd);
59+
HeapBlockDevice flash_bd(ul_bd_size + rbp_bd_size, 1, 1, 4096);
6260
SlicingBlockDevice ul_bd(&flash_bd, 0, ul_bd_size);
6361
SlicingBlockDevice rbp_bd(&flash_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
6462
#endif
@@ -417,8 +415,7 @@ static void multi_set_test()
417415

418416
timer.start();
419417
#if !defined(TEST_SPIF) && !defined(TEST_SD)
420-
HeapBlockDevice heap_bd(4096 * 64, 1, 1, 4096);
421-
FlashSimBlockDevice flash_bd(&heap_bd);
418+
HeapBlockDevice flash_bd(4096 * 64, 1, 1, 4096);
422419
#endif
423420

424421
// TODO: Fix

storage/kvstore/tdbstore/include/tdbstore/TDBStore.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class TDBStore : public KVStore {
4040
/**
4141
* @brief Class constructor
4242
*
43-
* @param[in] bd Underlying block device. The BlockDevice
44-
* can be any BlockDevice with flash characteristics.
45-
* If using a BlockDevice without flash, such as SDBlockDevice,
46-
* please add the FlashSimBlockDevice on top of it.
43+
* @param[in] bd Underlying block device.
4744
*
4845
* @returns none
4946
*/

storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "mbed_error.h"
2424
#include "Timer.h"
2525
#include "HeapBlockDevice.h"
26-
#include "FlashSimBlockDevice.h"
2726
#include "SlicingBlockDevice.h"
2827
#include "greentea-client/test_env.h"
2928
#include "unity/unity.h"
@@ -50,17 +49,15 @@ SlicingBlockDevice flash_bd(&bd, 0, 16 * 4096);
5049
#include "SDBlockDevice.h"
5150
SDBlockDevice bd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO,
5251
MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
53-
SlicingBlockDevice slice_bd(&bd, 0, 512 * 512);
54-
FlashSimBlockDevice flash_bd(&slice_bd);
52+
SlicingBlockDevice flash_bd(&bd, 0, 512 * 512);
5553

5654
#elif defined(TEST_FLASHIAP)
5755
#include "FlashIAPBlockDevice.h"
5856
FlashIAPBlockDevice flash_bd(0xF0000, 0x10000);
5957

6058
#else
6159
#define USE_HEAP_BD 1
62-
HeapBlockDevice bd(8 * 4096, 1, 1, 4096);
63-
FlashSimBlockDevice flash_bd(&bd);
60+
HeapBlockDevice flash_bd(8 * 4096, 1, 1, 4096);
6461
#endif
6562

6663
static const int heap_alloc_threshold_size = 4096;
@@ -129,19 +126,18 @@ static void white_box_test()
129126
printf("\n\nBD #%d: size %d, read %d, prog %d, erase %d\n",
130127
bd_num, bdp->size, bdp->read_size, bdp->prog_size, bdp->erase_size);
131128
HeapBlockDevice heap_bd(bdp->size, bdp->read_size, bdp->prog_size, bdp->erase_size);
132-
FlashSimBlockDevice flash_sim_bd(&heap_bd);
133129
BlockDevice *test_bd;
134130
if (bd_num == num_bds - 1) {
135131
test_bd = &flash_bd;
136132
} else {
137-
test_bd = &flash_sim_bd;
133+
test_bd = &heap_bd;
138134
// We need to skip the test if we don't have enough memory for the heap block device.
139135
// However, this device allocates the erase units on the fly, so "erase" it via the flash
140136
// simulator. A failure here means we haven't got enough memory.
141-
flash_sim_bd.init();
142-
result = flash_sim_bd.erase(0, flash_sim_bd.size());
137+
heap_bd.init();
138+
result = heap_bd.erase(0, heap_bd.size());
143139
TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test");
144-
flash_sim_bd.deinit();
140+
heap_bd.deinit();
145141
}
146142

147143
delete[] dummy;

storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/moduletest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "gtest/gtest.h"
1818
#include "blockdevice/HeapBlockDevice.h"
19-
#include "blockdevice/FlashSimBlockDevice.h"
2019
#include "tdbstore/TDBStore.h"
2120
#include <stdlib.h>
2221

@@ -28,8 +27,7 @@ using namespace mbed;
2827
class TDBStoreModuleTest : public testing::Test {
2928
protected:
3029
HeapBlockDevice heap{DEVICE_SIZE, BLOCK_SIZE};
31-
FlashSimBlockDevice flash{&heap};
32-
TDBStore tdb{&flash};
30+
TDBStore tdb{&heap};
3331

3432
virtual void SetUp()
3533
{
@@ -63,9 +61,9 @@ TEST_F(TDBStoreModuleTest, set_get)
6361
TEST_F(TDBStoreModuleTest, erased_set_get)
6462
{
6563
EXPECT_EQ(tdb.deinit(), MBED_SUCCESS);
66-
EXPECT_EQ(flash.init(), MBED_SUCCESS);
67-
EXPECT_EQ(flash.erase(0, flash.size()), MBED_SUCCESS);
68-
EXPECT_EQ(flash.deinit(), MBED_SUCCESS);
64+
EXPECT_EQ(heap.init(), MBED_SUCCESS);
65+
EXPECT_EQ(heap.erase(0, heap.size()), MBED_SUCCESS);
66+
EXPECT_EQ(heap.deinit(), MBED_SUCCESS);
6967
EXPECT_EQ(tdb.init(), MBED_SUCCESS);
7068
char buf[100];
7169
size_t size;

storage/kvstore/tdbstore/tests/UNITTESTS/TDBStore/unittest.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ set(unittest-includes ${unittest-includes}
1010
)
1111

1212
set(unittest-sources
13-
../storage/blockdevice/source/FlashSimBlockDevice.cpp
1413
../storage/blockdevice/source/HeapBlockDevice.cpp
1514
../storage/blockdevice/source/BufferedBlockDevice.cpp
1615
../storage/kvstore/tdbstore/source/TDBStore.cpp

storage/kvstore/tests/TESTS/kvstore/general_tests_phase_1/main.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "Thread.h"
2121
#endif
2222
#include "mbed_error.h"
23-
#include "FlashSimBlockDevice.h"
2423
#include "SlicingBlockDevice.h"
2524
#include "greentea-client/test_env.h"
2625
#include "unity/unity.h"
@@ -53,7 +52,6 @@ KVStore::iterator_t kvstore_it;
5352
KVStore *kvstore = NULL;
5453
FileSystem *fs = NULL;
5554
BlockDevice *bd = NULL;
56-
FlashSimBlockDevice *flash_bd = NULL;
5755
SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL;
5856

5957
enum kv_setup {
@@ -106,12 +104,7 @@ static void kvstore_init()
106104
TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS ||
107105
(MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF))
108106
#endif
109-
if (erase_val == -1) {
110-
flash_bd = new FlashSimBlockDevice(bd);
111-
kvstore = new TDBStore(flash_bd);
112-
} else {
113-
kvstore = new TDBStore(bd);
114-
}
107+
kvstore = new TDBStore(bd);
115108
}
116109
if (kv_setup == FSStoreSet) {
117110
fs = FileSystem::get_default_instance();
@@ -127,10 +120,6 @@ static void kvstore_init()
127120
#if SECURESTORE_ENABLED
128121
if (kv_setup == SecStoreSet) {
129122
sec_bd = bd;
130-
if (erase_val == -1) {
131-
flash_bd = new FlashSimBlockDevice(bd);
132-
sec_bd = flash_bd;
133-
}
134123
res = sec_bd->init();
135124
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
136125

@@ -175,21 +164,13 @@ static void kvstore_deinit()
175164
res = kvstore->deinit();
176165
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
177166

178-
if (kv_setup == TDBStoreSet) {
179-
if (erase_val == -1) {
180-
delete flash_bd;
181-
}
182-
}
183167
if (kv_setup == FSStoreSet) {
184168
fs = FileSystem::get_default_instance();
185169
TEST_SKIP_UNLESS(fs != NULL);
186170
res = fs->unmount();
187171
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
188172
}
189173
if (kv_setup == SecStoreSet) {
190-
if (erase_val == -1) {
191-
delete flash_bd;
192-
}
193174
delete ul_bd;
194175
delete rbp_bd;
195176
}

storage/kvstore/tests/TESTS/kvstore/general_tests_phase_2/main.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "securestore/SecureStore.h"
1818
#include "tdbstore/TDBStore.h"
1919
#include "mbed_error.h"
20-
#include "FlashSimBlockDevice.h"
2120
#include "SlicingBlockDevice.h"
2221
#include "greentea-client/test_env.h"
2322
#include "unity/unity.h"
@@ -48,7 +47,6 @@ KVStore::iterator_t kvstore_it;
4847
KVStore *kvstore = NULL;
4948
FileSystem *fs = NULL;
5049
BlockDevice *bd = NULL;
51-
FlashSimBlockDevice *flash_bd = NULL;
5250
SlicingBlockDevice *ul_bd = NULL, *rbp_bd = NULL;
5351

5452
enum kv_setup {
@@ -102,12 +100,7 @@ static void kvstore_init()
102100
TEST_SKIP_UNLESS(MBED_CONF_TARGET_INTERNAL_FLASH_UNIFORM_SECTORS ||
103101
(MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE != 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS != 0xFFFFFFFF))
104102
#endif
105-
if (erase_val == -1) {
106-
flash_bd = new FlashSimBlockDevice(bd);
107-
kvstore = new TDBStore(flash_bd);
108-
} else {
109-
kvstore = new TDBStore(bd);
110-
}
103+
kvstore = new TDBStore(bd);
111104
}
112105
if (kv_setup == FSStoreSet) {
113106
fs = FileSystem::get_default_instance();
@@ -123,10 +116,6 @@ static void kvstore_init()
123116
#if SECURESTORE_ENABLED
124117
if (kv_setup == SecStoreSet) {
125118
sec_bd = bd;
126-
if (erase_val == -1) {
127-
flash_bd = new FlashSimBlockDevice(bd);
128-
sec_bd = flash_bd;
129-
}
130119
res = sec_bd->init();
131120
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
132121

@@ -174,21 +163,13 @@ static void kvstore_deinit()
174163
res = kvstore->deinit();
175164
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
176165

177-
if (kv_setup == TDBStoreSet) {
178-
if (erase_val == -1) {
179-
delete flash_bd;
180-
}
181-
}
182166
if (kv_setup == FSStoreSet) {
183167
fs = FileSystem::get_default_instance();
184168
TEST_SKIP_UNLESS(fs != NULL);
185169
res = fs->unmount();
186170
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
187171
}
188172
if (kv_setup == SecStoreSet) {
189-
if (erase_val == -1) {
190-
delete flash_bd;
191-
}
192173
delete ul_bd;
193174
delete rbp_bd;
194175
}

0 commit comments

Comments
 (0)