Create CRC32 checksum for LPC55 application in Mcuxpresso IDE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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文件。

 

 

 

Labels (3)
%3CLINGO-SUB%20id%3D%22lingo-sub-1476286%22%20slang%3D%22zh-CN%22%20mode%3D%22CREATE%22%3ECreate%20CRC32%20checksum%20for%20LPC55%20application%20in%20Mcuxpresso%20IDE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1476286%22%20slang%3D%22zh-CN%22%20mode%3D%22CREATE%22%3E%3CDIV%20class%3D%22lia-message-template-symptoms-zone%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-diagnosis-zone%22%3E%0A%3CP%3E%3CSTRONG%3Eneed%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ECustomers%20need%20to%20perform%20integrity%20checks%20on%20the%20Image%20file.%20It%20is%20easy%20and%20reliable%20to%20add%20this%20type%20of%20information%20using%20the%20inherent%20functions%20of%20the%20IDE.%20In%20the%20past%2C%20similar%20links%20mentioned%20these%20configurations.%20For%20the%20LPC55%20series%2C%20some%20updates%20are%20needed.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FLPC-Microcontrollers-Knowledge%2FCRC-Checksum-Generation-with-MCUXpresso-IDE%2Fta-p%2F1180671%22%20target%3D%22_blank%22%3ECRC%20Checksum%20Generation%20with%20MCUXpresso%20IDE%20-%20NXP%20Community%3C%2FA%3E%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-message-template-solution-zone%22%3E%0A%3CH2%20id%3D%22toc-hId--1323933362%22%20id%3D%22toc-hId--493628526%22%3ESolution%3C%2FH2%3E%0A%3CH4%20id%3D%22toc-hId-1864644049%22%20id%3D%22toc-hId--1600018411%22%3E%3CSTRONG%3EBased%20on%3C%2FSTRONG%3E%20%3CSTRONG%3EMCUX%3C%2FSTRONG%3E%20%3CSTRONG%3Eenvironment%3C%2FSTRONG%3E%3C%2FH4%3E%0A%3CUL%3E%0A%3CLI%3E%E4%B8%8B%E8%BD%BD%20SRecord%20%3CA%20href%3D%22http%3A%2F%2Fsrecord.sourceforge.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fsrecord.sourceforge.net%2F%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3Esrec_cat.exe%20is%20the%20main%20tool%20we%20use%20after%20downloading.%20By%20adding%20a%20system%20variable%20name%20to%20it%2C%20the%20SRecord%20directory%20is%20added%20to%20the%20system%20path%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditordaweiyou_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22daweiyou_4-1655616249140.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22daweiyou_4-1655616249140.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F183810i42D79CC48ED3A8B0%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22daweiyou_4-1655616249140.png%22%20alt%3D%22daweiyou_4-1655616249140.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CP%3EAfter%20restarting%20MCUX%20IDE%2C%20you%20can%20see%20this%20variable%20in%20the%20project%20configuration%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22daweiyou_5-1655616259631.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22daweiyou_5-1655616259631.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F183811i7EDB0150EEEDACCD%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22daweiyou_5-1655616259631.png%22%20alt%3D%22daweiyou_5-1655616259631.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CDIV%20id%3D%22tinyMceEditordaweiyou_1%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3ECreate%20a%20script%20file%20crc_add.txt%20and%20put%20it%20in%20the%20debug%20directory%20to%20fill%20the%20free%20space%20of%20the%20flash%20after%20the%20app%20with%200xFF%2C%20and%20then%20generate%20the%20CRC32%20value%20and%20put%20it%20at%200x00037FFC.%20The%20final%20generated%20srec%20file%20is%20an%20image%20containing%20all%20the%20contents.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3E%23%20srec_cat%20command%20file%20to%20add%20the%20CRC%20and%20produce%20application%20file%20to%20be%20flashed%20%20%0A%23%20Usage%3A%20srec_cat%20%40filename%20%20%0A%20%20%0A%23first%3A%20create%20CRC%20checksum%20%20%0A%20%20%0Alpcxpresso55s06_hello_world_image_length_MCUX.srec%20%20%20%20%20%20%20%20%20%20%20%20%23%20input%20file%20%20%0A%20%20%0A%23-fill%200xFF%200x00000000%200x00038000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20fill%20blank%20code%20area%20with%200xff%20from%200x00000000%20to%200x00038000%20(0x00038000%E6%98%AF%E6%8A%8ALPC55S06%E7%9A%84%E6%9C%AB%E5%B0%BE%E5%9C%B0%E5%9D%80%E7%A8%8D%E5%BE%80%E5%89%8D%E6%8F%90%EF%BC%8C%E5%AE%9E%E9%99%85%E5%9B%A0%E4%B8%BA0x0003D7FF%EF%BC%89%20%20%0A-fill%200xFF%200x00000000%200x00037FFC%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%E5%A1%AB%E5%85%850-0x37FFC%E5%8C%BA%E9%97%B4%E7%9A%84%E6%9C%AA%E7%94%A8%E5%9C%B0%E5%9D%80%E4%B8%BA0xff%20%20%20%0A%20%20%0A-crop%200x00000000%200x00037FFC%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20just%20keep%20code%20area%20for%20CRC%20%20%20calculation%20below%20%2C%20%E4%BF%9D%E7%95%99%E8%BF%99%E6%AE%B5%E5%8C%BA%E9%97%B4%E7%9A%84%E5%86%85%E5%AE%B9%EF%BC%8C%E6%8E%92%E9%99%A4%E9%99%A4%E6%AD%A4%E8%8C%83%E5%9B%B4%E5%86%85%E7%9A%84%E5%85%B6%E4%BB%96%E6%95%B0%E6%8D%AE%20%20%0A%20%20%0A%23-CRC16_Big_Endian%200x00037FFE%20-CCITT%20%20%20%20%20%20%20%20%20%23%20calculate%20big%20endian%20CCITT%20%20CRC16%20at%20given%20address.%EF%BC%8C%20%E4%B8%BA%E4%BB%A5%E4%B8%8A%E7%A9%BA%E9%97%B4%E6%95%B0%E6%8D%AE%E8%AE%A1%E7%AE%97CRC16%EF%BC%8C%E5%B9%B6%E6%94%BE%E7%BD%AE%E5%9C%A80x00037FFE%E5%9C%B0%E5%9D%80%EF%BC%8C2%E5%AD%97%E8%8A%82%20%20%0A%20%20%0A-CRC32_Little_Endian%200x00037FFC%20-CCITT%20%20%20%20%23CRC32%20%20%0A%20%20%0A-crop%200x00037FFC%20%20%20%20%200x00038000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20keep%20the%20CRC%20itself%20%20%0A%20%20%0A%20%20%0A%23second%3A%20add%20application%20file%20%20%0Alpcxpresso55s06_hello_world_image_length_MCUX.srec%20%20%20%20%20%20%20%20%20%20%20%23%20input%20file%20%20%0A%20%20%0A-fill%200xFF%200x00000000%200x00037FFC%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20fill%20code%20area%20with%200xff%20%20%0A-crop%200x00000000%200x00037FFC%20%20%0A%20%20%0A%23-crop%200x10000000%200x10000170%200x10000172%200x10010000%20%20%23keep%20all%20except%20CRC%20%20%0A%20%20%0A%23finally%2C%20produce%20the%20output%20file%20%20%0A%20%20%0A-Output%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20produce%20output%20%20%0A%20%20%0Alpcxpresso55s06_hello_world_image_length_MCUX_crc.srec%20%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3ECreate%20a%20crc_file_convert.txt%20file%2C%20also%20placed%20in%20the%20debug%20directory%2C%20to%20convert%20the%20srec%20file%20of%20the%20final%20image%20generated%20in%20the%20previous%20step%20into%20a%20bin%20file%20for%20generation%20or%20comparison%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%20translate%3D%22no%22%3E%23%20srec_cat%20command%20file%20to%20add%20the%20CRC%20and%20produce%20application%20file%20to%20be%20flashed%20%20%0A%23%20Usage%3A%20srec_cat%20%40filename%20%20%0A%20%20%0A%23third%3A%20create%20bin%20file%20%20%0A%20%20%0Alpcxpresso55s06_hello_world_image_length_MCUX_crc.srec%20-o%20lpcxpresso55s06_hello_world_image_length_MCUX_crc.bin%20-binary%20%20%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAdd%20the%20following%20command%20in%20the%20Post%20build%20section%20of%20the%20IDE%3A%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditordaweiyou_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22daweiyou_6-1655616409900.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22daweiyou_6-1655616409900.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F183812iB702C363B5E197BD%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22daweiyou_6-1655616409900.png%22%20alt%3D%22daweiyou_6-1655616409900.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%3CEM%3Earm-none-eabi-size%20%22%24%7BBuildArtifactFileName%7D%22%26nbsp%3B%26nbsp%3B%20%3C%2FEM%3E%3CEM%3E%E9%BB%98%E8%AE%A4%E8%87%AA%E5%B8%A6%E7%9A%84%E7%BB%9F%E8%AE%A1%3C%2FEM%3E%3CEM%3Eimage%20size%3C%2FEM%3E%3CEM%3E%E5%8A%9F%E8%83%BD%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Earm-none-eabi-objcopy%20-v%20-O%20binary%20%22%20%24%7BBuildArtifactFileName%7D%20%22%20%22%20%24%7BBuildArtifactFileBaseName%7D%20.bin%22%3C%2FEM%3E%20%3CEM%3Econverts%3C%2FEM%3E%20%3CEM%3Ethe%20image%3C%2FEM%3E%20%3CEM%3Einto%3C%2FEM%3E%20a%20%3CEM%3Ebin%3C%2FEM%3E%20%3CEM%3Efile%20for%20subsequent%20use%20and%20comparison%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Earm-none-eabi-objcopy%20-v%20-O%20srec%20%22%20%24%7BBuildArtifactFileName%7D%20%22%20%22%20%24%7BBuildArtifactFileBaseName%7D%20.srec%22%20%26amp%3B%20srec_cat.exe%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29693%22%20target%3D%22_blank%22%3E%40CRC%3C%2FA%3E%20_add.txt%3C%2FEM%3E%20%3CEM%3Efills%3C%2FEM%3E%20%3CEM%3Eimage%3C%2FEM%3E%20%3CEM%3E%2C%20calculates%3C%2FEM%3E%20%3CEM%3ECRC32%3C%2FEM%3E%20%3CEM%3E%2C%20and%20integrates%20into%20a%20new%3C%2FEM%3E%20%3CEM%3Esrec%20image%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Esrec_cat.exe%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29693%22%20target%3D%22_blank%22%3E%40CRC%3C%2FA%3E%20_file_convert.txt%3C%2FEM%3E%20converts%20%3CEM%3Ethe%20srec%20image%3C%2FEM%3E%20%3CEM%3Eobtained%20in%20the%20previous%20step%3C%2FEM%3E%20%3CEM%3Einto%3C%2FEM%3E%20a%20%3CEM%3Ebin%3C%2FEM%3E%20%3CEM%3Efile%20for%20subsequent%20use%20and%20comparison%3C%2FEM%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EThe%20%22%20%3CSPAN%3Ehello_world_image_length_MCUX%3C%2FSPAN%3E%20%22%20routine%20will%20automatically%20count%20the%20%3CSPAN%3ECRC32%3C%2FSPAN%3E%20value%20of%20the%20application%20and%20compare%20it%20with%20the%20%3CSPAN%3ECRC32%3C%2FSPAN%3E%20value%20generated%20by%20%3CSPAN%3Ethe%20IDE%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EIt%20should%20be%20noted%20that%20since%20%3CSPAN%3EMCUX%20IDE%3C%2FSPAN%3E%20uses%20external%20tools%20to%20fill%20%3CSPAN%3Ethe%20flash%3C%2FSPAN%3E%20and%20calculate%20%3CSPAN%3ECRC32%3C%2FSPAN%3E%20%2C%20the%20default%20%3CSPAN%3EIDE%3C%2FSPAN%3E%20debugging%20and%20download%20selection%20%3CSPAN%3Eafx%3C%2FSPAN%3E%20file%20does%20not%20contain%20this%20information.%20When%20the%20verification%20program%20starts%20running%2C%20the%20following%20will%20happen%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EReading%20and%20writing%20unwritten%20%3CSPAN%3Eflash%3C%2FSPAN%3E%20will%20cause%20%3CSPAN%3Ehardfault%3C%2FSPAN%3E%20for%20%3CSPAN%3ELPC55%3C%2FSPAN%3E%20series%3C%2FLI%3E%0A%3CLI%3ECRC32%20value%20does%20not%20exist%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ETherefore%2C%20to%20test%20this%20program%2C%20you%20need%20to%20download%20a%20separate%20%3CSPAN%3Esrec%3C%2FSPAN%3E%20file%20or%20%3CSPAN%3Ebin%3C%2FSPAN%3E%20file%20containing%20all%20the%20files%2C%20instead%20of%20the%20default%20%3CSPAN%3Eafx%3C%2FSPAN%3E%20file.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditordaweiyou_3%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CBR%20%2F%3E%0A%3CBR%20%2F%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1476286%22%20slang%3D%22zh-CN%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EGeneral%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELPC55xx%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EChinese%20User%20Forum%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
No ratings
Version history
Last update:
‎06-18-2022 10:30 PM
Updated by: