16
16
*/
17
17
18
18
#include < algorithm>
19
- #include < cstdint>
20
- #include < cstdlib>
21
- #include < cstring>
19
+ #include < memory>
20
+ #include < stdint.h>
21
+ #include < stdlib.h>
22
+ #include < string.h>
23
+
24
+ #include " platform/mbed_error.h"
22
25
#include " drivers/internal/SFDP.h"
23
26
24
27
#if (DEVICE_SPI || DEVICE_QSPI)
@@ -179,14 +182,6 @@ int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
179
182
180
183
int sfdp_parse_sector_map_table (Callback<int (bd_addr_t , void *, bd_size_t )> sfdp_reader, sfdp_hdr_info &sfdp_info)
181
184
{
182
- /* The number of
183
- * - sector map configuration detection commands
184
- * - configurations
185
- * - regions in each configuration
186
- * is variable -> the size of this table is variable
187
- */
188
- uint8_t *smptbl_buff;
189
- int status = 0 ;
190
185
uint32_t tmp_region_size = 0 ;
191
186
uint8_t type_mask;
192
187
int prev_boundary = 0 ;
@@ -199,37 +194,41 @@ int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp
199
194
200
195
if (!sfdp_info.smptbl .addr || !sfdp_info.smptbl .size ) {
201
196
tr_debug (" No Sector Map Table" );
202
- return 0 ;
197
+ return MBED_SUCCESS ;
203
198
}
204
199
205
- smptbl_buff = (uint8_t *)malloc (sfdp_info.smptbl .size );
200
+ /* The number of
201
+ * - sector map configuration detection commands
202
+ * - configurations
203
+ * - regions in each configuration
204
+ * is variable -> the size of this table is variable
205
+ */
206
+ auto smptbl_buff = std::make_unique<uint8_t []>(sfdp_info.smptbl .size );
206
207
if (!smptbl_buff) {
207
208
tr_error (" Failed to allocate memory" );
208
209
return -1 ;
209
210
}
210
211
211
212
tr_debug (" Parsing Sector Map Table - addr: 0x%" PRIx32 " , Size: %d" , sfdp_info.smptbl .addr , sfdp_info.smptbl .size );
212
213
213
- status = sfdp_reader (sfdp_info.smptbl .addr , smptbl_buff, sfdp_info.smptbl .size );
214
+ int status = sfdp_reader (sfdp_info.smptbl .addr , smptbl_buff. get () , sfdp_info.smptbl .size );
214
215
if (status < 0 ) {
215
216
tr_error (" Sector Map: Table retrieval failed" );
216
- goto EXIT ;
217
+ return - 1 ;
217
218
}
218
219
219
220
// Currently we support only Single Map Descriptor
220
221
if (!((smptbl_buff[0 ] & 0x3 ) == 0x03 ) && (smptbl_buff[1 ] == 0x0 )) {
221
222
tr_error (" Sector Map: Supporting Only Single Map Descriptor (not map commands)" );
222
- status = -1 ;
223
- goto EXIT;
223
+ return -1 ;
224
224
}
225
225
226
226
sfdp_info.smptbl .region_cnt = smptbl_buff[2 ] + 1 ;
227
227
if (sfdp_info.smptbl .region_cnt > SFDP_SECTOR_MAP_MAX_REGIONS) {
228
228
tr_error (" Sector Map: Supporting up to %d regions, current setup to %d regions - fail" ,
229
229
SFDP_SECTOR_MAP_MAX_REGIONS,
230
230
sfdp_info.smptbl .region_cnt );
231
- status = -1 ;
232
- goto EXIT;
231
+ return -1 ;
233
232
}
234
233
235
234
// Loop through Regions and set for each one: size, supported erase types, high boundary offset
@@ -259,10 +258,7 @@ int sfdp_parse_sector_map_table(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp
259
258
type_mask = type_mask << 1 ;
260
259
}
261
260
262
- EXIT:
263
- free (smptbl_buff);
264
-
265
- return status;
261
+ return 0 ;
266
262
}
267
263
268
264
size_t sfdp_detect_page_size (uint8_t *basic_param_table_ptr, size_t basic_param_table_size)
0 commit comments