IELFTOOL 체크섬 - 기본 동작

기술노트 65473


Arm, STM8




2018-02-28 오전 2:33


Below follows the steps needed to set up an CRC16 checksum calcuation, both in the IAR Embedded Workbench toolchain and in the application.

This note applies to...

...these versions of the following IAR Embedded Workbench products:

IAR Embedded Workbench for ARM 5.11 (and later)

IAR Embedded Workbench for RX 2.10 (and later)

IAR Embedded Workbench for SH 2.10 (and later)

IAR Embedded Workbench for STM8 1.10 (and later)

Include checksum calculation source in your application.

  • The minimum requirement is that your source uses the symbol __checksum.
  • Note: If your source doesn't use the symbol __checksum you will get an error message from IELFTOOL: "The string '__checksum' was not found in the string table".
  • To be able to link anyway, you can turn on Project > Options... > Linker > Extra Options > mark "Use command line options" and add the command line option "--keep __checksum".

Checksum calculation in the application

The supplied example(s) shows how to use the CRC16 checksum calculation. In the C source of the application you need to add the actual generic C source to calculate the same checksum value as IAR Embedded Workbench for ARM calculates. There are two variants of the calculation:

Fast -- Short execution time, but it uses up more ROM/flash for a constant table.

Slow -- It uses less ROM/flash but more execution time.

Please note:

  • The checksum calculation must not (in order to work) be made over the bytes where the checksum is placed in memory. One solution is to place the checksum at the beginning or end of memory. So the bytes (1, 2 or 4) where the checksum is saved must be excluded from the checksum calculation.
  • If the slow function is used, you must make a final call to the checksum calculation with the same number of bytes, with value 0x00, as you have bytes (1, 2 or 4) in the checksum. See the Example (1 range, 3 diff. locations).zip project for details.

Turn on checksum calculation in the options for the linker

You can use these options either in IAR Embedded Workbench or on the command line. If using command line the command should first run the linker, then run IELFTOOL.

In IAR Embedded Workbench you set up calculation of the checksum in menu Project > Options > Linker > Checksum options tab.

The options used in the (place first) example are:
Fill unused code memory
Fill pattern 0xFF (can be any pattern)
Start address 0x0 (adjust to your application)
End address 0xFFFB (adjust to your application)
Generate checksum; size = 2 bytes; CRC16; Complement = as is; Bit order = MSB first; initial value = 0.

The corresponding command line is:

ielftool --fill 0xFF;0x0-0xfffb --checksum __checksum:2,crc16,0x0;0x0-0xfffb

There are 2 requirements that you have to fulfill to make this work. - See the next 2 parts of this tech note.

  • Select the address range to be checksummed. 
  • Select where the chacksum will be placed.

Select the range for which checksum will be calculated

The checksum should (normally) cover all non-RAM bytes of the application, excluding the bytes where the checksum is placed.

The way to get knowledge about this is to turn on

  • menu Project > Options... > Linker > Checksum > mark "Fill unused code memory" and mark "Generate checksum"
  • menu Project > Options... > Linker > List > mark "Generate linker map file"
  • menu Tools > Options... > Messages > Show build messages > All
  • Add usage of the symbol __checksum in your application.
  • Perform one build.
  • Then look in the .map file to see where the symbol __checksum is placed.
  • Look in the "Build Window" to see the memory range that will be used in the checksum calculation.

Specify where the checksum itself is stored

This is done in the .icf file. The following example will place it at the end of memory.

Add this in the .icf file.

place at end of ROM_region { ro section .checksum };

In the 'Example (1 range, 3 diff. locations)', configuration 'PlaceEndOfROM' , the start address is 0x0 and the end address is 0xFFFB.


There are several other solutions on how/where to place the checksum in memory. - These solutions are presented in Technical Note 62709.

All product names are trademarks or registered trademarks of their respective owners.

죄송하지만, 당사 사이트에서는 Internet Explorer를 지원하지 않습니다.보다 편안한 사이트를 위해 Chrome, Edge, Firefox 등과 같은 최신 브라우저를 사용해 주시길 부탁드립니다.