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