NXP ARM Vector Table CheckSum

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 = 0;
  uint32_t block;

  // Check for required arguments
  if (argc < 2)
  {
    printf("syntax: lpcrc <firmware.bin>\n");
    return 1;
  }

  // Try to open the supplied firmware
  if ((pf = fopen(argv[1],"rb+")) == NULL)
  {
    printf("error: could not open file [%s] with write access\n",argv[1]);
    return 1;
  }

  // Read out the data blocks used for crc calculation
  if (fread(buf,1,BLOCK_TOTAL,pf) != BLOCK_TOTAL)
  {
    printf("error: could not read required bytes\n");
    fclose(pf);
    return 1;
  }

  // Compute the crc value
  for (block=0; block<BLOCK_COUNT; block++)
  {
    crc += *((uint32_t*)(buf+(block*BLOCK_LENGTH)));
  }
  crc = (~crc) + 1;

  // Reposition the file stream indicator to switch between read and write
  if (fseek(pf,0,SEEK_CUR) != 0)
  {
    printf("error: could not switch from read to write mode\n");
    fclose(pf);
    return 1;
  }

  // Write the crc back to the file
  if (fwrite((byte_t*)&crc,1,BLOCK_LENGTH,pf) != BLOCK_LENGTH)
  {
    printf("error: could not write crc back to file\n");
    fclose(pf);
    return 1;
  }

  printf("succesfully updated crc to: %08x\n",crc);
  fclose(pf);

  return 0;
}
时间: 2024-10-04 04:22:09

NXP ARM Vector Table CheckSum的相关文章

STM32F4XX devices vector table for EWARM toolchain.

;/******************** (C) COPYRIGHT 2015 STMicroelectronics ******************** ;* File Name : startup_stm32f4xx.s ;* Author : MCD Application Team ;* Version : V2.3.2 ;* Date : 26-June-2015 ;* Description : STM32F4xx devices vector table for EWARM

STM32F1XX devices vector table for EWARM toolchain.

;******************** (C) COPYRIGHT 2014 STMicroelectronics ******************* ;* File Name : startup_stm32f1xx.s ;* Author : MCD Application Team ;* Version : V4.0.0 ;* Date : 16-December-2014 ;* Description : STM32F1XX devices vector table for EWA

【嵌入式开发】 Bootloader 详解 ( 代码环境 | ARM 启动流程 | uboot 工作流程 | 架构设计)

作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42462795 转载请著名出处 相关资源下载 :  -- u-boot 源码 : http://download.csdn.net/detail/han1202012/8342761 -- S3C2440 文档 : http://download.csdn.net/detail/han1202012/8342701 -- S5PV210_iROM_Applicati

ARM汇编指令汇总

1.ARM汇编的格式:    在ARM汇编里,有些字符是用来标记行号的,这些字符要求顶格写:有些伪码是需要成对出现的,例如ENTRY和END,就需要对齐出现,也就是说他们要么都顶格,要么都空相等的空,否则编译器将报错.常量定义需要顶格书写,不然,编译器同样会报错.    2.字符串变量的值是一系列的字符,并且使用双引号作为分界符,如果要在字符串中使用双引号,则必须连续使用两个双引号.    3.在使用LDR时,当格式是LDR r0,=0x022248,则第二个参数表示地址,即0x022248,同

ARM基础知识学习笔记

/*****************数电知识*******************/ PN结(Positive-Negative) 三极管:BJT(双极结型三极管Bipolar Junction Transistor)               FET(场效应管Field Effect Transistor)          (单极结型) 1.MOSFET (金属氧化物半导体Metal Oxide Semiconductor FET)               2.JFET(结型Junct

Linux kernel的中断子系统之(六):ARM中断处理过程

一.前言 本文主要以ARM体系结构下的中断处理为例,讲述整个中断处理过程中的硬件行为和软件动作.具体整个处理过程分成三个步骤来描述: 1.第二章描述了中断处理的准备过程 2.第三章描述了当发生中的时候,ARM硬件的行为 3.第四章描述了ARM的中断进入过程 4.第五章描述了ARM的中断退出过程 本文涉及的代码来自3.14内核.另外,本文注意描述ARM指令集的内容,有些source code为了简短一些,删除了THUMB相关的代码,除此之外,有些debug相关的内容也会删除. 二.中断处理的准备过

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

1. 定义一个段名为CSTACK, 这里: NOROOT表示如何定义的段没有被关联,那么同意会被优化掉,如果不想被优化掉就使用ROOT. 后面的括号里数字表示如下: (1):这个段是2的1次方即2字节对齐 (2):这个段是2的2次方即4字节对齐 (3):这个段是2的3次方即8字节对齐 SECTION CSTACK:DATA:NOROOT(2) 2. 下面代码表示执行后面的指令函数(我理解为函数~),指令函数_iar_program_start和SystemInit为系统定义好的,在C库启动代码中

ARM异常处理(IRQ中断处理)总结1

ARM A8的异常处理表如下可以看到vector table的基地址是不固定的但是所有异常的偏移地址是固定的.这张表也为了体现这个偏移量,还有要从硬件角度理解的是在CPU设计的时候这些异常就已经定义好了在发生相应的异常时候CPU就自动的转到在异常向量表里的地址处去执行这个过程是不需要软件干预的因此就简单了我们只要把出现相应的异常时候处理过程的函数名(函数名就是这个函数体的指针)放在相应的地址里边就可以执行了举例说明.以三星S5PV210为例,我们根据官方的Application Node可以查到

DROP TABLE 恢复【一】

当DROP TABLE指令敲下的时候,你很爽,你有考虑过后果么?如果该表真的没用,你DROP到无所谓,如果还有用的,这时你肯定吓惨了吧,如果你有备份,那么恭喜你,逃过一劫,如果没有备份呢?这时就该绝望了?NO! 如果你的表是innodb表,那么还有希望挽救,如果是myisam表,那么真的没救了.前面文章介绍了 Recover InnoDB dictionary,这是恢复数据的前提.恢复innodb字典信息使用的是TwinDB recovery toolkit,我们恢复数据也是使用该工具.下面的案