Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22177

Gcc objcopy get reasonable size binary

$
0
0

I am trying to create a binary from elf file with PPC GCC, I understand the the objcopy will create the whole area for the memory sections. here is my sample ld file:

MEMORY { RESETWORD: ORIGIN = 0x00f8c000, LENGTH = 0x00000020 ROM1        : ORIGIN = 0x09000040, LENGTH = 0x00000FC0}SECTIONS{    .resetword : {        *(.resetword.*)         } > RESETWORD   .startup :  {        *(.startup)    } > ROM1}

if I use objcopy -O binary demo.elf demo.bin, I will get a 131573KB bin file, basically the size is 0x09000040 + 0x00000FC0 - 0x00f8c000. so the binary is filled from 0x00f8c000 to 0x09001000. A huge area will be filled with zero from 0xF8 C020 to 0x09000040. I tried to change the Load address of .resetword section as below:

MEMORY { RESETWORD: ORIGIN = 0x00f8c000, LENGTH = 0x00000020 ROM1        : ORIGIN = 0x09000040, LENGTH = 0x00000FC0}SECTIONS{    .startup :  {        *(.startup)    } > ROM1    .resetword : AT(LOADADDR(.startup) + SIZEOF(.startup)){        *(.resetword.*)         } > RESETWORD}

the objcopy gets a 1k binary. I can see the load address of .resetword is 0x9000xxx and address is still 0x00f8c000 from map file. I think this time the objcopy starts from 0x09000040 and ends at 0x09000040 + length(.startup) + length(.resetword). I understand the logic here, but I am wondering my changes are reasonable? is there any side affect to do this change? What is the correct way to get a flashable binary in my scenario?

BTW: I tried Greenhills compiler , even with the original ld file without any loading address changes, it can generate a 1k binary, looks like Greenhills compiler doesn't put zeros between .resetword and .startup or Greenhills compiler does something similar change the load address of .resetword automatically .

Thanks!


Viewing all articles
Browse latest Browse all 22177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>