2018-05-07 06:37 AM
Hi All,
Am trying to fix the RAM addresses for new global variables in .data segment. For this, I have divided RAM into sections and by using attribute Am fixing address for newly created global variable. It was looks fine, but newly
added global variables are not initializing with default value i.e., 0 and it is persistent variables also getting affect i.e., after reset, persistent variables are initializing with zero instead of retaining the value.
I have created RAM sections like below,
In linker script:
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 120K
RAM2 (xrw) : ORIGIN = 0x20000000 + 120K, LENGTH = 8K.data :
{ . = ALIGN(4); _sdata = .; /* create a global symbol at data start */ *(.data) /* .data sections */ *(.data*) /* .data* sections */. = ALIGN(4);
_edata = .; /* define a global symbol at data end */ } >RAM AT> FLASH .data_user : { . = ALIGN(4); _sdata_user = .; /* create a global symbol at data start */ *(.data_user) /* .data sections */ *(.data_user*) /* .data* sections */. = ALIGN(4);
_edata_user = .; /* define a global symbol at data end */ } >RAM2 AT> FLASHIn startup code, I have added few instructions to initialize new global variables to 0.
movs r1, #0
b LoopCopyDataInit b LoopCopyUserDataInitCopyDataInit:
ldr r3, =_sidata ldr r3, [r3, r1] str r3, [r0, r1] adds r1, r1, #4 LoopCopyDataInit: ldr r0, =_sdata ldr r3, =_edata adds r2, r0, r1 cmp r2, r3 bcc CopyDataInit ldr r2, =_sbss b LoopFillZerobss/* Zero fill the bss segment. */ FillZerobss: movs r3, #0 str r3, [r2], #4 LoopFillZerobss: ldr r3, = _ebss cmp r2, r3 bcc FillZerobssCopyUserDataInit:
ldr r7, =_sdata_user ldr r7, [r7, r5] str r7, [r4, r5] adds r5, r5, #4LoopCopyUserDataInit:
ldr r4, =_sdata_user ldr r7, =_edata_user adds r6, r4, r5 cmp r6, r7 bcc CopyUserDataInit ldr r6, =_sdata_user bcc LoopFillZeroUserDataFillZeroUserbss:
movs r7, #0 str r7, [r6], #4LoopFillZeroUserData:
ldr r7, = _edata_user cmp r6, r7 bcc FillZeroUserbssIn .c file:
__attribute__((section('.user_data'))) int DebugEx1 = 0; // new global variable.
RAM address for
DebugEx1 is came inside .user_data section but, facing above bugs.
Please, Help me out from this problem
regards,
Bhargavi Ale.
2018-05-07 06:44 AM
You'll need to step through your assembler code find any bugs or issues with that. The code pasted here has lost all formatting.
The .MAP file will describe where the linker placed your assorted variables.
Not sure how the system would know which values you want to be persistent over a reset, those you'd likely need to direct to a NOLOAD/NOINIT type section, and not have your initialization routines touch.
2018-05-11 12:19 AM
,
,
Thanks for reply clive one.
After I changed code like below in startup file, new global
variables started working fine as a normal global variables.
movs r1, ♯ 0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3,
str r3,
adds r1, r1, ♯ 4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, ♯ 0
str r3, , ♯ 4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
movs r1, ♯ 0
b LoopCopyUserRamDataInit
CopyUserRamDataInit:
ldr r3, =_siuserdata
ldr r3,
str r3,
adds r1, r1, ♯ 4
LoopCopyUserRamDataInit:
ldr r0, =_suser_data
ldr r3, =_euser_data
adds r2, r0, r1
cmp r2, r3
bcc CopyUserRamDataInit.
And I need one more help i.e., have moved total *(.text) from .text section
of flash to user section (it is created by my own) of flash. Now, I want to
move few static library functions to .text section of flash. I know we can
move *.o files to particular section by exclude in user section of flash
and include in .text section, but I want to move only static library
fuctions.
Ex: example functions are memset, __sinit &, etc...
Can you help me out to move those functions?
Regards,
Bhargavi Ale.
On Mon, May 7, 2018 at 7:15 PM, Clive One <,st-microelectronics@jiveon.com>,
2018-05-11 12:46 AM
Perhaps you can:
Identify objects within a library
Have the tool generate 'One ELF Section per Function'
Use attribute to name section for function(s)
2018-05-11 06:08 AM
No, we can use attributes for functions which can see the definition or
prototype in files, but for static library function Am unable to give
attribute.
Is their any syntax like EXCLUDE_FILE to exclude function.
Regards,
Bhargavi Ale.
On Fri, May 11, 2018 at 11:16 AM, Clive One <st-microelectronics@jiveon.com>
2018-05-11 06:20 AM
GNU/GCC is not my tool of choice. Your options might be to rebuild the libraries in a way that permits function level identification (.text_memcpy), or reprocess the .ELF object/library to achieve the desired effect. Here I have the flexibility to code solutions to my own problems.
RealView had a method of passing the linker a definition file, you could provide name/address of ROM (or alternate memory images) based functions, and the linker would bind to those and drop the code from the current build, and do dead code elimination on an ancillary functions.
There might be better ways to solve your original problem.