Variable Space in internal AT91SAM7 flash

Guest #1172463
Rate this post
• ▲ useful
▼ not useful
Hello,

Has anyone found a need to modify the linker scripts for the AT91SAM7 to
carve off some internal flash variable space?

I'm working with a AT91SAM7S256 and would LIKE to shave off the top 1k
to store variables but am having trouble getting it to work right.

Details:  using WinARM w/ gcc 4.1.1
I have the linker scripts from Martin Thomas' gamma example (last
updated on 2-Sept-06.  In my AT91SAM7S256_memory.ldh file I modified it
as follows:

From:

MEMORY
{
  CODE (rx)  : ORIGIN = 0x00100000, LENGTH = 256k
  DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 64k
}

To:

MEMORY
{
  CODE (rx)  : ORIGIN = 0x00100000, LENGTH = 255k
  DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 64k
  VARS (rx)  : ORIGIN = 0x0013FC00, LENGTH = 1k
}


And declared a variable as:
const unsigned int checker _attribute_ ((section ("VARS"))) = 0xF;

When the linker runs and it reports the following:

Size after:
main.tmp.elf  :
section     size      addr
.text      53444   1048576
VARS           4   1102020
.data       2928   2097152
.noinit       12   2100080
.bss        3328   2100092
.comment    1512         0
Total      61228

So it looks like the variable is in the "VARS" section but the address
doesn't make sense.  It is in the "CODE" section a.k.a. addr:
0x0010D0C4.

I'm guessing I have to modify the AT91SAM7S_sections_ROM.ldh file to
accomodate this change but that file just looks scary.

Has anyone done something similar and got it to work out?

Thanks in advance for any help!
Guest #1172464
Rate this post
• ▲ useful
▼ not useful
Nick Moszer wrote:
> Hello,
>
> Has anyone found a need to modify the linker scripts for the AT91SAM7 to
> carve off some internal flash variable space?
>
> I'm working with a AT91SAM7S256 and would LIKE to shave off the top 1k
> to store variables but am having trouble getting it to work right.
>
> Details:  using WinARM w/ gcc 4.1.1
> I have the linker scripts from Martin Thomas' gamma example (last
> updated on 2-Sept-06.  In my AT91SAM7S256_memory.ldh file I modified it
> as follows:
>
> From:
>
> MEMORY
> {
>   CODE (rx)  : ORIGIN = 0x00100000, LENGTH = 256k
>   DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 64k
> }
>
> To:
>
> MEMORY
> {
>   CODE (rx)  : ORIGIN = 0x00100000, LENGTH = 255k
>   DATA (rwx) : ORIGIN = 0x00200000, LENGTH = 64k
>   VARS (rx)  : ORIGIN = 0x0013FC00, LENGTH = 1k
> }
>
>
> And declared a variable as:
> const unsigned int checker _attribute_ ((section ("VARS"))) = 0xF;
>
> When the linker runs and it reports the following:
>
> Size after:
> main.tmp.elf  :
> section     size      addr
> .text      53444   1048576
> VARS           4   1102020
> .data       2928   2097152
> .noinit       12   2100080
> .bss        3328   2100092
> .comment    1512         0
> Total      61228
>
> So it looks like the variable is in the "VARS" section but the address
> doesn't make sense.  It is in the "CODE" section a.k.a. addr:
> 0x0010D0C4.
>
> I'm guessing I have to modify the AT91SAM7S_sections_ROM.ldh file to
> accomodate this change but that file just looks scary.
>
> Has anyone done something similar and got it to work out?
>
> Thanks in advance for any help!


Wow, ok I think I actually got it.  Maybe anyway.

I just edited that AT91SAM7S_sections_ROM.ldh as (added .vars):

  .dtors :
  {
    PROVIDE(_dtors_start_ = .);
    KEEP(*(SORT(.dtors.*)))
    KEEP(*(.dtors))
    PROVIDE(_dtors_end_ = .);
  } >CODE

  . = ALIGN(4);

  .vars :
  {
    __vars_start = . ;
    _vars_start_ = . ;
    *(.vars)
    *(.vars.*)
    *(.gnu.linkonce.v.*)
    *(VARS)
    . = ALIGN(4);
  } >VARS

  . = ALIGN(4);

  _etext = . ;
  PROVIDE (etext = .);

  /* .data section which is used for initialized data */
  .data : AT (_etext)
  {


Is this the proper way to do this?

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.