Skip to content

Commit f40f4ba

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 ece58b7 commit f40f4ba

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
@@ -1464,7 +1464,8 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14641464
}
14651465

14661466
// Let's work from end of the flash backwards
1467-
bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size();
1467+
bd_addr_t end_of_flash = flash.get_flash_start() + flash.get_flash_size();
1468+
bd_addr_t curr_addr = end_of_flash;
14681469
bd_size_t sector_space = 0;
14691470

14701471
for (int i = STORE_SECTORS; i; i--) {
@@ -1478,7 +1479,9 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14781479
*size = sector_space;
14791480
} else {
14801481
curr_addr -= page_space;
1481-
*size = page_space;
1482+
// Align to 2 sector boundary so that garbage collection works properly
1483+
curr_addr = align_down(curr_addr, 2 * flash.get_sector_size(curr_addr));
1484+
*size = end_of_flash - curr_addr;
14821485
}
14831486

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

0 commit comments

Comments
 (0)