为什么bin文件会超大?
因为程序的加载地址不连续
MEMORY
{
ILM (rx!w) : ORIGIN = 0x00FC0000, LENGTH = 192K
Flash (rx!w) : ORIGIN = 0x51000000, LENGTH = 64K
RAM (xrwai) : ORIGIN = 0x20030000, LENGTH = 64K
}
如上区域划分,代码可以执行在ILM或Flash中,如果同时使用两个区域,地址跨度非常大,默认生成的bin文件也会超大
objcopy -O binary "test.elf" "test.bin"
在只使用ILM的情况下ELF的大小274K,bin的大小为44K
.xip :
{
. = ALIGN(4);
*( .text.test_matrix*)
. = ALIGN(4);
} >Flash
将部分代码(.xip段)放在Flash时ELF的大小275K,bin的大小则为1310981K
怎么解决?
生成多个bin
使用objcopy -h,可以得到如下信息(节选)
-j --only-section <name> Only copy section <name> into the output
--add-gnu-debuglink=<file> Add section .gnu_debuglink linking to <file>
-R --remove-section <name> Remove section <name> from the output
--remove-relocations <name> Remove relocations from section <name>
-j选项(或--only-section)用于指定要包含在输出文件中的段或节。使用此选项可以选择只包含特定的段或节,从而去除不需要的部分
-R选项(或--remove-section)用于指定要从输出文件中移除的段或节。使用此选项可以去除不需要的段或节
可以使用如下指令生成Flash.bin和ILM.bin
objcopy -O binary -j .xip "test.elf" "Flash.bin"
objcopy -O binary -R .xip "test.elf" "ILM.bin"
最终ELF的大小275K,Flash.bin的大小为5K,ILM.bin的大小为40K
1468

被折叠的 条评论
为什么被折叠?



