Generating CRC32 from .srec files

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating CRC32 from .srec files

Jump to solution
1,914 Views
Contributor V

I'm using the flash-resident Kinetis 2.x bootloader, and now my goal is to enable CRC checking in the Boot Configuration Area. 

I've read Erich Styger's excellent blog entry on CRC Checksum Generation with ‘SRecord’ Tools for GNU and Eclipse, that has gotten me 80% of the way toward my goal.

The challenge is that the CRC32 algorithm required by the Kinetis 2.0 bootloader is not supported by the SRecord tool suite.  In particular, the bootloader is expecting a CRC32 computed with the following parameters:

     crcUserConfigPtr.crcBits = kCrcBits32;
     crcUserConfigPtr.seed = 0xffffffff;
     crcUserConfigPtr.polynomial = 0x04c11db7U;
     crcUserConfigPtr.complementChecksum = false;
     crcUserConfigPtr.reflectIn = false;
     crcUserConfigPtr.reflectOut = false;

... and neither of the CRC32 algorithms provided with SRecord (CRC32 and STM32) supports this particular combination of parameters (notably reflectIn = false and reflectOut = false).

So: what's the shortest path to generating the CRC32 from a .srec file using those parameters?  Yes, I could write a parser for .srec files, compute the proper CRC and insert it into the Boot Configuration Area using SRecord, but it would seem like someone must have been down this path.  (It would be super if there was an add-on utility for KDS 3.x, but that might be asking too much!  Smiley Happy)

- Robert Poor

P.S. For some more information and context, you may look at this stack overflow entry.

Labels (1)
Tags (2)
1 Solution
108 Views
Contributor V

It turns out that with the right switches and filters, you can use srec_cat to generate a valid  KBoot 2.0 CRC32 from a .srec file:

$ srec_cat test.srec -Bit_Reverse -CRC32LE 0x1000 -Bit_Reverse -XOR 0xff -crop 0x1000 0x1004 -Output -HEX_DUMP 00001000: 93 8F 97 9A                                      #....

In other words, bit reverse the bits going to the CRC32 algorithm, bit reverse them on the way out, and 1's compliment them.  I'm now using this technique to generate CRCs for the Bootloader Configuration Area.

View solution in original post

5 Replies
108 Views
Contributor III
0 Kudos
108 Views
Contributor V

Padmanabh: I looked at the link you provided about generating CRC values from SREC files, and though it uses the same Srecord tool as in the "Correct Answer" above, I believe it will NOT generate the correct CRC for KBoot 2.0 with the switches provided.  

For generating CRC for KBoot 2.0, please refer to:

https://community.nxp.com/thread/462397#comment-955757 

Thanks!

108 Views
NXP Employee
NXP Employee

In addition to Robert's answer, and as well referencing his posts, here are some more details about that subject: Tutorial: CRC32 Checksum with the KBOOT Bootloader | MCU on Eclipse 

I hope this helps,

Erich

0 Kudos
109 Views
Contributor V

It turns out that with the right switches and filters, you can use srec_cat to generate a valid  KBoot 2.0 CRC32 from a .srec file:

$ srec_cat test.srec -Bit_Reverse -CRC32LE 0x1000 -Bit_Reverse -XOR 0xff -crop 0x1000 0x1004 -Output -HEX_DUMP 00001000: 93 8F 97 9A                                      #....

In other words, bit reverse the bits going to the CRC32 algorithm, bit reverse them on the way out, and 1's compliment them.  I'm now using this technique to generate CRCs for the Bootloader Configuration Area.

View solution in original post

108 Views
Contributor IV

Badass find, Robert! I needed this to get the "standard" polynomial for the S32 as well

0 Kudos