diff options
Diffstat (limited to 'firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c')
-rw-r--r-- | firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c index 65a282fe37..69fac62289 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c | |||
@@ -178,7 +178,7 @@ struct ftl_cxt_type | |||
178 | /* Seems to be unused, but gets loaded from flash by Whimory. */ | 178 | /* Seems to be unused, but gets loaded from flash by Whimory. */ |
179 | uint8_t field_130[0x15C]; | 179 | uint8_t field_130[0x15C]; |
180 | 180 | ||
181 | } __attribute__((packed)) FTLCxtType; | 181 | } __attribute__((packed)); |
182 | 182 | ||
183 | 183 | ||
184 | /* Keeps the state of the bank's VFL, both on flash and in memory. | 184 | /* Keeps the state of the bank's VFL, both on flash and in memory. |
@@ -363,54 +363,54 @@ const struct nand_device_info_type* ftl_nand_type; | |||
363 | uint32_t ftl_banks; | 363 | uint32_t ftl_banks; |
364 | 364 | ||
365 | /* Block map, used vor pBlock to vBlock mapping */ | 365 | /* Block map, used vor pBlock to vBlock mapping */ |
366 | uint16_t ftl_map[0x2000]; | 366 | static uint16_t ftl_map[0x2000]; |
367 | 367 | ||
368 | /* VFL context for each bank */ | 368 | /* VFL context for each bank */ |
369 | struct ftl_vfl_cxt_type ftl_vfl_cxt[4]; | 369 | static struct ftl_vfl_cxt_type ftl_vfl_cxt[4]; |
370 | 370 | ||
371 | /* FTL context */ | 371 | /* FTL context */ |
372 | struct ftl_cxt_type ftl_cxt; | 372 | static struct ftl_cxt_type ftl_cxt; |
373 | 373 | ||
374 | /* Temporary data buffers for internal use by the FTL */ | 374 | /* Temporary data buffers for internal use by the FTL */ |
375 | uint8_t ftl_buffer[0x800] STORAGE_ALIGN_ATTR; | 375 | static uint8_t ftl_buffer[0x800] STORAGE_ALIGN_ATTR; |
376 | 376 | ||
377 | /* Temporary spare byte buffer for internal use by the FTL */ | 377 | /* Temporary spare byte buffer for internal use by the FTL */ |
378 | union ftl_spare_data_type ftl_sparebuffer[FTL_WRITESPARE_SIZE] STORAGE_ALIGN_ATTR; | 378 | static union ftl_spare_data_type ftl_sparebuffer[FTL_WRITESPARE_SIZE] STORAGE_ALIGN_ATTR; |
379 | 379 | ||
380 | 380 | ||
381 | #ifndef FTL_READONLY | 381 | #ifndef FTL_READONLY |
382 | 382 | ||
383 | /* Lowlevel BBT for each bank */ | 383 | /* Lowlevel BBT for each bank */ |
384 | uint8_t ftl_bbt[4][0x410]; | 384 | static uint8_t ftl_bbt[4][0x410]; |
385 | 385 | ||
386 | /* Erase counters for the vBlocks */ | 386 | /* Erase counters for the vBlocks */ |
387 | uint16_t ftl_erasectr[0x2000]; | 387 | static uint16_t ftl_erasectr[0x2000]; |
388 | 388 | ||
389 | /* Used by ftl_log */ | 389 | /* Used by ftl_log */ |
390 | uint16_t ftl_offsets[0x11][0x200]; | 390 | static uint16_t ftl_offsets[0x11][0x200]; |
391 | 391 | ||
392 | /* Structs keeping record of scattered page blocks */ | 392 | /* Structs keeping record of scattered page blocks */ |
393 | struct ftl_log_type ftl_log[0x11]; | 393 | static struct ftl_log_type ftl_log[0x11]; |
394 | 394 | ||
395 | /* Global cross-bank update sequence number of the VFL context */ | 395 | /* Global cross-bank update sequence number of the VFL context */ |
396 | uint32_t ftl_vfl_usn; | 396 | static uint32_t ftl_vfl_usn; |
397 | 397 | ||
398 | /* Keeps track (temporarily) of troublesome blocks */ | 398 | /* Keeps track (temporarily) of troublesome blocks */ |
399 | struct ftl_trouble_type ftl_troublelog[5]; | 399 | static struct ftl_trouble_type ftl_troublelog[5]; |
400 | 400 | ||
401 | /* Counts erase counter page changes, after 100 of them the affected | 401 | /* Counts erase counter page changes, after 100 of them the affected |
402 | page will be committed to the flash. */ | 402 | page will be committed to the flash. */ |
403 | uint8_t ftl_erasectr_dirt[8]; | 403 | static uint8_t ftl_erasectr_dirt[8]; |
404 | 404 | ||
405 | /* Buffer needed for copying pages around while moving or committing blocks. | 405 | /* Buffer needed for copying pages around while moving or committing blocks. |
406 | This can't be shared with ftl_buffer, because this one could be overwritten | 406 | This can't be shared with ftl_buffer, because this one could be overwritten |
407 | during the copying operation in order to e.g. commit a CXT. */ | 407 | during the copying operation in order to e.g. commit a CXT. */ |
408 | uint8_t ftl_copybuffer[FTL_COPYBUF_SIZE][0x800] STORAGE_ALIGN_ATTR; | 408 | static uint8_t ftl_copybuffer[FTL_COPYBUF_SIZE][0x800] STORAGE_ALIGN_ATTR; |
409 | union ftl_spare_data_type ftl_copyspare[FTL_COPYBUF_SIZE] STORAGE_ALIGN_ATTR; | 409 | static union ftl_spare_data_type ftl_copyspare[FTL_COPYBUF_SIZE] STORAGE_ALIGN_ATTR; |
410 | 410 | ||
411 | /* Needed to store the old scattered page offsets in order to be able to roll | 411 | /* Needed to store the old scattered page offsets in order to be able to roll |
412 | back if something fails while compacting a scattered page block. */ | 412 | back if something fails while compacting a scattered page block. */ |
413 | uint16_t ftl_offsets_backup[0x200] STORAGE_ALIGN_ATTR; | 413 | static uint16_t ftl_offsets_backup[0x200] STORAGE_ALIGN_ATTR; |
414 | 414 | ||
415 | #endif | 415 | #endif |
416 | 416 | ||
@@ -421,7 +421,7 @@ static struct mutex ftl_mtx; | |||
421 | 421 | ||
422 | /* Finds a device info page for the specified bank and returns its number. | 422 | /* Finds a device info page for the specified bank and returns its number. |
423 | Used to check if one is present, and to read the lowlevel BBT. */ | 423 | Used to check if one is present, and to read the lowlevel BBT. */ |
424 | uint32_t ftl_find_devinfo(uint32_t bank) | 424 | static uint32_t ftl_find_devinfo(uint32_t bank) |
425 | { | 425 | { |
426 | /* Scan the last 10% of the flash for device info pages */ | 426 | /* Scan the last 10% of the flash for device info pages */ |
427 | uint32_t lowestBlock = ftl_nand_type->blocks | 427 | uint32_t lowestBlock = ftl_nand_type->blocks |
@@ -445,7 +445,7 @@ uint32_t ftl_find_devinfo(uint32_t bank) | |||
445 | 445 | ||
446 | 446 | ||
447 | /* Checks if all banks have proper device info pages */ | 447 | /* Checks if all banks have proper device info pages */ |
448 | uint32_t ftl_has_devinfo(void) | 448 | static uint32_t ftl_has_devinfo(void) |
449 | { | 449 | { |
450 | uint32_t i; | 450 | uint32_t i; |
451 | for (i = 0; i < ftl_banks; i++) if (ftl_find_devinfo(i) == 0) return 0; | 451 | for (i = 0; i < ftl_banks; i++) if (ftl_find_devinfo(i) == 0) return 0; |
@@ -455,7 +455,7 @@ uint32_t ftl_has_devinfo(void) | |||
455 | 455 | ||
456 | /* Loads the lowlevel BBT for a bank to the specified buffer. | 456 | /* Loads the lowlevel BBT for a bank to the specified buffer. |
457 | This is based on some cryptic disassembly and not fully understood yet. */ | 457 | This is based on some cryptic disassembly and not fully understood yet. */ |
458 | uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt) | 458 | static uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt) |
459 | { | 459 | { |
460 | uint32_t i, j; | 460 | uint32_t i, j; |
461 | uint32_t pagebase, page = ftl_find_devinfo(bank), page2; | 461 | uint32_t pagebase, page = ftl_find_devinfo(bank), page2; |
@@ -489,8 +489,8 @@ uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt) | |||
489 | 489 | ||
490 | 490 | ||
491 | /* Calculates the checksums for the VFL context page of the specified bank */ | 491 | /* Calculates the checksums for the VFL context page of the specified bank */ |
492 | void ftl_vfl_calculate_checksum(uint32_t bank, | 492 | static void ftl_vfl_calculate_checksum(uint32_t bank, |
493 | uint32_t* checksum1, uint32_t* checksum2) | 493 | uint32_t* checksum1, uint32_t* checksum2) |
494 | { | 494 | { |
495 | uint32_t i; | 495 | uint32_t i; |
496 | *checksum1 = 0xAABBCCDD; | 496 | *checksum1 = 0xAABBCCDD; |
@@ -505,7 +505,7 @@ void ftl_vfl_calculate_checksum(uint32_t bank, | |||
505 | 505 | ||
506 | /* Checks if the checksums of the VFL context | 506 | /* Checks if the checksums of the VFL context |
507 | of the specified bank are correct */ | 507 | of the specified bank are correct */ |
508 | uint32_t ftl_vfl_verify_checksum(uint32_t bank) | 508 | static uint32_t ftl_vfl_verify_checksum(uint32_t bank) |
509 | { | 509 | { |
510 | uint32_t checksum1, checksum2; | 510 | uint32_t checksum1, checksum2; |
511 | ftl_vfl_calculate_checksum(bank, &checksum1, &checksum2); | 511 | ftl_vfl_calculate_checksum(bank, &checksum1, &checksum2); |
@@ -520,7 +520,7 @@ uint32_t ftl_vfl_verify_checksum(uint32_t bank) | |||
520 | 520 | ||
521 | #ifndef FTL_READONLY | 521 | #ifndef FTL_READONLY |
522 | /* Updates the checksums of the VFL context of the specified bank */ | 522 | /* Updates the checksums of the VFL context of the specified bank */ |
523 | void ftl_vfl_update_checksum(uint32_t bank) | 523 | static void ftl_vfl_update_checksum(uint32_t bank) |
524 | { | 524 | { |
525 | ftl_vfl_calculate_checksum(bank, &ftl_vfl_cxt[bank].checksum1, | 525 | ftl_vfl_calculate_checksum(bank, &ftl_vfl_cxt[bank].checksum1, |
526 | &ftl_vfl_cxt[bank].checksum2); | 526 | &ftl_vfl_cxt[bank].checksum2); |
@@ -531,7 +531,7 @@ void ftl_vfl_update_checksum(uint32_t bank) | |||
531 | #ifndef FTL_READONLY | 531 | #ifndef FTL_READONLY |
532 | /* Writes 8 copies of the VFL context of the specified bank to flash, | 532 | /* Writes 8 copies of the VFL context of the specified bank to flash, |
533 | and succeeds if at least 4 can be read back properly. */ | 533 | and succeeds if at least 4 can be read back properly. */ |
534 | uint32_t ftl_vfl_store_cxt(uint32_t bank) | 534 | static uint32_t ftl_vfl_store_cxt(uint32_t bank) |
535 | { | 535 | { |
536 | uint32_t i; | 536 | uint32_t i; |
537 | ftl_vfl_cxt[bank].updatecount--; | 537 | ftl_vfl_cxt[bank].updatecount--; |
@@ -575,7 +575,7 @@ uint32_t ftl_vfl_store_cxt(uint32_t bank) | |||
575 | #ifndef FTL_READONLY | 575 | #ifndef FTL_READONLY |
576 | /* Commits the VFL context of the specified bank to flash, | 576 | /* Commits the VFL context of the specified bank to flash, |
577 | retries until it works or all available pages have been tried */ | 577 | retries until it works or all available pages have been tried */ |
578 | uint32_t ftl_vfl_commit_cxt(uint32_t bank) | 578 | static uint32_t ftl_vfl_commit_cxt(uint32_t bank) |
579 | { | 579 | { |
580 | if (ftl_vfl_cxt[bank].nextcxtpage + 8 <= ftl_nand_type->pagesperblock) | 580 | if (ftl_vfl_cxt[bank].nextcxtpage + 8 <= ftl_nand_type->pagesperblock) |
581 | if (ftl_vfl_store_cxt(bank) == 0) return 0; | 581 | if (ftl_vfl_store_cxt(bank) == 0) return 0; |
@@ -604,7 +604,7 @@ uint32_t ftl_vfl_commit_cxt(uint32_t bank) | |||
604 | /* Returns a pointer to the most recently updated VFL context, | 604 | /* Returns a pointer to the most recently updated VFL context, |
605 | used to find out the current FTL context vBlock numbers | 605 | used to find out the current FTL context vBlock numbers |
606 | (planetbeing's "maxthing") */ | 606 | (planetbeing's "maxthing") */ |
607 | struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void) | 607 | static struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void) |
608 | { | 608 | { |
609 | uint32_t i, maxusn; | 609 | uint32_t i, maxusn; |
610 | struct ftl_vfl_cxt_type* cxt = (struct ftl_vfl_cxt_type*)0; | 610 | struct ftl_vfl_cxt_type* cxt = (struct ftl_vfl_cxt_type*)0; |
@@ -621,7 +621,7 @@ struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void) | |||
621 | 621 | ||
622 | /* Checks if the specified pBlock is marked bad in the supplied lowlevel BBT. | 622 | /* Checks if the specified pBlock is marked bad in the supplied lowlevel BBT. |
623 | Only used while mounting the VFL. */ | 623 | Only used while mounting the VFL. */ |
624 | uint32_t ftl_is_good_block(uint8_t* bbt, uint32_t block) | 624 | static uint32_t ftl_is_good_block(uint8_t* bbt, uint32_t block) |
625 | { | 625 | { |
626 | if ((bbt[block >> 3] & (1 << (block & 7))) == 0) return 0; | 626 | if ((bbt[block >> 3] & (1 << (block & 7))) == 0) return 0; |
627 | else return 1; | 627 | else return 1; |
@@ -629,7 +629,7 @@ uint32_t ftl_is_good_block(uint8_t* bbt, uint32_t block) | |||
629 | 629 | ||
630 | 630 | ||
631 | /* Checks if the specified vBlock could be remapped */ | 631 | /* Checks if the specified vBlock could be remapped */ |
632 | uint32_t ftl_vfl_is_good_block(uint32_t bank, uint32_t block) | 632 | static uint32_t ftl_vfl_is_good_block(uint32_t bank, uint32_t block) |
633 | { | 633 | { |
634 | uint8_t bbtentry = ftl_vfl_cxt[bank].bbt[block >> 6]; | 634 | uint8_t bbtentry = ftl_vfl_cxt[bank].bbt[block >> 6]; |
635 | if ((bbtentry & (1 << ((7 - (block >> 3)) & 7))) == 0) return 0; | 635 | if ((bbtentry & (1 << ((7 - (block >> 3)) & 7))) == 0) return 0; |
@@ -640,7 +640,7 @@ uint32_t ftl_vfl_is_good_block(uint32_t bank, uint32_t block) | |||
640 | #ifndef FTL_READONLY | 640 | #ifndef FTL_READONLY |
641 | /* Sets or unsets the bad bit of the specified vBlock | 641 | /* Sets or unsets the bad bit of the specified vBlock |
642 | in the specified bank's VFL context */ | 642 | in the specified bank's VFL context */ |
643 | void ftl_vfl_set_good_block(uint32_t bank, uint32_t block, uint32_t isgood) | 643 | static void ftl_vfl_set_good_block(uint32_t bank, uint32_t block, uint32_t isgood) |
644 | { | 644 | { |
645 | uint8_t bit = (1 << ((7 - (block >> 3)) & 7)); | 645 | uint8_t bit = (1 << ((7 - (block >> 3)) & 7)); |
646 | if (isgood == 1) ftl_vfl_cxt[bank].bbt[block >> 6] |= bit; | 646 | if (isgood == 1) ftl_vfl_cxt[bank].bbt[block >> 6] |= bit; |
@@ -650,9 +650,9 @@ void ftl_vfl_set_good_block(uint32_t bank, uint32_t block, uint32_t isgood) | |||
650 | 650 | ||
651 | 651 | ||
652 | /* Tries to read a VFL context from the specified bank, pBlock and page */ | 652 | /* Tries to read a VFL context from the specified bank, pBlock and page */ |
653 | uint32_t ftl_vfl_read_page(uint32_t bank, uint32_t block, | 653 | static uint32_t ftl_vfl_read_page(uint32_t bank, uint32_t block, |
654 | uint32_t startpage, void* databuffer, | 654 | uint32_t startpage, void* databuffer, |
655 | union ftl_spare_data_type* sparebuffer) | 655 | union ftl_spare_data_type* sparebuffer) |
656 | { | 656 | { |
657 | uint32_t i; | 657 | uint32_t i; |
658 | for (i = 0; i < 8; i++) | 658 | for (i = 0; i < 8; i++) |
@@ -670,7 +670,7 @@ uint32_t ftl_vfl_read_page(uint32_t bank, uint32_t block, | |||
670 | 670 | ||
671 | 671 | ||
672 | /* Translates a bank and vBlock to a pBlock, following remaps */ | 672 | /* Translates a bank and vBlock to a pBlock, following remaps */ |
673 | uint32_t ftl_vfl_get_physical_block(uint32_t bank, uint32_t block) | 673 | static uint32_t ftl_vfl_get_physical_block(uint32_t bank, uint32_t block) |
674 | { | 674 | { |
675 | if (ftl_vfl_is_good_block(bank, block) == 1) return block; | 675 | if (ftl_vfl_is_good_block(bank, block) == 1) return block; |
676 | 676 | ||
@@ -685,7 +685,7 @@ uint32_t ftl_vfl_get_physical_block(uint32_t bank, uint32_t block) | |||
685 | 685 | ||
686 | #ifndef FTL_READONLY | 686 | #ifndef FTL_READONLY |
687 | /* Checks if remapping is scheduled for the specified bank and vBlock */ | 687 | /* Checks if remapping is scheduled for the specified bank and vBlock */ |
688 | uint32_t ftl_vfl_check_remap_scheduled(uint32_t bank, uint32_t block) | 688 | static uint32_t ftl_vfl_check_remap_scheduled(uint32_t bank, uint32_t block) |
689 | { | 689 | { |
690 | uint32_t i; | 690 | uint32_t i; |
691 | for (i = 0x333; i > 0 && i > ftl_vfl_cxt[bank].scheduledstart; i--) | 691 | for (i = 0x333; i > 0 && i > ftl_vfl_cxt[bank].scheduledstart; i--) |
@@ -697,7 +697,7 @@ uint32_t ftl_vfl_check_remap_scheduled(uint32_t bank, uint32_t block) | |||
697 | 697 | ||
698 | #ifndef FTL_READONLY | 698 | #ifndef FTL_READONLY |
699 | /* Schedules remapping for the specified bank and vBlock */ | 699 | /* Schedules remapping for the specified bank and vBlock */ |
700 | void ftl_vfl_schedule_block_for_remap(uint32_t bank, uint32_t block) | 700 | static void ftl_vfl_schedule_block_for_remap(uint32_t bank, uint32_t block) |
701 | { | 701 | { |
702 | if (ftl_vfl_check_remap_scheduled(bank, block) == 1) | 702 | if (ftl_vfl_check_remap_scheduled(bank, block) == 1) |
703 | return; | 703 | return; |
@@ -713,7 +713,7 @@ void ftl_vfl_schedule_block_for_remap(uint32_t bank, uint32_t block) | |||
713 | #ifndef FTL_READONLY | 713 | #ifndef FTL_READONLY |
714 | /* Removes the specified bank and vBlock combination | 714 | /* Removes the specified bank and vBlock combination |
715 | from the remap scheduled list */ | 715 | from the remap scheduled list */ |
716 | void ftl_vfl_mark_remap_done(uint32_t bank, uint32_t block) | 716 | static void ftl_vfl_mark_remap_done(uint32_t bank, uint32_t block) |
717 | { | 717 | { |
718 | uint32_t i; | 718 | uint32_t i; |
719 | uint32_t start = ftl_vfl_cxt[bank].scheduledstart; | 719 | uint32_t start = ftl_vfl_cxt[bank].scheduledstart; |
@@ -734,7 +734,7 @@ void ftl_vfl_mark_remap_done(uint32_t bank, uint32_t block) | |||
734 | /* Logs that there is trouble for the specified vBlock on the specified bank. | 734 | /* Logs that there is trouble for the specified vBlock on the specified bank. |
735 | The vBlock will be scheduled for remap | 735 | The vBlock will be scheduled for remap |
736 | if there is too much trouble with it. */ | 736 | if there is too much trouble with it. */ |
737 | void ftl_vfl_log_trouble(uint32_t bank, uint32_t vblock) | 737 | static void ftl_vfl_log_trouble(uint32_t bank, uint32_t vblock) |
738 | { | 738 | { |
739 | uint32_t i; | 739 | uint32_t i; |
740 | for (i = 0; i < 5; i++) | 740 | for (i = 0; i < 5; i++) |
@@ -763,7 +763,7 @@ void ftl_vfl_log_trouble(uint32_t bank, uint32_t vblock) | |||
763 | 763 | ||
764 | #ifndef FTL_READONLY | 764 | #ifndef FTL_READONLY |
765 | /* Logs a successful erase for the specified vBlock on the specified bank */ | 765 | /* Logs a successful erase for the specified vBlock on the specified bank */ |
766 | void ftl_vfl_log_success(uint32_t bank, uint32_t vblock) | 766 | static void ftl_vfl_log_success(uint32_t bank, uint32_t vblock) |
767 | { | 767 | { |
768 | uint32_t i; | 768 | uint32_t i; |
769 | for (i = 0; i < 5; i++) | 769 | for (i = 0; i < 5; i++) |
@@ -783,7 +783,7 @@ void ftl_vfl_log_success(uint32_t bank, uint32_t vblock) | |||
783 | not caring about data in there. | 783 | not caring about data in there. |
784 | If it worked, it will return the new pBlock number, | 784 | If it worked, it will return the new pBlock number, |
785 | if not (no more spare blocks available), it will return zero. */ | 785 | if not (no more spare blocks available), it will return zero. */ |
786 | uint32_t ftl_vfl_remap_block(uint32_t bank, uint32_t block) | 786 | static uint32_t ftl_vfl_remap_block(uint32_t bank, uint32_t block) |
787 | { | 787 | { |
788 | uint32_t i; | 788 | uint32_t i; |
789 | uint32_t newblock = 0, newidx; | 789 | uint32_t newblock = 0, newidx; |
@@ -813,8 +813,8 @@ uint32_t ftl_vfl_remap_block(uint32_t bank, uint32_t block) | |||
813 | 813 | ||
814 | 814 | ||
815 | /* Reads the specified vPage, dealing with all kinds of trouble */ | 815 | /* Reads the specified vPage, dealing with all kinds of trouble */ |
816 | uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer, | 816 | static uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer, |
817 | uint32_t checkempty, uint32_t remaponfail) | 817 | uint32_t checkempty, uint32_t remaponfail) |
818 | { | 818 | { |
819 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 819 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
820 | uint32_t syshyperblocks = ftl_nand_type->blocks | 820 | uint32_t syshyperblocks = ftl_nand_type->blocks |
@@ -852,8 +852,8 @@ uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer, | |||
852 | 852 | ||
853 | 853 | ||
854 | /* Multi-bank version of ftl_vfl_read, will read ftl_banks pages in parallel */ | 854 | /* Multi-bank version of ftl_vfl_read, will read ftl_banks pages in parallel */ |
855 | uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffer, | 855 | static uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffer, |
856 | uint32_t checkempty, uint32_t remaponfail) | 856 | uint32_t checkempty, uint32_t remaponfail) |
857 | { | 857 | { |
858 | uint32_t i, rc = 0; | 858 | uint32_t i, rc = 0; |
859 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 859 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -922,8 +922,8 @@ uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffer, | |||
922 | 922 | ||
923 | #ifndef FTL_READONLY | 923 | #ifndef FTL_READONLY |
924 | /* Writes the specified vPage, dealing with all kinds of trouble */ | 924 | /* Writes the specified vPage, dealing with all kinds of trouble */ |
925 | uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count, | 925 | static uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count, |
926 | void* buffer, void* sparebuffer) | 926 | void* buffer, void* sparebuffer) |
927 | { | 927 | { |
928 | uint32_t i, j; | 928 | uint32_t i, j; |
929 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 929 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -993,7 +993,7 @@ uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count, | |||
993 | 993 | ||
994 | 994 | ||
995 | /* Mounts the VFL on all banks */ | 995 | /* Mounts the VFL on all banks */ |
996 | uint32_t ftl_vfl_open(void) | 996 | static uint32_t ftl_vfl_open(void) |
997 | { | 997 | { |
998 | uint32_t i, j, k; | 998 | uint32_t i, j, k; |
999 | uint32_t minusn, vflcxtidx, last; | 999 | uint32_t minusn, vflcxtidx, last; |
@@ -1080,7 +1080,7 @@ uint32_t ftl_vfl_open(void) | |||
1080 | 1080 | ||
1081 | 1081 | ||
1082 | /* Mounts the actual FTL */ | 1082 | /* Mounts the actual FTL */ |
1083 | uint32_t ftl_open(void) | 1083 | static uint32_t ftl_open(void) |
1084 | { | 1084 | { |
1085 | uint32_t i; | 1085 | uint32_t i; |
1086 | uint32_t ret; | 1086 | uint32_t ret; |
@@ -1182,7 +1182,7 @@ uint32_t ftl_open(void) | |||
1182 | #ifndef FTL_READONLY | 1182 | #ifndef FTL_READONLY |
1183 | /* Returns a pointer to the ftl_log entry for the specified vBlock, | 1183 | /* Returns a pointer to the ftl_log entry for the specified vBlock, |
1184 | or null, if there is none */ | 1184 | or null, if there is none */ |
1185 | struct ftl_log_type* ftl_get_log_entry(uint32_t block) | 1185 | static struct ftl_log_type* ftl_get_log_entry(uint32_t block) |
1186 | { | 1186 | { |
1187 | uint32_t i; | 1187 | uint32_t i; |
1188 | for (i = 0; i < 0x11; i++) | 1188 | for (i = 0; i < 0x11; i++) |
@@ -1264,7 +1264,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer) | |||
1264 | #ifndef FTL_READONLY | 1264 | #ifndef FTL_READONLY |
1265 | /* Performs a vBlock erase, dealing with hardware, | 1265 | /* Performs a vBlock erase, dealing with hardware, |
1266 | remapping and all kinds of trouble */ | 1266 | remapping and all kinds of trouble */ |
1267 | uint32_t ftl_erase_block_internal(uint32_t block) | 1267 | static uint32_t ftl_erase_block_internal(uint32_t block) |
1268 | { | 1268 | { |
1269 | uint32_t i, j; | 1269 | uint32_t i, j; |
1270 | block = block + ftl_nand_type->blocks | 1270 | block = block + ftl_nand_type->blocks |
@@ -1308,7 +1308,7 @@ uint32_t ftl_erase_block_internal(uint32_t block) | |||
1308 | 1308 | ||
1309 | #ifndef FTL_READONLY | 1309 | #ifndef FTL_READONLY |
1310 | /* Highlevel vBlock erase, that increments the erase counter for the block */ | 1310 | /* Highlevel vBlock erase, that increments the erase counter for the block */ |
1311 | uint32_t ftl_erase_block(uint32_t block) | 1311 | static uint32_t ftl_erase_block(uint32_t block) |
1312 | { | 1312 | { |
1313 | ftl_erasectr[block]++; | 1313 | ftl_erasectr[block]++; |
1314 | if (ftl_erasectr_dirt[block >> 10] == 100) ftl_cxt.erasedirty = 1; | 1314 | if (ftl_erasectr_dirt[block >> 10] == 100) ftl_cxt.erasedirty = 1; |
@@ -1321,7 +1321,7 @@ uint32_t ftl_erase_block(uint32_t block) | |||
1321 | #ifndef FTL_READONLY | 1321 | #ifndef FTL_READONLY |
1322 | /* Allocates a block from the pool, | 1322 | /* Allocates a block from the pool, |
1323 | returning its vBlock number, or 0xFFFFFFFF on error */ | 1323 | returning its vBlock number, or 0xFFFFFFFF on error */ |
1324 | uint32_t ftl_allocate_pool_block(void) | 1324 | static uint32_t ftl_allocate_pool_block(void) |
1325 | { | 1325 | { |
1326 | uint32_t i; | 1326 | uint32_t i; |
1327 | uint32_t erasectr = 0xFFFFFFFF, bestidx = 0xFFFFFFFF, block; | 1327 | uint32_t erasectr = 0xFFFFFFFF, bestidx = 0xFFFFFFFF, block; |
@@ -1355,7 +1355,7 @@ uint32_t ftl_allocate_pool_block(void) | |||
1355 | 1355 | ||
1356 | #ifndef FTL_READONLY | 1356 | #ifndef FTL_READONLY |
1357 | /* Releases a vBlock back into the pool */ | 1357 | /* Releases a vBlock back into the pool */ |
1358 | void ftl_release_pool_block(uint32_t block) | 1358 | static void ftl_release_pool_block(uint32_t block) |
1359 | { | 1359 | { |
1360 | if (block >= (uint32_t)ftl_nand_type->userblocks + 0x17) | 1360 | if (block >= (uint32_t)ftl_nand_type->userblocks + 0x17) |
1361 | panicf("FTL: Tried to release block %u", (unsigned)block); | 1361 | panicf("FTL: Tried to release block %u", (unsigned)block); |
@@ -1369,7 +1369,7 @@ void ftl_release_pool_block(uint32_t block) | |||
1369 | #ifndef FTL_READONLY | 1369 | #ifndef FTL_READONLY |
1370 | /* Commits the location of the FTL context blocks | 1370 | /* Commits the location of the FTL context blocks |
1371 | to a semi-randomly chosen VFL context */ | 1371 | to a semi-randomly chosen VFL context */ |
1372 | uint32_t ftl_store_ctrl_block_list(void) | 1372 | static uint32_t ftl_store_ctrl_block_list(void) |
1373 | { | 1373 | { |
1374 | uint32_t i; | 1374 | uint32_t i; |
1375 | for (i = 0; i < ftl_banks; i++) | 1375 | for (i = 0; i < ftl_banks; i++) |
@@ -1382,7 +1382,7 @@ uint32_t ftl_store_ctrl_block_list(void) | |||
1382 | #ifndef FTL_READONLY | 1382 | #ifndef FTL_READONLY |
1383 | /* Saves the n-th erase counter page to the flash, | 1383 | /* Saves the n-th erase counter page to the flash, |
1384 | because it is too dirty or needs to be moved. */ | 1384 | because it is too dirty or needs to be moved. */ |
1385 | uint32_t ftl_save_erasectr_page(uint32_t index) | 1385 | static uint32_t ftl_save_erasectr_page(uint32_t index) |
1386 | { | 1386 | { |
1387 | memset(&ftl_sparebuffer[0], 0xFF, 0x40); | 1387 | memset(&ftl_sparebuffer[0], 0xFF, 0x40); |
1388 | ftl_sparebuffer[0].meta.usn = ftl_cxt.usn; | 1388 | ftl_sparebuffer[0].meta.usn = ftl_cxt.usn; |
@@ -1408,7 +1408,7 @@ uint32_t ftl_save_erasectr_page(uint32_t index) | |||
1408 | #ifndef FTL_READONLY | 1408 | #ifndef FTL_READONLY |
1409 | /* Increments ftl_cxt.ftlctrlpage to the next available FTL context page, | 1409 | /* Increments ftl_cxt.ftlctrlpage to the next available FTL context page, |
1410 | allocating a new context block if neccessary. */ | 1410 | allocating a new context block if neccessary. */ |
1411 | uint32_t ftl_next_ctrl_pool_page(void) | 1411 | static uint32_t ftl_next_ctrl_pool_page(void) |
1412 | { | 1412 | { |
1413 | uint32_t i; | 1413 | uint32_t i; |
1414 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1414 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1446,8 +1446,8 @@ uint32_t ftl_next_ctrl_pool_page(void) | |||
1446 | 1446 | ||
1447 | #ifndef FTL_READONLY | 1447 | #ifndef FTL_READONLY |
1448 | /* Copies a vPage from one location to another */ | 1448 | /* Copies a vPage from one location to another */ |
1449 | uint32_t ftl_copy_page(uint32_t source, uint32_t destination, | 1449 | static uint32_t ftl_copy_page(uint32_t source, uint32_t destination, |
1450 | uint32_t lpn, uint32_t type) | 1450 | uint32_t lpn, uint32_t type) |
1451 | { | 1451 | { |
1452 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1452 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
1453 | uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0], | 1453 | uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0], |
@@ -1467,7 +1467,7 @@ uint32_t ftl_copy_page(uint32_t source, uint32_t destination, | |||
1467 | 1467 | ||
1468 | #ifndef FTL_READONLY | 1468 | #ifndef FTL_READONLY |
1469 | /* Copies a pBlock to a vBlock */ | 1469 | /* Copies a pBlock to a vBlock */ |
1470 | uint32_t ftl_copy_block(uint32_t source, uint32_t destination) | 1470 | static uint32_t ftl_copy_block(uint32_t source, uint32_t destination) |
1471 | { | 1471 | { |
1472 | uint32_t i, j; | 1472 | uint32_t i, j; |
1473 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1473 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1509,7 +1509,7 @@ uint32_t ftl_copy_block(uint32_t source, uint32_t destination) | |||
1509 | 1509 | ||
1510 | #ifndef FTL_READONLY | 1510 | #ifndef FTL_READONLY |
1511 | /* Clears ftl_log.issequential, if something violating that is written. */ | 1511 | /* Clears ftl_log.issequential, if something violating that is written. */ |
1512 | void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page) | 1512 | static void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page) |
1513 | { | 1513 | { |
1514 | if (entry->pagesused != entry->pagescurrent | 1514 | if (entry->pagesused != entry->pagescurrent |
1515 | || entry->pageoffsets[page] != page) | 1515 | || entry->pageoffsets[page] != page) |
@@ -1526,7 +1526,7 @@ void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page) | |||
1526 | space again. This is usually done when a scattered page block is being | 1526 | space again. This is usually done when a scattered page block is being |
1527 | removed because it is full, but less than half of the pages in there are | 1527 | removed because it is full, but less than half of the pages in there are |
1528 | still in use and rest is just filled with old crap. */ | 1528 | still in use and rest is just filled with old crap. */ |
1529 | uint32_t ftl_compact_scattered(struct ftl_log_type* entry) | 1529 | static uint32_t ftl_compact_scattered(struct ftl_log_type* entry) |
1530 | { | 1530 | { |
1531 | uint32_t i, j; | 1531 | uint32_t i, j; |
1532 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1532 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1582,7 +1582,7 @@ uint32_t ftl_compact_scattered(struct ftl_log_type* entry) | |||
1582 | 1582 | ||
1583 | #ifndef FTL_READONLY | 1583 | #ifndef FTL_READONLY |
1584 | /* Commits an ftl_log entry to proper blocks, no matter what's in there. */ | 1584 | /* Commits an ftl_log entry to proper blocks, no matter what's in there. */ |
1585 | uint32_t ftl_commit_scattered(struct ftl_log_type* entry) | 1585 | static uint32_t ftl_commit_scattered(struct ftl_log_type* entry) |
1586 | { | 1586 | { |
1587 | uint32_t i; | 1587 | uint32_t i; |
1588 | uint32_t error; | 1588 | uint32_t error; |
@@ -1610,7 +1610,7 @@ uint32_t ftl_commit_scattered(struct ftl_log_type* entry) | |||
1610 | sequentially until now, in order to be able to save a block erase by | 1610 | sequentially until now, in order to be able to save a block erase by |
1611 | committing it without needing to copy it again. | 1611 | committing it without needing to copy it again. |
1612 | If this fails for whichever reason, it will be committed the usual way. */ | 1612 | If this fails for whichever reason, it will be committed the usual way. */ |
1613 | uint32_t ftl_commit_sequential(struct ftl_log_type* entry) | 1613 | static uint32_t ftl_commit_sequential(struct ftl_log_type* entry) |
1614 | { | 1614 | { |
1615 | uint32_t i; | 1615 | uint32_t i; |
1616 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1616 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1656,7 +1656,7 @@ uint32_t ftl_commit_sequential(struct ftl_log_type* entry) | |||
1656 | /* If a log entry is supplied, its scattered page block will be removed in | 1656 | /* If a log entry is supplied, its scattered page block will be removed in |
1657 | whatever way seems most appropriate. Else, the oldest scattered page block | 1657 | whatever way seems most appropriate. Else, the oldest scattered page block |
1658 | will be freed by committing it. */ | 1658 | will be freed by committing it. */ |
1659 | uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) | 1659 | static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) |
1660 | { | 1660 | { |
1661 | uint32_t i; | 1661 | uint32_t i; |
1662 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1662 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1692,7 +1692,7 @@ uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) | |||
1692 | 1692 | ||
1693 | #ifndef FTL_READONLY | 1693 | #ifndef FTL_READONLY |
1694 | /* Initialize a log entry to the values for an empty scattered page block */ | 1694 | /* Initialize a log entry to the values for an empty scattered page block */ |
1695 | void ftl_init_log_entry(struct ftl_log_type* entry) | 1695 | static void ftl_init_log_entry(struct ftl_log_type* entry) |
1696 | { | 1696 | { |
1697 | entry->issequential = 1; | 1697 | entry->issequential = 1; |
1698 | entry->pagescurrent = 0; | 1698 | entry->pagescurrent = 0; |
@@ -1705,7 +1705,7 @@ void ftl_init_log_entry(struct ftl_log_type* entry) | |||
1705 | #ifndef FTL_READONLY | 1705 | #ifndef FTL_READONLY |
1706 | /* Allocates a log entry for the specified vBlock, | 1706 | /* Allocates a log entry for the specified vBlock, |
1707 | first making space, if neccessary. */ | 1707 | first making space, if neccessary. */ |
1708 | struct ftl_log_type* ftl_allocate_log_entry(uint32_t block) | 1708 | static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block) |
1709 | { | 1709 | { |
1710 | uint32_t i; | 1710 | uint32_t i; |
1711 | struct ftl_log_type* entry = ftl_get_log_entry(block); | 1711 | struct ftl_log_type* entry = ftl_get_log_entry(block); |
@@ -1746,7 +1746,7 @@ struct ftl_log_type* ftl_allocate_log_entry(uint32_t block) | |||
1746 | 1746 | ||
1747 | #ifndef FTL_READONLY | 1747 | #ifndef FTL_READONLY |
1748 | /* Commits the FTL block map, erase counters, and context to flash */ | 1748 | /* Commits the FTL block map, erase counters, and context to flash */ |
1749 | uint32_t ftl_commit_cxt(void) | 1749 | static uint32_t ftl_commit_cxt(void) |
1750 | { | 1750 | { |
1751 | uint32_t i; | 1751 | uint32_t i; |
1752 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1752 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
@@ -1788,7 +1788,7 @@ uint32_t ftl_commit_cxt(void) | |||
1788 | /* Swaps the most and least worn block on the flash, | 1788 | /* Swaps the most and least worn block on the flash, |
1789 | to better distribute wear. It will refuse to do anything | 1789 | to better distribute wear. It will refuse to do anything |
1790 | if the wear spread is lower than 5 erases. */ | 1790 | if the wear spread is lower than 5 erases. */ |
1791 | uint32_t ftl_swap_blocks(void) | 1791 | static uint32_t ftl_swap_blocks(void) |
1792 | { | 1792 | { |
1793 | uint32_t i; | 1793 | uint32_t i; |
1794 | uint32_t min = 0xFFFFFFFF, max = 0, maxidx = 0x14; | 1794 | uint32_t min = 0xFFFFFFFF, max = 0, maxidx = 0x14; |