freemyipod r223 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r222‎ | r223 | r224 >
Date:02:18, 24 October 2010
Author:theseven
Status:new
Tags:
Comment:
iPod Nano 2G FTL: Fix nandfsck memory corruption bug and remove some dead code
Modified paths:
  • /embios/trunk/target/ipodnano2g/ftl.c (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/ftl.c
@@ -2253,12 +2253,12 @@
22542254 lcdconsole_progressbar(&progressbar, 0, ftl_nand_type->userblocks + 0x17);
22552255 #endif
22562256 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
2257 - memset(&ftl_cxt, 0x00, 0x800);
2258 - memset(ftl_map, 0xff, 0x4000);
2259 - memset(blk_usn, 0x00, 0x8000);
2260 - memset(blk_type, 0x00, 0x2000);
2261 - memset(ftl_erasectr, 0x00, 0x4000);
2262 - memset(erasectr_usn, 0xff, 32);
 2257+ memset(&ftl_cxt, 0x00, sizeof(ftl_cxt));
 2258+ memset(ftl_map, 0xff, sizeof(ftl_map));
 2259+ memset(blk_usn, 0x00, sizeof(blk_usn));
 2260+ memset(blk_type, 0x00, sizeof(blk_type));
 2261+ memset(ftl_erasectr, 0x00, sizeof(ftl_erasectr));
 2262+ memset(erasectr_usn, 0xff, sizeof(erasectr_usn));
22632263 user_usn = 0;
22642264 meta_usn = 0xffffffff;
22652265 for (i = 0; i < ftl_nand_type->userblocks + 0x17; i++)
@@ -2521,44 +2521,19 @@
25222522 if (ftl_initialized) return 0;
25232523 mutex_init(&ftl_mtx);
25242524 uint32_t i;
2525 - uint32_t result = 0;
2526 - uint32_t foundsignature, founddevinfo, blockwiped, repaired, skip;
25272525 int rc;
2528 - if ((rc = nand_device_init()) != 0) //return 1;
 2526+ if ((rc = nand_device_init()) != 0)
25292527 panicf(PANIC_FATAL, "FTL: Lowlevel NAND driver init failed: %d", rc);
25302528 ftl_banks = 0;
25312529 for (i = 0; i < 4; i++)
25322530 if (nand_get_device_type(i) != 0) ftl_banks = i + 1;
25332531 ftl_nand_type = nand_get_device_type(0);
2534 - foundsignature = 0;
2535 - blockwiped = 1;
2536 - for (i = 0; i < ftl_nand_type->pagesperblock; i++)
2537 - {
2538 - result = nand_read_page(0, i, ftl_buffer, NULL, 1, 1);
2539 - if ((result & 0x11F) == 0)
2540 - {
2541 - blockwiped = 0;
2542 - if (((uint32_t*)ftl_buffer)[0] != 0x41303034) continue;
2543 - foundsignature = 1;
2544 - break;
2545 - }
2546 - else if ((result & 2) != 2) blockwiped = 0;
2547 - }
25482532
2549 - founddevinfo = ftl_has_devinfo();
2550 -
2551 - repaired = 0;
2552 - skip = 0;
2553 - if (founddevinfo == 0)
 2533+ if (!ftl_has_devinfo())
25542534 {
25552535 DEBUGF("FTL: No DEVICEINFO found!");
25562536 return -1;
25572537 }
2558 - if (foundsignature != 0 && (result & 0x11F) != 0)
2559 - {
2560 - DEBUGF("FTL: Problem with the signature!");
2561 - return -2;
2562 - }
25632538 if (ftl_vfl_open() == 0)
25642539 {
25652540 if (ftl_open() == 0)
@@ -2584,5 +2559,5 @@
25852560
25862561 DEBUGF("FTL: Initialization failed!");
25872562
2588 - return -3;
 2563+ return -2;
25892564 }