diff options
author | Michael Sparmann <theseven@rockbox.org> | 2010-08-21 14:40:53 +0000 |
---|---|---|
committer | Michael Sparmann <theseven@rockbox.org> | 2010-08-21 14:40:53 +0000 |
commit | 2c24a6790000df3c6693a318ce81a8ada7f6da84 (patch) | |
tree | e8f7503476615e06c9be07e29bdf737a8d5671db | |
parent | 0a080891e7b5849df2686df504c15b008ba8cc73 (diff) | |
download | rockbox-2c24a6790000df3c6693a318ce81a8ada7f6da84.tar.gz rockbox-2c24a6790000df3c6693a318ce81a8ada7f6da84.zip |
Some Nano2G FTL cosmetics
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27851 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c index 42ff08eefb..0cada3162a 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c | |||
@@ -464,7 +464,7 @@ static uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt) | |||
464 | if (page == 0) return 1; | 464 | if (page == 0) return 1; |
465 | pagebase = page & ~(ftl_nand_type->pagesperblock - 1); | 465 | pagebase = page & ~(ftl_nand_type->pagesperblock - 1); |
466 | if ((nand_read_page(bank, page, ftl_buffer, | 466 | if ((nand_read_page(bank, page, ftl_buffer, |
467 | (uint32_t*)0, 1, 0) & 0x11F) != 0) return 1; | 467 | NULL, 1, 0) & 0x11F) != 0) return 1; |
468 | if (memcmp(&ftl_buffer[0x18], "BBT", 4) != 0) return 1; | 468 | if (memcmp(&ftl_buffer[0x18], "BBT", 4) != 0) return 1; |
469 | unk1 = ((uint16_t*)ftl_buffer)[0x10]; | 469 | unk1 = ((uint16_t*)ftl_buffer)[0x10]; |
470 | unk2 = ((uint16_t*)ftl_buffer)[0x11]; | 470 | unk2 = ((uint16_t*)ftl_buffer)[0x11]; |
@@ -478,7 +478,7 @@ static uint32_t ftl_load_bbt(uint32_t bank, uint8_t* bbt) | |||
478 | if (page2 >= (uint32_t)(ftl_nand_type->pagesperblock - 8)) | 478 | if (page2 >= (uint32_t)(ftl_nand_type->pagesperblock - 8)) |
479 | break; | 479 | break; |
480 | if ((nand_read_page(bank, pagebase + page2, ftl_buffer, | 480 | if ((nand_read_page(bank, pagebase + page2, ftl_buffer, |
481 | (void*)0, 1, 0) & 0x11F) == 0) | 481 | NULL, 1, 0) & 0x11F) == 0) |
482 | { | 482 | { |
483 | memcpy(bbt, ftl_buffer, 0x410); | 483 | memcpy(bbt, ftl_buffer, 0x410); |
484 | return 0; | 484 | return 0; |
@@ -609,7 +609,7 @@ static uint32_t ftl_vfl_commit_cxt(uint32_t bank) | |||
609 | static struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void) | 609 | static struct ftl_vfl_cxt_type* ftl_vfl_get_newest_cxt(void) |
610 | { | 610 | { |
611 | uint32_t i, maxusn; | 611 | uint32_t i, maxusn; |
612 | struct ftl_vfl_cxt_type* cxt = (struct ftl_vfl_cxt_type*)0; | 612 | struct ftl_vfl_cxt_type* cxt = NULL; |
613 | maxusn = 0; | 613 | maxusn = 0; |
614 | for (i = 0; i < ftl_banks; i++) | 614 | for (i = 0; i < ftl_banks; i++) |
615 | if (ftl_vfl_cxt[i].usn >= maxusn) | 615 | if (ftl_vfl_cxt[i].usn >= maxusn) |
@@ -896,8 +896,8 @@ static uint32_t ftl_vfl_read_fast(uint32_t vpage, void* buffer, void* sparebuffe | |||
896 | { | 896 | { |
897 | for (i = 0; i < ftl_banks; i++) | 897 | for (i = 0; i < ftl_banks; i++) |
898 | { | 898 | { |
899 | void* databuf = (void*)0; | 899 | void* databuf = NULL; |
900 | void* sparebuf = (void*)0; | 900 | void* sparebuf = NULL; |
901 | if (buffer) databuf = (void*)((uint32_t)buffer + 0x800 * i); | 901 | if (buffer) databuf = (void*)((uint32_t)buffer + 0x800 * i); |
902 | if (sparebuffer) sparebuf = (void*)((uint32_t)sparebuffer + 0x40 * i); | 902 | if (sparebuffer) sparebuf = (void*)((uint32_t)sparebuffer + 0x40 * i); |
903 | uint32_t ret = ftl_vfl_read(vpage + i, databuf, sparebuf, checkempty, remaponfail); | 903 | uint32_t ret = ftl_vfl_read(vpage + i, databuf, sparebuf, checkempty, remaponfail); |
@@ -1171,6 +1171,7 @@ static uint32_t ftl_open(void) | |||
1171 | return 1; | 1171 | return 1; |
1172 | } | 1172 | } |
1173 | 1173 | ||
1174 | DEBUGF("FTL: Successfully read FTL context block\n"); | ||
1174 | uint32_t pagestoread = ftl_nand_type->userblocks >> 10; | 1175 | uint32_t pagestoread = ftl_nand_type->userblocks >> 10; |
1175 | if ((ftl_nand_type->userblocks & 0x1FF) != 0) pagestoread++; | 1176 | if ((ftl_nand_type->userblocks & 0x1FF) != 0) pagestoread++; |
1176 | 1177 | ||
@@ -1253,7 +1254,7 @@ static uint32_t ftl_open(void) | |||
1253 | total += ftl_erasectr[i]; | 1254 | total += ftl_erasectr[i]; |
1254 | } | 1255 | } |
1255 | DEBUGF("FTL: Erase counters: Minimum: %d, maximum %d, average: %d, total: %d\n", | 1256 | DEBUGF("FTL: Erase counters: Minimum: %d, maximum %d, average: %d, total: %d\n", |
1256 | min, max, total / ((*ftl_nand_type).userblocks + 23), total); | 1257 | min, max, total / (ftl_nand_type->userblocks + 23), total); |
1257 | #endif | 1258 | #endif |
1258 | #endif | 1259 | #endif |
1259 | 1260 | ||
@@ -1272,7 +1273,7 @@ static struct ftl_log_type* ftl_get_log_entry(uint32_t block) | |||
1272 | if (ftl_log[i].scatteredvblock == 0xFFFF) continue; | 1273 | if (ftl_log[i].scatteredvblock == 0xFFFF) continue; |
1273 | if (ftl_log[i].logicalvblock == block) return &ftl_log[i]; | 1274 | if (ftl_log[i].logicalvblock == block) return &ftl_log[i]; |
1274 | } | 1275 | } |
1275 | return (struct ftl_log_type*)0; | 1276 | return NULL; |
1276 | } | 1277 | } |
1277 | #endif | 1278 | #endif |
1278 | 1279 | ||
@@ -1304,7 +1305,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer) | |||
1304 | uint32_t abspage = ftl_map[block] * ppb + page; | 1305 | uint32_t abspage = ftl_map[block] * ppb + page; |
1305 | #ifndef FTL_READONLY | 1306 | #ifndef FTL_READONLY |
1306 | struct ftl_log_type* logentry = ftl_get_log_entry(block); | 1307 | struct ftl_log_type* logentry = ftl_get_log_entry(block); |
1307 | if (logentry != (struct ftl_log_type*)0) | 1308 | if (logentry != NULL) |
1308 | { | 1309 | { |
1309 | #ifdef FTL_TRACE | 1310 | #ifdef FTL_TRACE |
1310 | DEBUGF("FTL: Block %d has a log entry\n", block); | 1311 | DEBUGF("FTL: Block %d has a log entry\n", block); |
@@ -1324,7 +1325,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer) | |||
1324 | 1325 | ||
1325 | #ifndef FTL_READONLY | 1326 | #ifndef FTL_READONLY |
1326 | if (count >= i + ftl_banks && !(page & (ftl_banks - 1)) | 1327 | if (count >= i + ftl_banks && !(page & (ftl_banks - 1)) |
1327 | && logentry == (struct ftl_log_type*)0) | 1328 | && logentry == NULL) |
1328 | #else | 1329 | #else |
1329 | if (count >= i + ftl_banks && !(page & (ftl_banks - 1))) | 1330 | if (count >= i + ftl_banks && !(page & (ftl_banks - 1))) |
1330 | #endif | 1331 | #endif |
@@ -1437,7 +1438,7 @@ static uint32_t ftl_allocate_pool_block(void) | |||
1437 | bestidx = idx; | 1438 | bestidx = idx; |
1438 | } | 1439 | } |
1439 | } | 1440 | } |
1440 | if (bestidx == 0xFFFFFFFF) panicf("Out of pool blocks!"); | 1441 | if (bestidx == 0xFFFFFFFF) panicf("FTL: Out of pool blocks!"); |
1441 | block = ftl_cxt.blockpool[bestidx]; | 1442 | block = ftl_cxt.blockpool[bestidx]; |
1442 | if (bestidx != ftl_cxt.nextfreeidx) | 1443 | if (bestidx != ftl_cxt.nextfreeidx) |
1443 | { | 1444 | { |
@@ -1763,7 +1764,7 @@ static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) | |||
1763 | uint32_t i; | 1764 | uint32_t i; |
1764 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; | 1765 | uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks; |
1765 | uint32_t age = 0xFFFFFFFF, used = 0; | 1766 | uint32_t age = 0xFFFFFFFF, used = 0; |
1766 | if (entry == (struct ftl_log_type*)0) | 1767 | if (entry == NULL) |
1767 | { | 1768 | { |
1768 | for (i = 0; i < 0x11; i++) | 1769 | for (i = 0; i < 0x11; i++) |
1769 | { | 1770 | { |
@@ -1778,7 +1779,7 @@ static uint32_t ftl_remove_scattered_block(struct ftl_log_type* entry) | |||
1778 | entry = &ftl_log[i]; | 1779 | entry = &ftl_log[i]; |
1779 | } | 1780 | } |
1780 | } | 1781 | } |
1781 | if (entry == (struct ftl_log_type*)0) return 1; | 1782 | if (entry == NULL) return 1; |
1782 | } | 1783 | } |
1783 | else if (entry->pagescurrent < ppb / 2) | 1784 | else if (entry->pagescurrent < ppb / 2) |
1784 | { | 1785 | { |
@@ -1811,7 +1812,7 @@ static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block) | |||
1811 | { | 1812 | { |
1812 | uint32_t i; | 1813 | uint32_t i; |
1813 | struct ftl_log_type* entry = ftl_get_log_entry(block); | 1814 | struct ftl_log_type* entry = ftl_get_log_entry(block); |
1814 | if (entry != (struct ftl_log_type*)0) | 1815 | if (entry != NULL) |
1815 | { | 1816 | { |
1816 | entry->usn = ftl_cxt.nextblockusn - 1; | 1817 | entry->usn = ftl_cxt.nextblockusn - 1; |
1817 | return entry; | 1818 | return entry; |
@@ -1827,17 +1828,17 @@ static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block) | |||
1827 | } | 1828 | } |
1828 | } | 1829 | } |
1829 | 1830 | ||
1830 | if (entry == (struct ftl_log_type*)0) | 1831 | if (entry == NULL) |
1831 | { | 1832 | { |
1832 | if (ftl_cxt.freecount < 3) panicf("FTL: Detected a pool block leak!"); | 1833 | if (ftl_cxt.freecount < 3) panicf("FTL: Detected a pool block leak!"); |
1833 | else if (ftl_cxt.freecount == 3) | 1834 | else if (ftl_cxt.freecount == 3) |
1834 | if (ftl_remove_scattered_block((struct ftl_log_type*)0) != 0) | 1835 | if (ftl_remove_scattered_block(NULL) != 0) |
1835 | return (struct ftl_log_type*)0; | 1836 | return NULL; |
1836 | entry = ftl_log; | 1837 | entry = ftl_log; |
1837 | while (entry->scatteredvblock != 0xFFFF) entry = &entry[1]; | 1838 | while (entry->scatteredvblock != 0xFFFF) entry = &entry[1]; |
1838 | entry->scatteredvblock = ftl_allocate_pool_block(); | 1839 | entry->scatteredvblock = ftl_allocate_pool_block(); |
1839 | if (entry->scatteredvblock == 0xFFFF) | 1840 | if (entry->scatteredvblock == 0xFFFF) |
1840 | return (struct ftl_log_type*)0; | 1841 | return NULL; |
1841 | } | 1842 | } |
1842 | 1843 | ||
1843 | ftl_init_log_entry(entry); | 1844 | ftl_init_log_entry(entry); |
@@ -1915,7 +1916,7 @@ static uint32_t ftl_swap_blocks(void) | |||
1915 | for (i = 0; i < ftl_nand_type->userblocks; i++) | 1916 | for (i = 0; i < ftl_nand_type->userblocks; i++) |
1916 | { | 1917 | { |
1917 | if (ftl_erasectr[ftl_map[i]] > max) max = ftl_erasectr[ftl_map[i]]; | 1918 | if (ftl_erasectr[ftl_map[i]] > max) max = ftl_erasectr[ftl_map[i]]; |
1918 | if (ftl_get_log_entry(i) != (struct ftl_log_type*)0) continue; | 1919 | if (ftl_get_log_entry(i) != NULL) continue; |
1919 | if (ftl_erasectr[ftl_map[i]] < min) | 1920 | if (ftl_erasectr[ftl_map[i]] < min) |
1920 | { | 1921 | { |
1921 | minidx = i; | 1922 | minidx = i; |
@@ -1987,7 +1988,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer) | |||
1987 | uint32_t page = (sector + i) % ppb; | 1988 | uint32_t page = (sector + i) % ppb; |
1988 | 1989 | ||
1989 | struct ftl_log_type* logentry = ftl_allocate_log_entry(block); | 1990 | struct ftl_log_type* logentry = ftl_allocate_log_entry(block); |
1990 | if (logentry == (struct ftl_log_type*)0) | 1991 | if (logentry == NULL) |
1991 | { | 1992 | { |
1992 | mutex_unlock(&ftl_mtx); | 1993 | mutex_unlock(&ftl_mtx); |
1993 | return -5; | 1994 | return -5; |
@@ -2048,7 +2049,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer) | |||
2048 | #endif | 2049 | #endif |
2049 | ftl_remove_scattered_block(logentry); | 2050 | ftl_remove_scattered_block(logentry); |
2050 | logentry = ftl_allocate_log_entry(block); | 2051 | logentry = ftl_allocate_log_entry(block); |
2051 | if (logentry == (struct ftl_log_type*)0) | 2052 | if (logentry == NULL) |
2052 | { | 2053 | { |
2053 | mutex_unlock(&ftl_mtx); | 2054 | mutex_unlock(&ftl_mtx); |
2054 | return -7; | 2055 | return -7; |
@@ -2180,7 +2181,7 @@ uint32_t ftl_init(void) | |||
2180 | blockwiped = 1; | 2181 | blockwiped = 1; |
2181 | for (i = 0; i < ftl_nand_type->pagesperblock; i++) | 2182 | for (i = 0; i < ftl_nand_type->pagesperblock; i++) |
2182 | { | 2183 | { |
2183 | result = nand_read_page(0, i, ftl_buffer, (uint32_t*)0, 1, 1); | 2184 | result = nand_read_page(0, i, ftl_buffer, NULL, 1, 1); |
2184 | if ((result & 0x11F) == 0) | 2185 | if ((result & 0x11F) == 0) |
2185 | { | 2186 | { |
2186 | blockwiped = 0; | 2187 | blockwiped = 0; |