summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--atmel-samd/Makefile8
-rw-r--r--tools/build_memory_info.py65
2 files changed, 68 insertions, 5 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index cbfe4fc0a..d6e2090f5 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -139,12 +139,10 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
endif
-LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
-LDFLAGS = -L asf/thirdparty/CMSIS/Lib/GCC/ -L QTouch/ -L $(dir $(LIBGCC_FILE_NAME)) -L $(dir $(LIBM_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
+LDFLAGS = -Lasf/thirdparty/CMSIS/Lib/GCC/ -LQTouch/ -L$(dir $(LIBM_FILE_NAME)) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LIBS = -larm_cortexM0l_math -lsamd21_qtouch_gcc -lm -lgcc -lc
-
SRC_ASF = $(addprefix asf/sam0/,\
drivers/adc/adc_sam_d_r/adc.c \
drivers/dac/dac_sam_d_c/dac.c \
@@ -260,8 +258,8 @@ all: $(BUILD)/firmware.bin
$(BUILD)/firmware.elf: $(OBJ)
$(ECHO) "LINK $@"
- $(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
- $(Q)$(SIZE) $@
+ $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
+ $(Q)$(SIZE) $@ | python3 ../tools/build_memory_info.py $(LD_FILE)
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(ECHO) "Create $@"
diff --git a/tools/build_memory_info.py b/tools/build_memory_info.py
new file mode 100644
index 000000000..af871c0ce
--- /dev/null
+++ b/tools/build_memory_info.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+#
+# This file is part of the MicroPython project, http://micropython.org/
+#
+# The MIT License (MIT)
+#
+# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+import sys
+
+print()
+
+text = 0
+data = 0
+bss = 0
+# stdin is the linker output.
+for line in sys.stdin:
+ line = line.strip()
+ if not line.startswith("text"):
+ text, data, bss = map(int, line.split()[:3])
+
+regions = {}
+# This file is the linker script.
+with open(sys.argv[1], "r") as f:
+ for line in f:
+ line = line.strip()
+ if line.startswith(("FLASH", "RAM")):
+ regions[line.split()[0]] = line.split("=")[-1]
+
+for region in regions:
+ space = regions[region]
+ if "/*" in space:
+ space = space.split("/*")[0]
+ regions[region] = eval(space)
+
+free_flash = regions["FLASH"] - text - data
+free_ram = regions["RAM"] - data - bss
+print(free_flash, "bytes free in flash out of", regions["FLASH"], "bytes (", regions["FLASH"] / 1024, "kb ).")
+print(free_ram, "bytes free in ram for stack out of", regions["RAM"], "bytes (", regions["RAM"] / 1024, "kb ).")
+print()
+
+# Check that we have free flash space. GCC doesn't fail when the text + data
+# sections don't fit in FLASH. It only counts data in RAM.
+if free_flash < 0:
+ print("Too little flash!!!")
+ print()
+ sys.exit(-1)