Enabling checksum using the IAR toolchain in Simplicity Studio V4

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Ninja Employee</font></font> </a> marao on ‎12-12-2016 02: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

 

  1. Go to the Project. Right click >> Properties
  2. Navigate to C/C++ Build >> Settings
  3. Under IAR Linker for ARM, go to Checksum
  4. Check the required boxeskb4.png
  5. Look at IAR Linker for ARM. You will see that the checksum properties have been appliedkb6.png
  6. Apply changes and Build the project

 

Problem

 

The build fails. 

 

kb5.png

 

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:

 

    1. Go to the Project. Right click >> Properties
    2. Navigate to C/C++ Build >> Settings
    3. Click IAR Linker for ARM. Copy the text in All Options
    4. Paste the instructions in a text editor
    5. Under IAR Linker for ARM, go to Checksum
    6. Check the required boxes
    7. Look at IAR Linker for ARM. You will see that the checksum properties have been applied.
    8. Copy the text in All Options. Paste it in a text editor
    9. Go back to Step 5, uncheck all the boxes and undo the changes made
    10. 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

 

This is the default IAR Linker settings

 

--config "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.5/arm/config/generic_cortex.icf" --no_wrap_diagnostics --semihosting --ihex --bin

 

When the checksum is added (with the check boxes shown in the figure above), the settings change to this

--config "C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.5/arm/config/generic_cortex.icf" --no_wrap_diagnostics --semihosting --ihex --bin --fill 0xFF;0x0-0x0 --checksum __checksum:2,crc16,0x0;0x0-0x0 --place_holder __checksum,2,.checksum,1 --define_symbol __checksum_begin=0x0 --define_symbol __checksum_end=0x0

The text that is different between the two:

--fill 0xFF;0x0-0x0 --checksum __checksum:2,crc16,0x0;0x0-0x0 --place_holder __checksum,2,.checksum,1 --define_symbol __checksum_begin=0x0 --define_symbol __checksum_end=0x0

Now, the "/" escape character needs to be added.

 

--fill 0xFF\;0x0-0x0 --checksum __checksum:2,crc16,0x0\;0x0-0x0 --place_holder __checksum,2,.checksum,1 --define_symbol __checksum_begin=0x0 --define_symbol __checksum_end=0x0 

 

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. 

 

Hence the modified setting would be:

 

--keep __checksum --fill 0xFF\;0x0-0x0 --checksum __checksum:2,crc16,0x0\;0x0-0x0 --place_holder __checksum,2,.checksum,1 --define_symbol __checksum_begin=0x0 --define_symbol __checksum_end=0x0 

Where is this modification supposed 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:

 

kb7.png

 

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.