summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-08-27 16:43:19 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-08-27 16:43:19 -0600
commit6b35d7af6caf96b641336200afd52704b419f346 (patch)
treea9b15a5298799f3e0f38bee43c56e85844f6d18f
parent36a28654f1bb665c631e888b3917963d4d4388ca (diff)
downloadpx4-nuttx-6b35d7af6caf96b641336200afd52704b419f346.tar.gz
px4-nuttx-6b35d7af6caf96b641336200afd52704b419f346.tar.bz2
px4-nuttx-6b35d7af6caf96b641336200afd52704b419f346.zip
SAMA5: Fixes a bug in the way that the heap regions were being allocated
-rw-r--r--nuttx/ChangeLog4
-rw-r--r--nuttx/arch/arm/src/sama5/sam_allocateheap.c55
-rw-r--r--nuttx/tools/mkconfig.c3
3 files changed, 51 insertions, 11 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index b991259e8..ca8f89c9f 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -5469,4 +5469,8 @@
* arch/arm: Add hooks for Cortex-A8. Not much more yet (2013-8-27).
* Lots of files: Fix all occurrents of "the the" in documentation and
comments (2013-8-27).
+ * arch/arm/src/sama5/sam_allocateheap.c: Correct the logic that
+ determines which memory regions get added to the heap. When
+ CONFIG_MM_NREGIONS > 1, the logic was adding the ISRAM region to
+ the heap twice! (2013-6-27).
diff --git a/nuttx/arch/arm/src/sama5/sam_allocateheap.c b/nuttx/arch/arm/src/sama5/sam_allocateheap.c
index a87aa50ab..fda2b7951 100644
--- a/nuttx/arch/arm/src/sama5/sam_allocateheap.c
+++ b/nuttx/arch/arm/src/sama5/sam_allocateheap.c
@@ -59,19 +59,23 @@
* Private Definitions
****************************************************************************/
/* The Primary Heap *********************************************************/
-/* The primary heap is defined by CONFIG_RAM_START, CONFIG_RAM_SIZE, and
- * CONFIG_RAM_END where:
+/* The physical address of the primary heap is defined by CONFIG_RAM_START,
+ * CONFIG_RAM_SIZE, and CONFIG_RAM_END where:
*
* CONFIG_RAM_END = CONFIG_RAM_START + CONFIG_RAM_SIZE
*
- * CONFIG_RAM_START is the usable beginning of the RAM region. The "usable"
+ * and the corresponding virtual address are give by:
+ *
+ * CONFIG_RAM_VEND = CONFIG_RAM_VSTART + CONFIG_RAM_SIZE
+ *
+ * CONFIG_RAM_VSTART is the usable beginning of the RAM region. The "usable"
* start would exclude, for example, any memory at the bottom of the RAM
* region used for the 16KB page table. If we are also executing from this
* same RAM region then CONFIG_RAM_START is not used. Instead, the value of
* g_idle_stack is the used; this variable holds the first avaiable byte of
* memory after the .text, .data, .bss, and IDLE stack allocations.
*
- * CONFIG_RAM_END is defined in the configuration it is the usable top of
+ * CONFIG_RAM_VEND is defined in the configuration it is the usable top of
* the RAM region beginning at CONFIG_RAM_START. The "usable" top would
* exclude, for example, any memory reserved at the top of the for the 16KB
* page table.
@@ -83,7 +87,7 @@
*
* We cannot add the region if it is if we are executing from it! In that
* case, the remainder of the memory will automatically be added to the heap
- * based on g_idle_topstack and CONFIG_RAM_END.
+ * based on g_idle_topstack and CONFIG_RAM_VEND.
*/
#if defined(CONFIG_SAMA5_BOOT_ISRAM)
@@ -118,6 +122,35 @@
# undef SAMA5_EBICS3_HEAP
#endif
+/* The heap space in the primary memory region is added automatically when
+ * up_allocate heap is called. So if the memory region is the primary region,
+ * it should not be added to the heap (again).
+ */
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_ISRAM0_VADDR
+# undef CONFIG_SAMA5_ISRAM_HEAP
+#endif
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_DDRCS_VSECTION
+# undef CONFIG_SAMA5_DDRCS_HEAP
+#endif
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_EBICS0_VSECTION
+# undef SAMA5_EBICS0_HEAP
+#endif
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_EBICS1_VSECTION
+# undef SAMA5_EBICS1_HEAP
+#endif
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_EBICS2_VSECTION
+# undef SAMA5_EBICS2_HEAP
+#endif
+
+#if (CONFIG_RAM_VSTART & 0xfff00000) == SAM_EBICS3_VSECTION
+# undef SAMA5_EBICS3_HEAP
+#endif
+
/****************************************************************************
* Private Data
****************************************************************************/
@@ -173,10 +206,10 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
*/
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + CONFIG_MM_KERNEL_HEAPSIZE;
- size_t usize = CONFIG_RAM_END - ubase;
+ size_t usize = CONFIG_RAM_VEND - ubase;
int log2;
- DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_END);
+ DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_VEND);
/* Return the user-space heap settings */
@@ -189,7 +222,7 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
up_ledon(LED_HEAPALLOCATE);
*heap_start = (FAR void*)g_idle_topstack;
- *heap_size = CONFIG_RAM_END - g_idle_topstack;
+ *heap_size = CONFIG_RAM_VEND - g_idle_topstack;
#endif
}
@@ -213,10 +246,10 @@ void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
*/
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend + CONFIG_MM_KERNEL_HEAPSIZE;
- size_t usize = CONFIG_RAM_END - ubase;
+ size_t usize = CONFIG_RAM_VEND - ubase;
int log2;
- DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_END);
+ DEBUGASSERT(ubase < (uintptr_t)CONFIG_RAM_VEND);
/* Return the kernel heap settings (i.e., the part of the heap region
* that was not dedicated to the user heap).
@@ -239,7 +272,7 @@ void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
#if CONFIG_MM_REGIONS > 1
void up_addregion(void)
{
- int nregions = CONFIG_MM_REGIONS;
+ int nregions = CONFIG_MM_REGIONS - 1;
size_t size;
#ifdef CONFIG_SAMA5_ISRAM_HEAP
diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c
index c90f62735..92fb04a68 100644
--- a/nuttx/tools/mkconfig.c
+++ b/nuttx/tools/mkconfig.c
@@ -184,6 +184,9 @@ int main(int argc, char **argv, char **envp)
printf("#ifndef CONFIG_RAM_END\n");
printf("# define CONFIG_RAM_END (CONFIG_RAM_START+CONFIG_RAM_SIZE)\n");
printf("#endif\n\n");
+ printf("#ifndef CONFIG_RAM_VEND\n");
+ printf("# define CONFIG_RAM_VEND (CONFIG_RAM_VSTART+CONFIG_RAM_SIZE)\n");
+ printf("#endif\n\n");
printf("/* If the end of FLASH is not specified then it is assumed to be the beginning\n");
printf(" * of FLASH plus the FLASH size.\n");
printf(" */\n\n");