作者:鱼鹰Osprey
ID :emOsprey
自检内容
资料
FLASH 检查
如何检查 | 基本原理
实操
;*******************************************************************************
; User Checksum - must be placed at the end of memory
;*******************************************************************************
AREA CHECKSUM, DATA, READONLY, ALIGN=6
EXPORT __Check_Sum
; Alignement here must correspond to the size of tested block at FLASH run time test (16 words ~ 64 bytes)!!!
ALIGN
__Check_Sum DCD 0x3D334398; ; Check sum computed externaly
ER_IROM1 0x08000000 0x10000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
*.o (CHECKSUM, +Last) ;放置在最后
}
if not exist %SREC_PATH% (
echo %SREC_PATH% is not exit, exit
echo ----------------------------------------del %INPUT_HEX% -- %AXF_FILE% ---------------
del %INPUT_HEX% %AXF_FILE%
exit
)
@echo off
ECHO Computing CRC
ECHO -------------------------------------
REM Batch script for generating CRC in KEIL project
REM Must be placed at MDK-ARM folder (project folder)
REM Path configuration
SET SREC_PATH=C:\SREC
SET MAP_NAME=STM3210C_EVAL
SET MAP_PATH=STM3210C_EVAL
SET TARGET_NAME=STM3210C_EVAL
SET TARGET_PATH=STM3210C_EVAL
SET BYTE_SWAP=1
SET COMPARE_HEX=1
SET CRC_ADDR_FROM_MAP=1
REM Not used when CRC_ADDR_FROM_MAP=1
SET CRC_ADDR=0x08007ce0
REM Derived configuration
SET HEX_ADRR=0x08000000
SET MAP_FILE=%MAP_PATH%\%MAP_NAME%.map
SET AXF_FILE=%TARGET_PATH%\%MAP_NAME%.axf
SET INPUT_HEX=%TARGET_PATH%\%TARGET_NAME%.hex
SET OUTPUT_HEX=%TARGET_PATH%\%TARGET_NAME%_CRC.hex
SET OUTPUT_BIN=.\%TARGET_NAME%_CRC.bin
SET TMP_FILE=crc_tmp_file.txt
if not exist %SREC_PATH%\srec_cat.exe (
echo %SREC_PATH% is not exit, exit
echo ----------------------------------------del %INPUT_HEX% -- %AXF_FILE% ---------------
del %INPUT_HEX% %AXF_FILE%
exit
)
IF NOT "%CRC_ADDR_FROM_MAP%"=="1" goto:end_of_map_extraction
REM Extract CRC address from MAP file
REM -----------------------------------------------------------
REM Load line with checksum location to crc_search variable
ECHO Extracting CRC address from MAP file
FINDSTR /R /C:"^ *CHECKSUM" %MAP_FILE%>%TMP_FILE%
SET /p crc_search=<%TMP_FILE%
DEL %TMP_FILE%
REM remove '(' character and string after, which causes errors
for /f "tokens=1 delims=(" %%a in ("%crc_search%") do set crc_search=%%a
REM remove CHECKSUM string from variable
SET crc_search=%crc_search:CHECKSUM=%
REM get first word at line, which should be CRC address in HEX format
for /f "tokens=1 delims= " %%a in ("%crc_search%") do set CRC_ADDR=%%a
REM -----------------------------------------------------------
REM End of CRC address extraction
:end_of_map_extraction
REM Compute CRC and store it to new HEX file
ECHO CRC address: %CRC_ADDR%
if "%BYTE_SWAP%"=="1" (
REM ECHO to see what is going on
ECHO %SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel ^
-crop %HEX_ADRR% %CRC_ADDR% ^
-byte_swap 4 ^
-stm32-b-e %CRC_ADDR% ^
-byte_swap 4 ^
-o %TMP_FILE% -intel
%SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel ^
-crop %HEX_ADRR% %CRC_ADDR% ^
-byte_swap 4 ^
-stm32-b-e %CRC_ADDR% ^
-byte_swap 4 ^
-o %TMP_FILE% -intel
) else (
REM ECHO to see what is going on
ECHO %SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel ^
-crop %HEX_ADRR% %CRC_ADDR% ^
-stm32-l-e %CRC_ADDR% ^
-o %TMP_FILE% -intel
%SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel ^
-crop %HEX_ADRR% %CRC_ADDR% ^
-stm32-l-e %CRC_ADDR% ^
-o %TMP_FILE% -intel
)
ECHO %SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel -exclude -within %TMP_FILE% -intel ^
%TMP_FILE% -intel ^
-o %OUTPUT_HEX% -intel
%SREC_PATH%\srec_cat.exe ^
%INPUT_HEX% -intel -exclude -within %TMP_FILE% -intel ^
%TMP_FILE% -intel ^
-o %OUTPUT_HEX% -intel
REM Delete temporary file
DEL %TMP_FILE%
ECHO Modified HEX file with CRC stored at %OUTPUT_HEX%
REM Compare input HEX file with output HEX file
if "%COMPARE_HEX%"=="1" (
ECHO Comparing %INPUT_HEX% with %OUTPUT_HEX%
%SREC_PATH%\srec_cmp.exe ^
%INPUT_HEX% -intel %OUTPUT_HEX% -intel -v
)
del %INPUT_HEX%
ECHO %SREC_PATH%\srec_cat.exe ^
%OUTPUT_HEX% -intel -offset -%HEX_ADRR% -o %OUTPUT_BIN% -binary
%SREC_PATH%\srec_cat.exe ^
%OUTPUT_HEX% -intel -offset -%HEX_ADRR% -o %OUTPUT_BIN% -binary
ECHO -------------------------------------
效果
工具命令解释
C:\SREC\srec_cat.exe STM3210C_EVAL\STM3210C_EVAL.hex -intel -crop 0x08000000 0x08007640 -byte_swap 4 -stm32-b-e 0x08007640 -byte_swap 4 -o crc_tmp_file.txt -intel
C:\SREC\srec_cat.exe STM3210C_EVAL\STM3210C_EVAL.hex -intel -exclude -within crc_tmp_file.txt -intel crc_tmp_file.txt -intel -o STM3210C_EVAL\STM3210C_EVAL_CRC.hex -intel
C:\SREC\srec_cmp.exe STM3210C_EVAL\STM3210C_EVAL.hex -intel STM3210C_EVAL\STM3210C_EVAL_CRC.hex -intel -v
欢迎转发、留言、点赞、分享给您的朋友,感谢您的支持!
本文分享自微信公众号 - 嵌入式客栈(embInn)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。