Checksum generation for ModusToolbox™ hex file - KBA236086
Community Translation: ModusToolbox™ hex ファイルのチェックサム生成 - KBA236086
It is often a requirement for a custom programmer tool to detect any tamperings with the hex file that is to be flashed into a PSoC™ device. In such situations, it is helpful if the programmer software can calculate the checksum of the hex file and compare this value with the checksum at address location 0x90300000 and if both match, then it indicates that the hex file is tamper-free.
The checksum for the hex file generated in ModusToolbox™ can be generated and loaded in address location 0x90300000 by using the python script.
To use the python script, do the following:
- Extract and copy the ‘hexCheckSumScript.py’ file to the folder containing the hex file, such as ‘mtb-example.hex’, whose checksum is to be calculated.
- Open a command prompt (Win Key + R and open ‘cmd’)
- Navigate to the folder containing ‘hexCheckSumScript.py’ and the ‘mtb-example.hex’ using the command “cd <path to folder >”
- Run the following command to get the checksum of the hex file:
- python hexCheckSumScript.py <Name of hex file>
After the script runs, it generates a new hex file with the prefix “csout_” in the same folder in which the python script and the input hex file are located.
Figure 1 Script execution & output hex file generation
Verify if the checksum has been added to the hex file by checking the last three lines of the generated hex file as shown in Figure 2.
Figure 2 Location of checksum in generated hex
The custom programmer software verifies if the hex file has been corrupted/modified by calculating the checksum of the hex file and comparing the same with the hex file value mentioned in the second last line ( 0xD07C as shown in Figure2).
Note: Python version tested on v3.10.4
- hex file