Subversion Repositories freemyipod

Rev

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

Rev 427 Rev 435
Line 415... Line 415...
415
 
415
 
416
/* Needed to store the old scattered page offsets in order to be able to roll
416
/* Needed to store the old scattered page offsets in order to be able to roll
417
   back if something fails while compacting a scattered page block. */
417
   back if something fails while compacting a scattered page block. */
418
static uint16_t ftl_offsets_backup[0x200] CACHEALIGN_ATTR;
418
static uint16_t ftl_offsets_backup[0x200] CACHEALIGN_ATTR;
419
 
419
 
-
 
420
struct nandfsck_bss  /* This will be malloc()ed if needed */
-
 
421
{
420
/* Buffers needed for FTL recovery */
422
    /* Buffers needed for FTL recovery */
421
static uint32_t blk_usn[0x2000] INITBSS_ATTR;
423
    uint32_t blk_usn[0x2000];
422
static uint8_t blk_type[0x2000] INITBSS_ATTR;
424
    int8_t blk_type[0x2000];
423
static uint32_t erasectr_usn[8] INITBSS_ATTR;
425
    uint32_t erasectr_usn[8];
424
static uint32_t pageusn[0x200] INITBSS_ATTR;
426
    uint32_t pageusn[0x200];
425
static uint8_t pagedata[0x200][0x800] INITBSS_ATTR CACHEALIGN_ATTR;
427
    uint8_t pagedata[0x200][0x800];
426
 
428
 
427
/* State information needed for FTL recovery */
429
    /* State information needed for FTL recovery */
428
static uint32_t meta_usn INITBSS_ATTR;
430
    uint32_t meta_usn;
429
static uint32_t user_usn INITBSS_ATTR;
431
    uint32_t user_usn;
430
static uint32_t allocmode INITBSS_ATTR;
432
    uint32_t allocmode;
431
static uint32_t firstfree INITBSS_ATTR;
433
    uint32_t firstfree;
432
 
434
};
433
#endif
435
#endif
434
 
436
 
435
 
437
 
436
static struct mutex ftl_mtx;
438
static struct mutex ftl_mtx;
437
bool ftl_initialized = false;
439
bool ftl_initialized = false;
Line 2234... Line 2236...
2234
}
2236
}
2235
#endif
2237
#endif
2236
 
2238
 
2237
 
2239
 
2238
/* Block allocator for FTL recovery */
2240
/* Block allocator for FTL recovery */
2239
static uint32_t ftl_alloc_block() INITCODE_ATTR;
2241
static uint32_t ftl_alloc_block(struct nandfsck_bss* nb) INITCODE_ATTR;
2240
static uint32_t ftl_alloc_block()
2242
static uint32_t ftl_alloc_block(struct nandfsck_bss* nb)
2241
{
2243
{
2242
    while (1)
2244
    while (1)
2243
    {
2245
    {
2244
        for (; firstfree < ftl_nand_type->userblocks + 0x17; firstfree++)
2246
        for (; nb->firstfree < ftl_nand_type->userblocks + 0x17; nb->firstfree++)
2245
            if (!blk_type[firstfree]) break;
2247
            if (!nb->blk_type[nb->firstfree]) break;
2246
            else if (allocmode && blk_type[firstfree] != 1)
2248
            else if (nb->allocmode && nb->blk_type[nb->firstfree] != 1)
2247
            {
2249
            {
2248
                if (ftl_erase_block(firstfree))
2250
                if (ftl_erase_block(nb->firstfree))
2249
                {
2251
                {
2250
                    cprintf(CONSOLE_BOOT, "Couldn't erase vBlock %d (pool alloc)!\n", firstfree);
2252
                    cprintf(CONSOLE_BOOT, "Couldn't erase vBlock %d (pool alloc)!\n",
-
 
2253
                            nb->firstfree);
2251
                    return 1;
2254
                    return 1;
2252
                }
2255
                }
2253
                break;
2256
                break;
2254
            }
2257
            }
2255
        if (firstfree < ftl_nand_type->userblocks + 0x17)
2258
        if (nb->firstfree < ftl_nand_type->userblocks + 0x17)
2256
        {
2259
        {
2257
            blk_type[firstfree] = 1;
2260
            nb->blk_type[nb->firstfree] = 1;
2258
            return firstfree++;
2261
            return nb->firstfree++;
2259
        }
2262
        }
2260
        if (!allocmode)
2263
        if (!nb->allocmode)
2261
        {
2264
        {
2262
            allocmode = 1;
2265
            nb->allocmode = 1;
2263
            firstfree = 0;
2266
            nb->firstfree = 0;
2264
        }
2267
        }
2265
        else
2268
        else
2266
        {
2269
        {
2267
            cputs(CONSOLE_BOOT, "Out of empty blocks!\n");
2270
            cputs(CONSOLE_BOOT, "Out of empty blocks!\n");
2268
            return 1;
2271
            return 1;
Line 2277... Line 2280...
2277
    uint32_t i, j, k;
2280
    uint32_t i, j, k;
2278
#ifdef HAVE_LCD
2281
#ifdef HAVE_LCD
2279
    struct progressbar_state progressbar;
2282
    struct progressbar_state progressbar;
2280
#endif
2283
#endif
2281
 
2284
 
-
 
2285
    struct nandfsck_bss* nb = (struct nandfsck_bss*)memalign(0x10, sizeof(struct nandfsck_bss));
-
 
2286
 
2282
    cputs(CONSOLE_BOOT, "Scanning flash...\n");
2287
    cputs(CONSOLE_BOOT, "Scanning flash...\n");
2283
#ifdef HAVE_LCD
2288
#ifdef HAVE_LCD
2284
    lcdconsole_progressbar(&progressbar, 0, ftl_nand_type->userblocks + 0x17);
2289
    lcdconsole_progressbar(&progressbar, 0, ftl_nand_type->userblocks + 0x17);
2285
#endif
2290
#endif
2286
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
2291
    uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
2287
    memset(&ftl_cxt, 0x00, sizeof(ftl_cxt));
2292
    memset(&ftl_cxt, 0x00, sizeof(ftl_cxt));
2288
    memset(ftl_map, 0xff, sizeof(ftl_map));
2293
    memset(ftl_map, 0xff, sizeof(ftl_map));
2289
    memset(blk_usn, 0x00, sizeof(blk_usn));
2294
    memset(nb->blk_usn, 0x00, sizeof(nb->blk_usn));
2290
    memset(blk_type, 0x00, sizeof(blk_type));
2295
    memset(nb->blk_type, 0x00, sizeof(nb->blk_type));
2291
    memset(ftl_erasectr, 0x00, sizeof(ftl_erasectr));
2296
    memset(ftl_erasectr, 0x00, sizeof(ftl_erasectr));
2292
    memset(erasectr_usn, 0xff, sizeof(erasectr_usn));
2297
    memset(nb->erasectr_usn, 0xff, sizeof(nb->erasectr_usn));
2293
    user_usn = 0;
2298
    nb->user_usn = 0;
2294
    meta_usn = 0xffffffff;
2299
    nb->meta_usn = 0xffffffff;
2295
    for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2300
    for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2296
    {
2301
    {
2297
        uint32_t ret = ftl_vfl_read((i + 1) * ppb - 1, 0, &ftl_sparebuffer[0], 1, 0);
2302
        uint32_t ret = ftl_vfl_read((i + 1) * ppb - 1, 0, &ftl_sparebuffer[0], 1, 0);
2298
        if ((ret & 0x11F) == 0 && ftl_sparebuffer[0].meta.type == 0x41)
2303
        if ((ret & 0x11F) == 0 && ftl_sparebuffer[0].meta.type == 0x41)
2299
        {
2304
        {
2300
            uint32_t lbn = ftl_sparebuffer[0].user.lpn / ppb;
2305
            uint32_t lbn = ftl_sparebuffer[0].user.lpn / ppb;
2301
            if (ftl_sparebuffer[0].user.usn > user_usn)
2306
            if (ftl_sparebuffer[0].user.usn > nb->user_usn)
2302
                user_usn = ftl_sparebuffer[0].user.usn;
2307
                nb->user_usn = ftl_sparebuffer[0].user.usn;
2303
            if (ftl_sparebuffer[0].user.usn > blk_usn[lbn])
2308
            if (ftl_sparebuffer[0].user.usn > nb->blk_usn[lbn])
2304
            {
2309
            {
2305
                if (ftl_map[lbn] != 0xffff)
2310
                if (ftl_map[lbn] != 0xffff)
2306
                    blk_type[ftl_map[lbn]] = 5;
2311
                    nb->blk_type[ftl_map[lbn]] = 5;
2307
                blk_usn[lbn] = ftl_sparebuffer[0].user.usn;
2312
                nb->blk_usn[lbn] = ftl_sparebuffer[0].user.usn;
2308
                ftl_map[lbn] = i;
2313
                ftl_map[lbn] = i;
2309
                blk_type[i] = 1;
2314
                nb->blk_type[i] = 1;
2310
            }
2315
            }
2311
            else blk_type[i] = 5;
2316
            else nb->blk_type[i] = 5;
2312
        }
2317
        }
2313
        else
2318
        else
2314
            for (j = 0; j < ppb; j++)
2319
            for (j = 0; j < ppb; j++)
2315
            {
2320
            {
2316
                ret = ftl_vfl_read(i * ppb + j, ftl_buffer, &ftl_sparebuffer[0], 1, 0);
2321
                ret = ftl_vfl_read(i * ppb + j, ftl_buffer, &ftl_sparebuffer[0], 1, 0);
2317
                if (ret & 2) break;
2322
                if (ret & 2) break;
2318
                if (ret & 0x11F)
2323
                if (ret & 0x11F)
2319
                {
2324
                {
2320
                    blk_type[i] = 4;
2325
                    nb->blk_type[i] = 4;
2321
                    continue;
2326
                    continue;
2322
                }
2327
                }
2323
                if (ftl_sparebuffer[0].meta.type == 0x40)
2328
                if (ftl_sparebuffer[0].meta.type == 0x40)
2324
                {
2329
                {
2325
                    blk_type[i] = 2;
2330
                    nb->blk_type[i] = 2;
2326
                    break;
2331
                    break;
2327
                }
2332
                }
2328
                else if (ftl_sparebuffer[0].meta.type - 0x43 <= 4)
2333
                else if (ftl_sparebuffer[0].meta.type - 0x43 <= 4)
2329
                {
2334
                {
2330
                    blk_type[i] = 3;
2335
                    nb->blk_type[i] = 3;
2331
                    if (ftl_sparebuffer[0].meta.type == 0x46)
2336
                    if (ftl_sparebuffer[0].meta.type == 0x46)
2332
                    {
2337
                    {
2333
                        uint32_t idx = ftl_sparebuffer[0].meta.idx;
2338
                        uint32_t idx = ftl_sparebuffer[0].meta.idx;
2334
                        if (ftl_sparebuffer[0].meta.usn < meta_usn)
2339
                        if (ftl_sparebuffer[0].meta.usn < nb->meta_usn)
2335
                            meta_usn = ftl_sparebuffer[0].meta.usn;
2340
                            nb->meta_usn = ftl_sparebuffer[0].meta.usn;
2336
                        if (ftl_sparebuffer[0].meta.usn < erasectr_usn[idx])
2341
                        if (ftl_sparebuffer[0].meta.usn < nb->erasectr_usn[idx])
2337
                        {
2342
                        {
2338
                            erasectr_usn[idx] = ftl_sparebuffer[0].meta.usn;
2343
                            nb->erasectr_usn[idx] = ftl_sparebuffer[0].meta.usn;
2339
                            ret = ftl_vfl_read(i * ppb + j, &ftl_erasectr[idx << 10],
2344
                            ret = ftl_vfl_read(i * ppb + j, &ftl_erasectr[idx << 10],
2340
                                               &ftl_sparebuffer[0], 1, 0);
2345
                                               &ftl_sparebuffer[0], 1, 0);
2341
                            if (ret & 0x11f) memset(&ftl_erasectr[idx << 10], 0, 0x800);
2346
                            if (ret & 0x11f) memset(&ftl_erasectr[idx << 10], 0, 0x800);
2342
                        }
2347
                        }
2343
                    }
2348
                    }
Line 2364... Line 2369...
2364
                                    ftl_vfl_cxt[j].remaptable[i], ftl_vfl_cxt[j].firstspare + i);
2369
                                    ftl_vfl_cxt[j].remaptable[i], ftl_vfl_cxt[j].firstspare + i);
2365
                            if (ftl_vfl_is_good_block(j, i) != 1) cprintf(CONSOLE_BOOT, "(NOT IN BBT) ");
2370
                            if (ftl_vfl_is_good_block(j, i) != 1) cprintf(CONSOLE_BOOT, "(NOT IN BBT) ");
2366
                        }
2371
                        }
2367
                    }
2372
                    }
2368
                    cprintf(CONSOLE_BOOT, "\n");
2373
                    cprintf(CONSOLE_BOOT, "\n");
-
 
2374
                    free(nb);
2369
                    return 1;
2375
                    return 1;
2370
                }
2376
                }
2371
            }
2377
            }
2372
#ifdef HAVE_LCD
2378
#ifdef HAVE_LCD
2373
        progressbar_setpos(&progressbar, i + 1, false);
2379
        progressbar_setpos(&progressbar, i + 1, false);
Line 2389... Line 2395...
2389
            ftl_erasectr[i] = average;
2395
            ftl_erasectr[i] = average;
2390
 
2396
 
2391
    cputs(CONSOLE_BOOT, "Committing scattered pages...\n");
2397
    cputs(CONSOLE_BOOT, "Committing scattered pages...\n");
2392
    count = 0;
2398
    count = 0;
2393
    for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2399
    for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2394
        if (blk_type[i] == 2) count++;
2400
        if (nb->blk_type[i] == 2) count++;
2395
    uint32_t block;
2401
    uint32_t block;
2396
    uint32_t dirty;
2402
    uint32_t dirty;
2397
    if (count)
2403
    if (count)
2398
    {
2404
    {
2399
#ifdef HAVE_LCD
2405
#ifdef HAVE_LCD
2400
        lcdconsole_progressbar(&progressbar, 0, count * ppb * 2);
2406
        lcdconsole_progressbar(&progressbar, 0, count * ppb * 2);
2401
#endif
2407
#endif
2402
        count = 0;
2408
        count = 0;
2403
        for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2409
        for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
2404
            if (blk_type[i] == 2)
2410
            if (nb->blk_type[i] == 2)
2405
            {
2411
            {
2406
                block = 0xffff;
2412
                block = 0xffff;
2407
                for (j = 0; j < ppb; j++)
2413
                for (j = 0; j < ppb; j++)
2408
                {
2414
                {
2409
#ifdef HAVE_LCD
2415
#ifdef HAVE_LCD
Line 2415... Line 2421...
2415
                    if (ftl_sparebuffer[0].user.type != 0x40)
2421
                    if (ftl_sparebuffer[0].user.type != 0x40)
2416
                    {
2422
                    {
2417
                        cprintf(CONSOLE_BOOT, "Invalid block type %02X while reading "
2423
                        cprintf(CONSOLE_BOOT, "Invalid block type %02X while reading "
2418
                                              "vPage %d (scattered page)!\n",
2424
                                              "vPage %d (scattered page)!\n",
2419
                                ftl_sparebuffer[0].meta.type, i * ppb + j);
2425
                                ftl_sparebuffer[0].meta.type, i * ppb + j);
-
 
2426
                        free(nb);
2420
                        return 1;
2427
                        return 1;
2421
                    }
2428
                    }
2422
                    if (block == 0xffff)
2429
                    if (block == 0xffff)
2423
                    {
2430
                    {
2424
                        block = ftl_sparebuffer[0].user.lpn / ppb;
2431
                        block = ftl_sparebuffer[0].user.lpn / ppb;
2425
                        memset(pageusn, 0x00, 0x800);
2432
                        memset(nb->pageusn, 0x00, 0x800);
2426
                        memset(pagedata, 0x00, 0x100000);
2433
                        memset(nb->pagedata, 0x00, 0x100000);
2427
                        if (ftl_map[block] != 0xffff)
2434
                        if (ftl_map[block] != 0xffff)
2428
                            for (k = 0; k < ppb; k++)
2435
                            for (k = 0; k < ppb; k++)
2429
                            {
2436
                            {
2430
                                uint32_t ret = ftl_vfl_read(ftl_map[block] * ppb + k, pagedata[k],
2437
                                uint32_t ret = ftl_vfl_read(ftl_map[block] * ppb + k, nb->pagedata[k],
2431
                                                            &ftl_copyspare[0], 1, 0);
2438
                                                            &ftl_copyspare[0], 1, 0);
2432
                                if (ret & 0x11F) continue;
2439
                                if (ret & 0x11F) continue;
2433
                                if (ftl_copyspare[0].user.type != 0x40
2440
                                if (ftl_copyspare[0].user.type != 0x40
2434
                                 && ftl_copyspare[0].user.type != 0x41)
2441
                                 && ftl_copyspare[0].user.type != 0x41)
2435
                                {
2442
                                {
2436
                                    cprintf(CONSOLE_BOOT, "Invalid block type %02X while reading "
2443
                                    cprintf(CONSOLE_BOOT, "Invalid block type %02X while reading "
2437
                                                          "vPage %d (scattered page orig)!\n",
2444
                                                          "vPage %d (scattered page orig)!\n",
2438
                                            ftl_sparebuffer[0].meta.type,
2445
                                            ftl_sparebuffer[0].meta.type,
2439
                                            ftl_map[block] * ppb + k);
2446
                                            ftl_map[block] * ppb + k);
-
 
2447
                                    free(nb);
2440
                                    return 1;
2448
                                    return 1;
2441
                                }
2449
                                }
2442
                                if (block != ftl_copyspare[0].user.lpn / ppb)
2450
                                if (block != ftl_copyspare[0].user.lpn / ppb)
2443
                                {
2451
                                {
2444
                                    cprintf(CONSOLE_BOOT, "Foreign page in scattered page orig "
2452
                                    cprintf(CONSOLE_BOOT, "Foreign page in scattered page orig "
2445
                                                          "block (vPage %d, LPN %d)!\n",
2453
                                                          "block (vPage %d, LPN %d)!\n",
2446
                                            ftl_map[block] * ppb + k,
2454
                                            ftl_map[block] * ppb + k,
2447
                                            ftl_sparebuffer[0].user.usn);
2455
                                            ftl_sparebuffer[0].user.usn);
-
 
2456
                                    free(nb);
2448
                                    return 1;
2457
                                    return 1;
2449
                                }
2458
                                }
2450
                                pageusn[k] = ftl_copyspare[0].user.usn;
2459
                                nb->pageusn[k] = ftl_copyspare[0].user.usn;
2451
                            }
2460
                            }
2452
                        dirty = 0;
2461
                        dirty = 0;
2453
                    }
2462
                    }
2454
                    if (block != ftl_sparebuffer[0].user.lpn / ppb)
2463
                    if (block != ftl_sparebuffer[0].user.lpn / ppb)
2455
                    {
2464
                    {
2456
                        cprintf(CONSOLE_BOOT, "Foreign page in scattered page block "
2465
                        cprintf(CONSOLE_BOOT, "Foreign page in scattered page block "
2457
                                              "block (vPage %d, LPN %d)!\n",
2466
                                              "block (vPage %d, LPN %d)!\n",
2458
                                i * ppb + j, ftl_sparebuffer[0].user.lpn);
2467
                                i * ppb + j, ftl_sparebuffer[0].user.lpn);
-
 
2468
                        free(nb);
2459
                        return 1;
2469
                        return 1;
2460
                    }
2470
                    }
2461
                    uint32_t idx = ftl_sparebuffer[0].user.lpn % ppb;
2471
                    uint32_t idx = ftl_sparebuffer[0].user.lpn % ppb;
2462
                    if (ftl_sparebuffer[0].user.usn > user_usn)
2472
                    if (ftl_sparebuffer[0].user.usn > nb->user_usn)
2463
                        user_usn = ftl_sparebuffer[0].user.usn;
2473
                        nb->user_usn = ftl_sparebuffer[0].user.usn;
2464
                    if (ftl_sparebuffer[0].user.usn > pageusn[idx])
2474
                    if (ftl_sparebuffer[0].user.usn > nb->pageusn[idx])
2465
                    {
2475
                    {
2466
                        pageusn[idx] = ftl_sparebuffer[0].user.usn;
2476
                        nb->pageusn[idx] = ftl_sparebuffer[0].user.usn;
2467
                        memcpy(pagedata[idx], ftl_buffer, 0x800);
2477
                        memcpy(nb->pagedata[idx], ftl_buffer, 0x800);
2468
                        dirty = 1;
2478
                        dirty = 1;
2469
                    }
2479
                    }
2470
                }
2480
                }
2471
                if (dirty)
2481
                if (dirty)
2472
                {
2482
                {
2473
                    if (ftl_erase_block(i))
2483
                    if (ftl_erase_block(i))
2474
                    {
2484
                    {
2475
                        cprintf(CONSOLE_BOOT, "Couldn't erase vBlock %d "
2485
                        cprintf(CONSOLE_BOOT, "Couldn't erase vBlock %d "
2476
                                              "(scattered page commit)!\n", i);
2486
                                              "(scattered page commit)!\n", i);
-
 
2487
                        free(nb);
2477
                        return 1;
2488
                        return 1;
2478
                    }
2489
                    }
2479
                    for (j = 0; j < ppb; j++)
2490
                    for (j = 0; j < ppb; j++)
2480
                    {
2491
                    {
2481
#ifdef HAVE_LCD
2492
#ifdef HAVE_LCD
2482
                        progressbar_setpos(&progressbar, count * ppb * 2 + ppb + j, false);
2493
                        progressbar_setpos(&progressbar, count * ppb * 2 + ppb + j, false);
2483
#endif
2494
#endif
2484
                        memset(&ftl_sparebuffer[0], 0xFF, 0x40);
2495
                        memset(&ftl_sparebuffer[0], 0xFF, 0x40);
2485
                        ftl_sparebuffer[0].user.lpn = block * ppb + j;
2496
                        ftl_sparebuffer[0].user.lpn = block * ppb + j;
2486
                        ftl_sparebuffer[0].user.usn = pageusn[j];
2497
                        ftl_sparebuffer[0].user.usn = nb->pageusn[j];
2487
                        ftl_sparebuffer[0].user.type = 0x40;
2498
                        ftl_sparebuffer[0].user.type = 0x40;
2488
                        if (j == ppb - 1) ftl_sparebuffer[0].user.type = 0x41;
2499
                        if (j == ppb - 1) ftl_sparebuffer[0].user.type = 0x41;
2489
                        if (ftl_vfl_write(i * ppb + j, 1, pagedata[j], &ftl_sparebuffer[0]))
2500
                        if (ftl_vfl_write(i * ppb + j, 1, nb->pagedata[j], &ftl_sparebuffer[0]))
2490
                        {
2501
                        {
2491
                            cprintf(CONSOLE_BOOT, "Couldn't write vPage %d "
2502
                            cprintf(CONSOLE_BOOT, "Couldn't write vPage %d "
2492
                                                  "(scattered page commit)!\n", i * ppb + j);
2503
                                                  "(scattered page commit)!\n", i * ppb + j);
-
 
2504
                            free(nb);
2493
                            return 1;
2505
                            return 1;
2494
                        }
2506
                        }
2495
                    }
2507
                    }
2496
                    if (ftl_map[block] != 0xffff) blk_type[ftl_map[block]] = 5;
2508
                    if (ftl_map[block] != 0xffff) nb->blk_type[ftl_map[block]] = 5;
2497
                    blk_type[i] = 1;
2509
                    nb->blk_type[i] = 1;
2498
                    ftl_map[block] = i;
2510
                    ftl_map[block] = i;
2499
                }
2511
                }
2500
                else blk_type[i] = 5;
2512
                else nb->blk_type[i] = 5;
2501
#ifdef HAVE_LCD
2513
#ifdef HAVE_LCD
2502
                progressbar_setpos(&progressbar, ++count * ppb * 2, false);
2514
                progressbar_setpos(&progressbar, ++count * ppb * 2, false);
2503
#endif
2515
#endif
2504
            }
2516
            }
2505
    }
2517
    }
2506
 
2518
 
2507
    cputs(CONSOLE_BOOT, "Fixing block map...\n");
2519
    cputs(CONSOLE_BOOT, "Fixing block map...\n");
2508
    allocmode = 0;
2520
    nb->allocmode = 0;
2509
    firstfree = 0;
2521
    nb->firstfree = 0;
2510
    for (i = 0; i < 3; i++) ftl_cxt.ftlctrlblocks[i] = ftl_alloc_block();
2522
    for (i = 0; i < 3; i++) ftl_cxt.ftlctrlblocks[i] = ftl_alloc_block(nb);
2511
    for (i = 0; i < 20; i++) ftl_cxt.blockpool[i] = ftl_alloc_block();
2523
    for (i = 0; i < 20; i++) ftl_cxt.blockpool[i] = ftl_alloc_block(nb);
2512
    for (i = 0; i < ftl_nand_type->userblocks; i++)
2524
    for (i = 0; i < ftl_nand_type->userblocks; i++)
2513
        if (ftl_map[i] == 0xffff)
2525
        if (ftl_map[i] == 0xffff)
2514
            ftl_map[i] = ftl_alloc_block();
2526
            ftl_map[i] = ftl_alloc_block(nb);
2515
    ftl_cxt.usn = meta_usn - 1;
2527
    ftl_cxt.usn = nb->meta_usn - 1;
2516
    ftl_cxt.nextblockusn = user_usn + 1;
2528
    ftl_cxt.nextblockusn = nb->user_usn + 1;
2517
    ftl_cxt.freecount = 20;
2529
    ftl_cxt.freecount = 20;
2518
    ftl_cxt.clean_flag = 1;
2530
    ftl_cxt.clean_flag = 1;
-
 
2531
    free(nb);
2519
 
2532
 
2520
    cputs(CONSOLE_BOOT, "Committing FTL context...\n");
2533
    cputs(CONSOLE_BOOT, "Committing FTL context...\n");
2521
    uint32_t blockmappages = ftl_nand_type->userblocks >> 10;
2534
    uint32_t blockmappages = ftl_nand_type->userblocks >> 10;
2522
    if ((ftl_nand_type->userblocks & 0x1FF) != 0) blockmappages++;
2535
    if ((ftl_nand_type->userblocks & 0x1FF) != 0) blockmappages++;
2523
    uint32_t erasectrpages = (ftl_nand_type->userblocks + 23) >> 10;
2536
    uint32_t erasectrpages = (ftl_nand_type->userblocks + 23) >> 10;