Skip to main content
AKuma.2074
Associate II
July 14, 2022
Question

Difference between bin, hex and elf file and their sizes

  • July 14, 2022
  • 3 replies
  • 19889 views

Dear members,

After fiddling a bit with stm32cube ide, I found that after project compilation, I have 3 files generated i.e. elf, hex and bin, in my debug folder.

But the size of all three varies.

Elf is 925kb

Bin is 13kb

Hex is 36 kb

I know elf have lots of extra data + debug info

Bin is raw file without address

Hex is raw file with address

Now my question is, when i look into memory regions of build analyzer, and console output values of text, data and bss sizes, what does it represent?

It it the breakdown of bin or hex or elf file?

By default settings which file is sent to uc, through ide?

Elf, bin or hex?

Thanks and regards

Avinash

3 replies

Tesla DeLorean
Guru
July 14, 2022

The .BIN file is the most representative of the data written into the MCUs memory.

From this flash image it unpack the data content into RAM, and zeros the BSS​ beyond that.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
AKuma.2074
Associate II
July 14, 2022

Ok. This part is clear to me, but what is the answer to 2nd part of the question?

Andrew Neil
Super User
July 14, 2022
  1. BIN is a byte-by-byte binary image of what goes into the target memory - nothing more, nothing less. No gaps.
  2. HEX is a text representation of the image; it has addresses and checksums - so it can be "sparse"
  3. ELF is the full build output - it contains symbol information, debug information, etc, in addition to the code itself. BIN and HEX are generated from the ELF.

 

https://en.wikipedia.org/wiki/Intel_HEX

 

https://en.wikipedia.org/wiki/Executable_and_Linkable_Format

 

This is all general stuff - nothing specific to ST or STM32 or CubeIDE

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
AKuma.2074
Associate II
July 14, 2022

Ok. This part is clear to me, but what is the answer to 2nd part of the question?

Andrew Neil
Super User
July 14, 2022

"text, data and bss sizes, what does it represent?"

That's really an entirely different question!

Again, this is standard stuff; not specific to STM32 - or even embedded:

https://www.google.com/search?q=what+are+text+data+and+bss

It's all contained in the ELF, but is irrelevant to Hex or Bin.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
MQi.1
Senior II
December 11, 2024

@AKuma.2074 wrote:

By default settings which file is sent to uc, through ide?

Elf, bin or hex?


this is set in "run configuration" window inside DE.