Added CRC32 checksumming to dumping blocks
This commit is contained in:
parent
cdeedef92d
commit
6972543e24
|
@ -76,3 +76,5 @@ Code/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.o
|
||||||
Code/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.d
|
Code/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.d
|
||||||
Code/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.o
|
Code/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.o
|
||||||
Code/test.rom
|
Code/test.rom
|
||||||
|
EETool_pcb.jpg
|
||||||
|
EETool_sch.jpg
|
||||||
|
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import sys, getopt, serial, binascii
|
import sys, getopt, serial, binascii, struct
|
||||||
|
|
||||||
|
|
||||||
class Mode:
|
class Mode:
|
||||||
|
@ -20,6 +20,7 @@ class Command:
|
||||||
|
|
||||||
PONG = 'PONG'
|
PONG = 'PONG'
|
||||||
BLOCKSIZE = 512
|
BLOCKSIZE = 512
|
||||||
|
CRCSIZE = 4
|
||||||
|
|
||||||
romfile = ''
|
romfile = ''
|
||||||
serialport = ''
|
serialport = ''
|
||||||
|
@ -149,32 +150,41 @@ def dumpROM():
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
numBytes = connection.inWaiting()
|
numBytes = connection.inWaiting()
|
||||||
if numBytes>=BLOCKSIZE:
|
if numBytes>=BLOCKSIZE + CRCSIZE:
|
||||||
break
|
break
|
||||||
|
|
||||||
if (numBytes!=BLOCKSIZE):
|
if (numBytes!=BLOCKSIZE + CRCSIZE):
|
||||||
print 'ERROR: Block',blockNum,'failed to download. Aborting.'
|
print 'ERROR: Block',blockNum,'failed to download. Aborting.'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
response = connection.read(numBytes)
|
response = connection.read(numBytes)
|
||||||
|
crc = struct.unpack('<I',response[BLOCKSIZE:BLOCKSIZE+CRCSIZE])[0]
|
||||||
|
block = response[0:BLOCKSIZE]
|
||||||
|
calcCRC = binascii.crc32(block) & 0xFFFFFFFF
|
||||||
|
if crc != calcCRC:
|
||||||
|
print numBytes,'CRC failed on block',blockNum,'Read CRC =',hexU32(crc),' Calcuated CRC =',hexU32(calcCRC)
|
||||||
|
print 'Aborting.'
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
# Write the block to our file
|
# Write the block to our file
|
||||||
destFile.write(bytes(response))
|
destFile.write(bytes(block))
|
||||||
|
|
||||||
sys.stdout.write('#')
|
sys.stdout.write('#')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
totalSize += numBytes
|
totalSize += numBytes - CRCSIZE
|
||||||
|
|
||||||
destFile.close()
|
destFile.close()
|
||||||
print '\nDone! ROM is',totalSize,'bytes.'
|
print '\nDone! ROM is',totalSize,'bytes.'
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
except (ValueError,OSError,serial.SerialException):
|
except (ValueError,OSError,serial.SerialException):
|
||||||
|
print 'UNKNOWN ERROR'
|
||||||
connection.close()
|
connection.close()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def hexU32(n):
|
||||||
|
return "0x%x"%(n&0xffffffff)
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print '''
|
print '''
|
||||||
|
|
|
@ -21,6 +21,7 @@ void Echo(const char* string);
|
||||||
void WriteBlock(void);
|
void WriteBlock(void);
|
||||||
void ReadBlock(uint16_t startAddr, uint16_t length, bool maskROM);
|
void ReadBlock(uint16_t startAddr, uint16_t length, bool maskROM);
|
||||||
void SetAddressMSB(uint8_t addr, bool maskROM);
|
void SetAddressMSB(uint8_t addr, bool maskROM);
|
||||||
|
uint32_t CRC32(uint8_t *buf, size_t size);
|
||||||
|
|
||||||
|
|
||||||
void EVENT_USB_Device_Connect(void);
|
void EVENT_USB_Device_Connect(void);
|
||||||
|
@ -336,6 +337,14 @@ void ReadBlock(uint16_t startAddr, uint16_t length, bool maskROM)
|
||||||
|
|
||||||
// Send data to host
|
// Send data to host
|
||||||
CDC_Device_SendData(&EETool_CDC_Interface, gCommBuffer, length);
|
CDC_Device_SendData(&EETool_CDC_Interface, gCommBuffer, length);
|
||||||
|
|
||||||
|
// Compute a 32 bit CRC and send it
|
||||||
|
uint32_t crc = CRC32(gCommBuffer,length);
|
||||||
|
for (int i=0; i<4; i++)
|
||||||
|
{
|
||||||
|
CDC_Device_SendByte(&EETool_CDC_Interface, (uint8_t)(crc & 0xff));
|
||||||
|
crc>>=8;
|
||||||
|
}
|
||||||
_delay_ms(10);
|
_delay_ms(10);
|
||||||
|
|
||||||
PULSEC(LEDPIN);
|
PULSEC(LEDPIN);
|
||||||
|
@ -350,6 +359,28 @@ void WriteBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t CRC32(uint8_t *buf, size_t size)
|
||||||
|
{
|
||||||
|
// This could be made faster with a table lookup, but it's plenty fast enough for our purposes
|
||||||
|
int i, j;
|
||||||
|
uint32_t byte, crc, mask;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
crc = 0xFFFFFFFF;
|
||||||
|
while (size--)
|
||||||
|
{
|
||||||
|
byte = buf[i];
|
||||||
|
crc = crc ^ byte;
|
||||||
|
for (j = 7; j >= 0; j--)
|
||||||
|
{
|
||||||
|
mask = -(crc & 1);
|
||||||
|
crc = (crc >> 1) ^ (0xEDB88320 & mask);
|
||||||
|
}
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
return ~crc;
|
||||||
|
}
|
||||||
|
|
||||||
// USB Event Handlers
|
// USB Event Handlers
|
||||||
void EVENT_USB_Device_Connect(void)
|
void EVENT_USB_Device_Connect(void)
|
||||||
{
|
{
|
||||||
|
@ -372,5 +403,3 @@ void EVENT_USB_Device_ControlRequest(void)
|
||||||
{
|
{
|
||||||
CDC_Device_ProcessControlRequest(&EETool_CDC_Interface);
|
CDC_Device_ProcessControlRequest(&EETool_CDC_Interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
|
||||||
|
<false/>
|
||||||
|
<key>IDESourceControlProjectIdentifier</key>
|
||||||
|
<string>95794E8C-031F-41B1-9037-218BC0C75061</string>
|
||||||
|
<key>IDESourceControlProjectName</key>
|
||||||
|
<string>project</string>
|
||||||
|
<key>IDESourceControlProjectOriginsDictionary</key>
|
||||||
|
<dict>
|
||||||
|
<key>922DEEC8B722BFB3865485680EBE965F5270D110</key>
|
||||||
|
<string>https://github.com/blondie7575/EETool.git</string>
|
||||||
|
</dict>
|
||||||
|
<key>IDESourceControlProjectPath</key>
|
||||||
|
<string>Code/EETool.xcodeproj/project.xcworkspace</string>
|
||||||
|
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
|
||||||
|
<dict>
|
||||||
|
<key>922DEEC8B722BFB3865485680EBE965F5270D110</key>
|
||||||
|
<string>../../..</string>
|
||||||
|
</dict>
|
||||||
|
<key>IDESourceControlProjectURL</key>
|
||||||
|
<string>https://github.com/blondie7575/EETool.git</string>
|
||||||
|
<key>IDESourceControlProjectVersion</key>
|
||||||
|
<integer>111</integer>
|
||||||
|
<key>IDESourceControlProjectWCCIdentifier</key>
|
||||||
|
<string>922DEEC8B722BFB3865485680EBE965F5270D110</string>
|
||||||
|
<key>IDESourceControlProjectWCConfigurations</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
|
||||||
|
<string>public.vcs.git</string>
|
||||||
|
<key>IDESourceControlWCCIdentifierKey</key>
|
||||||
|
<string>922DEEC8B722BFB3865485680EBE965F5270D110</string>
|
||||||
|
<key>IDESourceControlWCCName</key>
|
||||||
|
<string>EETool</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
Loading…
Reference in New Issue