/*------------------------------------------------------------------
//
//      Sub functions
//
//------------------------------------------------------------------*/
static int mcsdl_erase_flash(INT8 IdxNum)
{
    int         i;
    UINT8 readBuffer[32];
    int eraseCompareValue = 0xFF;
    /*----------------------------------------
    //      Do erase
    //----------------------------------------*/
    if (IdxNum > 0) {
        mcsdl_select_isp_mode(ISP_MODE_NEXT_CHIP_BYPASS);
        mcsdl_delay(MCSDL_DELAY_3US);
    }
    mcsdl_select_isp_mode(ISP_MODE_ERASE_FLASH);
    mcsdl_unselect_isp_mode();

    /*----------------------------------------
    //      Check 'erased well'
    //----------------------------------------*/

    mcsdl_read_flash_from(readBuffer, 0x0000, 16, IdxNum);
    mcsdl_read_flash_from(&readBuffer[16], 0x7FF0, 16, IdxNum);

    if (IdxNum > 0) {
        eraseCompareValue = 0x00;
    }
    for (i = 0; i < 32; i++) {
        if (readBuffer[i] != eraseCompareValue)
            return MCSDL_RET_ERASE_FLASH_VERIFY_FAILED;
    }

    return MCSDL_RET_SUCCESS;
}
static int mcsdl_erase_flash(INT8 IdxNum)
{
	int i;
	UINT8 readBuffer[32];

	//----------------------------------------
	//	Do erase
	//----------------------------------------
	if (IdxNum > 0)
		mcsdl_select_isp_mode(ISP_MODE_NEXT_CHIP_BYPASS);

	mcsdl_select_isp_mode(ISP_MODE_ERASE_FLASH);
	mcsdl_unselect_isp_mode();

	//----------------------------------------
	//	Check 'erased well'
	//----------------------------------------
	//start ADD DELAY
	mcsdl_read_flash_from(readBuffer, 0x0000, 16, IdxNum);
	mcsdl_read_flash_from(&readBuffer[16], 0x7FF0, 16, IdxNum);
	//end ADD DELAY

	// Compare with '0xFF'
	for (i = 0; i < 32; i++)
	{
		if (readBuffer[i] != 0xFF)
			return MCSDL_RET_ERASE_FLASH_VERIFY_FAILED;
	}

	return MCSDL_RET_SUCCESS;
}
static int mcsdl_read_flash_from(UINT8 *pBuffer, UINT16 unStart_addr, UINT16 unLength, INT8 IdxNum)
{
    int i;
    int j;

    UINT8  ucLength;

    UINT16 addr;
    UINT32 wordData;

    if (unLength >= MELFAS_FIRMWARE_MAX_SIZE)
        return MCSDL_RET_PROGRAM_SIZE_IS_WRONG;

    addr  = 0;
    ucLength  = MELFAS_TRANSFER_LENGTH;

#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" %04X : ", unStart_addr);
#endif
    for (i = 0; i < (int)unLength; i += (int)ucLength) {
        addr = (UINT16)i;
        if (IdxNum > 0) {
            mcsdl_select_isp_mode(ISP_MODE_NEXT_CHIP_BYPASS);
            mcsdl_delay(MCSDL_DELAY_3US);
        }

        mcsdl_select_isp_mode(ISP_MODE_SERIAL_READ);
        wordData   = (((unStart_addr + addr)&0x1FFF) << 1) | 0x0;
        wordData <<= 14;

        mcsdl_write_bits(wordData, 18);

        if ((unLength - addr) < MELFAS_TRANSFER_LENGTH)
            ucLength = (UINT8)(unLength - addr);

        /*--------------------
        // Read flash
        //--------------------*/
        mcsdl_read_flash(&pBuffer[addr]);

#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
        for (j = 0; j < (int)ucLength; j++)
            printk("%02X ", pBuffer[j]);
#endif
        mcsdl_unselect_isp_mode();
    }

#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    /*printk("\n");*/
#endif
    return MCSDL_RET_SUCCESS;
}
Exemplo n.º 4
0
static int mcsdl_download(const UINT8 *pBianry, const UINT16 unLength, INT8 IdxNum, struct melfas_tsi_platform_data *data)
{
    int	i;
    int nRet;

    UINT8 Check_IC = 0xFF;  // d.model
    UINT8 readBuffer[32];
    UINT8 writeBuffer[4];
    UINT32 wordData;

    //---------------------------------
    // Check Binary Size
    //---------------------------------
    if (unLength >= MELFAS_FIRMWARE_MAX_SIZE)
    {
        nRet = MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
        goto MCSDL_DOWNLOAD_FINISH;
    }


#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" - Starting download...\n");
#endif

    //---------------------------------
    // Make it ready
    //---------------------------------
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" > Ready\n");
#endif
    mcsdl_set_ready(data);

    mcsdl_delay(MCSDL_DELAY_1MS);
    //--------------------------------------------------------------
    // IC Information read from Flash
    //--------------------------------------------------------------
#if 1
    if (IdxNum == 0)
    {
        mcsdl_select_isp_mode(ISP_MODE_SERIAL_READ);

        wordData   = ((0x1F00 & 0x1FFF) << 1) | 0x0;
        wordData <<= 14;
        mcsdl_write_bits(wordData, 18);

        mcsdl_read_flash(readBuffer);
        MCSDL_GPIO_SDA_SET_LOW();
/* code for samsung */
        //MCSDL_GPIO_SDA_SET_OUTPUT(0);
/* code for samsung */

        mcsdl_unselect_isp_mode();

        //if (readBuffer[3] != 0xFF)
        Check_IC = readBuffer[3];
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
        printk("\IC Information :0x%02X,  0x%02X\n", readBuffer[3], Check_IC);
#endif
        mcsdl_delay(MCSDL_DELAY_1MS);
    }
Exemplo n.º 5
0
static int mcsdl_program_flash( UINT8 *pDataOriginal, UINT16 unLength )
{
	int		i;

	UINT8	*pData;
	UINT8   ucLength;

	UINT16  addr;
	UINT32  header;

	addr   = 0;
	pData  = pDataOriginal;

	//--------------------------------------
	//	Select ISP Mode  [In System Programming Mode]
	//--------------------------------------

	mcsdl_select_isp_mode( ISP_MODE_SERIAL_WRITE );

	//---------------------------------------------
	//	Header
	//	Length[13ibts] <<17 ) | Address[13ibts]<<2
	//---------------------------------------------
	header = ( ((unLength/4+1)&0x1FFF) << 17 ) | ( (0x0000&0x1FFF) << 2 );

	// Write 32bits
	mcsdl_write_bits( header, 32 );

	//---------------------------------
	//	Repeat Writing
	//---------------------------------

	ucLength = MELFAS_TRANSFER_LENGTH;

	for( i = 0; i< (int)unLength; i+=(int)ucLength ){

		addr = (UINT16)i;

		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		printk("#");
		#endif

		if( ( unLength - addr ) < MELFAS_TRANSFER_LENGTH ){
			ucLength  = (UINT8)(unLength - addr);
		}

		mcsdl_program_flash_part( pData, ucLength );

		pData  += ucLength;

	}

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk("\n");
	#endif

	mcsdl_unselect_isp_mode();

	return MCSDL_RET_SUCCESS;
}
Exemplo n.º 6
0
static int mcsdl_erase_flash(void)
{
	int	  i;
	UINT8 readBuffer[32];

	//----------------------------------------
	//	Do erase
	//----------------------------------------
	mcsdl_select_isp_mode(ISP_MODE_ERASE_FLASH);
	mcsdl_unselect_isp_mode();


	//----------------------------------------
	//	Check 'erased well'
	//----------------------------------------

	mcsdl_read_flash_from(  readBuffer	  , 0x0000, 16 );
	mcsdl_read_flash_from( &readBuffer[16], 0x7FF0, 16 );

	// Compare with '0xFF'
	for(i=0; i<32; i++){
		if( readBuffer[i] != 0xFF )
			return MCSDL_RET_ERASE_FLASH_VERIFY_FAILED;
	}
	return MCSDL_RET_SUCCESS;
}
Exemplo n.º 7
0
static int mcsdl_verify_flash( UINT8 *pDataOriginal, UINT16 unLength, INT8 IdxNum )
{
	int	  i, j;
	int	  nRet;

	UINT8 *pData;
	UINT8 ucLength;

	UINT16 addr;
	UINT32 wordData;

	addr  = 0;
	pData = (UINT8 *) pDataOriginal;

	ucLength  = MELFAS_TRANSFER_LENGTH;

    while ((addr*4) < (int)unLength)
    {
        if ((unLength - (addr*4)) < MELFAS_TRANSFER_LENGTH)
        {
            ucLength = (UINT8)(unLength - (addr * 4));
        }
        // start ADD DELAY
        mcsdl_delay(MCSDL_DELAY_40US);

        //--------------------------------------
        //	Select ISP Mode
        //--------------------------------------
        if (IdxNum > 0)
        {
            mcsdl_select_isp_mode(ISP_MODE_NEXT_CHIP_BYPASS);
		mcsdl_delay(MCSDL_DELAY_3US);
        }

    	mcsdl_select_isp_mode(ISP_MODE_SERIAL_READ);


    	//---------------------------------------------
    	//	Header
    	//	Address[13ibts] <<1
    	//---------------------------------------------

    	wordData   = ( (addr&0x1FFF) << 1 ) | 0x0;
    	wordData <<= 14;

    	mcsdl_write_bits( wordData, 18 );

        addr+=1;

    		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    		printk("#");
    		#endif



    		//--------------------
    		// Read flash
    		//--------------------
    		mcsdl_read_flash( ucVerifyBuffer);

//kang

        MCSDL_GPIO_SDA_SET_LOW();
        MCSDL_GPIO_SDA_SET_OUTPUT(0);
//            mcsdl_delay(MCSDL_DELAY_1MS);
//kang
    		//--------------------
    		// Comparing
    		//--------------------


        if (IdxNum == 0)
        {
            for (j = 0; j < (int)ucLength; j++)
            {
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
                printk(" %02X", ucVerifyBuffer[j]);
#endif
                if (ucVerifyBuffer[j] != pData[j])
                {
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	    				printk("\n [Error] Address : 0x%04X : 0x%02X - 0x%02X\n", addr, pData[j], ucVerifyBuffer[j] );
	                    #endif


	    				nRet = MCSDL_RET_PROGRAM_VERIFY_FAILED;
	    				goto MCSDL_VERIFY_FLASH_FINISH;

	    			}
	    		}
		}
        else // slave
        {
            for (j = 0; j < (int)ucLength; j++)
            {
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
                printk(" %02X", ucVerifyBuffer[j]);
#endif
                if ((0xff - ucVerifyBuffer[j]) != pData[j])
                {
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
                    printk("\n [Error] Address : 0x%04X : 0x%02X - 0x%02X\n", addr, pData[j], ucVerifyBuffer[j]);
	                    #endif


	    				nRet = MCSDL_RET_PROGRAM_VERIFY_FAILED;
	    				goto MCSDL_VERIFY_FLASH_FINISH;

                }
            }
        }
        pData += ucLength;
        mcsdl_unselect_isp_mode();
    	}

	nRet = MCSDL_RET_SUCCESS;

MCSDL_VERIFY_FLASH_FINISH:

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk("\n");
	#endif

	mcsdl_unselect_isp_mode();

	return nRet;
}
Exemplo n.º 8
0
static int mcsdl_program_flash( UINT8 *pDataOriginal, UINT16 unLength, INT8 IdxNum )
{
	int		i;

	UINT8	*pData;
	UINT8   ucLength;

	UINT16  addr;
	UINT32  header;

	addr   = 0;
	pData  = pDataOriginal;

    ucLength = MELFAS_TRANSFER_LENGTH;

//kang

    while ((addr*4) < (int)unLength)
    {
        if ((unLength - (addr*4)) < MELFAS_TRANSFER_LENGTH)
        {
            ucLength  = (UINT8)(unLength - (addr * 4));
        }

    	//--------------------------------------
    	//	Select ISP Mode
    	//--------------------------------------

		// start ADD DELAY
        mcsdl_delay(MCSDL_DELAY_40US);
		//end ADD DELAY
        if(IdxNum > 0)  {
		mcsdl_select_isp_mode(ISP_MODE_NEXT_CHIP_BYPASS);
		mcsdl_delay(MCSDL_DELAY_3US);

        }
    	mcsdl_select_isp_mode( ISP_MODE_SERIAL_WRITE );

    	//---------------------------------------------
    	//	Header
    	//	Address[13ibts] <<1
    	//---------------------------------------------
    	header = ((addr&0x1FFF) << 1) | 0x0 ;
 		header = header << 14;

    	 //Write 18bits
    	mcsdl_write_bits( header, 18 );
		//start ADD DELAY
        //mcsdl_delay(MCSDL_DELAY_5MS);
		//end ADD DELAY

    	//---------------------------------
    	//	Writing
    	//---------------------------------
    //		addr += (UINT16)ucLength;
            addr +=1;

		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		printk("#");
		#endif


		mcsdl_program_flash_part(pData);

		pData  += ucLength;

    	//---------------------------------------------
    	//	Tail
    	//---------------------------------------------
        MCSDL_GPIO_SDA_SET_HIGH();
//kang
	    mcsdl_delay(MCSDL_DELAY_40US);

        for (i = 0; i < 6; i++)
        {
            if (i == 2)
            {
                mcsdl_delay(MCSDL_DELAY_20US);
            }
            else if (i == 3)
            {
                mcsdl_delay(MCSDL_DELAY_40US);
            }

            MCSDL_GPIO_SCL_SET_HIGH();  mcsdl_delay(MCSDL_DELAY_10US);
            MCSDL_GPIO_SCL_SET_LOW();   mcsdl_delay(MCSDL_DELAY_10US);
        }
        MCSDL_GPIO_SDA_SET_LOW();

    	mcsdl_unselect_isp_mode();
//start ADD DELAY
        mcsdl_delay(MCSDL_DELAY_300US);
//end ADD DELAY


	}

	return MCSDL_RET_SUCCESS;
}
Exemplo n.º 9
0
static int mcsdl_read_flash_from( UINT8 *pBuffer, UINT16 unStart_addr, UINT16 unLength)
{
	int	  i;
	//int j;

	UINT8  ucLength;

	UINT16 addr;
	UINT32 wordData;

	if( unLength >= MELFAS_FIRMWARE_MAX_SIZE ){
		return MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
	}

	addr  = 0;

	mcsdl_select_isp_mode(ISP_MODE_SERIAL_READ);

	wordData   = ( (unStart_addr&0x1FFF) << 7 ) | 0x7F;
	wordData <<= 1;

	mcsdl_write_bits( wordData, 31 );

	ucLength  = MELFAS_TRANSFER_LENGTH;

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	//printk(" %04X : ", unStart_addr );
	#endif


	for( i = 0; i < (int)unLength; i+=(int)ucLength ){

		addr = (UINT16)i;

		if( ( unLength - addr ) < MELFAS_TRANSFER_LENGTH ){

			ucLength = (UINT8)(unLength - addr);
		}

		//--------------------
		// Read flash
		//--------------------
		mcsdl_read_flash( &pBuffer[addr], ucLength );


		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		//for(j=0; j<(int)ucLength; j++){
		//	printk("%02X ", pBuffer[j] );
		//}
		#endif

	}

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	//printk("\n");
	#endif

	mcsdl_unselect_isp_mode();

	return MCSDL_RET_SUCCESS;

}
Exemplo n.º 10
0
static int mcsdl_verify_flash( UINT8 *pDataOriginal, UINT16 unLength )
{
	int	  i, j;
	int	  nRet;

	UINT8 *pData;
	UINT8 ucLength;

	UINT16 addr;
	UINT32 wordData;

	addr  = 0;
	pData = (UINT8 *) pDataOriginal;

	mcsdl_select_isp_mode(ISP_MODE_SERIAL_READ);

	wordData   = ( (addr&0x1FFF) << 7 ) | 0x7F;
	wordData <<= 1;

	mcsdl_write_bits( wordData, 31 );

	ucLength  = MELFAS_TRANSFER_LENGTH;

	for( i = 0; i < (int)unLength; i+=(int)ucLength ){

		addr = (UINT16)i;

		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		printk("#");
		#endif

		if( ( unLength - addr ) < MELFAS_TRANSFER_LENGTH ){
			ucLength = (UINT8)(unLength - addr);
		}

		//--------------------
		// Read flash
		//--------------------

		mcsdl_read_flash( ucVerifyBuffer, ucLength );


		//--------------------
		// Comparing
		//--------------------

		for(j=0; j<(int)ucLength; j++){

			if( ucVerifyBuffer[j] != pData[j] ){

				#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
				printk("\n [Error] Address : 0x%04X : 0x%02X - 0x%02X\n", addr, pData[j], ucVerifyBuffer[j] );
                #endif


				nRet = MCSDL_RET_PROGRAM_VERIFY_FAILED;
				goto MCSDL_VERIFY_FLASH_FINISH;

			}
		}

		pData += ucLength;

		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		//printk("\n");
		#endif

	}

	nRet = MCSDL_RET_SUCCESS;

MCSDL_VERIFY_FLASH_FINISH:

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk("\n");
	#endif

	mcsdl_unselect_isp_mode();

	return nRet;
}