How to convert .elf file to Intel .hex file format (CW v2.7)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to convert .elf file to Intel .hex file format (CW v2.7)

32,927 Views
Kasu
Contributor I

Hi everyone,

 

can any one please suggest me how can I convert my .elf file generated by default Codewarrior project for MPC5603P to an intel .hex file format?

 

My flash tool supports only .hex file, so I need to do this.

Labels (1)
0 Kudos
Reply
9 Replies

6,348 Views
whitmanmall
Contributor I

Check here to see 30+ image conversion formant, hopt you can find useful info even the key is existed.

0 Kudos
Reply

6,348 Views
martinw
Contributor III

I use powerpc-eabi-objcopy to create a binary image:

 

powerpc-eabi-objcopy -O binary image.elf image.bin

 

I'm pretty sure it will create an intel hex output file by changing the -O type.

 

If not there are plenty of tools around to create intel hex from binary

 

looks like you can download a free set of tools from CodeSourcery - objcopy is in there:

 

http://www.codesourcery.com/sgpp/lite/power/portal/release1572

0 Kudos
Reply

6,348 Views
Kasu
Contributor I

Dear Tom and Martin,

 

Thanks alot for your quick reply. I tried to find in the google, but I could not :smileysad:

 

Unfortunately I'm not quite familiar with the file conversion process.

 

If there is any thing you can do, that would be great.

 

thank you

0 Kudos
Reply

6,348 Views
martinw
Contributor III

if you follow the CodeSourcery link in my previous post, you will be able to download some command line power PC tools.

 

Part of the toolset is the objcopy utility.

 

This is the windows installer you need to download:

IA32 Windows Installer

 

 

On the download page there is also a link to a pdf file which details use of the objcopy tool

 

Binary Utilities (PDF)

 

 

0 Kudos
Reply

6,347 Views
Kasu
Contributor I

Dear Martin,

 

Thanks alot for helping me out very quickly. I installed the setup file and try to execute the 'objcopy'  utitly file.

 

But I think I'm using wrong name for bfd target as shown below. Please check the attached picture.

Could you correct my syntax please~

 

thank you

0 Kudos
Reply

6,347 Views
martinw
Contributor III

you should be able to get 'help' from objcopy.

 

try "objcopy -h"

 

then it should show you a list of the available output formats

 

my guess would be "ihex" for intel hex

 

the other option would be to output a binary file (.bin) then use a bin2hex tool to convert to intel hex

 

0 Kudos
Reply

6,347 Views
martinw
Contributor III

if you check the pdf file I suggested you download (binutils.pdf), it explains how to find out the supported output file formats

 

see section 19.1

 

19.1 Target Selection


A target is an object file format. A given target may be supported for multiple architectures
(see Section 19.2 [Architecture Selection], page 67). A target selection may also have
variations for different operating systems or architectures.


The command to list valid target values is ‘objdump -i’ (the first column of output
contains the relevant information).

 

I would have thought that this format will also apply to objcopy

 

0 Kudos
Reply

6,347 Views
Kasu
Contributor I

Dear Martin,

 

Thanks alot. You helped me alot.

 

Yes, I read the section 19.1 and using the command "objdump -i", i check the supported file formats. 
Yes, 'CodeSourcery' supports the Intel hex format using 'ihex'. So, I issued the command like below.

 

C:\Program Files\CodeSourcery\Sourcery G++ Lite\powerpc-eabi\bin\objcopy -O ihex internal_Flash.elf internal_Flash.hex

 

After this, CodeSourcery generated the internal_Flash.hex file. But I think there is some problem in the generated .hex file.

Because, I already have an original internal_Flash.hex file for the same project, and now when I compare the original hex file with the hex file generated  using CodeSourcery, there is lot of difference.


So, I tried with your another suggestion. I.e. convert the .elf file to binary file first and then use Bin2Hex application. After doing this, when I compare the generated .hex file with my original hex file, both are seems to be almost same except the un-used memory areas are filled with '0' in the generated hex file where as it was filled with 0xFF in my original hex file. I'm thinking it wont cause problem if I download this hex file to my target board.....(please correct me if I'm wrong)

 

That was the story. 

 

But anyway, when I use (objcopy -O binary internal_Flash.elf internal_Flash.bin) or (objcopy -O ihex internal_Flash.elf internal_Flash.hex), the '"CodeSourcery" throws some kind of error. Can you check the attachment and suggest me what is that please.

 

thank you~

0 Kudos
Reply

6,347 Views
J2MEJediMaster
Specialist I

Do a Google search on "elf2hex" or "elf2flash".

 

I did find this page, unfortunately it is for conversion of ELF to Motorola S-records, and not Intel HEX.

 

---Tom

 

 

0 Kudos
Reply