From dee5ea245e73bd72f8099016ff1102a083ba26cb Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Wed, 27 Feb 2019 23:01:41 +0100 Subject: [PATCH] [core] Use Collectors for linkerscript additions --- src/modm/board/disco_f469ni/board.xml | 33 ------- src/modm/board/disco_f469ni/module.lb | 45 ++++++++- src/modm/platform/core/cortex/linker.macros | 13 ++- src/modm/platform/core/cortex/module.lb | 91 +++++++++++++------ .../core/stm32/linkerscript/stm32_dccm.ld.in | 5 +- .../core/stm32/linkerscript/stm32_iccm.ld.in | 5 +- .../core/stm32/linkerscript/stm32_idtcm.ld.in | 5 +- .../core/stm32/linkerscript/stm32_ram.ld.in | 5 +- src/modm/platform/core/stm32/module.lb | 5 +- src/modm/platform/fault/cortex/module.lb | 1 + 10 files changed, 124 insertions(+), 84 deletions(-) diff --git a/src/modm/board/disco_f469ni/board.xml b/src/modm/board/disco_f469ni/board.xml index cbe56ba401..e9b50d1f62 100644 --- a/src/modm/board/disco_f469ni/board.xml +++ b/src/modm/board/disco_f469ni/board.xml @@ -10,39 +10,6 @@ - - - - - modm:board:disco-f469ni diff --git a/src/modm/board/disco_f469ni/module.lb b/src/modm/board/disco_f469ni/module.lb index 77102a1436..a8f8602988 100644 --- a/src/modm/board/disco_f469ni/module.lb +++ b/src/modm/board/disco_f469ni/module.lb @@ -39,4 +39,47 @@ def build(env): env.substitutions = {"board_has_logger": True} env.template("../board.cpp.in", "board.cpp") env.copy('.') - env.collect(":build:openocd.source", "board/stm32f469discovery.cfg"); + env.collect(":build:openocd.source", "board/stm32f469discovery.cfg") + + 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.copy", linkerscript_extern_copy) + env.collect(":platform:cortex-m:linkerscript.table_extern.heap", linkerscript_extern_heap) + + +# ============================================================================= +linkerscript_memory = """\ +SDRAM (rwx) : ORIGIN = 0xC0000000, LENGTH = 16M +""" + +linkerscript_sections = """\ +.sdramdata : +{ + __sdramdata_load = LOADADDR (.sdramdata); /* address in FLASH */ + __sdramdata_start = .; /* address in RAM */ + + KEEP(*(.sdramdata)) + + . = ALIGN(4); + __sdramdata_end = .; +} >SDRAM AT >FLASH + +.heap_extern (NOLOAD) : ALIGN(4) +{ + __heap_extern_start = .; + . = ORIGIN(SDRAM) + LENGTH(SDRAM); + __heap_extern_end = .; +} >SDRAM +""" + +linkerscript_extern_copy = """\ +LONG (__sdramdata_load) +LONG (__sdramdata_start) +LONG (__sdramdata_end) +""" + +linkerscript_extern_heap = """\ +LONG (0x801f) +LONG (__heap_extern_start) +LONG (__heap_extern_end) +""" \ No newline at end of file diff --git a/src/modm/platform/core/cortex/linker.macros b/src/modm/platform/core/cortex/linker.macros index 4ecf853339..c3385230c2 100644 --- a/src/modm/platform/core/cortex/linker.macros +++ b/src/modm/platform/core/cortex/linker.macros @@ -21,7 +21,7 @@ MEMORY {{ memory.name | upper }} ({{ memory.access }}) : ORIGIN = {{ memory.start }}, LENGTH = {{ memory.size }} %% endfor RAM (rwx) : ORIGIN = 0x{{ "%08x" % ram_origin }}, LENGTH = {{ ram_size }} -{{ options[":platform:cortex-m:linkerscript.memory"] }} +{{ linkerscript_memory | indent(first=True) }} } OUTPUT_FORMAT("elf32-littlearm") @@ -108,6 +108,9 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE; %% macro section_table_copy(sections) + %% if vector_table_location == "ram" + %% do sections.append("vector_table_ram") + %% endif .table.copy.intern : ALIGN(4) { __table_copy_intern_start = .; @@ -125,14 +128,14 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE; .table.zero.extern : ALIGN(4) { __table_zero_extern_start = .; -{{ options[":platform:cortex-m:linkerscript.table_extern.zero"] }} +{{ linkerscript_extern_zero | indent(8, first=True) }} __table_zero_extern_end = .; } >FLASH .table.copy.extern : ALIGN(4) { __table_copy_extern_start = .; -{{ options[":platform:cortex-m:linkerscript.table_extern.copy"] }} +{{ linkerscript_extern_copy | indent(8, first=True) }} __table_copy_extern_end = .; } >FLASH %% endmacro @@ -153,7 +156,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE; * - 0x4000: non-volatile (or battery backed) memory * - 0x8000: external memory */ - .table.section_heap : ALIGN(4) + .table.heap : ALIGN(4) { __table_heap_start = .; %% for section in sections @@ -161,7 +164,7 @@ TOTAL_STACK_SIZE = MAIN_STACK_SIZE + PROCESS_STACK_SIZE; LONG(__{{ section.name }}_start) LONG(__{{ section.name }}_end) %% endfor -{{ options[":platform:cortex-m:linkerscript.table_extern.heap"] }} +{{ linkerscript_extern_heap | indent(8, first=True) }} __table_heap_end = .; } >FLASH %% endmacro diff --git a/src/modm/platform/core/cortex/module.lb b/src/modm/platform/core/cortex/module.lb index 06b5687784..4811b73f5d 100644 --- a/src/modm/platform/core/cortex/module.lb +++ b/src/modm/platform/core/cortex/module.lb @@ -68,26 +68,62 @@ def common_memories(env): - regions: memory region names - ram_origin: Lowest SRAM origin address - ram_origin: Total size of all SRAM regions - - process_stack_size: requested process stack - - vector_table_location: ram or rom :returns: dictionary of memory properties """ device = env[":target"] memories = listify(device.get_driver("core")["memory"]) - process_stack_size = 0 - if env.get(":platform:fault.cortex:led", "disabled") == "disabled": - process_stack_size = 32 properties = { "memories": memories, "regions": [m["name"] for m in memories], "ram_origin": min(int(m["start"], 16) for m in memories if "sram" in m["name"]), "ram_size": sum(int(m["size"]) for m in memories if "sram" in m["name"]), - "process_stack_size": process_stack_size, - "vector_table_location": common_vector_table_location(env), } return properties + +def common_linkerscript(env): + """ + Computes linkerscript properties *post-build*: + - process_stack_size: largest requested process stack size by any module + - vector_table_location: ram or rom + + Stripped and newline-joined collector values of: + - linkerscript_memory + - linkerscript_sections + - linkerscript_extern_zero + - linkerscript_extern_copy + - linkerscript_extern_heap + + Additional memory properties: + - memories: unfiltered memory regions + - regions: memory region names + - ram_origin: Lowest SRAM origin address + - ram_origin: Total size of all SRAM regions + + :returns: dictionary of linkerscript properties + """ + properties = { + "process_stack_size": + max(env.collector_values(":platform:cortex-m:linkerscript.process_stack_size", 0)), + "vector_table_location": + common_vector_table_location(env), + + "linkerscript_memory": "\n".join([m.strip() for m in + env.collector_values(":platform:cortex-m:linkerscript.memory")]), + "linkerscript_sections": "\n".join([m.strip() for m in + env.collector_values(":platform:cortex-m:linkerscript.sections")]), + "linkerscript_extern_zero": "\n".join([m.strip() for m in + env.collector_values(":platform:cortex-m:linkerscript.table_extern.zero")]), + "linkerscript_extern_copy": "\n".join([m.strip() for m in + env.collector_values(":platform:cortex-m:linkerscript.table_extern.copy")]), + "linkerscript_extern_heap": "\n".join([m.strip() for m in + env.collector_values(":platform:cortex-m:linkerscript.table_extern.heap")]), + } + properties.update(common_memories(env)) + return properties + + def init(module): module.name = "cortex-m" module.parent = "platform" @@ -143,36 +179,35 @@ def prepare(module, options): enumeration=["rom", "ram"], default=default_location)) - module.add_option( - StringOption( + module.add_collector( + StringCollector( name="linkerscript.memory", - description="", - default="")) - module.add_option( - StringOption( + description="Additions to the linkerscript's 'MEMORY'")) + module.add_collector( + StringCollector( name="linkerscript.sections", - description="", - default="")) - module.add_option( - StringOption( + description="Additions to the linkerscript's 'SECTIONS'")) + module.add_collector( + StringCollector( name="linkerscript.table_extern.zero", - description="", - default="")) - module.add_option( - StringOption( + description="Additions to the linkerscript's '.table.zero.extern' section")) + module.add_collector( + StringCollector( name="linkerscript.table_extern.copy", - description="", - default="")) - module.add_option( - StringOption( + description="Additions to the linkerscript's '.table.copy.extern' section")) + module.add_collector( + StringCollector( name="linkerscript.table_extern.heap", - description="", - default="")) + description="Additions to the linkerscript's '.table.heap' section")) + module.add_collector( + NumericCollector( + name="linkerscript.process_stack_size", + description="Maximum required size of the process stack")) module.add_query( EnvironmentQuery(name="vector_table", factory=common_vector_table)) module.add_query( - EnvironmentQuery(name="memories", factory=common_memories)) + EnvironmentQuery(name="linkerscript", factory=common_linkerscript)) return True diff --git a/src/modm/platform/core/stm32/linkerscript/stm32_dccm.ld.in b/src/modm/platform/core/stm32/linkerscript/stm32_dccm.ld.in index 7e8b297be4..97ee8765ee 100644 --- a/src/modm/platform/core/stm32/linkerscript/stm32_dccm.ld.in +++ b/src/modm/platform/core/stm32/linkerscript/stm32_dccm.ld.in @@ -38,7 +38,7 @@ SECTIONS {{ linker.section_heap("SRAM3", "heap3") }} %% endif -{{ options[":platform:cortex-m:linkerscript.sections"] }} +{{ linkerscript_sections | indent(first=True) }} /* TABLES! TABLES! ALL THE TABLES YOU COULD EVER WANT! TABLES! */ {{ linker.section_table_zero(["bss"]) }} @@ -47,9 +47,6 @@ SECTIONS %% if "backup" in regions %% do copy_table.append("backup") %% endif -%% if vector_table_location == "ram" - %% do copy_table.append("vector_table_ram") -%% endif {{ linker.section_table_copy(copy_table) }} {{ linker.section_table_extern() }} diff --git a/src/modm/platform/core/stm32/linkerscript/stm32_iccm.ld.in b/src/modm/platform/core/stm32/linkerscript/stm32_iccm.ld.in index 30b39126ea..8c14f9293c 100644 --- a/src/modm/platform/core/stm32/linkerscript/stm32_iccm.ld.in +++ b/src/modm/platform/core/stm32/linkerscript/stm32_iccm.ld.in @@ -24,15 +24,12 @@ SECTIONS {{ linker.section_heap("RAM", "heap1") }} -{{ options[":platform:cortex-m:linkerscript.sections"] }} +{{ linkerscript_sections | indent(first=True) }} /* TABLES! TABLES! ALL THE TABLES YOU COULD EVER WANT! TABLES! */ {{ linker.section_table_zero(["bss"]) }} %% set copy_table = ["data", "fastdata", "fastcode"] -%% if vector_table_location == "ram" - %% do copy_table.append("vector_table_ram") -%% endif {{ linker.section_table_copy(copy_table) }} {{ linker.section_table_extern() }} diff --git a/src/modm/platform/core/stm32/linkerscript/stm32_idtcm.ld.in b/src/modm/platform/core/stm32/linkerscript/stm32_idtcm.ld.in index 7d1efa7860..ed976207a4 100644 --- a/src/modm/platform/core/stm32/linkerscript/stm32_idtcm.ld.in +++ b/src/modm/platform/core/stm32/linkerscript/stm32_idtcm.ld.in @@ -34,15 +34,12 @@ SECTIONS {{ linker.section_heap("SRAM2", "heap2") }} -{{ options[":platform:cortex-m:linkerscript.sections"] }} +{{ linkerscript_sections | indent(first=True) }} /* TABLES! TABLES! ALL THE TABLES YOU COULD EVER WANT! TABLES! */ {{ linker.section_table_zero(["bss"]) }} %% set copy_table = ["data", "fastdata", "fastcode"] -%% if vector_table_location == "ram" - %% do copy_table.append("vector_table_ram") -%% endif {{ linker.section_table_copy(copy_table) }} {{ linker.section_table_extern() }} diff --git a/src/modm/platform/core/stm32/linkerscript/stm32_ram.ld.in b/src/modm/platform/core/stm32/linkerscript/stm32_ram.ld.in index 3ec9cd9fa9..a87afa8de9 100644 --- a/src/modm/platform/core/stm32/linkerscript/stm32_ram.ld.in +++ b/src/modm/platform/core/stm32/linkerscript/stm32_ram.ld.in @@ -32,15 +32,12 @@ SECTIONS {{ linker.section_heap("SRAM2", "heap2") }} %% endif -{{ options[":platform:cortex-m:linkerscript.sections"] }} +{{ linkerscript_sections | indent(first=True) }} /* TABLES! TABLES! ALL THE TABLES YOU COULD EVER WANT! TABLES! */ {{ linker.section_table_zero(["bss"]) }} %% set copy_table = ["data"] -%% if vector_table_location == "ram" - %% do copy_table.append("vector_table_ram") -%% endif {{ linker.section_table_copy(copy_table) }} {{ linker.section_table_extern() }} diff --git a/src/modm/platform/core/stm32/module.lb b/src/modm/platform/core/stm32/module.lb index 1691e647cd..8cdbf314d1 100644 --- a/src/modm/platform/core/stm32/module.lb +++ b/src/modm/platform/core/stm32/module.lb @@ -26,13 +26,16 @@ def prepare(module, options): module.depends(":platform:cortex-m") return True + def build(env): env.substitutions = {"target": env[":target"].identifier} env.outbasepath = "modm/src/modm/platform/core" # startup helper code env.template("startup_platform.c.in") - properties = env.query("::cortex-m:memories") + +def post_build(env): + properties = env.query("::cortex-m:linkerscript") target = env[":target"].identifier if target.family in ["l4"]: # FIXME! diff --git a/src/modm/platform/fault/cortex/module.lb b/src/modm/platform/fault/cortex/module.lb index 0172622d25..20358f7d3b 100644 --- a/src/modm/platform/fault/cortex/module.lb +++ b/src/modm/platform/fault/cortex/module.lb @@ -59,3 +59,4 @@ def build(env): env.template("hard_fault.sx.in") if env["led"] != "disabled": env.template("hard_fault_handler.cpp.in") + env.collect(":::linkerscript.process_stack_size", 32)