aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--arduino-mk/Arduino.mk23
-rwxr-xr-xbin/ard-verify-size9
3 files changed, 31 insertions, 4 deletions
diff --git a/README.md b/README.md
index 3a0f280..44a8d9f 100644
--- a/README.md
+++ b/README.md
@@ -116,6 +116,9 @@ The following are the list of changes that I have made or merged in this fork. H
- Make everybody depend on the makefile, in case cflags are changed, etc.
- Make the makefile error if the arduino port is not present.
+### 0.10.2 15.xii.2012 Sudar
+- Added sketch size verification. (https://github.com/fornellas)
+
## Know Issues
- Because of the way the makefile is structured, the configuration parameters gets printed twice.
- Doesn't work with Leonardo yet.
diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk
index 478ef07..57680b5 100644
--- a/arduino-mk/Arduino.mk
+++ b/arduino-mk/Arduino.mk
@@ -141,6 +141,9 @@
# - Make everybody depend on the makefile, in case cflags are changed, etc. (https://github.com/rpavlik)
# - Make the makefile error if the arduino port is not present. (https://github.com/rpavlik)
#
+# 0.10.2 15.xii.2012 Sudar
+# - Added sketch size verification. (https://github.com/fornellas)
+#
########################################################################
#
# PATHS YOU NEED TO SET UP
@@ -261,6 +264,8 @@
# make disasm - generate a .lss file in build-cli that contains
# disassembly of the compiled file interspersed
# with your original source code.
+# make verify_size - Verify that the size of the final file is less than
+# the capacity of the micro controller.
#
########################################################################
#
@@ -591,6 +596,10 @@ ifndef OBJDIR
OBJDIR = build-$(BOARD_TAG)
endif
+ifndef HEX_MAXIMUM_SIZE
+HEX_MAXIMUM_SIZE = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.maximum_size)
+endif
+
########################################################################
# Local sources
#
@@ -883,7 +892,7 @@ AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)
# Explicit targets start here
#
-all: $(OBJDIR) $(TARGET_HEX)
+all: $(OBJDIR) $(TARGET_HEX) verify_size
$(OBJDIR):
mkdir $(OBJDIR)
@@ -899,7 +908,7 @@ $(DEP_FILE): $(OBJDIR) $(DEPS)
upload: raw_upload
-raw_upload: reset $(TARGET_HEX)
+raw_upload: reset $(TARGET_HEX) verify_size
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
-U flash:w:$(TARGET_HEX):i
@@ -917,7 +926,7 @@ reset_stty:
(sleep 0.1 || sleep 1) ;\
$$STTYF $(call get_arduino_port) -hupcl
-ispload: $(TARGET_HEX)
+ispload: $(TARGET_HEX) verify_size
$(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
-U lock:w:$(ISP_LOCK_FUSE_PRE):m \
-U hfuse:w:$(ISP_HIGH_FUSE):m \
@@ -949,10 +958,16 @@ disasm: $(OBJDIR)/$(TARGET).lss
symbol_sizes: $(OBJDIR)/$(TARGET).sym
@$(ECHO) A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym
+$(TARGET_HEX).sizeok: $(TARGET_HEX)
+ $(ARDMK_PATH)/ard-verify-size $(TARGET_HEX) $(HEX_MAXIMUM_SIZE)
+ touch $@
+
+verify_size: $(TARGET_HEX) $(TARGET_HEX).sizeok
+
generated_assembly: $(OBJDIR)/$(TARGET).s
@$(ECHO) Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s
-.PHONY: all upload raw_upload reset reset_stty ispload clean depends size show_boards monitor disasm symbol_sizes generated_assembly
+.PHONY: all upload raw_upload reset reset_stty ispload clean depends size show_boards monitor disasm symbol_sizes generated_assembly verify_size
# added - in the beginning, so that we don't get an error if the file is not present
ifneq ($(MAKECMDGOALS),clean)
diff --git a/bin/ard-verify-size b/bin/ard-verify-size
new file mode 100755
index 0000000..2a7fa28
--- /dev/null
+++ b/bin/ard-verify-size
@@ -0,0 +1,9 @@
+#!/bin/bash
+TARGET_HEX="$1"
+MAX_SIZE="$2"
+HEX_SIZE="$(cut -c12- < $TARGET_HEX | tr -d \\n | tr -d \\r | wc -c | awk '{print $1/2}')"
+if [ $HEX_SIZE -gt $MAX_SIZE ]
+then
+ echo "Sketch size is ${HEX_SIZE} bytes and maximum allowed is ${MAX_SIZE} bytes; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it." 1>&2
+ exit 1
+fi