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); }
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; }
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; }
static int mcsdl_download(uint8_t *pgm_data, uint16_t length ) { int i; int ret; uint8_t cLength; uint16_t nStart_address=0; uint8_t buffer[MCSDL_TRANSFER_LENGTH]; /* Enter Download mode */ ret = mcsdl_enter_download_mode(); if (0 != ret) { return -1; } printk("mcsdl enter download mode success!\n"); mdelay(1); /* erase flash */ printk("Erasing...\n"); ret = mcsdl_erase_flash(); if (0 != ret) { return -1; } printk("Erase OK!\n"); mdelay(1); /* Verify erase */ printk("Verifying erase...\n"); ret = mcsdl_read_flash(buffer, 0x00, 16); /* Must be '0xFF' after erase */ if (0 != ret) { return -1; } for(i=0; i<16; i++){ if( buffer[i] != 0xFF ){ printk("Verify flash error\n"); return -1; } } mdelay(1); /* Prepare for Program flash */ printk("Preparing Program...\n"); ret = mcsdl_prepare_program(); if (0 != ret) { return -1; } mdelay(1); /* Program flash */ printk("Programing flash..."); nStart_address = 0; cLength = MCSDL_TRANSFER_LENGTH; for( nStart_address = 0; nStart_address < length; nStart_address+=cLength ){ printk("#"); if( ( length - nStart_address ) < MCSDL_TRANSFER_LENGTH ){ cLength = (uint8_t)(length - nStart_address); cLength += (cLength%2); /* For odd length */ } ret = mcsdl_program_flash(&pgm_data[nStart_address], nStart_address, cLength); if (0 != ret) { printk("\nProgram flash failed.\n"); return -1; } ndelay(500); } /* Verify flash */ printk("\nVerifying flash..."); nStart_address = 0; cLength = MCSDL_TRANSFER_LENGTH; for( nStart_address = 0; nStart_address < length; nStart_address+=cLength ){ printk("#"); if( ( length - nStart_address ) < MCSDL_TRANSFER_LENGTH ){ cLength = (uint8_t)(length - nStart_address); cLength += (cLength%2); /* For odd length */ } ret = mcsdl_read_flash(buffer, nStart_address, cLength); if (0 != ret) { printk("\nVerify flash read failed.\n"); return -1; } for(i=0; i<(int)cLength; i++){ if( buffer[i] != pgm_data[nStart_address+i] ){ printk("\nVerify flash compare failed.\n"); return -1; } } ndelay(500); } printk("\n"); /* Reset command */ mdelay(1); ret = i2c_smbus_write_byte(g_client, 0x07); /* 0x07 is reset cmd */ if( 0 != ret ){ printk("reset error\n"); return -1; } mdelay(180); return 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; }
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; }