EmbDev.net

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


von Monika T. (Company: ST Microelectronics) (monikat)


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

von Monika T. (Company: ST Microelectronics) (monikat)


Rate this post
useful
not useful
Hello,

Can anyone please help on this topic??

Thanks and Regards,
Monika

von Markus F. (mfro)


Rate this post
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:
1
MEMORY
2
{
3
  ram (rwx) : ORIGIN = 0, LENGTH = 0x14000000
4
  uncachedram (rwx) : ORIGIN = 0x14000000, LENGTH = 0x10000000
5
  dram (rwx) : ORIGIN = 0x15000000, LENGTH = 0xEAFFFFFF
6
}
7
8
SECTIONS
9
{ 
10
  arbitrary_named_section_1:
11
  {
12
    file_for_normal_section.o (*);
13
    file_for_other_bss_section.o (.text, .data)
14
  } > ram
15
16
  arbitrary_named_section_2:
17
  {
18
    file_for_other_bss_section.o (.bss)
19
  } > uncachedram
20
}

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.

von Monika T. (Company: ST Microelectronics) (monikat)


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

von Markus F. (mfro)


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

1
Name             Ursprung           Länge             Eigenschaften
2
ram              0x0000000000000000 0x0000000014000000 xrw
3
uncachedram      0x0000000014000000 0x0000000010000000 xrw
4
dram             0x0000000015000000 0x00000000eaffffff xrw
5
*default*        0x0000000000000000 0xffffffffffffffff
6
7
Linker script and memory map
8
9
10
arbitrary_named_section_1
11
                0x0000000015000000       0x9c
12
 file_for_normal_section.o(*)
13
 .text          0x0000000015000000        0xd file_for_normal_section.o
14
                0x0000000015000000                main
15
 .data          0x000000001500000d        0x0 file_for_normal_section.o
16
 *fill*         0x000000001500000d        0x3 
17
 .bss           0x0000000015000010        0x4 file_for_normal_section.o
18
                0x0000000015000010                sepp
19
 .comment       0x0000000015000014       0x25 file_for_normal_section.o
20
                                         0x26 (size before relaxing)
21
 .note.GNU-stack
22
                0x0000000015000039        0x0 file_for_normal_section.o
23
 *fill*         0x0000000015000039        0x7 
24
 .eh_frame      0x0000000015000040       0x38 file_for_normal_section.o
25
 .note.gnu.build-id
26
                0x0000000015000078       0x24 file_for_normal_section.o
27
 .eh_frame_hdr  0x000000001500009c        0x0 file_for_normal_section.o
28
 file_for_other_bss_section.o(.text, .data)
29
 .data          0x000000001500009c        0x0 file_for_other_bss_section.o
30
31
.text           0x000000001500009c        0x0
32
 .text          0x000000001500009c        0x0 file_for_other_bss_section.o
33
34
arbitrary_named_section_2
35
                0x0000000014000000        0x4
36
 file_for_other_bss_section.o(.bss)
37
 .bss           0x0000000014000000        0x4 file_for_other_bss_section.o
38
                0x0000000014000000                gbl_slave_start_flag
39
OUTPUT(a.out elf64-x86-64)
40
41
.comment        0x0000000000000000       0x25
42
 .comment       0x0000000000000000       0x25 file_for_other_bss_section.o
43
                                         0x26 (size before relaxing)
44
45
.note.GNU-stack
46
                0x0000000000000000        0x0
47
 .note.GNU-stack
48
                0x0000000000000000        0x0 file_for_other_bss_section.o

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

: Edited by User
von Monika T. (Company: ST Microelectronics) (monikat)


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

von Markus F. (mfro)


Rate this post
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 = .);
> }

von JoJo (Guest)


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

von Monika T. (Company: ST Microelectronics) (monikat)


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

von Markus F. (mfro)


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

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

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.