EmbDev.net

Forum: ARM programming with GCC/GNU tools How to put two files at two different addresses in bss section


Author: Monika Tripathi (Company: ST Microelectronics) (monikat)
Posted on:

Rate this post
0 useful
not useful
Hello,

Can anyone please help me to fix the issue, I have two files uncached.c 
and gbl_data.c and both these files contain global variables meaning bss 
data, Now my requirement is i want to place these two files at different 
memory address i.e.
MEMORY
  {
  ram (rwx) : ORIGIN = 0, LENGTH = 0x14000000
  uncachedram (rwx) : ORIGIN = 0x14000000, LENGTH = 0x10000000
  dram (rwx) : ORIGIN = 0x15000000, LENGTH = 0xEAFFFFFF

  }

i want uncached.o should start from "uncachedram" and gbl_data.o from 
"dram"

I could place both .o file at same location i.e.
   .bss :
   {
   *(uncached_flags.o)
   *(.bss)
   *(gbl_shared_data.o)

   }>uncachedram


But while trying to put uncached.o @ "uncachedram" and gbl_data.o @ 
"dram"
I tried many options but none of them worked.

Author: Monika Tripathi (Company: ST Microelectronics) (monikat)
Posted on:

Rate this post
0 useful
not useful
Hello,

Can anyone please help on this topic??

Thanks and Regards,
Monika

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
Monika T. wrote:
> Can anyone please help me to fix the issue, ...

If you want to do this through the linker script, you'll need to get rid 
of wildcards in your file names (otherwise the linker will pick up all 
matching files for the default section).

Try like this:
MEMORY
{
  ram (rwx) : ORIGIN = 0, LENGTH = 0x14000000
  uncachedram (rwx) : ORIGIN = 0x14000000, LENGTH = 0x10000000
  dram (rwx) : ORIGIN = 0x15000000, LENGTH = 0xEAFFFFFF
}

SECTIONS
{ 
  arbitrary_named_section_1:
  {
    file_for_normal_section.o (*);
    file_for_other_bss_section.o (.text, .data)
  } > ram

  arbitrary_named_section_2:
  {
    file_for_other_bss_section.o (.bss)
  } > uncachedram
}

This should put all data of all mentioned files into ram except the .bss 
section of file_for_other_bss_section.o which will go into uncachedram.

Note that if you have other sections in your 
file_for_other_bss_section.o file, you want to have in ram, you'll need 
to add their names into the parenthesis.

Author: Monika Tripathi (Company: ST Microelectronics) (monikat)
Posted on:

Rate this post
0 useful
not useful
Hello Markus,

Thanks for information , but by doing so the global variables (bss 
section)of "uncached_flags.o"
rather than starting @address 0x14000000 i.e. uncachedram is taking 
address of .bss section being generated from compiler

my uncached.c file has following contents:
volatile int gbl_slave_start_flag;

gbl_data.c has following contents:
unsigned int lock;

Now i want to place "gbl_slave_start_flag" (From uncached.c) at 
0x14000000 i.e. @uncachedram

And "lock" (from gbl_data.c) at 0x15000000 i.e. @ dram

But by doing so the compiler generates its .bss section with some 
address lets say 0xxx and places
both these variables at 0xxx and 0xxx+some offset

Even if i define .bss section in my linker script then also the above 
mentioned variables go into the address of .bss section

I also tried one more thing i.e. i removed .bss from following:

arbitrary_named_section_2:
  {
    uncached.o (.bss)
  } > uncachedram

  Then also since ""gbl_slave_start_flag" is global unitialized data so 
it lies in .bss section resulting in its address being taken from .bss 
area not from uncachedram.

So my query is how can i place  variables/.o's files which lies in bss 
section at a fixed addresses.

i.e. two files which lie in bss section at two fixed memory locations.

Thanks for help.

Monika

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
Just checked. The file as shown above works for me:

Note that you'll need to compile and link your sources with -fno-common 
to avoid special .bss treatment as gcc's common blocks.

Name             Ursprung           Länge             Eigenschaften
ram              0x0000000000000000 0x0000000014000000 xrw
uncachedram      0x0000000014000000 0x0000000010000000 xrw
dram             0x0000000015000000 0x00000000eaffffff xrw
*default*        0x0000000000000000 0xffffffffffffffff

Linker script and memory map


arbitrary_named_section_1
                0x0000000015000000       0x9c
 file_for_normal_section.o(*)
 .text          0x0000000015000000        0xd file_for_normal_section.o
                0x0000000015000000                main
 .data          0x000000001500000d        0x0 file_for_normal_section.o
 *fill*         0x000000001500000d        0x3 
 .bss           0x0000000015000010        0x4 file_for_normal_section.o
                0x0000000015000010                sepp
 .comment       0x0000000015000014       0x25 file_for_normal_section.o
                                         0x26 (size before relaxing)
 .note.GNU-stack
                0x0000000015000039        0x0 file_for_normal_section.o
 *fill*         0x0000000015000039        0x7 
 .eh_frame      0x0000000015000040       0x38 file_for_normal_section.o
 .note.gnu.build-id
                0x0000000015000078       0x24 file_for_normal_section.o
 .eh_frame_hdr  0x000000001500009c        0x0 file_for_normal_section.o
 file_for_other_bss_section.o(.text, .data)
 .data          0x000000001500009c        0x0 file_for_other_bss_section.o

.text           0x000000001500009c        0x0
 .text          0x000000001500009c        0x0 file_for_other_bss_section.o

arbitrary_named_section_2
                0x0000000014000000        0x4
 file_for_other_bss_section.o(.bss)
 .bss           0x0000000014000000        0x4 file_for_other_bss_section.o
                0x0000000014000000                gbl_slave_start_flag
OUTPUT(a.out elf64-x86-64)

.comment        0x0000000000000000       0x25
 .comment       0x0000000000000000       0x25 file_for_other_bss_section.o
                                         0x26 (size before relaxing)

.note.GNU-stack
                0x0000000000000000        0x0
 .note.GNU-stack
                0x0000000000000000        0x0 file_for_other_bss_section.o

This is what you were asking for, isn't it?

: Edited by User
Author: Monika Tripathi (Company: ST Microelectronics) (monikat)
Posted on:

Rate this post
0 useful
not useful
Hello Markus,

Thanks for explanation, but by doing so i get following error:

/sw/st/gnu_compil/comp/arm/st/armv7-stlinux/bare-4.8.2-3/bin/../lib/gcc/ 
arm-none-eabi/4.8.2/../../../../arm-none-eabi/lib/rdimon-crt0.o:  In 
function `cpu_nostack_init_hook':
/tmp/3220925_1.tmpdir/stlinux-shared/build/packages/stm-bare-newlib-armv 
7/BUILD/newlib-2.0.0/objdir/arm-none-eabi/libgloss/arm/../../../../libgl 
oss/arm/crt0.S:510:  undefined reference to `__bss_start__'
/tmp/3220925_1.tmpdir/stlinux-shared/build/packages/stm-bare-newlib-armv 
7/BUILD/newlib-2.0.0/objdir/arm-none-eabi/libgloss/arm/../../../../libgl 
oss/arm/crt0.S:510:  undefined reference to `__bss_end__'
collect2: error: ld returned 1 exit status

The above error occurs when by linker.ld file is as follows:
MEMORY
  {
        ram (rwx) :     ORIGIN = 0,     LENGTH = 0x14000000
  uncachedram (rwx) :   ORIGIN = 0x14000000,   LENGTH = 0x10000000
  dram (rwx) :     ORIGIN = 0x15000000,   LENGTH = 0xEAFFFFFF

  }
IRQ_STACK_SIZE = 0x1000;
TEMP_STACKHEAP_SIZE = 0x2000;
SVC_STACK_SIZE = 0x1000;

ENTRY(Vectors)

SECTIONS
{
  . = 0x00000000;

  /* Code starts with bootcode, then the vector table, then the
   * remainder of the code */
  .text :
  {
    *boot.o(boot)
    *vectors.o(vectors)
    *(.text)
  } >ram


  /* Data */
   __data_start = .;
   .data  : { *(.data) } >ram
   .data1 :
     {
     *(.data1)
    }  >ram

  section_0 :
  {

  uncached_flags.o (.bss)
  }>uncachedram

 section_1 :
  {
  gbl_data.o (.bss)

   } >dram



 .stack :
 {
  _stack_start_ = . ;
   . += IRQ_STACK_SIZE;
   . = ALIGN (4);
  _irq_stack_top_ = . ;
   . += TEMP_STACKHEAP_SIZE;
   . = ALIGN (4);
  _temp_stack_top_ = . ;
   . += SVC_STACK_SIZE;
   . = ALIGN (4);
  _svc_stack_top_ = . ;
  _stack_end_ = .;
  } >dram


  . = ALIGN(4);
  __end   = .;
  _end_ = .;

  PROVIDE (end = .);
}

So to avoid above error i changed my linker.ld as follows:

MEMORY
  {
        ram (rwx) :     ORIGIN = 0,     LENGTH = 0x14000000
  uncachedram (rwx) :   ORIGIN = 0x14000000,   LENGTH = 0x10000000
  dram (rwx) :     ORIGIN = 0x15000000,   LENGTH = 0xEAFFFFFF

  }
IRQ_STACK_SIZE = 0x1000;
TEMP_STACKHEAP_SIZE = 0x2000;
SVC_STACK_SIZE = 0x1000;

ENTRY(Vectors)

SECTIONS
{


  . = 0x00000000;

  /* Code starts with bootcode, then the vector table, then the
   * remainder of the code */
  .text :
  {
    *boot.o(boot)
    *vectors.o(vectors)
    *(.text)
  } >ram


  /* Data */
   __data_start = .;
   .data  : { *(.data) } >ram
   .data1 :
     {
     *(.data1)
    }  >ram

  section_0 :
  {

  uncached_flags.o (.bss)
  }>uncachedram

 section_1 :
  {
  gbl_data.o (.bss)

   } >dram




  /* Uninitialized data */
  __bss_start   = .;
  _bss_start_ = .;


  __bss_end   = .;
  _bss_end_ = .;

 .stack :
 {
  _stack_start_ = . ;
   . += IRQ_STACK_SIZE;
   . = ALIGN (4);
  _irq_stack_top_ = . ;
   . += TEMP_STACKHEAP_SIZE;
   . = ALIGN (4);
  _temp_stack_top_ = . ;
   . += SVC_STACK_SIZE;
   . = ALIGN (4);
  _svc_stack_top_ = . ;
  _stack_end_ = .;
  } >dram


  . = ALIGN(4);
  __end   = .;
  _end_ = .;

  PROVIDE (end = .);
}

But now again my memory map is as follows:
 _bss_start_
    __bss_end
    _bss_end_
    __bss_start

====================================

** Section #17

    Name        : .bss
    Type        : SHT_NOBITS (0x00000008)
    Flags       : SHF_ALLOC + SHF_WRITE (0x00000003)
    Addr        : 0x15000000
    File Offset : 98304 (0x18000)
    Size        : 1600 bytes (0x640)
    Link        : SHN_UNDEF
    Info        : 0
    Alignment   : 64
    Entry Size  : 0

459  lock                   0x150005c0   Gb   17  Data  De   0x4
514  gbl_slave_start_flag       0x15000604   Gb   17  Data  De   0x4

"gbl_slave_start_flag" should be @0x14000000

Please note i have used -fno-common in my compiler as well as linker 
option.

Please suggest something, i want to fix this issue.
Thanks and Regards,
Monika

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
The error message indicates your newlib environment requires a .bss 
section. Why don't you just try and give it one?


Monika T. wrote:
> MEMORY
>   {
>         ram (rwx) :     ORIGIN = 0,     LENGTH = 0x14000000
>   uncachedram (rwx) :   ORIGIN = 0x14000000,   LENGTH = 0x10000000
>   dram (rwx) :     ORIGIN = 0x15000000,   LENGTH = 0xEAFFFFFF
>
>   }
> IRQ_STACK_SIZE = 0x1000;
> TEMP_STACKHEAP_SIZE = 0x2000;
> SVC_STACK_SIZE = 0x1000;
>
> ENTRY(Vectors)
>
> SECTIONS
> {
>
>   . = 0x00000000;
>
>   /* Code starts with bootcode, then the vector table, then the
>    * remainder of the code */
>   .text :
>   {
>     *boot.o(boot)
>     *vectors.o(vectors)
>     *(.text)
>   } >ram
>
>   /* Data */
>    __data_start = .;
>    .data  : { *(.data) } >ram
>    .data1 :
>      {
>      *(.data1)
>     }  >ram
>
>   section_0 :
>   {
>
>   uncached_flags.o (.bss)
>   }>uncachedram
>
>  section_1 :
>   {
>   gbl_data.o (.bss)
>
>    } >dram
>
  .bss :
  {
    /* Uninitialized data */
    __bss_start   = .;
    bss_start = .;

    whatever_file_needs_a_bss_section.o (.bss)

    __bss_end   = .;
    bss_end = .;
  } > ram
>
>  .stack :
>  {
>   stack_start = . ;
>    . += IRQ_STACK_SIZE;
>    . = ALIGN (4);
>   irq_stack_top = . ;
>    . += TEMP_STACKHEAP_SIZE;
>    . = ALIGN (4);
>   temp_stack_top = . ;
>    . += SVC_STACK_SIZE;
>    . = ALIGN (4);
>   svc_stack_top = . ;
>   stack_end = .;
>   } >dram
>
>   . = ALIGN(4);
>   __end   = .;
>   end = .;
>
>   PROVIDE (end = .);
> }

Author: JoJo (Guest)
Posted on:

Rate this post
0 useful
not useful
Aja, Fachkräfte.

Author: Monika Tripathi (Company: ST Microelectronics) (monikat)
Posted on:

Rate this post
0 useful
not useful
Hello Markus,

To get rid of error if i define bss section then again i am getting the 
same issue i.e. my gbl_slave pointing to 0x15000xxxx and gbl_data also 
pointing to 0x15000xxxx where as my requirement was:
gbl_slave should point to 0x14000xxxx and gbl_data should point to 
0x15000xxxx.

Regards,
Monika

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
Monika T. wrote:
> i define bss section

How does your linker script look like regarding the .bss section?

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.