Index: embios/trunk/target/ipodnano2g/nand.c |
— | — | @@ -232,7 +232,7 @@ |
233 | 233 | static uint32_t nand_transfer_data_collect(uint32_t direction)
|
234 | 234 | {
|
235 | 235 | uint32_t timeout = USEC_TIMER + 20000;
|
236 | | - while ((DMAALLST & DMAALLST_DMABUSY3))
|
| 236 | + while (DMAALLST & DMAALLST_DMABUSY3)
|
237 | 237 | if (nand_timeout(timeout)) return 1;
|
238 | 238 | if (!direction) invalidate_dcache();
|
239 | 239 | if (nand_wait_addrdone()) return 1;
|
— | — | @@ -409,8 +409,6 @@ |
410 | 410 | {
|
411 | 411 | if (nand_transfer_data(bank, 0, spare, 0x40))
|
412 | 412 | return nand_unlock(1);
|
413 | | - if (sparebuffer)
|
414 | | - memcpy(sparebuffer, spare, 0x800);
|
415 | 413 | if (checkempty)
|
416 | 414 | rc = nand_check_empty((uint8_t*)sparebuffer) << 1;
|
417 | 415 | }
|
Index: embios/trunk/target/ipodnano2g/ftl.c |
— | — | @@ -364,6 +364,9 @@ |
365 | 365 | /* Number of banks we detected a chip on */
|
366 | 366 | uint32_t ftl_banks;
|
367 | 367 |
|
| 368 | +/* Number of banks we detected a chip on (power of two) */
|
| 369 | +uint32_t ftl_banks_exponent;
|
| 370 | +
|
368 | 371 | /* Block map, used vor pBlock to vBlock mapping */
|
369 | 372 | static uint16_t ftl_map[0x2000] CACHEALIGN_ATTR;
|
370 | 373 |
|
— | — | @@ -433,8 +436,17 @@ |
434 | 437 | static struct mutex ftl_mtx;
|
435 | 438 | bool ftl_initialized = false;
|
436 | 439 |
|
| 440 | +/* Pages per hyperblock (ftl_nand_type->pagesperblock * ftl_banks) */
|
| 441 | +static uint32_t ppb;
|
437 | 442 |
|
| 443 | +/* Pages per hyperblock (power of two) */
|
| 444 | +static uint32_t ppb_exponent;
|
438 | 445 |
|
| 446 | +/* Reserved hyperblocks (ftl_nand_type->blocks
|
| 447 | + - ftl_nand_type->userblocks - 0x17) */
|
| 448 | +static uint32_t syshyperblocks;
|
| 449 | +
|
| 450 | +
|
439 | 451 | /* Finds a device info page for the specified bank and returns its number.
|
440 | 452 | Used to check if one is present, and to read the lowlevel BBT. */
|
441 | 453 | static uint32_t ftl_find_devinfo(uint32_t bank) INITCODE_ATTR;
|
— | — | @@ -853,9 +865,6 @@ |
854 | 866 | DEBUGF("FTL: VFL: Reading page %d", vpage);
|
855 | 867 | #endif
|
856 | 868 |
|
857 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
858 | | - uint32_t syshyperblocks = ftl_nand_type->blocks
|
859 | | - - ftl_nand_type->userblocks - 0x17;
|
860 | 869 | uint32_t abspage = vpage + ppb * syshyperblocks;
|
861 | 870 | if (abspage >= ftl_nand_type->blocks * ppb || abspage < ppb)
|
862 | 871 | {
|
— | — | @@ -863,9 +872,9 @@ |
864 | 873 | return 4;
|
865 | 874 | }
|
866 | 875 |
|
867 | | - uint32_t bank = abspage % ftl_banks;
|
868 | | - uint32_t block = abspage / (ftl_nand_type->pagesperblock * ftl_banks);
|
869 | | - uint32_t page = (abspage / ftl_banks) % ftl_nand_type->pagesperblock;
|
| 876 | + uint32_t bank = abspage & (ftl_banks - 1);
|
| 877 | + uint32_t block = abspage >> ppb_exponent;
|
| 878 | + uint32_t page = (abspage >> ftl_banks_exponent) & ((1 << ftl_nand_type->blocksizeexponent) - 1);
|
870 | 879 | uint32_t physblock = ftl_vfl_get_physical_block(bank, block);
|
871 | 880 | uint32_t physpage = physblock * ftl_nand_type->pagesperblock + page;
|
872 | 881 |
|
— | — | @@ -902,9 +911,6 @@ |
903 | 912 | #endif
|
904 | 913 |
|
905 | 914 | uint32_t i, rc = 0;
|
906 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
907 | | - uint32_t syshyperblocks = ftl_nand_type->blocks
|
908 | | - - ftl_nand_type->userblocks - 0x17;
|
909 | 915 | uint32_t abspage = vpage + ppb * syshyperblocks;
|
910 | 916 | if (abspage + ftl_banks - 1 >= ftl_nand_type->blocks * ppb || abspage < ppb)
|
911 | 917 | {
|
— | — | @@ -912,9 +918,9 @@ |
913 | 919 | return 4;
|
914 | 920 | }
|
915 | 921 |
|
916 | | - uint32_t bank = abspage % ftl_banks;
|
917 | | - uint32_t block = abspage / (ftl_nand_type->pagesperblock * ftl_banks);
|
918 | | - uint32_t page = (abspage / ftl_banks) % ftl_nand_type->pagesperblock;
|
| 922 | + uint32_t bank = abspage & (ftl_banks - 1);
|
| 923 | + uint32_t block = abspage >> ppb_exponent;
|
| 924 | + uint32_t page = (abspage >> ftl_banks_exponent) & ((1 << ftl_nand_type->blocksizeexponent) - 1);
|
919 | 925 | uint32_t remapped = 0;
|
920 | 926 | for (i = 0; i < ftl_banks; i++)
|
921 | 927 | if (ftl_vfl_get_physical_block(i, block) != block)
|
— | — | @@ -978,9 +984,6 @@ |
979 | 985 | DEBUGF("FTL: VFL: Writing page %d", vpage);
|
980 | 986 | #endif
|
981 | 987 |
|
982 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
983 | | - uint32_t syshyperblocks = ftl_nand_type->blocks
|
984 | | - - ftl_nand_type->userblocks - 0x17;
|
985 | 988 | uint32_t abspage = vpage + ppb * syshyperblocks;
|
986 | 989 | if (abspage + count > ftl_nand_type->blocks * ppb || abspage < ppb)
|
987 | 990 | {
|
— | — | @@ -1065,9 +1068,6 @@ |
1066 | 1069 | uint8_t bbt[0x410];
|
1067 | 1070 | #endif
|
1068 | 1071 |
|
1069 | | - uint32_t syshyperblocks = ftl_nand_type->blocks
|
1070 | | - - ftl_nand_type->userblocks - 0x18;
|
1071 | | -
|
1072 | 1072 | for (i = 0; i < ftl_banks; i++)
|
1073 | 1073 | #ifndef FTL_READONLY
|
1074 | 1074 | if (ftl_load_bbt(i, ftl_bbt[i]) == 0)
|
— | — | @@ -1152,7 +1152,6 @@ |
1153 | 1153 | {
|
1154 | 1154 | uint32_t i;
|
1155 | 1155 | uint32_t ret;
|
1156 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1157 | 1156 | struct ftl_vfl_cxt_type* cxt = ftl_vfl_get_newest_cxt();
|
1158 | 1157 |
|
1159 | 1158 | uint32_t ftlcxtblock = 0xffffffff;
|
— | — | @@ -1316,7 +1315,6 @@ |
1317 | 1316 | uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer)
|
1318 | 1317 | {
|
1319 | 1318 | uint32_t i, j;
|
1320 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1321 | 1319 | uint32_t error = 0;
|
1322 | 1320 |
|
1323 | 1321 | if (!ftl_initialized) return -1;
|
— | — | @@ -1571,7 +1569,6 @@ |
1572 | 1570 | static uint32_t ftl_next_ctrl_pool_page(void)
|
1573 | 1571 | {
|
1574 | 1572 | uint32_t i;
|
1575 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1576 | 1573 | if (++ftl_cxt.ftlctrlpage % ppb != 0) return 0;
|
1577 | 1574 | for (i = 0; i < 3; i++)
|
1578 | 1575 | if ((ftl_cxt.ftlctrlblocks[i] + 1) * ppb == ftl_cxt.ftlctrlpage)
|
— | — | @@ -1610,7 +1607,6 @@ |
1611 | 1608 | static uint32_t ftl_copy_page(uint32_t source, uint32_t destination,
|
1612 | 1609 | uint32_t lpn, uint32_t type)
|
1613 | 1610 | {
|
1614 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1615 | 1611 | uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0],
|
1616 | 1612 | &ftl_copyspare[0], 1, 1) & 0x11F;
|
1617 | 1613 | memset(&ftl_copyspare[0], 0xFF, 0x40);
|
— | — | @@ -1631,7 +1627,6 @@ |
1632 | 1628 | static uint32_t ftl_copy_block(uint32_t source, uint32_t destination)
|
1633 | 1629 | {
|
1634 | 1630 | uint32_t i, j;
|
1635 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1636 | 1631 | uint32_t error = 0;
|
1637 | 1632 | ftl_cxt.nextblockusn++;
|
1638 | 1633 | for (i = 0; i < ppb; i += FTL_COPYBUF_SIZE)
|
— | — | @@ -1690,7 +1685,6 @@ |
1691 | 1686 | static uint32_t ftl_compact_scattered(struct ftl_log_type* entry)
|
1692 | 1687 | {
|
1693 | 1688 | uint32_t i, j;
|
1694 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1695 | 1689 | uint32_t error;
|
1696 | 1690 | struct ftl_log_type backup;
|
1697 | 1691 | if (entry->pagescurrent == 0)
|
— | — | @@ -1774,7 +1768,6 @@ |
1775 | 1769 | static uint32_t ftl_commit_sequential(struct ftl_log_type* entry)
|
1776 | 1770 | {
|
1777 | 1771 | uint32_t i;
|
1778 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1779 | 1772 |
|
1780 | 1773 | if (entry->issequential != 1
|
1781 | 1774 | || entry->pagescurrent != entry->pagesused)
|
— | — | @@ -1820,7 +1813,6 @@ |
1821 | 1814 | static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry)
|
1822 | 1815 | {
|
1823 | 1816 | uint32_t i;
|
1824 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1825 | 1817 | uint32_t age = 0xFFFFFFFF, used = 0;
|
1826 | 1818 | if (entry == NULL)
|
1827 | 1819 | {
|
— | — | @@ -1917,7 +1909,6 @@ |
1918 | 1910 | static uint32_t ftl_commit_cxt(void)
|
1919 | 1911 | {
|
1920 | 1912 | uint32_t i;
|
1921 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
1922 | 1913 | uint32_t mappages = (ftl_nand_type->userblocks + 0x3ff) >> 10;
|
1923 | 1914 | uint32_t ctrpages = (ftl_nand_type->userblocks + 23 + 0x3ff) >> 10;
|
1924 | 1915 | uint32_t endpage = ftl_cxt.ftlctrlpage + mappages + ctrpages + 1;
|
— | — | @@ -2002,7 +1993,6 @@ |
2003 | 1994 | uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
|
2004 | 1995 | {
|
2005 | 1996 | uint32_t i, j, k;
|
2006 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
2007 | 1997 |
|
2008 | 1998 | if (!ftl_initialized) return -1;
|
2009 | 1999 |
|
— | — | @@ -2197,8 +2187,6 @@ |
2198 | 2188 | {
|
2199 | 2189 | uint32_t i;
|
2200 | 2190 | uint32_t rc = 0;
|
2201 | | - uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
|
2202 | | -
|
2203 | 2191 | if (!ftl_initialized) return 0;
|
2204 | 2192 |
|
2205 | 2193 | if (ftl_cxt.clean_flag == 1) return 0;
|
— | — | @@ -2591,6 +2579,10 @@ |
2592 | 2580 | for (i = 0; i < 4; i++)
|
2593 | 2581 | if (nand_get_device_type(i) != 0) ftl_banks = i + 1;
|
2594 | 2582 | ftl_nand_type = nand_get_device_type(0);
|
| 2583 | + ftl_banks_exponent = ftl_banks == 4 ? 2 : ftl_banks == 2 ? 1 : 0;
|
| 2584 | + ppb_exponent = ftl_nand_type->blocksizeexponent + ftl_banks_exponent;
|
| 2585 | + ppb = (1 << ppb_exponent);
|
| 2586 | + syshyperblocks = ftl_nand_type->blocks - ftl_nand_type->userblocks - 0x17;
|
2595 | 2587 |
|
2596 | 2588 | if (!ftl_has_devinfo())
|
2597 | 2589 | {
|