int cypress_update( int HW_ver )
{
	// -- This example section of commands show the high-level calls to -------
	// -- perform Target Initialization, SilcionID Test, Bulk-Erase, Target ---
	// -- RAM Load, FLASH-Block Program, and Target Checksum Verification. ----
	unsigned char fIsError = 0;
	//	unsigned char bTry=0;

	// >>>> ISSP Programming Starts Here <<<<

	//    ioctl(touch_fd, DEV_CTRL_TOUCH_INT_DISABLE,NULL);
	//    ioctl(touch_fd, DEV_CTRL_TOUCH_SET_FLAG,NULL);
	printk(KERN_INFO "[TSP] %s, %d, HW ver=%d\n", __func__, __LINE__,HW_ver);
#if defined(CONFIG_MACH_GIO)
	if( HW_ver == 1)
		pSocData = Firmware_Data_HW1;
	else if ( HW_ver == 2 )
		pSocData = Firmware_Data_HW2;
	else if ( HW_ver == 3 || HW_ver == 0 )
		pSocData = Firmware_Data_HW3;
	else if ( HW_ver == 17 )
		pSocData = Firmware_Data_HW11;
	else if ( HW_ver == 33 )
		pSocData = Firmware_Data_HW21;
	else if ( HW_ver == 34)
		pSocData = Firmware_Data_HW22;
	else if ( HW_ver == 35)
		pSocData = Firmware_Data_HW23;	
#elif defined(CONFIG_MACH_COOPER) 
	if( HW_ver == 4 || HW_ver == 3 || HW_ver == 0 )
		pSocData = Firmware_Data_HW3;
#else
	if( HW_ver == 1 )
		pSocData = Firmware_Data_HW1;
	else if( HW_ver == 2 )
		pSocData = Firmware_Data_HW2;
	else if( HW_ver == 3 )
		pSocData = Firmware_Data_HW3;
	else if( HW_ver == 4 )
		pSocData = Firmware_Data_HW4;
#endif
	else
	{
		printk(KERN_INFO "[TSP] %s, %d, HW ver is wrong!!\n", __func__, __LINE__);
		goto update_err;
	}
#ifdef TX_ON
	UART_Start();
	UART_CPutString("Start HSSP - Ovation");
	UART_PutCRLF();
#endif
	// >>>> ISSP Programming Starts Here <<<<

	// Acquire the device through reset or power cycle
#ifdef RESET_MODE
	UART_CPutString("Reset Mode activated");
#else
	//    UART_CPutString("Power Cycle Mode activated");
	// Initialize the Host & Target for ISSP operations
	fIsError = fPowerCycleInitializeTargetForISSP();
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify SiliconID");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

	// Run the SiliconID Verification, and proceed according to result.
#if !defined(CONFIG_MACH_TASS) && !defined(CONFIG_MACH_TASSDT) && !defined(CONFIG_MACH_GIO)
	fIsError = fVerifySiliconID();
#endif
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End VerifySiliconID");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

#if 1
	// Bulk-Erase the Device.
	fIsError = fEraseTarget();
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End EraseTarget");
	UART_PutCRLF();
	UART_CPutString("Program Flash Blocks Start");
	UART_PutCRLF();
#endif

#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#if 1   // program flash block
	//LCD_Char_Position(1, 0);
	//LCD_Char_PrintString("Program Flash Blocks Start");

	//==============================================================//
	// Program Flash blocks with predetermined data. In the final application
	// this data should come from the HEX output of PSoC Designer.

	iChecksumData = 0;     // Calculte the device checksum as you go
	for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
	{
		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		//LoadProgramData(bBankCounter, (unsigned char)iBlockCounter);
		iChecksumData += iLoadTarget(iBlockCounter);

		fIsError = fProgramTargetBlock(bBankCounter,(unsigned char)iBlockCounter);
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadStatus();
		if (fIsError)
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

#ifdef TX_ON
		UART_PutChar('#');
#endif

	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Program Flash Blocks End");
#endif

#endif


#if 1  // verify
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify Start");
	UART_PutCRLF();
#endif

	//=======================================================//
	//PTJ: Doing Verify
	//PTJ: this code isnt needed in the program flow because we use PROGRAM-AND-VERIFY (ProgramAndVerify SROM Func)
	//PTJ: which has Verify built into it.
	// Verify included for completeness in case host desires to do a stand-alone verify at a later date.

	for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
	{
		//LoadProgramData(bBankCounter, (unsigned char) iBlockCounter);

		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fVerifySetup(bBankCounter,(unsigned char)iBlockCounter);
		if (fIsError)
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadStatus();
		if (fIsError ) {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadWriteSetup();
		if (fIsError)  {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

		fIsError = fReadByteLoop(iBlockCounter);
		if (fIsError ) {
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}

#ifdef TX_ON
		UART_PutChar('.');
#endif

	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Verify End");
#endif

#endif // end verify

#if 1
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Security Start");
#endif


	//=======================================================//
	// Program security data into target PSoC. In the final application this
	// data should come from the HEX output of PSoC Designer.
	for (bBankCounter=0; (bBankCounter<NUM_BANKS) ; bBankCounter++)
	{
		//PTJ: READ-WRITE-SETUP used here to select SRAM Bank 1

		fIsError = fReadWriteSetup();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
		// Load one bank of security data from hex file into buffer
   		fIsError = fLoadSecurityData(bBankCounter);
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
		// Secure one bank of the target flash
		fIsError = fSecureTargetFlash();
		if (fIsError )
		{
			printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
			ErrorTrap(fIsError);
			goto update_err;
		}
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End Security data");
#endif

#endif


#if 1   // checksum
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("CheckSum Start");
#endif

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
	//PTJ: Doing Checksum
	iChecksumTarget = 0;
	fIsError = fAccTargetBankChecksum(&iChecksumTarget);
	if (fIsError )
	{
		printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
		ErrorTrap(fIsError);
		goto update_err;
	}

//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);
#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("Checksum : iChecksumTarget (0x");
	UART_PutHexWord(iChecksumTarget);
	UART_CPutString("), iChecksumData (0x");
	UART_PutHexWord(iChecksumData);
	UART_CPutString(")");
#endif

	iChecksumTarget = iChecksumTarget & 0xFFFF;
	iChecksumData = iChecksumData & 0xFFFF;

	if (iChecksumTarget != iChecksumData)
	{
		printk(KERN_INFO "[TSP] %s, %d, iChecksumTarget=%d, iChecksumData=%d\n", __func__, __LINE__,iChecksumTarget, iChecksumData );
		ErrorTrap(CHECKSUM_ERROR);
		goto update_err;
	}

#ifdef TX_ON
	UART_PutCRLF();
	UART_CPutString("End Checksum");
#endif

#endif

	// *** SUCCESS ***
	// At this point, the Target has been successfully Initialize, ID-Checked,
	// Bulk-Erased, Block-Loaded, Block-Programmed, Block-Verified, and Device-
	// Checksum Verified.

	// You may want to restart Your Target PSoC Here.
	ReStartTarget();
//	printk(KERN_INFO "[TSP] %s, %d\n", __func__, __LINE__);

	return 1;

update_err:
	return 0;
}
示例#2
0
int touch_update_main(unsigned char bBlack)
{

    int retval = PASS;
    // -- This example section of commands show the high-level calls to -------
    // -- perform Target Initialization, SilcionID Test, Bulk-Erase, Target ---
    // -- RAM Load, FLASH-Block Program, and Target Checksum Verification. ----

    // >>>> ISSP Programming Starts Here <<<<
    CYTTSP_DBG(">>>> ISSP Programming Starts <<<<\n");

    // Acquire the device through reset or power cycle
#ifdef RESET_MODE
    // Initialize the Host & Target for ISSP operations
    if (fIsError = fXRESInitializeTargetForISSP())
    {
        retval = fIsError;
        ErrorTrap(fIsError);
        return fIsError;
    }
#else
    // Initialize the Host & Target for ISSP operations
    fIsError = fPowerCycleInitializeTargetForISSP();
    if (fIsError)
    {
        CYTTSP_DBG( "error - Initialize target for ISSP : %d\n", fIsError);
        retval = fIsError;
        ErrorTrap(fIsError);
        return fIsError;
    }
#endif

    CYTTSP_DBG(">>>> Run the SiliconID Verification, and proceed according to result <<<<\n");

    // Run the SiliconID Verification, and proceed according to result.
    fIsError = fVerifySiliconID();
    if (fIsError)
    {
        CYTTSP_DBG( "error - siliconID verification : %d\n", fIsError);
        retval = fIsError;
        ErrorTrap(fIsError);
        return fIsError;
    }

    CYTTSP_DBG(">>>> Bulk-Erase the Device <<<<\n");

#if 1
    // Bulk-Erase the Device.
    fIsError = fEraseTarget();
    if (fIsError)
    {
        CYTTSP_DBG("error - bulk-erase : %d\n", fIsError);
        retval = fIsError;
        ErrorTrap(fIsError);
        return fIsError;
    }

#endif

    CYTTSP_DBG(">>>> program flash block <<<<\n");

#if 1   // program flash block
    //==============================================================//
    // Program Flash blocks with predetermined data. In the final application
    // this data should come from the HEX output of PSoC Designer.
    binary_index = 0;
    iChecksumData = 0;     // Calculte the device checksum as you go
    for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
    {
        msleep(1);
        fIsError = fReadWriteSetup();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadWriteSetup : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

        LoadProgramData(bBankCounter, (unsigned char)iBlockCounter, bBlack);
        iChecksumData += iLoadTarget();

        fIsError = fProgramTargetBlock(bBankCounter,(unsigned char)iBlockCounter);
        if (fIsError)
        {
            CYTTSP_DBG("error - fProgramTargetBlock : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

//			printk("Write Block: %d\n", iBlockCounter);

        fIsError = fReadStatus();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadStatus : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

    }

#endif

    CYTTSP_DBG(">>>> verify <<<<\n");

#if 0  // verify

    //=======================================================//
    //PTJ: Doing Verify
    //PTJ: this code isnt needed in the program flow because we use PROGRAM-AND-VERIFY (ProgramAndVerify SROM Func)
    //PTJ: which has Verify built into it.
    // Verify included for completeness in case host desires to do a stand-alone verify at a later date.
    binary_index = 0;
    for (iBlockCounter=0; iBlockCounter<BLOCKS_PER_BANK; iBlockCounter++)
    {
        LoadProgramData(bBankCounter, (unsigned char) iBlockCounter);

        fIsError = fReadWriteSetup();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadWriteSetup : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

        fIsError = fVerifySetup(bBankCounter,(unsigned char)iBlockCounter);
        if (fIsError)
        {
            CYTTSP_DBG("error - fVerifySetup : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

        fIsError = fReadStatus();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadStatus : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

        fIsError = fReadWriteSetup();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadWriteSetup : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }

        fIsError = fReadByteLoop();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadByteLoop : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }
    }
#endif // end verify

    CYTTSP_DBG(">>>> Program security data <<<<\n");

#if 1

    //=======================================================//
    // Program security data into target PSoC. In the final application this
    // data should come from the HEX output of PSoC Designer.

    abSecurityDataPtr = 0;
    for (bBankCounter=0; bBankCounter<NUM_BANKS; bBankCounter++)
    {
        //PTJ: READ-WRITE-SETUP used here to select SRAM Bank 1
        fIsError = fReadWriteSetup();
        if (fIsError)
        {
            CYTTSP_DBG("error - fReadWriteSetup : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }
        // Load one bank of security data from hex file into buffer
        fIsError = fLoadSecurityData(bBankCounter);
        if (fIsError)
        {
            CYTTSP_DBG("error - fLoadSecurityData : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }
        // Secure one bank of the target flash
        fIsError = fSecureTargetFlash();
        if (fIsError)
        {
            CYTTSP_DBG("error - fSecureTargetFlash : %d\n", fIsError);
            retval = fIsError;
            ErrorTrap(fIsError);
            return fIsError;
        }
    }
#endif

    CYTTSP_DBG(">>>> checksum <<<<\n");

#if 1   // checksum
    //Doing Checksum
    iChecksumTarget = 0;
    fIsError = fAccTargetBankChecksum(&iChecksumTarget);
    if (fIsError)
    {
        CYTTSP_DBG("error - fAccTargetBankChecksum : %d\n", fIsError);
        retval = fIsError;
        ErrorTrap(fIsError);
        return fIsError;
    }

    iChecksumData = iChecksumData & 0xFFFF;  //jpmoks : to be deleted.
    if (iChecksumTarget != iChecksumData)
    {
        CYTTSP_DBG("error - checksum is different\n");
        retval = fIsError;
        ErrorTrap(CHECKSUM_ERROR);
        return fIsError;
    }

#endif

    // *** SUCCESS ***
    // At this point, the Target has been successfully Initialize, ID-Checked,
    // Bulk-Erased, Block-Loaded, Block-Programmed, Block-Verified, and Device-
    // Checksum Verified.

    // You may want to restart Your Target PSoC Here.
    ReStartTarget();
    CYTTSP_DBG(">>>> firmware update success <<<<\n");
    return retval;
}