Пример #1
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;
}
Пример #2
0
signed char download_firmware_main(char *filename)
{
    struct file     *filp;
    struct inode    *inode = NULL;
    int	length = 0, remaining = 0, count = 0;
    mm_segment_t    oldfs;

    char *fw_buf = NULL, *buffer;

    oldfs = get_fs();
    set_fs(KERNEL_DS);

    filp = filp_open(filename, O_RDONLY, S_IRUSR);
    if (IS_ERR(filp)) {
        pr_info("%s: file %s filp_open error, is_err = %x\n", __func__, filename, (int)IS_ERR(filp));
        return -EIO;
    }

    if (!filp->f_op) {
        pr_info("%s: File Operation Method Error\n", __func__);
        return -EIO;
    }

    inode = filp->f_path.dentry->d_inode;

    if (!inode) {
        pr_info("%s: Get inode from filp failed\n", __func__);
        filp_close(filp, NULL);
        return -EIO;
    }

    pr_info("%s file offset opsition: %xh\n", __func__, (unsigned)filp->f_pos);

    length = i_size_read(inode->i_mapping->host);
    if (length == 0) {
        pr_info("%s: Try to get file size error\n", __func__);
        goto Transfer_DONE;
    }

    pr_info("%s: length=%d\n", __func__, length);
    fw_buf = (char *)kmalloc((length + 1), GFP_KERNEL);
    if (fw_buf == NULL) {
        pr_info("%s: kernel memory alloc error\n", __func__);
        filp_close(filp, NULL);
        return -EIO;
    }
    if (filp->f_op->read(filp, fw_buf, length, &filp->f_pos) != length) {
        pr_info("%s: file read error\n", __func__);
        goto Transfer_DONE;
    }
    /* >>>> ISSP Programming Starts Here <<<< */

#ifdef RESET_MODE
    fIsError = fXRESInitializeTargetForISSP();
    if (fIsError) {
        pr_info("power on failed!\n");
        ErrorTrap(fIsError);
    }
    pr_info("power on success!\n");
#else
    /* Initialize the Host & Target for ISSP operations */
    fIsError = fPowerCycleInitializeTargetForISSP();
    if (fIsError) {
        pr_info("power on failed!\n");
        ErrorTrap(fIsError);
    }
    pr_info("power on success!\n");
#endif
    /* Run the SiliconID Verification, and proceed according to result. */

    fIsError = fVerifySiliconID();
    if (fIsError) {
        pr_info("SiliconID Verification failed!\n");
        ErrorTrap(fIsError);
        return -EIO;
    }
    pr_info("SiliconID Verification success!\n");



    /*-----------------------------------------------------------------------
    xch: the function call below will erase one block (128bytes) of flash
    in the target device.  The block number to be erased is passed in
    as a parameter
    fEraseBlock(5);  // arbitrarily used the 5th block for debugging purposes
    --------------------------------------------------------------------------
    */

    fIsError = fEraseTarget();
    if (fIsError)
        ErrorTrap(fIsError);
    pr_info("erase one block success!\n");

    /* ==============================================================//
       Program Flash blocks with predetermined data. In the final application
       this data should come from the HEX output of PSoC Designer.
       firmware_transfer(tgt_fw);
     */
    remaining = length;
    buffer = fw_buf;
    iChecksumData = 0;     /* Calculte the device checksum as you go */
    for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) {
        for (iBlockCounter = 0; iBlockCounter < BLOCKS_PER_BANK; iBlockCounter++) {
            /* count = (remaining > TARGET_DATABUFF_LEN)? TARGET_DATABUFF_LEN : remaining; */
            LoadProgramData(bBankCounter, (unsigned char)iBlockCounter, buffer, count);
            /*
               This loads the host with test data, not the DUT
               if(iBlockCounter==1)
               return;
               remaining = remaining - count;
               buffer = &fw_buf[count * (iBlockCounter+1)];
             */
            iChecksumData += iLoadTarget();	/* This loads the DUT */

#ifdef USE_TP
            SetTPHigh();    /* Only used of Test Points are enabled */
#endif
            fIsError = fProgramTargetBlock(bBankCounter, (unsigned char)iBlockCounter);
            if (fIsError)
                ErrorTrap(fIsError);
#ifdef USE_TP
            SetTPLow(); /* Only used of Test Points are enabled */
#endif
            fIsError = fReadStatus();
            if (fIsError) /* READ-STATUS after PROGRAM-AND-VERIFY */
                ErrorTrap(fIsError);
        }

    }
    pr_info("Program Flash blocks with predetermined data success.\n");

    /*=======================================================//
      Doing Verify
      Verify included for completeness in case host desires to do a
      stand-alone verify at a later date.
     */
    remaining = length;
    buffer = fw_buf;
    for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) {
        for (iBlockCounter = 0; iBlockCounter < BLOCKS_PER_BANK; iBlockCounter++) {
            /* LoadProgramData(bBankCounter, (unsigned char) iBlockCounter,buffer,count);
               count = (remaining > TARGET_DATABUFF_LEN)? TARGET_DATABUFF_LEN : remaining;
             */
            LoadProgramData(bBankCounter, (unsigned char)iBlockCounter, buffer, count);
            /* This loads the host with test data, not the DUT
               remaining = remaining - count;
               buffer = &fw_buf[count * (iBlockCounter+1)];
             */
            fIsError = fVerifySetup(bBankCounter, (unsigned char)iBlockCounter);
            if (fIsError) {
                pr_info("fVerifySetup err = %d\n", fIsError);
                ErrorTrap(fIsError);
            }
            fIsError = fReadStatus();

            if (fIsError) {
                pr_info("fReadStatus err = %d\n", fIsError);
                ErrorTrap(fIsError);
            }
            fIsError = fReadByteLoop();
            if (fIsError) {
                pr_info("fReadByteLoop err = %d\n", fIsError);
                ErrorTrap(fIsError);
            }
        }
    }

    pr_info("Doing Verify success.\n");

    /*---------------------------------------------------------------------------
    xch: the function call below will erase one block (128bytes) of flash
    in the target device.  The block number to be erased is passed in
    as a parameter
    fEraseBlock(5);  // arbitrarily used the 5th block for debugging purposes
    -----------------------------------------------------------------------------*/

    /* =======================================================
     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++) {
        /* Load one bank of security data from hex file into buffer */
        fIsError = fLoadSecurityData(bBankCounter, buffer);
        if (fIsError)
            ErrorTrap(fIsError);

        /* Secure one bank of the target flash */
        fIsError = fSecureTargetFlash();
        if (fIsError)
            ErrorTrap(fIsError);
    }
    pr_info("set securitydata success\n");
    /* ==============================================================
       Do VERIFY-SECURITY after SECURE
       Load one bank of security data from hex file into buffer
       loads abTargetDataOUT[] with security data that was used in secure
       bit stream
     */
    fIsError = fLoadSecurityData(bBankCounter, buffer);
    if (fIsError)
        ErrorTrap(fIsError);

    fIsError = fVerifySecurity();
    if (fIsError)
        ErrorTrap(fIsError);

    /* =======================================================
       Doing Checksum after VERIFY-SECURITY
     */
    iChecksumTarget = 0;
    for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) {
        fIsError = fAccTargetBankChecksum(&iChecksumTarget);
        if (fIsError)
            ErrorTrap(fIsError);
    }

    pr_info("%s: checksum = %x\n", __func__, iChecksumTarget);
    if (iChecksumTarget != (iChecksumData & 0xFFFF))
        ErrorTrap(VERIFY_ERROR);

    pr_info("checksum success!\n");
    pr_info("download firmware success!\n");
    /* *** SUCCESS ***
       At this point, the Target has been successfully Initialize,
       ID-Checked, Bulk-Erased, Block-Loaded, Block-Programmed,
       Block-Verified, and Device-
       Checksum Verified.
     */

    return 0;

Transfer_DONE:
    kfree(fw_buf);
    filp_close(filp, NULL);
    set_fs(oldfs);

    return -EIO;
}