22
22
#include " mbed_error.h"
23
23
#include " MbedCRC.h"
24
24
#include " mbed_trace.h"
25
+ #include " TDBStore.h"
25
26
#define TRACE_GROUP " DADK"
26
27
27
28
using namespace mbed ;
@@ -81,7 +82,7 @@ int direct_access_to_devicekey(uint32_t tdb_start_offset, uint32_t tdb_end_offse
81
82
82
83
status = calc_area_params (&flash, tdb_start_offset, tdb_end_offset, area_params);
83
84
if (status != MBED_SUCCESS) {
84
- tr_error (" Couldn't calulate Area Params - err: %d" , status);
85
+ tr_error (" Couldn't calculate Area Params - err: %d" , status);
85
86
goto exit_point;
86
87
}
87
88
@@ -107,37 +108,33 @@ int direct_access_to_devicekey(uint32_t tdb_start_offset, uint32_t tdb_end_offse
107
108
return status;
108
109
}
109
110
110
- int get_expected_internal_TDBStore_position (uint32_t *out_tdb_start_offset, uint32_t *out_tdb_end_offset)
111
+ int get_expected_internal_TDBStore_position (uint32_t *out_tdb_start_offset, uint32_t *out_tdb_end_offset)
111
112
{
112
- uint32_t flash_end_address;
113
- uint32_t flash_start_address;
114
- uint32_t aligned_start_address;
115
- uint32_t aligned_end_address;
113
+ bd_addr_t tdb_start_address;
114
+ bd_size_t tdb_size;
116
115
FlashIAP flash;
117
- bool is_default_configuration = false ;
118
- uint32_t tdb_size;
119
116
120
117
if (strcmp (STR (MBED_CONF_STORAGE_STORAGE_TYPE), " FILESYSTEM" ) == 0 ) {
121
118
#ifndef MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS
122
119
return MBED_ERROR_ITEM_NOT_FOUND;
123
120
#else
124
- *out_tdb_start_offset = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS;
121
+ tdb_start_address = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS;
125
122
tdb_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE;
126
123
#endif
127
124
128
125
} else if (strcmp (STR (MBED_CONF_STORAGE_STORAGE_TYPE), " TDB_EXTERNAL" ) == 0 ) {
129
126
#ifndef MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS
130
127
return MBED_ERROR_ITEM_NOT_FOUND;
131
128
#else
132
- *out_tdb_start_offset = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
129
+ tdb_start_address = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
133
130
tdb_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE;
134
131
#endif
135
132
136
133
} else if (strcmp (STR (MBED_CONF_STORAGE_STORAGE_TYPE), " TDB_INTERNAL" ) == 0 ) {
137
134
#ifndef MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS
138
135
return MBED_ERROR_ITEM_NOT_FOUND;
139
136
#else
140
- *out_tdb_start_offset = MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS;
137
+ tdb_start_address = MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS;
141
138
tdb_size = MBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE;
142
139
#endif
143
140
@@ -146,7 +143,7 @@ int get_expected_internal_TDBStore_position(uint32_t *out_tdb_start_offset, uin
146
143
return MBED_ERROR_ITEM_NOT_FOUND;
147
144
#else
148
145
#if COMPONENT_QSPIF || COMPONENT_SPIF || COMPONENT_DATAFLASH
149
- *out_tdb_start_offset = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
146
+ tdb_start_address = MBED_CONF_STORAGE_TDB_EXTERNAL_INTERNAL_BASE_ADDRESS;
150
147
tdb_size = MBED_CONF_STORAGE_TDB_EXTERNAL_RBP_INTERNAL_SIZE;
151
148
#elif COMPONENT_SD
152
149
tdb_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE;
@@ -158,45 +155,21 @@ int get_expected_internal_TDBStore_position(uint32_t *out_tdb_start_offset, uin
158
155
return MBED_ERROR_UNSUPPORTED;
159
156
}
160
157
161
- *out_tdb_end_offset = (*out_tdb_start_offset) + tdb_size ;
162
-
163
- if ((*out_tdb_start_offset == 0 ) && (tdb_size == 0 )) {
164
- is_default_configuration = true ;
165
- } else if ((*out_tdb_start_offset == 0 ) || (tdb_size == 0 )) {
166
- return MBED_ERROR_UNSUPPORTED;
158
+ int ret ;
159
+ if ((tdb_start_address == 0 ) && (tdb_size == 0 )) {
160
+ ret = TDBStore::get_default_flash_addresses (&tdb_start_address, &tdb_size);
161
+ if (ret != MBED_SUCCESS) {
162
+ return MBED_ERROR_FAILED_OPERATION;
163
+ }
167
164
}
168
165
169
- int ret = flash. init ( );
170
- if (ret != 0 ) {
166
+ ret = TDBStore::get_flash_bounds_from_config (&tdb_start_address, &tdb_size );
167
+ if (ret != MBED_SUCCESS ) {
171
168
return MBED_ERROR_FAILED_OPERATION;
172
169
}
173
170
174
- uint32_t flash_first_writable_sector_address = (uint32_t )(align_up (FLASHIAP_APP_ROM_END_ADDR,
175
- flash.get_sector_size (FLASHIAP_APP_ROM_END_ADDR)));
176
-
177
- // Get flash parameters before starting
178
- flash_start_address = flash.get_flash_start ();
179
- flash_end_address = flash_start_address + flash.get_flash_size ();
180
-
181
- if (!is_default_configuration) {
182
- aligned_start_address = align_down (*out_tdb_start_offset, flash.get_sector_size (*out_tdb_start_offset));
183
- aligned_end_address = align_up (*out_tdb_end_offset, flash.get_sector_size (*out_tdb_end_offset - 1 ));
184
- if ((*out_tdb_start_offset != aligned_start_address) || (*out_tdb_end_offset != aligned_end_address)
185
- || (*out_tdb_end_offset > flash_end_address)) {
186
- flash.deinit ();
187
- return MBED_ERROR_INVALID_OPERATION;
188
- }
189
- } else {
190
- aligned_start_address = flash_end_address - (flash.get_sector_size (flash_end_address - 1 ) * 2 );
191
- if (aligned_start_address < flash_first_writable_sector_address) {
192
- flash.deinit ();
193
- return MBED_ERROR_INVALID_OPERATION;
194
- }
195
- *out_tdb_start_offset = aligned_start_address;
196
- *out_tdb_end_offset = flash_end_address;
197
- }
198
-
199
- flash.deinit ();
171
+ *out_tdb_start_offset = tdb_start_address;
172
+ *out_tdb_end_offset = tdb_start_address + tdb_size;
200
173
201
174
return MBED_SUCCESS;
202
175
}
0 commit comments