Automated Loading Using a Batch File
56800E Flash Programmer User Guide, Rev. 0
Freescale Semiconductor
23
Appendix B
CRC32 Algorithm
Of special note: The CRC32 algorithm used in this program is Copyright © 1993 Richard Black. For more
information about this algorithm please visit:
http://www.cl.cam.ac.uk/Research/SRG/bluebook/21/crc/crc.html
The following standard polynomial was used:
x
32
+ x
26
+ x
23
+ x
22
+ x
16
+ x
12
+ x
11
+ x
10
+ x
8
+ x
7
+ x
5
+ x
4
+ x
2
+ x + 1
Please note words not defined in the S-Record, or ELF file, will be assumed to be 0xFFFF. This
assumption is because 0xFFFF is the value of a word after its Flash Memory is erased. By default, the
application will CRC32 the entire device. If the program is configured to erase by pages, however, every
page programmed will have its contents verified with the CRC32 algorithm. The speed of the CRC32
algorithm is based partially on the JTAG clock speed. This speed only applies to the 56800E Flash
Programmer. Therefore, if this code were to port to an application, it will run significantly faster because
it would run without the JTAG interface.
C Version of the CRC32 Algorithm
This algorithm assumes there is a 32-bit table named crc32table.The contents of the table are included in
Assembly Version of the CRC32 Algorithm for the DSC
section on page 23. This routine assumes a
long is 32-bits wide.
unsigned long CRC32 (unsigned char *start, unsigned long dwCount,
unsigned long crc)
{
for (unsigned long dwCounter = 0;
dwCounter < (dwCount&0xFFFFFFFc); dw=4 )
{
crc ^= *(DWORD*)(start);
start+=4;
crc = crc32table [ crc & 0xFF ] ^ ( crc >> 8 );
crc = crc32table [ crc & 0xFF ] ^ ( crc >> 8 );
crc = crc32table [ crc & 0xFF ] ^ ( crc >> 8 );
crc = crc32table [ crc & 0xFF ] ^ ( crc >> 8 );
}
for ( ; dwCounter < dwCount; dw+ )
{
crc = crc32table [ (crc ^ *start++) & 0xFF ] ^ ( crc >> 8 );
}
return crc;
}