Create CRC32 checksum for LPC55 application in Mcuxpresso IDE

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Create CRC32 checksum for LPC55 application in Mcuxpresso IDE

Create CRC32 checksum for LPC55 application in Mcuxpresso IDE

 

需求:

客户需要对Image文件做出完整性检测,利用IDE固有功能添加这类信息简便且可靠,以往有类似的link提到了这些配置,对于LPC55系列,需要做一些更新。

CRC Checksum Generation with MCUXpresso IDE - NXP Community

Solution

基于MCUX环境

srec_cat.exe是下载后我们主要使用的工具,通过为其添加一个系统变量名,将SRecord目录加入系统路径

 
daweiyou_4-1655616249140.png

 

重启MCUX IDE之后可以在工程配置中看到该变量:

 

daweiyou_5-1655616259631.png

 

 

创建一个脚本文件crc_add.txt,放在debug目录下,用于填充app后的flash空余位置为0xFF, 并后续生成CRC32值并放置0x00037FFC位置。最终生成的srec文件为包含所有内容的image。          

# srec_cat command file to add the CRC and produce application file to be flashed  
# Usage: srec_cat @filename  
  
#first: create CRC checksum  
  
lpcxpresso55s06_hello_world_image_length_MCUX.srec            # input file  
  
#-fill 0xFF 0x00000000 0x00038000               # fill blank code area with 0xff from 0x00000000 to 0x00038000 (0x00038000是把LPC55S06的末尾地址稍往前提,实际因为0x0003D7FF)  
-fill 0xFF 0x00000000 0x00037FFC                 #填充0-0x37FFC区间的未用地址为0xff   
  
-crop 0x00000000 0x00037FFC                 # just keep code area for CRC   calculation below , 保留这段区间的内容,排除除此范围内的其他数据  
  
#-CRC16_Big_Endian 0x00037FFE -CCITT         # calculate big endian CCITT  CRC16 at given address., 为以上空间数据计算CRC16,并放置在0x00037FFE地址,2字节  
  
-CRC32_Little_Endian 0x00037FFC -CCITT    #CRC32  
  
-crop 0x00037FFC     0x00038000                 # keep the CRC itself  
  
  
#second: add application file  
lpcxpresso55s06_hello_world_image_length_MCUX.srec           # input file  
  
-fill 0xFF 0x00000000 0x00037FFC                 # fill code area with 0xff  
-crop 0x00000000 0x00037FFC  
  
#-crop 0x10000000 0x10000170 0x10000172 0x10010000  #keep all except CRC  
  
#finally, produce the output file  
  
-Output                                     # produce output  
  
lpcxpresso55s06_hello_world_image_length_MCUX_crc.srec 

  

 

创建一个crc_file_convert.txt文件,也放在debug目录下,用于将上一步生成的最终image的srec文件转换为bin文件,用于生成或者比对

# srec_cat command file to add the CRC and produce application file to be flashed  
# Usage: srec_cat @filename  
  
#third: create bin file  
  
lpcxpresso55s06_hello_world_image_length_MCUX_crc.srec -o lpcxpresso55s06_hello_world_image_length_MCUX_crc.bin -binary  

在IDE的Post build栏目添加如下命令:

 
daweiyou_6-1655616409900.png

 

arm-none-eabi-size "${BuildArtifactFileName}"   默认自带的统计image size功能

arm-none-eabi-objcopy -v -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin"    image转成bin文件,用于后续使用和比对

arm-none-eabi-objcopy -v -O srec "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.srec" & srec_cat.exe @CRC_add.txt 填充image,计算CRC32,整合成新的srec image

srec_cat.exe @CRC_file_convert.txt  将上一步得到的srec image转化为bin文件,用于后续使用和比对

 

hello_world_image_length_MCUX》例程会自行统计应用程序的CRC32值,并于IDE产生的CRC32值做比对

 

这里需要注意的是,由于MCUX IDE是借助于外部工具来填充flash和计算CRC32,所以默认IDE调试和下载选择afx文件并不包含这些信息。当校验程序开始运行,会发生:

  • 读写未写入的flash,对于LPC55系列会发生hardfault
  • CRC32值并不存在

所以测试这个程序需要单独下载包含所有的srec文件或者bin文件,而不是默认的afx文件。

 

 

 

标签 (3)
无评分
版本历史
最后更新:
‎06-18-2022 10:30 PM
更新人: