Code::Blocks Forums

User forums => Embedded development => Topic started by: anandamu16 on March 03, 2017, 05:39:31 am

Title: output file extension .bin/.hex
Post by: anandamu16 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 ?
Title: Re: output file extension .bin/.hex
Post by: christobal 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.
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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"?
Title: Re: output file extension .bin/.hex
Post by: Commaster 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.
Title: Re: output file extension .bin/.hex
Post by: BlueHazzard 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...)
Title: Re: output file extension .bin/.hex
Post by: christobal 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
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
-Wl,-Map=..\output\$(PROJECT_NAME).map

Title: Re: output file extension .bin/.hex
Post by: anandamu16 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
Title: Re: output file extension .bin/.hex
Post by: BlueHazzard 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...
Title: Re: output file extension .bin/.hex
Post by: christobal 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 (https://launchpad.net/gcc-arm-embedded/+download)
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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.
Title: Re: output file extension .bin/.hex
Post by: christobal 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
objcopy.exe -O ihex ElfFile.elf HexFile.hex

If you get errors, please post the command you're executing and the error message.
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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?
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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. :)
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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
Title: Re: output file extension .bin/.hex
Post by: yvesdm3000 on March 09, 2017, 10:04:22 am
http://forums.codeblocks.org/index.php?topic=13024.0
Title: Re: output file extension .bin/.hex
Post by: anandamu16 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.