2019-08-01 04:42 AM
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.
2019-08-19 02:39 AM
Hi Yacob,
As mentioned by waclawek, srec_cat without -fill switch will do what you want. But, it brings another problem: where to put the checksum as srec_cat requires an address. Here is a possible option (simple but not generic) for your reference if your code only stays in single partition of FLASH and you want to put CRC right next to your code:
Regards,
Ethan
2019-08-19 02:52 AM
Hi @Pavel A.
YES, CubeIDE provides Build Variable and Environment Variable. I've known those from TrueSTUDIO but didn't have chance to play those until read your question and decided to test them. Please check my record of my testing in the attached PDF.
Thanks for giving me the opportunity to play with them :)
Regards,
Ethan
2019-08-21 11:22 PM
Hello @Ethan HUANG ,
Thank you for your explanations.
Yacob Hassidim.
2020-02-11 08:08 PM
Hi Guys,
I was able to use srec_cat.exe to append the CRC to the end of a binary file. It worked using the -maxiumum-address flag. Took me a while to work out how to get it to work as the examples were a little confusing. Below are a couple of examples that worked for me:
srec_cat.exe firmware_nocrc.bin -Binary -crc32-l-e -maximum-address firmware_nocrc.bin -Binary -o firmware_crc.bin -Binary
srec_cat.exe firmware_nocrc.bin -Binary -STM32_Little_Endian -maximum-address firmware_nocrc.bin -Binary -o firmware_crc.bin -Binary
I have been successfully able to validate the -crc32-l-e in both JS and a C on the micro. The STM32 one doesn't seem to match the hardware CRC with default settings like I was hoping it would. But that's a story for another forum post if anyone can help there.
Cheers,
Hamish.
2020-02-12 10:14 PM
Hello @HMcKi
Thank you for your response.
I will try it later.
Yacob Hassidim.
2021-01-06 04:31 AM
Hello YHass.14 , Ethan HUANG
Can anyone please tell me here :-
If i want to store generated CRC just after code memory address or end of the code automatically , flexible with changing code size , how can i implement it ? any explaining site link will be very helpful here.
Regards,
Arjun Salariya
2021-01-06 05:17 AM
Need to be familiar with C file functions, fopen, fread, fseek, etc.
You probably want the tools to output a binary to work with, processing a .ELF/AXF or .HEX is possible, but we're here.
The size can be inferred from the binary. You can however use linker symbols to write this size into a location in/after the vector table. The exact method differs for Keil vs GNU/GCC, but has been covered on multiple occasions.
The ST CRC works on 32-bit values, so align suitably.
https://community.st.com/s/question/0D50X0000AIeYIbSQN/stm32f4-crc32-algorithm-headache