Skip to content

Commit 9d41431

Browse files
author
Kyle Kearney
committed
TDBStore: Fix potential alignment issue in default addresses
When 10 pages is larger than 2 sectors, align the selected size down to be an even multiple of the sector size, to ensure that the allocated space divides cleanly in half for garbage collection.
1 parent 7cd4d11 commit 9d41431

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,8 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14391439
}
14401440

14411441
// Let's work from end of the flash backwards
1442-
bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size();
1442+
bd_addr_t end_of_flash = flash.get_flash_start() + flash.get_flash_size();
1443+
bd_addr_t curr_addr = end_of_flash;
14431444
bd_size_t sector_space = 0;
14441445

14451446
for (int i = STORE_SECTORS; i; i--) {
@@ -1453,7 +1454,9 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14531454
*size = sector_space;
14541455
} else {
14551456
curr_addr -= page_space;
1456-
*size = page_space;
1457+
// Align to 2 sector boundary so that garbage collection works properly
1458+
curr_addr = align_down(curr_addr, 2 * flash.get_sector_size(curr_addr));
1459+
*size = end_of_flash - curr_addr;
14571460
}
14581461

14591462
// Store- and application-sectors mustn't overlap

0 commit comments

Comments
 (0)