From 8c9de3aeebaf4128362cbef6e3b710e0cae40931 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 Sep 2017 10:15:27 +0800 Subject: [PATCH] 20170922 : Commit changed files to github. We add the "--device" command to let the user to assign the device number to work. --- 60-dediprog.rules | 0 ChipInfoDb.dedicfg | 0 ChipInfoDb.h | 2 +- FlashCommand.c | 5 +- FlashCommand.h | 2 +- IntelHexFile.c | 0 IntelHexFile.h | 0 Macro.h | 0 MotorolaFile.c | 0 MotorolaFile.h | 0 SerialFlash.c | 6 +- SerialFlash.h | 3 + board.c | 59 ++-- board.h | 5 +- dpcmd.c | 718 ++++++++++++++++++++++++++++++++------------- dpcmd.h | 8 +- makefile | 8 +- parse.c | 3 +- project.c | 540 +++++++++++++++++++--------------- project.h | 20 +- usbdriver.c | 207 ++++++++----- usbdriver.h | 12 +- 22 files changed, 1020 insertions(+), 578 deletions(-) mode change 100644 => 100755 60-dediprog.rules mode change 100644 => 100755 ChipInfoDb.dedicfg mode change 100644 => 100755 ChipInfoDb.h mode change 100644 => 100755 FlashCommand.c mode change 100644 => 100755 FlashCommand.h mode change 100644 => 100755 IntelHexFile.c mode change 100644 => 100755 IntelHexFile.h mode change 100644 => 100755 Macro.h mode change 100644 => 100755 MotorolaFile.c mode change 100644 => 100755 MotorolaFile.h mode change 100644 => 100755 SerialFlash.c mode change 100644 => 100755 SerialFlash.h mode change 100644 => 100755 board.c mode change 100644 => 100755 board.h mode change 100644 => 100755 dpcmd.c mode change 100644 => 100755 dpcmd.h mode change 100644 => 100755 makefile mode change 100644 => 100755 parse.c mode change 100644 => 100755 project.c mode change 100644 => 100755 project.h mode change 100644 => 100755 usbdriver.c mode change 100644 => 100755 usbdriver.h diff --git a/60-dediprog.rules b/60-dediprog.rules old mode 100644 new mode 100755 diff --git a/ChipInfoDb.dedicfg b/ChipInfoDb.dedicfg old mode 100644 new mode 100755 diff --git a/ChipInfoDb.h b/ChipInfoDb.h old mode 100644 new mode 100755 index 6a06681..d524824 --- a/ChipInfoDb.h +++ b/ChipInfoDb.h @@ -22,7 +22,7 @@ int ChipInfoDbFindItem(CHIP_INFO ChipInfoDb[], int NumberOfItems, long JedecDevi void ChipInfoDump(long JedecDeviceIDToFind); long ChipInfoDumpChipSizeInKByte(long Jedec); -int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO *Chip_Info, int search_all); +int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO *Chip_Info, int Index); void getExecPath(char* Path); diff --git a/FlashCommand.c b/FlashCommand.c old mode 100644 new mode 100755 index 76b0b66..f81c201 --- a/FlashCommand.c +++ b/FlashCommand.c @@ -60,7 +60,7 @@ int FlashCommand_TransceiveIn(unsigned char *v, int len, int Index) int FlashCommand_SendCommand_OutOnlyInstruction(unsigned char *v, int len, int Index) -{ +{ return FlashCommand_TransceiveOut(v, len,NO_RESULT_IN, Index); } @@ -145,8 +145,7 @@ int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange *AddrR rq.Value = (unsigned short)(AddrRange->start & 0xffff) ; //16 bits LSB rq.Index = (unsigned short)((AddrRange->start >> 16) & 0xffff) ; //16 bits MSB rq.Length = (unsigned long)(5) ; - } - + } // send rq via control pipe return OutCtrlRequest(&rq, vInstruction, rq.Length,Index); } diff --git a/FlashCommand.h b/FlashCommand.h old mode 100644 new mode 100755 index 0e8b769..ee5fd39 --- a/FlashCommand.h +++ b/FlashCommand.h @@ -24,4 +24,4 @@ int FlashCommand_SendCommand_SetupPacketForAT45DBBulkWrite(struct CAddressRange int FlashCommand_SendCommand_SetupPacketForBulkRead(struct CAddressRange *AddrRange, unsigned char modeRead,unsigned char ReadCom,int Index); -#endif //FLASHCOMMANDS \ No newline at end of file +#endif //FLASHCOMMANDS diff --git a/IntelHexFile.c b/IntelHexFile.c old mode 100644 new mode 100755 diff --git a/IntelHexFile.h b/IntelHexFile.h old mode 100644 new mode 100755 diff --git a/Macro.h b/Macro.h old mode 100644 new mode 100755 diff --git a/MotorolaFile.c b/MotorolaFile.c old mode 100644 new mode 100755 diff --git a/MotorolaFile.h b/MotorolaFile.h old mode 100644 new mode 100755 diff --git a/SerialFlash.c b/SerialFlash.c old mode 100644 new mode 100755 index 48cec56..152cfec --- a/SerialFlash.c +++ b/SerialFlash.c @@ -30,8 +30,7 @@ unsigned int g_AT45_PageSizeMask=0; size_t AT45ChipSize=0; size_t AT45PageSize=0; bool AT45doRDSR(unsigned char* cSR, int Index) -{ - unsigned char Out=0xD7; +{ CNTRPIPE_RQ rq ; unsigned char vInstruction; //size 1 @@ -1245,7 +1244,7 @@ int SerialFlash_Enable4ByteAddrMode(int bEnable,int Index) // strstr(Chip_Info.Class,SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) return CN25Qxxx_LargeEnable4ByteAddrMode(bEnable, Index); - return SerialFlash_TRUE; + return SerialFlash_TRUE; } @@ -1525,6 +1524,7 @@ int SerialFlash_chipErase(int Index) return AT45chipErase(0, Chip_Info.ChipSizeInByte, Index); if( SerialFlash_protectBlock(false,Index) == SerialFlash_FALSE) return false ; + SerialFlash_waitForWEL(Index) ; unsigned char v = mcode_ChipErase; FlashCommand_SendCommand_OutOnlyInstruction(&v,1,Index); diff --git a/SerialFlash.h b/SerialFlash.h old mode 100644 new mode 100755 index 340d37c..4c3fa2c --- a/SerialFlash.h +++ b/SerialFlash.h @@ -7,6 +7,9 @@ #define SerialFlash_FALSE -1 #define SerialFlash_TRUE 1 +#ifdef _NON_UBUNTU +typedef unsigned long uintptr_t; +#endif //#define size_t unsigned int enum //list of all chip-specific instruction, for ST serial flash diff --git a/board.c b/board.c old mode 100644 new mode 100755 index 83c9d17..5435631 --- a/board.c +++ b/board.c @@ -20,7 +20,7 @@ void QueryBoard(int Index) { // printf("QueryBoard\r\n"); return; - if(!Is_usbworking()) + if(!Is_usbworking(Index)) { printf("Do not find SFxx programmer!!\n"); return ; @@ -148,7 +148,7 @@ bool SetTargetFlash(unsigned char StartupMode,int Index) bool SetLEDProgBoard(size_t Color,int Index) { - if(! Is_usbworking()) + if(! Is_usbworking(Index)) { return false; } @@ -195,23 +195,28 @@ bool SetRedLEDOn(bool boOn, int Index) bool SetLEDOnOff(size_t Color,int Index) { + bool result=true; switch(Color) { case SITE_ERROR: - return SetRedLEDOn(true,Index); + result&=SetRedLEDOn(true,Index); + break; case SITE_BUSY: - return SetOrangeLEDOn(true,Index); + result&=SetOrangeLEDOn(true,Index); + break; case SITE_OK: - return SetGreenLEDOn(true,Index); + result&=SetGreenLEDOn(true,Index); + break; case SITE_NORMAL: - return SetLEDProgBoard(0x0709,Index);// Turn off LED - } - return false; + result&=SetLEDProgBoard(0x0709,Index);// Turn off LED + break; + } + return result; } bool SetCS(size_t value,int Index) { - if(! Is_usbworking()) + if(! Is_usbworking(Index)) { return false; } @@ -235,7 +240,7 @@ bool SetCS(size_t value,int Index) bool SetIOModeToSF600(size_t value,int Index) { - if(! Is_usbworking()) + if(! Is_usbworking(Index)) { return false; } @@ -259,16 +264,16 @@ bool SetIOModeToSF600(size_t value,int Index) bool BlinkProgBoard(bool boIsV5,int Index) { - if(! Is_usbworking() ) + if(! Is_usbworking(Index) ) { return false; } - SetGreenLEDOn(true,0); + SetGreenLEDOn(true,Index); Sleep(500); - SetGreenLEDOn(false,0); + SetGreenLEDOn(false,Index); return true; } @@ -300,9 +305,9 @@ bool ReadOnBoardFlash(unsigned char* Data,bool ReadUID,int Index) memcpy(Data,vBuffer,16); } -bool LeaveSF600Standalone(bool Enable,int USBIndex) +bool LeaveSF600Standalone(bool Enable,int Index) { - if(! Is_usbworking()) + if(! Is_usbworking(Index)) { return false; } @@ -316,7 +321,7 @@ bool LeaveSF600Standalone(bool Enable,int USBIndex) rq.Index = RFU ; rq.Length = 0 ; - if(OutCtrlRequest(&rq,&vBuffer,0,USBIndex)==SerialFlash_FALSE) + if(OutCtrlRequest(&rq,&vBuffer,0,Index)==SerialFlash_FALSE) { return false; } @@ -326,7 +331,7 @@ bool LeaveSF600Standalone(bool Enable,int USBIndex) bool SetSPIClockValue(unsigned short v,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; // send request @@ -347,7 +352,7 @@ bool SetSPIClockValue(unsigned short v,int Index) unsigned int ReadUID(int Index) { - if(! Is_usbworking() ) + if(! Is_usbworking(Index) ) { return false; } @@ -383,7 +388,7 @@ unsigned int ReadUID(int Index) bool SetSPIClockDefault(int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; // send request CNTRPIPE_RQ rq ; @@ -406,7 +411,7 @@ bool SetSPIClockDefault(int Index) bool SetVpp4IAP(bool bOn,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; // send request CNTRPIPE_RQ rq ; @@ -430,7 +435,7 @@ bool SetVpp4IAP(bool bOn,int Index) bool UnlockRASS(int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; // send request @@ -453,7 +458,7 @@ bool UnlockRASS(int Index) unsigned char ReadManufacturerID(int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; if(g_bIsSF600==true) @@ -484,7 +489,7 @@ unsigned char ReadManufacturerID(int Index) bool EraseST7Sectors(bool bSect1,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; // send request @@ -602,7 +607,7 @@ bool ProgramSectors(const char* sFilePath, bool bSect1,int Index) bool UpdateChkSum(int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; CNTRPIPE_RQ rq ; @@ -626,7 +631,7 @@ bool UpdateChkSum(int Index) bool WriteUID(unsigned int dwUID,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; if(g_bIsSF600) @@ -669,7 +674,7 @@ bool WriteUID(unsigned int dwUID,int Index) bool WriteManufacturerID(unsigned char ManuID,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; if(g_bIsSF600) @@ -696,7 +701,7 @@ bool WriteManufacturerID(unsigned char ManuID,int Index) bool ReadMemOnST7(unsigned int iAddr,int Index) { - if(!Is_usbworking() ) + if(!Is_usbworking(Index) ) return false; CNTRPIPE_RQ rq ; diff --git a/board.h b/board.h old mode 100644 new mode 100755 index 57a0b14..f651e7a --- a/board.h +++ b/board.h @@ -15,9 +15,8 @@ bool SetRedLEDOn(bool boOn, int Index); bool SetLEDOnOff(size_t Color,int Index); bool SetCS(size_t value,int Index); bool SetIOModeToSF600(size_t value,int Index); -bool BlinkProgBoard(bool boIsV5,int Index); -bool ReadOnBoardFlash(unsigned char* Data,bool ReadUID,int Index); -bool LeaveSF600Standalone(bool Enable,int USBIndex); +bool BlinkProgBoard(bool boIsV5,int Index); +bool LeaveSF600Standalone(bool Enable,int Index); bool SetSPIClockValue(unsigned short v,int Index); unsigned int ReadUID(int Index); bool SetSPIClockDefault(int Index); diff --git a/dpcmd.c b/dpcmd.c old mode 100644 new mode 100755 index e1e5154..2228247 --- a/dpcmd.c +++ b/dpcmd.c @@ -21,13 +21,12 @@ #include "FlashCommand.h" #define min(a,b) (a>b? b:a) -extern unsigned char* pBufferForLastReadData; +extern unsigned char* pBufferForLastReadData[16]; extern unsigned char* pBufferforLoadedFile; extern unsigned int g_uiFileChecksum; extern unsigned long g_ulFileSize; -extern volatile bool g_bIsSF600; -extern unsigned char g_BatchIndex; -extern volatile bool g_bIsSF600; +extern volatile bool g_bIsSF600[16]; +extern unsigned char g_BatchIndex; unsigned int g_Vcc=vcc3_5V; unsigned int g_Vpp=9; @@ -38,6 +37,7 @@ unsigned int g_ucTarget=1; unsigned int g_uiTimeout=300; unsigned int g_ucSPIClock=clk_12M; unsigned int g_uiBlink=0; +unsigned int g_uiDevNum=0; unsigned int g_uiDeviceID=0; unsigned int g_IO1Select=0; unsigned int g_IO4Select=1; @@ -74,15 +74,14 @@ char g_LogPath[512]={0}; unsigned long g_ucOperation; struct memory_id g_ChipID; char g_board_type[8]; -int g_firmversion; -//bool g_bIsSF600=false; +int g_firmversion; int g_CurrentSeriase=Seriase_25; int m_isCanceled = 0; int m_bProtectAfterWritenErase = 0; int m_boEnReadQuadIO = 0; int m_boEnWriteQuadIO = 0; volatile bool g_is_operation_on_going=false; -bool g_is_operation_successful=true; +bool g_is_operation_successful[16]={false}; bool g_bDisplayTimer=true; @@ -144,7 +143,7 @@ struct option long_options[] = { { "lock-start", 1, NULL, 'S' }, { "lock-length", 1, NULL, 'N' }, { "blink", 1, NULL, 'B' }, -// { "device", 1, NULL, 'D' }, + { "device", 1, NULL, 'D' }, // { "fix-device", 1, NULL, 'F' }, { "list-device-id", 1, NULL, 'V' }, { "timeout", 1, NULL, 't' }, @@ -315,15 +314,20 @@ int Sequence() { // *** the calling order in the following block must be kept as is *** bool boResult=true; - + boResult &= BlankCheck(); if(boResult==false) - return EXCODE_FAIL_BLANK; - - boResult &= Erase(); - if(boResult==false) - return EXCODE_FAIL_ERASE; - + { + if(!(g_ucOperation&ERASE)) + return EXCODE_FAIL_BLANK; + } + if((!((g_ucOperation&BLANK)&&(boResult==true))||(!(g_ucOperation&BLANK)))) + { + boResult = Erase(); + if(boResult==false) + return EXCODE_FAIL_ERASE; + } + boResult &= Program(); if(boResult==false) return EXCODE_FAIL_PROG; @@ -343,9 +347,19 @@ int Sequence() if(g_ucOperation & CSUM) { if(g_uiLen==0) - return CRC32(pBufferForLastReadData, Chip_Info.ChipSizeInByte); - else - return CRC32(pBufferForLastReadData, g_uiLen); + { + if(g_uiDevNum==0) + return CRC32(pBufferForLastReadData[0], Chip_Info.ChipSizeInByte); + else + return CRC32(pBufferForLastReadData[g_uiDevNum-1], Chip_Info.ChipSizeInByte); + } + else + { + if(g_uiDevNum==0) + return CRC32(pBufferForLastReadData[0], g_uiLen); + else + return CRC32(pBufferForLastReadData[g_uiDevNum-1], g_uiLen); + } } } else @@ -354,7 +368,7 @@ int Sequence() boResult &= Verify(); if(boResult==false) return EXCODE_FAIL_VERIFY; - + return EXCODE_PASS; } @@ -377,16 +391,16 @@ void GetLogPath(char* pBuf) } } -void EnterStandaloneMode(int USBIndex) +void EnterStandaloneMode(int Index) { - if(g_bIsSF600==true) - LeaveSF600Standalone(false,USBIndex); + if(g_bIsSF600[Index]==true) + LeaveSF600Standalone(false,Index); } -void LeaveStandaloneMode(int USBIndex) +void LeaveStandaloneMode(int Index) { - if(g_bIsSF600==true) - LeaveSF600Standalone(true,USBIndex); + if(g_bIsSF600[Index]==true) + LeaveSF600Standalone(true,Index); } void WriteLog(int ErrorCode, bool Init) @@ -475,8 +489,9 @@ int main(int argc, char *argv[]) int c; int iExitCode=EXCODE_PASS; bool bDetect=false; + bool bDevice=false; - printf("\nDpCmd Linux 1.1.2.%02d Engine Version:\nLast Built on Mar 13 2017\n\n",GetConfigVer()); + printf("\nDpCmd Linux 1.2.1.%02d Engine Version:\nLast Built on Sep 22 2017\n\n",GetConfigVer()); //1. new feature.bug.config g_ucOperation=0; GetLogPath(g_LogPath); @@ -486,15 +501,18 @@ int main(int argc, char *argv[]) cli_classic_usage(false); return 0; } + + if(OpenUSB()==0) iExitCode=EXCODE_FAIL_USB; - -// QueryBoard(0); + LeaveStandaloneMode(0); QueryBoard(0); + + while((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) - { + { switch (c) { case '?': @@ -578,8 +596,12 @@ int main(int argc, char *argv[]) g_ucOperation |= BLINK; break; case 'D': // device - l_opt_arg = optarg; - printf("activate only the programmer connected to USBx (with arg: %s)\n", l_opt_arg); + //l_opt_arg = optarg; + //printf("activate only the programmer connected to USBx (with arg: %s)\n", l_opt_arg); + + bDevice = true; + sscanf(optarg,"%x",&g_uiDevNum); + //devpath = optarg; break; case 'F': l_opt_arg = optarg; @@ -633,23 +655,59 @@ int main(int argc, char *argv[]) break; } } + + + int dev_cnt=get_usb_dev_cnt(); if(bDetect==true) - { -// printf("%s\r\n",g_LogPath); - WriteLog(iExitCode, true); - printf("detecting chip\r\n"); - Chip_Info=GetFirstDetectionMatch(0); - if(Chip_Info.UniqueID !=0 ) - { - printf("By reading the chip ID, the chip applies to [ %s ]\r\n", Chip_Info.TypeName); - printf("%s chip size is %zd bytes.\r\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); + { + if(bDevice==false) + { + for(int i=0;i0) + printf("\nDevice %d (SF%06d):\tdetecting chip\r\n",i+1,dwUID); + else + printf("\nDevice %d (DP%06d):\tdetecting chip\r\n",i+1,dwUID); + + WriteLog(iExitCode, true); + Chip_Info=GetFirstDetectionMatch(i); + if(Chip_Info.UniqueID !=0 ) + { + printf("By reading the chip ID, the chip applies to [ %s ]\r\n", Chip_Info.TypeName); + printf("%s chip size is %zd bytes.\r\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); + } + else + { + printf("%s",msg_err_identifychip); + iExitCode=EXCODE_FAIL_IDENTIFY; + } + } + } + else if(g_uiDevNum!=0) + { + WriteLog(iExitCode, true); + printf("%d,\tdetecting chip\r\n",g_uiDevNum); + Chip_Info=GetFirstDetectionMatch(g_uiDevNum-1); + if(Chip_Info.UniqueID !=0 ) + { + printf(" \tBy reading the chip ID, the chip applies to [ %s ]\r\n", Chip_Info.TypeName); + printf(" \t%s chip size is %zd bytes.\r\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); + } + else + { + printf("%s",msg_err_identifychip); + iExitCode=EXCODE_FAIL_IDENTIFY; + } } else { - printf("%s",msg_err_identifychip); - iExitCode=EXCODE_FAIL_IDENTIFY; + printf("The number of programmer is not defined!\n"); + iExitCode=EXCODE_FAIL_IDENTIFY; } - goto Exit; + goto Exit; } else WriteLog(iExitCode, true); @@ -659,6 +717,7 @@ int main(int argc, char *argv[]) iExitCode=Handler(); Exit: + printf("\n\n"); CloseProject(); ExitProgram(); WriteLog(iExitCode,false); @@ -666,11 +725,15 @@ int main(int argc, char *argv[]) } void ExitProgram(void) -{ - if(pBufferForLastReadData != NULL) - free(pBufferForLastReadData); - if(pBufferforLoadedFile != NULL) - free(pBufferforLoadedFile); +{ + for(int i=0;i0) - { - RawInstructions(0); + { + int dev_cnt=get_usb_dev_cnt(); + if(g_uiDevNum==0) + { + for(int i=0;i0) - { - if(Dedi_Search_Chip_Db_ByTypeName(g_parameter_type,&Chip_Info,1)) - { - printf("Chip Type %s is applied manually.\r\n",Chip_Info.TypeName); - printf("%s chip size is %zd bytes.\n\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); - ProjectInitWithID(Chip_Info,0); - } - else - { - printf("Chip Type Unknow is applied manually.\r\n"); - return false; - } + if(g_uiDevNum==0) + { - } - else - { - ProjectInit(0); - } + for(int i=0;i0) + { + if(Dedi_Search_Chip_Db_ByTypeName(g_parameter_type,&Chip_Info,i)) + { + printf("Chip Type %s is applied manually.\r\n",Chip_Info.TypeName); + printf("%s chip size is %zd bytes.\n\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); + ProjectInitWithID(Chip_Info,i); + } + else + { + printf("Chip Type Unknow is applied manually.\r\n"); + return false; + } + + } + else + { + ProjectInit(i); + } + } + } + else if(g_uiDevNum<=dev_cnt) + { + g_StartupMode=targets[g_ucTarget]; + SetTargetFlash((unsigned char)targets[g_ucTarget], g_uiDevNum-1); + SetSPIClock(g_uiDevNum-1); + SetVcc(g_uiDevNum-1); + + if(strlen(g_parameter_type)>0) + { + if(Dedi_Search_Chip_Db_ByTypeName(g_parameter_type,&Chip_Info,g_uiDevNum-1)) + { + printf("Chip Type %s is applied manually.\r\n",Chip_Info.TypeName); + printf("%s chip size is %zd bytes.\n\n",Chip_Info.TypeName,Chip_Info.ChipSizeInByte); + ProjectInitWithID(Chip_Info,g_uiDevNum-1); + } + else + { + printf("Chip Type Unknow is applied manually.\r\n"); + return false; + } + + } + else + { + ProjectInit(g_uiDevNum-1); + } + } + else + printf("Error: Did not find the programmer.\r\n"); + + return true; } return false; } void CloseProject(void) -{ - EnterStandaloneMode(0); +{ + for(int i=0;i=1800 && g_bIsSF600==true) + if(g_Vcc<=3800 && g_Vcc>=1800 && g_bIsSF600[Index]==true) ; else - g_Vcc= (0x10 | (g_Vcc&0x03)); - //printf("Vcc=%x\r\n",g_Vcc); + g_Vcc= (0x10 | (g_Vcc&0x03)); } int do_loadFile(void) @@ -1020,19 +1173,19 @@ int do_loadFile(void) { switch(g_BatchIndex) { - case 1: - filename=g_parameter_batch; - break; - case 2: - default: - filename=g_parameter_auto; - break; + case 1: + filename=g_parameter_batch; + break; + case 2: + default: + filename=g_parameter_auto; + break; } } else if(g_ucOperation & FSUM) filename=g_parameter_fsum; printf("%s",msg_info_loading); - printf("(%s)",filename); + printf("(%s)",filename); return LoadFile(filename); } @@ -1047,16 +1200,29 @@ bool ListTypes(void) void BlinkProgrammer(void) { bool IsV5=is_BoardVersionGreaterThan_5_0_0(0); - if(IsV5==false) return; - - if(g_uiBlink<=1) + if(IsV5==false) return; + int dev_cnt=get_usb_dev_cnt(); + + if(g_uiBlink==0) + { + for(int i=0;idev_cnt) + printf("The number of programmer is not defined!\r\n"); + else + { + dwUID=ReadUID(g_uiDeviceID-1); + if((dwUID / 600000)==0) + printf("%d,\tDP%06d\r\n",g_uiDeviceID,dwUID); + else + printf("%d,\tSF%06d\r\n",g_uiDeviceID,dwUID); + } + } } void do_BlankCheck(void) -{ - printf("%s",msg_info_checking); - Run(BLANKCHECK_WHOLE_CHIP); +{ + printf("%s\n",msg_info_checking); + Run(BLANKCHECK_WHOLE_CHIP,g_uiDevNum); Wait ( msg_info_chipblank, msg_info_chipnotblank ); } void do_Erase(void) { - printf("%s,",msg_info_erasing); - Run(ERASE_WHOLE_CHIP); + printf("%s \n",msg_info_erasing); + Run(ERASE_WHOLE_CHIP,g_uiDevNum); - Wait( msg_info_eraseOK, msg_info_erasefail) ; + + Wait( msg_info_eraseOK, msg_info_erasefail) ; } void do_Program(void) { - if(!do_loadFile()) return; - + if(!do_loadFile()) return; SaveProgContextChanges(); - printf("%s",msg_info_programming); - Run(PROGRAM_CHIP); + printf("%s\n",msg_info_programming); + Run(PROGRAM_CHIP,g_uiDevNum); - if( Wait( msg_info_progOK, msg_info_progfail ) ) + if( Wait( msg_info_progOK, msg_info_progfail )) { printf("\nChecksum(whole file): %08X",g_uiFileChecksum); printf("\nChecksum(Written part of file): %08X\n",CRC32(pBufferforLoadedFile, min(DownloadAddrRange.end-DownloadAddrRange.start,g_ulFileSize))); @@ -1112,35 +1298,76 @@ void do_Read(void) DownloadAddrRange.length=g_uiLen; DownloadAddrRange.end=g_uiAddr+g_uiLen; - printf("%s",msg_info_reading); - Run(READ_ANY_BY_PREFERENCE_CONFIGURATION); + printf("%s\n",msg_info_reading); + Run(READ_ANY_BY_PREFERENCE_CONFIGURATION,g_uiDevNum); Wait(msg_info_readOK,msg_info_readfail); } void do_DisplayOrSave(void) { - if(strcmp(g_parameter_read, "STDOUT")==0) + int dev_cnt=get_usb_dev_cnt(); + + if(g_uiDevNum==0) { - int i,Len=UploadAddrRange.end-UploadAddrRange.start; - printf("\n"); - printf("Hex value display (starting from 0x%02X, 0x%02zXbytes in total): \n",g_uiAddr,g_uiLen); - for(i=0; i0) + { + printf("\nDevice %d:\n",Index+1); do_RawInstructions(Index); + + + } } bool BlankCheck(void) @@ -1244,8 +1475,7 @@ bool BlankCheck(void) bool Erase(void) { if(g_ucOperation&ERASE) - do_Erase(); - + do_Erase(); return g_bStatus; } @@ -1259,10 +1489,12 @@ bool Program(void) bool Read(void) { + int dev_cnt=get_usb_dev_cnt(); if(g_ucOperation&READ_TO_FILE) { - do_Read(); - do_DisplayOrSave(); + do_Read(); + do_DisplayOrSave(); + } return g_bStatus; } @@ -1284,6 +1516,7 @@ bool Verify(void) bool CalChecksum(void) { + int dev_cnt = get_usb_dev_cnt(); if(g_ucOperation & FSUM) { do_loadFile(); @@ -1293,15 +1526,57 @@ bool CalChecksum(void) if(g_ucOperation & CSUM) { do_Read(); + + if(g_uiDevNum==0) + { + for(int i=0;i(b))? (b):(a)) @@ -314,7 +315,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, long UniqueID, CHIP_INFO *Chip_Info, i return found_flag; /*Executed without errors*/ }/*End main*/ -int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO *Chip_Info, int search_all) +int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO *Chip_Info, int Index) { FILE* fp; /*Declare file pointer variable*/ int found_flag = 0,i; diff --git a/project.c b/project.c old mode 100644 new mode 100755 index 881df1f..852f26d --- a/project.c +++ b/project.c @@ -13,17 +13,21 @@ #include "usbdriver.h" #include "board.h" +#include #define min(a,b) (a>b? b:a) -unsigned char* pBufferForLastReadData=NULL; +unsigned char* pBufferForLastReadData[16]={NULL}; unsigned char* pBufferforLoadedFile=NULL; unsigned long g_ulFileSize=0; unsigned int g_uiFileChecksum=0; unsigned char g_BatchIndex=2; +unsigned int CompleteCnt=0; +bool m_bOperationResult[16]; +bool bAuto[16]={false}; extern unsigned int g_ucFill; extern int m_boEnReadQuadIO; extern int m_boEnWriteQuadIO; -extern volatile bool g_bIsSF600; +extern volatile bool g_bIsSF600[16]; extern char g_board_type[8]; extern int g_firmversion; extern char* g_parameter_vcc; @@ -46,15 +50,17 @@ extern int g_CurrentSeriase; extern struct CAddressRange DownloadAddrRange; extern struct CAddressRange UploadAddrRange; extern bool g_is_operation_on_going; -extern bool g_is_operation_successful; +extern bool g_is_operation_successful[16]; extern unsigned int g_Vcc; extern unsigned int g_Vpp; extern unsigned int g_uiAddr; extern size_t g_uiLen; extern bool g_bEnableVpp; +extern unsigned int g_uiDevNum; //evy add +extern int FlashIdentifier(CHIP_INFO * Chip_Info, int search_all,int Index); -extern int FlashIdentifier(CHIP_INFO * Chip_Info, int search_all); +pthread_mutex_t g_count_mutex; #define FIRMWARE_VERSION(x,y,z) ((x<<16) | (y<<8) | z) enum FILE_FORMAT{ @@ -68,27 +74,26 @@ void Sleep(unsigned int mSec) usleep(mSec*1000); } -void TurnONVpp(void) +void TurnONVpp(int Index) { if(g_bEnableVpp==true) - dediprog_set_vpp_voltage(Chip_Info.VppSupport); + dediprog_set_vpp_voltage(Chip_Info.VppSupport,Index); } -void TurnOFFVpp(void) +void TurnOFFVpp(int Index) { if(g_bEnableVpp==true) - dediprog_set_vpp_voltage(0); + dediprog_set_vpp_voltage(0,Index); } void TurnONVcc(int Index) -{ -// printf("g_Vcc=%x\n",g_Vcc); - dediprog_set_spi_voltage(g_Vcc,Index); +{ + dediprog_set_spi_voltage(g_Vcc,Index); } void TurnOFFVcc(int Index) -{ - dediprog_set_spi_voltage(0,Index); +{ + dediprog_set_spi_voltage(0,Index); } @@ -121,12 +126,12 @@ int ReadBINFile(const char *filename,unsigned char *buf, unsigned long* size) fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); - // allocate memory to contain the whole file: if(pBufferforLoadedFile!=NULL) - free(pBufferforLoadedFile); + free(pBufferforLoadedFile); - pBufferforLoadedFile = (unsigned char*) malloc (sizeof(char)*lSize); + pBufferforLoadedFile = (unsigned char*) malloc (lSize); + if (pBufferforLoadedFile == NULL) { @@ -202,6 +207,7 @@ int GetFileFormatFromExt(const char* csPath) bool ReadFile(const char* csPath, unsigned char* buffer,unsigned long* FileSize,unsigned char PaddingByte) { + switch(GetFileFormatFromExt(csPath)) { case HEX : @@ -215,7 +221,7 @@ bool ReadFile(const char* csPath, unsigned char* buffer,unsigned long* FileSize, // write file bool WriteFile(const char* csPath, unsigned char* buffer,unsigned int FileSize) -{ +{ switch(GetFileFormatFromExt(csPath)) { case HEX : @@ -228,16 +234,17 @@ bool WriteFile(const char* csPath, unsigned char* buffer,unsigned int FileSize) } bool LoadFile(char* filename) -{ +{ bool result=true; unsigned long size; result &= ReadFile(filename,pBufferforLoadedFile, &size, g_ucFill); g_uiFileChecksum=CRC32(pBufferforLoadedFile,g_ulFileSize); + return result; } bool IdentifyChipBeforeOperation(int Index) -{ +{ bool result = false; CHIP_INFO binfo; binfo.UniqueID=0; @@ -247,17 +254,17 @@ bool IdentifyChipBeforeOperation(int Index) strstr(Chip_Info.Class, SUPPORT_SILICONBLUE_iCE65) != NULL) return true; - Found=FlashIdentifier(&binfo,0); + Found=FlashIdentifier(&binfo,0,Index); + // printf("\n binfo.UniqueID = 0x%lx, Chip_Info.UniqueID = 0x%lx\n", binfo.UniqueID,Chip_Info.UniqueID); if(Found && (binfo.UniqueID == Chip_Info.UniqueID || binfo.UniqueID == Chip_Info.JedecDeviceID)) - result = true; - + result = true; return result; } void PrepareProgramParameters(int Index) -{ +{ size_t len = 0; size_t addrStart = 0; @@ -267,12 +274,12 @@ void PrepareProgramParameters(int Index) size_t addrLeng = (0 == len) ? g_ulFileSize: len; DownloadAddrRange.start=addrStart; DownloadAddrRange.end=addrStart + addrLeng; - DownloadAddrRange.length=addrLeng; - + DownloadAddrRange.length=addrLeng; } bool ValidateProgramParameters(int Index) -{ +{ + PrepareProgramParameters(Index); /// special treatment for AT45DBxxxD @@ -299,16 +306,16 @@ bool ValidateProgramParameters(int Index) } bool ProgramChip(int Index) -{ +{ bool need_padding = (g_ucFill != 0xFF); unsigned char* vc; - struct CAddressRange real_addr; - real_addr.start=(DownloadAddrRange.start &(~(0x200 - 1))); - real_addr.end=((DownloadAddrRange.end + (0x200 - 1)) & (~(0x200 - 1))); - real_addr.length=real_addr.end-real_addr.start; - - vc=(unsigned char*)malloc(real_addr.length); - memset(vc,g_ucFill,real_addr.length); + struct CAddressRange real_addr[16]; + real_addr[Index].start=(DownloadAddrRange.start &(~(0x200 - 1))); + real_addr[Index].end=((DownloadAddrRange.end + (0x200 - 1)) & (~(0x200 - 1))); + real_addr[Index].length=real_addr[Index].end-real_addr[Index].start; + + vc=(unsigned char*)malloc(real_addr[Index].length); + memset(vc,g_ucFill,real_addr[Index].length); if(need_padding==true) { @@ -319,8 +326,7 @@ bool ProgramChip(int Index) memcpy(vc+(DownloadAddrRange.start & 0x1FF),pBufferforLoadedFile,DownloadAddrRange.length); } - bool result= SerialFlash_rangeProgram(&real_addr, vc,Index); - + bool result= SerialFlash_rangeProgram(&real_addr[Index], vc,Index); return result; } @@ -341,75 +347,63 @@ bool ReadChip(const struct CAddressRange range,int Index) if(result) { - if(pBufferForLastReadData != NULL) - free(pBufferForLastReadData); - + if(pBufferForLastReadData[Index] != NULL) + { + free(pBufferForLastReadData[Index]); + } unsigned int offset = (addrStart & 0x1FF); - pBufferForLastReadData=(unsigned char*)malloc(range.length); - memcpy(pBufferForLastReadData,vc+offset,range.length); + pBufferForLastReadData[Index]=(unsigned char*)malloc(range.length); + memcpy(pBufferForLastReadData[Index],vc+offset,range.length); UploadAddrRange=range; } if(vc != NULL) free (vc); - return result; + return result; } bool threadBlankCheck(int Index) -{ - bool result = false; -// bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); +{ + bool result = false; struct CAddressRange Addr; Addr.start=0; - Addr.end=Chip_Info.ChipSizeInByte; - - //(L"Blank Checking ..."); - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(SITE_BUSY,Index); + Addr.end=Chip_Info.ChipSizeInByte; SetIOMode(false,Index); result = SerialFlash_rangeBlankCheck(&Addr,Index) ; -// m_bOperationResult[Index]=result? 1:RES_BLANK; + m_bOperationResult[Index]=result? 1:RES_BLANK; #if 0 - if( !bAuto[Index] ) - { - m_context.runtime.elapsed_time_of_last_operation = timer.elapsed() ; - Log(wformat(L"Operation completed. \n%1% seconds elapsed.")%m_context.runtime.elapsed_time_of_last_operation); + if( !bAuto[Index] ) //not batch + { + + CompleteCnt++; + /*if( CompleteCnt==get_usb_dev_cnt()) + { + g_is_operation_on_going = false; + //SerialFlash_ClearCancelOperationFlag(); + }*/ - CompleteCnt++; - - if( CompleteCnt==GetDevNum() ) - { - m_context.runtime.is_operation_on_going = false; - m_chip[Index]->ClearCancelOperationFlag(); - } - - if(is_greater_than_5_0_0) - m_board->SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); } -#endif -// SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); -// g_is_operation_on_going = false; - g_is_operation_successful = result; + else //batch + { + // SerialFlash_ClearCancelOperationFlag(); + + } +#endif + g_is_operation_successful[Index] = result; return result; } bool threadEraseWholeChip(int Index) -{ - bool result = false; -// bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(SITE_BUSY,Index); - -// Log(L"Erasing a whole chip ..."); +{ + bool result = false; + // power::CAutoVccPower autopowerVcc(m_usb, m_context.power.vcc,Index); // power::CAutoVppPower autopowerVpp(m_usb, SupportedVpp(),Index); @@ -420,41 +414,33 @@ bool threadEraseWholeChip(int Index) // Log(result ? L"A whole chip erased" : L"Error: Failed to erase a whole chip"); -// m_bOperationResult[Index]=result? 1:RES_ERASE; + m_bOperationResult[Index]=result? 1:RES_ERASE; #if 0 - if( !bAuto[Index] ) - { - m_context.runtime.is_operation_successful = result; - m_context.runtime.elapsed_time_of_last_operation = timer.elapsed() ; - Log(wformat(L"Operation completed. \n%1% seconds elapsed.")%m_context.runtime.elapsed_time_of_last_operation); - - CompleteCnt++; - - if( CompleteCnt==GetDevNum() ) - { - m_context.runtime.is_operation_on_going = false; - m_chip[Index]->ClearCancelOperationFlag(); - } - - if(is_greater_than_5_0_0) - m_board->SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); + if( !bAuto[Index] ) //not batch + { + + CompleteCnt++; + if( CompleteCnt==get_usb_dev_cnt()) + { + g_is_operation_on_going=false; + + SerialFlash_ClearCancelOperationFlag(); + } } -#endif -// SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); - g_is_operation_successful = result; -// g_is_operation_on_going = false; + else + { + SerialFlash_ClearCancelOperationFlag(); + } +#endif + g_is_operation_successful[Index] = result; return result; } bool threadReadRangeChip(struct CAddressRange range,int Index) { bool result = true; -// bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); - struct CAddressRange AddrRound; - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(SITE_BUSY,Index); - + struct CAddressRange AddrRound; + SetIOMode(false,Index); AddrRound.start= (range.start &(~(0x1FF))); @@ -462,14 +448,14 @@ bool threadReadRangeChip(struct CAddressRange range,int Index) AddrRound.length=AddrRound.end-AddrRound.start; unsigned char *pBuffer = malloc(AddrRound.length); - if(pBufferForLastReadData==NULL) - pBufferForLastReadData=malloc(range.end-range.start); + if(pBufferForLastReadData[Index]==NULL) + pBufferForLastReadData[Index]=malloc(range.end-range.start); else - { - free(pBufferForLastReadData); - pBufferForLastReadData=malloc(range.end-range.start); + { + free(pBufferForLastReadData[Index]); + pBufferForLastReadData[Index]=malloc(range.end-range.start); } - if(pBufferForLastReadData==NULL) + if(pBufferForLastReadData[Index]==NULL) { printf("allocate memory fail.\n"); free(pBuffer); @@ -482,44 +468,37 @@ bool threadReadRangeChip(struct CAddressRange range,int Index) UploadAddrRange.start = range.start; UploadAddrRange.end= range.end; UploadAddrRange.length = range.end-range.start; - memcpy(pBufferForLastReadData,pBuffer+ (UploadAddrRange.start & 0x1FF),UploadAddrRange.length); + memcpy(pBufferForLastReadData[Index],pBuffer+ (UploadAddrRange.start & 0x1FF),UploadAddrRange.length); } - free(pBuffer); - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); - + free(pBuffer); + return result; - } bool threadReadChip(int Index) { - bool result = false; -// bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); + bool result = false; struct CAddressRange Addr; Addr.start=0; Addr.end=Chip_Info.ChipSizeInByte; - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(SITE_BUSY,Index); + SetIOMode(false,Index); - if(pBufferForLastReadData==NULL) - pBufferForLastReadData=(unsigned char*)malloc(Chip_Info.ChipSizeInByte); + if(pBufferForLastReadData[Index]==NULL) + pBufferForLastReadData[Index]=(unsigned char*)malloc(Chip_Info.ChipSizeInByte); else { - free(pBufferForLastReadData); - pBufferForLastReadData=(unsigned char*)malloc(Chip_Info.ChipSizeInByte); + free(pBufferForLastReadData[Index]); + pBufferForLastReadData[Index]=(unsigned char*)malloc(Chip_Info.ChipSizeInByte); } - if(pBufferForLastReadData==NULL) + if(pBufferForLastReadData[Index]==NULL) { printf("allocate memory fail.\n"); return false; } - result = SerialFlash_rangeRead(&Addr, pBufferForLastReadData,Index); + result = SerialFlash_rangeRead(&Addr, pBufferForLastReadData[Index],Index); if(result) { @@ -527,11 +506,9 @@ bool threadReadChip(int Index) UploadAddrRange.end=Chip_Info.ChipSizeInByte; UploadAddrRange.length=Chip_Info.ChipSizeInByte; } + -// if(is_greater_than_5_0_0) -// SetLEDOnOff(result?SITE_OK:SITE_ERROR,Index); - - g_is_operation_successful = result; + g_is_operation_successful[Index] = result; return result; } @@ -560,49 +537,76 @@ bool threadConfiguredReadChip(int Index) result = threadReadRangeChip(addr,Index); } - g_is_operation_successful = result; + g_is_operation_successful[Index] = result; // g_is_operation_on_going = false; return result; } bool threadProgram(int Index) -{ - bool result = true; - SetIOMode(true,Index); +{ + int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restricattr); + + bool result = true; + SetIOMode(true,Index); + pthread_mutex_lock(&g_count_mutex); if(g_ulFileSize== 0) { - result = false; + result = false; } if( result && (!ValidateProgramParameters(Index)) ) { - result = false; - } + //printf("evy - program failed1(%df)\n",Index); + result = false; + } + pthread_mutex_unlock(&g_count_mutex); + + int pthread_mutex_destroy(pthread_mutex_t *mutex); if( result && ProgramChip(Index)) { + //printf("evy - program failed2(%d)\n",Index); result = true; } else { - result = false; + //printf("evy - program failed3(%d)\n",Index); + result = false; } -// if(is_greater_than_5_0_0) -// SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); - g_is_operation_successful = result; +#if 0 + + /* if( !bAuto[Index] ) + { + + CompleteCnt++; + + if( CompleteCnt==get_usb_dev_cnt() ) + { + //m_context.runtime.is_operation_on_going = false; + //m_chip[Index]->ClearCancelOperationFlag(); + g_is_operation_on_going = false; + SerialFlash_ClearCancelOperationFlag(); + } + + } + else + { + // SerialFlash_ClearCancelOperationFlag(); + + }*/ +#endif + + + g_is_operation_successful[Index] = result; return result; } bool threadCompareFileAndChip(int Index) -{ - bool result = true; -// bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); - -// if(is_greater_than_5_0_0) -// SetLEDOnOff(SITE_BUSY,Index); +{ + bool result = true; SetIOMode(false,Index); @@ -618,7 +622,7 @@ bool threadCompareFileAndChip(int Index) size_t offset = min(DownloadAddrRange.length,g_ulFileSize); unsigned int crcFile = CRC32(pBufferforLoadedFile,offset); - unsigned int crcChip = CRC32(pBufferForLastReadData,offset); + unsigned int crcChip = CRC32(pBufferForLastReadData[Index],offset); // unsigned int i=0; #if 0 for(i=0; i<10; i++) @@ -630,11 +634,31 @@ bool threadCompareFileAndChip(int Index) result = (crcChip == crcFile); } + +#if 0 -// if(is_greater_than_5_0_0) -// SetLEDOnOff(result? SITE_OK:SITE_ERROR,Index); + if( !bAuto[Index] ) //not batch + { + + CompleteCnt++; + /*if( CompleteCnt==get_usb_dev_cnt() ) + { + //m_context.runtime.is_operation_on_going = false; + //m_chip[Index]->ClearCancelOperationFlag(); + g_is_operation_on_going = false; + //SerialFlash_ClearCancelOperationFlag(); + }*/ - g_is_operation_successful = result; + } + else + { + // g_is_operation_on_going = false; + // SerialFlash_ClearCancelOperationFlag(); + + } +#endif + + g_is_operation_successful[Index] = result; return result; } @@ -689,6 +713,8 @@ bool BlazeUpdate(int Index) // SetPageSize(&Chip_Info,Index); // dealwith lock phase 1 + + struct CAddressRange down_with_lock_range;//(m_context.runtime.range_download); down_with_lock_range.start=DownloadAddrRange.start; down_with_lock_range.end=DownloadAddrRange.end; @@ -699,14 +725,14 @@ bool BlazeUpdate(int Index) effectiveRange.start=down_with_lock_range.start &(~(Chip_Info.MaxErasableSegmentInByte - 1)) ; effectiveRange.end=(down_with_lock_range.end + (Chip_Info.MaxErasableSegmentInByte - 1)) & (~(Chip_Info.MaxErasableSegmentInByte - 1)); effectiveRange.length=effectiveRange.end-effectiveRange.start; - + if(!threadReadRangeChip(effectiveRange,Index)) return false; unsigned int offsetOfRealStartAddrOffset = DownloadAddrRange.start - effectiveRange.start; unsigned char* vc; vc=(unsigned char*)malloc(effectiveRange.length); - memcpy(vc,pBufferForLastReadData,effectiveRange.length); + memcpy(vc,pBufferForLastReadData[Index],effectiveRange.length); uintptr_t* addrs=(size_t*)malloc(min(DownloadAddrRange.length,g_ulFileSize)); size_t Leng=0; Leng=GenerateDiff(addrs,vc+offsetOfRealStartAddrOffset,DownloadAddrRange.length,pBufferforLoadedFile,g_ulFileSize,DownloadAddrRange.start,Chip_Info.MaxErasableSegmentInByte); @@ -819,13 +845,12 @@ bool RangeUpdate(int Index) : RangeUpdateThruChipErase(Index); } bool ReplaceChipContentThruChipErase(int Index) -{ - if(!threadBlankCheck(Index))//not blank - { - if(!threadEraseWholeChip(Index)) - return false; - } - +{ + if(!threadBlankCheck(Index))//not blank + { + if(!threadEraseWholeChip(Index)) + return false; + } return threadProgram(Index); } @@ -839,7 +864,7 @@ bool threadPredefinedBatchSequences(int Index) // bool bVerifyAfterCompletion; // 07.11.2009 // bool bIdentifyBeforeOperation; - + if( result && (!ValidateProgramParameters(Index)) ) result = false; #if 0 if(strstr(Chip_Info.Class,SUPPORT_MACRONIX_MX25Lxxx)!= NULL @@ -847,119 +872,152 @@ bool threadPredefinedBatchSequences(int Index) ||strstr(Chip_Info.Class,SUPPORT_MACRONIX_MX25Lxxx_PP32)!=NULL) Sleep(10); #endif - + if( result ) { switch(g_BatchIndex) { - case 1: - result=ReplaceChipContentThruChipErase(Index); - break; - case 2: - default: - result = RangeUpdate(Index); - break; + case 1: //-z + result=ReplaceChipContentThruChipErase(Index); + break; + case 2: + default: + result = RangeUpdate(Index); + break; } - } - + } return result; } void threadRun(void* Type) -{ +{ + THREAD_STRUCT* thread_data=(THREAD_STRUCT*)Type; OPERATION_TYPE opType=thread_data->type; - int Index=thread_data->USBIndex; - g_is_operation_successful = true; - - g_is_operation_on_going = true; - + int Index=thread_data->USBIndex; + g_is_operation_successful[Index] = true; + bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); + + if( opType==UPDATE_FIRMWARE ) - { - g_is_operation_successful=UpdateFirmware(g_parameter_fw, Index); - g_is_operation_on_going=false; - free(Type); + { + g_is_operation_successful[Index]=UpdateFirmware(g_parameter_fw, Index); + g_is_operation_on_going=false; + free(Type); return; } if(opType==AUTO_UPDATE_FIRMWARE) - { - free(Type); + { + free(Type); return; } if(1)//is_good()) - { + { TurnONVcc(Index); - bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); - - if(is_greater_than_5_0_0) - SetLEDOnOff(SITE_BUSY,Index); - + if(is_greater_than_5_0_0) + { + SetLEDOnOff(SITE_BUSY,Index); + } + if(IdentifyChipBeforeOperation(Index)==false) - { - printf("Warning: Failed to detect flash.\r\n"); - g_is_operation_on_going = false; - g_is_operation_successful = false; - SetLEDOnOff(g_is_operation_successful? SITE_OK:SITE_ERROR,Index); - TurnOFFVcc(Index); - free(Type); - return; + { + printf("Warning: Failed to detect flash (%d).\r\n",Index); + g_is_operation_successful[Index] = false; + } - // operations - switch(opType) + else + { + switch(opType) // operations { - case BLANKCHECK_WHOLE_CHIP: + case BLANKCHECK_WHOLE_CHIP: threadBlankCheck(Index); break; - - case ERASE_WHOLE_CHIP: + + case ERASE_WHOLE_CHIP: threadEraseWholeChip(Index); break; - case PROGRAM_CHIP: - TurnONVpp(); - threadProgram(Index); + case PROGRAM_CHIP: + + TurnONVpp(Index); + threadProgram(Index); + TurnOFFVpp(Index); break; case READ_WHOLE_CHIP: -// m threadReadChip(Index); + // m threadReadChip(Index); break; case READ_ANY_BY_PREFERENCE_CONFIGURATION: threadConfiguredReadChip(Index); break; - case VERIFY_CONTENT: + case VERIFY_CONTENT: threadCompareFileAndChip(Index); break; - case AUTO: - TurnONVpp(); + case AUTO: + TurnONVpp(Index); + bAuto[Index]=true; threadPredefinedBatchSequences(Index) ; + TurnOFFVpp(Index); break; - default: + default: break; } - } - TurnOFFVcc(Index); - TurnOFFVpp(); - SetLEDOnOff(g_is_operation_successful? SITE_OK:SITE_ERROR,Index); - g_is_operation_on_going = false; - free(Type); + } + + } + + SetLEDOnOff(g_is_operation_successful[Index]? SITE_OK:SITE_ERROR,Index); + + TurnOFFVcc(Index); + free(Type); + CompleteCnt++; + if(g_uiDevNum!=0) + g_is_operation_on_going = false; + else if( CompleteCnt==get_usb_dev_cnt()) + g_is_operation_on_going = false; + } -void Run(OPERATION_TYPE type) -{ - pthread_t id; -// int ret; +void Run(OPERATION_TYPE type,int DevIndex) +{ + int dev_cnt=get_usb_dev_cnt(); + pthread_t id; + THREAD_STRUCT *thread_data[16]; + CompleteCnt = 0; + g_is_operation_on_going = true; - THREAD_STRUCT *thread_data=(THREAD_STRUCT*)malloc(sizeof(THREAD_STRUCT)); - thread_data->type=type; - thread_data->USBIndex=0; - pthread_create(&id,NULL,(void *) threadRun,(void*)thread_data); + if(DevIndex==0)//mutiple + { + for(int i=0;itype=type; + bAuto[i]=false; + thread_data[i]->USBIndex=i; + pthread_create(&id,NULL,(void *) threadRun,(void*)thread_data[i]); + + } + } + else if(DevIndex<=dev_cnt) + { + thread_data[DevIndex-1]=(THREAD_STRUCT*)malloc(sizeof(THREAD_STRUCT)); + thread_data[DevIndex-1]->type=type; + bAuto[DevIndex-1]=false; + printf("\nSlot %d (%06d)",DevIndex,ReadUID(DevIndex-1)); + thread_data[DevIndex-1]->USBIndex=DevIndex-1; //0; + pthread_create(&id,NULL,(void *) threadRun,(void*)thread_data[DevIndex-1]); + } + else + printf("Error: Did not find the programmer.\r\n"); + + } void SetIOMode(bool isProg,int Index) @@ -968,7 +1026,7 @@ void SetIOMode(bool isProg,int Index) m_boEnReadQuadIO=0; m_boEnWriteQuadIO=0; - if(g_bIsSF600==false) return; + if(g_bIsSF600[Index]==false) return; SetIOModeToSF600(IOValue, Index); return; @@ -1067,21 +1125,21 @@ void SetIOMode(bool isProg,int Index) #endif } -int is_BoardVersionGreaterThan_5_0_0(int Index) +bool is_BoardVersionGreaterThan_5_0_0(int Index) { if(g_firmversion < FIRMWARE_VERSION(5, 0, 0)) return false; return true; } -int is_SF100nBoardVersionGreaterThan_5_5_0(int Index) +bool is_SF100nBoardVersionGreaterThan_5_5_0(int Index) { if((g_firmversion >= FIRMWARE_VERSION(5, 5, 0)) && strstr(g_board_type,"SF100") != NULL) return true; return false; } -int is_SF600nBoardVersionGreaterThan_6_9_0(int Index) +bool is_SF600nBoardVersionGreaterThan_6_9_0(int Index) { // printf("g_board_type=%s\r\n",g_board_type); if(strstr(g_board_type,"SF600") != NULL) @@ -1095,14 +1153,14 @@ int is_SF600nBoardVersionGreaterThan_6_9_0(int Index) return false; } -int is_SF100nBoardVersionGreaterThan_5_2_0(int Index) +bool is_SF100nBoardVersionGreaterThan_5_2_0(int Index) { if((g_firmversion >= FIRMWARE_VERSION(5, 2, 0)) && strstr(g_board_type,"SF100") != NULL) return true; return false; } -int is_SF600nBoardVersionGreaterThan_7_0_1n6_7_0(int Index) +bool is_SF600nBoardVersionGreaterThan_7_0_1n6_7_0(int Index) { if(strstr(g_board_type,"SF600") != NULL) { @@ -1132,9 +1190,9 @@ CHIP_INFO GetFirstDetectionMatch(int Index) g_Vcc=vcc1_8V-i; TurnONVcc(Index); - if(Is_usbworking()) + if(Is_usbworking(Index)) { - if(g_bIsSF600==true) + if(g_bIsSF600[Index]==true) { int startmode; @@ -1144,20 +1202,20 @@ CHIP_INFO GetFirstDetectionMatch(int Index) SetTargetFlash(STARTUP_APPLI_SF_1,Index); startmode=g_StartupMode; - Found=FlashIdentifier(&binfo,0); + Found=FlashIdentifier(&binfo,0,Index); if(Found==0) { TurnOFFVcc(Index); SetTargetFlash(STARTUP_APPLI_SF_SKT,Index); g_CurrentSeriase=Seriase_25; TurnONVcc(Index); - Found=FlashIdentifier(&binfo,0); + Found=FlashIdentifier(&binfo,0,Index); if(Found==0) { TurnOFFVcc(Index); g_CurrentSeriase=Seriase_45; TurnONVcc(Index); - Found=FlashIdentifier(&binfo,0); + Found=FlashIdentifier(&binfo,0,Index); if(Found==0) g_StartupMode=startmode; } @@ -1165,7 +1223,7 @@ CHIP_INFO GetFirstDetectionMatch(int Index) } else { - Found=FlashIdentifier(&binfo,0); + Found=FlashIdentifier(&binfo,0,Index); } } TurnOFFVcc(Index); @@ -1187,7 +1245,7 @@ void InitLED(int Index) SetLEDOnOff(SITE_NORMAL,Index); } -void SetProgReadCommand(void) +void SetProgReadCommand(int Index) { static const unsigned int AT26DF041 = 0x1F4400; static const unsigned int AT26DF004 = 0x1F0400; @@ -1411,7 +1469,7 @@ bool ProjectInitWithID(CHIP_INFO chipinfo,int Index) // by designated ID DownloadAddrRange.end=Chip_Info.ChipSizeInByte; InitLED(Index); // SetTargetFlash(g_StartupMode,Index); //for SF600 Freescale issue - SetProgReadCommand(); + SetProgReadCommand(Index); if(strcmp(g_parameter_vcc,"NO") == 0) { switch(Chip_Info.VoltageInMv) diff --git a/project.h b/project.h old mode 100644 new mode 100755 index 35234e8..31b7eda --- a/project.h +++ b/project.h @@ -24,11 +24,11 @@ typedef struct thread_data CONSOLE_USERS = 2, DLL_USERS = 3 } ; -int is_BoardVersionGreaterThan_5_0_0(int Inde); -int is_SF100nBoardVersionGreaterThan_5_5_0(int Index); -int is_SF600nBoardVersionGreaterThan_6_9_0(int Index); -int is_SF100nBoardVersionGreaterThan_5_2_0(int Index); -int is_SF600nBoardVersionGreaterThan_7_0_1n6_7_0(int Index); +bool is_BoardVersionGreaterThan_5_0_0(int Inde); +bool is_SF100nBoardVersionGreaterThan_5_5_0(int Index); +bool is_SF600nBoardVersionGreaterThan_6_9_0(int Index); +bool is_SF100nBoardVersionGreaterThan_5_2_0(int Index); +bool is_SF600nBoardVersionGreaterThan_7_0_1n6_7_0(int Index); int GetFileFormatFromExt(const char* csPath); CHIP_INFO GetFirstDetectionMatch(int Index); void SetIOMode(bool isProg,int Index); @@ -37,9 +37,9 @@ bool WriteFile(const char * csPath, unsigned char * buffer, unsigned int FileSiz void InitLED(int Index); bool ProjectInitWithID(CHIP_INFO chipinfo,int Index); // by designated ID bool ProjectInit(int Index); // by designated ID -void SetProgReadCommand(void); +void SetProgReadCommand(int Index); void threadRun(void* Type); -void Run(OPERATION_TYPE type); +void Run(OPERATION_TYPE type,int DevIndex); bool threadBlankCheck(int Index); bool threadEraseWholeChip(int Index); bool threadReadRangeChip(struct CAddressRange range,int Index); @@ -50,10 +50,10 @@ int ReadBINFile(const char *filename,unsigned char *buf, unsigned long* size); int WriteBINFile(const char *filename,unsigned char *buf, unsigned long size); bool LoadFile(char* filename); unsigned int CRC32(unsigned char* v, unsigned long size); -void TurnONVpp(void); +void TurnONVpp(int Index); void TurnONVcc(int Index); -void TurnOFFVpp(void); -void TurnOFFVcc(int Idex); +void TurnOFFVpp(int Index); +void TurnOFFVcc(int Index); bool ProgramChip(int Index); void PrepareProgramParameters(int Index); bool ValidateProgramParameters(int Index); diff --git a/usbdriver.c b/usbdriver.c old mode 100644 new mode 100755 index 5b54842..2c9d218 --- a/usbdriver.c +++ b/usbdriver.c @@ -6,19 +6,26 @@ unsigned int m_nbDeviceDetected = 0; unsigned char DevIndex = 0; -extern volatile bool g_bIsSF600; +extern volatile bool g_bIsSF600[16]; extern int g_CurrentSeriase; extern char g_board_type[8]; extern int g_firmversion; extern void Sleep(unsigned int ms); extern CHIP_INFO Chip_Info; +extern unsigned int g_uiDevNum; + + #define SerialFlash_FALSE -1 #define SerialFlash_TRUE 1 + +static usb_dev_handle *dediprog_handle[MAX_Dev_Index]; + extern int is_SF100nBoardVersionGreaterThan_5_5_0(int Inde); -// +extern int is_SF600nBoardVersionGreaterThan_6_9_0(int Inde); + bool Is_NewUSBCommand(int Index) { - if(is_SF100nBoardVersionGreaterThan_5_5_0(Index) || is_SF600nBoardVersionGreaterThan_6_9_0(Index)) + if(is_SF100nBoardVersionGreaterThan_5_5_0(Index) || is_SF600nBoardVersionGreaterThan_6_9_0(Index)) return true; return false; } @@ -34,10 +41,11 @@ void usb_dev_init(void) void usb_db_init(void) { int i; - for(i=0; inext) - { - for (dev = bus->devices; dev; dev = dev->next) - { - if ((dev->descriptor.idVendor == vid) && (dev->descriptor.idProduct == pid)) - { - usb_device_entry[dev_index].usb_device_handler = *dev; - usb_device_entry[dev_index].valid = 1; - dev_index++; - break; + { + for (dev = bus->devices; dev; dev = dev->next) + { + if ((dev->descriptor.idVendor == vid) && (dev->descriptor.idProduct == pid)) + { + usb_device_entry[dev_index].usb_device_handler = *dev; + usb_device_entry[dev_index].valid = 1; + dev_index++; } - } - } + } + } + + + printf(" \n"); return dev_index; } @@ -107,7 +123,7 @@ int OutCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size if( Index==-1 ) Index = DevIndex; - if( (rq->Function!=URB_FUNCTION_VENDOR_ENDPOINT) && (g_bIsSF600==true)) return true; + if( (rq->Function!=URB_FUNCTION_VENDOR_ENDPOINT) && (g_bIsSF600[Index]==true)) return true; requesttype = 0x00; @@ -118,8 +134,8 @@ int OutCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size if( rq->Function==URB_FUNCTION_VENDOR_OTHER ) requesttype |= 0x43; - if (dediprog_handle ) { - ret = usb_control_msg(dediprog_handle, requesttype, rq->Request, rq->Value, rq->Index, buf, buf_size, DEFAULT_TIMEOUT); + if (dediprog_handle[Index] ) { + ret = usb_control_msg(dediprog_handle[Index], requesttype, rq->Request, rq->Value, rq->Index, (char*)buf, buf_size, DEFAULT_TIMEOUT); }// else // printf("no device"); if(ret != buf_size) @@ -151,7 +167,7 @@ int InCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size, int requesttype; int ret = 0; - if( (rq->Function!=URB_FUNCTION_VENDOR_ENDPOINT) && (g_bIsSF600==true)) return true; + if( (rq->Function!=URB_FUNCTION_VENDOR_ENDPOINT) && (g_bIsSF600[Index]==true)) return true; if( Index==-1 ) Index = DevIndex; @@ -167,8 +183,8 @@ int InCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size, if( rq->Function==URB_FUNCTION_VENDOR_ENDPOINT ) requesttype |= 0x42; if( rq->Function==URB_FUNCTION_VENDOR_OTHER ) requesttype |= 0x43; - if (dediprog_handle ) { - ret = usb_control_msg(dediprog_handle, requesttype, rq->Request, rq->Value, rq->Index, buf, buf_size, DEFAULT_TIMEOUT); + if (dediprog_handle[Index] ) { + ret = usb_control_msg(dediprog_handle[Index], requesttype, rq->Request, rq->Value, rq->Index, (char*)buf, buf_size, DEFAULT_TIMEOUT); }// else // printf("no device"); @@ -201,7 +217,7 @@ int dediprog_start_appli(int Index) rq.Index = 0x00 ; rq.Length = 0x01 ; - ret = OutCtrlRequest(&rq, &vInstruction, 1, 0); + ret = OutCtrlRequest(&rq, &vInstruction, 1, Index); return ret; } @@ -253,7 +269,7 @@ int BulkPipeRead(unsigned char *pBuff, unsigned int timeOut, int Index) if( Index==-1 ) Index = DevIndex; unsigned long cnRead = 512; - ret = usb_bulk_read(dediprog_handle, 0x82, (char*)pBuff, cnRead, DEFAULT_TIMEOUT); + ret = usb_bulk_read(dediprog_handle[Index], 0x82, (char*)pBuff, cnRead, DEFAULT_TIMEOUT); cnRead = ret; return cnRead ; } @@ -272,7 +288,7 @@ int BulkPipeWrite(unsigned char *pBuff, unsigned int size,unsigned int timeOut, if( Index==-1 ) Index = DevIndex; - ret = usb_bulk_write(dediprog_handle, (g_bIsSF600==true)? 0x01:0x02,pData, nWrite, DEFAULT_TIMEOUT); + ret = usb_bulk_write(dediprog_handle[Index], (g_bIsSF600[Index]==true)? 0x01:0x02,pData, nWrite, DEFAULT_TIMEOUT); nWrite = ret; return nWrite; } @@ -291,9 +307,9 @@ int dediprog_set_spi_voltage(int v,int Index) rq.Direction = VENDOR_DIRECTION_OUT ; rq.Request = SET_VCC ; rq.Length = 0 ; - + if(Is_NewUSBCommand(Index)) - { + { // if(g_bIsSF600==true && (strstr(Chip_Info.Class,SUPPORT_ATMEL_45DBxxxB) != NULL || strstr(Chip_Info.Class,SUPPORT_ATMEL_45DBxxxD) != NULL)) // v |= 0x8000; // printf("v==%x\n",v); @@ -301,10 +317,10 @@ int dediprog_set_spi_voltage(int v,int Index) rq.Index = 0; } else - { + { rq.Value = v ; rq.Index = 0x04 | g_CurrentSeriase; // ID detect mode - } + } ret = OutCtrlRequest(&rq, NULL, 0, Index); // printf("ret=%x\r\n",ret); #if 0 @@ -349,12 +365,12 @@ int dediprog_set_spi_voltage(int v,int Index) return false; } #endif - if(0 != v) Sleep(200); + if(0 != v) Sleep(200); return ret; } -int dediprog_set_vpp_voltage(int volt) +int dediprog_set_vpp_voltage(int volt,int Index) { int ret; int voltage_selector; @@ -383,7 +399,7 @@ int dediprog_set_vpp_voltage(int volt) rq.Index = 0 ; rq.Length = 0x0 ; - ret = OutCtrlRequest(&rq, NULL, 0, 0); + ret = OutCtrlRequest(&rq, NULL, 0, Index); if (ret == SerialFlash_FALSE) { // printf("Command Set VPP Voltage 0x%x failed!\n", voltage_selector); @@ -392,7 +408,7 @@ int dediprog_set_vpp_voltage(int volt) return 0; } -int dediprog_set_spi_clk(int khz) +int dediprog_set_spi_clk(int khz,int Index) { return 0; int ret; @@ -441,7 +457,7 @@ int dediprog_set_spi_clk(int khz) rq.Index = 0 ; rq.Length = 0x0 ; - ret = OutCtrlRequest(&rq, NULL, 0, 0); + ret = OutCtrlRequest(&rq, NULL, 0, Index); if (ret == SerialFlash_FALSE) { // printf("Command Set SPI clk 0x%x failed!\n", hz_selector); @@ -453,55 +469,110 @@ int dediprog_set_spi_clk(int khz) int usb_driver_init(void) { - struct usb_bus *bus; - struct usb_device *dev; - + // struct usb_bus *bus; + // struct usb_device *dev; + bool result = false; int device_cnt = 0; - int ret; - dediprog_handle=NULL; - usb_dev_init(); + int ret; - device_cnt = FindUSBDevice(); - if(usb_device_entry[device_cnt-1].valid==0) + for(int i=0;i command,int Index) long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size ,int Index) diff --git a/usbdriver.h b/usbdriver.h old mode 100644 new mode 100755 index 868251f..45e3efa --- a/usbdriver.h +++ b/usbdriver.h @@ -25,9 +25,8 @@ #define VENDOR_DIRECTION_OUT 0 #define DEFAULT_TIMEOUT 30000 - -static usb_dev_handle *dediprog_handle=NULL; -#define MAX_Dev_Index 10 + +#define MAX_Dev_Index 16 typedef struct usb_device_entry { struct usb_device usb_device_handler; @@ -55,8 +54,9 @@ usb_device_entry_t usb_device_entry[MAX_Dev_Index]; #define ERROR_ON (0 << 2) #define ERROR_OFF (1 << 2) -int usb_driver_init(void); - +int dev_index; +int usb_driver_init(void); +int get_usb_dev_cnt(void); int usb_driver_release(void); int OutCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size ,int Index ); @@ -66,7 +66,7 @@ int InCtrlRequest( CNTRPIPE_RQ *rq, unsigned char *buf, unsigned long buf_size, int BulkPipeRead(unsigned char *pBuff, unsigned int timeOut, int Index); int dediprog_set_spi_voltage(int millivolt, int Index); -int dediprog_set_vpp_voltage(int volt); +int dediprog_set_vpp_voltage(int volt,int Index); long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size ,int Index);