From 33acd73f494190e9a147e67007a5ee1c3556a2fd Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 9 Feb 2018 23:22:35 +0700 Subject: [PATCH] correct linker --- .../components/toolchain/gcc/nrf52_common.ld | 26 ++++--- .../components/toolchain/gcc/nrf5x_common.ld | 24 ++++-- src/s132_2.0.1.ld | 78 ------------------- src/s140_6.0.0.ld | 6 +- 4 files changed, 36 insertions(+), 98 deletions(-) delete mode 100644 src/s132_2.0.1.ld diff --git a/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf52_common.ld b/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf52_common.ld index 75e2f4c..95a0557 100644 --- a/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf52_common.ld +++ b/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf52_common.ld @@ -21,7 +21,7 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") * with other linker script that defines memory regions FLASH and RAM. * It references following symbols, which must be defined in code: * Reset_Handler : Entry of reset handler - * + * * It defines following symbols, which code can use without definition: * __exidx_start * __exidx_end @@ -38,6 +38,7 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") * __bss_end__ * __end__ * end + * __HeapBase * __HeapLimit * __StackLimit * __StackTop @@ -73,8 +74,8 @@ SECTIONS KEEP(*(.eh_frame*)) } > FLASH - - .ARM.extab : + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > FLASH @@ -87,7 +88,7 @@ SECTIONS __exidx_end = .; __etext = .; - + .data : AT (__etext) { __data_start__ = .; @@ -131,12 +132,13 @@ SECTIONS . = ALIGN(4); __bss_end__ = .; } > RAM - + .heap (COPY): { + __HeapBase = .; __end__ = .; PROVIDE(end = .); - *(.heap*) + KEEP(*(.heap*)) __HeapLimit = .; } > RAM @@ -145,7 +147,7 @@ SECTIONS * values to stack symbols later */ .stack_dummy (COPY): { - *(.stack*) + KEEP(*(.stack*)) } > RAM /* Set stack top to end of RAM, and stack limit move down by @@ -153,8 +155,14 @@ SECTIONS __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); PROVIDE(__stack = __StackTop); - + /* Check if data + heap + stack exceeds RAM limit */ ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") + + /* Check if text sections + data exceeds FLASH limit */ + DataInitFlashUsed = __bss_start__ - __data_start__; + CodeFlashUsed = __etext - ORIGIN(FLASH); + TotalFlashUsed = CodeFlashUsed + DataInitFlashUsed; + ASSERT(TotalFlashUsed <= LENGTH(FLASH), "region FLASH overflowed with .data and user data") + } - diff --git a/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf5x_common.ld b/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf5x_common.ld index 69c98f8..2b86799 100644 --- a/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf5x_common.ld +++ b/nRF5_SDK_11.0.0_89a8197/components/toolchain/gcc/nrf5x_common.ld @@ -21,7 +21,7 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") * with other linker script that defines memory regions FLASH and RAM. * It references following symbols, which must be defined in code: * Reset_Handler : Entry of reset handler - * + * * It defines following symbols, which code can use without definition: * __exidx_start * __exidx_end @@ -38,6 +38,7 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") * __bss_end__ * __end__ * end + * __HeapBase * __HeapLimit * __StackLimit * __StackTop @@ -73,8 +74,8 @@ SECTIONS KEEP(*(.eh_frame*)) } > FLASH - - .ARM.extab : + + .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > FLASH @@ -87,7 +88,7 @@ SECTIONS __exidx_end = .; __etext = .; - + .data : AT (__etext) { __data_start__ = .; @@ -134,9 +135,10 @@ SECTIONS .heap (COPY): { + __HeapBase = .; __end__ = .; PROVIDE(end = .); - *(.heap*) + KEEP(*(.heap*)) __HeapLimit = .; } > RAM @@ -145,7 +147,7 @@ SECTIONS * values to stack symbols later */ .stack_dummy (COPY): { - *(.stack*) + KEEP(*(.stack*)) } > RAM /* Set stack top to end of RAM, and stack limit move down by @@ -153,8 +155,14 @@ SECTIONS __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); PROVIDE(__stack = __StackTop); - + /* Check if data + heap + stack exceeds RAM limit */ ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") + + /* Check if text sections + data exceeds FLASH limit */ + DataInitFlashUsed = __bss_start__ - __data_start__; + CodeFlashUsed = __etext - ORIGIN(FLASH); + TotalFlashUsed = CodeFlashUsed + DataInitFlashUsed; + ASSERT(TotalFlashUsed <= LENGTH(FLASH), "region FLASH overflowed with .data and user data") + } - diff --git a/src/s132_2.0.1.ld b/src/s132_2.0.1.ld deleted file mode 100644 index f8d0c69..0000000 --- a/src/s132_2.0.1.ld +++ /dev/null @@ -1,78 +0,0 @@ -/* Linker script to configure memory regions. */ - -SEARCH_DIR(.) -GROUP(-lgcc -lc -lnosys) - -MEMORY -{ - /** Flash start address for the bootloader. This setting will also be stored in UICR to allow the - * MBR to init the bootloader when starting the system. This value must correspond to - * BOOTLOADER_REGION_START found in dfu_types.h. The system is prevented from starting up if - * those values do not match. The check is performed in main.c, see - * APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); - */ - FLASH (rx) : ORIGIN = 0x74000, LENGTH = 0xA000 /* 40 KB */ - - /** RAM Region for bootloader. This setting is suitable when used with s132. */ - RAM (rwx) : ORIGIN = 0x20002C00, LENGTH = 0x5380 - - /** Location of non initialized RAM. Non initialized RAM is used for exchanging bond information - * from application to bootloader when using buttonluss DFU OTA. - */ - NOINIT (rwx) : ORIGIN = 0x20007F80, LENGTH = 0x80 - - /** Location of bootloader setting in flash. */ - BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0007F000, LENGTH = 0x1000 - - /** Location in UICR where bootloader start address is stored. */ - UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04 - - /** Location of mbr params page in flash. */ - MBR_PARAMS_PAGE (rw) : ORIGIN = 0x0007E000, LENGTH = 0x1000 - - /** Location in UICR where mbr params page address is stored. */ - UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04 -} - -SECTIONS -{ - .fs_data_out ALIGN(4): - { - PROVIDE( __start_fs_data = .); - KEEP(*(fs_data)) - PROVIDE( __stop_fs_data = .); - } = 0 - - /* Place the bootloader settings page in flash. */ - .bootloaderSettings(NOLOAD) : - { - - } > BOOTLOADER_SETTINGS - - /* Write the bootloader address in UICR. */ - .uicrBootStartAddress : - { - KEEP(*(.uicrBootStartAddress)) - } > UICR_BOOTLOADER - - /* Place the mbr params page in flash. */ - .mbrParamsPage(NOLOAD) : - { - - } > MBR_PARAMS_PAGE - - /* Write the bootloader address in UICR. */ - .uicrMbrParamsPageAddress : - { - KEEP(*(.uicrMbrParamsPageAddress)) - } > UICR_MBR_PARAM_PAGE - - /* No init RAM section in bootloader. Used for bond information exchange. */ - .noinit(NOLOAD) : - { - - } > NOINIT - /* other placements follow here... */ -} - -INCLUDE "nrf52_common.ld" diff --git a/src/s140_6.0.0.ld b/src/s140_6.0.0.ld index dce6bff..b23221f 100644 --- a/src/s140_6.0.0.ld +++ b/src/s140_6.0.0.ld @@ -11,7 +11,7 @@ MEMORY * those values do not match. The check is performed in main.c, see * APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START); */ - FLASH (rx) : ORIGIN = 0x74000, LENGTH = 0xA000 /* 40 KB */ + FLASH (rx) : ORIGIN = 0xF4000, LENGTH = 0xA000 /* 40 KB */ /** RAM Region for bootloader. This setting is suitable when used with s132. */ RAM (rwx) : ORIGIN = 0x20003000, LENGTH = 0x4000 @@ -22,13 +22,13 @@ MEMORY NOINIT (rwx) : ORIGIN = 0x20007F80, LENGTH = 0x80 /** Location of bootloader setting in flash. */ - BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0007F000, LENGTH = 0x1000 + BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x000FF000, LENGTH = 0x1000 /** Location in UICR where bootloader start address is stored. */ UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04 /** Location of mbr params page in flash. */ - MBR_PARAMS_PAGE (rw) : ORIGIN = 0x0007E000, LENGTH = 0x1000 + MBR_PARAMS_PAGE (rw) : ORIGIN = 0x000FE000, LENGTH = 0x1000 /** Location in UICR where mbr params page address is stored. */ UICR_MBR_PARAM_PAGE(r) : ORIGIN = 0x10001018, LENGTH = 0x04