From 9a9488ae92bcfa5883b90b0ff6ae03058aff33ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Oct 2016 14:20:03 -0600 Subject: [PATCH] ESP32: Fix heap initialization --- arch/xtensa/src/common/xtensa.h | 12 ++++-------- arch/xtensa/src/esp32/esp32_allocateheap.c | 6 ++++-- arch/xtensa/src/esp32/esp32_start.c | 10 ---------- configs/esp32-core/scripts/esp32.template | 2 +- configs/esp32-core/scripts/esp32_common.ld | 15 +++++++++------ 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h index 3065911cf0..31a49e16e2 100644 --- a/arch/xtensa/src/common/xtensa.h +++ b/arch/xtensa/src/common/xtensa.h @@ -183,18 +183,14 @@ extern void g_intstackbase; extern uint32_t _init_start; /* Start of initialization logic */ extern uint32_t _stext; /* Start of .text */ extern uint32_t _etext; /* End+1 of .text + .rodata */ -extern const uint32_t _data_loaddr; /* Start of .data in FLASH */ extern uint32_t _sdata; /* Start of .data */ extern uint32_t _edata; /* End+1 of .data */ +extern uint32_t _srodata; /* Start of .rodata */ +extern uint32_t _erodata; /* End+1 of .rodata */ extern uint32_t _sbss; /* Start of .bss */ extern uint32_t _ebss; /* End+1 of .bss */ -#ifdef CONFIG_ARCH_RAMFUNCS -extern uint32_t _sramfunc; /* Start of ramfuncs */ -extern uint32_t _eramfunc; /* End+1 of ramfuncs */ -extern uint32_t _ramfunc_loadaddr; /* Start of ramfuncs in FLASH */ -extern uint32_t _ramfunc_sizeof; /* Size of ramfuncs */ -#endif /* CONFIG_ARCH_RAMFUNCS */ -#endif /* __ASSEMBLY__ */ +extern uint32_t _sheap; /* Start of heap */ +extern uint32_t _eheap; /* End+1 of heap */ /**************************************************************************** * Inline Functions diff --git a/arch/xtensa/src/esp32/esp32_allocateheap.c b/arch/xtensa/src/esp32/esp32_allocateheap.c index 4e613adc6d..c0b3b82218 100644 --- a/arch/xtensa/src/esp32/esp32_allocateheap.c +++ b/arch/xtensa/src/esp32/esp32_allocateheap.c @@ -67,11 +67,13 @@ * ****************************************************************************/ +#warning REVISIT heap. Do what with non-heterogeneous memory? + void up_allocate_heap(FAR void **heap_start, size_t *heap_size) { board_autoled_on(LED_HEAPALLOCATE); - *heap_start = (FAR void *)g_idle_topstack; - *heap_size = CONFIG_RAM_END - g_idle_topstack; + *heap_start = (FAR void *)&_sheap; + *heap_size = (size_t)((uintptr_t)&_eheap - (uintptr_t)&_sheap); } /**************************************************************************** diff --git a/arch/xtensa/src/esp32/esp32_start.c b/arch/xtensa/src/esp32/esp32_start.c index 3d1ca5c9b9..c52924a94e 100644 --- a/arch/xtensa/src/esp32/esp32_start.c +++ b/arch/xtensa/src/esp32/esp32_start.c @@ -85,16 +85,6 @@ void IRAM_ATTR __start(void) memset(&_sbss, 0, (&_ebss - &_sbss) * sizeof(_sbss)); -#warning Missing logic: Initialize .data - -#warning REVISIT heap. Do what with non-heterogeneous memory? -#warning REVISIT belongs in up_allocateheap() -#if 0 - /* Initialize heap allocator */ - - heap_alloc_caps_init(); -#endif - /* Make sure that the APP_CPU is disabled for now */ regval = getreg32(DPORT_APPCPU_CTRL_B_REG); diff --git a/configs/esp32-core/scripts/esp32.template b/configs/esp32-core/scripts/esp32.template index 9fbe0f1ccc..871171ddde 100644 --- a/configs/esp32-core/scripts/esp32.template +++ b/configs/esp32-core/scripts/esp32.template @@ -59,4 +59,4 @@ MEMORY /* Heap ends at top of dram0_0_seg */ -_heap_end = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM; +_eheap = 0x40000000 - CONFIG_ESP32_TRACEMEM_RESERVE_DRAM; diff --git a/configs/esp32-core/scripts/esp32_common.ld b/configs/esp32-core/scripts/esp32_common.ld index da7b74d510..213f53f499 100644 --- a/configs/esp32-core/scripts/esp32_common.ld +++ b/configs/esp32-core/scripts/esp32_common.ld @@ -56,7 +56,6 @@ SECTIONS _iram_text_start = ABSOLUTE(.); *(.iram1 .iram1.*) - *libfreertos.a:(.literal .text .literal.* .text.*) *libphy.a:(.literal .text .literal.* .text.*) *librtc.a:(.literal .text .literal.* .text.*) *libpp.a:(.literal .text .literal.* .text.*) @@ -90,7 +89,7 @@ SECTIONS .dram0.data : { - _data_start = ABSOLUTE(.); + _sdata = ABSOLUTE(.); KEEP(*(.data)) KEEP(*(.data.*)) KEEP(*(.gnu.linkonce.d.*)) @@ -103,14 +102,14 @@ SECTIONS KEEP(*(.gnu.linkonce.s2.*)) KEEP(*(.jcr)) *(.dram1 .dram1.*) - _data_end = ABSOLUTE(.); + _edata = ABSOLUTE(.); . = ALIGN(4); - _heap_start = ABSOLUTE(.); + _sheap = ABSOLUTE(.); } >dram0_0_seg .flash.rodata : { - _rodata_start = ABSOLUTE(.); + _srodata = ABSOLUTE(.); *(.rodata) *(.rodata.*) *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */ @@ -122,7 +121,9 @@ SECTIONS *(.gnu.linkonce.e.*) *(.gnu.version_r) *(.eh_frame) + . = (. + 3) & ~ 3; + /* C++ constructor and destructor tables, properly ordered: */ __init_array_start = ABSOLUTE(.); KEEP (*crtbegin.o(.ctors)) @@ -134,7 +135,9 @@ SECTIONS KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS_ = ABSOLUTE(.); *(.xt_except_desc) *(.gnu.linkonce.h.*) @@ -142,7 +145,7 @@ SECTIONS *(.xt_except_desc_end) *(.dynamic) *(.gnu.version_d) - _rodata_end = ABSOLUTE(.); + _erodata = ABSOLUTE(.); /* Literals are also RO data. */ _lit4_start = ABSOLUTE(.); *(*.lit4)