@@ -78,13 +78,24 @@ static inline uint32_t align_up(uint32_t val, uint32_t size)
7878// init the blockdevice
7979static void kvstore_init ()
8080{
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+
8187 int res;
8288 size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
8389 BlockDevice *sec_bd;
8490
8591 res = bd->init ();
8692 TEST_ASSERT_EQUAL_ERROR_CODE (0 , res);
8793 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);
8899 res = bd->deinit ();
89100 TEST_ASSERT_EQUAL_ERROR_CODE (0 , res);
90101
@@ -121,8 +132,8 @@ static void kvstore_init()
121132 erase_size = sec_bd->get_erase_size ();
122133 // We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
123134 // 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 );
126137
127138 res = sec_bd->deinit ();
128139 TEST_ASSERT_EQUAL_ERROR_CODE (MBED_SUCCESS, res);
0 commit comments