int VFL_Verify(void) { int i; int foundSignature = false; LOGDBG("ftl: Attempting to read %d pages from first block of first bank.\n", NANDGeometry->pagesPerBlock); for(i = 0; i < NANDGeometry->pagesPerBlock; i++) { int ret; if((ret = nand_read_alternate_ecc(0, i, PageBuffer)) == 0) { u32 id = *((u32*) PageBuffer); if(id == FTL_ID_V1 || id == FTL_ID_V2 || id == FTL_ID_V3) { LOG("ftl: Found production format: %x\n", id); foundSignature = true; break; } else { LOGDBG("ftl: Found non-matching signature: %x\n", ((u32*) PageBuffer)); } } else { LOGDBG("ftl: page %d of first bank is unreadable: %x!\n", i, ret); } } if(!foundSignature || !hasDeviceInfoBBT()) { LOG("ftl: no signature or production format.\n"); return -1; } return 0; }
int ftl_setup() { if(HasFTLInit) return 0; nand_setup(); Data = nand_get_geometry(); Data2 = nand_get_data(); if(VFL_Init() != 0) { bufferPrintf("ftl: VFL_Init failed\r\n"); return -1; } if(FTL_Init() != 0) { bufferPrintf("ftl: FTL_Init failed\r\n"); return -1; } int i; int foundSignature = FALSE; DebugPrintf("ftl: Attempting to read %d pages from first block of first bank.\r\n", Data->pagesPerBlock); uint8_t* buffer = malloc(Data->bytesPerPage); for(i = 0; i < Data->pagesPerBlock; i++) { int ret; if((ret = nand_read_alternate_ecc(0, i, buffer)) == 0) { uint32_t id = *((uint32_t*) buffer); if(id == FTL_ID_V1 || id == FTL_ID_V2) { bufferPrintf("ftl: Found production format: %x\r\n", id); foundSignature = TRUE; break; } else { DebugPrintf("ftl: Found non-matching signature: %x\r\n", ((uint32_t*) buffer)); } } else { DebugPrintf("ftl: page %d of first bank is unreadable: %x!\r\n", i, ret); } } free(buffer); if(!foundSignature || !hasDeviceInfoBBT()) { bufferPrintf("ftl: no signature or production format.\r\n"); return -1; } if(VFL_Open() != 0) { bufferPrintf("ftl: VFL_Open failed\r\n"); return -1; } int pagesAvailable; int bytesPerPage; if(FTL_Open(&pagesAvailable, &bytesPerPage) != 0) { bufferPrintf("ftl: FTL_Open failed\r\n"); return -1; } HasFTLInit = TRUE; return 0; }