Difference between revisions of "Placing external library symbols at specific address"

From SEGGER Wiki
Jump to: navigation, search
(Created page with "One of the big benefits of the SEGGER Linker is its simple usage. In this scenario an external library will be placed in a specific memory location. * Usually everything is pl...")
 
(How to)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
  +
[[Category:Embedded Studio]]
One of the big benefits of the SEGGER Linker is its simple usage. In this scenario an external library will be placed in a specific memory location.
 
  +
==How to==
* Usually everything is placed under .text section. Check your symbol browser or map file to locate how the subsection of the external library is called. For this example we will show how the libc library can be placed into a different Flash memory region.
 
  +
One of the big benefits of the SEGGER Linker is its simple usage.
  +
In this scenario an external library will be placed in a specific memory location.
  +
* Usually everything is placed under .text section. Check your symbol browser or map file to locate how the subsection of the external library is called. For this example we will show how the libc library can be placed into a different memory region.
 
* Open your projects linker script(.icf file) for editing.
 
* Open your projects linker script(.icf file) for editing.
  +
* Add a new placement for your particular library subsection into the desired region. e.g.
* Make sure the memory regions you are looking to use are defined in your memory map file or in project settings in memory segments. e.g.
 
<pre>define region FLASH = FLASH1;
 
define region FLASH_LIB = FLASH2;</pre>
 
* Add a new Flash placement for your particular library subsection e.g.
 
 
<pre>
 
<pre>
place in FLASH_LIB { section .text.libc, section .text.libc.*};
+
place in MEM_LIB { section .text.libc, section .text.libc.*};
 
</pre>
 
</pre>
* In the general .text Flash placement add an exception for this subsection otherwise the linker will throw an error that the same symbols are linked twice.
+
* In the general placement where other code sections are placed, add an exception for this subsection otherwise the linker will throw an error that the same symbols are linked twice.
 
<pre>
 
<pre>
 
place in FLASH with minimum size order { section .init, section .init.*, // Init code section
 
place in FLASH with minimum size order { section .init, section .init.*, // Init code section
Line 21: Line 21:
 
except { section .text.libc, section .text.libc.*};
 
except { section .text.libc, section .text.libc.*};
 
</pre>
 
</pre>
* Now everything should be set up and all libc function should be linked into region FLASH2
+
* Now everything should be set up and all libc function should be linked into region MEM_LIB.
  +
'''Note:''' If you are placing the symbols in RAM the following must be considered additionally:
  +
[https://wiki.segger.com/Functions_in_RAM Placing functions in RAM]
  +
  +
==Example project==
  +
The following example project shows such a setup where the SEGGER Runtime Library functions are all linked into RAM. To verify the setup the IDE [https://www.segger.com/products/development-tools/embedded-studio/ Embedded Studio] can be used to rebuild and debug the project.
  +
===Prerequisites===
  +
* Embedded Studio V4.50 or later
  +
* STM32F407VE based target board e.g. a [https://www.segger.com/products/debug-probes/j-trace/accessories/trace-reference-boards/overview/#cortex-m-trace-reference-board Cortex-M Trace Reference Board]
  +
* [https://www.segger.com/products/debug-probes/j-link/models/model-overview/ J-Link Base] V10 or higher
  +
  +
===Project===
  +
[[Media:STM32F407VE_SEGGER_RunTimeLibrary_LinkToRAM.zip|STM32F407VE_SEGGER_RunTimeLibrary_LinkToRAM.zip]]

Latest revision as of 17:07, 17 June 2020

How to

One of the big benefits of the SEGGER Linker is its simple usage. In this scenario an external library will be placed in a specific memory location.

  • Usually everything is placed under .text section. Check your symbol browser or map file to locate how the subsection of the external library is called. For this example we will show how the libc library can be placed into a different memory region.
  • Open your projects linker script(.icf file) for editing.
  • Add a new placement for your particular library subsection into the desired region. e.g.
place in MEM_LIB                            { section .text.libc, section .text.libc.*};
  • In the general placement where other code sections are placed, add an exception for this subsection otherwise the linker will throw an error that the same symbols are linked twice.
place in FLASH with minimum size order      { section .init,   section .init.*,        // Init code section
                                              section .init_rodata, section .init_rodata.*, // Init read-only section
                                              section .text,   section .text.*,        // Code section
                                              section .rodata, section .rodata.*,      // Read-only data section
                                              section .segger.*,                       // Auto-generated initialization
                                              block exidx,                             // ARM exception unwinding block
                                              block ctors,                             // Constructors block
                                              block dtors }                            // Destructors block
                                     except { section .text.libc, section .text.libc.*};
  • Now everything should be set up and all libc function should be linked into region MEM_LIB.

Note: If you are placing the symbols in RAM the following must be considered additionally: Placing functions in RAM

Example project

The following example project shows such a setup where the SEGGER Runtime Library functions are all linked into RAM. To verify the setup the IDE Embedded Studio can be used to rebuild and debug the project.

Prerequisites

Project

STM32F407VE_SEGGER_RunTimeLibrary_LinkToRAM.zip