motorcontroldemo_035/cmd/build.ld
2019-07-29 08:17:46 +03:00

243 lines
9.1 KiB
Plaintext

/******************************************************************************
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
* @file build.ld
* @brief Ôàéë ðàñïðåäåëåíèÿ ïàìÿòè äëÿ âûïîëíåíèÿ èç FLASH
* @version v1.0
* @date 11 äåêàáðÿ 2015
*
* @author ÎÎÎ "ÍÏÔ Âåêòîð", http://motorcontrol.ru
*
******************************************************************************/
/* Entry Point */
ENTRY(Reset_Handler)
/* Generate a link error if heap and stack don't fit into RAM */
_Stack_Size = 0x1000; /* required amount of stack */
/* Specify the memory areas */
/* Áóêâû â ñêîáêàõ îïðåäåëÿþò àòðèáóòû: äîñòóï íà ÷òåíèå,
* çàïèñü, èñïîëíåíèå, âûäåëåíèå ïàìÿòè. */
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x10000
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x4000
}
/* Êîíåö ÐÀÌû íà ÍÈÈÝÒÅ (ñ çàïàñèêîì) - îòñþäà âíóòðü áóäåò ðàñòè ñòåê*/
_estack = ORIGIN(RAM) + LENGTH(RAM) - 4;
/* Define output sections */
SECTIONS
{
. = ORIGIN(RAM);
/* òàáëèöà âåêòîðîâ ïðåðûâàíèé, îáÿçàíà áûòü âûðîâíåíà ïî 0õ80 */
.isr_vector ALIGN(0x80):
{
__isr_vector_flash_start = LOADADDR (.isr_vector); /* Áåðåì àäðåñ, ãäå íà ôëåøå ëåæèò ýòà òàáëèöà */
__isr_vector_ram_start = .;
KEEP(*(.isr_vector)) /* Startup code - KEEP çàïðåùàåò óäàëèòü ñåêöèþ ñáîðùèêó ìóñîðà */
. = ALIGN(4);
__isr_vector_ram_end = .; /* êîíåö îïåðàòèâêè, êóäà áóäåò ñêîïèðîâàí êîä */
} >RAM AT>FLASH
/* Ñåêöèÿ äëÿ êîäà, êîòîðûé èñïîëíÿåòñÿ â îïåðàòèâêå, à ëåæèò íà ôëåøå.
*  íà÷àëå ìåéíà îí êîïèðóåòñÿ èç ROM â RAM.*/
.fastcode ALIGN(4): {
__fastcode_flash_start = LOADADDR (.fastcode); /* Áåðåì àäðåñ, ãäå íà ôëåøå ëåæèò êîä. */
/* Òî÷êà - ýòî êóðñîð òåêóùåãî ðàçìåùåíèÿ â ïàìÿòè. Ò.å. â
* __fastcode_ram_start áóäåò ëåæàòü àäðåñ îïåðàòèâêè, ãäå áóäåò èñïîëíÿòüñÿ ñêîïèðîâàííûé êîä.*/
__fastcode_ram_start = .;
*(.glue_7t) *(.glue_7)
*(.fastcode)
*(.fastcode*)
. = ALIGN (4);
__fastcode_ram_end = .; /* êîíåö îïåðàòèâêè, êóäà áóäåò ñêîïèðîâàí êîä */
} >RAM AT>FLASH
/* The program code and other data goes into RAM */
.text :
{
. = ALIGN(4);
*(.text) /* .text sections (code) */
*(.text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
/* define a global symbols at end of code - óêàçàòåëü íà êîíåö êîäà,
ò.ê. òî÷êà - ýòî ïåðåìåííàÿ ñ èíêðåìåíòèðóþùèìñÿ çíà÷åíèåì àäðåñà (íàçûâàþò å¸ êóðñîð)*/
_etext = .;
} >FLASH
/* .preinit_array - ñåêöèÿ äëÿ óêàçàòåëåé íà ôóíêöèè ïðå-èíèöèàëèçàöèè,
* âûçûâàåìûõ ïåðåä ëþáûìè äðóãèìè ôóíêöèÿìè
* èíèöèàëèçàöèè (ïåðåä âûïîëíåíèåì êîäà èç ñåêöèè
* '.init' è âûçîâàìè ôóíêöèé èç ñåêöèè '.init_array').
*
* Ñïåöèàëüíàÿ ñåêöèÿ ñ èìåíåì '.preinit_array' è âûøåíàçâàííûì
* íàçíà÷åíèåì îïèñàíà â System V gABI. Âûçîâ ôóíêöèé, óêàçàòåëè íà
* êîòîðûå ñîäåðæàòñÿ â ñåêöèè '.preinit_array', âîçëàãàåòñÿ íà áèáëèîòåêó
* âðåìåíè âûïîëíåíèÿ (runtime library) -- íàïðèìåð, íà C runtime. Åñëè â
* áèáëèîòåêå íå ïðåäóñìîòðåí òàêîé âûçîâ, òî ôóíêöèè èç ñåêöèè
* '.preinit_array' íå áóäóò âûçâàíû.
*
* Ñåêöèÿ '.preinit_array' ïðåäíàçíà÷åíà äëÿ ïðå-èíèöèàëèçàöèè
* èñïîëíÿåìîãî ôàéëà (executable), âûïîëíÿåìîé ïåðåä èíèöèàëèçàöèåé
* äèíàìè÷åñêè ñêîìïîíîâàííûõ ñ íèì ðàçäåëÿåìûõ îáúåêòîâ (shared objects).
*
* Ñèìâîëû __preinit_array_start è __preinit_array_end èñïîëüçóþòñÿ
* áèáëèîòåêîé C âðåìåíè âûïîëíåíèÿ (newlib, glibc).
*/
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH
/* .init_array - ñåêöèè ñ óêàçàòåëÿìè íà ôóíêöèè èíèöèàëèçàöèè,
* âûïîëíÿþùèåñÿ ïåðåä âûçîâîì âõîäíîé òî÷êè ïðîãðàììû, ò.å.
* ïåðåä âûçîâîì ôóíêöèè main.
*
* Ñïåöèàëüíàÿ ñåêöèÿ ñ èìåíåì '.init_array' è âûøåíàçâàííûì íàçíà÷åíèåì
* îïèñàíà â System V gABI. Âûçîâ ôóíêöèé, óêàçàòåëè íà êîòîðûå ñîäåðæàòñÿ â
* ñåêöèè '.init_array', âîçëàãàåòñÿ íà áèáëèîòåêó âðåìåíè âûïîëíåíèÿ
* (runtime library) -- íàïðèìåð, íà C runtime. Åñëè â áèáëèîòåêå íå
* ïðåäóñìîòðåí òàêîé âûçîâ, òî ôóíêöèè èç ñåêöèè '.init_array' íå áóäóò
* âûçâàíû.
*
* GCC èñïîëüçóåò ñåêöèþ '.init_array' äëÿ îáåñïå÷åíèÿ âûçîâà ñòàòè÷åñêèõ
* êîíñòðóêòîðîâ: ôóíêöèé, îáúÿâëåííûõ ñ __attribute__((constructor)).
*
* Äëÿ ñòàòè÷åñêèõ êîíñòðóêòîðîâ ñ îáúÿâëåííûì ïðèîðèòåòîì PRIORITY,
* èñïîëüçóþòñÿ ñåêöèè ñ èìåíåì '.init_array.PRIORITY'
*
* Òàêæå GCC èñïîëüçóåò ñåêöèþ '.init_array' äëÿ âûçîâà êîíñòðóêòîðîâ
* ñòàòè÷åñêèõ îáúåêòîâ C++.
*
* Ñèìâîëû __init_array_start è __init_array_end èñïîëüçóþòñÿ áèáëèîòåêîé
* C âðåìåíè âûïîëíåíèÿ (newlib, glibc).
*/
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH
/* .fini_array - ñåêöèè ñ óêàçàòåëÿìè íà ôóíêöèè òåðìèíàöèè,
* âûïîëíÿþùèåñÿ ïî çàâåðøåíèþ ïðîãðàììû (ïîñëå âîçâðàòà èç
* âõîäíîé òî÷êè ïðîãðàììû, ò.å. èç ôóíêöèè main).
*
* Ñïåöèàëüíàÿ ñåêöèÿ ñ èìåíåì '.fini_array' è âûøåíàçâàííûì íàçíà÷åíèåì
* îïèñàíà â System V gABI. Âûçîâ ôóíêöèé, óêàçàòåëè íà êîòîðûå ñîäåðæàòñÿ â
* ñåêöèè '.fini_array', âîçëàãàåòñÿ íà áèáëèîòåêó âðåìåíè âûïîëíåíèÿ
* (runtime library) -- íàïðèìåð, íà C runtime. Åñëè â áèáëèîòåêå íå
* ïðåäóñìîòðåí òàêîé âûçîâ, òî ôóíêöèè èç ñåêöèè '.fini_array' íå áóäóò
* âûçâàíû.
*
* GCC èñïîëüçóåò ñåêöèþ '.fini_array' äëÿ îáåñïå÷åíèÿ âûçîâà ñòàòè÷åñêèõ
* äåñòðóêòîðîâ: ôóíêöèé, îáúÿâëåííûõ ñ __attribute__((destructor)).
*
* Äëÿ ñòàòè÷åñêèõ äåñòðóêòîðîâ ñ îáúÿâëåííûì ïðèîðèòåòîì PRIORITY,
* èñïîëüçóþòñÿ ñåêöèè ñ èìåíåì '.fini_array.PRIORITY'
*
* Ñèìâîëû __fini_array_start è __fini_array_end èñïîëüçóþòñÿ áèáëèîòåêîé
* C âðåìåíè âûïîëíåíèÿ (newlib, glibc).
*/
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array*))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH
/* used by the startup to initialize data */
_sidata = .;
/* Âûðàæåíèå _sidata, êîòîðîå ñëåäóåò çà êëþ÷åâûì ñëîâîì AT,
* îïðåäåëÿåò àäðåñ çàãðóçêè ñåêöèè. Ïî óìîë÷àíèþ, åñëè Âû
* íå èñïîëüçîâàëè êëþ÷åâîå ñëîâî AT, àäðåñ çàãðóçêè ðàâåí àäðåñó ïåðåìåùåíèÿ.
* Òàê êàê _sidata äî ýòîãî áûëî ðàâíî òî÷êå (óêàçàòåëü íà òåêóùèé àäðåñ),
* òî .data ïîéäåò ñðàçó äàëüøå ïîñëå íå¸. Êàê áû äèíàìè÷åñêîå ñìåùåíèå òàêîå.
* */
/* Initialized data sections goes into RAM, load LMA copy after code */
.data : AT ( _sidata )
{
. = 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
_________________________ZHOPA__________________________ = .;
/* Uninitialized data section */
. = ALIGN(4);
.bss :
{
/* This is used by the startup in order to initialize the .bss secion */
_sbss = .; /* define a global symbol at bss start */
__bss_start__ = _sbss;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM
/* Ôóíêöè ïðîâåðÿåò, ÷òî ïîñëå âñåãî êîäà îñòàëîñü ìåñòî ïîä ñòåê.
* Ñòåê ñäåëàí ñíèçó îïåðàòèâêè!
* Íå ðàçìåùàéòå ñâîè ñåêöèè ïîñëå ýòîé ôóíêöèè, òîëüêî ïåðåä!*/
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Stack_Size + 4;
. = ALIGN(4);
} >RAM
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
/* Òóò êàêèå-òî àòðèáóòû îá îñîáåííîñòÿõ êîìïèëÿöèè, ñïåöèôè÷íàÿ èíôà ïðîèçâîäèòåëÿ è õç åùå ÷òî, ÷èòàéòå
* 4.3.6 Build Attributes http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf */
.ARM.attributes 0 : { *(.ARM.attributes) }
}