Subversion Repositories freemyipod

Rev

Rev 134 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 134 Rev 155
Line 1308... Line 1308...
1308
{
1308
{
1309
    uint32_t i, j;
1309
    uint32_t i, j;
1310
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1310
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1311
    uint32_t error = 0;
1311
    uint32_t error = 0;
1312
 
1312
 
1313
    if (!ftl_initialized) return 1;
1313
    if (!ftl_initialized) return -1;
1314
 
1314
 
1315
#ifdef FTL_TRACE
1315
#ifdef FTL_TRACE
1316
    DEBUGF("FTL: Reading %d sectors starting at %d", count, sector);
1316
    DEBUGF("FTL: Reading %d sectors starting at %d", count, sector);
1317
#endif
1317
#endif
1318
 
1318
 
Line 1322... Line 1322...
1322
			   (unsigned int)buffer, sector, count);
1322
			   (unsigned int)buffer, sector, count);
1323
 
1323
 
1324
    if (sector + count > ftl_nand_type->userblocks * ppb)
1324
    if (sector + count > ftl_nand_type->userblocks * ppb)
1325
    {
1325
    {
1326
        DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
1326
        DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
1327
        return 1;
1327
        return -2;
1328
    }
1328
    }
1329
    if (count == 0) return 0;
1329
    if (count == 0) return 0;
1330
 
1330
 
1331
    mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
1331
    mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
1332
 
1332
 
Line 1369... Line 1369...
1369
                if (ret & (2 << (j << 2)))
1369
                if (ret & (2 << (j << 2)))
1370
                    memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800);
1370
                    memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800);
1371
                else if ((ret & (0xd << (j << 2))) || ftl_sparebuffer[j].user.eccmark != 0xFF)
1371
                else if ((ret & (0xd << (j << 2))) || ftl_sparebuffer[j].user.eccmark != 0xFF)
1372
                {
1372
                {
1373
		            DEBUGF("FTL: Error while reading sector %d!", (sector + i));
1373
		            DEBUGF("FTL: Error while reading sector %d!", (sector + i));
1374
                    error = 1;
1374
                    error = -3;
1375
                    memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800);
1375
                    memset(&((uint8_t*)buffer)[(i + j) << 11], 0, 0x800);
1376
                }
1376
                }
1377
            i += ftl_banks - 1;
1377
            i += ftl_banks - 1;
1378
        }
1378
        }
1379
        else
1379
        else
Line 1382... Line 1382...
1382
                                        &ftl_sparebuffer[0], 1, 1);
1382
                                        &ftl_sparebuffer[0], 1, 1);
1383
            if (ret & 2) memset(&((uint8_t*)buffer)[i << 11], 0, 0x800);
1383
            if (ret & 2) memset(&((uint8_t*)buffer)[i << 11], 0, 0x800);
1384
            else if ((ret & 0x11D) != 0 || ftl_sparebuffer[0].user.eccmark != 0xFF)
1384
            else if ((ret & 0x11D) != 0 || ftl_sparebuffer[0].user.eccmark != 0xFF)
1385
            {
1385
            {
1386
	            DEBUGF("FTL: Error while reading sector %d!", (sector + i));
1386
	            DEBUGF("FTL: Error while reading sector %d!", (sector + i));
1387
                error = 1;
1387
                error = -4;
1388
                memset(&((uint8_t*)buffer)[i << 11], 0, 0x800);
1388
                memset(&((uint8_t*)buffer)[i << 11], 0, 0x800);
1389
            }
1389
            }
1390
        }
1390
        }
1391
    }
1391
    }
1392
 
1392
 
Line 1843... Line 1843...
1843
   first making space, if neccessary. */
1843
   first making space, if neccessary. */
1844
static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
1844
static struct ftl_log_type* ftl_allocate_log_entry(uint32_t block)
1845
{
1845
{
1846
    uint32_t i;
1846
    uint32_t i;
1847
    struct ftl_log_type* entry = ftl_get_log_entry(block);
1847
    struct ftl_log_type* entry = ftl_get_log_entry(block);
-
 
1848
    if (entry != (struct ftl_log_type*)0)
-
 
1849
    {
1848
    entry->usn = ftl_cxt.nextblockusn - 1;
1850
        entry->usn = ftl_cxt.nextblockusn - 1;
1849
    if (entry != (struct ftl_log_type*)0) return entry;
1851
        return entry;
-
 
1852
    }
1850
 
1853
 
1851
    for (i = 0; i < 0x11; i++)
1854
    for (i = 0; i < 0x11; i++)
1852
    {
1855
    {
1853
        if (ftl_log[i].scatteredvblock == 0xFFFF) continue;
1856
        if (ftl_log[i].scatteredvblock == 0xFFFF) continue;
1854
        if (ftl_log[i].pagesused == 0)
1857
        if (ftl_log[i].pagesused == 0)
Line 1970... Line 1973...
1970
uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1973
uint32_t ftl_write(uint32_t sector, uint32_t count, const void* buffer)
1971
{
1974
{
1972
    uint32_t i, j, k;
1975
    uint32_t i, j, k;
1973
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1976
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
1974
 
1977
 
1975
    if (!ftl_initialized) return 1;
1978
    if (!ftl_initialized) return -1;
1976
 
1979
 
1977
#ifdef FTL_TRACE
1980
#ifdef FTL_TRACE
1978
    DEBUGF("FTL: Writing %d sectors starting at %d", count, sector);
1981
    DEBUGF("FTL: Writing %d sectors starting at %d", count, sector);
1979
#endif
1982
#endif
1980
 
1983
 
Line 1984... Line 1987...
1984
			   (unsigned int)buffer, sector, count);
1987
			   (unsigned int)buffer, sector, count);
1985
 
1988
 
1986
    if (sector + count > ftl_nand_type->userblocks * ppb)
1989
    if (sector + count > ftl_nand_type->userblocks * ppb)
1987
    {
1990
    {
1988
        DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
1991
        DEBUGF("FTL: Sector %d is out of range!", sector + count - 1);
1989
        return 1;
1992
        return -2;
1990
    }
1993
    }
1991
    if (count == 0) return 0;
1994
    if (count == 0) return 0;
1992
 
1995
 
1993
    mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
1996
    mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
1994
 
1997
 
Line 1998... Line 2001...
1998
        {
2001
        {
1999
		    DEBUGF("FTL: Marking dirty, try %d", i);
2002
		    DEBUGF("FTL: Marking dirty, try %d", i);
2000
            if (ftl_next_ctrl_pool_page() != 0)
2003
            if (ftl_next_ctrl_pool_page() != 0)
2001
            {
2004
            {
2002
                mutex_unlock(&ftl_mtx);
2005
                mutex_unlock(&ftl_mtx);
2003
                return 1;
2006
                return -3;
2004
            }
2007
            }
2005
            memset(ftl_buffer, 0xFF, 0x800);
2008
            memset(ftl_buffer, 0xFF, 0x800);
2006
            memset(&ftl_sparebuffer[0], 0xFF, 0x40);
2009
            memset(&ftl_sparebuffer[0], 0xFF, 0x40);
2007
            ftl_sparebuffer[0].meta.usn = ftl_cxt.usn;
2010
            ftl_sparebuffer[0].meta.usn = ftl_cxt.usn;
2008
            ftl_sparebuffer[0].meta.type = 0x47;
2011
            ftl_sparebuffer[0].meta.type = 0x47;
Line 2011... Line 2014...
2011
                break;
2014
                break;
2012
        }
2015
        }
2013
        if (i == 3)
2016
        if (i == 3)
2014
        {
2017
        {
2015
            mutex_unlock(&ftl_mtx);
2018
            mutex_unlock(&ftl_mtx);
2016
            return 1;
2019
            return -4;
2017
        }
2020
        }
2018
    	DEBUGF("FTL: Wrote dirty mark to %d", ftl_cxt.ftlctrlpage);
2021
    	DEBUGF("FTL: Wrote dirty mark to %d", ftl_cxt.ftlctrlpage);
2019
        ftl_cxt.clean_flag = 0;
2022
        ftl_cxt.clean_flag = 0;
2020
    }
2023
    }
2021
 
2024
 
Line 2026... Line 2029...
2026
 
2029
 
2027
        struct ftl_log_type* logentry = ftl_allocate_log_entry(block);
2030
        struct ftl_log_type* logentry = ftl_allocate_log_entry(block);
2028
        if (logentry == (struct ftl_log_type*)0)
2031
        if (logentry == (struct ftl_log_type*)0)
2029
        {
2032
        {
2030
            mutex_unlock(&ftl_mtx);
2033
            mutex_unlock(&ftl_mtx);
2031
            return 1;
2034
            return -5;
2032
        }
2035
        }
2033
        if (page == 0 && count - i >= ppb)
2036
        if (page == 0 && count - i >= ppb)
2034
        {
2037
        {
2035
#ifdef FTL_TRACE
2038
#ifdef FTL_TRACE
2036
		    DEBUGF("FTL: Going to write a full hyperblock in one shot");
2039
		    DEBUGF("FTL: Going to write a full hyperblock in one shot");
Line 2045... Line 2048...
2045
                ftl_release_pool_block(vblock);
2048
                ftl_release_pool_block(vblock);
2046
                vblock = ftl_allocate_pool_block();
2049
                vblock = ftl_allocate_pool_block();
2047
                if (vblock == 0xFFFFFFFF)
2050
                if (vblock == 0xFFFFFFFF)
2048
                {
2051
                {
2049
                    mutex_unlock(&ftl_mtx);
2052
                    mutex_unlock(&ftl_mtx);
2050
                    return 1;
2053
                    return -6;
2051
                }
2054
                }
2052
            }
2055
            }
2053
            ftl_cxt.nextblockusn++;
2056
            ftl_cxt.nextblockusn++;
2054
            for (j = 0; j < ppb; j += FTL_WRITESPARE_SIZE)
2057
            for (j = 0; j < ppb; j += FTL_WRITESPARE_SIZE)
2055
            {
2058
            {
Line 2087... Line 2090...
2087
                ftl_remove_scattered_block(logentry);
2090
                ftl_remove_scattered_block(logentry);
2088
                logentry = ftl_allocate_log_entry(block);
2091
                logentry = ftl_allocate_log_entry(block);
2089
                if (logentry == (struct ftl_log_type*)0)
2092
                if (logentry == (struct ftl_log_type*)0)
2090
                {
2093
                {
2091
                    mutex_unlock(&ftl_mtx);
2094
                    mutex_unlock(&ftl_mtx);
2092
                    return 1;
2095
                    return -7;
2093
                }
2096
                }
2094
            }
2097
            }
2095
            uint32_t cnt = FTL_WRITESPARE_SIZE;
2098
            uint32_t cnt = FTL_WRITESPARE_SIZE;
2096
            if (cnt > count - i) cnt = count - i;
2099
            if (cnt > count - i) cnt = count - i;
2097
            if (cnt > ppb - logentry->pagesused) cnt = ppb - logentry->pagesused;
2100
            if (cnt > ppb - logentry->pagesused) cnt = ppb - logentry->pagesused;
Line 2184... Line 2187...
2184
        else rc |= ftl_commit_scattered(&ftl_log[i]);
2187
        else rc |= ftl_commit_scattered(&ftl_log[i]);
2185
    }
2188
    }
2186
    if (rc != 0)
2189
    if (rc != 0)
2187
    {
2190
    {
2188
        mutex_unlock(&ftl_mtx);
2191
        mutex_unlock(&ftl_mtx);
2189
        return 1;
2192
        return -1;
2190
    }
2193
    }
2191
    for (i = 0; i < 5; i++)
2194
    for (i = 0; i < 5; i++)
2192
        if (ftl_commit_cxt() == 0)
2195
        if (ftl_commit_cxt() == 0)
2193
        {
2196
        {
2194
            mutex_unlock(&ftl_mtx);
2197
            mutex_unlock(&ftl_mtx);
2195
            return 0;
2198
            return 0;
2196
        }
2199
        }
2197
        else ftl_cxt.ftlctrlpage |= ppb - 1;
2200
        else ftl_cxt.ftlctrlpage |= ppb - 1;
2198
    mutex_unlock(&ftl_mtx);
2201
    mutex_unlock(&ftl_mtx);
2199
    return 1;
2202
    return -2;
2200
}
2203
}
2201
#endif
2204
#endif
2202
 
2205
 
2203
 
2206
 
2204
/* Block allocator for FTL recovery */
2207
/* Block allocator for FTL recovery */
Line 2545... Line 2548...
2545
    repaired = 0;
2548
    repaired = 0;
2546
    skip = 0;
2549
    skip = 0;
2547
    if (founddevinfo == 0)
2550
    if (founddevinfo == 0)
2548
    {
2551
    {
2549
	   	DEBUGF("FTL: No DEVICEINFO found!");
2552
	   	DEBUGF("FTL: No DEVICEINFO found!");
2550
        return 1;
2553
        return -1;
2551
    }
2554
    }
2552
    if (foundsignature != 0 && (result & 0x11F) != 0)
2555
    if (foundsignature != 0 && (result & 0x11F) != 0)
2553
    {
2556
    {
2554
        DEBUGF("FTL: Problem with the signature!");
2557
        DEBUGF("FTL: Problem with the signature!");
2555
        return 1;
2558
        return -2;
2556
    }
2559
    }
2557
    if (ftl_vfl_open() == 0)
2560
    if (ftl_vfl_open() == 0)
2558
	{
2561
	{
2559
        if (ftl_open() == 0)
2562
        if (ftl_open() == 0)
2560
        {
2563
        {
Line 2577... Line 2580...
2577
		}
2580
		}
2578
	}
2581
	}
2579
 
2582
 
2580
    DEBUGF("FTL: Initialization failed!");
2583
    DEBUGF("FTL: Initialization failed!");
2581
 
2584
 
2582
    return 1;
2585
    return -3;
2583
}
2586
}