简体   繁体   English

为什么上传的二进制文件大小比实际大小小得多?

[英]Why is the uploaded binary size so much smaller than the actual size?

I've only ever worked with AVRs and MSP430s, but this is true for both of them. 我只使用过AVR和MSP430,但对于这两种情况都是如此。 After compiling and statically linking, my final ELF binary is around 208kB and the Intel Hex binary is about 41kB. 在编译和静态链接之后,我的最终ELF二进制文件大约为208kB,而Intel Hex二进制文件大约为41kB。 AVRDUDE tells me it's uploading about 18kB. AVRDUDE告诉我上传大约18kB。 What's actually going on here? 这里到底发生了什么?

my final ELF binary is around 208kB 我最后的ELF二进制文件大约是208kB

Yes, because ELF ain't raw machine code. 是的,因为ELF不是原始机器代码。 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. Intel Hex二进制文件约为41kB。 AVRDUDE tells me it's uploading about 18kB. AVRDUDE告诉我上传大约18kB。

Two reasons. 两个原因。 One, an Intel hex file contains checksums on the end of each line. 一,Intel hex文件包含每行末尾的校验和。 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. 如果你使用合理的平均线长度来剪切这些,你可以期望文件缩小几个百分点,例如36kB。 Then, there's a reason Intel Hex files are named 'hex' files. 然后,英特尔Hex文件被命名为'hex'文件是有原因的。 They don't contain raw binary data but raw binary data in hexadecimal form - ie 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%. 因此,当AVRdude上传代码时,它会将其转换为原始二进制文件(这是AVR处理器可以运行的),然后数据大小再次减少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. 如果使用GNU工具链,大多数数据通常可以通过编译器和/或链接器选项或条带实用程序剥离

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. 十六进制文件使用2个十六进制数字字符来表示单个字节,加上记录开销,因此总是比二进制文件长度的两倍多一点。

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: 正如上面其他人所说,HEX文件格式是ascii-printable,这使得通过comms链接(例如7位调制解调器/终端)更容易传输,非常类似于Motorola .s19:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM