Signature Creator for NXP Cortex-M Devices

Algorithm for creating the checksum

The reserved Cortex-M3 exception vector location 7 (offset 0x001C in the vector table)

should contain the 2’s complement of the check-sum of table entries 0 through 6.

This causes the checksum of the first 8 table entries to be 0.

The boot loader code checksums the first 8 locations in sector 0 of the flash.

If the result is 0, then execution control is transferred to the user code.

Application integrity check

Following a reset the secondary bootloader checks if there is a valid image contained

within the application flash sectors.

It does this by generating a 16-bit CRC of the application flash sectors

and comparing it to the value stored in the last 2 bytes of flash memory.

If the two values match then the secondary bootloader executes the application,

if not the process of downloading a new application is started.

NXP LPC parts use a word in the vector table of the processor to store a checksum

that is examined by the bootloader to identify a valid image.

For ARM7/ARM9 based parts this checksum word is stored at offset 0x14,

for Cortex-M based parts it is stored at offset 0x1C

Note: 

This checksum is calculated from the contents of the vector table, not the whole image.

For more details please see the user manual for the MCU that you are using.

When downloading code via the debugger, this checksum word

will be filled in automatically as the image is downloaded.

When creating a binary file, you will need to ensure that you run the supplied checksum utility

to post-process the binary yourself.

If you modify the supplied post-build step to create your binary

(as per the FAQ Post-processing your linked application,

then this will normally be done automatically by the post-build step:

checksum -p ${TargetChip} -d ${BuildArtifactFileBaseName}.bin;  

But if you need to create a hex file for use by FlashMagic care needs to be taken

that you do not run the checksum utility on the hex file itself.

The checksum utility only works on binary files, not hex files.

Therefore, the checksum utilty will corrupt your hex file if you use the hex file as input.

Note that FlashMagic will automatically set the checksum word for you

when you use it to program a hex file to an LPC device.

But if you wish to set the checksum yourself, then the recommend way of creating such a hex file is as follows:

  • convert to binary

  • run the checkum utility

  • convert the binary in hex, using 
    arm-none-eabi-objcopy -I binary -O ihex myfile.bin myfile.hex

Generating other types of checksum

There are many other different types of checksums that users may want to perform on an image.

A great tool for manipulating image files and generating a variety of checksums is the Open Source SRecord Tool.

ARM: LPC18xx/43xx

On-chip Flash Loader Vector Checksum Calculation

Information in this knowledgebase article applies to:

  • MDK-ARM
  • LPC18xx/43xx On-chip Flash Loader

SYMPTOM

When I load an example to the internal flash on the LPC18xx/43xx and correctly set the boot pins, the program still won't run.

What could be wrong?

CAUSE

The most likely reason this happens is that the application does not fulfill the criterion for Valid User Code.

Unlike the on-chip flash loaders for other LPC devices, the flash loader for LPC18xx/43xx on-chip flash

does not calculate the NXP specific vector table checksum.

So the on-chip boot loader will not detect valid user code and does not boot from it.

The reason for this different behavior is that LPC18xx/43xx

can boot from different flash banks.

It is up to the user to place the vector table in flash bank A or B.

The generic flash loader must NOT modify the flash bank which does not contain the vector table.

RESOLUTION

Add the checksum to the output file with a user command that runs automatically after the build.

MDK-ARM also supplies the suitable command line tool for this purpose.

In Options for Target — User — Run User Programs After Build/Rebuild add:

$K\ARM\BIN\ELFDWT.EXE !L BASEADDRESS(0x1A000000)

If your application starts from bank A.
Or add:

$K\ARM\BIN\ELFDWT.EXE !L BASEADDRESS(0x1B000000)

if your application starts from bank B.

So the correct vector checksum will be added to the output file

and the NXP on-chip boot loader will recognize it as valid user code.

#include <stdio.h>
#include <stdint.h> #define BLOCK_COUNT 7
#define BLOCK_LENGTH 4
#define BLOCK_TOTAL (BLOCK_COUNT*BLOCK_LENGTH) typedef unsigned char byte_t; int main(int argc, char *argv[])
{
FILE* pf;
byte_t buf[BLOCK_TOTAL];
uint32_t crc = ;
uint32_t block; // Check for required arguments
if (argc < )
{
printf("syntax: lpcrc <firmware.bin>\n");
return ;
} // Try to open the supplied firmware
if ((pf = fopen(argv[],"rb+")) == NULL)
{
printf("error: could not open file [%s] with write access\n",argv[]);
return ;
} // Read out the data blocks used for crc calculation
if (fread(buf,,BLOCK_TOTAL,pf) != BLOCK_TOTAL)
{
printf("error: could not read required bytes\n");
fclose(pf);
return ;
} // Compute the crc value
for (block=; block<BLOCK_COUNT; block++)
{
crc += *((uint32_t*)(buf+(block*BLOCK_LENGTH)));
}
crc = (~crc) + ; // Reposition the file stream indicator to switch between read and write
if (fseek(pf,,SEEK_CUR) != )
{
printf("error: could not switch from read to write mode\n");
fclose(pf);
return ;
} // Write the crc back to the file
if (fwrite((byte_t*)&crc,,BLOCK_LENGTH,pf) != BLOCK_LENGTH)
{
printf("error: could not write crc back to file\n");
fclose(pf);
return ;
} printf("succesfully updated crc to: %08x\n",crc);
fclose(pf); return ;
}

NXP ARM Vector Table CheckSum的更多相关文章

  1. imx6 Image Vector Table (IVT)

    imx6开启启动之后,运行板子上的ROM程序.ROM确定启动的设备,进行一些初始化,然后读取IVT,进行寄存器初始化,最后运行uboot/cpu/arm_cortexa8/start.S中的_star ...

  2. STM32F4XX devices vector table for EWARM toolchain.

    ;/******************** (C) COPYRIGHT 2015 STMicroelectronics ******************** ;* File Name : sta ...

  3. STM32F1XX devices vector table for EWARM toolchain.

    ;******************** (C) COPYRIGHT 2014 STMicroelectronics ******************* ;* File Name : start ...

  4. swddude -- A SWD programmer for ARM Cortex microcontrollers.

    Introducing swddude I love the ARM Cortex-M series of microcontrollers.   The sheer computational po ...

  5. IAR EWARM Checksum Technical Note

    IELFTOOL Checksum - Basic actions EW targets: ARM, RH850, RX, SH, STM8 EW component: General issues ...

  6. Cortex-M0(NXP LPC11C14)启动代码分析

    作者:刘老师,华清远见嵌入式学院讲师. 启动代码的一般作用 1.堆和栈的初始化: 2.向量表定义: 3.地址重映射及中断向量表的转移: 4.初始化有特殊要求的断口: 5.处理器模式: 6.进入C应用程 ...

  7. Cortex-M3(NXP LPC 1788) 启动代码

    startup_LPC177x_8x.s启动代码分析. 参考资料: Cortex-M3 (NXP LPC1788)之启动代码分析 ARM启动过程(Cortex-M3 NXP LPC1768为例) ;/ ...

  8. 自己用C语言写NXP S32K116 serial bootloader

    了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 每次我有了新的EVA ...

  9. [ARM] Cortex-M Startup.s启动文件相关代码解释

    1. 定义一个段名为CSTACK, 这里: NOROOT表示如何定义的段没有被关联,那么同意会被优化掉,如果不想被优化掉就使用ROOT. 后面的括号里数字表示如下: (1):这个段是2的1次方即2字节 ...

随机推荐

  1. <header><footer>引用

    示例:http://www.w3school.com.cn/html/html_layout.asp

  2. c++刷题(33/100)笔试题1

    笔试总共2小时,三道题,时间挺充裕的,但是最后只做了一道,原因在于自己很浮躁,不审题,不仔细思考.没过的两道都是稍微改一下代码就能过,但是没过就是没过,要引以为戒 题目1: 小W有一个电子时钟用于显示 ...

  3. 【工具】用命令行与Python使用YARA规则

    1.前言 YARA是一款旨在帮助恶意软件研究人员识别和分类恶意软件样本的开源工具,使用YARA可以基于文本或二进制模式创建恶意软件家族描述与匹配信息.现在已经被多家公司所运用于自身的产品. 2.YAR ...

  4. 为什么要使用断路器Hystrix?

    为什么需要 Hystrix? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用(RPC).为了保证其高可用,单个服务又必须集群部署.由于网络原因或者自身的原因,服务并不能保证服 ...

  5. Java环境的搭建及用记事本来揭露下JDK到底做了些什么

    和我一样的新手想学Java就从自己搭建环境开始,请看完这边文章,我搜集资料的整合. Java的标准版本是Java SE,所说的JDK(Java Development Kits)就是Java SE的开 ...

  6. reportng之测试报告升级美化

    背景:偶然看到一个人的自动化框架的测试报告好漂亮,心痒痒,今天弄了一下午,还是不行,结果到现在就现在,我特么成功了,不为什么 Mark一下: 本地化修改 获取源码,修改reportng.propert ...

  7. activiti主要组件解析

    Activiti内部实现中,各主要部件关系 对外,提供Service服务,它是无状态的. 这些Service包括: protected RepositoryService repositoryServ ...

  8. 配置kotlin自带的编译器,并使用kotlinc、kotlin命令

    Kotlin是一种静态类型的编程语言,可在Java虚拟机上运行,也可以编译为JavaScript源代码. 其主要发展来自位于俄罗斯圣彼得堡的JetBrains程序员团队. 虽然语法与Java不兼容,但 ...

  9. Vue.JS 2.x

    基于ThinkPHP 5.0与Vue.JS 2.x的前后端开源开发框架VueThink VueThink 项目介绍 VueThink是一套基于Vue全家桶(Vue2.x + Vue-router2.x ...

  10. element-ui 日期选择范围限制,只允许选择上下浮动一个月内的日期

    <el-date-picker class="filter-item" type="daterange" value-format="yyyy- ...