s32k1xx_linker script

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

s32k1xx_linker script

1,445 Views
jongtaepark
Contributor I

Hello,

I'm using s32studio ARM v.2.0 and s32k144 EVB.

there is one thing that I don't understand in s32k1xx_flash.ld from SDK.

as you can see below, .stack segment is located next to .heap not in the end of m_data_2.

[        m_data_2                       ]

[bss][heap][stack]

however, __StackTop is set to the end address of m_data_2 as depicted in the below.

[        m_data_2                       ]

[bss][heap][stack]                    ^

                                                |---- __StackTop

I believe it should be like the below.

[        m_data_2                       ]

[bss][heap][stack]                   

                           |---- __StackTop

Plus, stack limit indicates the wrong position according to the linker script from SDK.

  [        m_data_2                       ]

  [bss][heap][stack]          [--1K--]         

                             ^         |----  stack limit position.

  should be here --|

Did I understand incorrectly?

s32k1xx_flash.ld

/* Specify the memory areas */
MEMORY
{
/* Flash */
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0

/* SRAM_L */
m_data (RW) : ORIGIN = 0x1FFF8000, LENGTH = 0x00008000

/* SRAM_U */
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00007000
}

.customSectionBlock ORIGIN(m_data_2) :
{
KEEP(*(.customSection)) /* Keep section even if not referenced. */
} > m_data_2

/* Uninitialized data section. */
.bss :
{
/* This is used by the startup in order to initialize the .bss section. */
. = ALIGN(4);
__BSS_START = .;
__bss_start__ = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
__BSS_END = .;
} > m_data_2

.heap :
{
. = ALIGN(8);
__end__ = .;
PROVIDE(end = .);
PROVIDE(_end = .);
PROVIDE(__end = .);
__HeapBase = .;
. += HEAP_SIZE;
__HeapLimit = .;
__heap_limit = .;
} > m_data_2

.stack :
{
. = ALIGN(8);
. += STACK_SIZE;
} > m_data_2

/* Initializes stack on the end of block */
__StackTop = ORIGIN(m_data_2) + LENGTH(m_data_2);
__StackLimit = __StackTop - STACK_SIZE;
PROVIDE(__stack = __StackTop);

.ARM.attributes 0 : { *(.ARM.attributes) }

Startup_S32k144.S

/* Initialize the stack pointer */
ldr r0,=__StackTop
mov r13,r0
0 Kudos
1 Reply

1,132 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

the Stack is filled backward - from StackTop down to StackLimit. So - the location is okay. 

Anyway - you can change stack location/size as you needed. Only not so "safe" thing on stack location at the end of RAM is that by stack overflow you may (but also may not)  re-write data in RAM. With stacktop location on the beginning of RAM + StackSize you got exception on stack overflow because you are trying write out of memory range. 

Jiri

0 Kudos