2021-11-26 11:10 AM
Hello,
I am building a project using a batch script which is calling stm32cubeidec.exe to build the separate entities. The project contains a bootloader as well as main application code. I am wondering the best way to combine the two binary files in the batch script into one complete binary for flashing.
I have a specific bootloader size and I know where the application code will be flashed. I just need to figure out the best way to combine them into one binary file.
Solved! Go to Solution.
2021-11-26 11:47 AM
Here is a batch file that will do it. Rename to combine_hex_files.bat and put somewhere accessible.
:: Usage: combine_hex_files source1.hex source2.hex combined.hex
@ECHO OFF
IF "%1"=="" GOTO BAD_ARGUMENTS
IF "%2"=="" GOTO BAD_ARGUMENTS
IF "%3"=="" GOTO BAD_ARGUMENTS
FINDSTR /R /V "^:00000001FF" "%1" > "%3"
TYPE "%2" >> "%3"
GOTO COMPLETE
:BAD_ARGUMENTS
ECHO ERROR: incorrect number of arguments
ECHO.
ECHO Usage:
ECHO combine_hex_files.bat source1.hex source2.hex combined.hex
:COMPLETE
2021-11-26 11:13 AM
A HEX file will be easier, otherwise you need to pad the binary with data between the two sections. Concatenate the files and remove the EOL line from the first file and you're done.
Or, if your bootloader BIN is the exact size of the bootloader, you can just concatenate the two files.
2021-11-26 11:17 AM
Thank you, how would one do this via batch for the hex files?
It is not the exact size and will require padding.
2021-11-26 11:47 AM
Here is a batch file that will do it. Rename to combine_hex_files.bat and put somewhere accessible.
:: Usage: combine_hex_files source1.hex source2.hex combined.hex
@ECHO OFF
IF "%1"=="" GOTO BAD_ARGUMENTS
IF "%2"=="" GOTO BAD_ARGUMENTS
IF "%3"=="" GOTO BAD_ARGUMENTS
FINDSTR /R /V "^:00000001FF" "%1" > "%3"
TYPE "%2" >> "%3"
GOTO COMPLETE
:BAD_ARGUMENTS
ECHO ERROR: incorrect number of arguments
ECHO.
ECHO Usage:
ECHO combine_hex_files.bat source1.hex source2.hex combined.hex
:COMPLETE
2021-11-26 01:31 PM
If you're a C programmer, you could presumably code something with a handful of STDIO file handling functions.
2021-11-28 05:13 AM
How utility you use for flash or for what you need one file ???
In normal i runs sstlink cli twice and flash boot and app...