Skip to content

Commit

Permalink
Run clang-format on source code again
Browse files Browse the repository at this point in the history
- reformat source code (also removes white space at end of line)
- add "make release" target that fixes permissions and
  reformats source code before check-in

Signed-off-by: Stefan Reinauer <[email protected]>
  • Loading branch information
reinauer committed Feb 10, 2022
1 parent e903084 commit 4c64d14
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 602 deletions.
2 changes: 1 addition & 1 deletion ChipInfoDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef ChipInfo_H
#define ChipInfo_H

#include "Macro.h"
#include "Macro.h"

#define NUMBER_OF_SUPPORTING_CHIPS 3

Expand Down
8 changes: 4 additions & 4 deletions FlashCommand.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int FlashCommand_SendCommand_OneOutOneIn(unsigned char* vOut, int out_len, unsig
return FlashCommand_TRUE;
}

int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode,int Index)
int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode, int Index)
{
unsigned char vInstruction[16];
CNTRPIPE_RQ rq;
Expand Down Expand Up @@ -125,11 +125,11 @@ int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrR
vInstruction[7] = ((AddrRange->start >> 8) & 0xff);
vInstruction[8] = ((AddrRange->start >> 16) & 0xff);
vInstruction[9] = ((AddrRange->start >> 24) & 0xff);
vInstruction[10] = ((PageSize) & 0xff);
vInstruction[10] = (PageSize & 0xff);
vInstruction[11] = ((PageSize >> 8) & 0xff);
vInstruction[12] = ((PageSize>> 16) & 0xff);
vInstruction[12] = ((PageSize >> 16) & 0xff);
vInstruction[13] = ((PageSize >> 24) & 0xff);
vInstruction[14] = ((AddressMode) & 0xff);
vInstruction[14] = (AddressMode & 0xff);
rq.Value = 0;
rq.Index = 0;
rq.Length = (unsigned long)(16);
Expand Down
2 changes: 1 addition & 1 deletion FlashCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int FlashCommand_SendCommand_OutInstructionWithCS(unsigned char* v, int len, int

int FlashCommand_SendCommand_OneOutOneIn(unsigned char* vOut, int out_len, unsigned char* vIn, int in_len, int Index);

int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode,int Index);
int FlashCommand_SendCommand_SetupPacketForBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, unsigned int PageSize, unsigned int AddressMode, int Index);

int FlashCommand_SendCommand_SetupPacketForAT45DBBulkWrite(struct CAddressRange* AddrRange, unsigned char modeWrite, unsigned char WriteCom, int Index);

Expand Down
4 changes: 2 additions & 2 deletions Macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct FirmwareInfo {
} FW_INFO;

typedef enum {
TRANSCEIVE = 0x01,
TRANSCEIVE = 0x01,
DTC_READ = 0x20,
WRITE = 0x30,

Expand Down Expand Up @@ -304,7 +304,7 @@ typedef struct ChipInfo {
#define READ_TO_FILE BIT9
#define BLINK BIT10
#define DEVICE_ID BIT11
#define LIST_TYPE BIT12
#define LIST_TYPE BIT12
#define LOADFILEWITHVERIFY BIT13
#define CHECK_INFO BIT14

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Q:=@
ifneq ($(V),1)
ifneq ($(Q),)
.SILENT:
endif
endif
endif

PROGRAM = dpcmd
Expand All @@ -27,7 +27,7 @@ LDFLAGS += $(shell $(PKG_CONFIG) --libs libusb-1.0)
DEPDIR := .deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d

SRCS = dpcmd.c usbdriver.c FlashCommand.c SerialFlash.c parse.c board.c project.c IntelHexFile.c MotorolaFile.c
SRCS = dpcmd.c usbdriver.c FlashCommand.c SerialFlash.c parse.c board.c project.c IntelHexFile.c MotorolaFile.c

PROGRAMMER_OBJS := $(SRCS:%.c=%.o)

Expand Down Expand Up @@ -66,3 +66,8 @@ uninstall:
[ $(shell id -u) -eq 0 ] || (echo "Error: uninstall needs root privileges" && false)
rm -vf $(PREFIX)/bin/$(PROGRAM) $(PREFIX)/share/DediProg/ChipInfoDb.dedicfg /etc/udev/rules.d/60-dediprog.rules
[ -d "$(PREFIX)/share/DediProg" ] && rmdir -v $(PREFIX)/share/DediProg || true

# Run before every release / check-in to keep the source code tidy
release:
chmod 644 *.c *.h README.md Makefile LICENSE .gitignore ChipInfoDb.dedicfg 60-dediprog.rules
clang-format -i -style=WebKit *.c *.h
104 changes: 44 additions & 60 deletions SerialFlash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ unsigned char mcode_ProgramCode_4Adr = 0x02;
unsigned char mcode_ProgramCode_4Adr_12 = 0x12;
unsigned char mcode_Read = BULK_FAST_READ;
unsigned char mcode_ReadCode = 0x0B;
unsigned char mcode_ReadCode_0C = 0x0C;
unsigned char mcode_ReadCode_0C = 0x0C;
unsigned int g_AT45_PageSize = 0;
unsigned int g_AT45_PageSizeMask = 0;
size_t AT45ChipSize = 0;
Expand Down Expand Up @@ -1584,8 +1584,7 @@ bool CN25Qxxx_MutipleDIe_LargeWREAR(unsigned char cSR, int Index)

bool CS25FLxx_LargeEnable4ByteAddrMode(bool Enable4Byte, int Index)
{
if ((strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x") != NULL) || (strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x(Secure)") != NULL))
{
if ((strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x") != NULL) || (strstr(Chip_Info.TypeName, "S25FL512Sxxxxxx1x(Secure)") != NULL)) {
SerialFlash_waitForWEL(Index);
if (Enable4Byte) {
unsigned char v[2];
Expand All @@ -1612,15 +1611,15 @@ 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);
return true;
} else {
unsigned char v = EXIT4B;
FlashCommand_TransceiveOut(&v, 1, false, Index);
return true;
return true;
}
return true;
}
Expand Down Expand Up @@ -1716,7 +1715,7 @@ int SerialFlash_Enable4ByteAddrMode(int bEnable, int Index)
return CN25Qxxx_LargeEnable4ByteAddrMode(bEnable, Index);
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL)
return CS25FLxx_LargeEnable4ByteAddrMode(bEnable, Index);
else
else
return Universal_LargeEnable4ByteAddrMode(bEnable, Index);
return SerialFlash_TRUE;
}
Expand Down Expand Up @@ -1775,60 +1774,45 @@ int SerialFlash_rangeBlankCheck(struct CAddressRange* Range, int Index)
* false, if data size larger than memory size, or operation fails
*/
int SerialFlash_rangeProgram(struct CAddressRange* AddrRange, unsigned char* vData, int Index)
{
{
if (strstr(Chip_Info.Class, SUPPORT_ATMEL_45DBxxxB) != NULL || strstr(Chip_Info.Class, SUPPORT_ATMEL_45DBxxxD) != NULL)
return AT45rangeProgram(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index);
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL)
{
if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) {
if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))
return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADR_256BYTE, mcode_ProgramCode_4Adr, Index);
else
return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_12, mcode_ProgramCode_4Adr, Index);
}
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL)
{

} else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) {

return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADR_256BYTE, mcode_ProgramCode_4Adr_12, Index);
}
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL)
{
if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))
{
} else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) {
if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true)) {
return SerialFlash_bulkPipeProgram(AddrRange, vData, PP_4ADDR_256BYTE_S70FS01GS, mcode_ProgramCode_4Adr_12, Index);
}
else
} else
return false;
}
else
{

} else {

return SerialFlash_bulkPipeProgram(AddrRange, vData, mcode_Program, mcode_ProgramCode_4Adr, Index);
}
}

int SerialFlash_rangeRead(struct CAddressRange* AddrRange, unsigned char* vData, int Index)
{
//printf("SerialFlash_rangeRead");
if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL)
{
if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))
//printf("SerialFlash_rangeRead");
if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxx_Large) != NULL) {
if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))
return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode, Index);
else
return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ_MICRON, mcode_ReadCode, Index);
}
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL)
{
} else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S25FLxxL_Large) != NULL) {
return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ_MICRON, mcode_ReadCode_0C, Index);
}
else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL)
{
if ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))
} else if (strstr(Chip_Info.Class, SUPPORT_SPANSION_S70FSxx_Large) != NULL) {
if ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))
return SerialFlash_bulkPipeRead(AddrRange, vData, BULK_4BYTE_FAST_READ, mcode_ReadCode_0C, Index);
else
return false;
} else
} else
return SerialFlash_bulkPipeRead(AddrRange, vData, (unsigned char)mcode_Read, (unsigned char)mcode_ReadCode, Index);

};

/**
Expand Down Expand Up @@ -2169,7 +2153,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char*
packageNum = down_range.length >> divider;
// printf("packageNum=%d \n",packageNum);
// printf("down_range.start=%X, down_range.end=%X\n",down_range.start, down_range.end);
FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth,Index);
FlashCommand_SendCommand_SetupPacketForBulkWrite(&down_range, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index);
for (i = 0; i < packageNum; ++i) {
BulkPipeWrite((unsigned char*)(itr_begin + (i << divider)), 1 << divider, USB_TIMEOUT, Index);
if (m_isCanceled)
Expand All @@ -2179,7 +2163,7 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char*
}
} else {
size_t packageNum = (AddrRange->end - AddrRange->start) >> divider;
FlashCommand_SendCommand_SetupPacketForBulkWrite(AddrRange, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth,Index);
FlashCommand_SendCommand_SetupPacketForBulkWrite(AddrRange, modeWrite, WriteCom, Chip_Info.PageSizeInByte, Chip_Info.AddrWidth, Index);
for (i = 0; i < packageNum; ++i) {
BulkPipeWrite((unsigned char*)((itr_begin + (i << divider))), 1 << divider, USB_TIMEOUT, Index);
if (m_isCanceled)
Expand All @@ -2202,21 +2186,21 @@ int SerialFlash_bulkPipeProgram(struct CAddressRange* AddrRange, unsigned char*
}

int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vData, unsigned char modeRead, unsigned char ReadCom, int Index)
{
{
size_t i, j, loop, pageNum, BufferLocation = 0;
int ret = 0;
if (!SerialFlash_StartofOperation(Index))
return false;
if (!(strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL && strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL && ((g_bIsSF600[Index] == true)||(g_bIsSF700[Index] == true))))
int ret = 0;
if (!SerialFlash_StartofOperation(Index))
return false;
if (!(strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL && strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL && ((g_bIsSF600[Index] == true) || (g_bIsSF700[Index] == true))))
SerialFlash_Enable4ByteAddrMode(true, Index);

if (SerialFlash_EnableQuadIO(true, m_boEnReadQuadIO, Index) == SerialFlash_FALSE)
return false;

AddrRange->length = AddrRange->end - AddrRange->start;
if (AddrRange->length <= 0)
if (AddrRange->length <= 0)
return false;

// printf("AddrRange->end=%x, AddrRange->start=%x\n",AddrRange->end,AddrRange->start);
if ((AddrRange->end / 0x1000000) > (AddrRange->start / 0x1000000)) //(AddrRange.end>0x1000000 && AddrRange.start<0x1000000)
{
Expand All @@ -2230,7 +2214,7 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa
loop = (range_temp.end - range_temp.start) / 0x1000000;

for (j = 0; j < loop; j++) {
if (((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) // for sf100
if (((g_bIsSF600[Index] == false) && (g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) // for sf100
{
unsigned char re = 0;
int numOfRetry = 5;
Expand All @@ -2244,8 +2228,8 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa
Sleep(100);
CN25Qxxx_MutipleDIe_LargeRDEAR(&re, Index);
} while (((re & j) != j) && numOfRetry-- > 0);
if (numOfRetry == 0)
return false;
if (numOfRetry == 0)
return false;
}

if (j == (loop - 1))
Expand All @@ -2264,15 +2248,15 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa
FlashCommand_SendCommand_SetupPacketForBulkRead(&read_range, modeRead, ReadCom, Index);
for (i = 0; i < pageNum; ++i) {
ret = BulkPipeRead(vData + (BufferLocation + i) * 512, USB_TIMEOUT, Index);
if ((ret != 512) || m_isCanceled)
return 0;
if ((ret != 512) || m_isCanceled)
return 0;
//memcpy(vData + (BufferLocation+i)*512, v, 512);
}
BufferLocation += pageNum;
}
} else {
unsigned char EAR = (AddrRange->start * 0x1000000) >> 24;
if (((g_bIsSF600[Index] == false)&&(g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) {
if (((g_bIsSF600[Index] == false) && (g_bIsSF700[Index] == false)) && (strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_2Die) != NULL || strstr(Chip_Info.Class, SUPPORT_NUMONYX_N25Qxxx_Large_4Die) != NULL)) {
unsigned char re = 0;
int numOfRetry = 5;
do {
Expand All @@ -2285,23 +2269,23 @@ int SerialFlash_bulkPipeRead(struct CAddressRange* AddrRange, unsigned char* vDa
Sleep(100);
CN25Qxxx_MutipleDIe_LargeRDEAR(&re, Index);
} while (((re & EAR) != EAR) && numOfRetry-- > 0);
if (numOfRetry == 0){
if (numOfRetry == 0) {
return false;
}
}
}
pageNum = AddrRange->length >> 9;
FlashCommand_SendCommand_SetupPacketForBulkRead(AddrRange, modeRead, ReadCom, Index);
for (i = 0; i < pageNum; ++i) {
ret = BulkPipeRead(vData + i * ret, USB_TIMEOUT, Index);
if ((ret != 512) || m_isCanceled) {
//printf("SerialFlash_bulkPipeRead5,ret=%d, m_isCanceled=%s\n",ret,m_isCanceled?"true":"false");
//printf("SerialFlash_bulkPipeRead5,ret=%d, m_isCanceled=%s\n",ret,m_isCanceled?"true":"false");
return false;
}
//memcpy(vData + i*ret, v, ret);
}
}
}
if (SerialFlash_EnableQuadIO(false, m_boEnReadQuadIO, Index) == SerialFlash_FALSE)
return false;
return false;
SerialFlash_Enable4ByteAddrMode(false, Index);

if (!SerialFlash_EndofOperation(Index))
Expand Down
Loading

0 comments on commit 4c64d14

Please sign in to comment.