After reading this blog, you will understand how to calculate CRC of hex file using SREC tool with example.
1. Introduction :
SREC is an open source tool. SREC is powerful tool package to play with HEX files. As name is SREC it does not mean it is meant for Motorola SREC format, it will work on other formats too (Intel). Yo can download SREC tool package from here http://srecord.sourceforge.net/download.html. Also download its manual for more use http://srecord.sourceforge.net/srecord-1.64.pdf
SREC package contains powerful tools.
1. srec_cat
2. srec_cmp
3. srec_info
Out of these three tools, srec_cat is most powerful tool used for hex file manipulation. i.e.one use is to calculate CRC of hex file.
2. How to calculate checksum :
Step 1: Download SREC tool package and extract it in one folder.
Fig. 1 SREC tool package download path |
Step 2: Copy your hex file into the folder (It is not mandatory to copy hex file in the same folder, for an example we are keeping here).
Step 3: Open command window from a folder where SREC tools present. Below image shows SREC tool packages with hex files (Motorola S19 and intel hex file)
Fig. 2 SREC package |
Now we need to use srec_cat to calculate CRC of hex file. Syntax is as mentioned below
srec_cat <input hex file path> -fill <pattern to fill holes in hex file> <address range over which holes need to fill> -crop<range of address range over which CRC to be calculated> -crc32_Big_endian <address to store CRC> -crop <address range where CRC is stored> -o --hex-dump
e.g. Consider Fig.2, we will calculate CRC of sample.hex over address 0x00 to 0xFF and CRC should be stored at 0x1000 in big endain format and CRC32 algorithm is used.(Check manual for more help)
srec_cat sample.hex -fill 0x00 0x00 0xFF -crop 0x00 0xFF -CRC32_big_endian 0x1000 -crop 0x1000 0x1005 -o --hex-dump
Fi.3 shows how you will see output.
--hex-dump : - is to display output CRC on command prompt and -hex-dump is an option to display CRC in hex dump format.
Now to store CRC into hex file use below command
srec_cat sample.hex -fill 0x00 0x00 0xFF -crop 0x00 0xFF -CRC32_big_endian 0x1000 -crop 0x1000 0x1005 -o sample.hex
Refer manual for more options to play with output format of hex file.
Fig. 3 CRC of hex file |