aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-01 13:25:29 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-03-01 19:03:34 -0500
commitd33c4820bd9f9d8d6301270c846757ee4c3d362c (patch)
tree18be734d21f2d03e2a649497a262983277b3897c /src
parente18501d01cd5ff361edf4d1ad577946f502c4019 (diff)
downloadkutter-d33c4820bd9f9d8d6301270c846757ee4c3d362c.tar.gz
kutter-d33c4820bd9f9d8d6301270c846757ee4c3d362c.tar.xz
kutter-d33c4820bd9f9d8d6301270c846757ee4c3d362c.zip
atsamd: Use local linker script
Use a local linker script instead of the linker script provided by Atmel. This will allow Klipper to use dynamic memory allocation. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/atsamd/Kconfig16
-rw-r--r--src/atsamd/Makefile14
-rw-r--r--src/atsamd/samd.lds.S63
3 files changed, 84 insertions, 9 deletions
diff --git a/src/atsamd/Kconfig b/src/atsamd/Kconfig
index c77f57bb..236a2a0e 100644
--- a/src/atsamd/Kconfig
+++ b/src/atsamd/Kconfig
@@ -53,6 +53,22 @@ config CLOCK_FREQ
default 48000000 if MACH_SAMD21
default 120000000 if MACH_SAMD51
+config FLASH_SIZE
+ hex
+ default 0x40000 if MACH_SAMD21G18
+ default 0x80000 if MACH_SAMD51G19 || MACH_SAMD51J19 || MACH_SAMD51N19
+ default 0x100000 if MACH_SAMD51P20
+
+config RAM_SIZE
+ hex
+ default 0x8000 if MACH_SAMD21G18
+ default 0x30000 if MACH_SAMD51G19 || MACH_SAMD51J19 || MACH_SAMD51N19
+ default 0x40000 if MACH_SAMD51P20
+
+config STACK_SIZE
+ int
+ default 512
+
choice
prompt "Clock Reference"
config CLOCK_REF_X32K
diff --git a/src/atsamd/Makefile b/src/atsamd/Makefile
index 3b749d5d..0ef2aa91 100644
--- a/src/atsamd/Makefile
+++ b/src/atsamd/Makefile
@@ -37,17 +37,13 @@ src-$(CONFIG_MACH_SAMD51) += atsamd/samd51_clock.c generic/armcm_timer.c
src-$(CONFIG_MACH_SAMD51) += ../lib/samd51/samd51a/gcc/gcc/startup_samd51.c
# Support bootloader offset address
-target-y := $(OUT)samd.ld $(target-y)
+target-y := $(target-y)
-ldfile-$(CONFIG_MACH_SAMD21G18) := lib/samd21/samd21a/gcc/gcc/samd21g18a_flash.ld
-ldfile-$(CONFIG_MACH_SAMD51G19) := lib/samd51/samd51a/gcc/gcc/samd51g19a_flash.ld
-ldfile-$(CONFIG_MACH_SAMD51J19) := lib/samd51/samd51a/gcc/gcc/samd51j19a_flash.ld
-ldfile-$(CONFIG_MACH_SAMD51N19) := lib/samd51/samd51a/gcc/gcc/samd51n19a_flash.ld
-ldfile-$(CONFIG_MACH_SAMD51P20) := lib/samd51/samd51a/gcc/gcc/samd51p20a_flash.ld
-
-$(OUT)samd.ld: $(ldfile-y) $(OUT)board-link
+$(OUT)samd.ld: src/atsamd/samd.lds.S $(OUT)board-link
@echo " Preprocessing $@"
- $(Q)$(CPP) -P -MD -MT $@ -DFLASH_START=$(CONFIG_FLASH_START) $< -o $@
+ $(Q)$(CPP) -I$(OUT) -P -MD -MT $@ $< -o $@
+
+$(OUT)klipper.elf: $(OUT)samd.ld
# Build the additional hex and bin output files
target-y += $(OUT)klipper.bin $(OUT)klipper.elf.hex
diff --git a/src/atsamd/samd.lds.S b/src/atsamd/samd.lds.S
new file mode 100644
index 00000000..62e9d6ad
--- /dev/null
+++ b/src/atsamd/samd.lds.S
@@ -0,0 +1,63 @@
+/* Linker script for atsamd chips
+ *
+ * Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+ *
+ * This file may be distributed under the terms of the GNU GPLv3 license.
+ */
+
+#include "autoconf.h"
+
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+
+MEMORY
+{
+ rom (rx) : ORIGIN = CONFIG_FLASH_START , LENGTH = CONFIG_FLASH_SIZE
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = CONFIG_RAM_SIZE
+}
+
+SECTIONS
+{
+ .text : {
+ . = ALIGN(4);
+ _sfixed = .;
+ KEEP(*(.vectors .vectors.*))
+ *(.text .text.*)
+ *(.rodata .rodata*)
+
+ . = ALIGN(4);
+ KEEP(*(.init))
+ . = ALIGN(4);
+ KEEP(*(.fini))
+ } > rom
+
+ . = ALIGN(4);
+ _etext = .;
+
+ .relocate : AT (_etext)
+ {
+ . = ALIGN(4);
+ _srelocate = .;
+ *(.ramfunc .ramfunc.*);
+ *(.data .data.*);
+ . = ALIGN(4);
+ _erelocate = .;
+ } > ram
+
+ .bss (NOLOAD) :
+ {
+ . = ALIGN(4);
+ _szero = .;
+ *(.bss .bss.*)
+ *(COMMON)
+ . = ALIGN(4);
+ _ezero = .;
+ } > ram
+
+ _sstack = 0x20000000 + CONFIG_RAM_SIZE - CONFIG_STACK_SIZE ;
+ .stack _sstack (NOLOAD) :
+ {
+ . = . + CONFIG_STACK_SIZE;
+ _estack = .;
+ } > ram
+}