From b99e9db6352f85a446e274b284ab4beb4da34973 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 7 Jan 2021 11:30:49 +0800 Subject: [PATCH] dpcmd.c --- .gitignore | 0 60-dediprog.rules | 0 ChipInfoDb.dedicfg | 0 ChipInfoDb.h | 6 + FlashCommand.c | 0 FlashCommand.h | 0 IntelHexFile.c | 0 IntelHexFile.h | 0 LICENSE | 0 Macro.h | 2 +- Makefile | 0 MotorolaFile.c | 0 MotorolaFile.h | 0 README.md | 0 SerialFlash.c | 53 ++++--- SerialFlash.h | 0 board.c | 32 ++-- board.h | 0 dpcmd.c | 378 +++++++++++++++++++++++++++++++++++---------- dpcmd.h | 5 +- parse.c | 343 ++++++++++++++++++++++++++++++++-------- project.c | 126 +++++++++++++-- project.h | 5 + usbdriver.c | 88 ++++++----- usbdriver.h | 0 25 files changed, 794 insertions(+), 244 deletions(-) mode change 100644 => 100755 .gitignore 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 LICENSE mode change 100644 => 100755 Macro.h mode change 100644 => 100755 Makefile mode change 100644 => 100755 MotorolaFile.c mode change 100644 => 100755 MotorolaFile.h mode change 100644 => 100755 README.md 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 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/.gitignore b/.gitignore old mode 100644 new mode 100755 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 3fd3390..8def8e1 --- a/ChipInfoDb.h +++ b/ChipInfoDb.h @@ -20,7 +20,13 @@ bool Dedi_List_AllChip(void); int ChipInfoDbFindItem(CHIP_INFO ChipInfoDb[], int NumberOfItems, long JedecDeviceIDToFind); void ChipInfoDump(long JedecDeviceIDToFind); long ChipInfoDumpChipSizeInKByte(long Jedec); +#if 0 int Dedi_Search_Chip_Db(long RDIDCommand, long UniqueID, CHIP_INFO* Chip_Info, int search_all); + +#else + +int Dedi_Search_Chip_Db(char* TypeName, long RDIDCommand, long UniqueID, CHIP_INFO* Chip_Info, int search_all); +#endif int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info); FILE* openChipInfoDb(void); diff --git a/FlashCommand.c b/FlashCommand.c old mode 100644 new mode 100755 diff --git a/FlashCommand.h b/FlashCommand.h old mode 100644 new mode 100755 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/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Macro.h b/Macro.h old mode 100644 new mode 100755 index e7a8ae1..184ba87 --- a/Macro.h +++ b/Macro.h @@ -303,7 +303,7 @@ typedef struct ChipInfo { #define BLINK BIT10 #define DEVICE_ID BIT11 #define LIST_TYPE BIT12 -#define LOADFILE BIT13 +#define LOADFILEWITHVERIFY BIT13 struct CAddressRange { size_t start; diff --git a/Makefile b/Makefile 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/README.md b/README.md old mode 100644 new mode 100755 diff --git a/SerialFlash.c b/SerialFlash.c old mode 100644 new mode 100755 index c74bf5d..fdf5ec3 --- a/SerialFlash.c +++ b/SerialFlash.c @@ -12,6 +12,7 @@ extern int m_boEnReadQuadIO; extern int m_boEnWriteQuadIO; extern CHIP_INFO Chip_Info; extern volatile bool g_bIsSF600[16]; +extern volatile bool g_bIsSF700[16]; extern bool Is_NewUSBCommand(int Index); unsigned char mcode_WRSR = 0x01; @@ -1762,12 +1763,12 @@ int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vDa if (strstr(Chip_Info.Class, SUPPORT_ATMEL_45DBxxxB) != NULL || strstr(Chip_Info.Class, SUPPORT_ATMEL_45DBxxxD) != NULL) return AT45rangeProgram(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) { - if (g_bIsSF600[Index] == true) + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADR_256BYTE, mcode_ProgramCode_4Adr, Index); else return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_12, mcode_ProgramCode_4Adr, Index); } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) { - if (g_bIsSF600[Index] == true) { + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) { return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_S70FS01GS, mcode_ProgramCode_4Adr_S70FSxxx, Index); } else return false; @@ -1777,20 +1778,21 @@ int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vDa int SerialFlash_rangeRead(struct CAddressRange* AddrRange, unsigned char* vData, int Index) { +//printf("SerialFlash_rangeRead"); if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) { - if (g_bIsSF600[Index] == true) + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode, Index); else return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ_MICRON, mcode_ReadCode, Index); } if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) { - if (g_bIsSF600[Index] == true) + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode_S70FSxxx, Index); else return false; - } else { + } else return SerialFlash_bulkPipeRead(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode, Index); - } + }; /** @@ -2164,22 +2166,21 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* } int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeRead, unsigned char ReadCom, int Index) -{ +{ size_t i, j, loop, pageNum, BufferLocation = 0; - int ret = 0; - if (!SerialFlash_StartofOperation(Index)) - return false; - if (!(strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL && strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL && g_bIsSF600[Index] == true)) + int ret = 0; + if (!SerialFlash_StartofOperation(Index)) + return false; + if (!(strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL && strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL && ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)))) SerialFlash_Enable4ByteAddrMode(true, Index); - + if (SerialFlash_EnableQuadIO(true, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) return false; - - // unsigned char v[512]; + AddrRange->length = AddrRange->end - AddrRange->start; - if (AddrRange->length <= 0) { + if (AddrRange->length <= 0) return false; - } + // printf("AddrRange->end=%x, AddrRange->start=%x\n",AddrRange->end,AddrRange->start); if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) //(AddrRange.end>0x1000000 && AddrRange.start<0x1000000) { @@ -2193,7 +2194,7 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa loop = (range_temp.end - range_temp.start) / 0x1000000; for (j = 0; j < loop; j++) { - if (g_bIsSF600[Index] == false && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) // for sf100 + if (((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) // for sf100 { unsigned char re = 0; int numOfRetry = 5; @@ -2207,8 +2208,8 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa Sleep(100); CN25Qxxx_MutipleDIe_LargeRDEAR(&re, Index); } while (((re & j) != j) && numOfRetry-- > 0); - if (numOfRetry == 0) - return false; + if (numOfRetry == 0) + return false; } if (j == (loop - 1)) @@ -2227,15 +2228,15 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Index); for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + (BufferLocation + i) * 512, USB_TIMEOUT, Index); - if ((ret != 512) || m_isCanceled) - return 0; + if ((ret != 512) || m_isCanceled) + return 0; //memcpy(vData + (BufferLocation+i)*512, v, 512); } BufferLocation += pageNum; } } else { unsigned char EAR = (AddrRange->start * 0x1000000) >> 24; - if (g_bIsSF600[Index] == false && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) { + if (((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) { unsigned char re = 0; int numOfRetry = 5; do { @@ -2248,21 +2249,23 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa Sleep(100); CN25Qxxx_MutipleDIe_LargeRDEAR(&re, Index); } while (((re & EAR) != EAR) && numOfRetry-- > 0); - if (numOfRetry == 0) + if (numOfRetry == 0){ return false; + } } pageNum = AddrRange->length >> 9; FlashCommand_SendCommand_SetupPacketForBulkRead(AddrRange, modeRead, ReadCom, Index); for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + i * ret, USB_TIMEOUT, Index); if ((ret != 512) || m_isCanceled) { + //printf("SerialFlash_bulkPipeRead5,ret=%d, m_isCanceled=%s\n",ret,m_isCanceled?"true":"false"); return false; } //memcpy(vData + i*ret, v, ret); } - } + } if (SerialFlash_EnableQuadIO(false, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) - return false; + return false; SerialFlash_Enable4ByteAddrMode(false, Index); if (!SerialFlash_EndofOperation(Index)) diff --git a/SerialFlash.h b/SerialFlash.h old mode 100644 new mode 100755 diff --git a/board.c b/board.c old mode 100644 new mode 100755 index 1e3fa57..14fdd9d --- a/board.c +++ b/board.c @@ -8,6 +8,7 @@ #define min(a, b) (a > b ? b : a) volatile bool g_bIsSF600 = false; +volatile bool g_bIsSF700 = false; extern char g_board_type[8]; extern int g_firmversion; extern unsigned int g_IO1Select; @@ -102,9 +103,8 @@ void QueryBoard(int Index) unsigned char GetFPGAVersion(int Index) { - if (strstr(g_board_type, "SF600") == NULL) - return -1; - + if ((strstr(g_board_type, "SF600") == NULL) && (strstr(g_board_type, "SF700") == NULL)) + return -1; CNTRPIPE_RQ rq; unsigned char vDataPack; @@ -168,6 +168,7 @@ bool SetTargetFlash(unsigned char StartupMode, int Index) bool SetLEDProgBoard(size_t Color, int Index) { + //printf("\n===>board.c ---- SetLEDProgBoard(Color=%ld,SetLEDProgBoard=%d)\n",Color,Index); if (!Is_usbworking(Index)) { return false; } @@ -178,10 +179,12 @@ bool SetLEDProgBoard(size_t Color, int Index) rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = SET_IO; - if (Is_NewUSBCommand(Index)) { - rq.Value = (Color & 0xFFF7) | (g_IO1Select << 1) | (g_IO4Select << 3); + if (Is_NewUSBCommand(Index)) { + rq.Value = Color | (g_IO1Select << 1); + rq.Value = (rq.Value& 0xFFF7) | (g_IO4Select << 3); + //rq.Value = (Color & 0xFFF7) | (g_IO1Select << 1) | (g_IO4Select << 3); rq.Index = 0; - } else { + } else { rq.Value = 0x09; rq.Index = Color >> 8; // LED 0:ON 1:OFF Bit0:Green Bit1:Orange Bit2:Red } @@ -336,12 +339,15 @@ unsigned int ReadUID(int Index) return false; } unsigned int dwUID = 0; + unsigned char vUID[16]; - if (g_bIsSF600 == true) { - unsigned char vUID[16]; + if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) { if (ReadOnBoardFlash(vUID, false, Index) == false) return false; - dwUID = (unsigned int)vUID[0] << 16 | (unsigned int)vUID[1] << 8 | vUID[2]; + if(g_bIsSF600 == true) + dwUID = (unsigned int)vUID[0] << 16 | (unsigned int)vUID[1] << 8 | vUID[2]; + else + dwUID = (unsigned int)vUID[2] << 16 | (unsigned int)vUID[1] << 8 | vUID[0]; return dwUID; } @@ -436,7 +442,7 @@ unsigned char ReadManufacturerID(int Index) if (!Is_usbworking(Index)) return false; - if (g_bIsSF600 == true) { + if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) { unsigned char vUID[16]; if (ReadOnBoardFlash(vUID, false, Index) == false) return false; @@ -596,7 +602,7 @@ bool WriteUID(unsigned int dwUID, int Index) if (!Is_usbworking(Index)) return false; - if (g_bIsSF600) + if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) return true; CNTRPIPE_RQ rq; @@ -636,7 +642,7 @@ bool WriteManufacturerID(unsigned char ManuID, int Index) if (!Is_usbworking(Index)) return false; - if (g_bIsSF600) + if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) return true; CNTRPIPE_RQ rq; @@ -898,7 +904,7 @@ bool UpdateFirmware(const char* sFolder, int Index) unsigned int UID = 0; unsigned char ManID = 0; // read status - if (g_bIsSF600 == true) + if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) return UpdateSF600Firmware(sFolder, Index); dediprog_set_spi_voltage(g_Vcc, Index); diff --git a/board.h b/board.h old mode 100644 new mode 100755 diff --git a/dpcmd.c b/dpcmd.c old mode 100644 new mode 100755 index e17d57b..6d90a64 --- a/dpcmd.c +++ b/dpcmd.c @@ -22,6 +22,7 @@ extern unsigned char* pBufferforLoadedFile; extern unsigned int g_uiFileChecksum; extern unsigned long g_ulFileSize; extern volatile bool g_bIsSF600[16]; +extern volatile bool g_bIsSF700[16]; extern unsigned char g_BatchIndex; unsigned int g_Vcc = vcc3_5V; @@ -30,19 +31,21 @@ unsigned int g_uiAddr = 0; size_t g_uiLen = 0; unsigned int g_ucFill = 0xFF; unsigned int g_ucTarget = 1; -unsigned int g_uiTimeout = 1800; +unsigned int g_uiTimeout = 3000; unsigned int g_ucSPIClock = clk_12M; unsigned int g_uiBlink = 0; unsigned int g_uiDevNum = 0; +//unsigned int g_uiDevSNNum = 0; unsigned int g_uiDeviceID = 0; unsigned int g_IO1Select = 0; -unsigned int g_IO4Select = 1; +unsigned int g_IO4Select = 1; +char strTypeName[1024] = "\0"; bool g_bEnableVpp = false; int g_StartupMode = STARTUP_APPLI_SF_1; bool g_bStatus = true; -CHIP_INFO Chip_Info; +CHIP_INFO Chip_Info; char* l_opt_arg; struct CAddressRange DownloadAddrRange; struct CAddressRange UploadAddrRange; @@ -52,8 +55,8 @@ unsigned int g_uiLockLen = 0; unsigned int g_uiLockStart = 0; char* g_parameter_read = "\0"; -char* g_parameter_program = "\0"; -char* g_parameter_loadfile = "\0"; +char* g_parameter_program = "\0"; +char* g_parameter_loadfile_with_verify = "\0"; char* g_parameter_auto = "\0"; char* g_parameter_batch = "\0"; char* g_parameter_fsum = "\0"; @@ -153,10 +156,11 @@ 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' }, + { "device-SN", 1, NULL, 'X' }, // { "fix-device", 1, NULL, 'F' }, { "list-device-id", 1, NULL, 'V' }, - { "load-file", 1, NULL, 'F' }, + { "loadFile-with-verify", 1, NULL, 'W' }, { "timeout", 1, NULL, 't' }, { "target", 1, NULL, 'g' }, { "vcc", 1, NULL, 'c' }, @@ -175,7 +179,7 @@ struct option long_options[] = { }; int OpenUSB(void); -#if 0 +#if 0 //evy test SF700 int verbose = 1; void print_endpoint(struct usb_endpoint_descriptor *endpoint) @@ -326,7 +330,7 @@ int Check(int argc, char *argv[]) #endif int Sequence() -{ +{ // *** the calling order in the following block must be kept as is *** bool boResult = true; boResult &= BlankCheck(); @@ -369,11 +373,15 @@ int Sequence() } } else return EXCODE_FAIL_CHKSUM; - + boResult &= Verify(); if (boResult == false) return EXCODE_FAIL_VERIFY; + boResult &= LoadFileWithVerify(); + if (boResult == false) + return EXCODE_FAIL_LOADFILEWITHVERIFY; + return EXCODE_PASS; } @@ -396,13 +404,13 @@ void GetLogPath(char* pBuf) void EnterStandaloneMode(int Index) { - if (g_bIsSF600[Index] == true) + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) LeaveSF600Standalone(false, Index); } void LeaveStandaloneMode(int Index) { - if (g_bIsSF600[Index] == true) + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) LeaveSF600Standalone(true, Index); } @@ -474,8 +482,8 @@ int GetConfigVer() } int main(int argc, char* argv[]) -{ -#if 0 //Check all USB device capability +{ +#if 0 //Check all USB device capability //evy test SF700 Check(argc,argv); return; @@ -484,10 +492,11 @@ int main(int argc, char* argv[]) int iExitCode = EXCODE_PASS; bool bDetect = false; bool bDevice = false; + bool bDeviceSN = false; unsigned long r; char *env; - printf("\nDpCmd Linux 1.11.3.%02d Engine Version:\nLast Built on May 25 2018\n\n", GetConfigVer()); // 1. new feature.bug.configS + printf("\nDpCmd Linux 1.11.4.%02d Engine Version:\nLast Built on May 25 2018\n\n", GetConfigVer()); // 1. new feature.bug.configS g_ucOperation = 0; GetLogPath(g_LogPath); @@ -626,20 +635,22 @@ int main(int argc, char* argv[]) sscanf(optarg, "%d", &g_uiBlink); g_ucOperation |= BLINK; break; - case 'D': // device - //l_opt_arg = optarg; + case 'D': // device + bDevice = true; + sscanf(optarg, "%x", &g_uiDevNum); + break; + case 'X': // device-SN + 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; + bDeviceSN = true; break; - case 'F': + case 'W': // l_opt_arg = optarg; // printf("Fix programmer serial number with programmer sequence. (with arg: %s)\n", l_opt_arg); // break; - g_parameter_loadfile = optarg; - g_ucOperation |= LOADFILE; + g_parameter_loadfile_with_verify = optarg; + g_ucOperation |= LOADFILEWITHVERIFY; break; case 'V': sscanf(optarg, "%d", &g_uiDeviceID); @@ -721,53 +732,117 @@ int main(int argc, char* argv[]) } } - + int dev_cnt = get_usb_dev_cnt(); - if (bDetect == true) { - if (bDevice == false) { - for (int i = 0; i < dev_cnt; i++) { - // //printf("%s\n",g_LogPath); - - int dwUID = ReadUID(i); - if ((dwUID / 600000) > 0) { - printf("\nDevice %d (SF%06d):\tdetecting chip\n", i + 1, dwUID); - } else { - printf("\nDevice %d (DP%06d):\tdetecting chip\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 ]\n", Chip_Info.TypeName); - printf("%s chip size is %zd bytes.\n", Chip_Info.TypeName, Chip_Info.ChipSizeInByte); - } else { - printf("%s", msg_err_identifychip); - iExitCode = EXCODE_FAIL_IDENTIFY; + if (bDetect == true) { + if (bDevice == false) { + if(bDeviceSN){ + char *arg_temp=&l_opt_arg[2]; + int arg_int = atoi(arg_temp); + + for (int i = 0; i < dev_cnt; i++) { + int dwUID = ReadUID(i); + if(arg_int==dwUID) { + g_uiDevNum = i + 1; + break; + } + } + int dwUID = ReadUID(g_uiDevNum - 1); + if (g_bIsSF700[g_uiDevNum -1]==true){ + printf("\nDevice %d (SF7%05X):\tdetecting chip\n", g_uiDevNum, dwUID); + } + else if ((dwUID / 600000) > 0) { + printf("\nDevice %d (SF%06d):\tdetecting chip\n", g_uiDevNum, dwUID); + } else { + printf("\nDevice %d (DP%06d):\tdetecting chip\n", g_uiDevNum, dwUID); + } + WriteLog(iExitCode, true); + Chip_Info=GetFirstDetectionMatch(strTypeName,g_uiDevNum - 1); + if (Chip_Info.UniqueID != 0) { + if(strlen(strTypeName)){ + printf("By reading the chip ID, the chip applies to [ %s ]\n\n", strTypeName); + printf("%s chip size is %zd bytes.\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; } + } else { //bDevice == true + for (int i = 0; i < dev_cnt; i++) { + //printf("%s\n",g_LogPath); + + int dwUID = ReadUID(i); + if (g_bIsSF700[i]==true){ + printf("\nDevice %d (SF7%05X):\tdetecting chip\n", i + 1, dwUID); + } + else if ((dwUID / 600000) > 0) { + printf("\nDevice %d (SF%06d):\tdetecting chip\n", i + 1, dwUID); + } else { + printf("\nDevice %d (DP%06d):\tdetecting chip\n", i + 1, dwUID); + } + WriteLog(iExitCode, true); + Chip_Info=GetFirstDetectionMatch(strTypeName,i); + if (Chip_Info.UniqueID != 0) { + if(strlen(strTypeName)){ + printf("By reading the chip ID, the chip applies to [ %s ]\n", strTypeName); + printf("%s chip size is %zd bytes.\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; + } + } } - } else if (g_uiDevNum != 0) { + + } else if (g_uiDevNum != 0) { WriteLog(iExitCode, true); printf("%d,\tdetecting chip\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 ]\n", Chip_Info.TypeName); - printf(" \t%s chip size is %zd bytes.\n", Chip_Info.TypeName, Chip_Info.ChipSizeInByte); - } else { - printf("%s", msg_err_identifychip); - iExitCode = EXCODE_FAIL_IDENTIFY; + Chip_Info=GetFirstDetectionMatch(strTypeName,g_uiDevNum - 1); + + if (Chip_Info.UniqueID != 0) { + //printf("strlen(strTypeName)=%ld\n",strlen(strTypeName)); + if(strlen(strTypeName)){ + printf(" \tBy reading the chip ID, the chip applies to [ %s ]\n\n", strTypeName); + printf(" \t%s chip size is %zd bytes.\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; } - } else { + }else { printf("The number of programmer is not defined!\n"); iExitCode = EXCODE_FAIL_IDENTIFY; - } + } goto Exit; - } else + } else{ + if(bDeviceSN){ + char *arg_temp=&l_opt_arg[2]; + int arg_int = atoi(arg_temp); + + for (int i = 0; i < dev_cnt; i++) { + int dwUID = ReadUID(i); + if(arg_int==dwUID) { + g_uiDevNum = i + 1; + break; + } + } + } WriteLog(iExitCode, true); - + } if (iExitCode != EXCODE_PASS) goto Exit; iExitCode = Handler(); -Exit: +Exit: printf("\n\n"); CloseProject(); ExitProgram(); @@ -991,7 +1066,7 @@ void cli_classic_usage(bool IsShowExample) } int OpenUSB(void) -{ +{ return usb_driver_init(); } @@ -1003,7 +1078,7 @@ void sin_handler(int sig) } int Handler(void) -{ +{ if (Is_usbworking(0) == true) { #if 0 if(m_vm.count("fix-device")) @@ -1050,8 +1125,9 @@ int Handler(void) printf("Error: Did not find the programmer.\n"); return EXCODE_FAIL_OTHERS; } + return Sequence(); - } else if (DetectChip()) { + } else if (DetectChip()) { return Sequence(); } else return EXCODE_FAIL_IDENTIFY; @@ -1061,6 +1137,7 @@ int Handler(void) bool InitProject(void) { + //printf("bool InitProject(void)\n"); int dev_cnt = get_usb_dev_cnt(); if (Is_usbworking(0)) { int targets[4] = { @@ -1130,8 +1207,9 @@ void CloseProject(void) bool DetectChip(void) { +//printf("DetectChip(void)\n"); int dev_cnt = get_usb_dev_cnt(); - Chip_Info = GetFirstDetectionMatch(0); + Chip_Info = GetFirstDetectionMatch(strTypeName,0); if (g_uiDevNum == 0) { for (int i = 0; i < dev_cnt; i++) { if (!Is_usbworking(i)) { @@ -1142,7 +1220,7 @@ bool DetectChip(void) printf("%s", msg_err_identifychip); return false; } - printf("By reading the chip ID, the chip applies to [ %s ]\n", Chip_Info.TypeName); + printf("By reading the chip ID, the chip applies to [ %s ]\n\n", strTypeName); printf("%s parameters to be applied by default\n", Chip_Info.TypeName); printf("%s chip size is %zd bytes.\n\n", Chip_Info.TypeName, Chip_Info.ChipSizeInByte); @@ -1157,7 +1235,7 @@ bool DetectChip(void) printf("%s", msg_err_identifychip); return false; } - printf("By reading the chip ID, the chip applies to [ %s ]\n", Chip_Info.TypeName); + printf("By reading the chip ID, the chip applies to [ %s ]\n\n", Chip_Info.TypeName); printf("%s parameters to be applied by default\n", Chip_Info.TypeName); printf("%s chip size is %zd bytes.\n\n", Chip_Info.TypeName, Chip_Info.ChipSizeInByte); @@ -1183,7 +1261,7 @@ void SetSPIClock(int Index) void SetVcc(int Index) { // sscanf(g_parameter_vcc,"%d",&g_Vcc); - if (!(g_Vcc <= 3800 && g_Vcc >= 1800 && g_bIsSF600[Index] == true)) + if (!(g_Vcc <= 3800 && g_Vcc >= 1800 && ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)))) g_Vcc = (0x10 | (g_Vcc & 0x03)); } @@ -1191,9 +1269,7 @@ int do_loadFile(void) { char* filename = NULL; if (g_ucOperation & PROGRAM) - filename = g_parameter_program; - else if (g_ucOperation & LOADFILE) - filename = g_parameter_loadfile; + filename = g_parameter_program; else if (g_ucOperation & BATCH) { switch (g_BatchIndex) { case 1: @@ -1207,7 +1283,17 @@ int do_loadFile(void) } else if (g_ucOperation & FSUM) filename = g_parameter_fsum; printf("%s", msg_info_loading); - printf("(%s)", filename); + printf("(%s)\n", filename); + return LoadFile(filename); +} + +int do_loadFileWithVerify(void) +{ + char* filename = NULL; + if (g_ucOperation & LOADFILEWITHVERIFY) + filename = g_parameter_loadfile_with_verify; + printf("%s", msg_info_loading); + printf("(%s)\n", filename); return LoadFile(filename); } @@ -1254,7 +1340,9 @@ void ListSFSerialID(void) if (g_uiDeviceID < 1) { for (unsigned int i = 0; i < dev_cnt; i++) { dwUID = ReadUID(i); - if ((dwUID / 600000) == 0) + if (g_bIsSF700[i]==true) + printf("%d,\tSF7%05X\n", i + 1, dwUID); + else if ((dwUID / 600000) == 0) printf("%d,\tDP%06d\n", i + 1, dwUID); else printf("%d,\tSF%06d\n", i + 1, dwUID); @@ -1264,7 +1352,9 @@ void ListSFSerialID(void) printf("The number of programmer is not defined!\n"); else { dwUID = ReadUID(g_uiDeviceID - 1); - if ((dwUID / 600000) == 0) + if (g_bIsSF700[g_uiDeviceID - 1]==true) + printf("%d,\tSF7%05X\n", g_uiDeviceID, dwUID); + else if ((dwUID / 600000) == 0) printf("%d,\tDP%06d\n", g_uiDeviceID, dwUID); else printf("%d,\tSF%06d\n", g_uiDeviceID, dwUID); @@ -1398,8 +1488,8 @@ void do_Auto(void) void do_Verify(void) { - if (g_ucOperation & LOADFILE) - do_loadFile(); + // if (g_ucOperation & LOADFILE) + // do_loadFile(); printf("%s", msg_info_verifying); Run(VERIFY_CONTENT, g_uiDevNum); @@ -1536,8 +1626,18 @@ bool Auto(void) return g_bStatus; } +bool LoadFileWithVerify(void) +{ + if (g_ucOperation & LOADFILEWITHVERIFY) { + do_loadFileWithVerify(); + if(g_bStatus) + do_Verify(); + } + return g_bStatus; +} + bool Verify(void) -{ +{ if (g_ucOperation & VERIFY) do_Verify(); return g_bStatus; @@ -1556,14 +1656,18 @@ bool CalChecksum(void) for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); if (g_uiAddr == 0 && g_uiLen == 0) { - if ((dwUID / 600000) == 0) + if (g_bIsSF700[i]==true) + printf("\nDevice %d (SF7%05X):", i + 1, dwUID); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", i + 1, dwUID); else printf("\nDevice %d (SF%06d):", i + 1, dwUID); printf("Checksum of the whole chip(address starting from: 0x%X, 0x%zX bytes in total): %08X\n", g_uiAddr, Chip_Info.ChipSizeInByte, CRC32(pBufferForLastReadData[i], Chip_Info.ChipSizeInByte)); } else { - if ((dwUID / 600000) == 0) + if (g_bIsSF700[i]==true) + printf("\nDevice %d (SF7%05X):", i + 1, ReadUID(i)); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", i + 1, ReadUID(i)); else printf("\nDevice %d (SF%06d):", i + 1, ReadUID(i)); @@ -1574,14 +1678,18 @@ bool CalChecksum(void) } else if (g_uiDevNum != 0) { int dwUID = ReadUID(g_uiDevNum - 1); if (g_uiAddr == 0 && g_uiLen == 0) { - if ((dwUID / 600000) == 0) + if (g_bIsSF700[g_uiDevNum - 1]==true) + printf("\nDevice %d (SF7%05X):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); else printf("\nDevice %d (SF%06d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); printf("Checksum of the whole chip(address starting from: 0x%X, 0x%zX bytes in total): %08X\n", g_uiAddr, Chip_Info.ChipSizeInByte, CRC32(pBufferForLastReadData[g_uiDevNum - 1], Chip_Info.ChipSizeInByte)); - } else { - if ((dwUID / 600000) == 0) + } else { + if (g_bIsSF700[g_uiDevNum - 1]==true) + printf("\nDevice %d (SF7%05X):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); else printf("\nDevice %d (SF%06d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); @@ -1596,7 +1704,7 @@ bool CalChecksum(void) bool Wait(const char* strOK, const char* strFail) { - size_t timeOut = g_uiTimeout; + size_t timeOut = g_uiTimeout; struct timeval tv, basetv, diff; int dev_cnt = get_usb_dev_cnt(); gettimeofday(&basetv, NULL); @@ -1627,7 +1735,9 @@ bool Wait(const char* strOK, const char* strFail) { for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); - if ((dwUID / 600000) == 0) + if (g_bIsSF700[i]==true) + printf("\nDevice %d (SF7%05X):", i + 1, dwUID); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", i + 1, dwUID); else printf("\nDevice %d (SF%06d):", i + 1, dwUID); @@ -1636,7 +1746,9 @@ bool Wait(const char* strOK, const char* strFail) } } else if (g_uiDevNum <= dev_cnt) { int dwUID = ReadUID(g_uiDevNum - 1); - if ((dwUID / 600000) == 0) + if (g_bIsSF700[g_uiDevNum - 1]==true) + printf("\nDevice %d (SF7%05X):", g_uiDevNum, dwUID); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", g_uiDevNum, dwUID); else printf("\nDevice %d (SF%06d):", g_uiDevNum, dwUID); @@ -1646,12 +1758,14 @@ bool Wait(const char* strOK, const char* strFail) } return g_bStatus; } - -int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) +#if 0 +int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) { + +printf("FlashIdentifier(search_all=%d,Index=%x)\n",search_all,Index); long UniqueID = 0; int rc = 0; - + for (int c = 0; c < 2; c++) { if (c == 1) SendFFSequence(Index); @@ -1740,3 +1854,101 @@ int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) } return rc; } +#else +int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) +{ + + long UniqueID = 0; + char TypeName[1024]; + int rc = 0; + + for (int c = 0; c < 2; c++) { + if (c == 1) + SendFFSequence(Index); + UniqueID = flash_ReadId(0x9f, 4, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) { + if (c == 1) + isSendFFsequence = true; + return rc; + } + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x9f, 3, Index); + + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); + strcpy(strTypeName,TypeName); + if (rc && (search_all == 0)) { + if (c == 1) + isSendFFsequence = true; + return rc; + } + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x9f, 2, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) { + if (c == 1) + isSendFFsequence = true; + return rc; + } + } + } + + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x15, 2, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x15, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0xab, 3, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0xab, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0xab, 2, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0xab, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x90, 3, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x90, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x90, 2, Index); + if (UniqueID != 0) { + rc = Dedi_Search_Chip_Db(TypeName, 0x90, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + UniqueID = 0; + rc = 0; + UniqueID = flash_ReadId(0x90, 5, Index); // for 25LF020 + if (UniqueID != 0) { + UniqueID = UniqueID - 0xFFFF0000; + rc = Dedi_Search_Chip_Db(TypeName, 0x90, UniqueID, Chip_Info, search_all); + if (rc && (search_all == 0)) + return rc; + } + return rc; +} +#endif diff --git a/dpcmd.h b/dpcmd.h old mode 100644 new mode 100755 index 2d3c327..4c150fa --- a/dpcmd.h +++ b/dpcmd.h @@ -11,8 +11,9 @@ enum ErrorCode { EXCODE_FAIL_ERASE, EXCODE_FAIL_PROG, EXCODE_FAIL_VERIFY, + EXCODE_FAIL_LOADFILEWITHVERIFY, EXCODE_FAIL_READ, - EXCODE_FAIL_BLANK, // 5 + EXCODE_FAIL_BLANK, // 7 EXCODE_FAIL_BATCH, EXCODE_FAIL_CHKSUM, EXCODE_FAIL_IDENTIFY, @@ -50,6 +51,7 @@ void SetVpp(int Index); void SetSPIClock(int Index); void SetVcc(int Index); int do_loadFile(void); +int do_loadFileWithVerify(void); void BlinkProgrammer(void); void ListSFSerialID(void); void do_BlankCheck(void); @@ -70,6 +72,7 @@ bool Program(void); bool Read(void); bool Auto(void); bool Verify(void); +bool LoadFileWithVerify(void); bool CalChecksum(void); int Handler(); bool ListTypes(void); diff --git a/parse.c b/parse.c old mode 100644 new mode 100755 index bd165bb..4af42bd --- a/parse.c +++ b/parse.c @@ -42,18 +42,20 @@ long fsize(FILE* fp) fseek(fp, prev, SEEK_SET); // go back to where we were return sz; } - +#if 0 int Dedi_Search_Chip_Db(long RDIDCommand, long UniqueID, CHIP_INFO* Chip_Info, int search_all) { + +printf("evy- Dedi_Search_Chip_Db(RDIDCommand=0x%lx,UniqueID=0x%lx,search_all=%d)\n",RDIDCommand,UniqueID,search_all); + FILE* fp; /*Declare file pointer variable*/ int found_flag = 0; char file_line_buf[linebufsize], *tok, *file_buf, test[testbufsize]; char* pch; long sz = 0; - if ((fp = openChipInfoDb()) == NULL) return 1; sz = fsize(fp); @@ -104,7 +106,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Class")); tok = strtok(test, "\"= \t"); - // printf("Class = %s\n",tok); + // printf("evy- Class = %s\n",tok); strcpy(Chip_Info->Class, tok); continue; } @@ -113,7 +115,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("UniqueID")); tok = strtok(test, "\"= \t"); - // printf("UniqueID = 0x%lx\n",strtol(tok,NULL,16)); + //printf("evy- UniqueID = 0x%lx\n",strtol(tok,NULL,16)); Chip_Info->UniqueID = strtol(tok, NULL, 16); if ((UniqueID == Chip_Info->UniqueID)) found_flag = 1; @@ -124,7 +126,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Manufacturer")); tok = strtok(test, "\"= \t"); - // printf("Manufacturer = %s\n",tok); + //printf("evy- Manufacturer = %s\n",tok); strcpy(Chip_Info->Manufacturer, tok); continue; } @@ -133,7 +135,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Voltage")); tok = strtok(test, "\"= \t"); - // printf("Voltage = %s\n",tok); + //printf("evy- Voltage = %s\n",tok); if (strcmp(tok, "3.3V") == 0) Chip_Info->VoltageInMv = 3300; else if (strcmp(tok, "2.5V") == 0) @@ -149,10 +151,11 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("JedecDeviceID")); tok = strtok(test, "\"= \t"); - // printf("JedecDeviceID = 0x%lx\n",strtol(tok,NULL,16)); + //printf("evy- JedecDeviceID = 0x%lx\n",strtol(tok,NULL,16)); Chip_Info->JedecDeviceID = strtol(tok, NULL, 16); - if ((UniqueID == Chip_Info->JedecDeviceID)) - found_flag = 1; + if ((UniqueID == Chip_Info->JedecDeviceID)) { + found_flag = 1; + } continue; } pch = strstr(file_line_buf, "ChipSizeInKByte"); @@ -160,7 +163,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("ChipSizeInKByte")); tok = strtok(test, "\"= \t"); - // printf("ChipSizeInKByte = %ld\n",strtol(tok,NULL,10)); + //printf("evy- ChipSizeInKByte = %ld\n",strtol(tok,NULL,10)); Chip_Info->ChipSizeInByte = strtol(tok, NULL, 10) * 1024; continue; } @@ -169,7 +172,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("SectorSizeInByte")); tok = strtok(test, "\"= \t"); - // printf("SectorSizeInByte = %ld\n",strtol(tok,NULL,10)); + //printf("evy- SectorSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info->SectorSizeInByte = strtol(tok, NULL, 10); continue; } @@ -178,7 +181,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("BlockSizeInByte")); tok = strtok(test, "\"= \t"); - // printf("BlockSizeInByte = %ld\n",strtol(tok,NULL,10)); + //printf("evy- BlockSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info->BlockSizeInByte = strtol(tok, NULL, 10); continue; } @@ -187,7 +190,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("PageSizeInByte")); tok = strtok(test, "\"= \t"); - // printf("PageSizeInByte = %ld\n",strtol(tok,NULL,10)); + //printf("evy- PageSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info->PageSizeInByte = strtol(tok, NULL, 10); continue; } @@ -196,7 +199,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("AddrWidth")); tok = strtok(test, "\"= \t"); - // printf("AddrWidth = %ld\n",strtol(tok,NULL,10)); + //printf("evy- AddrWidth = %ld\n",strtol(tok,NULL,10)); Chip_Info->AddrWidth = strtol(tok, NULL, 10); continue; } @@ -205,7 +208,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("IDNumber")); tok = strtok(test, "\"= \t"); - // printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + //printf("evy- IDNumber = %ld\n",strtol(tok,NULL,10)); Chip_Info->IDNumber = strtol(tok, NULL, 10); continue; } @@ -214,7 +217,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("VppSupport")); tok = strtok(test, "\"= \t"); - // printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + //printf("evy- IDNumber = %ld\n",strtol(tok,NULL,10)); Chip_Info->VppSupport = strtol(tok, NULL, 10); continue; } @@ -223,6 +226,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("RDIDCommand")); tok = strtok(test, "\"= \t"); + //printf("evy- RDIDCommand = %ld\n",strtol(tok,NULL,10)); Chip_Info->RDIDCommand = strtol(tok, NULL, 16); continue; } @@ -231,6 +235,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Timeout")); tok = strtok(test, "\"= \t"); + //printf("evy- Timeout = %ld\n",strtol(tok,NULL,10)); Chip_Info->Timeout = strtol(tok, NULL, 16); continue; } @@ -244,57 +249,7 @@ int Dedi_Search_Chip_Db(long RDIDCommand, else Chip_Info->MXIC_WPmode = false; // starting checking input data - } -#if 0 - pch=strstr(file_line_buf,"Description="); - if( pch != NULL) - { - memset(test, '\0', testbufsize); - strcpy(test,pch+strlen("Description=")); - tok = strtok(test,"\""); - // printf("Description = %s\n",tok); - strcpy(Chip_Info->Description,tok); - continue; - } - pch=strstr(file_line_buf,"ManufactureUrl="); - if(pch != NULL) - { - memset(test, '\0', testbufsize); - strcpy(test,pch+strlen("ManufactureUrl=")); - tok = strtok(test,"\""); - //printf("ManufactureUrl = %s\n",tok); - strcpy(Chip_Info->ManufactureUrl,tok); - continue; - } - pch=strstr(file_line_buf,"Clock="); - if(pch != NULL) - { - memset(test, '\0', testbufsize); - strcpy(test,pch+strlen("Clock=")); - tok = strtok(test,"\""); - //printf("Clock = %s\n",tok); - Chip_Info->Clock[0] = '\0'; - continue; - } - pch=strstr(file_line_buf,"ManufactureID="); - if(pch != NULL) - { - memset(test, '\0', ); - strcpy(test,pch+strlen("ManufactureID=")); - tok = strtok(test,"\""); - printf("ManufactureID = 0x%lx\n",strtol(tok,NULL,16)); - Chip_Info->ManufactureID = strtol(tok,NULL,16); - } - pch=strstr(file_line_buf,"DeviceID="); - if(pch != NULL) - { - memset(test, '\0', testbufsize); - strcpy(test,pch+strlen("DeviceID=")); - tok = strtok(test,"\""); - //printf("DeviceID = 0x%lx\n",strtol(tok,NULL,16)); - Chip_Info->AlternativeID= strtol(tok,NULL,16); - } -#endif + } } /*Continue until EOF is encoutered*/ fclose(fp); /*Close file*/ @@ -303,6 +258,260 @@ int Dedi_Search_Chip_Db(long RDIDCommand, return found_flag; /*Executed without errors*/ } /*End main*/ +#else + +int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, + long UniqueID, + CHIP_INFO* Chip_Info, + int search_all) +{ + //printf("Dedi_Search_Chip_Db_FirstDetect(RDIDCommand=0x%lx,UniqueID=0x%lx,search_all=%d)\n",RDIDCommand,UniqueID,search_all); + + FILE* fp; /*Declare file pointer variable*/ + int found_flag = 0; + char file_line_buf[linebufsize], *tok, *file_buf, test[testbufsize]; + char* pch; + long sz = 0; + int detectICNum = 0; + char strTypeName[32][100]; + CHIP_INFO Chip_Info_temp; + + for(int i=0;i<32;i++) + memset(strTypeName[i], '\0', 100); + + memset(chTypeName, '\0', 1024); + + memset(Chip_Info->TypeName, '\0', linebufsize); //strlen(Chip_Info->TypeName)=0 + + if ((fp = openChipInfoDb()) == NULL) + return 1; + sz = fsize(fp); + file_buf = (char*)malloc(sz); + + memset(file_buf, '\0', sz); + /*Read into the buffer contents within thr file stream*/ + + while (fgets(file_line_buf, linebufsize, fp) != NULL) { + pch = strstr(file_line_buf, "TypeName"); + //printf("ile_line_buf=%s",file_line_buf) ; + if (pch != NULL) { + if (found_flag == 1) + { + found_flag = 0; + + if(strlen(Chip_Info->TypeName)==0) + *Chip_Info=Chip_Info_temp; //first chip info + } + // break; + + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("TypeName")); + tok = strtok(test, "\"= \t"); + Chip_Info_temp.TypeName[0] = '\0'; + Chip_Info_temp.Class[0] = '\0'; + Chip_Info_temp.UniqueID = 0; + Chip_Info_temp.Description[0] = '\0'; + Chip_Info_temp.Manufacturer[0] = '\0'; + Chip_Info_temp.ManufactureUrl[0] = '\0'; + Chip_Info_temp.ProgramIOMethod[0] = '\0'; + Chip_Info_temp.Voltage[0] = '\0'; + Chip_Info_temp.Clock[0] = '\0'; + Chip_Info_temp.ManufactureID = 0; + Chip_Info_temp.JedecDeviceID = 0; + Chip_Info_temp.AlternativeID = 0; + Chip_Info_temp.ChipSizeInByte = 0; + Chip_Info_temp.SectorSizeInByte = 0; + Chip_Info_temp.BlockSizeInByte = 0; + Chip_Info_temp.PageSizeInByte = 0; + Chip_Info_temp.AddrWidth = 0; + Chip_Info_temp.IDNumber = 0; + Chip_Info_temp.RDIDCommand = 0; + Chip_Info_temp.MaxErasableSegmentInByte = 0; + Chip_Info_temp.DualID = false; + Chip_Info_temp.VppSupport = 0; + Chip_Info_temp.MXIC_WPmode = false; + Chip_Info_temp.Timeout = 0; + // end of struct init + strcpy(Chip_Info_temp.TypeName, tok); + + continue; + } + + pch = strstr(file_line_buf, "Class"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("Class")); + tok = strtok(test, "\"= \t"); + //printf("Class = %s\n",tok); + strcpy(Chip_Info_temp.Class, tok); + continue; + } + pch = strstr(file_line_buf, "UniqueID"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("UniqueID")); + tok = strtok(test, "\"= \t"); + //printf("UniqueID = 0x%lx\n",strtol(tok,NULL,16)); + Chip_Info_temp.UniqueID = strtol(tok, NULL, 16); + if ((UniqueID == Chip_Info_temp.UniqueID)) { + //found_flag = 1; + //detectICNum++; + } + + continue; + } + pch = strstr(file_line_buf, "Manufacturer"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("Manufacturer")); + tok = strtok(test, "\"= \t"); + //printf("Manufacturer = %s\n",tok); + strcpy(Chip_Info_temp.Manufacturer, tok); + continue; + } + pch = strstr(file_line_buf, "Voltage"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("Voltage")); + tok = strtok(test, "\"= \t"); + //printf("Voltage = %s\n",tok); + if (strcmp(tok, "3.3V") == 0) + Chip_Info_temp.VoltageInMv = 3300; + else if (strcmp(tok, "2.5V") == 0) + Chip_Info_temp.VoltageInMv = 2500; + else if (strcmp(tok, "1.8V") == 0) + Chip_Info_temp.VoltageInMv = 1800; + else + Chip_Info_temp.VoltageInMv = 3300; + continue; + } + pch = strstr(file_line_buf, "JedecDeviceID"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("JedecDeviceID")); + tok = strtok(test, "\"= \t"); + //printf("JedecDeviceID = 0x%lx\n",strtol(tok,NULL,16)); + Chip_Info_temp.JedecDeviceID = strtol(tok, NULL, 16); + if ((UniqueID == Chip_Info_temp.JedecDeviceID)) { + found_flag = 1; + + strcpy(strTypeName[detectICNum], Chip_Info_temp.TypeName); + //printf("strTypeName[%d] = %s\n",detectICNum,strTypeName[detectICNum]); + strcat(chTypeName, " "); + strcat(chTypeName, strTypeName[detectICNum]); + detectICNum++; + } + continue; + } + pch = strstr(file_line_buf, "ChipSizeInKByte"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("ChipSizeInKByte")); + tok = strtok(test, "\"= \t"); + //printf("ChipSizeInKByte = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.ChipSizeInByte = strtol(tok, NULL, 10) * 1024; + continue; + } + pch = strstr(file_line_buf, "SectorSizeInByte"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("SectorSizeInByte")); + tok = strtok(test, "\"= \t"); + //printf("SectorSizeInByte = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.SectorSizeInByte = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "BlockSizeInByte"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("BlockSizeInByte")); + tok = strtok(test, "\"= \t"); + //printf("BlockSizeInByte = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.BlockSizeInByte = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "PageSizeInByte"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("PageSizeInByte")); + tok = strtok(test, "\"= \t"); + //printf("PageSizeInByte = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.PageSizeInByte = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "AddrWidth"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("AddrWidth")); + tok = strtok(test, "\"= \t"); + //printf("AddrWidth = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.AddrWidth = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "IDNumber"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("IDNumber")); + tok = strtok(test, "\"= \t"); + //printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.IDNumber = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "VppSupport"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("VppSupport")); + tok = strtok(test, "\"= \t"); + //printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.VppSupport = strtol(tok, NULL, 10); + continue; + } + pch = strstr(file_line_buf, "RDIDCommand"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("RDIDCommand")); + tok = strtok(test, "\"= \t"); + //printf("RDIDCommand = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.RDIDCommand = strtol(tok, NULL, 16); + continue; + } + pch = strstr(file_line_buf, "Timeout"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("Timeout")); + tok = strtok(test, "\"= \t"); + //printf("Timeout = %ld\n",strtol(tok,NULL,10)); + Chip_Info_temp.Timeout = strtol(tok, NULL, 16); + continue; + } + pch = strstr(file_line_buf, "MXIC_WPmode"); + if (pch != NULL) { + memset(test, '\0', testbufsize); + strcpy(test, pch + strlen("MXIC_WPmode")); + tok = strtok(test, "\"= \t"); + if (strstr(tok, "true") != NULL) + Chip_Info_temp.MXIC_WPmode = true; + else + Chip_Info_temp.MXIC_WPmode = false; + // starting checking input data + } + pch = strstr(file_line_buf, "Portofolio");//end + if (pch != NULL) { + if(detectICNum) + found_flag = 1; + } + + + } /*Continue until EOF is encoutered*/ + + fclose(fp); /*Close file*/ + Chip_Info->MaxErasableSegmentInByte = max(Chip_Info->SectorSizeInByte, Chip_Info->BlockSizeInByte); + free(file_buf); + return found_flag; /*Executed without errors*/ +} /*End main*/ + +#endif + int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) { FILE* fp; /*Declare file pointer variable*/ diff --git a/project.c b/project.c old mode 100644 new mode 100755 index 9b6f8c8..b1a7ea3 --- a/project.c +++ b/project.c @@ -26,6 +26,7 @@ extern unsigned int g_ucFill; extern int m_boEnReadQuadIO; extern int m_boEnWriteQuadIO; extern volatile bool g_bIsSF600[16]; +extern volatile bool g_bIsSF700[16]; extern char g_board_type[8]; extern int g_firmversion; extern char* g_parameter_vcc; @@ -40,7 +41,7 @@ extern unsigned char mcode_Program; extern unsigned char mcode_ProgramCode_4Adr; extern unsigned char mcode_Read; extern unsigned char mcode_ReadCode; -extern CHIP_INFO Chip_Info; +extern CHIP_INFO Chip_Info; extern int g_StartupMode; extern int g_CurrentSeriase; extern struct CAddressRange DownloadAddrRange; @@ -53,8 +54,13 @@ 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 unsigned int g_uiDevNum; +extern char strTypeName[1024]; +#if 0 +extern int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index); +#else extern int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index); +#endif pthread_mutex_t g_count_mutex; #define FIRMWARE_VERSION(x, y, z) ((x << 16) | (y << 8) | z) @@ -277,6 +283,7 @@ bool LoadFile(char* filename) bool IdentifyChipBeforeOperation(int Index) { + //printf("\n===>project.c ---- bool IdentifyChipBeforeOperation(%d)\n",Index); bool result = false; CHIP_INFO binfo; binfo.UniqueID = 0; @@ -285,9 +292,7 @@ bool IdentifyChipBeforeOperation(int Index) if (strstr(Chip_Info.Class, SUPPORT_FREESCALE_MCF) != NULL || strstr(Chip_Info.Class, SUPPORT_SILICONBLUE_iCE65) != NULL) return true; - Found = FlashIdentifier(&binfo, 0, Index); - - // printf("\n binfo.UniqueID = 0x%lx, Chip_Info.UniqueID = 0x%lx\n", binfo.UniqueID,Chip_Info.UniqueID); + Found = FlashIdentifier(&binfo, 0, Index); if (Found && (binfo.UniqueID == Chip_Info.UniqueID || binfo.UniqueID == Chip_Info.JedecDeviceID)) result = true; @@ -357,6 +362,7 @@ bool ProgramChip(int Index) bool ReadChip(const struct CAddressRange range, int Index) { + //printf("\n===>project.c ---- ReadChip()\n"); bool result = true; unsigned char* vc; size_t addrStart = range.start; @@ -365,22 +371,26 @@ bool ReadChip(const struct CAddressRange range, int Index) addr.start = range.start & (~(0x200 - 1)); addr.end = (range.end + (0x200 - 1)) & (~(0x200 - 1)); addr.length = addr.end - addr.start; + vc = (unsigned char*)malloc(addr.length); - result = SerialFlash_rangeRead(&addr, vc, Index); + result = SerialFlash_rangeRead(&addr, vc, Index); + if (result) { if (pBufferForLastReadData[Index] != NULL) { free(pBufferForLastReadData[Index]); } unsigned int offset = (addrStart & 0x1FF); - pBufferForLastReadData[Index] = (unsigned char*)malloc(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; } @@ -604,6 +614,7 @@ bool threadProgram(int Index) bool threadCompareFileAndChip(int Index) { + //printf("\n===>project.c ---- bool threadCompareFileAndChip(%d)\n",Index); bool result = true; SetIOMode(false, Index); @@ -664,6 +675,7 @@ bool threadCompareFileAndChip(int Index) #endif g_is_operation_successful[Index] = result; + return result; } @@ -902,15 +914,19 @@ bool threadPredefinedBatchSequences(int Index) void threadRun(void* Type) { + //printf("\n====>project ---- void threadRun(void* Type)\n"); THREAD_STRUCT* thread_data = (THREAD_STRUCT*)Type; OPERATION_TYPE opType = thread_data->type; int Index = thread_data->USBIndex; g_is_operation_successful[Index] = true; bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); + bool is_SF700_greater_than_4_0_0 = ( g_firmversion > 0x40000); int dwUID = ReadUID(Index); if (g_uiAddr == 0 && g_uiLen == 0) { - if ((dwUID / 600000) == 0) + if (g_bIsSF700[Index]==true) + printf("\nDevice %d (SF7%05X):", Index + 1, dwUID); + else if ((dwUID / 600000) == 0) printf("\nDevice %d (DP%06d):", Index + 1, dwUID); else printf("\nDevice %d (SF%06d):", Index + 1, dwUID); @@ -929,8 +945,9 @@ void threadRun(void* Type) if (1) // is_good()) { + //printf("\n====>project ---- void threadRun(void* Type) --- is_good\n"); TurnONVcc(Index); - if (is_greater_than_5_0_0) { + if (is_greater_than_5_0_0||is_SF700_greater_than_4_0_0) { SetLEDOnOff(SITE_BUSY, Index); } @@ -964,7 +981,7 @@ void threadRun(void* Type) threadConfiguredReadChip(Index); break; - case VERIFY_CONTENT: + case VERIFY_CONTENT: threadCompareFileAndChip(Index); break; @@ -1027,7 +1044,7 @@ void SetIOMode(bool isProg, int Index) m_boEnReadQuadIO = 0; m_boEnWriteQuadIO = 0; - if (g_bIsSF600[Index] == false) + if ((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) return; SetIOModeToSF600(IOValue, Index); @@ -1128,8 +1145,10 @@ void SetIOMode(bool isProg, int Index) bool is_BoardVersionGreaterThan_5_0_0(int Index) { if (g_firmversion < FIRMWARE_VERSION(5, 0, 0)) +{ + //printf("\n====>project.c ---- bool is_BoardVersionGreaterThan_5_0_0(Index=%d)g_firmversion=%d,FIRMWARE_VERSION(5, 0, 0)=0x%x\n",Index,g_firmversion,FIRMWARE_VERSION(5, 0, 0)); return false; - return true; + } return true; } bool is_SF100nBoardVersionGreaterThan_5_5_0(int Index) @@ -1166,9 +1185,18 @@ bool is_SF600nBoardVersionGreaterThan_7_0_1n6_7_0(int Index) } return false; } - +bool is_SF700(int Index) +{ + if (strstr(g_board_type, "SF700") != NULL) { + return true; + } + return false; +} +#if 0 CHIP_INFO GetFirstDetectionMatch(int Index) { + +printf("GetFirstDetectionMatch(%x)\n",Index); CHIP_INFO binfo; binfo.UniqueID = 0; int Found = 0; @@ -1224,13 +1252,78 @@ CHIP_INFO GetFirstDetectionMatch(int Index) } return binfo; } +#else +CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index) +{ + + //printf("GetFirstDetectionMatch_temp(%x)\n",Index); + CHIP_INFO binfo; + binfo.UniqueID = 0; + //char TypeName[1024]; + + // memset(TypeName, '\0', 1024); + int Found = 0; + int i = 0; + int Loop = 3; + if (strcmp(g_parameter_vcc, "NO") != 0) + Loop = 1; + + for (i = 0; i < Loop; i++) { + if (Found == 1) + break; + if (Loop == 1) + g_Vcc = vcc3_5V; + else + g_Vcc = vcc1_8V - i; + + TurnONVcc(Index); + if (Is_usbworking(Index)) { + if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) { + int startmode; + if (g_StartupMode == STARTUP_APPLI_SF_2) + SetTargetFlash(STARTUP_APPLI_SF_2, Index); + else + SetTargetFlash(STARTUP_APPLI_SF_1, Index); + + startmode = g_StartupMode; + 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, Index); + + if (Found == 0) { + TurnOFFVcc(Index); + g_CurrentSeriase = Seriase_45; + TurnONVcc(Index); + Found = FlashIdentifier(&binfo, 0, Index); + if (Found == 0) + g_StartupMode = startmode; + } + } + } else { + Found = FlashIdentifier(&binfo, 0, Index); + } + } + TurnOFFVcc(Index); + } + if (Found == 0) { + binfo.UniqueID = 0; + binfo.TypeName[0] = '\0'; + } + return binfo;//*TypeName; +} +#endif // fail in case of 1) USB failure, 2) unrecognised ID. void InitLED(int Index) { - bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); + bool is_greater_than_5_0_0 = is_BoardVersionGreaterThan_5_0_0(Index); + bool is_SF700_greater_than_4_0_0 = ( g_firmversion > 0x40000); - if (is_greater_than_5_0_0) + if (is_greater_than_5_0_0||is_SF700_greater_than_4_0_0) SetLEDOnOff(SITE_NORMAL, Index); } @@ -1443,7 +1536,8 @@ bool ProjectInitWithID(CHIP_INFO chipinfo, int Index) // by designated ID bool ProjectInit(int Index) // by designated ID { - Chip_Info = GetFirstDetectionMatch(Index); + //printf("bool ProjectInit(%d)\n",Index); + Chip_Info = GetFirstDetectionMatch(strTypeName,Index); if (Chip_Info.UniqueID == 0) return false; return ProjectInitWithID(Chip_Info, Index); diff --git a/project.h b/project.h old mode 100644 new mode 100755 index 0bf62e0..052c1ce --- a/project.h +++ b/project.h @@ -46,8 +46,13 @@ 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); +bool is_SF700(int Index); int GetFileFormatFromExt(const char* csPath); +#if 0 CHIP_INFO GetFirstDetectionMatch(int Index); +#else +CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index); +#endif void SetIOMode(bool isProg, int Index); bool ReadFile(const char* csPath, unsigned char* buffer, unsigned long* FileSize, unsigned char PaddingByte); bool WriteFile(const char* csPath, unsigned char* buffer, unsigned int FileSize); diff --git a/usbdriver.c b/usbdriver.c old mode 100644 new mode 100755 index 4e4ce60..a06c6b1 --- a/usbdriver.c +++ b/usbdriver.c @@ -7,6 +7,7 @@ unsigned int m_nbDeviceDetected = 0; unsigned char DevIndex = 0; extern volatile bool g_bIsSF600[16]; +extern volatile bool g_bIsSF700[16]; extern int g_CurrentSeriase; extern char g_board_type[8]; extern int g_firmversion; @@ -32,8 +33,10 @@ unsigned g_usb_busnum = -1; bool Is_NewUSBCommand(int Index) { - if (is_SF100nBoardVersionGreaterThan_5_5_0(Index) || is_SF600nBoardVersionGreaterThan_6_9_0(Index)) - return true; + if (is_SF100nBoardVersionGreaterThan_5_5_0(Index) || is_SF600nBoardVersionGreaterThan_6_9_0(Index)||is_SF700(Index)) { + //printf("\n====>usbdriver.c ---- Is_NewUSBCommand(Index=%d) == ture\n",Index); + return true; + } return false; } extern unsigned char GetFPGAVersion(int Index); @@ -62,11 +65,15 @@ void usb_db_init(void) } } -void IsSF600(int Index) +void AssignSF600orSF700var(int Index) { + //printf("\n===>usbdrive.c --- IsSF600\n"); if (Index == -1) Index = DevIndex; - + + g_bIsSF600[Index] = false; + g_bIsSF700[Index] = false; + CNTRPIPE_RQ rq; unsigned char vBuffer[16]; int fw[3]; @@ -80,20 +87,26 @@ void IsSF600(int Index) rq.Length = 16; if (InCtrlRequest(&rq, vBuffer, 16, Index) == SerialFlash_FALSE) - return; - + return; + memcpy(g_board_type, &vBuffer[0], 8); + //memcpy(g_firmversion,&vBuffer[10],8); sscanf((char*)&vBuffer[8], "V:%d.%d.%d", &fw[0], &fw[1], &fw[2]); g_firmversion = ((fw[0] << 16) | (fw[1] << 8) | fw[2]); - // printf("g_firmversion=%x\n",g_firmversion); - // printf("g_board_type=%s\n",g_board_type); + if (strstr(g_board_type, "SF600") != NULL) g_bIsSF600[Index] = true; else g_bIsSF600[Index] = false; + + if (strstr(g_board_type, "SF700") != NULL) + g_bIsSF700[Index] = true; + else + g_bIsSF700[Index] = false; + GetFPGAVersion(Index); } - + int get_usb_dev_cnt(void) { return dev_index; @@ -137,7 +150,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[Index] == true)) + if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))) return true; requesttype = 0x00; @@ -182,7 +195,7 @@ int InCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, i int requesttype; int ret = 0; - if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && (g_bIsSF600[Index] == true)) + if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))) return true; if (Index == -1) Index = DevIndex; @@ -208,8 +221,8 @@ int InCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, i } else { printf("no device"); } - - if (ret != buf_size) { + + if (ret != buf_size) { printf("Control Pipe input error!\n"); return -1; } @@ -220,8 +233,7 @@ int InCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, i // part of USB driver , open usb pipes for data transfor // should be called after usb successfully opens pipes. int dediprog_start_appli(int Index) -{ - //IsSF600(Index); +{ CNTRPIPE_RQ rq; int ret; unsigned char vInstruction; @@ -243,7 +255,7 @@ int dediprog_start_appli(int Index) int dediprog_get_chipid(int Index) { - //IsSF600(Index); + //printf("\n===>usbdrive.c --- dediprog_get_chipid\n"); CNTRPIPE_RQ rq; int ret; unsigned char vInstruction[3]; @@ -288,8 +300,10 @@ int BulkPipeRead(unsigned char* pBuff, unsigned int timeOut, int Index) Index = DevIndex; unsigned long cnRead = 512; - ret = libusb_bulk_transfer(dediprog_handle[Index], 2 | LIBUSB_ENDPOINT_IN, pBuff, cnRead, &actual_length, DEFAULT_TIMEOUT); - cnRead = ret; + ret = libusb_bulk_transfer(dediprog_handle[Index], 2 | LIBUSB_ENDPOINT_IN, pBuff, cnRead, &actual_length, DEFAULT_TIMEOUT); + if(ret!=0)//libusb_bulk_transfer return false + return 0; + return cnRead; } @@ -307,7 +321,7 @@ int BulkPipeWrite(unsigned char* pBuff, unsigned int size, unsigned int timeOut, if (Index == -1) Index = DevIndex; - ret = libusb_bulk_transfer(dediprog_handle[Index], (g_bIsSF600[Index] == true) ? 0x01 : 0x02, pData, nWrite, &actual_length, DEFAULT_TIMEOUT); + ret = libusb_bulk_transfer(dediprog_handle[Index], ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) ? 0x01 : 0x02, pData, nWrite, &actual_length, DEFAULT_TIMEOUT); nWrite = ret; return nWrite; } @@ -388,8 +402,7 @@ int dediprog_set_spi_clk(int khz, int Index) { return 0; int ret; - int hz_selector; - //IsSF600(Index); + int hz_selector; CNTRPIPE_RQ rq; switch (khz) { @@ -443,6 +456,7 @@ int dediprog_set_spi_clk(int khz, int Index) int usb_driver_init(void) { +//printf("\n===>usbdrive.c --- usb_driver_init\n"); // struct usb_bus *bus; // struct usb_device *dev; bool result = false; @@ -453,10 +467,10 @@ int usb_driver_init(void) dediprog_handle[i] = NULL; } usb_dev_init(); - + device_cnt = FindUSBDevice(); - if (g_uiDevNum == 0) { + if (g_uiDevNum == 0) { for (int i = 0; i < device_cnt; i++) { if (usb_device_entry[i].valid == 0) { printf("Error: Programmers are not connected.\n"); @@ -478,12 +492,10 @@ int usb_driver_init(void) if (ret) { printf("Error: Programmers USB claim interface: 0x%x.\n", ret); return 0; - } - g_bIsSF600[i] = false; - - IsSF600(i); + } + dediprog_start_appli(i); - IsSF600(i); + AssignSF600orSF700var(i); result = (dediprog_handle[i] != NULL); } } else { @@ -491,13 +503,13 @@ int usb_driver_init(void) printf("Error: Programmers are not connected.\n"); return 0; } - + ret = libusb_open(usb_device_entry[g_uiDevNum - 1].usb_device, &dediprog_handle[g_uiDevNum - 1]); if (dediprog_handle[g_uiDevNum - 1] == NULL) { printf("Error: Programmers are not connected.\n"); return 0; } - printf("dediprog_handle[%d]=%p\n", g_uiDevNum - 1, dediprog_handle[g_uiDevNum - 1]); + //printf("dediprog_handle[%d]=%p\n", g_uiDevNum - 1, dediprog_handle[g_uiDevNum - 1]); ret = libusb_set_configuration(dediprog_handle[g_uiDevNum - 1], 1); if (ret) { @@ -508,15 +520,15 @@ int usb_driver_init(void) if (ret) { printf("Error: Programmers USB claim interface: 0x%x.\n", ret); return 0; - } - g_bIsSF600[g_uiDevNum - 1] = false; + } - IsSF600(g_uiDevNum - 1); dediprog_start_appli(g_uiDevNum - 1); - IsSF600(g_uiDevNum - 1); + + AssignSF600orSF700var(g_uiDevNum - 1); + result = (dediprog_handle[g_uiDevNum - 1] != NULL); } - + return result; //((dediprog_handle[i] != NULL)? 1:0); } @@ -572,7 +584,7 @@ bool Is_usbworking(int Index) } //long long flash_ReadId(boost::tuple command,int Index) long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size, int Index) -{ +{ // read status // if(! m_usb.is_open() ) // return 0 ; @@ -592,10 +604,10 @@ long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size, int Ind rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = TRANSCEIVE; - if (Is_NewUSBCommand(Index)) { + if (Is_NewUSBCommand(Index)) { rq.Value = RESULT_IN; rq.Index = 0; - } else { + } else { rq.Value = RFU; rq.Index = RESULT_IN; } diff --git a/usbdriver.h b/usbdriver.h old mode 100644 new mode 100755