Skip to content

Commit 879d234

Browse files
offirkoadbridge
authored andcommitted
Updated test to consider tdb_internal non default configuration as well
1 parent 7136c78 commit 879d234

File tree

1 file changed

+29
-12
lines changed
  • features/storage/TESTS/kvstore/direct_access_devicekey_test

1 file changed

+29
-12
lines changed

features/storage/TESTS/kvstore/direct_access_devicekey_test/main.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline uint32_t align_down(uint64_t val, uint64_t size)
5454
int get_virtual_TDBStore_position(uint32_t conf_start_address, uint32_t conf_size, bool is_conf_tdb_internal,
5555
uint32_t *tdb_start_address, uint32_t *tdb_end_address)
5656
{
57-
uint32_t bd_final_size;
57+
uint32_t bd_final_size = conf_size;;
5858
uint32_t flash_end_address;
5959
uint32_t flash_start_address;
6060
uint32_t aligned_start_address;
@@ -78,25 +78,42 @@ int get_virtual_TDBStore_position(uint32_t conf_start_address, uint32_t conf_si
7878
}
7979

8080
if (!request_default) {
81+
if (conf_start_address == 0) {
82+
conf_start_address = flash_end_address - conf_size;
83+
}
8184
aligned_start_address = align_down(conf_start_address, flash.get_sector_size(conf_start_address));
82-
if (aligned_start_address < flash_first_writable_sector_address) {
83-
aligned_start_address = flash_first_writable_sector_address;
85+
if (conf_size == 0) {
86+
bd_final_size = (flash_end_address - aligned_start_address);
8487
}
85-
bd_final_size = (flash_end_address - aligned_start_address);
86-
if (bd_final_size < 2 * 4096) {
87-
flash.deinit();
88-
return -2;
88+
89+
if ((conf_size == 0) || (conf_start_address == 0)) {
90+
if (aligned_start_address < flash_first_writable_sector_address) {
91+
flash.deinit();
92+
return -2;
93+
}
8994
}
9095
} else {
9196
if (is_conf_tdb_internal == true) {
9297
aligned_start_address = flash_first_writable_sector_address;
93-
bd_final_size = (flash_end_address - aligned_start_address);
94-
if (bd_final_size < 2 * 4096) {
95-
flash.deinit();
96-
return -2;
98+
bd_size_t spare_size_for_app = 0;
99+
bd_addr_t curr_addr = aligned_start_address;
100+
int spare_sectors_for_app = 2;
101+
int min_sectors_for_storage = 2;
102+
for (int i = 0; i < spare_sectors_for_app + min_sectors_for_storage - 1; i++) {
103+
bd_size_t sector_size = flash.get_sector_size(curr_addr);
104+
curr_addr += sector_size;
105+
if (curr_addr >= flash_end_address) {
106+
spare_size_for_app = 0;
107+
break;
108+
}
109+
110+
if (i < spare_sectors_for_app) {
111+
spare_size_for_app += sector_size;
112+
}
97113
}
114+
aligned_start_address += spare_size_for_app;
115+
bd_final_size = (flash_end_address - aligned_start_address);
98116
} else {
99-
//update start_address to double the size for TDBStore needs
100117
aligned_start_address = flash_end_address - (flash.get_sector_size(flash_end_address - 1) * 2);
101118
if (aligned_start_address < flash_first_writable_sector_address) {
102119
flash.deinit();

0 commit comments

Comments
 (0)