@@ -78,13 +78,24 @@ static inline uint32_t align_up(uint32_t val, uint32_t size)
78
78
// init the blockdevice
79
79
static void kvstore_init ()
80
80
{
81
+ // This directly corresponds to the pages allocated for each of the SecureStore block devices
82
+ // For the others it may not match exactly to the space that is used, but it is expected to
83
+ // be a close enough approximation to act as a guideline for how much of the block device we
84
+ // need to erase in order to ensure a stable initial condition.
85
+ const size_t PAGES_ESTIMATE = 40 ;
86
+
81
87
int res;
82
88
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
83
89
BlockDevice *sec_bd;
84
90
85
91
res = bd->init ();
86
92
TEST_ASSERT_EQUAL_ERROR_CODE (0 , res);
87
93
int erase_val = bd->get_erase_value ();
94
+ // Clear out any stale data that might be left from a previous test
95
+ // Multiply by 2 because SecureStore requires two underlying block devices of this size
96
+ size_t bytes_to_erase = align_up (2 * PAGES_ESTIMATE * bd->get_program_size (), bd->get_erase_size ());
97
+
98
+ bd->erase (0 , bytes_to_erase);
88
99
res = bd->deinit ();
89
100
TEST_ASSERT_EQUAL_ERROR_CODE (0 , res);
90
101
@@ -121,8 +132,8 @@ static void kvstore_init()
121
132
erase_size = sec_bd->get_erase_size ();
122
133
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
123
134
// but minimum of 2 erase sectors, so that the garbage collection way work
124
- ul_bd_size = align_up (program_size * 40 , erase_size * 2 );
125
- rbp_bd_size = align_up (program_size * 40 , erase_size * 2 );
135
+ ul_bd_size = align_up (program_size * PAGES_ESTIMATE , erase_size * 2 );
136
+ rbp_bd_size = align_up (program_size * PAGES_ESTIMATE , erase_size * 2 );
126
137
127
138
res = sec_bd->deinit ();
128
139
TEST_ASSERT_EQUAL_ERROR_CODE (MBED_SUCCESS, res);
0 commit comments