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

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

commit 0a277edd3aefbd48b9cf51a9a110a9f3675943d0
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Mon Jul 6 15:39:08 2026 +0200

    boot: add dedicated heap section
    
    Added a dedicated .heap section to prevent memory overlap issues.
    Previously, adding a variable to the application's .noinit section
    shifted the heap's start address, causing memory addresses to drift
    and allowing the bootloader and application to overwrite each other.
    Furthermore, the heap inherited its location directly from .noinit,
    meaning that if .noinit was mapped to a specific memory region like
    DTCM, the heap was unintentionally placed there as well.
---
 boot/startup/mynewt_cortex_m0.ld  | 12 +++++++-----
 boot/startup/mynewt_cortex_m3.ld  | 12 +++++++-----
 boot/startup/mynewt_cortex_m33.ld | 12 +++++++-----
 boot/startup/mynewt_cortex_m4.ld  | 12 +++++++-----
 boot/startup/mynewt_cortex_m7.ld  | 12 +++++++-----
 5 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/boot/startup/mynewt_cortex_m0.ld b/boot/startup/mynewt_cortex_m0.ld
index 130d31ce1..f0244032c 100644
--- a/boot/startup/mynewt_cortex_m0.ld
+++ b/boot/startup/mynewt_cortex_m0.ld
@@ -296,11 +296,13 @@ SECTIONS
         __noinit_end__ = .;
     } > NOINIT_RAM
 
-    /* Heap starts after BSS */
-    . = ALIGN(8);
-    __HeapBase = .;
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    .heap :
+    {
+        . = ALIGN(8);
+        __HeapBase = .;
+         /* Top of head is the bottom of the stack */
+        __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    } > RAM
 
     /* Check if data + heap + stack exceeds RAM limit */
     ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
diff --git a/boot/startup/mynewt_cortex_m3.ld b/boot/startup/mynewt_cortex_m3.ld
index 0d1cf319f..07e775250 100644
--- a/boot/startup/mynewt_cortex_m3.ld
+++ b/boot/startup/mynewt_cortex_m3.ld
@@ -296,11 +296,13 @@ SECTIONS
         __noinit_end__ = .;
     } > NOINIT_RAM
 
-    /* Heap starts after BSS */
-    . = ALIGN(8);
-    __HeapBase = .;
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    .heap :
+    {
+        . = ALIGN(8);
+        __HeapBase = .;
+         /* Top of head is the bottom of the stack */
+        __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    } > RAM
 
     /* Check if data + heap + stack exceeds RAM limit */
     ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
diff --git a/boot/startup/mynewt_cortex_m33.ld 
b/boot/startup/mynewt_cortex_m33.ld
index 0d1cf319f..07e775250 100644
--- a/boot/startup/mynewt_cortex_m33.ld
+++ b/boot/startup/mynewt_cortex_m33.ld
@@ -296,11 +296,13 @@ SECTIONS
         __noinit_end__ = .;
     } > NOINIT_RAM
 
-    /* Heap starts after BSS */
-    . = ALIGN(8);
-    __HeapBase = .;
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    .heap :
+    {
+        . = ALIGN(8);
+        __HeapBase = .;
+         /* Top of head is the bottom of the stack */
+        __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    } > RAM
 
     /* Check if data + heap + stack exceeds RAM limit */
     ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
diff --git a/boot/startup/mynewt_cortex_m4.ld b/boot/startup/mynewt_cortex_m4.ld
index 0d1cf319f..07e775250 100644
--- a/boot/startup/mynewt_cortex_m4.ld
+++ b/boot/startup/mynewt_cortex_m4.ld
@@ -296,11 +296,13 @@ SECTIONS
         __noinit_end__ = .;
     } > NOINIT_RAM
 
-    /* Heap starts after BSS */
-    . = ALIGN(8);
-    __HeapBase = .;
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    .heap :
+    {
+        . = ALIGN(8);
+        __HeapBase = .;
+         /* Top of head is the bottom of the stack */
+        __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    } > RAM
 
     /* Check if data + heap + stack exceeds RAM limit */
     ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")
diff --git a/boot/startup/mynewt_cortex_m7.ld b/boot/startup/mynewt_cortex_m7.ld
index 0d1cf319f..07e775250 100644
--- a/boot/startup/mynewt_cortex_m7.ld
+++ b/boot/startup/mynewt_cortex_m7.ld
@@ -296,11 +296,13 @@ SECTIONS
         __noinit_end__ = .;
     } > NOINIT_RAM
 
-    /* Heap starts after BSS */
-    . = ALIGN(8);
-    __HeapBase = .;
-    /* Top of head is the bottom of the stack */
-    __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    .heap :
+    {
+        . = ALIGN(8);
+        __HeapBase = .;
+         /* Top of head is the bottom of the stack */
+        __HeapLimit = ORIGIN(RAM) + LENGTH(RAM);
+    } > RAM
 
     /* Check if data + heap + stack exceeds RAM limit */
     ASSERT(__HeapBase <= __HeapLimit, "No space for MCU heap")

Reply via email to