static int __init ecc_test_init(void)
{
	srandom32(jiffies);

	nand_ecc_test(256);
	nand_ecc_test(512);

	return 0;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
//
//  Function:  DFT_IOControl
//
//  This function sends a command to a device.
//
BOOL DFT_IOControl(
    DWORD context, DWORD dwCode,
    BYTE *pInBuffer, DWORD inSize,
    BYTE *pOutBuffer, DWORD outSize, DWORD *pOutSize)
{
    NANDTEST_CONTEXT *pContext = (NANDTEST_CONTEXT *)context;
    HANDLE hFMD;
    PCI_REG_INFO regInfo;
    FlashInfo flashInfo;
    DWORD sector,block; 
    BOOL rc=FALSE;
    UCHAR p_goodata[SECTOR_SIZE*2];

    UNREFERENCED_PARAMETER(pOutSize); 

    DEBUGMSG(ZONE_FUNCTION,
             (L"+DFT_IOControl(0x%08x, 0x%08x, 0x%08x, %d, 0x%08x, %d, 0x%08x)\r\n",
              context, dwCode, pInBuffer, inSize, pOutBuffer, outSize, pOutSize));

    regInfo.MemBase.Reg[0] = OMAP_GPMC_REGS_PA;
    regInfo.MemLen.Reg[0] = 0x00001000;
    regInfo.MemBase.Reg[1] = BSP_NAND_REGS_PA;
    regInfo.MemLen.Reg[1] = 0x00001000;
	
    hFMD  = FMD_Init(NULL, &regInfo, NULL);
    if (hFMD  == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (L"ERROR: FMD_Init call failed!\r\n"));
        goto cleanUp;
    }

    switch (dwCode)
    {
        case NAND_SET_SECTOR:
            // Checking parameter
            if (pInBuffer == NULL || inSize < sizeof(DWORD))
            {
                DEBUGMSG(ZONE_ERROR, (L"+DFT_IOControl(%d): ERROR - invalid parameters\r\n", dwCode));
                goto cleanUp;
            }
            // Get flash info
            if (!FMD_GetInfo(&flashInfo))
            {
                DEBUGMSG(ZONE_ERROR,  (L"ERROR: FMD_GetInfo call failed!\r\n"));
                goto cleanUp;
            }

            pContext->test_sector = *(DWORD*)pInBuffer;
            block  =     pContext->test_sector / flashInfo.wSectorsPerBlock;
            sector = 	pContext->test_sector % flashInfo.wSectorsPerBlock;

            DEBUGMSG(ZONE_ERROR,  (L"Test section info: block=%d sector=%d !\r\n", block, sector));

	     if(block >= flashInfo.dwNumBlocks)
            {
                DEBUGMSG(ZONE_ERROR,  (L"ERROR: invalid sector!\r\n"));
                goto cleanUp;
            }
            if(FMD_GetBlockStatus(block) & 
				(BLOCK_STATUS_BAD |BLOCK_STATUS_RESERVED |BLOCK_STATUS_READONLY))		

            {
                DEBUGMSG(ZONE_ERROR,  (L"ERROR: invalid sector status:%x!\r\n", FMD_GetBlockStatus(block) ));
                goto cleanUp;
            }
			
            rc = TRUE;
			
	     break;
			
        case NAND_ECC_CORRECTION:
            /* Expecting 2 * 2K data, first 2K is good data, 
			                             second 2K is bad data needs correction */
            // Checking parameter
            if (pInBuffer == NULL || inSize != SECTOR_SIZE *2)
            {
                DEBUGMSG(ZONE_ERROR, (L"+DFT_IOControl(%d): ERROR - invalid in parameters\r\n", dwCode));
                goto cleanUp;
            }
            memcpy(p_goodata, pInBuffer, SECTOR_SIZE * 2);
			
            if (pOutBuffer == NULL || outSize != SECTOR_SIZE)
            {
                DEBUGMSG(ZONE_ERROR, (L"+DFT_IOControl(%d): ERROR - invalid out parameters\r\n", dwCode));
                goto cleanUp;
            }

            /* Call ECC test routine */
            rc = nand_ecc_test(context, p_goodata, pOutBuffer);
	     break;
			
	 default:
	     break;
    }
	
cleanUp:
    if (hFMD  != NULL) FMD_Deinit(hFMD);
	
    return rc;
}