From e9030846d505eb8b9c67b2f0182f0566e55c7569 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Wed, 9 Feb 2022 16:46:39 -0800 Subject: [PATCH 1/2] Remove executable bit from source code files Signed-off-by: Stefan Reinauer --- .gitignore | 0 60-dediprog.rules | 0 ChipInfoDb.dedicfg | 0 ChipInfoDb.h | 0 FlashCommand.c | 0 FlashCommand.h | 0 IntelHexFile.c | 0 IntelHexFile.h | 0 LICENSE | 0 Macro.h | 0 Makefile | 0 MotorolaFile.c | 0 MotorolaFile.h | 0 README.md | 0 SerialFlash.c | 0 SerialFlash.h | 0 board.c | 0 board.h | 0 dpcmd.c | 0 dpcmd.h | 0 parse.c | 0 project.c | 0 project.h | 0 usbdriver.c | 0 usbdriver.h | 0 25 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 60-dediprog.rules mode change 100755 => 100644 ChipInfoDb.dedicfg mode change 100755 => 100644 ChipInfoDb.h mode change 100755 => 100644 FlashCommand.c mode change 100755 => 100644 FlashCommand.h mode change 100755 => 100644 IntelHexFile.c mode change 100755 => 100644 IntelHexFile.h mode change 100755 => 100644 LICENSE mode change 100755 => 100644 Macro.h mode change 100755 => 100644 Makefile mode change 100755 => 100644 MotorolaFile.c mode change 100755 => 100644 MotorolaFile.h mode change 100755 => 100644 README.md mode change 100755 => 100644 SerialFlash.c mode change 100755 => 100644 SerialFlash.h mode change 100755 => 100644 board.c mode change 100755 => 100644 board.h mode change 100755 => 100644 dpcmd.c mode change 100755 => 100644 dpcmd.h mode change 100755 => 100644 parse.c mode change 100755 => 100644 project.c mode change 100755 => 100644 project.h mode change 100755 => 100644 usbdriver.c mode change 100755 => 100644 usbdriver.h diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/60-dediprog.rules b/60-dediprog.rules old mode 100755 new mode 100644 diff --git a/ChipInfoDb.dedicfg b/ChipInfoDb.dedicfg old mode 100755 new mode 100644 diff --git a/ChipInfoDb.h b/ChipInfoDb.h old mode 100755 new mode 100644 diff --git a/FlashCommand.c b/FlashCommand.c old mode 100755 new mode 100644 diff --git a/FlashCommand.h b/FlashCommand.h old mode 100755 new mode 100644 diff --git a/IntelHexFile.c b/IntelHexFile.c old mode 100755 new mode 100644 diff --git a/IntelHexFile.h b/IntelHexFile.h old mode 100755 new mode 100644 diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/Macro.h b/Macro.h old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/MotorolaFile.c b/MotorolaFile.c old mode 100755 new mode 100644 diff --git a/MotorolaFile.h b/MotorolaFile.h old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/SerialFlash.c b/SerialFlash.c old mode 100755 new mode 100644 diff --git a/SerialFlash.h b/SerialFlash.h old mode 100755 new mode 100644 diff --git a/board.c b/board.c old mode 100755 new mode 100644 diff --git a/board.h b/board.h old mode 100755 new mode 100644 diff --git a/dpcmd.c b/dpcmd.c old mode 100755 new mode 100644 diff --git a/dpcmd.h b/dpcmd.h old mode 100755 new mode 100644 diff --git a/parse.c b/parse.c old mode 100755 new mode 100644 diff --git a/project.c b/project.c old mode 100755 new mode 100644 diff --git a/project.h b/project.h old mode 100755 new mode 100644 diff --git a/usbdriver.c b/usbdriver.c old mode 100755 new mode 100644 diff --git a/usbdriver.h b/usbdriver.h old mode 100755 new mode 100644 From 4c64d14b19bd1d8ff798d04f9f30e3a51c19eabe Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Wed, 9 Feb 2022 17:10:41 -0800 Subject: [PATCH 2/2] Run clang-format on source code again - reformat source code (also removes white space at end of line) - add "make release" target that fixes permissions and reformats source code before check-in Signed-off-by: Stefan Reinauer --- ChipInfoDb.h | 2 +- FlashCommand.c | 8 +- FlashCommand.h | 2 +- Macro.h | 4 +- Makefile | 9 +- SerialFlash.c | 104 ++++---- board.c | 52 ++-- board.h | 2 +- dpcmd.c | 640 ++++++++++++++++++++++--------------------------- dpcmd.h | 2 +- parse.c | 109 ++++----- project.c | 109 ++++----- project.h | 2 +- usbdriver.c | 67 +++--- 14 files changed, 510 insertions(+), 602 deletions(-) diff --git a/ChipInfoDb.h b/ChipInfoDb.h index eb80321..8def8e1 100644 --- a/ChipInfoDb.h +++ b/ChipInfoDb.h @@ -3,7 +3,7 @@ #ifndef ChipInfo_H #define ChipInfo_H -#include "Macro.h" +#include "Macro.h" #define NUMBER_OF_SUPPORTING_CHIPS 3 diff --git a/FlashCommand.c b/FlashCommand.c index a0b2db8..952d807 100644 --- a/FlashCommand.c +++ b/FlashCommand.c @@ -89,7 +89,7 @@ int FlashCommand_SendCommand_OneOutOneIn(unsigned char* vOut, int out_len, unsig return FlashCommand_TRUE; } -int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode,int Index) +int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode, int Index) { unsigned char vInstruction[16]; CNTRPIPE_RQ rq; @@ -125,11 +125,11 @@ int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrR vInstruction[7] = ((AddrRange->start >> 8) & 0xff); vInstruction[8] = ((AddrRange->start >> 16) & 0xff); vInstruction[9] = ((AddrRange->start >> 24) & 0xff); - vInstruction[10] = ((PageSize) & 0xff); + vInstruction[10] = (PageSize & 0xff); vInstruction[11] = ((PageSize >> 8) & 0xff); - vInstruction[12] = ((PageSize>> 16) & 0xff); + vInstruction[12] = ((PageSize >> 16) & 0xff); vInstruction[13] = ((PageSize >> 24) & 0xff); - vInstruction[14] = ((AddressMode) & 0xff); + vInstruction[14] = (AddressMode & 0xff); rq.Value = 0; rq.Index = 0; rq.Length = (unsigned long)(16); diff --git a/FlashCommand.h b/FlashCommand.h index c4eeee4..a088db1 100644 --- a/FlashCommand.h +++ b/FlashCommand.h @@ -18,7 +18,7 @@ int FlashCommand_SendCommand_OutInstructionWithCS(unsigned char* v, int len, int int FlashCommand_SendCommand_OneOutOneIn(unsigned char* vOut, int out_len, unsigned char* vIn, int in_len, int Index); -int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode,int Index); +int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode, int Index); int FlashCommand_SendCommand_SetupPacketForAT45DBBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, int Index); diff --git a/Macro.h b/Macro.h index 7c23218..2afad8d 100644 --- a/Macro.h +++ b/Macro.h @@ -43,7 +43,7 @@ typedef struct FirmwareInfo { } FW_INFO; typedef enum { - TRANSCEIVE = 0x01, + TRANSCEIVE = 0x01, DTC_READ = 0x20, WRITE = 0x30, @@ -304,7 +304,7 @@ typedef struct ChipInfo { #define READ_TO_FILE BIT9 #define BLINK BIT10 #define DEVICE_ID BIT11 -#define LIST_TYPE BIT12 +#define LIST_TYPE BIT12 #define LOADFILEWITHVERIFY BIT13 #define CHECK_INFO BIT14 diff --git a/Makefile b/Makefile index dc88dab..ea61b8b 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ Q:=@ ifneq ($(V),1) ifneq ($(Q),) .SILENT: -endif +endif endif PROGRAM = dpcmd @@ -27,7 +27,7 @@ LDFLAGS += $(shell $(PKG_CONFIG) --libs libusb-1.0) DEPDIR := .deps DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d -SRCS = dpcmd.c usbdriver.c FlashCommand.c SerialFlash.c parse.c board.c project.c IntelHexFile.c MotorolaFile.c +SRCS = dpcmd.c usbdriver.c FlashCommand.c SerialFlash.c parse.c board.c project.c IntelHexFile.c MotorolaFile.c PROGRAMMER_OBJS := $(SRCS:%.c=%.o) @@ -66,3 +66,8 @@ uninstall: [ $(shell id -u) -eq 0 ] || (echo "Error: uninstall needs root privileges" && false) rm -vf $(PREFIX)/bin/$(PROGRAM) $(PREFIX)/share/DediProg/ChipInfoDb.dedicfg /etc/udev/rules.d/60-dediprog.rules [ -d "$(PREFIX)/share/DediProg" ] && rmdir -v $(PREFIX)/share/DediProg || true + +# Run before every release / check-in to keep the source code tidy +release: + chmod 644 *.c *.h README.md Makefile LICENSE .gitignore ChipInfoDb.dedicfg 60-dediprog.rules + clang-format -i -style=WebKit *.c *.h diff --git a/SerialFlash.c b/SerialFlash.c index 31c1f6c..0c15e15 100644 --- a/SerialFlash.c +++ b/SerialFlash.c @@ -26,7 +26,7 @@ unsigned char mcode_ProgramCode_4Adr = 0x02; unsigned char mcode_ProgramCode_4Adr_12 = 0x12; unsigned char mcode_Read = BULK_FAST_READ; unsigned char mcode_ReadCode = 0x0B; -unsigned char mcode_ReadCode_0C = 0x0C; +unsigned char mcode_ReadCode_0C = 0x0C; unsigned int g_AT45_PageSize = 0; unsigned int g_AT45_PageSizeMask = 0; size_t AT45ChipSize = 0; @@ -1584,8 +1584,7 @@ bool CN25Qxxx_MutipleDIe_LargeWREAR(unsigned char cSR, int Index) bool CS25FLxx_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index) { - if ((strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x") != NULL) || (strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x(Secure)") != NULL)) - { + if ((strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x") != NULL) || (strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x(Secure)") != NULL)) { SerialFlash_waitForWEL(Index); if (Enable4Byte) { unsigned char v[2]; @@ -1612,7 +1611,7 @@ bool CS25FLxx_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index) return true; } bool Universal_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index) -{ +{ if (Enable4Byte) { unsigned char v = EN4B; FlashCommand_TransceiveOut(&v, 1, false, Index); @@ -1620,7 +1619,7 @@ bool Universal_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index) } else { unsigned char v = EXIT4B; FlashCommand_TransceiveOut(&v, 1, false, Index); - return true; + return true; } return true; } @@ -1716,7 +1715,7 @@ int SerialFlash_Enable4ByteAddrMode(int bEnable, int Index) return CN25Qxxx_LargeEnable4ByteAddrMode(bEnable, Index); else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) return CS25FLxx_LargeEnable4ByteAddrMode(bEnable, Index); - else + else return Universal_LargeEnable4ByteAddrMode(bEnable, Index); return SerialFlash_TRUE; } @@ -1775,60 +1774,45 @@ int SerialFlash_rangeBlankCheck(struct CAddressRange* Range, int Index) * false, if data size larger than memory size, or operation fails */ int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vData, int Index) -{ +{ 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)||(g_bIsSF700[Index] == true)) + else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) { + 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_S25FLxxL_Large) != NULL) - { - + } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) { + return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADR_256BYTE, mcode_ProgramCode_4Adr_12, Index); - } - else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) - { - if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) - { + } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) { + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) { return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_S70FS01GS, mcode_ProgramCode_4Adr_12, Index); - } - else + } else return false; - } - else - { - + } else { + return SerialFlash_bulkPipeProgram(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); } } 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)||(g_bIsSF700[Index] == true)) + //printf("SerialFlash_rangeRead"); + if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) { + 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); - } - else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) - { + } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) { return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ_MICRON, mcode_ReadCode_0C, Index); - } - else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) - { - if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) + } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) { + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode_0C, Index); else return false; - } else + } else return SerialFlash_bulkPipeRead(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode, Index); - }; /** @@ -2169,7 +2153,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* packageNum = down_range.length >> divider; // printf("packageNum=%d \n",packageNum); // printf("down_range.start=%X, down_range.end=%X\n",down_range.start, down_range.end); - FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth,Index); + FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index); for (i = 0; i < packageNum; ++i) { BulkPipeWrite((unsigned char*)(itr_begin + (i << divider)), 1 << divider, USB_TIMEOUT, Index); if (m_isCanceled) @@ -2179,7 +2163,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* } } else { size_t packageNum = (AddrRange->end - AddrRange->start) >> divider; - FlashCommand_SendCommand_SetupPacketForBulkWrite(AddrRange, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth,Index); + FlashCommand_SendCommand_SetupPacketForBulkWrite(AddrRange, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index); for (i = 0; i < packageNum; ++i) { BulkPipeWrite((unsigned char*)((itr_begin + (i << divider))), 1 << divider, USB_TIMEOUT, Index); if (m_isCanceled) @@ -2202,21 +2186,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)||(g_bIsSF700[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; - + 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) { @@ -2230,7 +2214,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)&&(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 + 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; @@ -2244,8 +2228,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)) @@ -2264,15 +2248,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)&&(g_bIsSF700[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 { @@ -2285,23 +2269,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"); + //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/board.c b/board.c index 6d17429..1d28205 100644 --- a/board.c +++ b/board.c @@ -108,10 +108,10 @@ void QueryBoard(int Index) unsigned int GetFPGAVersion(int Index) { if ((strstr(g_board_type, "SF600") == NULL) && (strstr(g_board_type, "SF700") == NULL)) - return -1; + return -1; CNTRPIPE_RQ rq; - unsigned int uiFPGAver= 0; + unsigned int uiFPGAver = 0; unsigned char vDataPack[2]; rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; @@ -125,7 +125,7 @@ unsigned int GetFPGAVersion(int Index) return -1; } - uiFPGAver = ( (unsigned int)vDataPack[1] << 8 | vDataPack[0]); + uiFPGAver = ((unsigned int)vDataPack[1] << 8 | vDataPack[0]); return uiFPGAver; } @@ -186,12 +186,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 | (g_IO1Select << 1); - rq.Value = (rq.Value& 0xFFF7) | (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 } @@ -340,8 +340,6 @@ bool SetSPIClockValue(unsigned short v, int Index) return true; } - - unsigned int ReadUID(int Index) { if (!Is_usbworking(Index)) { @@ -350,10 +348,10 @@ unsigned int ReadUID(int Index) unsigned int dwUID = 0; unsigned char vUID[16]; - if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) { + if ((g_bIsSF600 == true) || (g_bIsSF700 == true)) { if (ReadOnBoardFlash(vUID, false, Index) == false) return false; - if(g_bIsSF600 == true) + 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]; @@ -451,7 +449,7 @@ unsigned char ReadManufacturerID(int Index) if (!Is_usbworking(Index)) return false; - if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) { + if ((g_bIsSF600 == true) || (g_bIsSF700 == true)) { unsigned char vUID[16]; if (ReadOnBoardFlash(vUID, false, Index) == false) return false; @@ -611,7 +609,7 @@ bool WriteUID(unsigned int dwUID, int Index) if (!Is_usbworking(Index)) return false; - if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) + if ((g_bIsSF600 == true) || (g_bIsSF700 == true)) return true; CNTRPIPE_RQ rq; @@ -651,7 +649,7 @@ bool WriteManufacturerID(unsigned char ManuID, int Index) if (!Is_usbworking(Index)) return false; - if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) + if ((g_bIsSF600 == true) || (g_bIsSF700 == true)) return true; CNTRPIPE_RQ rq; @@ -746,11 +744,11 @@ bool CheckSDCard(int Index) rq.Request = CHECK_SD_CARD; rq.Value = 0; rq.Index = 0; - rq.Length = 1; + rq.Length = 1; if (!OutCtrlRequest(&rq, &vBuffer, 1, Index)) return false; - if(vBuffer==0) + if (vBuffer == 0) return false; return true; } @@ -767,7 +765,7 @@ bool GetFirmwareVer(int Index) rq.Request = PROGINFO_REQUEST; rq.Value = 0; rq.Index = 0; - rq.Length = 26; + rq.Length = 26; if (!OutCtrlRequest(&rq, vBuffer, 26, Index)) return false; @@ -777,14 +775,13 @@ bool GetFirmwareVer(int Index) return false; } - memcpy(g_board_type, &vBuffer[0], 8); - memcpy(g_FW_ver,&vBuffer[10],7); - - if(strstr(g_board_type, "SF600") != NULL) - memcpy(g_HW_ver,&vBuffer[20],4); - if(strstr(g_board_type, "SF700") != NULL) - memcpy(g_HW_ver,&vBuffer[21],4); + memcpy(g_FW_ver, &vBuffer[10], 7); + + if (strstr(g_board_type, "SF600") != NULL) + memcpy(g_HW_ver, &vBuffer[20], 4); + if (strstr(g_board_type, "SF700") != NULL) + memcpy(g_HW_ver, &vBuffer[21], 4); return true; } @@ -842,7 +839,7 @@ bool UpdateSF600Flash(const char* sFilePath, int Index) rq.Value = 0; rq.Index = 0; rq.Length = 6; - + unsigned char Package[6]; Package[0] = pBuffer[0]; Package[1] = pBuffer[1]; @@ -921,7 +918,7 @@ bool UpdateSF600Flash_FPGA(const char* sFilePath, int Index) rq.Value = 0; // static_cast(vBuffer.size() & 0xffff) ; rq.Index = 0; // static_cast((vBuffer.size() >> 16) & 0xffff) ; rq.Length = 4; - + unsigned char Package[4]; Package[0] = (fw_info.SecondSize & 0xff); Package[1] = ((fw_info.SecondSize >> 8) & 0xff); @@ -964,7 +961,7 @@ bool UpdateFirmware(const char* sFolder, int Index) unsigned int UID = 0; unsigned char ManID = 0; // read status - if ((g_bIsSF600 == true)||(g_bIsSF700 == true)) + if ((g_bIsSF600 == true) || (g_bIsSF700 == true)) return UpdateSF600Firmware(sFolder, Index); dediprog_set_spi_voltage(g_Vcc, Index); @@ -1002,4 +999,3 @@ void SendFFSequence(int Index) unsigned char v[4] = { 0xff, 0xff, 0xff, 0xff }; FlashCommand_SendCommand_OutOnlyInstruction(v, 4, Index); } - diff --git a/board.h b/board.h index df73ac8..a1e6829 100644 --- a/board.h +++ b/board.h @@ -8,7 +8,7 @@ void SendFFSequence(int Index); void QueryBoard(int Index); -unsigned int GetFPGAVersion(int Index); +unsigned int GetFPGAVersion(int Index); bool SetIO(unsigned char ioState, int Index); bool SetTargetFlash(unsigned char StartupMode, int Index); bool SetLEDProgBoard(size_t Clolor, int Index); diff --git a/dpcmd.c b/dpcmd.c index 650e372..c73ee5d 100644 --- a/dpcmd.c +++ b/dpcmd.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #define min(a, b) (a > b ? b : a) extern unsigned char* pBufferForLastReadData[16]; @@ -34,17 +34,17 @@ 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_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; @@ -54,7 +54,7 @@ unsigned int g_uiLockLen = 0; unsigned int g_uiLockStart = 0; char* g_parameter_read = "\0"; -char* g_parameter_program = "\0"; +char* g_parameter_program = "\0"; char* g_parameter_loadfile_with_verify = "\0"; char* g_parameter_auto = "\0"; char* g_parameter_batch = "\0"; @@ -79,7 +79,6 @@ char g_LogPath[512] = { 0 }; extern unsigned g_usb_devnum; extern unsigned g_usb_busnum; - unsigned long g_ucOperation; struct memory_id g_ChipID; char g_board_type[8]; @@ -160,8 +159,8 @@ struct option long_options[] = { { "lock-start", 1, NULL, 'S' }, { "lock-length", 1, NULL, 'N' }, { "blink", 1, NULL, 'B' }, - { "device", 1, NULL, 'D' }, - { "device-SN", 1, NULL, 'X' }, + { "device", 1, NULL, 'D' }, + { "device-SN", 1, NULL, 'X' }, // { "fix-device", 1, NULL, 'F' }, { "list-device-id", 1, NULL, 'V' }, { "loadFile-with-verify", 1, NULL, 'W' }, @@ -175,15 +174,15 @@ struct option long_options[] = { { "set-io1", 1, NULL, '1' }, { "set-io4", 1, NULL, '4' }, { "update-fw", 1, NULL, 'U' }, -// { "display-delta", 1, NULL, 'E' }, - { "devnum", 1, NULL, 'G' }, - { "busnum", 1, NULL, 'H' }, + // { "display-delta", 1, NULL, 'E' }, + { "devnum", 1, NULL, 'G' }, + { "busnum", 1, NULL, 'H' }, { 0, 0, 0, 0 }, }; int OpenUSB(void); -#if 0 //evy test SF700 +#if 0 //evy test SF700 int verbose = 1; void print_endpoint(struct usb_endpoint_descriptor *endpoint) @@ -334,7 +333,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(); @@ -377,7 +376,7 @@ int Sequence() } } else return EXCODE_FAIL_CHKSUM; - + boResult &= Verify(); if (boResult == false) return EXCODE_FAIL_VERIFY; @@ -408,13 +407,13 @@ void GetLogPath(char* pBuf) void EnterStandaloneMode(int Index) { - if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) LeaveSF600Standalone(false, Index); } void LeaveStandaloneMode(int Index) { - if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) LeaveSF600Standalone(true, Index); } @@ -486,7 +485,7 @@ int GetConfigVer() } int main(int argc, char* argv[]) -{ +{ #if 0 //Check all USB device capability //evy test SF700 Check(argc,argv); return; @@ -494,11 +493,11 @@ int main(int argc, char* argv[]) #endif int c; int iExitCode = EXCODE_PASS; - bool bDetect = false; + bool bDetect = false; bool bDevice = false; bool bDeviceSN = false; unsigned long r; - char *env; + char* env; printf("\nDpCmd Linux 1.12.9.%02d Engine Version:\nLast Built on October 27 2021\n\n", GetConfigVer()); // 1. new feature.bug.configS @@ -528,10 +527,10 @@ int main(int argc, char* argv[]) r = strtoul(env, NULL, 10); if (r == ULONG_MAX || r >= 256) { fprintf(stderr, "E: invalid USB device number in" - " DPCMD_USB_DEVNUM; expected 1-255\n"); + " DPCMD_USB_DEVNUM; expected 1-255\n"); return 1; } - g_usb_devnum = (unsigned char) r; + g_usb_devnum = (unsigned char)r; } env = getenv("DPCMD_USB_BUSNUM"); @@ -539,15 +538,14 @@ int main(int argc, char* argv[]) r = strtoul(env, NULL, 10); if (r == ULONG_MAX || r >= 256) { fprintf(stderr, "E: invalid USB bus number in" - " DPCMD_USB_BUSNUM\n"); + " DPCMD_USB_BUSNUM\n"); return 1; } - g_usb_busnum = (unsigned char) r; + g_usb_busnum = (unsigned char)r; } - - if(OpenUSB() == 0) - iExitCode=EXCODE_FAIL_USB; + if (OpenUSB() == 0) + iExitCode = EXCODE_FAIL_USB; LeaveStandaloneMode(0); QueryBoard(0); @@ -576,7 +574,7 @@ int main(int argc, char* argv[]) break; case 'r': g_parameter_read = optarg; - g_ucOperation |= READ_TO_FILE; + g_ucOperation |= READ_TO_FILE; break; case 'p': g_parameter_program = optarg; @@ -642,15 +640,15 @@ int main(int argc, char* argv[]) sscanf(optarg, "%d", &g_uiBlink); g_ucOperation |= BLINK; break; - case 'D': // device + case 'D': // device bDevice = true; - sscanf(optarg, "%x", &g_uiDevNum); + 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); - bDeviceSN = true; + bDeviceSN = true; break; case 'W': // l_opt_arg = optarg; @@ -673,7 +671,7 @@ int main(int argc, char* argv[]) sscanf(optarg, "%d", &g_ucTarget); break; case 'c': - g_parameter_vcc = optarg; + g_parameter_vcc = optarg; sscanf(optarg, "%d", &g_Vcc); break; case 'P': @@ -720,171 +718,138 @@ int main(int argc, char* argv[]) r = strtoul(optarg, NULL, 10); if (r == ULONG_MAX || r >= 256) { fprintf(stderr, "E: invalid device" - " number; expected 1-255\n"); + " number; expected 1-255\n"); return 1; } - g_usb_devnum = (unsigned char) r; + g_usb_devnum = (unsigned char)r; break; case 'H': r = strtoul(optarg, NULL, 10); if (r == ULONG_MAX) { fprintf(stderr, "E: invalid bus" - " number\n"); + " number\n"); return 1; } - g_usb_busnum = (unsigned) r; + g_usb_busnum = (unsigned)r; break; default: break; } - } - + int dev_cnt = get_usb_dev_cnt(); - - if (CheckProgrammerInfo()) - { + + if (CheckProgrammerInfo()) { iExitCode = EXCODE_PASS; goto Exit; } - - 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; + + 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; + } } - } - else - { - 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; + 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 { + 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); } - } - } - } - else if (g_uiDevNum != 0) - { + 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) { WriteLog(iExitCode, true); printf("%d,\tdetecting chip\n", g_uiDevNum); - Chip_Info=GetFirstDetectionMatch(strTypeName,g_uiDevNum - 1); - - if (Chip_Info.UniqueID != 0) { - //printf("strlen(strTypeName)=%ld\n",strlen(strTypeName)); - if(strlen(strTypeName)){ + 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 { + 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{ - 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; - } - } - } + } 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(); @@ -984,7 +949,7 @@ void cli_classic_usage(bool IsShowExample) printf(" -? [ --help ] show this help message\n" " --list print supported chip list\n" " --check get programmer information\n" - " -d [ --detect ] detect chip\n" + " -d [ --detect ] detect chip\n" " -b [ --blank ] blank check\n" " -e [ --erase ] erase entire chip\n" " -r [ --read ] arg read chip contents and save to a bin/hex/s19 file\n" @@ -1099,16 +1064,15 @@ void cli_classic_usage(bool IsShowExample) " before refreshing the screen\n" "\n" "Environment variables:\n" - " Specify DPCMD_USB_BUSNUM and DPCMD_USB_DEVNUM to ensure the tool touches only said device. Numbers can be found with tools such as lsusb and others.\n" + " Specify DPCMD_USB_BUSNUM and DPCMD_USB_DEVNUM to ensure the tool touches only said device. Numbers can be found with tools such as lsusb and others.\n" " - DPCMD_USB_BUSNUM Number of USB bus where device is\n" - " - DPCMD_USB_DEVNUM Number of device in USB bus\n" + " - DPCMD_USB_DEVNUM Number of device in USB bus\n" "\n\n\n"); - } int OpenUSB(void) -{ +{ return usb_driver_init(); } @@ -1120,7 +1084,7 @@ void sin_handler(int sig) } int Handler(void) -{ +{ if (Is_usbworking(0) == true) { #if 0 if(m_vm.count("fix-device")) @@ -1150,10 +1114,9 @@ int Handler(void) if (!InitProject()) return EXCODE_FAIL_OTHERS; //my_timer t; // opertion timer - + if (ListTypes()) return EXCODE_PASS; - if (strlen(g_parameter_type) > 0) { int dev_cnt = get_usb_dev_cnt(); @@ -1168,9 +1131,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; @@ -1249,10 +1212,10 @@ void CloseProject(void) } bool DetectChip(void) -{ +{ int dev_cnt = get_usb_dev_cnt(); - Chip_Info = GetFirstDetectionMatch(strTypeName,0); - if (g_uiDevNum == 0) { + Chip_Info = GetFirstDetectionMatch(strTypeName, 0); + if (g_uiDevNum == 0) { for (int i = 0; i < dev_cnt; i++) { if (!Is_usbworking(i)) { printf("%s", msg_err_communication); @@ -1268,7 +1231,7 @@ bool DetectChip(void) RawInstructions(i); } - } else if (g_uiDevNum <= dev_cnt) { + } else if (g_uiDevNum <= dev_cnt) { if (!Is_usbworking(g_uiDevNum - 1)) { printf("%s", msg_err_communication); return false; @@ -1303,7 +1266,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)||(g_bIsSF700[Index] == true)))) + if (!(g_Vcc <= 3800 && g_Vcc >= 1800 && ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)))) g_Vcc = (0x10 | (g_Vcc & 0x03)); } @@ -1311,7 +1274,7 @@ int do_loadFile(void) { char* filename = NULL; if (g_ucOperation & PROGRAM) - filename = g_parameter_program; + filename = g_parameter_program; else if (g_ucOperation & BATCH) { switch (g_BatchIndex) { case 1: @@ -1333,7 +1296,7 @@ int do_loadFileWithVerify(void) { char* filename = NULL; if (g_ucOperation & LOADFILEWITHVERIFY) - filename = g_parameter_loadfile_with_verify; + filename = g_parameter_loadfile_with_verify; printf("%s", msg_info_loading); printf("(%s)\n", filename); return LoadFile(filename); @@ -1346,113 +1309,92 @@ bool ListTypes(void) return Dedi_List_AllChip(); } bool CheckProgrammerInfo(void) -{ -//printf("evy-- CheckProgrammerInfo 1\n"); +{ + //printf("evy-- CheckProgrammerInfo 1\n"); if ((g_ucOperation & CHECK_INFO) != CHECK_INFO) - return false; + return false; -//printf("evy-- CheckProgrammerInfo 2\n"); + //printf("evy-- CheckProgrammerInfo 2\n"); int dev_cnt = get_usb_dev_cnt(); - unsigned int uiFPGAVer=0; - if(g_uiDevNum == 0) - { - for (int i = 0; i < dev_cnt; i++) + unsigned int uiFPGAVer = 0; + if (g_uiDevNum == 0) { + for (int i = 0; i < dev_cnt; i++) { + int dwUID = ReadUID(i); + 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); + + uiFPGAVer = GetFPGAVersion(i); + GetFirmwareVer(i); + if (g_bIsSF600[i]) { + if (CheckSDCard(i)) + printf(" Programmer type : SF600Plus\n"); + else + printf(" Programmer type : SF600\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : 0x%04x\n", uiFPGAVer); + printf(" Hardware version : %s\n", g_HW_ver); + } else if (g_bIsSF700[i]) { + printf(" Programmer type : SF700\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : 0x%04x\n", uiFPGAVer); + printf(" Hardware version : %s\n", g_HW_ver); + } else //SF100 { - int dwUID = ReadUID(i); - 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); - - uiFPGAVer = GetFPGAVersion(i); - GetFirmwareVer(i); - if(g_bIsSF600[i]) - { - if(CheckSDCard(i)) - printf(" Programmer type : SF600Plus\n"); - else - printf(" Programmer type : SF600\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : 0x%04x\n",uiFPGAVer); - printf(" Hardware version : %s\n",g_HW_ver); - } - else if(g_bIsSF700[i]) - { - printf(" Programmer type : SF700\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : 0x%04x\n",uiFPGAVer); - printf(" Hardware version : %s\n",g_HW_ver); - } - else//SF100 - { - printf(" Programmer type : SF100\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : N.A.\n"); - printf(" Hardware version : N.A.\n"); - } - + printf(" Programmer type : SF100\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : N.A.\n"); + printf(" Hardware version : N.A.\n"); } + } + } else { + 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):\n", g_uiDevNum, dwUID); + } else if ((dwUID / 600000) > 0) { + printf("\nDevice %d (SF%06d):\n", g_uiDevNum, dwUID); + } else { + printf("\nDevice %d (DP%06d):\n", g_uiDevNum, dwUID); + } + + uiFPGAVer = GetFPGAVersion(g_uiDevNum - 1); + GetFirmwareVer(g_uiDevNum - 1); + if (g_bIsSF600[g_uiDevNum - 1]) { + if (CheckSDCard(g_uiDevNum - 1i)) + printf(" Programmer type : SF600Plus\n"); + printf(" Programmer type : SF600Plus\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : 0x%x\n", uiFPGAVer); + printf(" Hardware version : %s\n", g_HW_ver); + } else if (g_bIsSF700[g_uiDevNum - 1]) { + printf(" Programmer type : SF700\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : 0x%x\n", uiFPGAVer); + printf(" Hardware version : %s\n", g_HW_ver); + } else //SF100 + { + printf(" Programmer type : SF100\n"); + printf(" Firmware version : %s\n", g_FW_ver); + printf(" FPGA version : N.A.\n"); + printf(" Hardware version : N.A.\n"); + } } - else - { - 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):\n", g_uiDevNum, dwUID); - } - else if ((dwUID / 600000) > 0) - { - printf("\nDevice %d (SF%06d):\n", g_uiDevNum, dwUID); - } - else - { - printf("\nDevice %d (DP%06d):\n", g_uiDevNum, dwUID); - } - - - uiFPGAVer = GetFPGAVersion(g_uiDevNum - 1); - GetFirmwareVer(g_uiDevNum - 1); - if(g_bIsSF600[g_uiDevNum - 1]) - { - if(CheckSDCard(g_uiDevNum - 1i)) - printf(" Programmer type : SF600Plus\n"); - printf(" Programmer type : SF600Plus\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : 0x%x\n",uiFPGAVer); - printf(" Hardware version : %s\n",g_HW_ver); - } - else if(g_bIsSF700[g_uiDevNum - 1]) - { - printf(" Programmer type : SF700\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : 0x%x\n",uiFPGAVer); - printf(" Hardware version : %s\n",g_HW_ver); - } - else//SF100 - { - printf(" Programmer type : SF100\n"); - printf(" Firmware version : %s\n",g_FW_ver); - printf(" FPGA version : N.A.\n"); - printf(" Hardware version : N.A.\n"); - } - } return true; } - + /* bool getFirmwareVer(void) { @@ -1504,7 +1446,7 @@ void ListSFSerialID(void) if (g_uiDeviceID < 1) { for (unsigned int i = 0; i < dev_cnt; i++) { dwUID = ReadUID(i); - if (g_bIsSF700[i]==true) + 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); @@ -1516,7 +1458,7 @@ void ListSFSerialID(void) printf("The number of programmer is not defined!\n"); else { dwUID = ReadUID(g_uiDeviceID - 1); - if (g_bIsSF700[g_uiDeviceID - 1]==true) + 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); @@ -1564,7 +1506,7 @@ void do_Read(void) DownloadAddrRange.end = g_uiAddr + g_uiLen; printf("%s\n", msg_info_reading); - + Run(READ_ANY_BY_PREFERENCE_CONFIGURATION, g_uiDevNum); Wait(msg_info_readOK, msg_info_readfail); } @@ -1588,47 +1530,41 @@ void do_DisplayOrSave(void) printf("\n\n"); } else { UploadAddrRange.length = UploadAddrRange.end - UploadAddrRange.start; - - char SourceStr[64]; - - - sprintf(SourceStr, "%s", g_parameter_read); - - if(dev_cnt>1) - { - int len = strlen(SourceStr); - int i = len; - - while(SourceStr[i]!='.' && i>0) - i--; - - char ExtStr[64]; - if(SourceStr[i]=='.') - { - sprintf(ExtStr, "%s", &SourceStr[i]); - char *loc = strstr(SourceStr,ExtStr); - - for(int i=loc-SourceStr;i 1) { + int len = strlen(SourceStr); + int i = len; + + while (SourceStr[i] != '.' && i > 0) + i--; + + char ExtStr[64]; + if (SourceStr[i] == '.') { + sprintf(ExtStr, "%s", &SourceStr[i]); + char* loc = strstr(SourceStr, ExtStr); + + for (int i = loc - SourceStr; i < strlen(SourceStr); i++) + SourceStr[i] = '\0'; + // printf("\n 1ExtStr= %s",ExtStr); + char str[64]; + + sprintf(str, "_%d", icnt + 1); + strcat(SourceStr, str); + strcat(SourceStr, ExtStr); + } else { + sprintf(ExtStr, "%s", &SourceStr[0]); + //printf("\n 2ExtStr= %s",ExtStr); + + char str[64]; + sprintf(str, "_%d", icnt + 1); + strcat(SourceStr, str); + } + } + if (WriteFile((const char*)SourceStr, pBufferForLastReadData[icnt], UploadAddrRange.length) == 1) printf("\nSuccessfully saved into file:%s \n", SourceStr); else @@ -1690,8 +1626,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); @@ -1829,17 +1765,17 @@ bool Auto(void) } bool LoadFileWithVerify(void) -{ +{ if (g_ucOperation & LOADFILEWITHVERIFY) { - do_loadFileWithVerify(); - if(g_bStatus) - do_Verify(); + do_loadFileWithVerify(); + if (g_bStatus) + do_Verify(); } return g_bStatus; } bool Verify(void) -{ +{ if (g_ucOperation & VERIFY) do_Verify(); return g_bStatus; @@ -1858,8 +1794,8 @@ bool CalChecksum(void) for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); if (g_uiAddr == 0 && g_uiLen == 0) { - if (g_bIsSF700[i]==true) - printf("\nDevice %d (SF7%05X):", i + 1, dwUID); + 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 @@ -1867,8 +1803,8 @@ bool CalChecksum(void) 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 (g_bIsSF700[i]==true) - printf("\nDevice %d (SF7%05X):", i + 1, ReadUID(i)); + 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 @@ -1880,17 +1816,17 @@ bool CalChecksum(void) } else if (g_uiDevNum != 0) { int dwUID = ReadUID(g_uiDevNum - 1); if (g_uiAddr == 0 && g_uiLen == 0) { - if (g_bIsSF700[g_uiDevNum - 1]==true) - printf("\nDevice %d (SF7%05X):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); + 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 (g_bIsSF700[g_uiDevNum - 1]==true) - printf("\nDevice %d (SF7%05X):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); + } 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 @@ -1906,7 +1842,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); @@ -1937,8 +1873,8 @@ bool Wait(const char* strOK, const char* strFail) { for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); - if (g_bIsSF700[i]==true) - printf("\nDevice %d (SF7%05X):", i + 1, dwUID); + 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 @@ -1948,8 +1884,8 @@ bool Wait(const char* strOK, const char* strFail) } } else if (g_uiDevNum <= dev_cnt) { int dwUID = ReadUID(g_uiDevNum - 1); - if (g_bIsSF700[g_uiDevNum - 1]==true) - printf("\nDevice %d (SF7%05X):", g_uiDevNum, dwUID); + 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 @@ -2057,19 +1993,19 @@ printf("FlashIdentifier(search_all=%d,Index=%x)\n",search_all,Index); return rc; } #else -int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) +int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) { - - long UniqueID = 0; - char TypeName[1024]; - int rc = 0; - + + long UniqueID = 0; + char TypeName[1024]; + int rc = 0; + for (int c = 0; c < 2; c++) { if (c == 1) - SendFFSequence(Index); + SendFFSequence(Index); UniqueID = flash_ReadId(0x9f, 4, Index); if (UniqueID != 0) { - rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); + rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); if (rc && (search_all == 0)) { if (c == 1) isSendFFsequence = true; @@ -2081,8 +2017,8 @@ int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) UniqueID = flash_ReadId(0x9f, 3, Index); if (UniqueID != 0) { - rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); - strcpy(strTypeName,TypeName); + 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; @@ -2093,7 +2029,7 @@ int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) rc = 0; UniqueID = flash_ReadId(0x9f, 2, Index); if (UniqueID != 0) { - rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); + rc = Dedi_Search_Chip_Db(TypeName, 0x9f, UniqueID, Chip_Info, search_all); if (rc && (search_all == 0)) { if (c == 1) isSendFFsequence = true; @@ -2114,7 +2050,7 @@ int FlashIdentifier(CHIP_INFO* Chip_Info ,int search_all, int Index) rc = 0; UniqueID = flash_ReadId(0xab, 3, Index); if (UniqueID != 0) { - rc = Dedi_Search_Chip_Db(TypeName, 0xab, UniqueID, Chip_Info, search_all); + rc = Dedi_Search_Chip_Db(TypeName, 0xab, UniqueID, Chip_Info, search_all); if (rc && (search_all == 0)) return rc; } diff --git a/dpcmd.h b/dpcmd.h index febb3ee..1bbadab 100644 --- a/dpcmd.h +++ b/dpcmd.h @@ -76,7 +76,7 @@ bool LoadFileWithVerify(void); bool CalChecksum(void); int Handler(); bool ListTypes(void); -bool CheckProgrammerInfo(void); +bool CheckProgrammerInfo(void); void GetLogPath(char* path); bool Wait(const char* strOK, const char* strFail); void ExitProgram(void); diff --git a/parse.c b/parse.c index 2584a08..0f1ea46 100644 --- a/parse.c +++ b/parse.c @@ -1,9 +1,9 @@ -#include "ChipInfoDb.h" +#include "ChipInfoDb.h" #include "project.h" #include #include #include -#include +#include //#include "pugixml.hpp" #define testbufsize 256 @@ -34,13 +34,11 @@ FILE* openChipInfoDb(void) if ((fp = fopen(Path, "rt")) == NULL) fprintf(stderr, "Error opening file: %s\n", Path); } - } - - - //xml_parse_result result = doc.load_file( Path ); - //if ( result.status != xml_parse_status::status_ok ) - // return; + } + //xml_parse_result result = doc.load_file( Path ); + //if ( result.status != xml_parse_status::status_ok ) + // return; return fp; } @@ -271,13 +269,13 @@ printf("evy- Dedi_Search_Chip_Db(RDIDCommand=0x%lx,UniqueID=0x%lx,search_all=%d) #else -int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, +int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, long UniqueID, - CHIP_INFO* Chip_Info, + CHIP_INFO* Chip_Info, int search_all) -{ +{ //printf("evy 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]; @@ -286,39 +284,38 @@ int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, 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); + 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; + 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; - + //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'; + 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'; @@ -342,13 +339,13 @@ int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, Chip_Info_temp.VppSupport = 0; Chip_Info_temp.MXIC_WPmode = false; Chip_Info_temp.Timeout = 0; - // end of struct init + // end of struct init strcpy(Chip_Info_temp.TypeName, tok); - + continue; } - - pch = strstr(file_line_buf, "Class"); + + pch = strstr(file_line_buf, "Class"); if (pch != NULL) { memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Class")); @@ -366,8 +363,8 @@ int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, Chip_Info_temp.UniqueID = strtol(tok, NULL, 16); if ((UniqueID == Chip_Info_temp.UniqueID)) { //found_flag = 1; - //detectICNum++; - } + //detectICNum++; + } continue; } @@ -384,7 +381,7 @@ int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, if (pch != NULL) { memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Voltage")); - tok = strtok(test, "\"= \t"); + tok = strtok(test, "\"= \t"); if (strcmp(tok, "3.3V") == 0) Chip_Info_temp.VoltageInMv = 3300; else if (strcmp(tok, "2.5V") == 0) @@ -400,17 +397,17 @@ int Dedi_Search_Chip_Db(char* chTypeName,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("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; + 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++; - } + 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"); @@ -505,15 +502,14 @@ int Dedi_Search_Chip_Db(char* chTypeName,long RDIDCommand, 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; - } + pch = strstr(file_line_buf, "Portofolio"); //end + if (pch != NULL) { + if (detectICNum) + found_flag = 1; + } + } /*Continue until EOF is encoutered*/ - } /*Continue until EOF is encoutered*/ - fclose(fp); /*Close file*/ Chip_Info->MaxErasableSegmentInByte = max(Chip_Info->SectorSizeInByte, Chip_Info->BlockSizeInByte); free(file_buf); @@ -792,9 +788,6 @@ int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) bool Dedi_List_AllChip(void) { - - - FILE* fp; /*Declare file pointer variable*/ char file_line_buf[linebufsize], *tok, *file_buf, test[testbufsize]; char* pch; diff --git a/project.c b/project.c index 568983a..fafbc1d 100644 --- a/project.c +++ b/project.c @@ -41,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; @@ -54,7 +54,7 @@ extern unsigned int g_Vpp; extern unsigned int g_uiAddr; extern size_t g_uiLen; extern bool g_bEnableVpp; -extern unsigned int g_uiDevNum; +extern unsigned int g_uiDevNum; extern char strTypeName[1024]; #if 0 extern int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index); @@ -130,7 +130,7 @@ void TurnOFFVpp(int Index) } void TurnONVcc(int Index) -{ +{ dediprog_set_spi_voltage(g_Vcc, Index); } @@ -292,7 +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); + Found = FlashIdentifier(&binfo, 0, Index); if (Found && (binfo.UniqueID == Chip_Info.UniqueID || binfo.UniqueID == Chip_Info.JedecDeviceID)) result = true; @@ -375,22 +375,20 @@ bool ReadChip(const struct CAddressRange range, int Index) vc = (unsigned char*)malloc(addr.length); 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; } @@ -430,7 +428,7 @@ bool threadBlankCheck(int Index) } bool threadEraseWholeChip(int Index) -{ +{ bool result = false; // power::CAutoVccPower autopowerVcc(m_usb, m_context.power.vcc,Index); @@ -465,7 +463,7 @@ bool threadEraseWholeChip(int Index) } bool threadReadRangeChip(struct CAddressRange range, int Index) -{ +{ bool result = true; struct CAddressRange AddrRound; @@ -504,7 +502,7 @@ bool threadReadRangeChip(struct CAddressRange range, int Index) } bool threadReadChip(int Index) -{ +{ bool result = false; struct CAddressRange Addr; Addr.start = 0; @@ -675,7 +673,7 @@ bool threadCompareFileAndChip(int Index) #endif g_is_operation_successful[Index] = result; - + return result; } @@ -920,11 +918,11 @@ void threadRun(void* 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); + bool is_SF700_greater_than_4_0_0 = (g_firmversion > 0x40000); int dwUID = ReadUID(Index); if (g_uiAddr == 0 && g_uiLen == 0) { - if (g_bIsSF700[Index]==true) + 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); @@ -947,7 +945,7 @@ void threadRun(void* Type) { //printf("\n====>project ---- void threadRun(void* Type) --- is_good\n"); TurnONVcc(Index); - if (is_greater_than_5_0_0||is_SF700_greater_than_4_0_0) { + if (is_greater_than_5_0_0 || is_SF700_greater_than_4_0_0) { SetLEDOnOff(SITE_BUSY, Index); } @@ -981,7 +979,7 @@ void threadRun(void* Type) threadConfiguredReadChip(Index); break; - case VERIFY_CONTENT: + case VERIFY_CONTENT: threadCompareFileAndChip(Index); break; @@ -1044,7 +1042,7 @@ void SetIOMode(bool isProg, int Index) m_boEnReadQuadIO = 0; m_boEnWriteQuadIO = 0; - if ((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) + if ((g_bIsSF600[Index] == false) && (g_bIsSF700[Index] == false)) return; SetIOModeToSF600(IOValue, Index); @@ -1144,11 +1142,11 @@ 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)); + 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) @@ -1186,9 +1184,9 @@ 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; +{ + if (strstr(g_board_type, "SF700") != NULL) { + return true; } return false; } @@ -1253,40 +1251,38 @@ printf("GetFirstDetectionMatch(%x)\n",Index); return binfo; } #else -CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index) -{ +CHIP_INFO GetFirstDetectionMatch(char* TypeName, int Index) +{ CHIP_INFO binfo; binfo.UniqueID = 0; unsigned int g_Vcc_temp = 0; - //char TypeName[1024]; + //char TypeName[1024]; - // memset(TypeName, '\0', 1024); + // memset(TypeName, '\0', 1024); int Found = 0; int i = 0; int Loop = 3; if (strcmp(g_parameter_vcc, "NO") != 0) //g_parameter_vcc!=NO - Loop = 1; - - if(strlen(TypeName)!=0) - g_Vcc_temp = g_Vcc; + Loop = 1; + + if (strlen(TypeName) != 0) + g_Vcc_temp = g_Vcc; for (i = 0; i < Loop; i++) { - if (Found == 1) - { - if(strlen(TypeName)!=0) - g_Vcc = g_Vcc_temp; + if (Found == 1) { + if (strlen(TypeName) != 0) + g_Vcc = g_Vcc_temp; break; } - if (Loop == 1) + if (Loop == 1) g_Vcc = vcc3_5V; else - g_Vcc = vcc1_8V - i; + g_Vcc = vcc1_8V - i; TurnONVcc(Index); - if (Is_usbworking(Index)) - { - if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true)) { + if (Is_usbworking(Index)) { + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) { int startmode; if (g_StartupMode == STARTUP_APPLI_SF_2) @@ -1295,25 +1291,25 @@ CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index) SetTargetFlash(STARTUP_APPLI_SF_1, Index); startmode = g_StartupMode; - Found = FlashIdentifier(&binfo, 0, Index); + 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); + Found = FlashIdentifier(&binfo, 0, Index); if (Found == 0) g_StartupMode = startmode; } } } else { - Found = FlashIdentifier(&binfo, 0, Index); + Found = FlashIdentifier(&binfo, 0, Index); } } TurnOFFVcc(Index); @@ -1322,17 +1318,17 @@ CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index) binfo.UniqueID = 0; binfo.TypeName[0] = '\0'; } - - return binfo;//*TypeName; + + 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_SF700_greater_than_4_0_0 = ( g_firmversion > 0x40000); + 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||is_SF700_greater_than_4_0_0) + if (is_greater_than_5_0_0 || is_SF700_greater_than_4_0_0) SetLEDOnOff(SITE_NORMAL, Index); } @@ -1529,13 +1525,13 @@ void SetProgReadCommand(int Index) } bool ProjectInitWithID(CHIP_INFO chipinfo, int Index) // by designated ID -{ +{ DownloadAddrRange.start = 0; DownloadAddrRange.end = Chip_Info.ChipSizeInByte; InitLED(Index); // SetTargetFlash(g_StartupMode,Index); //for SF600 Freescale issue SetProgReadCommand(Index); - if (strcmp(g_parameter_vcc, "NO") == 0) { + if (strcmp(g_parameter_vcc, "NO") == 0) { switch (Chip_Info.VoltageInMv) { case 1800: g_Vcc = vcc1_8V; @@ -1548,15 +1544,14 @@ bool ProjectInitWithID(CHIP_INFO chipinfo, int Index) // by designated ID break; } } - + return true; } bool ProjectInit(int Index) // by designated ID -{ - Chip_Info = GetFirstDetectionMatch(strTypeName,Index); - if (Chip_Info.UniqueID == 0) - { +{ + 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 index 052c1ce..0935644 100644 --- a/project.h +++ b/project.h @@ -51,7 +51,7 @@ int GetFileFormatFromExt(const char* csPath); #if 0 CHIP_INFO GetFirstDetectionMatch(int Index); #else -CHIP_INFO GetFirstDetectionMatch(char* TypeName,int Index); +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); diff --git a/usbdriver.c b/usbdriver.c index 36f11b9..9e5e033 100644 --- a/usbdriver.c +++ b/usbdriver.c @@ -22,7 +22,6 @@ static int dev_index; static usb_device_entry_t usb_device_entry[MAX_Dev_Index]; static libusb_device_handle* dediprog_handle[MAX_Dev_Index]; - static libusb_context* ctx = NULL; /* * Filter based on a bus:device combo, to make sure we *only* touch @@ -33,9 +32,9 @@ unsigned g_usb_busnum = -1; bool Is_NewUSBCommand(int Index) { - 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; + 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; } @@ -70,10 +69,10 @@ 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]; @@ -87,8 +86,8 @@ void AssignSF600orSF700var(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]); @@ -106,7 +105,7 @@ void AssignSF600orSF700var(int Index) GetFPGAVersion(Index); } - + int get_usb_dev_cnt(void) { return dev_index; @@ -150,7 +149,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)||(g_bIsSF700[Index] == true))) + if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))) return true; requesttype = 0x00; @@ -195,7 +194,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)||(g_bIsSF700[Index] == true))) + if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))) return true; if (Index == -1) Index = DevIndex; @@ -221,8 +220,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; } @@ -233,7 +232,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) -{ +{ CNTRPIPE_RQ rq; int ret; unsigned char vInstruction; @@ -255,7 +254,7 @@ int dediprog_start_appli(int Index) int dediprog_get_chipid(int Index) { - //printf("\n===>usbdrive.c --- dediprog_get_chipid\n"); + //printf("\n===>usbdrive.c --- dediprog_get_chipid\n"); CNTRPIPE_RQ rq; int ret; unsigned char vInstruction[3]; @@ -300,9 +299,9 @@ 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); - if(ret!=0)//libusb_bulk_transfer return false - return 0; + 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; } @@ -321,13 +320,13 @@ 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)||(g_bIsSF700[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; } int dediprog_set_spi_voltage(int v, int Index) -{ +{ int ret = 0; // int voltage_selector; CNTRPIPE_RQ rq; @@ -402,7 +401,7 @@ int dediprog_set_spi_clk(int khz, int Index) { return 0; int ret; - int hz_selector; + int hz_selector; CNTRPIPE_RQ rq; switch (khz) { @@ -456,7 +455,7 @@ int dediprog_set_spi_clk(int khz, int Index) int usb_driver_init(void) { -//printf("\n===>usbdrive.c --- usb_driver_init\n"); + //printf("\n===>usbdrive.c --- usb_driver_init\n"); // struct usb_bus *bus; // struct usb_device *dev; bool result = false; @@ -467,10 +466,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"); @@ -492,10 +491,10 @@ int usb_driver_init(void) if (ret) { printf("Error: Programmers USB claim interface: 0x%x.\n", ret); return 0; - } - + } + dediprog_start_appli(i); - AssignSF600orSF700var(i); + AssignSF600orSF700var(i); result = (dediprog_handle[i] != NULL); } } else { @@ -503,7 +502,7 @@ 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"); @@ -520,15 +519,15 @@ int usb_driver_init(void) if (ret) { printf("Error: Programmers USB claim interface: 0x%x.\n", ret); return 0; - } + } dediprog_start_appli(g_uiDevNum - 1); - AssignSF600orSF700var(g_uiDevNum - 1); + AssignSF600orSF700var(g_uiDevNum - 1); result = (dediprog_handle[g_uiDevNum - 1] != NULL); } - + return result; //((dediprog_handle[i] != NULL)? 1:0); } @@ -584,7 +583,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 ; @@ -604,10 +603,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; }