Skip to content

Commit

Permalink
[core] Use Collectors for linkerscript additions
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Feb 28, 2019
1 parent fb8ad54 commit dee5ea2
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 84 deletions.
33 changes: 0 additions & 33 deletions src/modm/board/disco_f469ni/board.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,6 @@
<option name="modm:platform:uart:3:buffer.tx">2048</option>
<option name="modm:platform:cortex-m:allocator">tlsf</option>
<option name="modm:tlsf:minimum_pool_size">16777216</option>

<option name="modm:platform:cortex-m:linkerscript.memory">
SDRAM (rwx) : ORIGIN = 0xC0000000, LENGTH = 16M
</option>
<option name="modm:platform:cortex-m: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
</option>
<option name="modm:platform:cortex-m:linkerscript.table_extern.copy">
LONG (__sdramdata_load)
LONG (__sdramdata_start)
LONG (__sdramdata_end)
</option>
<option name="modm:platform:cortex-m:linkerscript.table_extern.heap">
LONG (0x801f)
LONG (__heap_extern_start)
LONG (__heap_extern_end)
</option>
</options>
<modules>
<module>modm:board:disco-f469ni</module>
Expand Down
45 changes: 44 additions & 1 deletion src/modm/board/disco_f469ni/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
13 changes: 8 additions & 5 deletions src/modm/platform/core/cortex/linker.macros
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = .;
Expand All @@ -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
Expand All @@ -153,15 +156,15 @@ 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
LONG({{ section.prop }})
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
Expand Down
91 changes: 63 additions & 28 deletions src/modm/platform/core/cortex/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/modm/platform/core/stm32/linkerscript/stm32_dccm.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) }}
Expand All @@ -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() }}
Expand Down
5 changes: 1 addition & 4 deletions src/modm/platform/core/stm32/linkerscript/stm32_iccm.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
5 changes: 1 addition & 4 deletions src/modm/platform/core/stm32/linkerscript/stm32_idtcm.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
5 changes: 1 addition & 4 deletions src/modm/platform/core/stm32/linkerscript/stm32_ram.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
5 changes: 4 additions & 1 deletion src/modm/platform/core/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/fault/cortex/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dee5ea2

Please sign in to comment.