EmbDev.net

Forum: ARM programming with GCC/GNU tools accees constant defined in linker script


Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
Hello,

I define a constant in the linker script and want access it from C-code:

SECTIONS
{
...
 _bootsize = 0x00004000;
...
}

Here is code snippet:

extern unsigned long _bootsize;
char message[10];
...
siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
AT91F_DBGU_Frame(message);

But it always prints out "Bootsize: 0x2004d4" Why so?
As far as I understand, it's quite possible to do what I want.

Author: Giovanni Di sirio (gdisirio)
Posted on:

Rate this post
0 useful
not useful
Roman Mashak wrote:
> Hello,
>
> I define a constant in the linker script and want access it from C-code:
>
> SECTIONS
> {
> ...
>  _bootsize = 0x00004000;
> ...
> }
>
> Here is code snippet:
>
> extern unsigned long _bootsize;
> char message[10];
> ...
> siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
> AT91F_DBGU_Frame(message);
>
> But it always prints out "Bootsize: 0x2004d4" Why so?
> As far as I understand, it's quite possible to do what I want.

Looking at the documentation here:
http://sourceware.org/binutils/docs-2.18/ld/Source...

If I understood it right _bootsize is the address of your constant, the
constant is allocated there as a word.

Author: Jonathan Dumaresq (dumarjo)
Posted on:

Rate this post
0 useful
not useful
Roman Mashak wrote:
> Hello,
>
> I define a constant in the linker script and want access it from C-code:
>
> SECTIONS
> {
> ...
>  _bootsize = 0x00004000;
> ...
> }
>
> Here is code snippet:
>
> extern unsigned long _bootsize;
> char message[10];
> ...
> siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
> AT91F_DBGU_Frame(message);
>
> But it always prints out "Bootsize: 0x2004d4" Why so?
> As far as I understand, it's quite possible to do what I want.

Look at a sample here with the file syscall.c, you will have a sample on
how to access a constant address from C source.

Jonathan

Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
Giovanni Di Sirio wrote:
> Looking at the documentation here:
> 
http://sourceware.org/binutils/docs-2.18/ld/Source...
>
> If I understood it right _bootsize is the address of your constant, the
> constant is allocated there as a word.
Hm.. After reading documentation at the link, I come to the conclusion
that there is no way to assign a value to a linker script defined
symbol. Such symbol will always hold only address.

Am I right, there is no way to get what I want?

Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
Jonathan Dumaresq wrote:
> Look at a sample here with the file syscall.c, you will have a sample on
> how to access a constant address from C source.
Before posting I studied that code and did as in there. It seems I can't
achieve what I need: to define a constant value in a linker script and
use it from the C code.

Author: Roman Mashak (romez777)
Posted on:

Rate this post
0 useful
not useful
Giovanni Di Sirio wrote:
> Looking at the documentation here:
> 
http://sourceware.org/binutils/docs-2.18/ld/Source...

I must have read the link thoughtlessly the first time and missed the
point. Now I got it right - accessing the symbol defined in linker
script as "&_bootsize" works fine for me.

Thanks again.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.