cancel
Showing results for 
Search instead for 
Did you mean: 

Placing variables at specific address generates large binary file

zupazt3
Associate
Posted on January 08, 2016 at 12:24

I have to place some variables at specific address in memory. I'm using GCC.

I declare and use variable like this:

uint8_t __attribute__((section (''.mySection''))) buffer = 5;
int main()
{
 buffer = 10;
} 

And in linker script I've got:

MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 145K MYSEC (xrw) : ORIGIN = 0x20025000, LENGTH = 155K }

and later:

.mySection : { *(.mySection); } > MYSEC 

Normally my program takes 22 KB, with this modification it takes 384 MB (!).

I don't understand why. If I remove

__attribute__

it takes 22 KB again. What am I missing? #memory-sections-ram-linker
2 REPLIES 2
Posted on January 08, 2016 at 13:10

I don't understand why.

Likely because the RAM section gets correctly managed in the FLASH load region, and MYSEC does not. The .BIN isn't going to be able to represent sparse data, and unless you define MYSEC as uninitialized, or add start up code to unpack it from FLASH, none of this is going to work on a stand alone boot up of the system.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Radosław
Senior
Posted on January 08, 2016 at 15:17

Your section is in RAM, then add NOLOAD operator for this section.  Then it will not goes to output files (HEX & BIN).