IELFTOOL Checksum - Basic actions

EW targets: ARM, RH850, RX, SH, STM8
EW component: General issues
Last update: September 6, 2013

Below follows the steps needed to set up an CRC16 checksum calcuation, both in the EW-tool-chain and in the application.

This note applies to...
...these versions of the following Embedded Workbenches products:
EWARM 5.11 (and later) - - - EWRX 2.10 (and later)
EWSH 2.10 (and later) - - - EWSTM8 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 EWARM 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)' project for details. (Use the link to the upper right.)

Turn on checksum calculation in the options for the linker

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

In the EW 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 the 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.

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

EWARM - Example (1 range, 3 diff. locations) (ZIP, 170 KB)

Technical note 11927
Checksum calculation with IELFTOOL after linking with ILINK

Technical note 52619
IELFTOOL Checksum - When using LPC device

Technical note 53274
IELFTOOL Checksum - over several ranges

Technical note 62709
IELFTOOL Checksum - Placing the checksum

Checksum calculation with IELFTOOL after linking with ILINK

Technical Note 11927

EW targets: ARM, RH850, RX, SH, STM8
EW component: General issues
Keywords: checksum calculation
Last update: February 4, 2015

This tech note is the 'main tech note' for the set of tech notes that covers different aspects of CRC checksum calculations in these EW-tool-chains.

The set of tech notes applies to...
...these versions of the Embedded Workbenches (uses Elf/Dwarf as file format in the tool-chain). The Tech Note applies to:

EWARM 5.11 (and later)

EWRX 2.10 (and later)

EWSH 2.10 (and later)

EWSTM8 1.10 (and later)

Background information on IEFLTOOL
In IAR tool-chains with the ILINK linker, the checksum calculation is done in IELFTOOL. So if a checksum is to be calculated then ILINK links the application, passes on (to IELFTOOL) the commands for filling and checksum calculation, and IELFTOOL does the calculation.

Overview - I.e. steps that has to be done in order to get a checksum in the output of the project

You need to include checksum calculation source in your application.

You need to turn on checksum calculation in the options for the linker.

You must select for which memory range IELFTOOL will calculate the checksum.

You must decide where the checksum will reside in the memory.

Details of the checksum calculation
The details (of checksum) are placed in these sub tech notes:

IELFTOOL Checksum - Basic actions - Tech note 65473 - The steps needed to set it up.

IELFTOOL Checksum - Placing the checksum - Tech note 62709 - The locations where the checksum can be placed.

IELFTOOL Checksum - over several ranges - Tech note 53274.

The details (for specific devices) are placed in these sub tech notes:

Calculate CRC32 as in STM32 hardware (v.5.50 and later) - Tech note 64424 - (using the built-in hardware CRC32 calculator in STM32 devices from ST).

Calculate CRC32 as in K60 hardware - Tech note 85753 - (using the built-in hardware CRC32 calculator in K60-device from Freescale).

IELFTOOL Checksum - When using LPC device - Tech note 52619 - (Extra considerations for LPC devices from NXP.)

More information
There is more information about the checksum in the .htm read-me-file for ILINKand in the .pdf DevelopmentGuide file. These files are found in your installation.

Mr. Ross N. Williams at Rocksoft in Australia have written, what he calls: A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS and this document can be down loaded from the link CRC explained by Mr. Ross N. Williams to the right.

IELFTOOL Checksum - over several ranges

Technical Note 53274

EW targets: ARM, RH850, RX, SH, STM8
EW component: General issues
Keywords: checksum calculation
Last update: September 6, 2013

The checksum calculation can be made over several ranges. If several ranges are used, then please note:

The GUI accepts only one range, so you need to turn off the checksum options, and instead...

...enter some command line options in Project > Options... > Linker > "Extra options".

...enter some command line options to "build actions" > "post build command line"

Be careful to calculate (in the application) the ranges with the lowest address range first and so on.

The calculation (in the application) will not be able to use checksum symbols (defined by the GUI), so you need to make some effort to use correct ranges in the application.

Two ranges - two checksum values

See example project 'Example: Two ranges two checksums' .

The 1st range is 0x1006000 to 0x102FFFB and the 2nd range 0x1030000 to 0x103EFFB.

Three changes are required:

1. The changes for ILINK are made at "Project > Options... > Linker > Extra options".

Add the following:

--place_holder __checksum1,2,.checksum1,1
--place_holder __checksum2,2,.checksum2,1
--define_symbol __checksum_begin1=0x1006000
--define_symbol __checksum_end1=0x102FFFB
--define_symbol __checksum_begin2=0x1030000
--define_symbol __checksum_end2=0x103EFFB

2. Use a post-build command line to perform the checksum calculation, by setting "Project > Options... > Build Actions > Post-build command line"

ielftool --fill 0xFF;0x1006000-0x102FFFB  --fill 0xFF;0x1030000-0x103EFFB
--checksum __checksum1:2,crc16,0x0;0x1006000-0x102FFFB
--checksum __checksum2:2,crc16,0x0;0x1030000-0x103EFFB
--verbose "$TARGET_PATH$" "$TARGET_PATH$"

3. In the .icf file, define memory ranges and where to place the checksums:

define symbol __ICFEDIT_region_ROM_start__   = 0x1006000;
define symbol __ICFEDIT_region_ROM_end__ = 0x102FFFF; define symbol __ICFEDIT_region_PFM_start__ = 0x1030000;
define symbol __ICFEDIT_region_PFM_end__ = 0x103EFFF; define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__
to __ICFEDIT_region_ROM_end__]; define region PFM_region = mem:[from __ICFEDIT_region_PFM_start__
to __ICFEDIT_region_PFM_end__]; place at end of ROM_region { readonly section .checksum1 };
place at end of PFM_region { readonly section .checksum2 };
Two ranges - one checksum value

See example project 'Example: Two ranges one checksum' .

The 1st range is 0x1006000 to 0x102FFFB and the 2nd range is 0x1030000 to 0x103EFFF.

Three changes are required:

1. The changes for ILINK are made at "Project > Options... > Linker > Extra options".

Add the following:

--place_holder __checksum,2,.checksum,1
--define_symbol __checksum_begin1=0x1006000
--define_symbol __checksum_end1=0x102FFFB
--define_symbol __checksum_begin2=0x1030000
--define_symbol __checksum_end2=0x103EFFF

2. Use a post-build command line to perform the checksum calculation, by setting "Project > Options... > Build Actions > Post-build command line"

ielftool --fill 0xFF;0x1006000-0x102FFFB --fill 0xFF;0x1030000-0x103EFFF
--checksum __checksum1:2,crc16,0x0;0x1006000-0x102FFFB;0x1030000-0x103EFFF
--verbose "$TARGET_PATH$" "$TARGET_PATH$"

3. In the .icf file, define memory ranges and where to place the checksum:

define symbol __ICFEDIT_region_ROM_start__   = 0x1006000;
define symbol __ICFEDIT_region_ROM_end__ = 0x102FFFF; define symbol __ICFEDIT_region_PFM_start__ = 0x1030000;
define symbol __ICFEDIT_region_PFM_end__ = 0x103EFFF; define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__
to __ICFEDIT_region_ROM_end__]; define region PFM_region = mem:[from __ICFEDIT_region_PFM_start__
to __ICFEDIT_region_PFM_end__]; place at end of ROM_region { readonly section .checksum };

Example: Two ranges two checksums (ZIP, 103 KB)

Example: Two ranges one checksum (ZIP, 100 KB)

IELFTOOL Checksum - Placing the checksum

Technical Note 62709

EW targets: ARM, RH850, RX, SH, STM8
EW component: General issues
Keywords: checksum calculation
Last update: September 6, 2013

Here follows the possibilities for placement of the checksum.

Place last in memory.

Covered in the tech note 65473

Placing it before the start of application code.
define block CHECKSUM { ro section .checksum };
place in ROM_region { ro, first block CHECKSUM };

In the example 'Example (1 range, 3 diff. locations)', configuration 'PlaceInFirstBlock' , the start address is 0x84 and the end address is 0xFFFF.

Note: The start address is after the interrupt vector and after the checksum value, i.e. in this case, the checksum calculation does not include the interrupt vector (normally located at address 0x0 and placed with a specific "place at" directive).

Placing it after the end of the application code.
define block CHECKSUM { ro section .checksum };
place in ROM_region { ro, last block CHECKSUM };

In the 'Example (1 range, 3 diff. locations)', configuration 'PlaceInLastBlock' , the start address is 0x0 and the end address is 0x296B. During development the actual application end address will vary from build to build, thus it will become cumbersome to change the end address often (as the checksum must be placed outside the memory which is checksummed). Recommended is to use this configuration in the release phase of the project. Note: To overcome this inconvenience, see the alternative solution using checksum-start and checksum-end markers.

The ordinary (one range) example

The 'Example (1 range, 3 diff. locations)', includes the actual generic C source to calculate the same checksum value as IELFTOOL produces in its CRC calculation. It also contains EW settings for ILINK/IELFTOOL and modified .icf files for placing the CHECKSUM section at a specified place in memory.

There are three EW project configurations in the example 'Example (1 range, 3 diff. locations)' , where the checksum is placed in three different ways:

Placed at the very end of ROM (configuration PlaceEndOfROM).

Placed before the start of the application code (configuration PlaceInFirstBlock).

Placed after the end of the application code (configuration PlaceInLastBlock).

Alternative solution using checksum-start and checksum-end markers

The normal procedure for checksum calculation is to open the dialog "Options > Linker > Checksum" and enable "Fill unused memory", specify a fill pattern, also specify address range (start address, end address) - next enable "Generate checksum" and specify the algorithm.

The inconvenience of using this dialog is that the start address and end address have to be adjusted to match the application.

The start address is usually fixed, but the end address need to be adjusted from time to time, and this alternative solution is trying to overcome this inconvenience by using special symbols (checksum_start and checksum_end).

The main differences in 'Example (alternative solution with start and end markers)', compared to 'Example (1 range, 3 diff. locations) configuration PlaceInLastBlock' are

Menu "Project > Options... > Linker > Checksum > mark "Fill unused code memory" is NOT selected.

The C/C++ source adds checksum-start and checksum-end markers

__root const unsigned char  checksum_start    @ "checksum_start_mark" = 0;
__root const unsigned char checksum_end[4] @ "checksum_end_mark" = {0,0,0,0xEE}; // The last byte is the actual "checksum area end mark"
// Any values can be assigned to the start and end markers.
// The keyword __root is only needed if the source is not referencing these symbols.

The linker configuration file adds a ROM-block with fixed order:

define block ROM_CONTENT with fixed order
{
readonly section checksum_start_mark,
readonly,
readonly section checksum_end_mark,
readonly section checksum
}; place in ROM_region { block ROM_CONTENT };

The C/C++ source references the checksum value using an extern declaration

extern const unsigned short ielftool_checksum;

The "Project > Options > Linker > Extra Options > Use command line options" adds --place_holder to create/reserve space for the checksum symbol and --keep to make sure that the symbol is included

--place_holder ielftool_checksum,2,checksum,4
--keep=ielftool_checksum

The "Project > Options > Build Actions > Post-build command line" adds the ielftool command

ielftool --fill 0xFF;checksum_start-checksum_end+3
--checksum ielftool_checksum:2,crc16,0x0;checksum_start-checksum_end+3
--verbose "$TARGET_PATH$" "$TARGET_PATH$"

Note: The block ROM_CONTENT does not include the interrupt vector, which is normally located at address 0x0 and placed with a specific "place at" directive. To include the interrupt vector in the checksum calculation, replace "checksum_start" with 0x0 in the ielftool command line for both option --fill and option --checksum.

Output Converter - Binary file does not include checksum

EW targets: ARM, RX, SH, STM8
EW component: General issues
Last update: February 12, 2013
Problem

The option "Output Converter > Output > Generate additional output > Output format:

binary" is set, but the checksum of the application is not included in the generated binary file.

Solution

Probably the checksum is calculated using a post-build command line.

See Technical Note 52619 (Solution 2 and 3) about using a .bat file invoked from the post-build command line.

IELFTOOL Checksum - When using LPC device

Technical Note 52619

EW targets: ARM
EW component: General issues
Keywords: checksum calculation
Last update: February 12, 2013

Note for NXP LPC devices:
The LPC devices needs a special checksum to be placed at a specific address (in the vector table). IAR Embedded Workbench will automatically calculate this checksum and place it.
But the CRC checksum that these set of tech notes discuss must not be calculated over this special checksum in the vector table.

Problem 1 - ielftool error

When you build you get the error
ielftool error: Checksums have dependencies

The error is issued since both the vector table checksum and the application checksum are calculated by the same ielftool command.

Solution 1 - exclude the vector table

The solution is to exclude the vector table from the calculation of the application checksum, which can be done by setting the start address to the first address that follows the vector table.

Change option "Linker > Checksum > Start address" from 0x0 to 0x40.

(Check the .map file to find the end address of section .intvec)

Problem 2 - checksum have to include the vector table

The checksum of your application have to include the vector table too, but "Solution 1" excludes the vector table.

Solution 2 - use post-build command line

If you use a post-build command line, the two checksums will be calculated by separate ielftool commands, i.e. avoiding the dependency that caused the ielftool error, and the start address 0x0 can be used.

1. Deselect option "Linker > Checksum > Fill unused code memory".

2. Add option "Linker > Extra Options > Use command line options"

--place_holder  __checksum,2,.checksum,1
--define_symbol __checksum_begin=0x0
--define_symbol __checksum_end=0xfffb

3. Set option "Build Actions > Post-build command line"

ielftool --fill 0xFF;0x0-0xfffb --checksum __checksum:2,crc16,0x0;0x0-0xfffb
--verbose "$TARGET_PATH$" "$TARGET_PATH$"
Problem 3 - binary file does not include checksum

The option "Output Converter > Output > Generate additional output > Output format: binary" is set, but the checksum of the application is not included in the generated binary file.

The reason is that the binary file is generated after linking but before the post-build action, i.e. before the checksum is calculated by the post-build action!

Solution 3 - use post-build .bat file

The solution is to let the post-build command line invoke a .bat file that first calculates the checksum and then generates additional output.

See example project 'EWARM - Example (LPC device)' (link to the upper right).

EWARM - Example (LPC device) (ZIP, 114 KB)

Note: This example project is based on the 'Example (1 range, 3 diff. locations)', configuration 'PlaceEndOfROM'.

The target is changed to LPC1768 in order to provoke the ielftool error, but the address range over which the checksum is calculated is still the same as in the original example project.

Description:

1. Set option "Build Actions > Post-build command line"

$PROJ_DIR$\post-build.bat "$TARGET_BPATH$"

2. Create file post-build.bat in the project folder, with the following content:

set OUT=%1.out
set HEX=%1.hex
set BIN=%1.bin :: calculate application checksum
ielftool --fill 0xFF;0x0-0xfffb --checksum __checksum:2,crc16,0x0;0x0-0xfffb
--verbose %OUT% %OUT% :: generate additional ouput: hex
ielftool.exe --ihex --verbose %OUT% %HEX% :: generate additional ouput: binary
ielftool.exe --bin --verbose %OUT% %BIN%

IAR EWARM Checksum Technical Note的更多相关文章

  1. 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.5)- 串行NOR Flash下载算法(IAR EWARM篇)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是IAR开发环境下i.MXRT的串行NOR Flash下载算法设计. 在i.MXRT硬件那些事系列之<在串行NOR Flash XI ...

  2. IAR EWARM 字体设置

    如果只想简单的设置,可进行如下设置 Tools->IDE Options->Editor->Colors and Fonts->Editor Font->Font 但是这 ...

  3. 安装IAR ewarm

    一  安装准备 (ST方案) 1 嵌入式集成开发环境IAR ewarm 5.41 2 J-Link4.20 3 emberznet-4.3.0协议栈安装包 option1:tools - stm32软 ...

  4. IAR EWARM Argument variables $PROJ_DIR$ $TOOLKIT_DIR$

    在IAR中的help中输入argument variables时会找到这样的一个列表: Argument variables On many of the pages in the Options d ...

  5. IAR EWARM Example Download List

    https://srv.iar.com/ExamplesOnDemand/versions.xml http://netstorage.iar.com/SuppDB/Public/EXAMPLES/0 ...

  6. IAR EWARM PRINTF/SCANF FORMATTER

    The linker automatically chooses an appropriate formatter for printf- and scanf-related function bas ...

  7. IAR EWARM : Debugging with CMSIS-DAP

  8. IAR EWARM 关闭纯汇编函数的警告的方法

    /关闭警告 #pragma diag_suppress=Pe940 uint8_t GetMyData(void) { asm(“MOV R0, #0x550F”); } //恢复警告 #pragma ...

  9. IAR EWARM __iar_program_start, __iar_data_init3, __iar_copy_init3, __iar_zero_init3

    #include <stdint.h> // The type of a pointer into the init table. typedef void const * table_p ...

随机推荐

  1. python 入门基础4 --数据类型及内置方法

    今日目录: 零.解压赋值+for循环 一. 可变/不可变和有序/无序 二.基本数据类型及内置方法 1.整型 int 2.浮点型float 3.字符串类型 4.列表类型 三.后期补充内容 零.解压赋值+ ...

  2. Python 入门基础9 --函数基础2 实参与形参

    今日内容: 一.函数参数 1.形参与实参定义 2.实参分类 3.形参分类 4.可变参数的整体使用 一.形参与实参定义 def fn(参数们): pass 1.1 形参 定义函数,在括号内声明的变量名, ...

  3. linux c中select使用方法

    1.select函数作为定时器使用    it_value.tv_sec = 0;    it_value.tv_usec = 100000:    select(1,NULL,NULL,NULL,& ...

  4. Unity 网格 绘制

    网格绘制主要用是对Mesh进行操作,通过对vertex和triangles进行操作生成对应的面片: 这里首先得用到一个类:Triangulator(根据vertex生成triangles数组) usi ...

  5. 【题解】BZOJ 1901: Zju2112 Dynamic Rankings

    题目传送门(权限题) 一道类似的非权限题 题意 N个数的序列,每次修改一个数或者询问区间里的第K小.可以离线. 简要做法 假如要求在线,可以树状数组套个线段树~ 但是这题是可以离线的,就可以乱搞整体二 ...

  6. Python实现 -- 冒泡排序、选择排序、插入排序

    冒泡排序 冒泡排序(Bubble Sort),是一种计算机科学领域的较简单的排序算法. 冒泡排序的原理: 比较两个相邻的元素,如果第一个比第二个大,就交换他们 对每一对相邻的元素做同样的工作,从开始第 ...

  7. 初始ASP.NET数据控件【续 ListView】

    ListView控件   ListView控件可以用来显示数据,它还提供编辑,删除,插入,分页与排序等功能.ListView是GridView与DataList的融合体,它具有GridView控件编辑 ...

  8. LeetCode(13):罗马数字转整数

    Easy! 题目描述: 罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写 ...

  9. MAC下代理工具Charles使用

    一.跟踪HTTPS 1.下载官方的证书ssl.zip证书,解压成*.crt 2.可以通过邮箱或者发布到自己的服务器的方式,然后用手机去下载安装crt文件. 3.charles设置Proxy--> ...

  10. .NetCore 分页控件实现原理处理以及条件分页处理

    说明 自定义一个类继承TagHelper,注意自定义类的 必须以TagHelper结尾,这个有点类是属性 Attribute的写法 protected TagHelper(); // // 摘要: / ...