diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..39a8ea0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,246 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: WebKit +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE +... + 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.h b/ChipInfoDb.h old mode 100755 new mode 100644 diff --git a/FlashCommand.c b/FlashCommand.c old mode 100755 new mode 100644 index 02bcb28..8132a11 --- a/FlashCommand.c +++ b/FlashCommand.c @@ -35,14 +35,14 @@ int FlashCommand_TransceiveOut(unsigned char* v, int len, int has_result_in, int int FlashCommand_TransceiveIn(unsigned char* v, int len, int Index) { - CNTRPIPE_RQ rq; + CNTRPIPE_RQ rq; rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; - if (Is_NewUSBCommand(Index)) { + if (Is_NewUSBCommand(Index)) { rq.Value = 0x01; rq.Index = NO_REGISTER; - } else { + } else { rq.Value = CTRL_TIMEOUT; rq.Index = NO_REGISTER; } @@ -89,7 +89,7 @@ int FlashCommand_SendCommand_OneOutOneIn(unsigned char* vOut, int out_len, unsig } int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode, int Index) -{ +{ unsigned char vInstruction[15]; CNTRPIPE_RQ rq; // length in terms of 256/128 bytes @@ -106,11 +106,11 @@ int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrR divider = 7; break; case PP_PROGRAM_ANYSIZE_PAGESIZE: - if(PageSize == 0x200) + if (PageSize == 0x200) divider = 9; - else if(PageSize == 0x400) + else if (PageSize == 0x400) divider = 10; - else + else divider = 8; default: // 256 bytes divider = 8; @@ -125,7 +125,7 @@ int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrR vInstruction[3] = modeWrite; // PAGE_PROGRAM, PAGE_WRITE, AAI_1_BYTE, AAI_2_BYTE, PP_128BYTE, PP_AT26DF041 vInstruction[4] = WriteCom; - if (Is_NewUSBCommand(Index)) { + if (Is_NewUSBCommand(Index)) { vInstruction[5] = 0; vInstruction[6] = (AddrRange->start & 0xff); vInstruction[7] = ((AddrRange->start >> 8) & 0xff); @@ -205,14 +205,13 @@ int FlashCommand_SendCommand_SetupPacketForBulkRead(struct CAddressRange* AddrRa // length in terms of 256 bytes size_t pageNum = AddrRange->length >> 9; - vInstruction[0] = (unsigned char)(pageNum & 0xff); // lowest byte of length : page number vInstruction[1] = (unsigned char)((pageNum >> 8) & 0xff); // highest byte of length: page number vInstruction[2] = (unsigned char)((pageNum >> 16) & 0xff); // reserved vInstruction[3] = modeRead; // BULK_NORM_READ, BULK_FAST_READ vInstruction[4] = ReadCom; - if (Is_NewUSBCommand(Index)) { + if (Is_NewUSBCommand(Index)) { vInstruction[5] = 0xFF; vInstruction[6] = (AddrRange->start & 0xff); vInstruction[7] = ((AddrRange->start >> 8) & 0xff); diff --git a/FlashCommand.h b/FlashCommand.h old mode 100755 new mode 100644 index cb7dcdb..d78f0a0 --- a/FlashCommand.h +++ b/FlashCommand.h @@ -24,4 +24,4 @@ int FlashCommand_SendCommand_SetupPacketForAT45DBBulkWrite(struct CAddressRange* int FlashCommand_SendCommand_SetupPacketForBulkRead(struct CAddressRange* AddrRange, unsigned char modeRead, unsigned char ReadCom, unsigned int AddrLen, unsigned int DummyLen, int Index); -#endif //FLASHCOMMANDS +#endif // FLASHCOMMANDS 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 index 9278e81..0342e86 --- a/IntelHexFile.h +++ b/IntelHexFile.h @@ -136,7 +136,7 @@ typedef struct { #define INTEL_DATA_TYPE 0 -//save binary data in vBuffer to file in Intel Hex format +// save binary data in vBuffer to file in Intel Hex format bool BinToHexFile(const char* filePath, unsigned char* vBuffer, unsigned long FileSize); // read binary data from Intel Hex file 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 index a1bdec9..03fb029 --- a/Macro.h +++ b/Macro.h @@ -9,7 +9,7 @@ #include // new defined macros -//programmer info RQ +// programmer info RQ #define PROGINFO_REQUEST 0x08 #define SET_VCC 0x09 ///< set VCC #define SET_VPP 0x03 ///< set VPP @@ -19,17 +19,17 @@ #define SET_HOLD 0x1D #define SET_SA 0x0A -//first field of RQ +// first field of RQ #define OUT_REQUEST 0x42 #define IN_REQUEST 0xC2 -//second field of RQ in case of bulk transfer -//#define TRANSCEIVE 0x01 -//#define DTC_READ 0x20 -//#define WRITE 0x30 -//#define READ_EEPROM 0x05 -//#define WRITE_EEPROM 0x06 -// values of Request Field of a setup packet +// second field of RQ in case of bulk transfer +// #define TRANSCEIVE 0x01 +// #define DTC_READ 0x20 +// #define WRITE 0x30 +// #define READ_EEPROM 0x05 +// #define WRITE_EEPROM 0x06 +// values of Request Field of a setup packet typedef struct FirmwareInfo { char Programmer[20]; char Version[10]; @@ -90,7 +90,7 @@ typedef struct ChipInfo { size_t VoltageInMv; } CHIP_INFO; -//third field of RQ +// third field of RQ #define CTRL_TIMEOUT 3000 ///< time out for control pipe or for firmwire // fourth field of RQ @@ -123,9 +123,9 @@ typedef struct ChipInfo { #define BULK_FAST_READ 0x02 ///< fast read via bulk pipes #define BULK_AT45xx_READ 0x03 ///< fast read via bulk pipes #define BULK_4BYTE_FAST_READ 0x04 ///< For size is bigger than 128Mb -#define BULK_4BYTE_FAST_READ_MICRON 0x05 //for 0x0c +#define BULK_4BYTE_FAST_READ_MICRON 0x05 // for 0x0c -//for flash card +// for flash card #define POLLING 0x02 ///< polling #define SET_VPP 0x03 ///< set vpp #define VPP_OFF 0x00 ///< vpp value @@ -137,14 +137,14 @@ typedef struct ChipInfo { #define FLASH_CARD 0x01 ///< flash card #define APPLICATION_MEMORY_2 0x02 ///< application memory chip 2 -//for io & LED +// for io & LED #define SET_IO 0x07 ///< request -//IO number +// IO number #define IO_1 0x01 #define IO_2 0x02 #define IO_3 0x04 #define IO_4 0x08 -//led number +// led number #define LED_RED 0x01 #define LED_GREEN 0x02 #define LED_ORANGE 0x04 diff --git a/MotorolaFile.c b/MotorolaFile.c old mode 100755 new mode 100644 index fce4b31..8c77098 --- a/MotorolaFile.c +++ b/MotorolaFile.c @@ -1,100 +1,100 @@ //-------------------------------------------------------------------------------- -//NAME -//srec - S-record file and record format -//DESCRIPTION +// NAME +// srec - S-record file and record format +// DESCRIPTION -//An S-record file consists of a sequence of specially formatted ASCII character strings. An S-record will be less than or equal to 78 bytes in length. -//The order of S-records within a file is of no significance and no particular order may be assumed. +// An S-record file consists of a sequence of specially formatted ASCII character strings. An S-record will be less than or equal to 78 bytes in length. +// The order of S-records within a file is of no significance and no particular order may be assumed. -//The general format of an S-record follows: +// The general format of an S-record follows: //+-------------------//------------------//-----------------------+ //| type | count | address | data | checksum | //+-------------------//------------------//-----------------------+ -//type -- A char[2] field. These characters describe the type of record (S0, S1, S2, S3, S5, S7, S8, or S9). -//count -- A char[2] field. These characters when paired and interpreted as a hexadecimal value, display the count of remaining character pairs in the record. +// type -- A char[2] field. These characters describe the type of record (S0, S1, S2, S3, S5, S7, S8, or S9). +// count -- A char[2] field. These characters when paired and interpreted as a hexadecimal value, display the count of remaining character pairs in the record. -//address -- A char[4,6, or 8] field. These characters grouped and interpreted as a hexadecimal value, display the address at which the data field is to be loaded into memory. The length of the field depends on the number of bytes necessary to hold the address. A 2-byte address uses 4 characters, a 3-byte address uses 6 characters, and a 4-byte address uses 8 characters. +// address -- A char[4,6, or 8] field. These characters grouped and interpreted as a hexadecimal value, display the address at which the data field is to be loaded into memory. The length of the field depends on the number of bytes necessary to hold the address. A 2-byte address uses 4 characters, a 3-byte address uses 6 characters, and a 4-byte address uses 8 characters. -//data -- A char [0-64] field. These characters when paired and interpreted as hexadecimal values represent the memory loadable data or descriptive information. +// data -- A char [0-64] field. These characters when paired and interpreted as hexadecimal values represent the memory loadable data or descriptive information. -//checksum -- A char[2] field. These characters when paired and interpreted as a hexadecimal value display the least significant byte of the ones complement of the sum of the byte values represented by the pairs of characters making up the count, the address, and the data fields. +// checksum -- A char[2] field. These characters when paired and interpreted as a hexadecimal value display the least significant byte of the ones complement of the sum of the byte values represented by the pairs of characters making up the count, the address, and the data fields. -//Each record is terminated with a line feed. If any additional or different record terminator(s) or delay characters are needed during transmission to the target system it is the responsibility of the transmitting program to provide them. +// Each record is terminated with a line feed. If any additional or different record terminator(s) or delay characters are needed during transmission to the target system it is the responsibility of the transmitting program to provide them. -//S0 Record. The type of record is 'S0' (0x5330). The address field is unused and will be filled with zeros (0x0000). The header information within the data field is divided into the following subfields. +// S0 Record. The type of record is 'S0' (0x5330). The address field is unused and will be filled with zeros (0x0000). The header information within the data field is divided into the following subfields. -//mname is char[20] and is the module name. -//ver is char[2] and is the version number. -//rev is char[2] and is the revision number. -//description is char[0-36] and is a text comment. +// mname is char[20] and is the module name. +// ver is char[2] and is the version number. +// rev is char[2] and is the revision number. +// description is char[0-36] and is a text comment. -//Each of the subfields is composed of ASCII bytes whose associated characters, when paired, represent one byte hexadecimal values in the case of the version and revision numbers, or represent the hexadecimal values of the ASCII characters comprising the module name and description. -//S1 Record. The type of record field is 'S1' (0x5331). The address field is intrepreted as a 2-byte address. The data field is composed of memory loadable data. +// Each of the subfields is composed of ASCII bytes whose associated characters, when paired, represent one byte hexadecimal values in the case of the version and revision numbers, or represent the hexadecimal values of the ASCII characters comprising the module name and description. +// S1 Record. The type of record field is 'S1' (0x5331). The address field is intrepreted as a 2-byte address. The data field is composed of memory loadable data. -//S2 Record. The type of record field is 'S2' (0x5332). The address field is intrepreted as a 3-byte address. The data field is composed of memory loadable data. +// S2 Record. The type of record field is 'S2' (0x5332). The address field is intrepreted as a 3-byte address. The data field is composed of memory loadable data. -//S3 Record. The type of record field is 'S3' (0x5333). The address field is intrepreted as a 4-byte address. The data field is composed of memory loadable data. +// S3 Record. The type of record field is 'S3' (0x5333). The address field is intrepreted as a 4-byte address. The data field is composed of memory loadable data. -//S5 Record. The type of record field is 'S5' (0x5335). The address field is intrepreted as a 2-byte value and contains the count of S1, S2, and S3 records previously transmitted. There is no data field. +// S5 Record. The type of record field is 'S5' (0x5335). The address field is intrepreted as a 2-byte value and contains the count of S1, S2, and S3 records previously transmitted. There is no data field. -//S7 Record. The type of record field is 'S7' (0x5337). The address field contains the starting execution address and is intrepreted as 4-byte address. There is no data field. +// S7 Record. The type of record field is 'S7' (0x5337). The address field contains the starting execution address and is intrepreted as 4-byte address. There is no data field. -//S8 Record. The type of record field is 'S8' (0x5338). The address field contains the starting execution address and is intrepreted as 3-byte address. There is no data field. +// S8 Record. The type of record field is 'S8' (0x5338). The address field contains the starting execution address and is intrepreted as 3-byte address. There is no data field. -//S9 Record. The type of record field is 'S9' (0x5339). The address field contains the starting execution address and is intrepreted as 2-byte address. There is no data field. +// S9 Record. The type of record field is 'S9' (0x5339). The address field contains the starting execution address and is intrepreted as 2-byte address. There is no data field. -//EXAMPLE +// EXAMPLE -//Shown below is a typical S-record format file. +// Shown below is a typical S-record format file. -//S00600004844521B -//S1130000285F245F2212226A000424290008237C2A -//S11300100002000800082629001853812341001813 -//S113002041E900084E42234300182342000824A952 -//S107003000144ED492 -//S5030004F8 -//S9030000FC -//The file consists of one S0 record, four S1 records, one S5 record and an S9 record. +// S00600004844521B +// S1130000285F245F2212226A000424290008237C2A +// S11300100002000800082629001853812341001813 +// S113002041E900084E42234300182342000824A952 +// S107003000144ED492 +// S5030004F8 +// S9030000FC +// The file consists of one S0 record, four S1 records, one S5 record and an S9 record. -//The S0 record is comprised as follows: +// The S0 record is comprised as follows: -//S0 S-record type S0, indicating it is a header record. -//06 Hexadecimal 06 (decimal 6), indicating that six character pairs (or ASCII bytes) follow. -//00 00 Four character 2-byte address field, zeroes in this example. +// S0 S-record type S0, indicating it is a header record. +// 06 Hexadecimal 06 (decimal 6), indicating that six character pairs (or ASCII bytes) follow. +// 00 00 Four character 2-byte address field, zeroes in this example. -//48 44 52 ASCII H, D, and R - "HDR". -//1B The checksum. -//The first S1 record is comprised as follows: -//S1 S-record type S1, indicating it is a data record to be loaded at a 2-byte address. -//13 Hexadecimal 13 (decimal 19), indicating that nineteen character pairs, representing a 2 byte address, 16 bytes of binary data, and a 1 byte checksum, follow. -//00 00 Four character 2-byte address field; hexidecimal address 0x0000, where the data which follows is to be loaded. -//28 5F 24 5F 22 12 22 6A 00 04 24 29 00 08 23 7C Sixteen character pairs representing the actual binary data. -//2A The checksum. -//The second and third S1 records each contain 0x13 (19) character pairs and are ended with checksums of 13 and 52, respectively. The fourth S1 record contains 07 character pairs and has a checksum of 92. +// 48 44 52 ASCII H, D, and R - "HDR". +// 1B The checksum. +// The first S1 record is comprised as follows: +// S1 S-record type S1, indicating it is a data record to be loaded at a 2-byte address. +// 13 Hexadecimal 13 (decimal 19), indicating that nineteen character pairs, representing a 2 byte address, 16 bytes of binary data, and a 1 byte checksum, follow. +// 00 00 Four character 2-byte address field; hexidecimal address 0x0000, where the data which follows is to be loaded. +// 28 5F 24 5F 22 12 22 6A 00 04 24 29 00 08 23 7C Sixteen character pairs representing the actual binary data. +// 2A The checksum. +// The second and third S1 records each contain 0x13 (19) character pairs and are ended with checksums of 13 and 52, respectively. The fourth S1 record contains 07 character pairs and has a checksum of 92. -//The S5 record is comprised as follows: +// The S5 record is comprised as follows: -//S5 S-record type S5, indicating it is a count record indicating the number of S1 records -//03 Hexadecimal 03 (decimal 3), indicating that three character pairs follow. -//00 04 Hexadecimal 0004 (decimal 4), indicating that there are four data records previous to this record. -//F8 The checksum. -//The S9 record is comprised as follows: +// S5 S-record type S5, indicating it is a count record indicating the number of S1 records +// 03 Hexadecimal 03 (decimal 3), indicating that three character pairs follow. +// 00 04 Hexadecimal 0004 (decimal 4), indicating that there are four data records previous to this record. +// F8 The checksum. +// The S9 record is comprised as follows: -//S9 S-record type S9, indicating it is a termination record. -//03 Hexadecimal 03 (decimal 3), indicating that three character pairs follow. -//00 00 The address field, hexadecimal 0 (decimal 0) indicating the starting execution address. -//FC The checksum. +// S9 S-record type S9, indicating it is a termination record. +// 03 Hexadecimal 03 (decimal 3), indicating that three character pairs follow. +// 00 00 The address field, hexadecimal 0 (decimal 0) indicating the starting execution address. +// FC The checksum. //-------------------------------------------------------------------------------- -//Instructor Notes -//There isn't any evidence that Motorola ever has made use of the header information within the data field of the S0 record, as described above. This must have been used by some third party vendors. -//This is the only place that a 78-byte limit on total record length or 64-byte limit on data length is documented. These values shouldn't be trusted for the general case. -//The count field can have values in the range of 0x3 (2 bytes of address + 1 byte checksum = 3, a not very useful record) to 0xff; this is the count of remaining character pairs, including checksum. -//If you write code to convert S-Records, you should always assume that a record can be as long as 514 (decimal) characters in length (255 * 2 = 510, plus 4 characters for the type and count fields), -//plus any terminating character(s). That is, in establishing an input buffer in C, you would declare it to be an array of 515 chars, thus leaving room for the terminating null character. +// Instructor Notes +// There isn't any evidence that Motorola ever has made use of the header information within the data field of the S0 record, as described above. This must have been used by some third party vendors. +// This is the only place that a 78-byte limit on total record length or 64-byte limit on data length is documented. These values shouldn't be trusted for the general case. +// The count field can have values in the range of 0x3 (2 bytes of address + 1 byte checksum = 3, a not very useful record) to 0xff; this is the count of remaining character pairs, including checksum. +// If you write code to convert S-Records, you should always assume that a record can be as long as 514 (decimal) characters in length (255 * 2 = 510, plus 4 characters for the type and count fields), +// plus any terminating character(s). That is, in establishing an input buffer in C, you would declare it to be an array of 515 chars, thus leaving room for the terminating null character. #include "MotorolaFile.h" #include "project.h" #include @@ -257,7 +257,7 @@ bool S19FileToBin(const char* filePath, unsigned char* vData, unsigned long* Fil if ((temp2 != Checksum) && Enable_Checksum_Error) { } } else { - //fprintf(stderr,"Data record skipped at %8X\n",Phys_Addr); + // fprintf(stderr,"Data record skipped at %8X\n",Phys_Addr); } break; @@ -285,11 +285,11 @@ bool S19FileToBin(const char* filePath, unsigned char* vData, unsigned long* Fil wCKS += Memory_Block[i]; } - //fprintf(stdout,"8-bit Checksum = %02X\n",wCKS & 0xff); + // fprintf(stdout,"8-bit Checksum = %02X\n",wCKS & 0xff); if (Cks_Addr_set) { wCKS = Cks_Value - (wCKS - Memory_Block[Cks_Addr]); Memory_Block[Cks_Addr] = (unsigned char)(wCKS & 0xff); - //fprintf(stdout,"Addr %08X set to %02X\n",Cks_Addr, wCKS & 0xff); + // fprintf(stdout,"Addr %08X set to %02X\n",Cks_Addr, wCKS & 0xff); } break; @@ -300,13 +300,13 @@ bool S19FileToBin(const char* filePath, unsigned char* vData, unsigned long* Fil wCKS += w; } - //fprintf(stdout,"16-bit Checksum = %04X\n",wCKS); + // fprintf(stdout,"16-bit Checksum = %04X\n",wCKS); if (Cks_Addr_set) { w = Memory_Block[Cks_Addr + 1] | ((unsigned short)Memory_Block[Cks_Addr] << 8); wCKS = Cks_Value - (wCKS - w); Memory_Block[Cks_Addr] = (unsigned char)(wCKS >> 8); Memory_Block[Cks_Addr + 1] = (unsigned char)(wCKS & 0xff); - //fprintf(stdout,"Addr %08X set to %04X\n",Cks_Addr, wCKS); + // fprintf(stdout,"Addr %08X set to %04X\n",Cks_Addr, wCKS); } break; @@ -317,13 +317,13 @@ bool S19FileToBin(const char* filePath, unsigned char* vData, unsigned long* Fil wCKS += w; } - //fprintf(stdout,"16-bit Checksum = %04X\n",wCKS); + // fprintf(stdout,"16-bit Checksum = %04X\n",wCKS); if (Cks_Addr_set) { w = Memory_Block[Cks_Addr] | ((unsigned short)Memory_Block[Cks_Addr + 1] << 8); wCKS = Cks_Value - (wCKS - w); Memory_Block[Cks_Addr + 1] = (unsigned char)(wCKS >> 8); Memory_Block[Cks_Addr] = (unsigned char)(wCKS & 0xff); - //fprintf(stdout,"Addr %08X set to %04X\n",Cks_Addr, wCKS); + // fprintf(stdout,"Addr %08X set to %04X\n",Cks_Addr, wCKS); } default: @@ -349,7 +349,7 @@ bool S19FileToBin(const char* filePath, unsigned char* vData, unsigned long* Fil bool BinToS19File(const char* filePath, unsigned char* vData, unsigned long FileSize) { - //ANSI only + // ANSI only FILE* FileOut; /* input files */ FileOut = fopen(filePath, "wt"); if (FileOut == NULL) 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 index 3584add..30864f6 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ $ make The resulting binary should be called `dpcmd` and located in the root of the source tree. There is no install target at the moment. +`dpcmd` can also be built with `meson`. Ensure you have [`meson`](https://mesonbuild.com/Getting-meson.html) installed and then invoke it: +```bash +$ meson setup builddir +$ meson compile -C builddir +``` + ## Usage Most basic usage is writing a whole image file to a flash chip: ```bash diff --git a/SerialFlash.c b/SerialFlash.c old mode 100755 new mode 100644 index 9d462b7..3b6d30d --- a/SerialFlash.c +++ b/SerialFlash.c @@ -13,7 +13,7 @@ extern int m_boEnWriteQuadIO; extern CHIP_INFO Chip_Info; extern volatile bool g_bIsSF600[16]; extern volatile bool g_bIsSF700[16]; -extern volatile bool g_bIsSF600PG2[16]; +extern volatile bool g_bIsSF600PG2[16]; extern bool Is_NewUSBCommand(int Index); unsigned char mcode_WRSR = 0x01; @@ -36,7 +36,7 @@ size_t AT45PageSize = 0; bool AT45doRDSR(unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction; //size 1 + unsigned char vInstruction; // size 1 // first control packet vInstruction = 0xD7; @@ -57,7 +57,7 @@ bool AT45doRDSR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -119,17 +119,17 @@ unsigned char getWriteMode(int USBIndex) case AT45DB021D: case AT45DB041D: case AT45DB081D: - cMode = powerOfTwo ? 1 : 2; //256 : 264; + cMode = powerOfTwo ? 1 : 2; // 256 : 264; break; case AT45DB161D: case AT45DB321D: - cMode = powerOfTwo ? 3 : 4; //512 : 528; + cMode = powerOfTwo ? 3 : 4; // 512 : 528; break; case AT45DB642D: - cMode = powerOfTwo ? 5 : 6; //1024 : 1056; + cMode = powerOfTwo ? 5 : 6; // 1024 : 1056; break; default: - cMode = powerOfTwo ? 1 : 2; //256 : 264; + cMode = powerOfTwo ? 1 : 2; // 256 : 264; } return cMode; } @@ -165,7 +165,7 @@ size_t GetPageSize(void) bool AT45xxx_protectBlock(int bProtect, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[4]; //size 1 + unsigned char vInstruction[4]; // size 1 rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; @@ -248,9 +248,9 @@ int AT45rangSectorErase(size_t sectionSize, struct CAddressRange AddrRange, int for (i = 0; i < sectorNum; ++i) { size_t addr = (AddrRange.start + i * sectionSize); - vInstruction[1] = (unsigned char)((addr >> 16) & 0xff); //MSB - vInstruction[2] = (unsigned char)((addr >> 8) & 0xff); //M - vInstruction[3] = (unsigned char)(addr & 0xff); //LSB + vInstruction[1] = (unsigned char)((addr >> 16) & 0xff); // MSB + vInstruction[2] = (unsigned char)((addr >> 8) & 0xff); // M + vInstruction[3] = (unsigned char)(addr & 0xff); // LSB int b = OutCtrlRequest(&rq, vInstruction, 4, USBIndex); if ((b == SerialFlash_FALSE) || m_isCanceled) @@ -360,11 +360,11 @@ bool AT45batchErase(size_t* vAddrs, size_t AddrSize, int USBIndex) } break; case (1 << 21) * 264 / 256: // 16Mbit - if (vAddrs[i] < (1 << 14)) { + if (vAddrs[i] < (1 << 14)) { range.start = vAddrs[i]; range.end = vAddrs[i] + (1 << 13); AT45rangSectorErase(1 << 13, range, USBIndex); - } else { + } else { range.start = vAddrs[i]; range.end = vAddrs[i] + (1 << 18); AT45rangSectorErase(1 << 18, range, USBIndex); @@ -556,8 +556,8 @@ bool AT45chipErase(unsigned int Addr, unsigned int Length, int USBIndex) // WRSR only is effects on SRWD BP2 BP1 BP0 when WEL = 1 int SerialFlash_doWRSR(unsigned char cSR, int Index) { - //simon if(! m_usb.is_open()) - //Simon return false ; + // simon if(! m_usb.is_open()) + // Simon return false ; // wait until WIP = 0 SerialFlash_waitForWIP(Index); @@ -577,12 +577,12 @@ int SerialFlash_doWRSR(unsigned char cSR, int Index) int SerialFlash_doRDSR(unsigned char* cSR, int Index) { // read status - //Simon if(! m_usb.is_open() ) - //Simon return false ; + // Simon if(! m_usb.is_open() ) + // Simon return false ; // send request CNTRPIPE_RQ rq; - unsigned char vInstruction; //size 1 + unsigned char vInstruction; // size 1 // first control packet vInstruction = mcode_RDSR; @@ -603,7 +603,7 @@ int SerialFlash_doRDSR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -626,7 +626,7 @@ int SerialFlash_doRDSR(unsigned char* cSR, int Index) int S70FSxxx_Large_doRDSR1V(bool die1, unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[7] = { 0 }; //size 1 + unsigned char vInstruction[7] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x65; @@ -653,7 +653,7 @@ int S70FSxxx_Large_doRDSR1V(bool die1, unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -677,7 +677,7 @@ int S70FSxxx_Large_doRDSR1V(bool die1, unsigned char* cSR, int Index) int S70FSxxx_Large_doRDCR2V(bool die1, unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[7] = { 0 }; //size 1 + unsigned char vInstruction[7] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x65; @@ -704,7 +704,7 @@ int S70FSxxx_Large_doRDCR2V(bool die1, unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -728,7 +728,7 @@ int S70FSxxx_Large_doRDCR2V(bool die1, unsigned char* cSR, int Index) int MX25Lxxx_Large_doRDCR(unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[1] = { 0 }; //size 1 + unsigned char vInstruction[1] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x15; @@ -749,7 +749,7 @@ int MX25Lxxx_Large_doRDCR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -773,7 +773,7 @@ int MX25Lxxx_Large_doRDCR(unsigned char* cSR, int Index) int MX25Lxxx_Large_doRDSR(unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[1] = { 0 }; //size 1 + unsigned char vInstruction[1] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x05; @@ -794,7 +794,7 @@ int MX25Lxxx_Large_doRDSR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -820,7 +820,7 @@ int MX25Lxxx_Large_doWRCR(unsigned char cCR, int Index) unsigned char cSR; CNTRPIPE_RQ rq; - unsigned char vInstruction[1] = { 0 }; //size 1 + unsigned char vInstruction[1] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x05; @@ -841,7 +841,7 @@ int MX25Lxxx_Large_doWRCR(unsigned char cCR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -913,10 +913,10 @@ void S70FSxxx_Large_waitForWEL(bool die1, int Index) } while (((cSR & 0x02) == 0) && (i-- > 0)); } -bool S25FSxxS_Large_doRDCF3V(unsigned char *cSR, int Index) +bool S25FSxxS_Large_doRDCF3V(unsigned char* cSR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction[6] = { 0 }; //size 1 + unsigned char vInstruction[6] = { 0 }; // size 1 // first control packet vInstruction[0] = 0x65; @@ -942,7 +942,7 @@ bool S25FSxxS_Large_doRDCF3V(unsigned char *cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -1035,11 +1035,11 @@ bool SST25xFxx_protectBlock(int bProtect, int Index) } unsigned char vInstruction[2]; - vInstruction[0] = 0x50; //Write enable + vInstruction[0] = 0x50; // Write enable FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 1, Index); int numOfRetry = 1000; - vInstruction[0] = 0x01; //Write register + vInstruction[0] = 0x01; // Write register vInstruction[1] = dstSRVal; FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 2, Index); @@ -1210,7 +1210,7 @@ bool CMX25LxxxdoRDSCUR(unsigned char* cSR, int Index) // read status // send request CNTRPIPE_RQ rq; - unsigned char vInstruction = RDSCUR; //size 1 + unsigned char vInstruction = RDSCUR; // size 1 rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; @@ -1228,7 +1228,7 @@ bool CMX25LxxxdoRDSCUR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -1260,7 +1260,7 @@ bool CS25FLxxx_LargedoUnlockDYB(unsigned int cSR, int Index) int i; unsigned int topend, bottomstart, end; - if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) //256 + if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) // 256 { topend = 0x20000; bottomstart = 0x1fe0000; @@ -1271,10 +1271,10 @@ bool CS25FLxxx_LargedoUnlockDYB(unsigned int cSR, int Index) end = 0x1000000; } - for (i = 0; i < topend; i = i + 0x1000) //top 4k sectors + for (i = 0; i < topend; i = i + 0x1000) // top 4k sectors { SerialFlash_waitForWEL(Index); - vInstruction[0] = 0xE1; //write DYB + vInstruction[0] = 0xE1; // write DYB vInstruction[1] = (unsigned char)(i >> 24); vInstruction[2] = (unsigned char)(i >> 16); vInstruction[3] = (unsigned char)(i >> 8); @@ -1284,10 +1284,10 @@ bool CS25FLxxx_LargedoUnlockDYB(unsigned int cSR, int Index) SerialFlash_waitForWIP(Index); } - for (i = topend; i < bottomstart; i = i + 0x10000) //64k sectors + for (i = topend; i < bottomstart; i = i + 0x10000) // 64k sectors { SerialFlash_waitForWEL(Index); - vInstruction[0] = 0xE1; //write DYB + vInstruction[0] = 0xE1; // write DYB vInstruction[1] = (unsigned char)(i >> 24); vInstruction[2] = (unsigned char)(i >> 16); vInstruction[3] = (unsigned char)(i >> 8); @@ -1297,10 +1297,10 @@ bool CS25FLxxx_LargedoUnlockDYB(unsigned int cSR, int Index) SerialFlash_waitForWIP(Index); } - for (i = bottomstart; i < end; i = i + 0x1000) //bottom 4k sectors + for (i = bottomstart; i < end; i = i + 0x1000) // bottom 4k sectors { SerialFlash_waitForWEL(Index); - vInstruction[0] = 0xE1; //write DYB + vInstruction[0] = 0xE1; // write DYB vInstruction[1] = (unsigned char)(i >> 24); vInstruction[2] = (unsigned char)(i >> 16); vInstruction[3] = (unsigned char)(i >> 8); @@ -1349,8 +1349,8 @@ int SerialFlash_protectBlock(int bProtect, int Index) bool result = false; unsigned char tmpSRVal; unsigned char dstSRVal; - //int numOfRetry = 3 ; - // un-protect block ,set BP2 BP1 BP2 to 0 + // int numOfRetry = 3 ; + // un-protect block ,set BP2 BP1 BP2 to 0 dstSRVal = 0x00; // protect block ,set BP2 BP1 BP2 to 1 if (bProtect) { @@ -1376,8 +1376,8 @@ int SerialFlash_protectBlock(int bProtect, int Index) int SerialFlash_EnableQuadIO(int bEnable, int boRW, int Index) { - m_boEnWriteQuadIO = (bEnable & boRW); //Simon: ported done??? - m_boEnReadQuadIO = (bEnable & boRW); //Simon: ported done??? + m_boEnWriteQuadIO = (bEnable & boRW); // Simon: ported done??? + m_boEnReadQuadIO = (bEnable & boRW); // Simon: ported done??? return SerialFlash_TRUE; } @@ -1400,7 +1400,7 @@ bool CN25Qxxx_LargeRDFSR(unsigned char* cSR, int Index) { // send request CNTRPIPE_RQ rq; - unsigned char vInstruction = 0x70; //size 1 + unsigned char vInstruction = 0x70; // size 1 rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; @@ -1418,7 +1418,7 @@ bool CN25Qxxx_LargeRDFSR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -1438,14 +1438,14 @@ bool CN25Qxxx_LargeRDFSR(unsigned char* cSR, int Index) return SerialFlash_TRUE; } -bool CN25Qxxx_Large_4Die_WREAR(unsigned char cSR,int Index) -{ +bool CN25Qxxx_Large_4Die_WREAR(unsigned char cSR, int Index) +{ SerialFlash_waitForWIP(Index); SerialFlash_waitForWEL(Index); unsigned char vInstruction[2]; - vInstruction[0] = 0xC5 ; - vInstruction[1] = cSR&0xFF; + vInstruction[0] = 0xC5; + vInstruction[1] = cSR & 0xFF; FlashCommand_TransceiveOut(vInstruction, 2, false, Index); @@ -1455,12 +1455,11 @@ bool CN25Qxxx_Large_4Die_WREAR(unsigned char cSR,int Index) bool CN25Qxxx_Large_4Die_RDEAR(unsigned char* cEAR, int Index) { - + CNTRPIPE_RQ rq; - unsigned char vInstruction; + unsigned char vInstruction; vInstruction = 0xC8; - - + rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = TRANSCEIVE; @@ -1492,14 +1491,14 @@ bool CN25Qxxx_Large_4Die_RDEAR(unsigned char* cEAR, int Index) if (InCtrlRequest(&rq, &vBuffer, 1, Index) == SerialFlash_FALSE) return SerialFlash_FALSE; - - *cEAR = vBuffer; + + *cEAR = vBuffer; return SerialFlash_TRUE; } bool CN25Qxxx_Large_doWRVCR(unsigned char ucVCR, int Index) { - unsigned char vInstruction[2]; //size 1 + unsigned char vInstruction[2]; // size 1 SerialFlash_waitForWIP(Index); SerialFlash_waitForWEL(Index); @@ -1508,14 +1507,14 @@ bool CN25Qxxx_Large_doWRVCR(unsigned char ucVCR, int Index) FlashCommand_TransceiveOut(vInstruction, 2, false, Index); - SerialFlash_waitForWIP(Index); + SerialFlash_waitForWIP(Index); return true; } bool CN25Qxxx_Large_doRDENVCR(unsigned char* ucENVCR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction; //size 1 + unsigned char vInstruction; // size 1 vInstruction = 0x65; rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; @@ -1555,21 +1554,21 @@ bool CN25Qxxx_Large_doRDENVCR(unsigned char* ucENVCR, int Index) bool CN25Qxxx_Large_doWRENVCR(unsigned char ucENVCR, int Index) { - unsigned char vInstruction[2]; //size 1 + unsigned char vInstruction[2]; // size 1 SerialFlash_waitForWIP(Index); SerialFlash_waitForWEL(Index); vInstruction[0] = 0x61; vInstruction[1] = ucENVCR & 0xFF; - FlashCommand_TransceiveOut(vInstruction, 2, false, Index); + FlashCommand_TransceiveOut(vInstruction, 2, false, Index); return true; } bool CN25Qxxx_Large_doRDVCR(unsigned char* ucVCR, int Index) { CNTRPIPE_RQ rq; - unsigned char vInstruction; //size 1 + unsigned char vInstruction; // size 1 vInstruction = 0x85; rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; @@ -1608,12 +1607,12 @@ bool CN25Qxxx_Large_doRDVCR(unsigned char* ucVCR, int Index) } bool CN25Qxxx_MutipleDIe_LargeRDEAR(unsigned char* cSR, int Index) { // read status - //Simon if(! m_usb.is_open() ) - //Simon return false ; + // Simon if(! m_usb.is_open() ) + // Simon return false ; // send request CNTRPIPE_RQ rq; - unsigned char vInstruction; //size 1 + unsigned char vInstruction; // size 1 // first control packet vInstruction = 0xc8; @@ -1634,7 +1633,7 @@ bool CN25Qxxx_MutipleDIe_LargeRDEAR(unsigned char* cSR, int Index) return SerialFlash_FALSE; // second control packet : fetch data - unsigned char vBuffer; //just read one bytes , in fact more bytes are also available + unsigned char vBuffer; // just read one bytes , in fact more bytes are also available rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_IN; rq.Request = TRANSCEIVE; @@ -1692,7 +1691,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); @@ -1785,9 +1784,9 @@ int S70FSxxx_Large_Enable4ByteAddrMode(int Enable4Byte, int Index) return true; } } -//Simon: unused ??? +// Simon: unused ??? int SerialFlash_Enable4ByteAddrMode(int bEnable, int Index) -{ +{ if (strstr(Chip_Info.Class, SUPPORT_EON_EN25QHxx_Large) != NULL || strstr(Chip_Info.Class, SUPPORT_MACRONIX_MX25Lxxx_Large) != NULL || strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Pxx_Large) != NULL || strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Qxx_Large) != NULL) return CEN25QHxx_LargeEnable4ByteAddrMode(bEnable, Index); else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) @@ -1796,9 +1795,9 @@ 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 if(Chip_Info.ChipSizeInByte > 0x1000000) + else if (Chip_Info.ChipSizeInByte > 0x1000000) return Universal_LargeEnable4ByteAddrMode(bEnable, Index); - + return SerialFlash_TRUE; } @@ -1824,7 +1823,7 @@ int SerialFlash_rangeBlankCheck(struct CAddressRange* Range, int Index) return false; } for (i = 0; i < Range->length; i++) { - if (vBuffer[i] != 0xFF) { + if (vBuffer[i] != 0xFF) { free(vBuffer); return false; } @@ -1855,7 +1854,7 @@ 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) { @@ -1866,37 +1865,37 @@ int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vDa } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) { return SerialFlash_bulkPipeProgram(AddrRange, vData, mcode_Program, 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)|| (g_bIsSF600PG2[Index] == true)) { + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true) || (g_bIsSF600PG2[Index] == true)) { return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_S70FS01GS, mcode_ProgramCode_4Adr_12, Index); } else return false; - } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { - return SerialFlash_bulkPipeProgram_twoDie(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); - } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { - return SerialFlash_bulkPipeProgram_Micron_4Die(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); - } else { + } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { + return SerialFlash_bulkPipeProgram_twoDie(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); + } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { + return SerialFlash_bulkPipeProgram_Micron_4Die(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); + } else { return SerialFlash_bulkPipeProgram(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index); } } int SerialFlash_rangeRead(struct CAddressRange* AddrRange, unsigned char* vData, int Index) -{ +{ if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) { - if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)|| (g_bIsSF600PG2[Index] == true)) + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true) || (g_bIsSF600PG2[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) { return SerialFlash_bulkPipeRead(AddrRange, vData, mcode_Read, mcode_ReadCode, Index); } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) { - if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)|| (g_bIsSF600PG2[Index] == true)) + if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true) || (g_bIsSF600PG2[Index] == true)) return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode_0C, Index); else return false; - } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { - return SerialFlash_bulkPipeRead_twoDie(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode_0C, Index); - } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { - return SerialFlash_bulkPipeRead_Micron_4die(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode_0C, Index); + } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { + return SerialFlash_bulkPipeRead_twoDie(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode_0C, Index); + } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { + return SerialFlash_bulkPipeRead_Micron_4die(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode_0C, Index); } else return SerialFlash_bulkPipeRead(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode, Index); }; @@ -1948,14 +1947,14 @@ int SerialFlash_DoPolling(int Index) */ int SerialFlash_is_good() { - //Simon return ( m_info.is_good() && m_usb.is_open() ) ; + // Simon return ( m_info.is_good() && m_usb.is_open() ) ; return SerialFlash_TRUE; } int SerialFlash_batchErase_W25Mxx_Large(uintptr_t* vAddrs, size_t AddrSize, int Index) -{ +{ if (!SerialFlash_StartofOperation(Index)) return false; - + if (0 == mcode_SegmentErase) return 1; // chipErase code not initialised or not supported, please check chip class ctor.SerialFlash_waitForWEL @@ -1969,8 +1968,7 @@ int SerialFlash_batchErase_W25Mxx_Large(uintptr_t* vAddrs, size_t AddrSize, int size_t addrTemp; unsigned char vInstruction[5]; //(5, mcode_SegmentErase) ; vInstruction[0] = mcode_SegmentErase; - - + rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = TRANSCEIVE; @@ -1984,28 +1982,27 @@ int SerialFlash_batchErase_W25Mxx_Large(uintptr_t* vAddrs, size_t AddrSize, int rq.Length = 5; for (i = 0; i < AddrSize; i++) { SerialFlash_waitForWEL(Index); - if (vAddrs[i]>=0x2000000) { - SerialFlash_doSelectDie(0x01,Index); - addrTemp = vAddrs[i] - 0x2000000; - } - else { - SerialFlash_doSelectDie(0x00,Index); - addrTemp = vAddrs[i]; + if (vAddrs[i] >= 0x2000000) { + SerialFlash_doSelectDie(0x01, Index); + addrTemp = vAddrs[i] - 0x2000000; + } else { + SerialFlash_doSelectDie(0x00, Index); + addrTemp = vAddrs[i]; } - //if (Chip_Info.ChipSizeInByte > 0x1000000) { - // MSB~ LSB (31...0) - vInstruction[1] = (unsigned char)((addrTemp >> 24) & 0xff); //MSB - vInstruction[2] = (unsigned char)((addrTemp >> 16) & 0xff); //M - vInstruction[3] = (unsigned char)((addrTemp >> 8) & 0xff); //M - vInstruction[4] = (unsigned char)(addrTemp & 0xff); //LSB - rq.Length = 5; - /* } else { - // MSB~ LSB (23...0) - vInstruction[1] = (unsigned char)((vAddrs[i] >> 16) & 0xff); //MSB - vInstruction[2] = (unsigned char)((vAddrs[i] >> 8) & 0xff); //M - vInstruction[3] = (unsigned char)(vAddrs[i] & 0xff); //LSB - rq.Length = 4; - }*/ + // if (Chip_Info.ChipSizeInByte > 0x1000000) { + // MSB~ LSB (31...0) + vInstruction[1] = (unsigned char)((addrTemp >> 24) & 0xff); // MSB + vInstruction[2] = (unsigned char)((addrTemp >> 16) & 0xff); // M + vInstruction[3] = (unsigned char)((addrTemp >> 8) & 0xff); // M + vInstruction[4] = (unsigned char)(addrTemp & 0xff); // LSB + rq.Length = 5; + /* } else { + // MSB~ LSB (23...0) + vInstruction[1] = (unsigned char)((vAddrs[i] >> 16) & 0xff); //MSB + vInstruction[2] = (unsigned char)((vAddrs[i] >> 8) & 0xff); //M + vInstruction[3] = (unsigned char)(vAddrs[i] & 0xff); //LSB + rq.Length = 4; + }*/ OutCtrlRequest(&rq, vInstruction, rq.Length, Index); SerialFlash_waitForWIP(Index); @@ -2019,7 +2016,7 @@ int SerialFlash_batchErase(uintptr_t* vAddrs, size_t AddrSize, int Index) { if (!SerialFlash_StartofOperation(Index)) return false; - + if (0 == mcode_SegmentErase) return 1; // chipErase code not initialised or not supported, please check chip class ctor.SerialFlash_waitForWEL @@ -2033,7 +2030,6 @@ int SerialFlash_batchErase(uintptr_t* vAddrs, size_t AddrSize, int Index) unsigned char vInstruction[5]; //(5, mcode_SegmentErase) ; vInstruction[0] = mcode_SegmentErase; - rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = TRANSCEIVE; @@ -2049,16 +2045,16 @@ int SerialFlash_batchErase(uintptr_t* vAddrs, size_t AddrSize, int Index) SerialFlash_waitForWEL(Index); if (Chip_Info.ChipSizeInByte > 0x1000000) { // MSB~ LSB (31...0) - vInstruction[1] = (unsigned char)((vAddrs[i] >> 24) & 0xff); //MSB - vInstruction[2] = (unsigned char)((vAddrs[i] >> 16) & 0xff); //M - vInstruction[3] = (unsigned char)((vAddrs[i] >> 8) & 0xff); //M - vInstruction[4] = (unsigned char)(vAddrs[i] & 0xff); //LSB + vInstruction[1] = (unsigned char)((vAddrs[i] >> 24) & 0xff); // MSB + vInstruction[2] = (unsigned char)((vAddrs[i] >> 16) & 0xff); // M + vInstruction[3] = (unsigned char)((vAddrs[i] >> 8) & 0xff); // M + vInstruction[4] = (unsigned char)(vAddrs[i] & 0xff); // LSB rq.Length = 5; } else { // MSB~ LSB (23...0) - vInstruction[1] = (unsigned char)((vAddrs[i] >> 16) & 0xff); //MSB - vInstruction[2] = (unsigned char)((vAddrs[i] >> 8) & 0xff); //M - vInstruction[3] = (unsigned char)(vAddrs[i] & 0xff); //LSB + vInstruction[1] = (unsigned char)((vAddrs[i] >> 16) & 0xff); // MSB + vInstruction[2] = (unsigned char)((vAddrs[i] >> 8) & 0xff); // M + vInstruction[3] = (unsigned char)(vAddrs[i] & 0xff); // LSB rq.Length = 4; } OutCtrlRequest(&rq, vInstruction, rq.Length, Index); @@ -2082,7 +2078,7 @@ int SerialFlash_rangeErase(unsigned char cmd, size_t sectionSize, struct CAddres // send request CNTRPIPE_RQ rq; - unsigned char vInstruction[5]; + unsigned char vInstruction[5]; vInstruction[0] = cmd; // instrcution format @@ -2108,16 +2104,16 @@ int SerialFlash_rangeErase(unsigned char cmd, size_t sectionSize, struct CAddres if (Chip_Info.ChipSizeInByte > 0x1000000) { // MSB~ LSB (31...0) - vInstruction[1] = (unsigned char)((addr >> 24) & 0xff); //MSB - vInstruction[2] = (unsigned char)((addr >> 16) & 0xff); //M - vInstruction[3] = (unsigned char)((addr >> 8) & 0xff); //M - vInstruction[4] = (unsigned char)(addr & 0xff); //LSB + vInstruction[1] = (unsigned char)((addr >> 24) & 0xff); // MSB + vInstruction[2] = (unsigned char)((addr >> 16) & 0xff); // M + vInstruction[3] = (unsigned char)((addr >> 8) & 0xff); // M + vInstruction[4] = (unsigned char)(addr & 0xff); // LSB rq.Length = (unsigned long)(5); } else { // MSB~ LSB (23...0) - vInstruction[1] = (unsigned char)((addr >> 16) & 0xff); //MSB - vInstruction[2] = (unsigned char)((addr >> 8) & 0xff); //M - vInstruction[3] = (unsigned char)(addr & 0xff); //LSB + vInstruction[1] = (unsigned char)((addr >> 16) & 0xff); // MSB + vInstruction[2] = (unsigned char)((addr >> 8) & 0xff); // M + vInstruction[3] = (unsigned char)(addr & 0xff); // LSB rq.Length = (unsigned long)(4); } @@ -2133,7 +2129,7 @@ int SerialFlash_rangeErase(unsigned char cmd, size_t sectionSize, struct CAddres } bool S70FSxxx_Large_chipErase(unsigned int Addr, unsigned int Length, int USBIndex) -{ +{ // wait until WIP = 0 S70FSxxx_Large_waitForWIP(true, USBIndex); @@ -2147,7 +2143,7 @@ bool S70FSxxx_Large_chipErase(unsigned int Addr, unsigned int Length, int USBInd vInstruction[4] = 0x00; FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 5, USBIndex); - S70FSxxx_Large_waitForWIP(true, USBIndex); //check die 1 + S70FSxxx_Large_waitForWIP(true, USBIndex); // check die 1 S70FSxxx_Large_Enable4ByteAddrMode(false, USBIndex); S70FSxxx_Large_waitForWIP(false, USBIndex); @@ -2161,27 +2157,27 @@ bool S70FSxxx_Large_chipErase(unsigned int Addr, unsigned int Length, int USBInd vInstruction[4] = 0x00; FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 5, USBIndex); - S70FSxxx_Large_waitForWIP(false, USBIndex); //check die 2 + S70FSxxx_Large_waitForWIP(false, USBIndex); // check die 2 return true; } bool W25Mxx_Large_chipErase(unsigned int Addr, unsigned int Length, int USBIndex) { - SerialFlash_doSelectDie(0x00,USBIndex); - + SerialFlash_doSelectDie(0x00, USBIndex); + SerialFlash_waitForWEL(USBIndex); unsigned char v = mcode_ChipErase; FlashCommand_SendCommand_OutOnlyInstruction(&v, 1, USBIndex); - SerialFlash_waitForWIP(USBIndex); + SerialFlash_waitForWIP(USBIndex); if (!SerialFlash_EndofOperation(USBIndex)) return false; - SerialFlash_doSelectDie(0x01,USBIndex); - + SerialFlash_doSelectDie(0x01, USBIndex); + SerialFlash_waitForWEL(USBIndex); FlashCommand_SendCommand_OutOnlyInstruction(&v, 1, USBIndex); - SerialFlash_waitForWIP(USBIndex); + SerialFlash_waitForWIP(USBIndex); if (!SerialFlash_EndofOperation(USBIndex)) return false; @@ -2219,13 +2215,13 @@ int SerialFlash_DieErase(int Index) { if (SerialFlash_protectBlock(false, Index) == SerialFlash_FALSE) return false; - SerialFlash_Enable4ByteAddrMode(true, Index); + SerialFlash_Enable4ByteAddrMode(true, Index); // send request unsigned char vInstruction[5]; int numOfRetry = 5; unsigned char re; - vInstruction[0] = mcode_ChipErase; + vInstruction[0] = mcode_ChipErase; size_t dieNum = ((strstr(Chip_Info.Class, "2Die") != NULL) ? 2 : 4); size_t die_size = Chip_Info.ChipSizeInByte / dieNum; @@ -2236,10 +2232,10 @@ int SerialFlash_DieErase(int Index) // MSB~ LSB (23...0) size_t addr = (i * die_size); // MSB~ LSB (31...0) - vInstruction[1] = (unsigned char)((addr >> 24) & 0xff); //MSB - vInstruction[2] = (unsigned char)((addr >> 16) & 0xff); //M - vInstruction[3] = (unsigned char)((addr >> 8) & 0xff); //M - vInstruction[4] = (unsigned char)(addr & 0xff); //LSB + vInstruction[1] = (unsigned char)((addr >> 24) & 0xff); // MSB + vInstruction[2] = (unsigned char)((addr >> 16) & 0xff); // M + vInstruction[3] = (unsigned char)((addr >> 8) & 0xff); // M + vInstruction[4] = (unsigned char)(addr & 0xff); // LSB int b = FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 5, Index); if ((b == SerialFlash_FALSE) || m_isCanceled) @@ -2257,13 +2253,13 @@ int SerialFlash_DieErase(int Index) } int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index) -{ +{ size_t i, j, divider; unsigned char* itr_begin; itr_begin = vData; switch (modeWrite) { - //transfer how many data each time + // transfer how many data each time case MODE_NUMONYX_PCM: case PP_32BYTE: divider = 9; @@ -2272,11 +2268,11 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* divider = 7; break; case PP_PROGRAM_ANYSIZE_PAGESIZE: - if(Chip_Info.PageSizeInByte == 0x200) + if (Chip_Info.PageSizeInByte == 0x200) divider = 9; - else if(Chip_Info.PageSizeInByte == 0x400) + else if (Chip_Info.PageSizeInByte == 0x400) divider = 10; - else + else divider = 8; break; default: @@ -2284,31 +2280,28 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* break; } - if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxS_Large) != NULL) - { + if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxS_Large) != NULL) { unsigned char cSR; - S25FSxxS_Large_doRDCF3V(&cSR, Index); - if((cSR & 0x10) == 0x10) + S25FSxxS_Large_doRDCF3V(&cSR, Index); + if ((cSR & 0x10) == 0x10) divider = 9; else divider = 8; } - + if (!SerialFlash_StartofOperation(Index)) return false; if (SerialFlash_protectBlock(false, Index) == SerialFlash_FALSE) return false; - + if (modeWrite != PP_SB_FPGA) SerialFlash_waitForWEL(Index); - + SerialFlash_Enable4ByteAddrMode(true, Index); if (SerialFlash_EnableQuadIO(true, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) return false; - - if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) - { + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) { struct CAddressRange down_range; struct CAddressRange range_temp; range_temp.start = AddrRange->start & 0xFF000000; @@ -2317,7 +2310,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* down_range.start = AddrRange->start; down_range.end = AddrRange->end; size_t packageNum; - size_t loop = (range_temp.end - range_temp.start) / 0x1000000; + size_t loop = (range_temp.end - range_temp.start) / 0x1000000; for (j = 0; j < loop; j++) { if (j == (loop - 1)) @@ -2331,7 +2324,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* down_range.start = (AddrRange->start & 0xFF000000) + (0x1000000 * j); down_range.length = down_range.end - down_range.start; - packageNum = down_range.length >> divider; + packageNum = down_range.length >> divider; 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); @@ -2343,7 +2336,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* } else { size_t packageNum = (AddrRange->end - AddrRange->start) >> divider; FlashCommand_SendCommand_SetupPacketForBulkWrite(AddrRange, modeWrite, WriteCom, 1 << divider, Chip_Info.AddrWidth, Index); - for (i = 0; i < packageNum; ++i) { + for (i = 0; i < packageNum; ++i) { BulkPipeWrite((unsigned char*)((itr_begin + (i << divider))), 1 << divider, USB_TIMEOUT, Index); if (m_isCanceled) return false; @@ -2365,36 +2358,35 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* } int SerialFlash_bulkPipeProgram_Micron_4Die(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index) -{ +{ size_t i, j, divider; unsigned char* itr_begin; - if (!SerialFlash_StartofOperation(Index)) - return false; - if (SerialFlash_protectBlock(false, Index) == SerialFlash_FALSE) - return false; - if (SerialFlash_EnableQuadIO(true, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) - return false; + if (!SerialFlash_StartofOperation(Index)) + return false; + if (SerialFlash_protectBlock(false, Index) == SerialFlash_FALSE) + return false; + if (SerialFlash_EnableQuadIO(true, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) + return false; - itr_begin = vData; + itr_begin = vData; divider = 8; unsigned char timeout = 3; unsigned char re = 0; - unsigned char EAR = (AddrRange->start & 0xFF000000)>>24; + unsigned char EAR = (AddrRange->start & 0xFF000000) >> 24; unsigned char preEAR = 0; - - do{ - CN25Qxxx_Large_4Die_WREAR(0,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - }while((re!=0)&&(timeout!=0)); - if(timeout == 0) - return false; - - if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) - { + + do { + CN25Qxxx_Large_4Die_WREAR(0, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + } while ((re != 0) && (timeout != 0)); + if (timeout == 0) + return false; + + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) { struct CAddressRange down_range; struct CAddressRange range_temp; range_temp.start = AddrRange->start & 0xFF000000; @@ -2403,7 +2395,7 @@ int SerialFlash_bulkPipeProgram_Micron_4Die(struct CAddressRange* AddrRange, uns down_range.start = AddrRange->start; down_range.end = AddrRange->end; size_t packageNum; - size_t loop = (range_temp.end - range_temp.start) / 0x1000000; + size_t loop = (range_temp.end - range_temp.start) / 0x1000000; for (j = 0; j < loop; j++) { if (j == (loop - 1)) @@ -2416,94 +2408,91 @@ int SerialFlash_bulkPipeProgram_Micron_4Die(struct CAddressRange* AddrRange, uns else down_range.start = (AddrRange->start & 0xFF000000) + (0x1000000 * j); - - timeout = 3; - re = 0; - EAR = (down_range.start & 0xFF000000)>>24; - if((EAR != preEAR)&&(EAR!=0)) { - do{ - CN25Qxxx_Large_4Die_WREAR(EAR,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - }while(((re&EAR)!=EAR)&&(timeout!=0)); - if(timeout == 0) - return false; - preEAR = EAR; - } - - down_range.end=down_range.end-(0x1000000*EAR); - down_range.start=down_range.start-(0x1000000*EAR); - - down_range.length = down_range.end - down_range.start; - packageNum = down_range.length >> divider; - - 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) - return false; + re = 0; + EAR = (down_range.start & 0xFF000000) >> 24; + if ((EAR != preEAR) && (EAR != 0)) { + do { + CN25Qxxx_Large_4Die_WREAR(EAR, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + } while (((re & EAR) != EAR) && (timeout != 0)); + if (timeout == 0) + return false; + preEAR = EAR; + } + + down_range.end = down_range.end - (0x1000000 * EAR); + down_range.start = down_range.start - (0x1000000 * EAR); + + down_range.length = down_range.end - down_range.start; + packageNum = down_range.length >> divider; + + 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) + return false; } itr_begin = itr_begin + (packageNum << divider); } - } else { + } else { struct CAddressRange down_range; - divider = 8; - - timeout = 3; - re = 0; - EAR = (AddrRange->start & 0xFF000000)>>24; - if((EAR != preEAR)&&(EAR!=0)) { - do{ - CN25Qxxx_Large_4Die_WREAR(EAR,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - preEAR = EAR; - }while(((re&EAR)!=EAR)&&(timeout!=0)); - if(timeout == 0) - return false; - } - - down_range.end=AddrRange->end-(0x1000000*EAR); - down_range.start=AddrRange->start-(0x1000000*EAR); + divider = 8; + + timeout = 3; + re = 0; + EAR = (AddrRange->start & 0xFF000000) >> 24; + if ((EAR != preEAR) && (EAR != 0)) { + do { + CN25Qxxx_Large_4Die_WREAR(EAR, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + preEAR = EAR; + } while (((re & EAR) != EAR) && (timeout != 0)); + if (timeout == 0) + return false; + } + + down_range.end = AddrRange->end - (0x1000000 * EAR); + down_range.start = AddrRange->start - (0x1000000 * EAR); size_t packageNum = (down_range.end - down_range.start) >> divider; FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index); - for (i = 0; i < packageNum; ++i) { + for (i = 0; i < packageNum; ++i) { BulkPipeWrite((unsigned char*)((itr_begin + (i << divider))), 1 << divider, USB_TIMEOUT, Index); if (m_isCanceled) return false; } } - - if (SerialFlash_protectBlock(m_bProtectAfterWritenErase, Index) == SerialFlash_FALSE) - return false; - if (SerialFlash_EnableQuadIO(false, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) - return false; - if (!SerialFlash_EndofOperation(Index)) - return false; + if (SerialFlash_protectBlock(m_bProtectAfterWritenErase, Index) == SerialFlash_FALSE) + return false; + if (SerialFlash_EnableQuadIO(false, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) + return false; + if (!SerialFlash_EndofOperation(Index)) + return false; return true; -} -bool SerialFlash_doSelectDie(unsigned char dieNum,int Index) -{ - if(SerialFlash_waitForWIP(Index)==false) - return false; +} +bool SerialFlash_doSelectDie(unsigned char dieNum, int Index) +{ + if (SerialFlash_waitForWIP(Index) == false) + return false; SerialFlash_waitForWEL(Index); - + unsigned char vInstruction[2]; vInstruction[0] = 0xC2; - vInstruction[1] = dieNum; + vInstruction[1] = dieNum; return FlashCommand_SendCommand_OutOnlyInstruction(vInstruction, 2, Index); } int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index) -{ +{ size_t i, j, divider; unsigned char* itr_begin; @@ -2515,20 +2504,18 @@ int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned if (modeWrite != PP_SB_FPGA) SerialFlash_waitForWEL(Index); - if (SerialFlash_EnableQuadIO(true, m_boEnWriteQuadIO, Index) == SerialFlash_FALSE) return false; - - itr_begin = vData; - divider = 8; + + itr_begin = vData; + divider = 8; struct CAddressRange down_range; struct CAddressRange range_temp; struct CAddressRange down_range_die2; - - if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) - { + + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) { struct CAddressRange range_temp_die2; range_temp.start = AddrRange->start & 0xFF000000; @@ -2537,10 +2524,9 @@ int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned down_range.start = AddrRange->start; down_range.end = AddrRange->end; size_t packageNum; - size_t loop = (range_temp.end - range_temp.start) / 0x1000000; + size_t loop = (range_temp.end - range_temp.start) / 0x1000000; - for (j = 0; j < loop; j++) - { + for (j = 0; j < loop; j++) { if (j == (loop - 1)) down_range.end = AddrRange->end; else @@ -2551,56 +2537,50 @@ int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned else down_range.start = (AddrRange->start & 0xFF000000) + (0x1000000 * j); - range_temp_die2.start = down_range.start; - range_temp_die2.end = down_range.end; - if(down_range.start>=0x2000000) - { - SerialFlash_doSelectDie(1,Index); - // wait until WIP = 0 - if(SerialFlash_waitForWIP(Index)==false) - return false; - SerialFlash_waitForWEL(Index); - - down_range_die2.start = range_temp_die2.start-0x2000000; - down_range_die2.end = range_temp_die2.end-0x2000000; - } - else - { - SerialFlash_doSelectDie(0,Index); - down_range_die2.start = down_range.start; - down_range_die2.end = down_range.end; - } + range_temp_die2.start = down_range.start; + range_temp_die2.end = down_range.end; + if (down_range.start >= 0x2000000) { + SerialFlash_doSelectDie(1, Index); + // wait until WIP = 0 + if (SerialFlash_waitForWIP(Index) == false) + return false; + SerialFlash_waitForWEL(Index); + + down_range_die2.start = range_temp_die2.start - 0x2000000; + down_range_die2.end = range_temp_die2.end - 0x2000000; + } else { + SerialFlash_doSelectDie(0, Index); + down_range_die2.start = down_range.start; + down_range_die2.end = down_range.end; + } down_range.length = down_range.end - down_range.start; - packageNum = down_range.length >> divider; - - FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range_die2, modeWrite, WriteCom, Chip_Info.PageSizeInByte,Chip_Info.AddrWidth, Index); + packageNum = down_range.length >> divider; + + FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range_die2, 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) return false; } - itr_begin = itr_begin + (packageNum << divider); + itr_begin = itr_begin + (packageNum << divider); + } + } else { + // struct CAddressRange down_range_die2; + if (AddrRange->start >= 0x2000000) { + SerialFlash_doSelectDie(1, Index); + down_range_die2.start = AddrRange->start - 0x2000000; + down_range_die2.end = AddrRange->end - 0x2000000; + + } else { + SerialFlash_doSelectDie(0, Index); + down_range_die2.start = AddrRange->start; + down_range_die2.end = AddrRange->end; } - } else { - //struct CAddressRange down_range_die2; - if(AddrRange->start>=0x2000000) - { - SerialFlash_doSelectDie(1,Index); - down_range_die2.start = AddrRange->start-0x2000000; - down_range_die2.end = AddrRange->end-0x2000000; - - } - else - { - SerialFlash_doSelectDie(0,Index); - down_range_die2.start = AddrRange->start; - down_range_die2.end = AddrRange->end; - } size_t packageNum = (AddrRange->end - AddrRange->start) >> divider; FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range_die2, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index); - for (i = 0; i < packageNum; ++i) { + for (i = 0; i < packageNum; ++i) { BulkPipeWrite((unsigned char*)((itr_begin + (i << divider))), 1 << divider, USB_TIMEOUT, Index); if (m_isCanceled) return false; @@ -2622,12 +2602,12 @@ int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned } 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)|| (g_bIsSF600PG2[Index] == true)))) + 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) || (g_bIsSF600PG2[Index] == true)))) SerialFlash_Enable4ByteAddrMode(true, Index); if (SerialFlash_EnableQuadIO(true, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) @@ -2636,9 +2616,9 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa AddrRange->length = AddrRange->end - AddrRange->start; if (AddrRange->length <= 0) return false; - + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) //(AddrRange.end>0x1000000 && AddrRange.start<0x1000000) - { + { struct CAddressRange read_range; struct CAddressRange range_temp; range_temp.start = AddrRange->start & 0xFF000000; @@ -2649,7 +2629,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)&& (g_bIsSF600PG2[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) && (g_bIsSF600PG2[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; @@ -2679,13 +2659,13 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa read_range.length = read_range.end - read_range.start; - pageNum = read_range.length >> 9; - FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); + pageNum = read_range.length >> 9; + FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); for (i = 0; i < pageNum; ++i) { - ret = BulkPipeRead(vData + (BufferLocation + i) * (1<<9), USB_TIMEOUT, Index); - if ((ret != (1<<9)) || m_isCanceled) + ret = BulkPipeRead(vData + (BufferLocation + i) * (1 << 9), USB_TIMEOUT, Index); + if ((ret != (1 << 9)) || m_isCanceled) return 0; - //memcpy(vData + (BufferLocation+i)*512, v, 512); + // memcpy(vData + (BufferLocation+i)*512, v, 512); } BufferLocation += pageNum; } @@ -2707,15 +2687,15 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa if (numOfRetry == 0) { return false; } - } + } pageNum = AddrRange->length >> 9; - FlashCommand_SendCommand_SetupPacketForBulkRead(AddrRange, modeRead, ReadCom,Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); + FlashCommand_SendCommand_SetupPacketForBulkRead(AddrRange, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + i * ret, USB_TIMEOUT, Index); - if ((ret != 512) || m_isCanceled) { + if ((ret != 512) || m_isCanceled) { return false; } - //memcpy(vData + i*ret, v, ret); + // memcpy(vData + i*ret, v, ret); } } if (SerialFlash_EnableQuadIO(false, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) @@ -2729,33 +2709,33 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa } int SerialFlash_bulkPipeRead_Micron_4die(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; + return false; if (SerialFlash_EnableQuadIO(true, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) return false; AddrRange->length = AddrRange->end - AddrRange->start; if (AddrRange->length <= 0) return false; - + unsigned char EAR = 0; unsigned char preEAR = 0; unsigned char timeout = 3; unsigned char re = 0; - do{ - CN25Qxxx_Large_4Die_WREAR(0,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - }while((re != 0)&&(timeout!=0)); - if(timeout == 0) - return false; - + do { + CN25Qxxx_Large_4Die_WREAR(0, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + } while ((re != 0) && (timeout != 0)); + if (timeout == 0) + return false; + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) //(AddrRange.end>0x1000000 && AddrRange.start<0x1000000) - { + { struct CAddressRange read_range; struct CAddressRange range_temp; range_temp.start = AddrRange->start & 0xFF000000; @@ -2766,7 +2746,6 @@ int SerialFlash_bulkPipeRead_Micron_4die(struct CAddressRange* AddrRange, unsign loop = (range_temp.end - range_temp.start) / 0x1000000; for (j = 0; j < loop; j++) { - if (j == (loop - 1)) read_range.end = AddrRange->end; @@ -2777,67 +2756,65 @@ int SerialFlash_bulkPipeRead_Micron_4die(struct CAddressRange* AddrRange, unsign read_range.start = AddrRange->start; else read_range.start = ((AddrRange->start & 0xFF000000) + (0x1000000 * j)); - timeout = 3; - re = 0; - EAR = (read_range.start & 0xFF000000)>>24; - if((EAR != preEAR)&&(EAR)) { - do{ - CN25Qxxx_Large_4Die_WREAR(EAR,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - }while(((re&EAR)!=EAR)&&(timeout!=0)); - if(timeout == 0) - return false; - preEAR = EAR; - } - - read_range.end=read_range.end-(0x1000000*EAR); - read_range.start=read_range.start-(0x1000000*EAR); + timeout = 3; + re = 0; + EAR = (read_range.start & 0xFF000000) >> 24; + if ((EAR != preEAR) && (EAR)) { + do { + CN25Qxxx_Large_4Die_WREAR(EAR, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + } while (((re & EAR) != EAR) && (timeout != 0)); + if (timeout == 0) + return false; + preEAR = EAR; + } + + read_range.end = read_range.end - (0x1000000 * EAR); + read_range.start = read_range.start - (0x1000000 * EAR); read_range.length = read_range.end - read_range.start; - pageNum = read_range.length >> 9; - FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); + pageNum = read_range.length >> 9; + FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); for (i = 0; i < pageNum; ++i) { - ret = BulkPipeRead(vData + (BufferLocation + i) * (1<<9), USB_TIMEOUT, Index); - if ((ret != (1<<9)) || m_isCanceled) + ret = BulkPipeRead(vData + (BufferLocation + i) * (1 << 9), USB_TIMEOUT, Index); + if ((ret != (1 << 9)) || m_isCanceled) return 0; - //memcpy(vData + (BufferLocation+i)*512, v, 512); + // memcpy(vData + (BufferLocation+i)*512, v, 512); } BufferLocation += pageNum; } } else { - - + struct CAddressRange read_range; - + timeout = 3; re = 0; - EAR = (read_range.start & 0xFF000000)>>24; - if((EAR != preEAR)&&(EAR)) { - do{ - CN25Qxxx_Large_4Die_WREAR(EAR,Index); - Sleep(1); - CN25Qxxx_Large_4Die_RDEAR(&re,Index); - timeout--; - }while(((re&EAR)!=EAR)&&(timeout!=0)); - if(timeout == 0) - return false; - preEAR = EAR; - } - - - read_range.end=AddrRange->end-(0x1000000*EAR); - read_range.start=AddrRange->start-(0x1000000*EAR); + EAR = (read_range.start & 0xFF000000) >> 24; + if ((EAR != preEAR) && (EAR)) { + do { + CN25Qxxx_Large_4Die_WREAR(EAR, Index); + Sleep(1); + CN25Qxxx_Large_4Die_RDEAR(&re, Index); + timeout--; + } while (((re & EAR) != EAR) && (timeout != 0)); + if (timeout == 0) + return false; + preEAR = EAR; + } + + read_range.end = AddrRange->end - (0x1000000 * EAR); + read_range.start = AddrRange->start - (0x1000000 * EAR); pageNum = read_range.length >> 9; - FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom,Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); + FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + i * ret, USB_TIMEOUT, Index); - if ((ret != 512) || m_isCanceled) { + if ((ret != 512) || m_isCanceled) { return false; } - //memcpy(vData + i*ret, v, ret); + // memcpy(vData + i*ret, v, ret); } } if (SerialFlash_EnableQuadIO(false, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) @@ -2851,34 +2828,33 @@ int SerialFlash_bulkPipeRead_Micron_4die(struct CAddressRange* AddrRange, unsign } int SerialFlash_bulkPipeRead_twoDie(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; + return false; if (SerialFlash_EnableQuadIO(true, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) return false; AddrRange->length = AddrRange->end - AddrRange->start; if (AddrRange->length <= 0) return false; - + if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) //(AddrRange.end>0x1000000 && AddrRange.start<0x1000000) - { - SerialFlash_Enable4ByteAddrMode(true, Index); + { + SerialFlash_Enable4ByteAddrMode(true, Index); struct CAddressRange read_range; struct CAddressRange range_temp; - struct CAddressRange range_die2; - struct CAddressRange range_die2_temp; + struct CAddressRange range_die2; + struct CAddressRange range_die2_temp; range_temp.start = AddrRange->start & 0xFF000000; range_temp.end = AddrRange->end + ((AddrRange->end % 0x1000000) ? (0x1000000 - (AddrRange->end % 0x1000000)) : 0); - loop = (range_temp.end - range_temp.start) / 0x1000000; - for (j = 0; j < loop; j++) { + for (j = 0; j < loop; j++) { if (j == (loop - 1)) read_range.end = AddrRange->end; else @@ -2891,61 +2867,53 @@ int SerialFlash_bulkPipeRead_twoDie(struct CAddressRange* AddrRange, unsigned ch read_range.length = read_range.end - read_range.start; - range_die2_temp.start=read_range.start; - range_die2_temp.end=read_range.end; + range_die2_temp.start = read_range.start; + range_die2_temp.end = read_range.end; - if(read_range.start>=0x2000000) - { - SerialFlash_doSelectDie(1,Index); + if (read_range.start >= 0x2000000) { + SerialFlash_doSelectDie(1, Index); - range_die2.start=range_die2_temp.start-0x2000000; - range_die2.end=range_die2_temp.end-0x2000000; + range_die2.start = range_die2_temp.start - 0x2000000; + range_die2.end = range_die2_temp.end - 0x2000000; - read_range.start=range_die2.start; - read_range.end=range_die2.end; - } - else - { - SerialFlash_doSelectDie(0,Index); - } + read_range.start = range_die2.start; + read_range.end = range_die2.end; + } else { + SerialFlash_doSelectDie(0, Index); + } pageNum = read_range.length >> 9; - FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom,Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); + FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + (BufferLocation + i) * 512, USB_TIMEOUT, Index); if ((ret != 512) || m_isCanceled) return 0; - //memcpy(vData + (BufferLocation+i)*512, v, 512); + // memcpy(vData + (BufferLocation+i)*512, v, 512); } BufferLocation += pageNum; } - } else { - struct CAddressRange range_die2; - - range_die2.length = AddrRange->end - AddrRange->start; - if(AddrRange->start>=0x2000000) - { - SerialFlash_doSelectDie(1,Index); - range_die2.start=AddrRange->start-0x2000000; - range_die2.end=AddrRange->end-0x2000000; - } - else - { - SerialFlash_doSelectDie(0,Index); - range_die2.start=AddrRange->start; - range_die2.end=AddrRange->end; - } - - pageNum = range_die2.length >> 9; - - FlashCommand_SendCommand_SetupPacketForBulkRead(&range_die2, modeRead, ReadCom,Chip_Info.AddrWidth,Chip_Info.ReadDummyLen, Index); - for (i = 0; i < pageNum; ++i) - { + } else { + struct CAddressRange range_die2; + + range_die2.length = AddrRange->end - AddrRange->start; + if (AddrRange->start >= 0x2000000) { + SerialFlash_doSelectDie(1, Index); + range_die2.start = AddrRange->start - 0x2000000; + range_die2.end = AddrRange->end - 0x2000000; + } else { + SerialFlash_doSelectDie(0, Index); + range_die2.start = AddrRange->start; + range_die2.end = AddrRange->end; + } + + pageNum = range_die2.length >> 9; + + FlashCommand_SendCommand_SetupPacketForBulkRead(&range_die2, modeRead, ReadCom, Chip_Info.AddrWidth, Chip_Info.ReadDummyLen, Index); + for (i = 0; i < pageNum; ++i) { ret = BulkPipeRead(vData + i * ret, USB_TIMEOUT, Index); - if ((ret != 512) || m_isCanceled) - { + if ((ret != 512) || m_isCanceled) { return false; } - //memcpy(vData + i*ret, v, ret); + // memcpy(vData + i*ret, v, ret); } } if (SerialFlash_EnableQuadIO(false, m_boEnReadQuadIO, Index) == SerialFlash_FALSE) diff --git a/SerialFlash.h b/SerialFlash.h old mode 100755 new mode 100644 index aece02e..9a543e2 --- a/SerialFlash.h +++ b/SerialFlash.h @@ -9,21 +9,21 @@ #define SerialFlash_FALSE -1 #define SerialFlash_TRUE 1 -enum //list of all chip-specific instruction, for ST serial flash +enum // list of all chip-specific instruction, for ST serial flash { WREN = 0x06, // Write Enable WRDI = 0x04, // Write Disable - RDIDJ = 0x9F, //RDIDJ // Read Jedec ID , except 80 + RDIDJ = 0x9F, // RDIDJ // Read Jedec ID , except 80 RDSR = 0x05, // Read Status Register WRSR = 0x01, // Write Status Register READ = 0x03, // Byte Read FREAD = 0x0B, // Fast Read PP = 0x02, // Page Program SE = 0xD8, // Sector Erase - CHIP_ERASE = 0xC7, //CHIP_ERASE // Bulk (or Chip) Erase + CHIP_ERASE = 0xC7, // CHIP_ERASE // Bulk (or Chip) Erase DP = 0xB9, // Deep Power Down - RDP = 0xAB, //RES // Release Deep Power Down - RES = 0xAB, //RES // RDP and read signature + RDP = 0xAB, // RES // Release Deep Power Down + RES = 0xAB, // RES // RDP and read signature RDSCUR = 0x2B, GBULK = 0x98, EN4B = 0xB7, @@ -53,7 +53,7 @@ int SerialFlash_Enable4ByteAddrMode(int bEnable, int Index); int SerialFlash_rangeBlankCheck(struct CAddressRange* Range, int Index); -int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vData, int Index); +int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vData, int Index); int SerialFlash_rangeRead(struct CAddressRange* AddrRange, unsigned char* vData, int Index); int SerialFlash_DoPolling(int Index); @@ -69,7 +69,7 @@ int SerialFlash_DieErase(int Index); int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index); -int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index); +int SerialFlash_bulkPipeProgram_twoDie(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeWrite, unsigned char WriteCom, int Index); int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeRead, unsigned char ReadCom, int Index); @@ -78,7 +78,7 @@ int SerialFlash_bulkPipeRead_Micron_4die(struct CAddressRange* AddrRange, unsign int SerialFlash_bulkPipeRead_twoDie(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeRead, unsigned char ReadCom, int Index); int SerialFlash_bulkPipeProgram_Micron_4Die(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeRead, unsigned char ReadCom, int Index); -bool SerialFlash_doSelectDie(unsigned char dieNum,int Index); +bool SerialFlash_doSelectDie(unsigned char dieNum, int Index); void SerialFlash_SetCancelOperationFlag(); void SerialFlash_ClearCancelOperationFlag(); @@ -101,11 +101,11 @@ bool CN25Qxxx_Large_doWRVCR(unsigned char ucVCR, int Index); bool CN25Qxxx_Large_doRDENVCR(unsigned char* ucENVCR, int Index); bool CN25Qxxx_Large_doWRENVCR(unsigned char ucENVCR, int Index); bool CS25FLxx_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index); -bool CN25Qxxx_Large_4Die_WREAR(unsigned char cSR,int Index); -bool CN25Qxxx_Large_4Die_RDEAR(unsigned char* cEAR,int Index); +bool CN25Qxxx_Large_4Die_WREAR(unsigned char cSR, int Index); +bool CN25Qxxx_Large_4Die_RDEAR(unsigned char* cEAR, int Index); size_t GetChipSize(void); size_t GetPageSize(void); bool SerialFlash_StartofOperation(int Index); bool SerialFlash_EndofOperation(int Index); -#endif //SERIALFLASHS +#endif // SERIALFLASHS diff --git a/board.c b/board.c old mode 100755 new mode 100644 index d799cbe..557e78a --- a/board.c +++ b/board.c @@ -7,9 +7,9 @@ #define SerialFlash_TRUE 1 #define min(a, b) (a > b ? b : a) -volatile bool g_bIsSF600[16] = {false}; -volatile bool g_bIsSF700[16] = {false}; -volatile bool g_bIsSF600PG2[16] = {false}; +volatile bool g_bIsSF600[16] = { false }; +volatile bool g_bIsSF700[16] = { false }; +volatile bool g_bIsSF600PG2[16] = { false }; extern char g_board_type[8]; extern char g_FPGA_ver[8]; extern char g_FW_ver[10]; @@ -34,30 +34,29 @@ bool ReadSF700AndSF600PG2SN(unsigned char* Data, int Index) rq.Index = 0; rq.Length = 6; + vBuffer[0] = 0; + vBuffer[1] = 0; + vBuffer[2] = 0; + vBuffer[3] = 2; + vBuffer[4] = 0; + vBuffer[5] = 0; - vBuffer[0]=0; - vBuffer[1]=0; - vBuffer[2]=0; - vBuffer[3]=2; - vBuffer[4]=0; - vBuffer[5]=0; - - //must read twice + // must read twice if (OutCtrlRequest(&rq, vBuffer, 6, Index) == SerialFlash_FALSE) return false; - //first + // first unsigned char vBufferSN[512]; BulkPipeRead(vBufferSN, USB_TIMEOUT, Index); if (OutCtrlRequest(&rq, vBuffer, 6, Index) == SerialFlash_FALSE) return false; - //second + // second BulkPipeRead(vBufferSN, USB_TIMEOUT, Index); memcpy(Data, vBufferSN, 16); return true; } - bool ReadOnBoardFlash(unsigned char* Data, bool ReadUID, int Index) +bool ReadOnBoardFlash(unsigned char* Data, bool ReadUID, int Index) { CNTRPIPE_RQ rq; unsigned char vBuffer[16]; @@ -111,7 +110,7 @@ void QueryBoard(int Index) unsigned int GetFPGAVersion(int Index) { - if ((strstr(g_board_type, "SF600PG2") == NULL)&& (strstr(g_board_type, "SF600") == NULL) && (strstr(g_board_type, "SF700") == NULL)) + if ((strstr(g_board_type, "SF600PG2") == NULL) && (strstr(g_board_type, "SF600") == NULL) && (strstr(g_board_type, "SF700") == NULL)) return -1; CNTRPIPE_RQ rq; @@ -179,7 +178,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); + // printf("\n===>board.c ---- SetLEDProgBoard(Color=%ld,SetLEDProgBoard=%d)\n",Color,Index); if (!Is_usbworking(Index)) { return false; } @@ -193,7 +192,7 @@ bool SetLEDProgBoard(size_t Color, int Index) 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.Value = (Color & 0xFFF7) | (g_IO1Select << 1) | (g_IO4Select << 3); rq.Index = 0; } else { rq.Value = 0x09; @@ -265,7 +264,7 @@ bool SetCS(size_t value, int Index) } bool SetIOModeToSF600(size_t value, int Index) -{ +{ if (!Is_usbworking(Index)) { return false; } @@ -347,7 +346,7 @@ bool SetSPIClockValue(unsigned short v, int Index) bool SetIOMOdeValue(int Index) { if (strstr(g_board_type, "SF100")) - return true; + return true; if (!Is_usbworking(Index)) return false; @@ -357,7 +356,7 @@ bool SetIOMOdeValue(int Index) rq.Function = URB_FUNCTION_VENDOR_ENDPOINT; rq.Direction = VENDOR_DIRECTION_OUT; rq.Request = SET_IOMODE; - rq.Value = 0;//single IO + rq.Value = 0; // single IO rq.Index = RFU; rq.Length = 0; @@ -379,13 +378,11 @@ unsigned int ReadUID(int Index) if (ReadSF700AndSF600PG2SN(vUID, Index) == false) return false; - - dwUID = (unsigned int)vUID[2] << 16 | (unsigned int)vUID[1] << 8 | vUID[0]; + dwUID = (unsigned int)vUID[2] << 16 | (unsigned int)vUID[1] << 8 | vUID[0]; return dwUID; - } - if ((g_bIsSF600[Index] == true) ) { + if ((g_bIsSF600[Index] == true)) { if (ReadOnBoardFlash(vUID, false, Index) == false) return false; if (g_bIsSF600[Index] == true) @@ -795,9 +792,9 @@ bool GetFirmwareVer(int Index) CNTRPIPE_RQ rq; unsigned char vBuffer[32]; - unsigned int BufferSize =32; + unsigned int BufferSize = 32; - if((g_bIsSF600[Index] == false) && (is_SF700_Or_SF600PG2(Index) == false)) + if ((g_bIsSF600[Index] == false) && (is_SF700_Or_SF600PG2(Index) == false)) BufferSize = 16; // first control packet @@ -818,13 +815,10 @@ bool GetFirmwareVer(int Index) memcpy(g_board_type, &vBuffer[0], 8); - if (strstr(g_board_type, "SF600PG2") != NULL) - { - memcpy(g_FW_ver, &vBuffer[12], 9); + if (strstr(g_board_type, "SF600PG2") != NULL) { + memcpy(g_FW_ver, &vBuffer[12], 9); memcpy(g_HW_ver, &vBuffer[25], 5); - } - else - { + } else { memcpy(g_FW_ver, &vBuffer[10], 7); if (strstr(g_board_type, "SF600") != NULL) memcpy(g_HW_ver, &vBuffer[20], 4); @@ -832,7 +826,6 @@ bool GetFirmwareVer(int Index) memcpy(g_HW_ver, &vBuffer[21], 4); } - return true; } diff --git a/board.h b/board.h old mode 100755 new mode 100644 diff --git a/dpcmd.c b/dpcmd.c index ec4d1cd..67eaf65 100644 --- a/dpcmd.c +++ b/dpcmd.c @@ -22,7 +22,7 @@ extern unsigned int g_uiFileChecksum; extern unsigned long g_ulFileSize; extern volatile bool g_bIsSF600[16]; extern volatile bool g_bIsSF700[16]; -extern volatile bool g_bIsSF600PG2[16]; +extern volatile bool g_bIsSF600PG2[16]; extern unsigned char g_BatchIndex; unsigned int g_Vcc = vcc3_5V; @@ -35,7 +35,7 @@ unsigned int g_uiTimeout = 10000; 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; @@ -69,7 +69,7 @@ char* g_parameter_type = "\0"; char* g_parameter_timeout = "300"; char* g_parameter_target = "1"; char* g_parameter_vcc = "NO"; -//char* g_parameter_spi_clk="2"; +// char* g_parameter_spi_clk="2"; char* g_parameter_blink = "0"; char* g_parameter_fw = "\0"; @@ -99,14 +99,14 @@ bool g_bDisplayTimer = true; bool isSendFFsequence = false; /* only print timing progress info if this many seconds ellapsed * before the last time we did */ -//static float g_tv_display_delta_s = 0.5; +// static float g_tv_display_delta_s = 0.5; -//char* const short_options = "?Ldber:p:u:sf:I:R:a:l:vx:T:S:N:B:D:F:V:t:g:c:POik:"; -//static const char* msg_info_unknownoption= "\nError: illegal option."; -//static const char* msg_err_lengthoverflow_abortion= "\nError: Length parameter exceeding file size, operation aborted\n"; -//static const char* msg_err_addroverflow_abortion = "\nError: Exceeding chip size, operation aborted\n"; -//static const char* msg_warning_optionignore_al = "\nWarning: either --addr or --length cannot be used with --auto, will be ignored\n"; -//static const char* msg_err_openfile = "Error: Failed to open file.\n"; +// char* const short_options = "?Ldber:p:u:sf:I:R:a:l:vx:T:S:N:B:D:F:V:t:g:c:POik:"; +// static const char* msg_info_unknownoption= "\nError: illegal option."; +// static const char* msg_err_lengthoverflow_abortion= "\nError: Length parameter exceeding file size, operation aborted\n"; +// static const char* msg_err_addroverflow_abortion = "\nError: Exceeding chip size, operation aborted\n"; +// static const char* msg_warning_optionignore_al = "\nWarning: either --addr or --length cannot be used with --auto, will be ignored\n"; +// static const char* msg_err_openfile = "Error: Failed to open file.\n"; static const char* msg_err_communication = "Error: USB communication error or configuration file missing.\n"; static const char* msg_err_identifychip = "Error: chip not identified or chip is not supported.\n"; @@ -488,7 +488,7 @@ int GetConfigVer() int main(int argc, char* argv[]) { -#if 0 //Check all USB device capability //evy test SF700 +#if 0 // Check all USB device capability //evy test SF700 Check(argc,argv); return; @@ -556,11 +556,10 @@ int main(int argc, char* argv[]) " DPCMD_DEVNUM\n"); return 1; } - g_uiDevNum = (unsigned char)r; - bDevice = true; + g_uiDevNum = (unsigned char)r; + bDevice = true; } - if (OpenUSB() == 0) iExitCode = EXCODE_FAIL_USB; @@ -595,29 +594,29 @@ int main(int argc, char* argv[]) break; case 'p': g_parameter_program = optarg; - g_ucOperation |= PROGRAM; + g_ucOperation |= PROGRAM; break; case 'u': g_parameter_auto = optarg; g_ucOperation |= BATCH; - g_BatchIndex = 2; + g_BatchIndex = 2; break; case 'z': g_parameter_batch = optarg; g_ucOperation |= BATCH; - g_BatchIndex = 1; + g_BatchIndex = 1; break; case 's': // display chip checksum g_ucOperation |= CSUM; break; - case 'f': //display file checksum + case 'f': // display file checksum g_parameter_fsum = optarg; g_ucOperation |= FSUM; break; case 'I': g_parameter_raw = optarg; break; - case 'R': //raw-require-return + case 'R': // raw-require-return g_parameter_raw_return = optarg; break; /* Optional Switches that add fine-tune ability to Basic Switches: */ @@ -641,15 +640,15 @@ int main(int argc, char* argv[]) sscanf(optarg, "%x", &g_ucFill); break; case 'T': - g_parameter_type = optarg; //type + g_parameter_type = optarg; // type break; - case 'S': //lock start + case 'S': // lock start sscanf(optarg, "%x", &g_uiLockStart); // l_opt_arg = optarg; // printf("hexadecimal starting address (with arg: %s)\n", l_opt_arg); break; - case 'N': //lock length - sscanf(optarg, "%x", &g_uiLockLen); + case 'N': // lock length + sscanf(optarg, "%x", &g_uiLockLen); break; case 'B': sscanf(optarg, "%d", &g_uiBlink); @@ -661,7 +660,7 @@ int main(int argc, char* argv[]) break; case 'X': // device-SN l_opt_arg = optarg; - //printf("activate only the programmer connected to USBx (with arg: %s)\n", l_opt_arg); + // printf("activate only the programmer connected to USBx (with arg: %s)\n", l_opt_arg); bDeviceSN = true; break; @@ -670,11 +669,11 @@ int main(int argc, char* argv[]) // printf("Fix programmer serial number with programmer sequence. (with arg: %s)\n", l_opt_arg); // break; g_parameter_loadfile_with_verify = optarg; - g_ucOperation |= LOADFILEWITHVERIFY; + g_ucOperation |= LOADFILEWITHVERIFY; break; case 'V': sscanf(optarg, "%d", &g_uiDeviceID); - g_ucOperation |= DEVICE_ID; //list device id + g_ucOperation |= DEVICE_ID; // list device id break; /* Miscellaneous options: */ case 't': @@ -692,7 +691,7 @@ int main(int argc, char* argv[]) case 'P': g_bEnableVpp = true; break; - case 'O': //Log file + case 'O': // Log file strcpy(g_LogPath, optarg); // printf("%s\n",g_LogPath); break; @@ -774,11 +773,11 @@ int main(int argc, char* argv[]) } int dwUID = ReadUID(g_uiDevNum - 1); if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { - if (g_bIsSF700[g_uiDevNum - 1] == true) { + if (g_bIsSF700[g_uiDevNum - 1] == true) { printf("\nDevice %d (SF7%05d):\tdetecting chip\n", g_uiDevNum, dwUID); } else if (g_bIsSF600PG2[g_uiDevNum - 1] == true) { printf("\nDevice %d (S6B%05d):\tdetecting chip\n", g_uiDevNum, dwUID); - } + } } else if ((g_bIsSF600[g_uiDevNum - 1] == true) && (dwUID / 600000) > 0) { printf("\nDevice %d (SF%06d):\tdetecting chip\n", g_uiDevNum, dwUID); } else if ((dwUID / 100000) > 0) { @@ -802,15 +801,15 @@ int main(int argc, char* argv[]) } } else { for (int i = 0; i < dev_cnt; i++) { - //printf("%s\n",g_LogPath); + // printf("%s\n",g_LogPath); int dwUID = ReadUID(i); if (is_SF700_Or_SF600PG2(i)) { - if (g_bIsSF700[i] == true) { + if (g_bIsSF700[i] == true) { printf("\nDevice %d (SF7%05d):\tdetecting chip\n", i + 1, dwUID); } else if (g_bIsSF600PG2[i] == true) { printf("\nDevice %d (S6B%05d):\tdetecting chip\n", i + 1, dwUID); - } + } } else if ((g_bIsSF600[i] == true) && (dwUID / 600000) > 0) { printf("\nDevice %d (SF%06d):\tdetecting chip\n", i + 1, dwUID); } else if ((dwUID / 100000) > 0) { @@ -840,7 +839,7 @@ int main(int argc, char* argv[]) Chip_Info = GetFirstDetectionMatch(strTypeName, g_uiDevNum - 1); if (Chip_Info.UniqueID != 0) { - //printf("strlen(strTypeName)=%ld\n",strlen(strTypeName)); + // 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); @@ -1141,7 +1140,7 @@ int Handler(void) if (!InitProject()) return EXCODE_FAIL_OTHERS; - //my_timer t; // opertion timer + // my_timer t; // opertion timer if (ListTypes()) return EXCODE_PASS; @@ -1171,7 +1170,7 @@ int Handler(void) bool InitProject(void) { - //printf("bool InitProject(void)\n"); + // printf("bool InitProject(void)\n"); int dev_cnt = get_usb_dev_cnt(); if (Is_usbworking(0)) { int targets[4] = { @@ -1188,7 +1187,7 @@ bool InitProject(void) SetSPIIOMode(i); SetSPIClock(i); SetVcc(i); - SetVppVoltage(0,i); + SetVppVoltage(0, i); if (strlen(g_parameter_type) > 0) { if (Dedi_Search_Chip_Db_ByTypeName(g_parameter_type, &Chip_Info)) { @@ -1209,10 +1208,10 @@ bool InitProject(void) } else if (g_uiDevNum <= dev_cnt) { g_StartupMode = targets[g_ucTarget]; SetTargetFlash((unsigned char)targets[g_ucTarget], g_uiDevNum - 1); - SetSPIIOMode(g_uiDevNum - 1); + SetSPIIOMode(g_uiDevNum - 1); SetSPIClock(g_uiDevNum - 1); SetVcc(g_uiDevNum - 1); - SetVppVoltage(0,g_uiDevNum - 1); + SetVppVoltage(0, g_uiDevNum - 1); if (strlen(g_parameter_type) > 0) { if (Dedi_Search_Chip_Db_ByTypeName(g_parameter_type, &Chip_Info)) { @@ -1229,9 +1228,9 @@ bool InitProject(void) } } else printf("Error: Did not find the programmer.\n"); - + return true; - } + } return false; } @@ -1300,7 +1299,7 @@ void SetSPIClock(int Index) } void SetVcc(int Index) -{ +{ if (!(g_Vcc <= 3800 && g_Vcc >= 1800 && ((g_bIsSF600[Index] == true) || is_SF700_Or_SF600PG2(Index)))) g_Vcc = (0x10 | (g_Vcc & 0x03)); } @@ -1388,10 +1387,10 @@ bool CheckProgrammerInfo(void) int dev_cnt = get_usb_dev_cnt(); unsigned int uiFPGAVer = 0; if (g_uiDevNum == 0) { - for (int i = 0; i < dev_cnt; i++) { - int dwUID = ReadUID(i); + for (int i = 0; i < dev_cnt; i++) { + int dwUID = ReadUID(i); if (is_SF700_Or_SF600PG2(i)) { - if (g_bIsSF700[i] == true) + if (g_bIsSF700[i] == true) printf("%d,\tSF7%05d\n", i + 1, dwUID); else if (g_bIsSF600PG2[i] == true) printf("%d,\tS6B%05d\n", i + 1, dwUID); @@ -1401,9 +1400,9 @@ bool CheckProgrammerInfo(void) printf("%d,\tSF%06d\n", i + 1, dwUID); else printf("%d,\tDP%06d\n", i + 1, dwUID); - - uiFPGAVer = GetFPGAVersion(i); - GetFirmwareVer(i); + + uiFPGAVer = GetFPGAVersion(i); + GetFirmwareVer(i); if (g_bIsSF600[i]) { if (CheckSDCard(i)) printf(" Programmer type : SF600Plus\n"); @@ -1412,8 +1411,8 @@ bool CheckProgrammerInfo(void) 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 (is_SF700_Or_SF600PG2(i)){ - if (g_bIsSF700[i]) { + } else if (is_SF700_Or_SF600PG2(i)) { + if (g_bIsSF700[i]) { printf(" Programmer type : SF700\n"); printf(" Firmware version : %s\n", g_FW_ver); printf(" FPGA version : 0x%04x\n", uiFPGAVer); @@ -1424,7 +1423,7 @@ bool CheckProgrammerInfo(void) printf(" FPGA version : 0x%04x\n", uiFPGAVer); printf(" Hardware version : %s\n", g_HW_ver); } - } else //SF100 + } else // SF100 { printf(" Programmer type : SF100\n"); printf(" Firmware version : %s\n", g_FW_ver); @@ -1434,7 +1433,7 @@ bool CheckProgrammerInfo(void) } } else { int dwUID = ReadUID(g_uiDevNum - 1); - if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { + if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { if (g_bIsSF700[g_uiDevNum - 1] == true) { printf("\nDevice %d (SF7%05d):\n", g_uiDevNum, dwUID); } else if (g_bIsSF600PG2[g_uiDevNum - 1] == true) { @@ -1458,7 +1457,7 @@ bool CheckProgrammerInfo(void) printf(" FPGA version : 0x%x\n", uiFPGAVer); printf(" Hardware version : %s\n", g_HW_ver); } else if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { - if (g_bIsSF700[g_uiDevNum - 1]) { + if (g_bIsSF700[g_uiDevNum - 1]) { printf(" Programmer type : SF700\n"); } else if (g_bIsSF600PG2[g_uiDevNum - 1]) { printf(" Programmer type : SF600Plus-G2\n"); @@ -1466,7 +1465,7 @@ bool CheckProgrammerInfo(void) 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 + } else { // SF100 printf(" Programmer type : SF100\n"); printf(" Firmware version : %s\n", g_FW_ver); printf(" FPGA version : N.A.\n"); @@ -1527,7 +1526,7 @@ void ListSFSerialID(void) if (g_uiDeviceID < 1) { for (unsigned int i = 0; i < dev_cnt; i++) { dwUID = ReadUID(i); - if (is_SF700_Or_SF600PG2(i)) { + if (is_SF700_Or_SF600PG2(i)) { if (g_bIsSF700[i] == true) printf("%d,\tSF7%05d\n", i + 1, dwUID); else if (g_bIsSF600PG2[i] == true) @@ -1544,12 +1543,12 @@ void ListSFSerialID(void) printf("The number of programmer is not defined!\n"); else { dwUID = ReadUID(g_uiDeviceID - 1); - if (is_SF700_Or_SF600PG2(g_uiDeviceID - 1)) { + if (is_SF700_Or_SF600PG2(g_uiDeviceID - 1)) { if (g_bIsSF700[g_uiDeviceID - 1] == true) printf("%d,\tSF7%05d\n", g_uiDeviceID, dwUID); else if (g_bIsSF600PG2[g_uiDeviceID - 1] == true) printf("%d,\tS6B%05d\n", g_uiDeviceID, dwUID); - } else if ((g_bIsSF600[g_uiDeviceID - 1] == true) && (dwUID / 600000) > 0) + } else if ((g_bIsSF600[g_uiDeviceID - 1] == true) && (dwUID / 600000) > 0) printf("%d,\tSF%06d\n", g_uiDeviceID, dwUID); else if ((dwUID / 100000) > 0) printf("%d,\tSF%06d\n", g_uiDeviceID, dwUID); @@ -1578,7 +1577,7 @@ void do_Erase(void) void do_Program(void) { if (!do_loadFile()) - return; + return; SaveProgContextChanges(); printf("%s\n", msg_info_programming); @@ -1648,7 +1647,7 @@ void do_DisplayOrSave(void) strcat(SourceStr, ExtStr); } else { sprintf(ExtStr, "%s", &SourceStr[0]); - //printf("\n 2ExtStr= %s",ExtStr); + // printf("\n 2ExtStr= %s",ExtStr); char str[64]; sprintf(str, "_%d", icnt + 1); @@ -1782,13 +1781,13 @@ void do_RawInstructions(int Index) strcpy(parameter, g_parameter_raw); TurnONVcc(Index); pch[i] = strtok(parameter, "|"); - while (pch[i] != NULL) { + while (pch[i] != NULL) { i++; pch[i] = strtok(NULL, "|"); } - if (strlen(g_parameter_raw_return) > 0) { - + if (strlen(g_parameter_raw_return) > 0) { + sscanf(g_parameter_raw_return, "%hhu", &Length); strcpy(retrunParameter, g_parameter_raw_return); @@ -1804,7 +1803,7 @@ void do_RawInstructions(int Index) } } - for (int j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { do_RawInstructinos_2(pchReturn[j], pch[j], Index); } } @@ -1834,8 +1833,8 @@ bool Erase(void) bool Program(void) { - if (g_ucOperation & PROGRAM) - do_Program(); + if (g_ucOperation & PROGRAM) + do_Program(); return g_bStatus; } @@ -1850,8 +1849,8 @@ bool Read(void) bool Auto(void) { - if (g_ucOperation & BATCH) - do_Auto(); + if (g_ucOperation & BATCH) + do_Auto(); return g_bStatus; } @@ -1859,8 +1858,8 @@ bool LoadFileWithVerify(void) { if (g_ucOperation & LOADFILEWITHVERIFY) { do_loadFileWithVerify(); - if (g_bStatus) - do_Verify(); + if (g_bStatus) + do_Verify(); } return g_bStatus; } @@ -1885,7 +1884,7 @@ bool CalChecksum(void) for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); if (g_uiAddr == 0 && g_uiLen == 0) { - if (is_SF700_Or_SF600PG2(i)) { + if (is_SF700_Or_SF600PG2(i)) { if (g_bIsSF700[i] == true) printf("\nDevice %d (SF7%05d):", i + 1, dwUID); else if (g_bIsSF600PG2[i] == true) @@ -1900,7 +1899,7 @@ 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 (is_SF700_Or_SF600PG2(i)) { - if (g_bIsSF700[i] == true) + if (g_bIsSF700[i] == true) printf("\nDevice %d (SF7%05d):", i + 1, ReadUID(i)); else if (g_bIsSF600PG2[i] == true) printf("\nDevice %d (S6B%05d):", i + 1, ReadUID(i)); @@ -1917,7 +1916,7 @@ bool CalChecksum(void) } else if (g_uiDevNum != 0) { int dwUID = ReadUID(g_uiDevNum - 1); if (g_uiAddr == 0 && g_uiLen == 0) { - if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { + if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { if (g_bIsSF700[g_uiDevNum - 1] == true) printf("\nDevice %d (SF7%05d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); else if (g_bIsSF600PG2[g_uiDevNum - 1] == true) @@ -1931,7 +1930,7 @@ 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[g_uiDevNum - 1], Chip_Info.ChipSizeInByte)); } else { - if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { + if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { if (g_bIsSF700[g_uiDevNum - 1] == true) printf("\nDevice %d (SF7%05d):", g_uiDevNum, ReadUID(g_uiDevNum - 1)); else if (g_bIsSF600PG2[g_uiDevNum - 1] == true) @@ -1980,12 +1979,12 @@ bool Wait(const char* strOK, const char* strFail) } } printf("\n"); - if (g_uiDevNum == 0) //mutiple + if (g_uiDevNum == 0) // mutiple { for (int i = 0; i < dev_cnt; i++) { int dwUID = ReadUID(i); if (is_SF700_Or_SF600PG2(i)) { - if (g_bIsSF700[i] == true) + if (g_bIsSF700[i] == true) printf("\nDevice %d (SF7%05d):", i + 1, dwUID); else if (g_bIsSF600PG2[i] == true) printf("\nDevice %d (S6B%05d):", i + 1, dwUID); @@ -2001,7 +2000,7 @@ bool Wait(const char* strOK, const char* strFail) } else if (g_uiDevNum <= dev_cnt) { int dwUID = ReadUID(g_uiDevNum - 1); if (is_SF700_Or_SF600PG2(g_uiDevNum - 1)) { - if (g_bIsSF700[g_uiDevNum - 1] == true) + if (g_bIsSF700[g_uiDevNum - 1] == true) printf("\nDevice %d (SF7%05d):", g_uiDevNum, dwUID); else if (g_bIsSF600PG2[g_uiDevNum - 1] == true) printf("\nDevice %d (S6B%05d):", g_uiDevNum, dwUID); @@ -2016,7 +2015,7 @@ bool Wait(const char* strOK, const char* strFail) g_bStatus = g_is_operation_successful[g_uiDevNum - 1]; } return g_bStatus; -} +} int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) { @@ -2045,7 +2044,7 @@ int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) strcpy(strTypeName, TypeName); if (rc && (search_all == 0)) { if (c == 1) - isSendFFsequence = true; + isSendFFsequence = true; return rc; } } @@ -2059,7 +2058,7 @@ int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) isSendFFsequence = true; return rc; } - } + } } UniqueID = 0; @@ -2110,6 +2109,6 @@ int FlashIdentifier(CHIP_INFO* Chip_Info, int search_all, int Index) rc = Dedi_Search_Chip_Db(TypeName, 0x90, UniqueID, Chip_Info, search_all); if (rc && (search_all == 0)) return rc; - } + } return rc; -} +} diff --git a/dpcmd.h b/dpcmd.h old mode 100755 new mode 100644 index dafe9ad..02c58a3 --- a/dpcmd.h +++ b/dpcmd.h @@ -51,7 +51,7 @@ void SetVpp(int Index); void SetSPIIOMode(int Index); void SetSPIClock(int Index); void SetVcc(int Index); -int SetVppVoltage(int vol,int Index); +int SetVppVoltage(int vol, int Index); int do_loadFile(void); int do_loadFileWithVerify(void); void BlinkProgrammer(void); diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..34e496b --- /dev/null +++ b/meson.build @@ -0,0 +1,28 @@ +project('dpcmd', 'c', + license : 'GPL-2.0', + version : '1.14.21', + default_options: { + 'optimization': 'O2', + + } +) + +sources = files( + 'board.c', + 'dpcmd.c', + 'FlashCommand.c', + 'IntelHexFile.c', + 'MotorolaFile.c', + 'parse.c', + 'project.c', + 'SerialFlash.c', + 'usbdriver.c', +) + +libusb = dependency('libusb-1.0', version : '>=1.0.0') +pthreads = dependency('threads') + +executable('dpcmd', + sources, + dependencies : [libusb, pthreads], +) \ No newline at end of file diff --git a/parse.c b/parse.c old mode 100755 new mode 100644 index d119979..9130681 --- a/parse.c +++ b/parse.c @@ -11,8 +11,8 @@ #define min(a, b) (((a) > (b)) ? (b) : (a)) #define max(a, b) (((a) > (b)) ? (a) : (b)) -//using namespace pugi; -//xml_document doc; +// using namespace pugi; +// xml_document doc; FILE* openChipInfoDb(void) { @@ -35,8 +35,8 @@ FILE* openChipInfoDb(void) } } - //xml_parse_result result = doc.load_file( Path ); - //if ( result.status != xml_parse_status::status_ok ) + // xml_parse_result result = doc.load_file( Path ); + // if ( result.status != xml_parse_status::status_ok ) // return; return fp; @@ -50,13 +50,13 @@ long fsize(FILE* fp) fseek(fp, prev, SEEK_SET); // go back to where we were return sz; } - + int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, long UniqueID, CHIP_INFO* Chip_Info, int search_all) { - + FILE* fp; /*Declare file pointer variable*/ int found_flag = 0; char file_line_buf[linebufsize], *tok, *file_buf, test[testbufsize]; @@ -71,7 +71,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(chTypeName, '\0', 1024); - memset(Chip_Info->TypeName, '\0', linebufsize); //strlen(Chip_Info->TypeName)=0 + memset(Chip_Info->TypeName, '\0', linebufsize); // strlen(Chip_Info->TypeName)=0 if ((fp = openChipInfoDb()) == NULL) return 1; @@ -83,13 +83,13 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, while (fgets(file_line_buf, linebufsize, fp) != NULL) { pch = strstr(file_line_buf, "TypeName"); - //printf("ile_line_buf=%s",file_line_buf) ; + // 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 + *Chip_Info = Chip_Info_temp; // first chip info } // break; @@ -120,7 +120,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, Chip_Info_temp.DualID = false; Chip_Info_temp.VppSupport = 0; Chip_Info_temp.MXIC_WPmode = false; - Chip_Info_temp.Timeout = 0; + Chip_Info_temp.Timeout = 0; // end of struct init strcpy(Chip_Info_temp.TypeName, tok); @@ -132,7 +132,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Class")); tok = strtok(test, "\"= \t"); - //printf("Class = %s\n",tok); + // printf("Class = %s\n",tok); strcpy(Chip_Info_temp.Class, tok); continue; } @@ -141,11 +141,11 @@ int Dedi_Search_Chip_Db(char* chTypeName, 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("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++; + if (UniqueID == Chip_Info_temp.UniqueID) { + // found_flag = 1; + // detectICNum++; } continue; @@ -155,7 +155,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Manufacturer")); tok = strtok(test, "\"= \t"); - //printf("Manufacturer = %s\n",tok); + // printf("Manufacturer = %s\n",tok); strcpy(Chip_Info_temp.Manufacturer, tok); continue; } @@ -179,13 +179,13 @@ 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)) { + if (UniqueID == Chip_Info_temp.JedecDeviceID) { found_flag = 1; strcpy(strTypeName[detectICNum], Chip_Info_temp.TypeName); - //printf("strTypeName[%d] = %s\n",detectICNum,strTypeName[detectICNum]); + // printf("strTypeName[%d] = %s\n",detectICNum,strTypeName[detectICNum]); strcat(chTypeName, " "); strcat(chTypeName, strTypeName[detectICNum]); detectICNum++; @@ -197,7 +197,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("ChipSizeInKByte")); tok = strtok(test, "\"= \t"); - //printf("ChipSizeInKByte = %ld\n",strtol(tok,NULL,10)); + // printf("ChipSizeInKByte = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.ChipSizeInByte = strtol(tok, NULL, 10) * 1024; continue; } @@ -206,7 +206,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("SectorSizeInByte")); tok = strtok(test, "\"= \t"); - //printf("SectorSizeInByte = %ld\n",strtol(tok,NULL,10)); + // printf("SectorSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.SectorSizeInByte = strtol(tok, NULL, 10); continue; } @@ -215,7 +215,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("BlockSizeInByte")); tok = strtok(test, "\"= \t"); - //printf("BlockSizeInByte = %ld\n",strtol(tok,NULL,10)); + // printf("BlockSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.BlockSizeInByte = strtol(tok, NULL, 10); continue; } @@ -224,7 +224,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("PageSizeInByte")); tok = strtok(test, "\"= \t"); - //printf("PageSizeInByte = %ld\n",strtol(tok,NULL,10)); + // printf("PageSizeInByte = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.PageSizeInByte = strtol(tok, NULL, 10); continue; } @@ -233,7 +233,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("AddrWidth")); tok = strtok(test, "\"= \t"); - //printf("AddrWidth = %ld\n",strtol(tok,NULL,10)); + // printf("AddrWidth = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.AddrWidth = strtol(tok, NULL, 10); continue; } @@ -242,7 +242,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("ReadDummyLen")); tok = strtok(test, "\"= \t"); - //printf("ReadDummyLen = %ld\n",strtol(tok,NULL,10)); + // printf("ReadDummyLen = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.ReadDummyLen = strtol(tok, NULL, 10); continue; } @@ -251,7 +251,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("IDNumber")); tok = strtok(test, "\"= \t"); - //printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + // printf("IDNumber = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.IDNumber = strtol(tok, NULL, 10); continue; } @@ -260,7 +260,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("VppSupport")); tok = strtok(test, "\"= \t"); - //printf("IDNumber = %ld\n",strtol(tok,NULL,10)); + // printf("IDNumber = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.VppSupport = strtol(tok, NULL, 10); continue; } @@ -269,7 +269,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("RDIDCommand")); tok = strtok(test, "\"= \t"); - //printf("RDIDCommand = %ld\n",strtol(tok,NULL,10)); + // printf("RDIDCommand = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.RDIDCommand = strtol(tok, NULL, 16); continue; } @@ -278,7 +278,7 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, memset(test, '\0', testbufsize); strcpy(test, pch + strlen("Timeout")); tok = strtok(test, "\"= \t"); - //printf("Timeout = %ld\n",strtol(tok,NULL,10)); + // printf("Timeout = %ld\n",strtol(tok,NULL,10)); Chip_Info_temp.Timeout = strtol(tok, NULL, 16); continue; } @@ -292,8 +292,8 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, else Chip_Info_temp.MXIC_WPmode = false; // starting checking input data - } - pch = strstr(file_line_buf, "Portofolio"); //end + } + pch = strstr(file_line_buf, "Portofolio"); // end if (pch != NULL) { if (detectICNum) found_flag = 1; @@ -303,14 +303,14 @@ int Dedi_Search_Chip_Db(char* chTypeName, long RDIDCommand, 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*/ - + int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) { - //printf("Dedi_Search_Chip_Db_ByTypeName = %s\n",TypeName); + // printf("Dedi_Search_Chip_Db_ByTypeName = %s\n",TypeName); FILE* fp; /*Declare file pointer variable*/ int found_flag = 0, i; char file_line_buf[linebufsize], *tok, *file_buf, test[testbufsize]; @@ -366,7 +366,7 @@ int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) Chip_Info->MaxErasableSegmentInByte = 0; Chip_Info->DualID = false; Chip_Info->VppSupport = 0; - Chip_Info->MXIC_WPmode = false; + Chip_Info->MXIC_WPmode = false; Chip_Info->Timeout = 0; // end of struct init strcpy(Chip_Info->TypeName, tok); @@ -479,10 +479,10 @@ int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) memset(test, '\0', testbufsize); strcpy(test, pch + strlen("ReadDummyLen")); tok = strtok(test, "\"= \t"); - //printf("ReadDummyLen = %ld\n",strtol(tok,NULL,10)); + // printf("ReadDummyLen = %ld\n",strtol(tok,NULL,10)); Chip_Info->ReadDummyLen = strtol(tok, NULL, 10); continue; - } + } pch = strstr(file_line_buf, "IDNumber"); if (pch != NULL) { memset(test, '\0', testbufsize); @@ -528,11 +528,11 @@ int Dedi_Search_Chip_Db_ByTypeName(char* TypeName, CHIP_INFO* Chip_Info) Chip_Info->MXIC_WPmode = false; // starting checking input data continue; - } + } } /*Continue until EOF is encoutered*/ fclose(fp); /*Close file*/ Chip_Info->MaxErasableSegmentInByte = max(Chip_Info->SectorSizeInByte, Chip_Info->BlockSizeInByte); - + if (found_flag == 0) { Chip_Info->TypeName[0] = 0; Chip_Info->UniqueID = 0; diff --git a/project.c b/project.c old mode 100755 new mode 100644 index 79dbbc3..4fd70f9 --- a/project.c +++ b/project.c @@ -27,7 +27,7 @@ extern int m_boEnReadQuadIO; extern int m_boEnWriteQuadIO; extern volatile bool g_bIsSF600[16]; extern volatile bool g_bIsSF700[16]; -extern volatile bool g_bIsSF600PG2[16]; +extern volatile bool g_bIsSF600PG2[16]; extern char g_board_type[8]; extern int g_firmversion; extern char* g_parameter_vcc; @@ -145,7 +145,7 @@ unsigned int CRC32(unsigned char* v, unsigned long size) unsigned int dwCrc32 = 0xFFFFFFFF; unsigned long i; for (i = 0; i < size; i++) - dwCrc32 = ((dwCrc32) >> 8) ^ crc32_tab[(v[i]) ^ ((dwCrc32)&0x000000FF)]; + dwCrc32 = ((dwCrc32) >> 8) ^ crc32_tab[(v[i]) ^ ((dwCrc32) & 0x000000FF)]; // checksum += v[i]; dwCrc32 = ~dwCrc32; @@ -284,7 +284,7 @@ bool LoadFile(char* filename) bool IdentifyChipBeforeOperation(int Index) { - //printf("\n===>project.c ---- bool IdentifyChipBeforeOperation(%d)\n",Index); + // printf("\n===>project.c ---- bool IdentifyChipBeforeOperation(%d)\n",Index); bool result = false; CHIP_INFO binfo; binfo.UniqueID = 0; @@ -340,7 +340,7 @@ bool ValidateProgramParameters(int Index) } bool ProgramChip(int Index) -{ +{ bool need_padding = (g_ucFill != 0xFF); unsigned char* vc; struct CAddressRange real_addr[16]; @@ -358,12 +358,12 @@ bool ProgramChip(int Index) memcpy(vc + (DownloadAddrRange.start & 0x1FF), pBufferforLoadedFile, DownloadAddrRange.length); } - bool result = SerialFlash_rangeProgram(&real_addr[Index], vc, Index); + bool result = SerialFlash_rangeProgram(&real_addr[Index], vc, Index); return result; } bool ReadChip(const struct CAddressRange range, int Index) -{ +{ bool result = true; unsigned char* vc; size_t addrStart = range.start; @@ -559,8 +559,8 @@ bool threadConfiguredReadChip(int Index) } bool threadProgram(int Index) -{ - int pthread_mutex_init(pthread_mutex_t * restrict mutex, const pthread_mutexattr_t* restricattr); +{ + int pthread_mutex_init(pthread_mutex_t* restrict mutex, const pthread_mutexattr_t* restricattr); bool result = true; @@ -582,15 +582,15 @@ bool threadProgram(int Index) result = true; } else { result = false; - } - + } + g_is_operation_successful[Index] = result; return result; } bool threadCompareFileAndChip(int Index) { - //printf("\n===>project.c ---- bool threadCompareFileAndChip(%d)\n",Index); + // printf("\n===>project.c ---- bool threadCompareFileAndChip(%d)\n",Index); bool result = true; SetIOMode(false, Index); @@ -612,13 +612,13 @@ bool threadCompareFileAndChip(int Index) if (result) { ReadChip(DownloadAddrRange, Index); - size_t offset = min(DownloadAddrRange.length, g_ulFileSize); + size_t offset = min(DownloadAddrRange.length, g_ulFileSize); unsigned int crcFile = CRC32(pBufferforLoadedFile, offset); unsigned int crcChip = CRC32(pBufferForLastReadData[Index], offset); - - result = (crcChip == crcFile); + + result = (crcChip == crcFile); } - + g_is_operation_successful[Index] = result; return result; @@ -664,7 +664,7 @@ size_t Condense(uintptr_t* out, unsigned char* vc, uintptr_t* addrs, size_t addr extern void SetPageSize(CHIP_INFO* mem, int USBIndex); bool BlazeUpdate(int Index) -{ +{ struct CAddressRange down_with_lock_range; down_with_lock_range.start = DownloadAddrRange.start; down_with_lock_range.end = DownloadAddrRange.end; @@ -677,13 +677,12 @@ bool BlazeUpdate(int Index) if ((LockAddrrange.start + LockAddrrange.length) > DownloadAddrRange.end) down_with_lock_range.end = LockAddrrange.start + LockAddrrange.length; } - + struct CAddressRange effectiveRange; //(addr_round.SectionRound(down_with_lock_range)); effectiveRange.start = down_with_lock_range.start & (~(Chip_Info.MaxErasableSegmentInByte - 1)); effectiveRange.end = (down_with_lock_range.end + (Chip_Info.MaxErasableSegmentInByte - 1)) & (~(Chip_Info.MaxErasableSegmentInByte - 1)); effectiveRange.length = effectiveRange.end - effectiveRange.start; - - + if (!threadReadRangeChip(effectiveRange, Index)) return false; @@ -696,48 +695,48 @@ bool BlazeUpdate(int Index) uintptr_t* addrs = (size_t*)malloc(min(DownloadAddrRange.length, g_ulFileSize)); size_t Leng = 0; - - memcpy(vc, pBufferForLastReadData[Index], effectiveRange.length); //memory data - if (LockAddrrange.length > 0) { - offsetOfRealStartAddrOffset = LockAddrrange.start - effectiveRange.start; + memcpy(vc, pBufferForLastReadData[Index], effectiveRange.length); // memory data + + if (LockAddrrange.length > 0) { + offsetOfRealStartAddrOffset = LockAddrrange.start - effectiveRange.start; memcpy(pBufferforLoadedFile + offsetOfRealStartAddrOffset, pBufferForLastReadData[Index] + offsetOfRealStartAddrOffset, LockAddrrange.length); Leng = GenerateDiff(addrs, vc, DownloadAddrRange.length, pBufferforLoadedFile, g_ulFileSize, DownloadAddrRange.start, Chip_Info.MaxErasableSegmentInByte); - } else { - offsetOfRealStartAddrOffset = DownloadAddrRange.start - effectiveRange.start; - -Leng = GenerateDiff(addrs, vc + offsetOfRealStartAddrOffset, DownloadAddrRange.length, pBufferforLoadedFile, g_ulFileSize, DownloadAddrRange.start, Chip_Info.MaxErasableSegmentInByte); + } else { + offsetOfRealStartAddrOffset = DownloadAddrRange.start - effectiveRange.start; + + Leng = GenerateDiff(addrs, vc + offsetOfRealStartAddrOffset, DownloadAddrRange.length, pBufferforLoadedFile, g_ulFileSize, DownloadAddrRange.start, Chip_Info.MaxErasableSegmentInByte); } - - if (Leng == 0) // speed optimisation + + if (Leng == 0) // speed optimisation return true; else { uintptr_t* condensed_addr = (size_t*)malloc(min(DownloadAddrRange.length, g_ulFileSize)); size_t condensed_size; condensed_size = Condense(condensed_addr, vc, addrs, Leng, effectiveRange.start, Chip_Info.MaxErasableSegmentInByte); - - if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) - SerialFlash_batchErase_W25Mxx_Large(condensed_addr, condensed_size, Index); - else - SerialFlash_batchErase(condensed_addr, condensed_size, Index); + + if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) + SerialFlash_batchErase_W25Mxx_Large(condensed_addr, condensed_size, Index); + else + SerialFlash_batchErase(condensed_addr, condensed_size, Index); if (strstr(Chip_Info.Class, SUPPORT_MACRONIX_MX25Lxxx) != NULL) { TurnOFFVcc(Index); Sleep(100); TurnONVcc(Index); } - + memcpy(vc + offsetOfRealStartAddrOffset, pBufferforLoadedFile, DownloadAddrRange.length); - + size_t i = 0; for (i = 0; i < Leng; i++) { size_t idx_in_vc = addrs[i] - effectiveRange.start; struct CAddressRange addr_range; addr_range.start = addrs[i]; addr_range.end = addrs[i] + Chip_Info.MaxErasableSegmentInByte; - addr_range.length = addr_range.end - addr_range.start; - - if (SerialFlash_rangeProgram(&addr_range, vc + idx_in_vc, Index) == 0) { + addr_range.length = addr_range.end - addr_range.start; + + if (SerialFlash_rangeProgram(&addr_range, vc + idx_in_vc, Index) == 0) { free(vc); free(addrs); free(condensed_addr); @@ -762,7 +761,7 @@ bool RangeUpdateThruSectorErase(int Index) } bool RangeUpdateThruChipErase(int Index) -{ +{ unsigned char* vc = (unsigned char*)malloc(Chip_Info.ChipSizeInByte); unsigned int i = 0; bool boIsBlank = true; @@ -800,7 +799,6 @@ bool RangeUpdateThruChipErase(int Index) addr.end = Chip_Info.ChipSizeInByte; addr.length = Chip_Info.ChipSizeInByte; - return SerialFlash_rangeProgram(&addr, vc, Index); } @@ -823,23 +821,23 @@ bool ReplaceChipContentThruChipErase(int Index) } bool threadPredefinedBatchSequences(int Index) -{ +{ bool result = true; if (g_ulFileSize == 0) - result = false; + result = false; if (result && (!ValidateProgramParameters(Index))) - result = false; - + result = false; + if (result) { switch (g_BatchIndex) { - case 1: //-z + case 1: //-z result = ReplaceChipContentThruChipErase(Index); break; case 2: - default: - result = RangeUpdate(Index); + default: + result = RangeUpdate(Index); break; } } @@ -847,7 +845,7 @@ bool threadPredefinedBatchSequences(int Index) } void threadRun(void* Type) -{ +{ THREAD_STRUCT* thread_data = (THREAD_STRUCT*)Type; OPERATION_TYPE opType = thread_data->type; int Index = thread_data->USBIndex; @@ -857,17 +855,16 @@ void threadRun(void* Type) int dwUID = ReadUID(Index); if (g_uiAddr == 0 && g_uiLen == 0) { - if(is_SF700_Or_SF600PG2(Index)){ - if (g_bIsSF700[Index] == true) + if (is_SF700_Or_SF600PG2(Index)) { + if (g_bIsSF700[Index] == true) printf("\nDevice %d (SF7%05X):", Index + 1, dwUID); - else if (g_bIsSF600PG2[Index] == true) + else if (g_bIsSF600PG2[Index] == true) printf("\nDevice %d (S6%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); + } else { + if ((dwUID / 600000) == 0) + printf("\nDevice %d (DP%06d):", Index + 1, dwUID); + else + printf("\nDevice %d (SF%06d):", Index + 1, dwUID); } } @@ -883,7 +880,7 @@ void threadRun(void* Type) } if (1) // is_good()) - { + { TurnONVcc(Index); if (is_greater_than_5_0_0 || is_SF700_greater_than_4_0_0) { SetLEDOnOff(SITE_BUSY, Index); @@ -1082,24 +1079,24 @@ void SetIOMode(bool isProg, int Index) bool is_BoardVersionGreaterThan_5_0_0(int Index) { - if (g_firmversion < FIRMWARE_VERSION(5, 0, 0)) { + if (g_firmversion < FIRMWARE_VERSION(5, 0, 0)) { return false; } return true; } bool is_SF100nBoardVersionGreaterThan_5_5_0(int Index) -{ - if ((g_firmversion >= FIRMWARE_VERSION(5, 5, 0)) && strstr(g_board_type, "SF100") != NULL) +{ + if ((g_firmversion >= FIRMWARE_VERSION(5, 5, 0)) && strstr(g_board_type, "SF100") != NULL) return true; - - return false; + + return false; } bool is_SF600nBoardVersionGreaterThan_6_9_0(int Index) -{ +{ if (strstr(g_board_type, "SF600") != NULL) { - if ((g_firmversion > FIRMWARE_VERSION(7, 0, 1)) || (g_firmversion == FIRMWARE_VERSION(6, 9, 0))) { + if ((g_firmversion > FIRMWARE_VERSION(7, 0, 1)) || (g_firmversion == FIRMWARE_VERSION(6, 9, 0))) { return true; } } @@ -1126,26 +1123,25 @@ bool is_SF700_Or_SF600PG2(int Index) { if (strstr(g_board_type, "SF700") != NULL) { return true; - } - else if (strstr(g_board_type, "SF600PG2") != NULL) { + } else if (strstr(g_board_type, "SF600PG2") != NULL) { return true; } return false; -} +} 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); int Found = 0; int i = 0; int Loop = 3; - if (strcmp(g_parameter_vcc, "NO") != 0) //g_parameter_vcc!=NO + if (strcmp(g_parameter_vcc, "NO") != 0) // g_parameter_vcc!=NO Loop = 1; if (strlen(TypeName) != 0) @@ -1201,7 +1197,7 @@ CHIP_INFO GetFirstDetectionMatch(char* TypeName, int Index) return binfo; //*TypeName; } - + // fail in case of 1) USB failure, 2) unrecognised ID. void InitLED(int Index) { @@ -1323,29 +1319,29 @@ void SetProgReadCommand(int Index) mcode_SegmentErase = 0xD8; mcode_ProgramCode_4Adr = 0x12; mcode_ReadCode = 0x0C; - }else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxS_Large) != NULL) { + } else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxS_Large) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; mcode_ChipErase = CHIP_ERASE; - if(strstr(Chip_Info.TypeName, "S25FS256T") != NULL) + if (strstr(Chip_Info.TypeName, "S25FS256T") != NULL) mcode_Read = BULK_NORM_READ; else - mcode_Read = BULK_4BYTE_FAST_READ; - if(g_bIsSF600[Index] == true || g_bIsSF700[Index] == true || g_bIsSF600PG2[Index] == true) + mcode_Read = BULK_4BYTE_FAST_READ; + if (g_bIsSF600[Index] == true || g_bIsSF700[Index] == true || g_bIsSF600PG2[Index] == true) mcode_Program = PP_PROGRAM_ANYSIZE_PAGESIZE; else mcode_Program = PP_4ADR_256BYTE; mcode_SegmentErase = 0xD8; mcode_ProgramCode_4Adr = 0x12; - if (strstr(Chip_Info.TypeName, "S25HL01GT") != NULL - || strstr(Chip_Info.TypeName, "S25HL512T") != NULL - || strstr(Chip_Info.TypeName, "S25HL256T") != NULL - || strstr(Chip_Info.TypeName, "S25FS256T") != NULL - || strstr(Chip_Info.TypeName, "S35HL256T") != NULL) - mcode_ReadCode = 0x0B; - else - mcode_ReadCode = 0x0C; - } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL ) { + if (strstr(Chip_Info.TypeName, "S25HL01GT") != NULL + || strstr(Chip_Info.TypeName, "S25HL512T") != NULL + || strstr(Chip_Info.TypeName, "S25HL256T") != NULL + || strstr(Chip_Info.TypeName, "S25FS256T") != NULL + || strstr(Chip_Info.TypeName, "S35HL256T") != NULL) + mcode_ReadCode = 0x0B; + else + mcode_ReadCode = 0x0C; + } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; mcode_ChipErase = 0xC4; @@ -1364,7 +1360,7 @@ void SetProgReadCommand(int Index) mcode_Read = BULK_4BYTE_FAST_READ_MICRON; } - } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { + } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; mcode_ChipErase = 0xC4; @@ -1373,7 +1369,7 @@ void SetProgReadCommand(int Index) mcode_ProgramCode_4Adr = 0x02; mcode_ReadCode = 0x03; mcode_Read = BULK_NORM_READ; - + } else if (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; @@ -1402,20 +1398,20 @@ void SetProgReadCommand(int Index) mcode_Read = BULK_4BYTE_FAST_READ; mcode_SegmentErase = SE; mcode_ProgramCode_4Adr = 0x02; - mcode_ReadCode = 0x0C; - } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { + mcode_ReadCode = 0x0C; + } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Mxx_Large) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; mcode_ChipErase = CHIP_ERASE; - if (strstr(g_board_type, "SF100") != NULL) // is sf100 + if (strstr(g_board_type, "SF100") != NULL) // is sf100 mcode_Program = PP_4ADDR_256BYTE_12; - else + else mcode_Program = PP_4ADR_256BYTE; mcode_Read = BULK_4BYTE_FAST_READ_MICRON; mcode_SegmentErase = 0xDC; mcode_ProgramCode_4Adr = 0x12; - mcode_ReadCode = 0x0C; - }else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Pxx) != NULL) { + mcode_ReadCode = 0x0C; + } else if (strstr(Chip_Info.Class, SUPPORT_WINBOND_W25Pxx) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; mcode_ChipErase = CHIP_ERASE; @@ -1423,7 +1419,7 @@ void SetProgReadCommand(int Index) mcode_Read = BULK_FAST_READ; mcode_SegmentErase = SE; mcode_ProgramCode_4Adr = 0x02; - mcode_ReadCode = 0x0B; + mcode_ReadCode = 0x0B; } else if (strstr(Chip_Info.Class, SUPPORT_ST_M25Pxx_Large) != NULL) { mcode_RDSR = RDSR; mcode_WRSR = WRSR; diff --git a/project.h b/project.h old mode 100755 new mode 100644 index 1b2a020..98fda29 --- a/project.h +++ b/project.h @@ -46,8 +46,8 @@ 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); -//bool is_SF600PG2(int Index); +// bool is_SF700(int Index); +// bool is_SF600PG2(int Index); bool is_SF700_Or_SF600PG2(int Index); int GetFileFormatFromExt(const char* csPath); #if 0 diff --git a/usbdriver.c b/usbdriver.c old mode 100755 new mode 100644 index 62bc35c..0bfed7f --- a/usbdriver.c +++ b/usbdriver.c @@ -33,9 +33,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_Or_SF600PG2(Index)) { + if (is_SF100nBoardVersionGreaterThan_5_5_0(Index) || is_SF600nBoardVersionGreaterThan_6_9_0(Index) || is_SF700_Or_SF600PG2(Index)) { return true; - } + } return false; } extern unsigned char GetFPGAVersion(int Index); @@ -65,9 +65,9 @@ void usb_db_init(void) } void AssignSF600orSF700var(int Index) -{ +{ if (Index == -1) - Index = DevIndex; + Index = DevIndex; g_bIsSF600[Index] = false; g_bIsSF700[Index] = false; g_bIsSF600PG2[Index] = false; @@ -83,31 +83,26 @@ void AssignSF600orSF700var(int Index) rq.Value = 0; rq.Index = 0; rq.Length = 32; - + if (InCtrlRequest(&rq, vBuffer, 32, Index) == SerialFlash_FALSE) - return; + return; memcpy(g_board_type, &vBuffer[0], 8); - - //memcpy(g_firmversion,&vBuffer[10],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]); - if (strstr(g_board_type, "SF700") != NULL) - g_bIsSF700[Index] = true; - else if (strstr(g_board_type, "SF600") != NULL) - { - if (strstr(g_board_type, "SF600PG2") != NULL) - { - g_bIsSF600PG2[Index] = true; - Sleep(2); - } - else - { - g_bIsSF600[Index] = true; + if (strstr(g_board_type, "SF700") != NULL) + g_bIsSF700[Index] = true; + else if (strstr(g_board_type, "SF600") != NULL) { + if (strstr(g_board_type, "SF600PG2") != NULL) { + g_bIsSF600PG2[Index] = true; + Sleep(2); + } else { + g_bIsSF600[Index] = true; } - } - + } GetFPGAVersion(Index); } @@ -142,19 +137,19 @@ static int FindUSBDevice(void) dev_index++; } } - printf(" \n"); + printf(" \n"); return dev_index; } int OutCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, int Index) -{ +{ int requesttype; int ret = 0; if (Index == -1) Index = DevIndex; - if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true) || is_SF700_Or_SF600PG2(Index) == true)) + if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true) || is_SF700_Or_SF600PG2(Index) == true)) return true; requesttype = 0x00; @@ -175,7 +170,7 @@ int OutCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, } else { printf("no device"); } - if (ret != buf_size) { + if (ret != buf_size) { printf("Error: %s\n", libusb_strerror(ret)); return -1; } @@ -187,11 +182,9 @@ int InCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, i unsigned int requesttype; unsigned int ret = 0; - if ((rq->Function != URB_FUNCTION_VENDOR_ENDPOINT) && ((g_bIsSF600[Index] == true) || is_SF700_Or_SF600PG2(Index) == true)) return true; - - + if (Index == -1) Index = DevIndex; @@ -217,12 +210,9 @@ int InCtrlRequest(CNTRPIPE_RQ* rq, unsigned char* buf, unsigned long buf_size, i printf("no device"); } - if (ret != 0 /*!= buf_size*/) -{ - return ret; - } - else - { + if (ret != 0 /*!= buf_size*/) { + return ret; + } else { #if 0 printf("InCtrlRequest ---ret=%X\n",ret); @@ -247,9 +237,9 @@ 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) -{ - // if((g_bIsSF600[Index] != false) || is_SF700_Or_SF600PG2(Index)!=false) -// return 1; +{ + // if((g_bIsSF600[Index] != false) || is_SF700_Or_SF600PG2(Index)!=false) + // return 1; CNTRPIPE_RQ rq; int ret; @@ -272,7 +262,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]; @@ -309,21 +299,21 @@ int dediprog_get_chipid(int Index) // return size read // if fail , return -1 -//long CUSB::BulkPipeRead(PBYTE pBuff, UINT sz, UINT timeOut) const +// long CUSB::BulkPipeRead(PBYTE pBuff, UINT sz, UINT timeOut) const int BulkPipeRead(unsigned char* pBuff, unsigned int timeOut, int Index) { int ret, actual_length; if (Index == -1) 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; + + 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; return cnRead; } -//long CUSB::BulkPipeWrite(PBYTE pBuff, UINT sz, UINT timeOut) const +// long CUSB::BulkPipeWrite(PBYTE pBuff, UINT sz, UINT timeOut) const int BulkPipeWrite(unsigned char* pBuff, unsigned int size, unsigned int timeOut, int Index) { int ret, actual_length; @@ -372,12 +362,12 @@ int dediprog_set_spi_voltage(int v, int Index) unsigned char v[4] = { 0xff, 0xff, 0xff, 0xff }; FlashCommand_SendCommand_OutOnlyInstruction(v, 4, Index); } - } + } return ret; } int dediprog_set_vpp_voltage(int volt, int Index) -{ +{ int ret; int voltage_selector; CNTRPIPE_RQ rq; @@ -471,9 +461,9 @@ 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; + // printf("\n===>usbdrive.c --- usb_driver_init\n"); + // struct usb_bus *bus; + // struct usb_device *dev; bool result = false; int device_cnt = 0; int ret; @@ -510,7 +500,7 @@ int usb_driver_init(void) } dediprog_start_appli(i); - AssignSF600orSF700var(i); + AssignSF600orSF700var(i); result = (dediprog_handle[i] != NULL); } } else { @@ -524,7 +514,7 @@ int usb_driver_init(void) 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) { @@ -557,13 +547,13 @@ int usb_driver_release(void) } return 0; } - + bool Is_usbworking(int Index) { usleep(1000); // unknow reson return ((dediprog_handle[Index] != NULL) ? true : false); } -//long long flash_ReadId(boost::tuple command,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 @@ -575,7 +565,6 @@ long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size, int Ind // DoRDP() ; // send request - CNTRPIPE_RQ rq; unsigned char vInstruction[8]; @@ -597,7 +586,7 @@ long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size, int Ind rq.Length = 1; if (OutCtrlRequest(&rq, vInstruction, (unsigned long)1, Index) == SerialFlash_FALSE) - return rc; //OutCtrlRequest() return error + return rc; // OutCtrlRequest() return error // second control packet : fetch data memset(vInstruction, 0, sizeof(vInstruction)); diff --git a/usbdriver.h b/usbdriver.h old mode 100755 new mode 100644 index e5862d4..056317c --- a/usbdriver.h +++ b/usbdriver.h @@ -69,4 +69,4 @@ long flash_ReadId(unsigned int read_id_code, unsigned int out_data_size, int Ind int BulkPipeWrite(unsigned char* pBuff, unsigned int size, unsigned int timeOut, int Index); -#endif //DEDI_USB_DRIVER +#endif // DEDI_USB_DRIVER