cancel
Showing results for 
Search instead for 
Did you mean: 

Combining Bootloader and Application Code via Batch script

LGree.3
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you, how would one do this via batch for the hex files?

It is not the exact size and will require padding.

TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

If you're a C programmer, you could presumably code something with a handful of STDIO file handling functions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MM..1
Chief II

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...