Keil Logo

GENERAL: MERGING TWO APPLICATIONS INTO ONE INTEL HEX FILE


Information in this article applies to:

  • C51 All Versions
  • C166 All Versions
  • C251 All Versions
  • MDK-ARM any Version

QUESTION

I'm developing a bootloader program (project A) and a separate application program (project B). Project A starts at 0000h. Project B starts at 8000h.

I need a single HEX file that contains both programs for device programming. Is there a tool that allows me to do that?

ANSWER

Yes. You may use 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 multiple HEX files, cut out specific address areas, move them to a new address and merge everything to one HEX file.

You can invoke srec_cat.exe from a Windows command prompt or Make tool:

srec_cat.exe HexFile1.hex -Intel HexFile2.hex -Intel -o MergedHexFile.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:

  • -Disable_Sequence_Warnings
    This option suppresses a warning if records of the input Intel HEX file are not sorted in ascending address order. HEX file generated by OH51 or OHX51 are not sorted in ascending address order.
  • -address-length= 2 or 3 or 4
    Specifies the number of address bytes in the Intel HEX output file. By default, srec_cat generates extended address records (type 04) for an address range of up to 4GB. Since a code banked application is bigger than 64K, -address-length=2 must not be used before specifying the output file. This would limit the max. address space to 64K.
  • -Output_Block_Size= ByteCount
    Specifies the length of each HEX record. By default, srec_cat generates lines containing up to 32 bytes of data. If you want to limit the max. line length to 16 bytes (compatible to OH51, OHX51, OH251 or OH166), use -Output_Block_Size=16.
  • -fill FillValue StartAddress EndAddress
    Fills unused areas with the specified constant value. A fill value of 0xFF is often used with this option because it corresponds to erased Flash.
  • -crop StartAddress EndAddress
    Only loads the specified address area from the previous input file. This option can be combined with -offset.
  • -offset Offset
    Adds an address offset to the previous input file. Positive or negative values are allowed. This option can be combined with -crop.
  • -Intel
    Can be used after an input or output filename to specify that an input file should be interpreted as an Intel HEX file or an output file should be generated as an Intel HEX file.
  • -Binary
    Can be used after an input or output filename to specify that an input file should be interpreted as a binary file or an output file should be generated as a binary file.
  • @CommandFile
    A command file can contain some or all invocation parameters for srec_cat.exe. You can even use comments -- starting with '#' extending to the end of the line.


Example 1:

Merge two HEX files (HexFile1.hex and HexFile2.hex) which have no address overlaps:

srec_cat.exe HexFile1.hex -Intel HexFile2.hex -Intel -o MergedHexFile.hex -Intel


Example 2:

Merge two HEX files (HexFile1.hex and HexFile2.hex) which both allocate an address area from 0x000000-0x007FFF. The resulting merged HEX file should contain HexFile1.hex in the address range 0x000000-0x007FFF and HexFile2.hex in address range 0x008000-0x00FFFF. In this example, a command file (MergeHex.cmd) is used. The resulting HEX file is MyCompleteProject.hex:

Content of MergHex.cmd command file:

# BL51 hex files are not sorted for ascending addresses. Suppress this warning
-disable-sequence-warning
# take HexFile1.hex and restrict it to the address area 0x000000-0x007FFF
.\OBJ\HexFile1.hex -Intel -crop 0x000000 0x007FFF
# take HexFile2.hex, restrict it to 0x000000-0x007FFF and move it to 0x008000-0x00FFFF
.\OBJ\HexFile2.hex -Intel -crop 0x000000 0x007FFF -offset 0x008000
#generate hex records with 16 byte data length (default 32 byte)
-Output_Block_Size=16
# generate a complete Intel hex file
-o .\OBJ\MyCompleteProject.hex -Intel

Invocation of srec_cat.exe with command file:

srec_cat.exe @MergeHex.cmd


MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Tuesday, July 17, 2018


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.