IELFTOOL Checksum - The basic actions
Technical Note 65473
Arkitekturer:
Arm, STM8
Komponent:
general
Uppdaterad:
2017-12-29 16:33
Introduction
This technical note applies to the IAR Systems products that use the ILINK linker. The description below describes the basic actions needed to use the CRC16 checksum calculation in the application.
Discussion
Starting to use CRC16 checksum calculation implies these basic actions:
- Including and using the CRC16 source of checksum calculation in the application.
- Selecting the Checksum options in the IAR Embedded Workbench IDE.
Assumptions for the further discussion
For the rest of the text in this technical note it will be assumed that:
- A hypothetical device is used. It has read-only memory in the address-range of
0x0000
to0xFFFF
.
Including and using the CRC16 source for checksum calculation in the application
You must consider the following actions when adding the CRC16 source:
- Make sure that your application source uses the symbol
__checksum
. - Note: If your application source doesn't use the symbol
__checksum
you will get an error message fromielftool.exe
:
The string '__checksum' was not found in the string table.
The example projects show how to use the CRC16 checksum calculation. In the application you must add the CRC16 source for checksum calculation. There are two variants of the calculation:
- Fast -- Short execution time (uses more ROM/flash memory for a constant table).
- Slow -- It uses less ROM/flash memory (but has a longer execution time).
Important notes on the checksum calculation algorithm in the application
- The checksum calculation must not (in order to work) be made over the bytes where the checksum is stored in memory. So the address-range (for 1, 2 or 4 bytes) where the checksum is stored must be excluded from the checksum calculation.
- One approach is to store the checksum at the beginning or end of memory, as that makes it easier to setup the address-range correctly.
- If the slow calculation is used, your source must make an extra and final call to the slow checksum calculation. Make the call with the value 0x00 and the same number of bytes as the size (1, 2 or 4 bytes) of the checksum. See the example projects for details.
Selecting options for the checksum calculation in ielftool
In the IAR Embedded Workbench IDE, set options on the page Project>Options>Linker>Checksum. The settings used in the example projects 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
- Checksum size: 2 bytes
- Algorithm: CRC16
- Complement: as is
- Bit order: MSB first
- Initial value:
0
Fulfil the requirements to generate a correct checksum
There are two requirements that you must fulfill to make ielftool.exe
generate a correct checksum:
- Specify where the checksum value will be stored.
- Check the address range for which to calculate a checksum.
Specify where to store the checksum
Where the checksum is stored is controlled with directives in the linker configuration file. The following example will store the checksum at the end of memory. Add this line in the linker configuration file:
place at end of ROM_region { ro section .checksum };
Check the address range for the checksum calculation
Make sure the checksum is calculated for all read-only bytes of the application, excluding the bytes where the checksum value is stored.
Get knowledge about this by applying the following steps:
- Select Project>Options>Linker>List>Generate linker map file
- Select Tools>Options>Messages>Show build messages>All
- Build the application one time. (This is done to generate information for steps 4 and 5 below.)
- Look in the
.map
file. Search for the symbol__checksum
to check the address where__checksum
is stored. - Look at the Build window. Read the build messages for
ielftool.exe
to get the memory range to use in the checksum calculation.
The example projects
In the example projects, the start address is set to:
0x0
(for ARM)0x8000
(for STM8).
The end address is set to 0xFFFB
.
Links to the example projects:
Conclusion
You must consider the actions and precautions described in this Technical Note when you start to use CRC in your project.
There are more Technical Notes that can be useful to read. Examples are:
The Technical Note 11927, holds information about:
- General comments on checksum calculation using
ielftool.exe
. - Links to other Technical Notes that cover special cases of checksum handling.
Other suggestions on how/where to store the checksum in memory are described in Technical Note 62709.
All product names are trademarks or registered trademarks of their respective owners.