Skip to content

Commit

Permalink
[core] Refactor linkerscript templates
Browse files Browse the repository at this point in the history
- Adds a generic linkerscript for all basic Cortex-M devices.
- Adds .data_{ram} and .noinit_{ram} sections to all memories.
- Uses MAX() to forward the heap location counter so that a very
  large .data section will collapse the heap to zero and "spill" into
  the next RAM section without overflowing the subsection SRAM1.
- Generalizes RAM heap section placement via macro.
  • Loading branch information
salkinium committed Jul 15, 2021
1 parent f531161 commit 996e361
Show file tree
Hide file tree
Showing 18 changed files with 889 additions and 434 deletions.
4 changes: 2 additions & 2 deletions examples/black_pill_f411/usbfatfs/ramdisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// ----------------------------------------------------------------------------
static constexpr uint32_t sector_size{512};
static constexpr uint32_t sector_count{230};
// Allocate giant array inside a NOLOAD heap section
modm_section(".heap1") uint8_t ram_disk[sector_count * sector_size];
// Allocate giant array inside the SRAM1 noinit section
modm_section(".noinit_sram1") uint8_t ram_disk[sector_count * sector_size];

DSTATUS disk_initialize(BYTE pdrv) { return pdrv ? STA_NOINIT : 0; }
DSTATUS disk_status(BYTE pdrv) { return pdrv ? STA_NOINIT : 0; }
Expand Down
4 changes: 2 additions & 2 deletions examples/nucleo_g071rb/custom_allocator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

using namespace Board;

// Allocate giant array inside a NOLOAD heap section
// Allocate giant array inside the SRAM1 noinit section
// Play around with the array size and see effect it has on HeapTable!
modm_section(".heap1")
modm_section(".noinit_sram1")
uint8_t heap_begin[30*1024]; // 31kB overflows the linkerscript
const uint8_t *const heap_end{heap_begin + sizeof(heap_begin)};
const uint8_t *heap_top{heap_begin};
Expand Down
55 changes: 38 additions & 17 deletions src/modm/board/disco_f469ni/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def build(env):

env.collect(":platform:cortex-m:linkerscript.memory", linkerscript_memory)
env.collect(":platform:cortex-m:linkerscript.sections", linkerscript_sections)
env.collect(":platform:cortex-m:linkerscript.table_extern.zero", linkerscript_extern_zero)
env.collect(":platform:cortex-m:linkerscript.table_extern.copy", linkerscript_extern_copy)
env.collect(":platform:cortex-m:linkerscript.table_extern.heap", linkerscript_extern_heap)

Expand All @@ -57,36 +58,56 @@ SDRAM (rwx) : ORIGIN = 0xC0000000, LENGTH = 16M
"""

linkerscript_sections = """\
.sdramdata :
{
__sdramdata_load = LOADADDR (.sdramdata); /* address in FLASH */
__sdramdata_start = .; /* address in RAM */
*(.sdramdata)
__sdram_start = ORIGIN(SDRAM);
__sdram_end = ORIGIN(SDRAM) + LENGTH(SDRAM);
.data_sdram :
{
__data_sdram_load = LOADADDR(.data_sdram);
__data_sdram_start = .;
*(.data_sdram .data_sdram.*)
. = ALIGN(4);
__sdramdata_end = .;
__data_sdram_end = .;
} >SDRAM AT >FLASH
.heap_extern (NOLOAD) : ALIGN(4)
.bss_sdram (NOLOAD) :
{
*(.heap_extern)
__bss_sdram_start = .;
*(.bss_sdram .bss_sdram.*)
. = ALIGN(4);
__bss_sdram_end = .;
} >SDRAM
__heap_extern_start = .;
.noinit_sdram (NOLOAD) :
{
__noinit_sdram_start = .;
*(.noinit_sdram .noinit_sdram.*)
. = ALIGN(4);
__noinit_sdram_end = .;
} >SDRAM
.heap_sdram (NOLOAD) :
{
__heap_sdram_start = .;
*(.heap_sdram .heap_sdram.*)
. = ORIGIN(SDRAM) + LENGTH(SDRAM);
__heap_extern_end = .;
__heap_sdram_end = .;
} >SDRAM
"""

linkerscript_extern_zero = """\
LONG(__bss_sdram_start)
LONG(__bss_sdram_end)
"""

linkerscript_extern_copy = """\
LONG (__sdramdata_load)
LONG (__sdramdata_start)
LONG (__sdramdata_end)
LONG(__data_sdram_load)
LONG(__data_sdram_start)
LONG(__data_sdram_end)
"""

linkerscript_extern_heap = """\
LONG (0x801f)
LONG (__heap_extern_start)
LONG (__heap_extern_end)
LONG(0x801f)
LONG(__heap_sdram_start)
LONG(__heap_sdram_end)
"""
Loading

0 comments on commit 996e361

Please sign in to comment.