Enabling checksum using the IAR toolchain in Simplicity Studio V4
12/347/2016 | 08:39 PM
What is Checksum? Why use it?
Checksum is one of the oldest methods of ensuring that data has not been corrupted during transmission or encryption. Checksum also provides a form of authentication because an invalid checksum suggests that data has been compromised in some fashion.
Example:
Let's say a transmission packet has 1,100 bytes and the checksum of a packet is 1 byte long. This means that there is a total of 256 possible combinations. If the sum of the other bytes in the packet is 255 or less, then the checksum will contain that exact value. If the sum of the other bytes is more than 255, then the checksum is the remainder of the total value after it has been divided by 256.
So, in case of a packet with 1100 bytes:
1100/256 = 4.296 (round to 4)
4*256 = 1024
1100 - 1024 = 76 checksum
Okay, great! How do I enable checksum?
How to enable checksum to a project using the IAR toolchain WITH build errors
Go to the Project. Right click >> Properties
Navigate to C/C++ Build >> Settings
Under IAR Linker for ARM, go to Checksum
Check the required boxes
Look at IAR Linker for ARM. You will see that the checksum properties have been applied
Apply changes and Build the project
Problem
The build fails.
Cause
The ielftool executable that is called requires the ";" character to denote the range the checksum will be calculated from, but due to the fact that the makefile commands are called through a bash script, the ";" acts as an command separator and the command falls apart.
Solution
One of the ways to ensure the ";" is treated as a range instead of a command separator is to use the escape character. In bash scripts, the escape character is "\". There is some back and forth that needs to be done to fix this, so make sure you follow the instructions carefully.
Steps to be followed to enable checksum without build errors:
Go to the Project. Right click >> Properties
Navigate to C/C++ Build >> Settings
Click IAR Linker for ARM. Copy the text in All Options
Paste the instructions in a text editor
Under IAR Linker for ARM, go to Checksum
Check the required boxes
Look at IAR Linker for ARM. You will see that the checksum properties have been applied.
Copy the text in All Options. Paste it in a text editor
Go back to Step 5, uncheck all the boxes and undo the changes made
Click Ok.
Adding escape characters
The text copied from Step 8 will be longer than Step 4. Copy the text in Step 8 that is different from Step 4. It will usually begin with --fill.
If one tries to build the project now, the following error message will be seen:
IELFTOOL: "The string '__checksum' was not found in the string table".
This happens becasue our source doesn't use the symbol __checksum. to be able to link anyway, the command line option "--keep __checksum" needs to be added.
This should be pasted AFTER step 10, by navigating to Project Properties >> C/C++ Build >> Settings >> IAR Linker for ARM >> Extra Options. Paste the text above in the extra options text box:
Build the project once these changes have been made. This will be a one time fix for the project and subsequently checksum can be used for authentication/data corruption checks.
Enabling checksum using the IAR toolchain in Simplicity Studio V4