Main

12.1 EDK - An error message occurs when I attempt to convert an ".elf" file to binary file using mb-objcopy

AR# 25252

Search For Another Answer

Topic EDK Software
Last Updated 09/09/2010
Status Active
Description

When I attempt to convert an ".elf" file to a binary file using mb-objcopy.exe, the following error message occurs and a corrupt output (bin) file is generated: 

"Error Message: 

--------------------------------------- 

mb-objcopy -O binary loader.elf loader.bin
BFD: Warning: Writing section `.text' to huge (ie negative) file offset 0x86000000.
BFD: Warning: Writing section `.init' to huge (ie negative) file offset 0x86000b2c.
BFD: Warning: Writing section `.fini' to huge (ie negative) file offset 0x86000b58.
BFD: Warning: Writing section `.ctors' to huge (ie negative) file offset 0x86000b78.
BFD: Warning: Writing section `.dtors' to huge (ie negative) file offset 0x86000b80.
BFD: Warning: Writing section `.rodata' to huge (ie negative) file offset 0x86000b88.
BFD: Warning: Writing section `.data' to huge (ie negative) file offset 0x86000cc8.
BFD: Warning: Writing section `.jcr' to huge (ie negative) file offset 0x86001014.
mb-objcopy: loader.bin: File truncated"

Solution


The warnings are caused by a huge gap in memory between the vectors sections and the main sections for the executable file.

When the objcopy program encounters discontinued memory sections, it automatically pads them with 0s. In the above case, since the offset is so large, the program truncates the output ".bin" file and issues the warning messages. Otherwise, the output file will be extremely large (imagine the size in bytes from ox00 to 0x86000000 = 2 GB!).

To work around this problem, you can use the following commands to prevent the padding in the discontinued memory sections.

mb-objcopy -O binary -j .vectors.reset -j .vectors.sw_exception -j .vectors.interrupt -j .vectors.hw_exception ./spi_user_app/executable.elf ./flash_burn/spi_user_app1.b

mb-objcopy -O binary -R .vectors.reset -R .vectors.sw_exception -R .vectors.interrupt -R .vectors.hw_exception ./spi_user_app/executable.elf ./flash_burn/spi_user_app2.b

cat ./flash_burn/spi_user_app1.b >> ./flash_burn/spi_user_app2.b

These commands generate the bin file individually for different sections (with only and without the vector sections) and concatenates them together afterward.

This Answer Record also applies when you want to reduce the size of the resulting bin file from mb-objcopy and store the bin in Flash. This bin file cannot be run from Flash.
 
 
/csi/footer.htm