Author Topic: Flash Magic CRC  (Read 13000 times)

amchale

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
    • Email
Flash Magic CRC
« on: July 01, 2008, 06:31:03 am »
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

  • ESAcademy Staff
  • Sr. Member
  • *****
  • Posts: 2190
    • View Profile
    • Embedded Systems Academy, Inc.
    • Email
Re: Flash Magic CRC
« Reply #1 on: July 01, 2008, 08:46:23 am »
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

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
    • Email
Re: Flash Magic CRC
« Reply #2 on: July 02, 2008, 01:44:06 pm »
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

  • ESAcademy Staff
  • Sr. Member
  • *****
  • Posts: 2190
    • View Profile
    • Embedded Systems Academy, Inc.
    • Email
Re: Flash Magic CRC
« Reply #3 on: July 03, 2008, 01:44:03 pm »
« Last Edit: July 03, 2008, 01:45:43 pm by Andy Ayre »
Embedded Systems Academy, Inc.
support at esacademy dot com

amchale

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
    • Email
Re: Flash Magic CRC
« Reply #4 on: July 03, 2008, 03:18:16 pm »
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

  • ESAcademy Staff
  • Sr. Member
  • *****
  • Posts: 2190
    • View Profile
    • Embedded Systems Academy, Inc.
    • Email
Re: Flash Magic CRC
« Reply #5 on: July 03, 2008, 03:54:20 pm »
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

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
    • Email
Re: Flash Magic CRC
« Reply #6 on: July 09, 2008, 07:36:25 am »
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

  • Jr. Member
  • **
  • Posts: 1
    • View Profile
Re: Flash Magic CRC
« Reply #7 on: May 08, 2009, 02:20:00 am »
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;
}
« Last Edit: May 09, 2009, 11:15:44 am by eeric7777 »