This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 0fb90bd3a192b11f486ad8cc22877708da324758
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Thu Aug 22 10:05:35 2024 +0200

    boot/startup: Linker script template unification
    
    Now all cortex linker script files have region for
    interrupt stack.
    It can be provided by memory_regions.ld.h if
    stack is to be placed in separate memory region.
    If MCU/BSP specific region is defined (no definition
    of STACk_REGION)
    STACK_RAM region is created at the end of RAM.
    This simplifies check for heap.
    
    mtb section is removed for now from all linker script
    templates as it is not present in any MCU that has
    generated linker script.
    
    Few templates had duplicating section .bssnz that is now removed.
    
    bss sections now have (NOLOAD) attribute
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 boot/startup/mynewt_cortex_m0.ld  | 42 +++++++++++++++++++--------------------
 boot/startup/mynewt_cortex_m3.ld  | 42 +++++++++++++++++++--------------------
 boot/startup/mynewt_cortex_m33.ld | 42 +++++++++++++++++++--------------------
 boot/startup/mynewt_cortex_m7.ld  | 35 +++++++++++++++++---------------
 4 files changed, 79 insertions(+), 82 deletions(-)

diff --git a/boot/startup/mynewt_cortex_m0.ld b/boot/startup/mynewt_cortex_m0.ld
index ce4d8c0fa..b74fd10de 100644
--- a/boot/startup/mynewt_cortex_m0.ld
+++ b/boot/startup/mynewt_cortex_m0.ld
@@ -19,6 +19,7 @@
 
 #include <syscfg/syscfg.h>
 #include <sysflash/sysflash.h>
+#include <mcu_config.ld.h>
 #include <bsp_config.ld.h>
 #include <target_config.ld.h>
 #include <mynewt_config.ld.h>
@@ -36,7 +37,18 @@ MEMORY
 #ifdef FLASH_AREA_IMAGE_0_OFFSET
     SLOT0 (rx!w) : ORIGIN = FLASH_AREA_IMAGE_0_OFFSET, LENGTH = 
FLASH_AREA_IMAGE_0_SIZE
 #endif
+    /*
+     * If STACK_REGION is defined it means that MCU stack is place in other 
region then RAM
+     * int that case RAM region size is exactly RAM_SIZE
+     * If STACK_REGION is NOT defined STACK_RAM region is place at the end of 
RAM
+     * and RAM region size is shortened.
+     */
+#ifdef STACK_REGION
     RAM (rwx) : ORIGIN = RAM_START, LENGTH = RAM_SIZE
+#else
+    RAM (rwx) : ORIGIN = RAM_START, LENGTH = (RAM_SIZE - STACK_SIZE)
+    STACK_RAM (rw) : ORIGIN = RAM_START + RAM_SIZE - STACK_SIZE, LENGTH = 
STACK_SIZE
+#endif
 #include <memory_regions.ld.h>
 }
 
@@ -247,7 +259,7 @@ SECTIONS
     __data_image__ = LOADADDR(.data);
     _sidata = LOADADDR(.data);
 
-    .bssnz :
+    .bssnz (NOLOAD) :
     {
         . = ALIGN(4);
         __bssnz_start__ = .;
@@ -269,14 +281,8 @@ SECTIONS
         __ecorebss = .;
     } > COREBSS_RAM
 #endif
-    .bssnz (NOLOAD):
-    {
-        . = ALIGN(4);
-        *(.bss.core.nz)
-        . = ALIGN(4);
-    } > RAM
 
-    .bss :
+    .bss (NOLOAD) :
     {
         . = ALIGN(4);
         _sbss = .;
@@ -291,27 +297,19 @@ SECTIONS
     /* Heap starts after BSS */
     . = ALIGN(8);
     __HeapBase = .;
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
 
-    /* Dummy section to calculate whether we need to move stack out of MTB
-     * buffer or not. */
-    .mtb (NOLOAD) :
-    {
-        KEEP(*(.mtb));
-    }
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
 
     _ram_start = ORIGIN(RAM);
 
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
-    __StackTop = ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.mtb);
+    __StackTop = ORIGIN(STACK_RAM) + LENGTH(STACK_RAM);
+    __StackLimit = ORIGIN(STACK_RAM);
     _estack = __StackTop;
-    __StackLimit = __StackTop - STACK_SIZE;
     PROVIDE(__stack = __StackTop);
-
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = __StackLimit;
-
-    /* Check if data + heap + stack exceeds RAM limit */
-    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
 }
 
diff --git a/boot/startup/mynewt_cortex_m3.ld b/boot/startup/mynewt_cortex_m3.ld
index ce4d8c0fa..b74fd10de 100644
--- a/boot/startup/mynewt_cortex_m3.ld
+++ b/boot/startup/mynewt_cortex_m3.ld
@@ -19,6 +19,7 @@
 
 #include <syscfg/syscfg.h>
 #include <sysflash/sysflash.h>
+#include <mcu_config.ld.h>
 #include <bsp_config.ld.h>
 #include <target_config.ld.h>
 #include <mynewt_config.ld.h>
@@ -36,7 +37,18 @@ MEMORY
 #ifdef FLASH_AREA_IMAGE_0_OFFSET
     SLOT0 (rx!w) : ORIGIN = FLASH_AREA_IMAGE_0_OFFSET, LENGTH = 
FLASH_AREA_IMAGE_0_SIZE
 #endif
+    /*
+     * If STACK_REGION is defined it means that MCU stack is place in other 
region then RAM
+     * int that case RAM region size is exactly RAM_SIZE
+     * If STACK_REGION is NOT defined STACK_RAM region is place at the end of 
RAM
+     * and RAM region size is shortened.
+     */
+#ifdef STACK_REGION
     RAM (rwx) : ORIGIN = RAM_START, LENGTH = RAM_SIZE
+#else
+    RAM (rwx) : ORIGIN = RAM_START, LENGTH = (RAM_SIZE - STACK_SIZE)
+    STACK_RAM (rw) : ORIGIN = RAM_START + RAM_SIZE - STACK_SIZE, LENGTH = 
STACK_SIZE
+#endif
 #include <memory_regions.ld.h>
 }
 
@@ -247,7 +259,7 @@ SECTIONS
     __data_image__ = LOADADDR(.data);
     _sidata = LOADADDR(.data);
 
-    .bssnz :
+    .bssnz (NOLOAD) :
     {
         . = ALIGN(4);
         __bssnz_start__ = .;
@@ -269,14 +281,8 @@ SECTIONS
         __ecorebss = .;
     } > COREBSS_RAM
 #endif
-    .bssnz (NOLOAD):
-    {
-        . = ALIGN(4);
-        *(.bss.core.nz)
-        . = ALIGN(4);
-    } > RAM
 
-    .bss :
+    .bss (NOLOAD) :
     {
         . = ALIGN(4);
         _sbss = .;
@@ -291,27 +297,19 @@ SECTIONS
     /* Heap starts after BSS */
     . = ALIGN(8);
     __HeapBase = .;
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
 
-    /* Dummy section to calculate whether we need to move stack out of MTB
-     * buffer or not. */
-    .mtb (NOLOAD) :
-    {
-        KEEP(*(.mtb));
-    }
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
 
     _ram_start = ORIGIN(RAM);
 
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
-    __StackTop = ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.mtb);
+    __StackTop = ORIGIN(STACK_RAM) + LENGTH(STACK_RAM);
+    __StackLimit = ORIGIN(STACK_RAM);
     _estack = __StackTop;
-    __StackLimit = __StackTop - STACK_SIZE;
     PROVIDE(__stack = __StackTop);
-
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = __StackLimit;
-
-    /* Check if data + heap + stack exceeds RAM limit */
-    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
 }
 
diff --git a/boot/startup/mynewt_cortex_m33.ld 
b/boot/startup/mynewt_cortex_m33.ld
index ce4d8c0fa..b74fd10de 100644
--- a/boot/startup/mynewt_cortex_m33.ld
+++ b/boot/startup/mynewt_cortex_m33.ld
@@ -19,6 +19,7 @@
 
 #include <syscfg/syscfg.h>
 #include <sysflash/sysflash.h>
+#include <mcu_config.ld.h>
 #include <bsp_config.ld.h>
 #include <target_config.ld.h>
 #include <mynewt_config.ld.h>
@@ -36,7 +37,18 @@ MEMORY
 #ifdef FLASH_AREA_IMAGE_0_OFFSET
     SLOT0 (rx!w) : ORIGIN = FLASH_AREA_IMAGE_0_OFFSET, LENGTH = 
FLASH_AREA_IMAGE_0_SIZE
 #endif
+    /*
+     * If STACK_REGION is defined it means that MCU stack is place in other 
region then RAM
+     * int that case RAM region size is exactly RAM_SIZE
+     * If STACK_REGION is NOT defined STACK_RAM region is place at the end of 
RAM
+     * and RAM region size is shortened.
+     */
+#ifdef STACK_REGION
     RAM (rwx) : ORIGIN = RAM_START, LENGTH = RAM_SIZE
+#else
+    RAM (rwx) : ORIGIN = RAM_START, LENGTH = (RAM_SIZE - STACK_SIZE)
+    STACK_RAM (rw) : ORIGIN = RAM_START + RAM_SIZE - STACK_SIZE, LENGTH = 
STACK_SIZE
+#endif
 #include <memory_regions.ld.h>
 }
 
@@ -247,7 +259,7 @@ SECTIONS
     __data_image__ = LOADADDR(.data);
     _sidata = LOADADDR(.data);
 
-    .bssnz :
+    .bssnz (NOLOAD) :
     {
         . = ALIGN(4);
         __bssnz_start__ = .;
@@ -269,14 +281,8 @@ SECTIONS
         __ecorebss = .;
     } > COREBSS_RAM
 #endif
-    .bssnz (NOLOAD):
-    {
-        . = ALIGN(4);
-        *(.bss.core.nz)
-        . = ALIGN(4);
-    } > RAM
 
-    .bss :
+    .bss (NOLOAD) :
     {
         . = ALIGN(4);
         _sbss = .;
@@ -291,27 +297,19 @@ SECTIONS
     /* Heap starts after BSS */
     . = ALIGN(8);
     __HeapBase = .;
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
 
-    /* Dummy section to calculate whether we need to move stack out of MTB
-     * buffer or not. */
-    .mtb (NOLOAD) :
-    {
-        KEEP(*(.mtb));
-    }
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
 
     _ram_start = ORIGIN(RAM);
 
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
-    __StackTop = ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.mtb);
+    __StackTop = ORIGIN(STACK_RAM) + LENGTH(STACK_RAM);
+    __StackLimit = ORIGIN(STACK_RAM);
     _estack = __StackTop;
-    __StackLimit = __StackTop - STACK_SIZE;
     PROVIDE(__stack = __StackTop);
-
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = __StackLimit;
-
-    /* Check if data + heap + stack exceeds RAM limit */
-    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
 }
 
diff --git a/boot/startup/mynewt_cortex_m7.ld b/boot/startup/mynewt_cortex_m7.ld
index 5bbe1f069..b74fd10de 100644
--- a/boot/startup/mynewt_cortex_m7.ld
+++ b/boot/startup/mynewt_cortex_m7.ld
@@ -37,7 +37,18 @@ MEMORY
 #ifdef FLASH_AREA_IMAGE_0_OFFSET
     SLOT0 (rx!w) : ORIGIN = FLASH_AREA_IMAGE_0_OFFSET, LENGTH = 
FLASH_AREA_IMAGE_0_SIZE
 #endif
+    /*
+     * If STACK_REGION is defined it means that MCU stack is place in other 
region then RAM
+     * int that case RAM region size is exactly RAM_SIZE
+     * If STACK_REGION is NOT defined STACK_RAM region is place at the end of 
RAM
+     * and RAM region size is shortened.
+     */
+#ifdef STACK_REGION
     RAM (rwx) : ORIGIN = RAM_START, LENGTH = RAM_SIZE
+#else
+    RAM (rwx) : ORIGIN = RAM_START, LENGTH = (RAM_SIZE - STACK_SIZE)
+    STACK_RAM (rw) : ORIGIN = RAM_START + RAM_SIZE - STACK_SIZE, LENGTH = 
STACK_SIZE
+#endif
 #include <memory_regions.ld.h>
 }
 
@@ -248,7 +259,7 @@ SECTIONS
     __data_image__ = LOADADDR(.data);
     _sidata = LOADADDR(.data);
 
-    .bssnz :
+    .bssnz (NOLOAD) :
     {
         . = ALIGN(4);
         __bssnz_start__ = .;
@@ -271,7 +282,7 @@ SECTIONS
     } > COREBSS_RAM
 #endif
 
-    .bss :
+    .bss (NOLOAD) :
     {
         . = ALIGN(4);
         _sbss = .;
@@ -286,27 +297,19 @@ SECTIONS
     /* Heap starts after BSS */
     . = ALIGN(8);
     __HeapBase = .;
+    /* Top of head is the bottom of the stack */
+    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
 
-    /* Dummy section to calculate whether we need to move stack out of MTB
-     * buffer or not. */
-    .mtb (NOLOAD) :
-    {
-        KEEP(*(.mtb));
-    }
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
 
     _ram_start = ORIGIN(RAM);
 
     /* Set stack top to end of RAM, and stack limit move down by
      * size of stack_dummy section */
-    __StackTop = ORIGIN(RAM) + LENGTH(RAM) - SIZEOF(.mtb);
+    __StackTop = ORIGIN(STACK_RAM) + LENGTH(STACK_RAM);
+    __StackLimit = ORIGIN(STACK_RAM);
     _estack = __StackTop;
-    __StackLimit = __StackTop - STACK_SIZE;
     PROVIDE(__stack = __StackTop);
-
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = __StackLimit;
-
-    /* Check if data + heap + stack exceeds RAM limit */
-    ASSERT(__HeapBase <= __HeapLimit, "region RAM overflowed with stack")
 }
 

Reply via email to