cancel
Showing results for 
Search instead for 
Did you mean: 

How can I calculate CRC of image in post build?

YHass.14
Senior

Hello,

I want to calculate the CRC (32 bit) of image at post build and insert it in a known location in the image.

In order to do it I should perform the following steps:

a) Definition of placeholder in linker script file

b) Post build steps:

b.1) Calculation of image CRC (32 bit)

b.2) Insert it into the placeholder

The reason of 32 bit is to use the STM32 HW CRC calculation for checking the CRC.

The post build steps can be performed by IELFTOOL.

Can anyone help?

Yacob Hassidim.

16 REPLIES 16

srecord is one of the tools which can be used for this purpose.

JW

YHass.14
Senior

Hello,

JW: Can you please detail?

Yacob Hassidim.

Ok, so what's the problem here? You've described the steps

Doesn't IELFTOOL provide documentation for the command line expectations?

Does CubeIDE provide for a method to run scripts, or add lines to the makefile?

If you convert to a binary you could presumably write your own tools to read the file and add the CRC to the end. I've posted examples.

You can embedded image size data via linker symbols so the STM32 side code knows where the end of the code and copied statics falls.

https://community.st.com/s/question/0D50X0000Awa25qSQA/generated-binary-file-size-in-stm32l4

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
YHass.14
Senior

@Community member​: Thanks for the link. It helped me.

I should try your suggestions from the link.

Yacob Hassidim.

Hi Yacob,

Here is a step-by-step for your reference:

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/tree/master/hands-on/06_F746-DISCO-CRC

Please note that this step-by-step is made for STM32CubeIDE v.1.0.0 which has bug of the order of post-build so an workaround (using a batch file checksum.bat in post-build command) is used. This bug has been fixed after STM32CubeIDE v1.0.2 so we can simply use the following without using the batch file:

  1. Add the directory of srec_cat in PATH of Windows Environment Variables.
  2. Enable "Conver to Intel Hex file (-O ihex) in MCU Post build outputs in Tool Settings tab.
  3. Use the following in Post-build steps in Build Steps tab: srec_cat.exe 06_F746-DISCO-CRC.hex -Intel -fill 0xFF 0x08000000 0x08007FFC -STM32 0x08007FFC -o 06_F746-DISCO-CRC_SRECORD.hex -Intel

Regards,

Ethan

Interesting, a custom switch for srec-cat (--STM32).

But adding it to the PATH... Does CubeIDE provide a built-in variable for the toolkit binary path, like other Eclipse based environments?

-- pa

Hello @Ethan HUANG​ 

Thank you for your answer.

How can I calculate the CRC of actual code, i.e. end of the range will not be constant "0x08007FFC" but as actual end of the code?

Sincerely,

Yacob Hassidim.

> How can I calculate the CRC of actual code, i.e. end of the range will not be constant "0x08007FFC" but as actual end of the code?

srec_cat without the -fill switch will do exactly this. The problem is then, where to put the checksum, as srec_cat requires an address.

Play with srec_cat to understand how it works. Read the srecord manual; I know that it's not written very well and it's not an easy reading.

Or, as Clive said above, write your own program to add the checksum - it will then work exactly as you want.

JW

YHass.14
Senior

Hello @Community member​ 

Thank you for your advice.

Yacob Hassidim.