GENERAL: SPLITTING HEX FILES
Information in this article applies to:
Is there a utility or an easy way to split one Intel HEX file into two or more HEX files. This might be necessary if different Flash banks need to be programmed independently or when a bootloader should be separated from the application.
You may want to consider using the free srec_cat.exe utility which is available as Windows EXE file from https://sourceforge.net/projects/srecord/files/srecord-win32. It is part of the SRecord project hosted on sourceforge.net. With this utility, you can load one or multiple HEX files, cut out specific address areas, move them to a new address and store them to one HEX file.
You can invoke srec_cat.exe from a Windows command prompt or Make tool:
srec_cat.exe HexFile.hex -Intel -crop 0x0000 0x7FFF -o PartHexFile.hex -Intel
You can also invoke this tool after each project build/rebuild by specifying its invocation in the µVision dialog Options for Target - User - After Build/Rebuild. If many parameters are needed, it is easier to use a command file:
For a full description of all srec_cat.exe parameters, refer to the SRecord Reference Manual. Here are some options which are useful with Keil tools:
Split one HEX file (HexFile.hex) to two HEX files (HexFilePart1.hex and HexFilePart2.hex) where HexFilePart1.hex should contain the original address range from 0x000000-0x007FFF and HexFilePart2.hex should contain the original address range from 0x008000-0x00FFFF moved down to address 0x000000. Two invocations of srec_cat.exe are necessary to do this:
srec_cat.exe HexFile.hex -Intel -crop 0x000000 0x007FFF -o HexFilePart1.hex -Intel srec_cat.exe HexFile.hex -Intel -crop 0x008000 0x00FFFF -offset -0x008000 -o HexFilePart2.hex -Intel
This example is identical with example 1 but because some additional srec_cat.exe options are specified, a command file is used to invoke srec_cat.exe two times:
Content of SplitHexPart1.cmd command file:
# BL51 hex files are not sorted for ascending addresses. Suppress this warning -disable-sequence-warning # take HexFile.hex address area 0x000000-0x007FFF .\OBJ\HexFile.hex -Intel -crop 0x000000 0x007FFF #generate hex records with 16 byte data length (default 32 byte) -Output_Block_Size=16 # generate a Intel hex file -o .\OBJ\HexFilePart1.hex -Intel
Content of SplitHexPart2.cmd command file:
# BL51 hex files are not sorted for ascending addresses. Suppress this warning -disable-sequence-warning # take HexFile.hex address area 0x008000-0x00FFFF and shift it down to 0x000000 .\OBJ\HexFile.hex -Intel -crop 0x008000 0x00FFFF -offset 0x008000 #generate hex records with 16 byte data length (default 32 byte) -Output_Block_Size=16 # generate a Intel hex file -o .\OBJ\HexFilePart2.hex -Intel
Invocation of srec_cat.exe with two command files:
srec_cat.exe @SplitHexPart1.cmd srec_cat.exe @SplitHexPart2.cmd
Last Reviewed: Tuesday, July 17, 2018
of your data.