IAR EWARM Checksum Technical Note
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:
|
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...
|
||||
| • |
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; |
| • |
The linker configuration file adds a ROM-block with fixed order: define block ROM_CONTENT with fixed order |
| • |
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 |
| • |
The "Project > Options > Build Actions > Post-build command line" adds the ielftool command ielftool --fill 0xFF;checksum_start-checksum_end+3 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的更多相关文章
- 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU硬件那些事(2.5)- 串行NOR Flash下载算法(IAR EWARM篇)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是IAR开发环境下i.MXRT的串行NOR Flash下载算法设计. 在i.MXRT硬件那些事系列之<在串行NOR Flash XI ...
- IAR EWARM 字体设置
如果只想简单的设置,可进行如下设置 Tools->IDE Options->Editor->Colors and Fonts->Editor Font->Font 但是这 ...
- 安装IAR ewarm
一 安装准备 (ST方案) 1 嵌入式集成开发环境IAR ewarm 5.41 2 J-Link4.20 3 emberznet-4.3.0协议栈安装包 option1:tools - stm32软 ...
- IAR EWARM Argument variables $PROJ_DIR$ $TOOLKIT_DIR$
在IAR中的help中输入argument variables时会找到这样的一个列表: Argument variables On many of the pages in the Options d ...
- IAR EWARM Example Download List
https://srv.iar.com/ExamplesOnDemand/versions.xml http://netstorage.iar.com/SuppDB/Public/EXAMPLES/0 ...
- IAR EWARM PRINTF/SCANF FORMATTER
The linker automatically chooses an appropriate formatter for printf- and scanf-related function bas ...
- IAR EWARM : Debugging with CMSIS-DAP
- IAR EWARM 关闭纯汇编函数的警告的方法
/关闭警告 #pragma diag_suppress=Pe940 uint8_t GetMyData(void) { asm(“MOV R0, #0x550F”); } //恢复警告 #pragma ...
- 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 ...
随机推荐
- MyCat分库分表入门
1.分区 对业务透明,分区只不过把存放数据的文件分成了许多小块,例如mysql中的一张表对应三个文件.MYD,MYI,frm. 根据一定的规则把数据文件(MYD)和索引文件(MYI)进行了分割,分区后 ...
- 大话C#中能使用foreach的集合的实现
大家都知道foreach的语法:foreach(var item in items){ Console.Writeln(item);} 通过这样一个简单的语句,就能实现遍历集合items中的所有元素. ...
- Linux驱动技术(五) _设备阻塞/非阻塞读写【转】
转自:http://www.cnblogs.com/xiaojiang1025/p/6377925.html 等待队列是内核中实现进程调度的一个十分重要的数据结构,其任务是维护一个链表,链表中每一个节 ...
- C语言清空输入缓冲区的N种方法对比【转】
转自:http://www.cnblogs.com/codingmylife/archive/2010/04/18/1714954.html C语言中有几个基本输入函数: //获取字符系列 int f ...
- Python发送邮件:smtplib、sendmail
本地Ubuntu 18.04,本地Python 3.6.5, 阿里云Ubuntu 16.04,阿里云Python 3.5.2, smtplib,sendmail 8.15.2, 今天,打算实现通过电子 ...
- 浅谈js设计模式之发布 — 订阅模式
发布 — 订阅模式又叫观察者模式,它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知.在 JavaScript开发中,我们一般用事件模型来替代传统的发布 — ...
- 【linux】监控磁盘情况并自动删除备份文件
背景:我有一个备份目录/home/kzy/bakup,会每天备份一些信息.随着日子一天天的过去,这个文件夹越来越大,终于把磁盘撑满了..... 需求:当磁盘占有率超过80%时自动删除该文件夹下最老的3 ...
- CF1063A 【Oh Those Palindromes】
考虑在一个部分串中加入字符使得最终构造的串回文子串最多的方案 考虑简单情况,对于只含一种元素的串,我们要插入其他元素 记原有元素为$a$,新加元素为$b$ 考虑$b$的最优插入位置 原串$aaaa.. ...
- Servlet 3.0 新特性详解
转自:http://www.ibm.com/developerworks/cn/java/j-lo-servlet30/#major3 Servlet 是 Java EE 规范体系的重要组成部分,也是 ...
- Java编程的逻辑 (69) - 线程的中断
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...