Вопрос

I've only ever worked with AVRs and MSP430s, but this is true for both of them. After compiling and statically linking, my final ELF binary is around 208kB and the Intel Hex binary is about 41kB. AVRDUDE tells me it's uploading about 18kB. What's actually going on here?

Это было полезно?

Решение

my final ELF binary is around 208kB

Yes, because ELF ain't raw machine code. It is a universal executable format which has relocation info, dynamic loading info, different secrions for read-only data, writable data and code, etc. Most of these are irrelevant on a microcontroller since it has no OS, no dynamic loading facilities, so most of the extra info can be stripped off.

the Intel Hex binary is about 41kB. AVRDUDE tells me it's uploading about 18kB.

Two reasons. One, an Intel hex file contains checksums on the end of each line. If you, using a reasonable average line length, cut these, you can expect the file to shrink by a few percents, for example to 36kB. Then, there's a reason Intel Hex files are named 'hex' files. They don't contain raw binary data but raw binary data in hexadecimal form - i. e. one real byte is encoded using two bytes. So when AVRdude uploads the code, it converts it to raw binary (that's what the AVRs processor can run), and then the data size is again decreased by 50%.

Другие советы

The object code includes additional metatdata, including the symbol table and debugger information. Most of that data can normally be stripped by compiler and/or linker option or by the strip utility if you are using a GNU toolchain.

A hex file uses 2 hex digit characters to represent a single byte, plus the record overhead so will always be a little more than twice the length of the binary.

As others said above, the HEX file format is ascii-printable which makes it easier to transfer over comms links (eg a 7-bit modem/terminal), very similar to Motorola .s19:

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

http://en.wikipedia.org/wiki/S19_%28file_format%29

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top