Skip to content

Commit 7cd4d11

Browse files
author
Kyle Kearney
committed
Expand error checks in _calculate_blocksize_match_tdbstore
The minimum size required by tdbstore is either 2 sectors or 10 pages, whichever is larger. Correspondingly, adjust the error checks in _calculate_blocksize_match_tdbstore to match this requirement.
1 parent cda0af6 commit 7cd4d11

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

features/storage/kvstore/conf/kv_config.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,19 @@ int _calculate_blocksize_match_tdbstore(BlockDevice *bd)
180180
{
181181
bd_size_t size = bd->size();
182182
bd_size_t erase_size = bd->get_erase_size();
183+
bd_size_t page_size = bd->get_program_size();
183184
bd_size_t number_of_sector = size / erase_size;
184-
185-
if (number_of_sector < 2) {
185+
bd_size_t number_of_page = size / page_size;
186+
if (number_of_sector < TDBStore::STORE_SECTORS) {
186187
tr_warning("KV Config: There are less than two sectors - TDBStore will not work.");
187188
return -1;
188189
}
189190

191+
if (number_of_page < TDBStore::STORE_PAGES) {
192+
tr_warning("KV Config: There are less than ten pages sectors - TDBStore will not work.");
193+
return -1;
194+
}
195+
190196

191197
if (number_of_sector % 2 != 0) {
192198
tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size");
@@ -586,9 +592,9 @@ int _create_internal_tdb(BlockDevice **internal_bd, KVStore **internal_tdb, bd_s
586592
return MBED_ERROR_FAILED_OPERATION ;
587593
}
588594

589-
//Check if TDBStore has at least 2 sector.
595+
//Check if TDBStore has at least 2 sectors or 10 pages.
590596
if (_calculate_blocksize_match_tdbstore(*internal_bd) != MBED_SUCCESS) {
591-
tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
597+
tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
592598
return MBED_ERROR_INVALID_ARGUMENT;
593599
}
594600

@@ -754,9 +760,9 @@ int _storage_config_tdb_external_common()
754760
return MBED_ERROR_FAILED_OPERATION ;
755761
}
756762

757-
//Check that there is at least 2 sector for the external TDBStore
763+
//Check that there is at least 2 sectors for the external TDBStore
758764
if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) {
759-
tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
765+
tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
760766
return MBED_ERROR_INVALID_SIZE;
761767
}
762768

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,6 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14381438
return MBED_ERROR_INITIALIZATION_FAILED;
14391439
}
14401440

1441-
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
1442-
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
1443-
static const int STORE_SECTORS = 2;
1444-
static const int STORE_PAGES = 10;
1445-
14461441
// Let's work from end of the flash backwards
14471442
bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size();
14481443
bd_size_t sector_space = 0;

features/storage/kvstore/tdbstore/TDBStore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class TDBStore : public KVStore {
3737

3838
static const uint32_t RESERVED_AREA_SIZE = 64;
3939

40+
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
41+
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
42+
/** Minimum number of internal flash sectors required for TDBStore */
43+
static const int STORE_SECTORS = 2;
44+
/** Minimum number of internal flash pages required for TDBStore */
45+
static const int STORE_PAGES = 10;
46+
4047
/**
4148
* @brief Class constructor
4249
*

0 commit comments

Comments
 (0)