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.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
index f7c636d7bd..42ff08eefb 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/ftl-nano2g.c
@@ -1227,7 +1227,7 @@ static uint32_t ftl_open(void)
1227 { 1227 {
1228 uint32_t badblocks = 0; 1228 uint32_t badblocks = 0;
1229#ifndef FTL_READONLY 1229#ifndef FTL_READONLY
1230 for (j = 0; j < (*ftl_nand_type).blocks >> 3; j++) 1230 for (j = 0; j < ftl_nand_type->blocks >> 3; j++)
1231 { 1231 {
1232 uint8_t bbtentry = ftl_bbt[i][j]; 1232 uint8_t bbtentry = ftl_bbt[i][j];
1233 for (k = 0; k < 8; k++) if ((bbtentry & (1 << k)) == 0) badblocks++; 1233 for (k = 0; k < 8; k++) if ((bbtentry & (1 << k)) == 0) badblocks++;
@@ -1246,7 +1246,7 @@ static uint32_t ftl_open(void)
1246 } 1246 }
1247#ifndef FTL_READONLY 1247#ifndef FTL_READONLY
1248 uint32_t min = 0xFFFFFFFF, max = 0, total = 0; 1248 uint32_t min = 0xFFFFFFFF, max = 0, total = 0;
1249 for (i = 0; i < (*ftl_nand_type).userblocks + 23; i++) 1249 for (i = 0; i < ftl_nand_type->userblocks + 23; i++)
1250 { 1250 {
1251 if (ftl_erasectr[i] > max) max = ftl_erasectr[i]; 1251 if (ftl_erasectr[i] > max) max = ftl_erasectr[i];
1252 if (ftl_erasectr[i] < min) min = ftl_erasectr[i]; 1252 if (ftl_erasectr[i] < min) min = ftl_erasectr[i];
@@ -1290,7 +1290,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer)
1290 if (sector + count > ftl_nand_type->userblocks * ppb) 1290 if (sector + count > ftl_nand_type->userblocks * ppb)
1291 { 1291 {
1292 DEBUGF("FTL: Sector %d is out of range!\n", sector + count - 1); 1292 DEBUGF("FTL: Sector %d is out of range!\n", sector + count - 1);
1293 return 1; 1293 return -2;
1294 } 1294 }
1295 if (count == 0) return 0; 1295 if (count == 0) return 0;
1296 1296
@@ -1337,7 +1337,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer)
1337 else if ((ret & (0xd << (j << 2))) || ftl_sparebuffer[j].user.eccmark != 0xFF) 1337 else if ((ret & (0xd << (j << 2))) || ftl_sparebuffer[j].user.eccmark != 0xFF)
1338 { 1338 {
1339 DEBUGF("FTL: Error while reading sector %d!\n", (sector + i)); 1339 DEBUGF("FTL: Error while reading sector %d!\n", (sector + i));
1340 error = 1; 1340 error = -3;
1341 memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800); 1341 memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800);
1342 } 1342 }
1343 i += ftl_banks - 1; 1343 i += ftl_banks - 1;
@@ -1350,7 +1350,7 @@ uint32_t ftl_read(uint32_t sector, uint32_t count, void* buffer)
1350 else if ((ret & 0x11D) != 0 || ftl_sparebuffer[0].user.eccmark != 0xFF) 1350 else if ((ret & 0x11D) != 0 || ftl_sparebuffer[0].user.eccmark != 0xFF)
1351 { 1351 {
1352 DEBUGF("FTL: Error while reading sector %d!\n", (sector + i)); 1352 DEBUGF("FTL: Error while reading sector %d!\n", (sector + i));
1353 error = 1; 1353 error = -4;
1354 memset(&((uint8_t*)buffer)[i << 11], 0, 0x800); 1354 memset(&((uint8_t*)buffer)[i << 11], 0, 0x800);
1355 } 1355 }
1356 } 1356 }
@@ -1811,8 +1811,11 @@ static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
1811{ 1811{
1812 uint32_t i; 1812 uint32_t i;
1813 struct ftl_log_type* entry = ftl_get_log_entry(block); 1813 struct ftl_log_type* entry = ftl_get_log_entry(block);
1814 entry->usn = ftl_cxt.nextblockusn - 1; 1814 if (entry != (struct ftl_log_type*)0)
1815 if (entry != (struct ftl_log_type*)0) return entry; 1815 {
1816 entry->usn = ftl_cxt.nextblockusn - 1;
1817 return entry;
1818 }
1816 1819
1817 for (i = 0; i < 0x11; i++) 1820 for (i = 0; i < 0x11; i++)
1818 { 1821 {
@@ -1945,7 +1948,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1945 if (sector + count > ftl_nand_type->userblocks * ppb) 1948 if (sector + count > ftl_nand_type->userblocks * ppb)
1946 { 1949 {
1947 DEBUGF("FTL: Sector %d is out of range!\n", sector + count - 1); 1950 DEBUGF("FTL: Sector %d is out of range!\n", sector + count - 1);
1948 return 1; 1951 return -2;
1949 } 1952 }
1950 if (count == 0) return 0; 1953 if (count == 0) return 0;
1951 1954
@@ -1959,7 +1962,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1959 if (ftl_next_ctrl_pool_page() != 0) 1962 if (ftl_next_ctrl_pool_page() != 0)
1960 { 1963 {
1961 mutex_unlock(&ftl_mtx); 1964 mutex_unlock(&ftl_mtx);
1962 return 1; 1965 return -3;
1963 } 1966 }
1964 memset(ftl_buffer, 0xFF, 0x800); 1967 memset(ftl_buffer, 0xFF, 0x800);
1965 memset(&ftl_sparebuffer[0], 0xFF, 0x40); 1968 memset(&ftl_sparebuffer[0], 0xFF, 0x40);
@@ -1972,7 +1975,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1972 if (i == 3) 1975 if (i == 3)
1973 { 1976 {
1974 mutex_unlock(&ftl_mtx); 1977 mutex_unlock(&ftl_mtx);
1975 return 1; 1978 return -4;
1976 } 1979 }
1977 DEBUGF("FTL: Wrote dirty mark to %d\n", ftl_cxt.ftlctrlpage); 1980 DEBUGF("FTL: Wrote dirty mark to %d\n", ftl_cxt.ftlctrlpage);
1978 ftl_cxt.clean_flag = 0; 1981 ftl_cxt.clean_flag = 0;
@@ -1987,7 +1990,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1987 if (logentry == (struct ftl_log_type*)0) 1990 if (logentry == (struct ftl_log_type*)0)
1988 { 1991 {
1989 mutex_unlock(&ftl_mtx); 1992 mutex_unlock(&ftl_mtx);
1990 return 1; 1993 return -5;
1991 } 1994 }
1992 if (page == 0 && count - i >= ppb) 1995 if (page == 0 && count - i >= ppb)
1993 { 1996 {
@@ -2006,7 +2009,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
2006 if (vblock == 0xFFFFFFFF) 2009 if (vblock == 0xFFFFFFFF)
2007 { 2010 {
2008 mutex_unlock(&ftl_mtx); 2011 mutex_unlock(&ftl_mtx);
2009 return 1; 2012 return -6;
2010 } 2013 }
2011 } 2014 }
2012 ftl_cxt.nextblockusn++; 2015 ftl_cxt.nextblockusn++;
@@ -2048,7 +2051,7 @@ uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
2048 if (logentry == (struct ftl_log_type*)0) 2051 if (logentry == (struct ftl_log_type*)0)
2049 { 2052 {
2050 mutex_unlock(&ftl_mtx); 2053 mutex_unlock(&ftl_mtx);
2051 return 1; 2054 return -7;
2052 } 2055 }
2053 } 2056 }
2054 uint32_t cnt = FTL_WRITESPARE_SIZE; 2057 uint32_t cnt = FTL_WRITESPARE_SIZE;
@@ -2142,7 +2145,7 @@ uint32_t ftl_sync(void)
2142 if (rc != 0) 2145 if (rc != 0)
2143 { 2146 {
2144 mutex_unlock(&ftl_mtx); 2147 mutex_unlock(&ftl_mtx);
2145 return 1; 2148 return -1;
2146 } 2149 }
2147 for (i = 0; i < 5; i++) 2150 for (i = 0; i < 5; i++)
2148 if (ftl_commit_cxt() == 0) 2151 if (ftl_commit_cxt() == 0)
@@ -2152,7 +2155,7 @@ uint32_t ftl_sync(void)
2152 } 2155 }
2153 else ftl_cxt.ftlctrlpage |= ppb - 1; 2156 else ftl_cxt.ftlctrlpage |= ppb - 1;
2154 mutex_unlock(&ftl_mtx); 2157 mutex_unlock(&ftl_mtx);
2155 return 1; 2158 return -2;
2156} 2159}
2157#endif 2160#endif
2158 2161
@@ -2195,12 +2198,12 @@ uint32_t ftl_init(void)
2195 if (founddevinfo == 0) 2198 if (founddevinfo == 0)
2196 { 2199 {
2197 DEBUGF("FTL: No DEVICEINFO found!\n"); 2200 DEBUGF("FTL: No DEVICEINFO found!\n");
2198 return 1; 2201 return -1;
2199 } 2202 }
2200 if (foundsignature != 0 && (result & 0x11F) != 0) 2203 if (foundsignature != 0 && (result & 0x11F) != 0)
2201 { 2204 {
2202 DEBUGF("FTL: Problem with the signature!\n"); 2205 DEBUGF("FTL: Problem with the signature!\n");
2203 return 1; 2206 return -2;
2204 } 2207 }
2205 if (ftl_vfl_open() == 0) 2208 if (ftl_vfl_open() == 0)
2206 if (ftl_open() == 0) 2209 if (ftl_open() == 0)
@@ -2208,5 +2211,5 @@ uint32_t ftl_init(void)
2208 2211
2209 DEBUGF("FTL: Initialization failed!\n"); 2212 DEBUGF("FTL: Initialization failed!\n");
2210 2213
2211 return 1; 2214 return -3;
2212} 2215}