Skip to main content
Associate II
Feb 16, 2026 8:40 PM UTC
Solved

Can I include two .hex files into my final .hex build?

Is there a build tool to insert two .hex files into my final image? 

 

I am retroactively updating an existing firmware by moving a bootloader I've created from an unused place in the updated image into its proper sector. But to do this, I need to insert the bootloader into the image I am updating with. 

(Update image contains existing code + boot image1 + boot image2)

 

My main update image will be contained in sector 0 - 5. My first separately built bootloader.hex file must be squeezed into sector 6, and my second separately build bootloader2.hex must be squeezed into sector 7. 

 

I have found it is possible to use the linker file to insert raw hexadecimal bytes, but this requires converting the .hex file to an ascii hex array, copying it over and then building. 

Is there a command line build tool alternative to do this cleanly?

TDK
TDKBest answer
Feb 16, 2026 8:58 PM UTC

You could use srec_cat to do this.

SRecord - Browse /srecord-win32 at SourceForge.net

Solved: Re: Production flash tool for dual core STM32H745 - STMicroelectronics Community

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

2 replies

TDK
TDKBest answer
Feb 16, 2026 8:58 PM UTC
"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate II
Feb 16, 2026 9:44 PM UTC

I tried srec_cat and since my original .hex files are not at the address I need to insert them to the output is not correct. Tried doing this:

srec_cat update-image.hex -intel boot-stage1.hex -intel -offset 0x40000 boot-stage2.hex -intel -offset -0x80000 -o final_image.hex -intel

 

Output is not at correct addresses though... I'll go with the primitive method of just creating a hex ascii array and using the linker to keep the array.