The ‘standard’ binary files for many tools are S19, binary or Intel Hex files. Especially for S19 and Intel Hex it can be useful to control the amount of data per line. By default, the GNU objcopy creates files with a line length of 44 characters:
But it is possible to have Intel Hex files with an custom line length using the SRecord utility, and this is what this article is about.
First, use the GNU ‘objcopy‘ to generate a Intel Hex file (or use the MCUXpresso IDE for this). The following line generates the Intel Hex file from an ELF/Dwarf (.axf) file:
arm-none-eabi-objcopy -v -O ihex app.axf app.hex
This generates a ‘default’ Intel Hex file with a line length of 44 characters:
Then use the srec_cat tool from the SRecord package with the -line-length option:
srec_cat app.hex -intel -output new.hex -Intel -line-length=64
With this, I have a Intel Hex file with a different line length, in this case 64 characters:
That’s it 🙂
The SRecord tools are very versatile to convert and manipulate binary files, have a look at the links below.
Happy Inteling 🙂
Links
- SRecord Tool on SourceForge: http://srecord.sourceforge.net/
- GNU objcopy: https://sourceware.org/binutils/docs/binutils/objcopy.html
- MCUXpresso IDE: S-Record, Intel Hex and Binary Files
- Converting Binary Files to Intel Hex Format with the SRecord Tool
- S-Record, Intel Hex and Binary Files
- Merging S19 Files wir srec_cat
- Tutorial about SRecord: Tutorial: CRC32 Checksum with the KBOOT Bootloader
I did this already – a big benefit for our products is reprogram speed. My code programs each line of HEX as it comes over RS232; reformatting the file to more data on each line reduces communications overhead and speeded up our programming by about a third!
LikeLike
Did you use srec_cat too, or is there a way to do this in obj_copy?
LikeLike
Hey – don’t overlook your own post from the past! Though your post is about generating CRC32 checksums, it’s a good crash course on all the magic you can do with srec_cat:
https://mcuoneclipse.com/2018/03/05/tutorial-crc32-checksum-with-the-kboot-bootloader/
LikeLike
Indeed, too many articles I guess ;-). Thanks for the suggestion, I have added it to the list of links now.
LikeLike