From 5b0aaf0d39cbc99f620de08cfb153a2d27f88e3a Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 21 Sep 2018 15:06:49 +0200 Subject: [PATCH] targets: clean up and unify linker scripts Especially arm.ld needed some cleaning up. Other than that, I've made sure the two linker scripts look similar where possible. --- targets/arm.ld | 49 ++++++++++++++--------------------------- targets/avr.ld | 16 +++++++++----- tools/gen-device-svd.py | 4 ++-- 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/targets/arm.ld b/targets/arm.ld index dca80f7a..e5df3601 100644 --- a/targets/arm.ld +++ b/targets/arm.ld @@ -10,18 +10,14 @@ _stack_size = 2K; /* define output sections */ SECTIONS { - /* The program code and other data goes into FLASH */ + /* Program code and read-only data goes to FLASH_TEXT. */ .text : { - _stext = .; - . = ALIGN(4); KEEP(*(.isr_vector)) - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(4); - _etext = .; /* define a global symbol at end of code */ + *(.text) + *(.text*) + *(.rodata) + *(.rodata*) } >FLASH_TEXT /* Put the stack at the bottom of RAM, so that the application will @@ -31,54 +27,41 @@ SECTIONS { . = ALIGN(4); . += _stack_size; - __StackTop = .; + _stack_top = .; } >RAM + /* Start address (in flash) of .data, used by startup code. */ _sidata = LOADADDR(.data); - /* This is the initialized data section - The program executes knowing that the data is in the RAM - but the loader puts the initial values in the FLASH (inidata). - It is one task of the startup to copy the initial values from FLASH to RAM. */ + /* Globals with initial value */ .data : { . = ALIGN(4); - _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - + _sdata = .; /* used by startup code */ + *(.data) + *(.data*) . = ALIGN(4); - _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ + _edata = .; /* used by startup code */ } >RAM AT>FLASH_TEXT - /* Uninitialized data section */ + /* Zero-initialized globals */ .bss : { . = ALIGN(4); - _sbss = .; /* define a global symbol at bss start; used by startup code */ + _sbss = .; /* used by startup code */ *(.bss) *(.bss*) *(COMMON) - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end; used by startup code and GC */ + _ebss = .; /* used by startup code */ } >RAM /DISCARD/ : { - *(.ARM.exidx.*) - *(.ARM.attributes) - *(.stack) /* from nrfx */ - *(.heap) /* from nrfx */ + *(.ARM.exidx.*) /* causes spurious 'undefined reference' errors */ } } -/* For the nrfx startup file. */ -__etext = _etext; -__data_start__ = _sdata; -__bss_start__ = _sbss; -__bss_end__ = _ebss; - /* For the memory allocator. */ _heap_start = _ebss; _heap_end = ORIGIN(RAM) + LENGTH(RAM); diff --git a/targets/avr.ld b/targets/avr.ld index bd23d274..99d2f28b 100644 --- a/targets/avr.ld +++ b/targets/avr.ld @@ -1,10 +1,11 @@ MEMORY { - FLASH_TEXT (rw) : ORIGIN = 0, LENGTH = 32256 + FLASH_TEXT (rw) : ORIGIN = 0, LENGTH = 32K - _bootloader_size RAM (xrw) : ORIGIN = 0, LENGTH = 2K } +_bootloader_size = 512; _stack_size = 512; SECTIONS @@ -29,19 +30,22 @@ SECTIONS .data : { - _sdata = .; + _sdata = .; /* used by startup code */ *(.data) *(.data*) - _edata = .; + _edata = .; /* used by startup code */ } >RAM AT>FLASH_TEXT .bss : { - _sbss = .; + _sbss = .; /* used by startup code */ *(.bss) *(.bss*) *(COMMON) - _ebss = .; - _heap_start = .; + _ebss = .; /* used by startup code */ } >RAM } + +/* For the memory allocator. */ +_heap_start = _ebss; +_heap_end = ORIGIN(RAM) + LENGTH(RAM); diff --git a/tools/gen-device-svd.py b/tools/gen-device-svd.py index b2e86ebb..f5637f8f 100755 --- a/tools/gen-device-svd.py +++ b/tools/gen-device-svd.py @@ -278,8 +278,8 @@ Default_Handler: .global __isr_vector // Interrupt vector as defined by Cortex-M, starting with the stack top. // On reset, SP is initialized with *0x0 and PC is loaded with *0x4, loading - // __StackTop and Reset_Handler. - .long __StackTop + // _stack_top and Reset_Handler. + .long _stack_top .long Reset_Handler .long NMI_Handler .long HardFault_Handler