EmbDev.net

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


von Roman M. (romez777)


Rate this post
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.

von Giovanni D. (gdisirio)


Rate this post
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-Code-Reference.html#Source-Code-Reference

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

von Jonathan D. (dumarjo)


Rate this post
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

von Roman M. (romez777)


Rate this post
useful
not useful
Giovanni Di Sirio wrote:
> Looking at the documentation here:
> 
http://sourceware.org/binutils/docs-2.18/ld/Source-Code-Reference.html#Source-Code-Reference
>
> 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?

von Roman M. (romez777)


Rate this post
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.

von Roman M. (romez777)


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

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.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.