Flash Magic CRC

Started by amchale, July 01, 2008, 06:31:03 AM

Previous topic - Next topic

amchale

Hi there.  We just started using Flash Magic for loading our new product.  For production purposes, we would like to be able to include the CRC viewed in the "more info" screen independent of the file, generated programmatically.  Simply running the hex file through a standard CRC32 generator does not result in a CRC that matches the one in Flash Magic.  Is the polynomial that FM uses different than the "standard" poly that WinZip et al use?

Thanks for any help you can offer!

Alex

Andy Ayre

It is the 32-bit CCITT CRC, using the following polynomial:

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+X^0

Andy
Embedded Systems Academy, Inc.
support at esacademy dot com

amchale

I appreciate the quick reply.  For all my efforts, though, I cannot get a CRC32 algorithm to duplicate the checksum that FM reports.  Is there any way I could either get the source to the CRC algo it's using, or is there any way to retrieve the CRC of a given file with the FM api?

Thanks!

Alex

Andy Ayre

#3
Embedded Systems Academy, Inc.
support at esacademy dot com

amchale

I still can't get a CRC that matches what FM is reporting.  Is FM taking the CRC of the hex file, the bin file output, or some strange combination or subset of one of the files?  I've tried my test app on both the hex and bin, to no luck.

Thanks for the help.  I really appreciate it.

Andy Ayre

It's a CRC of the hexfile using the code I pointed you to. If you add a space character (0x20) on the end of the file it will change the checksum.

Andy
Embedded Systems Academy, Inc.
support at esacademy dot com

amchale

To anyone referring to this in the future, my problem was that I was reading the file in binary mode, and FM calculates the file based upon reading it in ascii mode.  Thanks for the help, Andy!

eeric7777

#7
Dear Andy,

I've tried the CRC32 macro , but still not work
it must be my code mistake somehow.

Could you kindly show me the code that how you use with CRC32 macro ?

My invalid code.
========================================================
unsigned long crc32(unsigned long crc, const unsigned char *buf, int len)
{
#define CRC32_POLYNOMIAL 0x00400007
    unsigned long crc_table[256];
    unsigned long crc32;
    int i, j;

    for (i = 0; i < 256; i++) {
        crc32 = i;
        for (j = 8; j > 0; j--) {
            if (crc32 & 1)
                crc32 = (crc32 >> 1) ^ CRC32_POLYNOMIAL;
            else
                crc32 >>= 1;
        }
        crc_table = crc32;
    }
  if (buf == NULL) return 0L;
#define CRC32(c,crc) ( crc_table[((int)(crc) ^ (c)) & 0xff] ^ (((crc) >> 8 ) &0x00FFFFFFL))
#define DO1(buf)  crc = CRC32(crc, *buf++)
#define DO2(buf)  DO1(buf); DO1(buf)
#define DO4(buf)  DO2(buf); DO2(buf)
#define DO8(buf)  DO4(buf); DO4(buf)
  crc = crc ^ 0xffffffffL;
#ifndef NO_UNROLLED_LOOPS
  while (len >= 8 ) {
    DO8(buf);
    len -= 8;
  }
#endif
  if (len) do {
    DO1(buf);
  } while (--len);
  return crc ^ 0xffffffffL;
}