@@ -266,140 +266,10 @@ FileSystem *_get_filesystem_default(const char *mount)
266
266
#endif
267
267
}
268
268
269
- int get_default_flash_addresses (bd_addr_t *start_address, bd_size_t *size)
270
- {
271
- int ret = MBED_SUCCESS;
272
-
273
- #if COMPONENT_FLASHIAP
274
- FlashIAP flash;
275
- if (flash.init () != 0 ) {
276
- return MBED_ERROR_INITIALIZATION_FAILED;
277
- }
278
-
279
- // Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
280
- // For each area: must be a minimum of 1 page of reserved and 2 pages for master record
281
- static const int STORE_SECTORS = 2 ;
282
- static const int STORE_PAGES = 10 ;
283
-
284
- // Let's work from end of the flash backwards
285
- bd_addr_t curr_addr = flash.get_flash_start () + flash.get_flash_size ();
286
- bd_size_t sector_space = 0 ;
287
-
288
- for (int i = STORE_SECTORS; i; i--) {
289
- bd_size_t sector_size = flash.get_sector_size (curr_addr - 1 );
290
- sector_space += sector_size;
291
- }
292
-
293
- bd_size_t page_space = flash.get_page_size () * STORE_PAGES;
294
- if (sector_space > page_space) {
295
- curr_addr -= sector_space;
296
- *size = sector_space;
297
- } else {
298
- curr_addr -= page_space;
299
- *size = page_space;
300
- }
301
-
302
- // Store- and application-sectors mustn't overlap
303
- uint32_t first_wrtbl_sector_addr =
304
- (uint32_t )(align_up (FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size (FLASHIAP_APP_ROM_END_ADDR)));
305
-
306
- MBED_ASSERT (curr_addr >= first_wrtbl_sector_addr);
307
- if (curr_addr < first_wrtbl_sector_addr) {
308
- ret = MBED_ERROR_MEDIA_FULL;
309
- } else {
310
- *start_address = curr_addr;
311
- }
312
-
313
- flash.deinit ();
314
- #endif
315
-
316
- return ret;
317
- }
318
-
319
- int get_flash_bounds_from_config (bd_addr_t *start_address, bd_size_t *size)
320
- {
321
- #if COMPONENT_FLASHIAP
322
-
323
- bd_addr_t flash_end_address;
324
- bd_addr_t flash_start_address;
325
- bd_addr_t flash_first_writable_sector_address;
326
- bd_addr_t aligned_start_address;
327
- bd_addr_t aligned_end_address;
328
- bd_addr_t end_address;
329
- FlashIAP flash;
330
-
331
- if (!start_address || !size) {
332
- return MBED_ERROR_INVALID_ARGUMENT;
333
- }
334
-
335
- int ret = flash.init ();
336
- if (ret != 0 ) {
337
- return MBED_ERROR_INITIALIZATION_FAILED;
338
- }
339
-
340
- // Get flash parameters
341
- flash_first_writable_sector_address = align_up (FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size (FLASHIAP_APP_ROM_END_ADDR));
342
- flash_start_address = flash.get_flash_start ();
343
- flash_end_address = flash_start_address + flash.get_flash_size ();
344
-
345
- if (*start_address == 0 ) {
346
- if (*size == 0 ) {
347
- flash.deinit ();
348
- return MBED_ERROR_INVALID_ARGUMENT;
349
- }
350
-
351
- *start_address = flash_end_address - *size;
352
- aligned_start_address = align_down (*start_address, flash.get_sector_size (*start_address));
353
- if (*start_address != aligned_start_address) {
354
- // Start address not aligned - size should likely be changed so that it is
355
- flash.deinit ();
356
- return MBED_ERROR_INVALID_SIZE;
357
- }
358
- } else {
359
- aligned_start_address = align_down (*start_address, flash.get_sector_size (*start_address));
360
- if (*start_address != aligned_start_address) {
361
- // Start address not aligned - size should likely be changed so that it is
362
- flash.deinit ();
363
- return MBED_ERROR_INVALID_SIZE;
364
- }
365
-
366
- if (*size == 0 ) {
367
- // The block device will have all space from start address to the end of the flash
368
- *size = (flash_end_address - *start_address);
369
- } else {
370
- // Do checks on end address to make sure configured start address/size are good
371
-
372
- end_address = *start_address + *size;
373
- if (end_address > flash_end_address) {
374
- // End address is out of flash bounds
375
- flash.deinit ();
376
- return MBED_ERROR_INVALID_SIZE;
377
- }
378
-
379
- aligned_end_address = align_up (end_address, flash.get_sector_size (end_address - 1 ));
380
- if (end_address != aligned_end_address) {
381
- // End address not aligned - size should likely be changed so that it is
382
- flash.deinit ();
383
- return MBED_ERROR_INVALID_SIZE;
384
- }
385
- }
386
- }
387
-
388
- flash.deinit ();
389
-
390
- if (*start_address < flash_first_writable_sector_address) {
391
- // Calculated start address overlaps with ROM
392
- return MBED_ERROR_MEDIA_FULL;
393
- }
394
- #endif
395
-
396
- return MBED_SUCCESS;
397
- }
398
-
399
269
BlockDevice *_get_blockdevice_FLASHIAP (bd_addr_t &start_address, bd_size_t &size)
400
270
{
401
271
#if COMPONENT_FLASHIAP
402
- int ret = get_flash_bounds_from_config (&start_address, &size);
272
+ int ret = TDBStore:: get_flash_bounds_from_config (&start_address, &size);
403
273
if (ret != 0 ) {
404
274
tr_error (" KV Config: Determination of internal block device bounds failed. The configured start address/size is likely invalid." );
405
275
return NULL ;
@@ -678,13 +548,14 @@ MBED_WEAK BlockDevice *get_other_blockdevice()
678
548
return NULL ;
679
549
}
680
550
681
- int _create_internal_tdb (BlockDevice **internal_bd, KVStore **internal_tdb, bd_size_t *size, bd_addr_t *start_address) {
551
+ int _create_internal_tdb (BlockDevice **internal_bd, KVStore **internal_tdb, bd_size_t *size, bd_addr_t *start_address)
552
+ {
682
553
int ret;
683
554
684
555
// Get the default address and size for the TDBStore
685
556
if (*size == 0 && *start_address == 0 ) {
686
557
// Calculate the block device size and start address in case default values are used.
687
- ret = get_default_flash_addresses (start_address, size);
558
+ ret = TDBStore:: get_default_flash_addresses (start_address, size);
688
559
if (ret != MBED_SUCCESS) {
689
560
return MBED_ERROR_FAILED_OPERATION;
690
561
}
0 commit comments