Linker file for Library

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

Linker file for Library

1,235 Views
info55
Contributor I

I am using CW10.3 for MK20xx.

I have created a library where in specific code is to be placed in RAM.

Before creating the library I had a test program created using PE and have used the code as follows

Header file contents

#pragma define_section relocate_code ".relocate_code" ".relocate_code" ".relocate_code" far_abs RW
#define __relocate_code__ __declspec(relocate_code)

File.C

__relocate_code__
UINT32 FlashCommandSequence (PFLASH_SSD_CONFIG PSSDConfig, \
UINT8 index, \
UINT8* pCommandArray)

{

. . . .

}

and the linker file ProcessorExpert.Lcf contains

KEEP_SECTION { .vectortable }
KEEP_SECTION { .cfmconfig }

KEEP_SECTION { .relocate_code }

MEMORY {
m_interrupts (RX) : ORIGIN = 0x00004000, LENGTH = 0x000001E0
m_text (RX) : ORIGIN = 0x00004400, LENGTH = 0x0003AC00
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00010000
m_data_20000000 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00010000
m_cfmprotrom (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
m_programbuff (RW) : ORIGIN = 0x14000000, LENGTH = 0x00001000
}

|

|

.relocate_code :
{
* (.relocate_code)
. = ALIGN (0x4);
} > m_programbuff

This worked perfectly all right for me.

After testing is done I created library (*.a) where this "FlashCommandSequence" function is used internally by a library function.

As there is no LCF file in the library project. I am wondering how to place the code in RAM so that when this library is linked to another project by me end user the code is placed in RAM.

Rgds

Uday 

0 Kudos
3 Replies

1,100 Views
info55
Contributor I

Hello Felipe,

Thanks for taking time to reply. I saw the link and found that

"The linker script template techniques described in this FAQ apply to LPCXpresso IDE v7.9.0"

As already mentioned I am using CW10.3 with PE, so I dont think this would be helpful.

In the meantime I tried doing following and got success

In the code file

#pragma define_section relocate_code ".relocate_code"  far_abs RX

__declspec(relocate_code) UINT32 foo()

{

|

|

}

And in linker file *.lcf

___CodeStart = ___ROM_AT+ SIZEOF(.data);
.relocate_code : AT(___CodeStart)
{
. = ALIGN (0x4);
___myRAMStart = .;
* (.relocate_code)
___myRAMEnd = .;
. = ALIGN (0x4);
} > m_programbuff
___CodeSize = ___myRAMEnd - ___myRAMStart;

This script I placed after the (.data) segment 

And finally 

_romp_at = ___ROM_AT + SIZEOF(.data) +SIZEOF(.m_data_20000000) +SIZEOF(.relocate_code);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
WRITEW(___ROM_AT);
WRITEW(ADDR(.data));
WRITEW(SIZEOF(.data));
WRITEW(___CodeStart);
WRITEW(___myRAMStart);
WRITEW(___CodeSize);
WRITEW(0);
WRITEW(0);
WRITEW(0);
}

This worked for me when I am checking the library code and when the created library is compiled in the end users code.

This method I learned from AN4498-CodeWarrior Linker Command File (LCF) for
Kinetis 

Thanks again..

0 Kudos

1,100 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello Uday,

 

Please check the below post in section Relocating particular libraries into RAM.

Relocating code from FLASH to RAM

 

Have a great day,
Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,100 Views
info55
Contributor I

Hello Felipe,

Thanks for taking time to reply. I saw the link and found that

"The linker script template techniques described in this FAQ apply to LPCXpresso IDE v7.9.0"

 

As already mentioned I am using CW10.3 with PE, so I dont think this would be helpful.

In the meantime I tried doing following and got success

 

In the code file

#pragma define_section relocate_code ".relocate_code"  far_abs RX

__declspec(relocate_code) UINT32 foo()

{

 

|

|

 

}

And in linker file *.lcf

___CodeStart = ___ROM_AT+ SIZEOF(.data);
.relocate_code : AT(___CodeStart)
{
. = ALIGN (0x4);
___myRAMStart = .;
* (.relocate_code)
___myRAMEnd = .;
. = ALIGN (0x4);
} > m_programbuff
___CodeSize = ___myRAMEnd - ___myRAMStart;

 

This script I placed after the (.data) segment 

 

And finally 

 

_romp_at = ___ROM_AT + SIZEOF(.data) +SIZEOF(.m_data_20000000) +SIZEOF(.relocate_code);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
WRITEW(___ROM_AT);
WRITEW(ADDR(.data));
WRITEW(SIZEOF(.data));
WRITEW(___CodeStart);
WRITEW(___myRAMStart);
WRITEW(___CodeSize);
WRITEW(0);
WRITEW(0);
WRITEW(0);
}

 

This worked for me when I am checking the library code and when the created library is compiled in the end users code.

 

This method I learned from AN4498-CodeWarrior Linker Command File (LCF) for
Kinetis 

 

Thanks again..

Uday

0 Kudos