cancel
Showing results for 
Search instead for 
Did you mean: 

hex (or bin) file to elf using Cube Programmer

TheRaprus
Associate III

Hi all.

With build project I can obtain .bin, .hex and .elf file.

I need to manipulate the file to add a CRC in determinate position. SO I use .bin (easiest), then convert in .hex and .elf file using:

arm-none-eabi-objcopy -I binary -O ihex --change-section-address .data=0x08000000 crc_FlashTest.bin crc_FlashTest.hex

arm-none-eabi-objcopy -I ihex -O elf32-little FlashTest.hex FlashTestX.elf

 

The elf file doesn't work: on CUBE programmer (latest version) I got "crc_FlashTestX.elf is an invalid ELF file"

Change elf  option on conversion doesn't solve (elf32-littlearm elf32-littlearm-fdpic elf32-bigarm elf32-bigarm-fdpic elf32-little elf32-big). Still the same file.

Hex file is correct. Even Iif I try to convert bin (hex) file without my manipulation the conevrtion doesn't match and doesn't work.

Have someone a suggestion?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Maryem
ST Employee

Hello @TheRaprus,

A HEX file only contains raw data without any additional information about the program structure. On the other hand, an ELF file contains detailed information about the program structure, including program headers, section headers, symbol tables, and relocation information. When you convert a HEX file to an ELF file using "objcopy", the resulting ELF file will contain only the basic program structure information, such as section headers.

So I think without the additional information, STM32CubeProgrammer will not be able to determine the memory layout of the program and will generate an error when you try to use the file.

 

Maryem.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
Maryem
ST Employee

Hello @TheRaprus,

A HEX file only contains raw data without any additional information about the program structure. On the other hand, an ELF file contains detailed information about the program structure, including program headers, section headers, symbol tables, and relocation information. When you convert a HEX file to an ELF file using "objcopy", the resulting ELF file will contain only the basic program structure information, such as section headers.

So I think without the additional information, STM32CubeProgrammer will not be able to determine the memory layout of the program and will generate an error when you try to use the file.

 

Maryem.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thanks Maryem.

I supposed it: CUBE programmer can save in bin/hex/sre format but not in elf! I thought this info can be added in "someway" just for the programmer, that don't need it.

Based on your knowledge, it is possible modify a .elf file to add a CRC in a particular memory zone, ad I do in hex/bin (and sre) file?
Thanks again.

Hello again @TheRaprus,

I'm not entirely sure, but I think you can calculate the CRC of the binary code using a CRC algorithm of your choice, and then add a new section which contains the calculated CRC value to the .elf file in the desired memory zone.

 

Maryem.


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.