Author Topic: output file extension .bin/.hex  (Read 2750 times)

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
output file extension .bin/.hex
« on: March 03, 2017, 05:39:31 am »
Hi,

I have recently started using codeblocks for embedded development. Whenever I make any project it gives the output file with extension .exe. I checked into project "properties->build targets" and realized that it gives the output extension bcz of the setting available here.
There are different types available here such as "Console Application", "Library static/dynamic", "GUI Application", "Commands only", "Native".
I want hex file as output which can be then run on embedded chip. So Can i do something like this:
- Select type as console application and set the output file extension as xxx.hex

Will it be ok?

Also is there any way to generate a .map file as output ?

Offline christobal

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: output file extension .bin/.hex
« Reply #1 on: March 03, 2017, 07:45:13 am »
So Can i do something like this:
- Select type as console application and set the output file extension as xxx.hex

Will it be ok?

No. How to get a hex file depends on the Compiler / Linker you use. For GCC, you need to build an "console application". This will generate an .elf File, which you have to convert to a HEX file in a post build step. You can use gcc objectcopy to accomplish this.

Also is there any way to generate a .map file as output ?

The linker usually provides a command line switch to produce a map file. Just add this to the linker options.

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #2 on: March 03, 2017, 11:42:46 am »
Quote
For GCC, you need to build an "console application". This will generate an .elf File
I am getting .exe file only but no .elf, although I have checked Compiler flag to "produce debugging symbols [-d]" still I am getting .exe file
Quote
.elf File, which you have to convert to a HEX file in a post build step. You can use gcc objectcopy to accomplish this.
(I am using GCC Compiler 5.3.0 on windows7)
I know there are pre/post build steps, but where to know about the post build steps, I mean what to enter.?
Quote
The linker usually provides a command line switch to produce a map file. Just add this to the linker options.
Did you mean "Project->Build Options->Linker Settings ->Other Linker options"?

Online Commaster

  • Multiple posting newcomer
  • *
  • Posts: 75
Re: output file extension .bin/.hex
« Reply #3 on: March 03, 2017, 11:55:18 am »
I am getting .exe file only but no .elf, although I have checked Compiler flag to "produce debugging symbols [-d]" still I am getting .exe file
(I am using GCC Compiler 5.3.0 on windows7)
You have to install and use the compiler for your TARGET DEVICE. Only then will it produce the right format. You are getting .exe, because you are using a windows compiler. And since Windows runs .exe...

Other possibility is cross-compilation, and you'll have to specify your target platform in compiler arguments.
« Last Edit: March 03, 2017, 11:56:53 am by Commaster »

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1581
Re: output file extension .bin/.hex
« Reply #4 on: March 03, 2017, 12:06:48 pm »
it would help if you tell us for what platform you are developing (arm, avr, pic, nxp...)

Offline christobal

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: output file extension .bin/.hex
« Reply #5 on: March 03, 2017, 12:21:18 pm »
I know there are pre/post build steps, but where to know about the post build steps, I mean what to enter.?
The GCC objcopy documentation should tell you what to do.

For Tricore GCC projects I use:
Code: [Select]
tricore-objcopy -O ihex  ..\result\$(PROJECT_NAME).elf ..\result\$(PROJECT_NAME).hex

Note: $(PROJECT_NAME) is a Code::Blocks enviroment variable, that expands to the Project name

Did you mean "Project->Build Options->Linker Settings ->Other Linker options"?
Yes. Again, the Linker documentation should tell you what to add.

In my case it is:
Code: [Select]
-Wl,-Map=..\output\$(PROJECT_NAME).map


Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #6 on: March 03, 2017, 02:33:05 pm »
Quote
You have to install and use the compiler for your TARGET DEVICE. Only then will it produce the right format. You are getting .exe, because you are using a windows compiler. And since Windows runs .exe...
Ok thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
Quote
it would help if you tell us for what platform you are developing (arm, avr, pic, nxp...)
ARM cortex m0
Any particular lead will be helpful.

Thanks christobl, I will refer GCC document

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1581
Re: output file extension .bin/.hex
« Reply #7 on: March 03, 2017, 06:03:32 pm »
Quote
Ok thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
Yes, but you have to install it to, codeblocks does not ship with the arm compiler...

Offline christobal

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: output file extension .bin/.hex
« Reply #8 on: March 06, 2017, 08:01:21 am »
Ok thanks. What I understood is.... If I am building my code specific to ARM, I must use "GNU GCC Compiler for ARM" and enable debugging symbols into it. I t will generate an elf file. Am I right?
In general: Yes, but debugging symbols are not relevant for producing an elf file.

As your target device is a Cortex M0, I assume that you'll not run an OS on your target and therefore need a bare metal GCC Compiler for ARM (aka "gcc-arm-none-eabi"). I did a quick search and found one one here: https://launchpad.net/gcc-arm-embedded/+download

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #9 on: March 06, 2017, 12:41:08 pm »
Quote
In general: Yes, but debugging symbols are not relevant for producing an elf file
Ok thanks, I used to think that to produce elf file, 1 need to enable debug symbols. Thanks for clarification.
Quote
Yes, but you have to install it to, codeblocks does not ship with the arm compiler...
I know that.. anyway thanks :)
Quote
I did a quick search and found one one here: https://launchpad.net/gcc-arm-embedded/+download
Thanks for searching, I already had.

I successful build elf file, but still I am not able to get .hex file as output from this elf, I mean I am not getting proper post build commands to do the job. I search on google but no relevent information. If anyone have worked to convert elf file into binary for ARMplz let me know.

Offline christobal

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: output file extension .bin/.hex
« Reply #10 on: March 06, 2017, 01:08:38 pm »
I successful build elf file, but still I am not able to get .hex file as output from this elf, I mean I am not getting proper post build commands to do the job. I search on google but no relevent information. If anyone have worked to convert elf file into binary for ARMplz let me know.

You should use the objcopy tool to convert elf to hex. Try at first from the command line without Code::Blocks post-build step. If you know how to generate the hex file, you can bring it into the post-build steps.
The call should be something like:

Code: [Select]
objcopy.exe -O ihex ElfFile.elf HexFile.hex
If you get errors, please post the command you're executing and the error message.

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #11 on: March 08, 2017, 05:57:57 am »
Yeah... I am able to build up hex file successfully from .elf file. The corresponding build commands is here arm-eabi-objcopy.exe -O ihex elfFile.elf hexfile.hex

I am thinking, is there any way to create a binary file also? I tried to chenge ihex to ibin and .hex to .bin in above file but it didn't work.
Any idea?

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #12 on: March 08, 2017, 06:10:29 am »
Updating.. yeah I checked.
To get a binary file as output, I need to use 'binary' instead of 'ihex'.
So now I can convert it into binary file also
Post build command is: arm-eabi-objcopy.exe -O binary elfFile.elf binFile.bin
May be anyone working with ARM Compiler can use these build commands directly.
Anyways thanks a lot for your help. :)
« Last Edit: March 08, 2017, 06:12:09 am by anandamu16 »

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #13 on: March 09, 2017, 09:24:54 am »
Is there any way to also get a .map file as output, Any post build step.?
I checked through binutils of GNU GCC Compiler for ARM document and there was no information on how to get a .map extension file as output

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 226
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline anandamu16

  • Multiple posting newcomer
  • *
  • Posts: 97
Re: output file extension .bin/.hex
« Reply #15 on: March 09, 2017, 12:21:58 pm »
Thanks.
I thought, I have to write some post build command to get a map file but it seems, I just need to give it in linker options.