summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c')
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
index 0cada3162a..90217363cc 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
@@ -418,6 +418,13 @@ static uint16_t ftl_offsets_backup[0x200] STORAGE_ALIGN_ATTR;
418 418
419static struct mutex ftl_mtx; 419static struct mutex ftl_mtx;
420 420
421/* Pages per hyperblock (ftl_nand_type->pagesperblock * ftl_banks) */
422static uint32_t ppb;
423
424/* Reserved hyperblocks (ftl_nand_type->blocks
425 - ftl_nand_type->userblocks - 0x17) */
426static uint32_t syshyperblocks;
427
421 428
422 429
423/* Finds a device info page for the specified bank and returns its number. 430/* Finds a device info page for the specified bank and returns its number.
@@ -826,9 +833,6 @@ static uint32_t ftl_vfl_read(uint32_t vpage, void* buffer, void* sparebuffer,
826 DEBUGF("FTL: VFL: Reading page %d\n", vpage); 833 DEBUGF("FTL: VFL: Reading page %d\n", vpage);
827#endif 834#endif
828 835
829 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
830 uint32_t syshyperblocks = ftl_nand_type->blocks
831 - ftl_nand_type->userblocks - 0x17;
832 uint32_t abspage = vpage + ppb * syshyperblocks; 836 uint32_t abspage = vpage + ppb * syshyperblocks;
833 if (abspage >= ftl_nand_type->blocks * ppb || abspage < ppb) 837 if (abspage >= ftl_nand_type->blocks * ppb || abspage < ppb)
834 { 838 {
@@ -875,9 +879,6 @@ static uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffe
875#endif 879#endif
876 880
877 uint32_t i, rc = 0; 881 uint32_t i, rc = 0;
878 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
879 uint32_t syshyperblocks = ftl_nand_type->blocks
880 - ftl_nand_type->userblocks - 0x17;
881 uint32_t abspage = vpage + ppb * syshyperblocks; 882 uint32_t abspage = vpage + ppb * syshyperblocks;
882 if (abspage + ftl_banks - 1 >= ftl_nand_type->blocks * ppb || abspage < ppb) 883 if (abspage + ftl_banks - 1 >= ftl_nand_type->blocks * ppb || abspage < ppb)
883 { 884 {
@@ -951,9 +952,6 @@ static uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count,
951 DEBUGF("FTL: VFL: Writing page %d\n", vpage); 952 DEBUGF("FTL: VFL: Writing page %d\n", vpage);
952#endif 953#endif
953 954
954 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
955 uint32_t syshyperblocks = ftl_nand_type->blocks
956 - ftl_nand_type->userblocks - 0x17;
957 uint32_t abspage = vpage + ppb * syshyperblocks; 955 uint32_t abspage = vpage + ppb * syshyperblocks;
958 if (abspage + count > ftl_nand_type->blocks * ppb || abspage < ppb) 956 if (abspage + count > ftl_nand_type->blocks * ppb || abspage < ppb)
959 { 957 {
@@ -962,9 +960,9 @@ static uint32_t ftl_vfl_write(uint32_t vpage, uint32_t count,
962 return 4; 960 return 4;
963 } 961 }
964 962
965 uint32_t bank[5]; 963 static uint32_t bank[5];
966 uint32_t block[5]; 964 static uint32_t block[5];
967 uint32_t physpage[5]; 965 static uint32_t physpage[5];
968 966
969 for (i = 0; i < count; i++, abspage++) 967 for (i = 0; i < count; i++, abspage++)
970 { 968 {
@@ -1034,9 +1032,6 @@ static uint32_t ftl_vfl_open(void)
1034 uint8_t bbt[0x410]; 1032 uint8_t bbt[0x410];
1035#endif 1033#endif
1036 1034
1037 uint32_t syshyperblocks = ftl_nand_type->blocks
1038 - ftl_nand_type->userblocks - 0x18;
1039
1040 for (i = 0; i < ftl_banks; i++) 1035 for (i = 0; i < ftl_banks; i++)
1041#ifndef FTL_READONLY 1036#ifndef FTL_READONLY
1042 if (ftl_load_bbt(i, ftl_bbt[i]) == 0) 1037 if (ftl_load_bbt(i, ftl_bbt[i]) == 0)
@@ -1117,7 +1112,6 @@ static uint32_t ftl_open(void)
1117{ 1112{
1118 uint32_t i; 1113 uint32_t i;
1119 uint32_t ret; 1114 uint32_t ret;
1120 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1121 struct ftl_vfl_cxt_type* cxt = ftl_vfl_get_newest_cxt(); 1115 struct ftl_vfl_cxt_type* cxt = ftl_vfl_get_newest_cxt();
1122 1116
1123 uint32_t ftlcxtblock = 0xffffffff; 1117 uint32_t ftlcxtblock = 0xffffffff;
@@ -1281,7 +1275,6 @@ static struct ftl_log_type* ftl_get_log_entry(uint32_t block)
1281uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer) 1275uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer)
1282{ 1276{
1283 uint32_t i, j; 1277 uint32_t i, j;
1284 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1285 uint32_t error = 0; 1278 uint32_t error = 0;
1286 1279
1287#ifdef FTL_TRACE 1280#ifdef FTL_TRACE
@@ -1513,7 +1506,6 @@ static uint32_t ftl_save_erasectr_page(uint32_t index)
1513static uint32_t ftl_next_ctrl_pool_page(void) 1506static uint32_t ftl_next_ctrl_pool_page(void)
1514{ 1507{
1515 uint32_t i; 1508 uint32_t i;
1516 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1517 if (++ftl_cxt.ftlctrlpage % ppb != 0) return 0; 1509 if (++ftl_cxt.ftlctrlpage % ppb != 0) return 0;
1518 for (i = 0; i < 3; i++) 1510 for (i = 0; i < 3; i++)
1519 if ((ftl_cxt.ftlctrlblocks[i] + 1) * ppb == ftl_cxt.ftlctrlpage) 1511 if ((ftl_cxt.ftlctrlblocks[i] + 1) * ppb == ftl_cxt.ftlctrlpage)
@@ -1552,7 +1544,6 @@ static uint32_t ftl_next_ctrl_pool_page(void)
1552static uint32_t ftl_copy_page(uint32_t source, uint32_t destination, 1544static uint32_t ftl_copy_page(uint32_t source, uint32_t destination,
1553 uint32_t lpn, uint32_t type) 1545 uint32_t lpn, uint32_t type)
1554{ 1546{
1555 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1556 uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0], 1547 uint32_t rc = ftl_vfl_read(source, ftl_copybuffer[0],
1557 &ftl_copyspare[0], 1, 1) & 0x11F; 1548 &ftl_copyspare[0], 1, 1) & 0x11F;
1558 memset(&ftl_copyspare[0], 0xFF, 0x40); 1549 memset(&ftl_copyspare[0], 0xFF, 0x40);
@@ -1573,7 +1564,6 @@ static uint32_t ftl_copy_page(uint32_t source, uint32_t destination,
1573static uint32_t ftl_copy_block(uint32_t source, uint32_t destination) 1564static uint32_t ftl_copy_block(uint32_t source, uint32_t destination)
1574{ 1565{
1575 uint32_t i, j; 1566 uint32_t i, j;
1576 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1577 uint32_t error = 0; 1567 uint32_t error = 0;
1578 ftl_cxt.nextblockusn++; 1568 ftl_cxt.nextblockusn++;
1579 for (i = 0; i < ppb; i += FTL_COPYBUF_SIZE) 1569 for (i = 0; i < ppb; i += FTL_COPYBUF_SIZE)
@@ -1632,7 +1622,6 @@ static void ftl_check_still_sequential(struct ftl_log_type* entry, uint32_t page
1632static uint32_t ftl_compact_scattered(struct ftl_log_type* entry) 1622static uint32_t ftl_compact_scattered(struct ftl_log_type* entry)
1633{ 1623{
1634 uint32_t i, j; 1624 uint32_t i, j;
1635 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1636 uint32_t error; 1625 uint32_t error;
1637 struct ftl_log_type backup; 1626 struct ftl_log_type backup;
1638 if (entry->pagescurrent == 0) 1627 if (entry->pagescurrent == 0)
@@ -1716,7 +1705,6 @@ static uint32_t ftl_commit_scattered(struct ftl_log_type* entry)
1716static uint32_t ftl_commit_sequential(struct ftl_log_type* entry) 1705static uint32_t ftl_commit_sequential(struct ftl_log_type* entry)
1717{ 1706{
1718 uint32_t i; 1707 uint32_t i;
1719 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1720 1708
1721 if (entry->issequential != 1 1709 if (entry->issequential != 1
1722 || entry->pagescurrent != entry->pagesused) 1710 || entry->pagescurrent != entry->pagesused)
@@ -1762,7 +1750,6 @@ static uint32_t ftl_commit_sequential(struct ftl_log_type* entry)
1762static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) 1750static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry)
1763{ 1751{
1764 uint32_t i; 1752 uint32_t i;
1765 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1766 uint32_t age = 0xFFFFFFFF, used = 0; 1753 uint32_t age = 0xFFFFFFFF, used = 0;
1767 if (entry == NULL) 1754 if (entry == NULL)
1768 { 1755 {
@@ -1855,7 +1842,6 @@ static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
1855static uint32_t ftl_commit_cxt(void) 1842static uint32_t ftl_commit_cxt(void)
1856{ 1843{
1857 uint32_t i; 1844 uint32_t i;
1858 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1859 uint32_t mappages = (ftl_nand_type->userblocks + 0x3ff) >> 10; 1845 uint32_t mappages = (ftl_nand_type->userblocks + 0x3ff) >> 10;
1860 uint32_t ctrpages = (ftl_nand_type->userblocks + 23 + 0x3ff) >> 10; 1846 uint32_t ctrpages = (ftl_nand_type->userblocks + 23 + 0x3ff) >> 10;
1861 uint32_t endpage = ftl_cxt.ftlctrlpage + mappages + ctrpages + 1; 1847 uint32_t endpage = ftl_cxt.ftlctrlpage + mappages + ctrpages + 1;
@@ -1894,7 +1880,7 @@ static uint32_t ftl_commit_cxt(void)
1894 1880
1895#ifndef FTL_READONLY 1881#ifndef FTL_READONLY
1896/* Swaps the most and least worn block on the flash, 1882/* Swaps the most and least worn block on the flash,
1897 to better distribute wear. It will refuse to do anything 1883 to better distribute wear. It will not do anything
1898 if the wear spread is lower than 5 erases. */ 1884 if the wear spread is lower than 5 erases. */
1899static uint32_t ftl_swap_blocks(void) 1885static uint32_t ftl_swap_blocks(void)
1900{ 1886{
@@ -1940,7 +1926,6 @@ static uint32_t ftl_swap_blocks(void)
1940uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer) 1926uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1941{ 1927{
1942 uint32_t i, j, k; 1928 uint32_t i, j, k;
1943 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1944 1929
1945#ifdef FTL_TRACE 1930#ifdef FTL_TRACE
1946 DEBUGF("FTL: Writing %d sectors starting at %d\n", count, sector); 1931 DEBUGF("FTL: Writing %d sectors starting at %d\n", count, sector);
@@ -2119,7 +2104,6 @@ uint32_t ftl_sync(void)
2119{ 2104{
2120 uint32_t i; 2105 uint32_t i;
2121 uint32_t rc = 0; 2106 uint32_t rc = 0;
2122 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
2123 if (ftl_cxt.clean_flag == 1) return 0; 2107 if (ftl_cxt.clean_flag == 1) return 0;
2124 2108
2125 mutex_lock(&ftl_mtx); 2109 mutex_lock(&ftl_mtx);
@@ -2177,6 +2161,8 @@ uint32_t ftl_init(void)
2177 for (i = 0; i < 4; i++) 2161 for (i = 0; i < 4; i++)
2178 if (nand_get_device_type(i) != 0) ftl_banks = i + 1; 2162 if (nand_get_device_type(i) != 0) ftl_banks = i + 1;
2179 ftl_nand_type = nand_get_device_type(0); 2163 ftl_nand_type = nand_get_device_type(0);
2164 ppb = ftl_nand_type->pagesperblock * ftl_banks;
2165 syshyperblocks = ftl_nand_type->blocks - ftl_nand_type->userblocks - 0x17;
2180 foundsignature = 0; 2166 foundsignature = 0;
2181 blockwiped = 1; 2167 blockwiped = 1;
2182 for (i = 0; i < ftl_nand_type->pagesperblock; i++) 2168 for (i = 0; i < ftl_nand_type->pagesperblock; i++)