From b5448a64dc20f996a753c2cd3332e30be8df3ab8 Mon Sep 17 00:00:00 2001 From: Fabio Pugliese Ornellas Date: Mon, 12 Nov 2012 21:34:51 -0200 Subject: [PATCH 1/2] Added sketch size verification. --- arduino-mk/Arduino.mk | 15 +++++++++++---- bin/ard-verify-size | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100755 bin/ard-verify-size diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 09819ac..56204f9 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -445,6 +445,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 # @@ -655,7 +659,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) @@ -671,7 +675,7 @@ $(DEP_FILE): $(OBJDIR) $(DEPS) upload: reset raw_upload -raw_upload: $(TARGET_HEX) +raw_upload: $(TARGET_HEX) verify_size $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ -U flash:w:$(TARGET_HEX):i @@ -689,7 +693,7 @@ reset_stty: (sleep 0.1 || sleep 1) ;\ $$STTYF $(ARD_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 \ @@ -715,6 +719,9 @@ show_boards: monitor: $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) -.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor +verify_size: $(TARGET_HEX) + $(ARDMK_PATH)/ard-verify-size $(TARGET_HEX) $(HEX_MAXIMUM_SIZE) + +.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor verify_size include $(DEP_FILE) 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 From bfd9dac2167043b4e8b24324119bf89fd90c75bf Mon Sep 17 00:00:00 2001 From: Fabio Pugliese Ornellas Date: Mon, 12 Nov 2012 22:13:03 -0200 Subject: [PATCH 2/2] Added dummy file to verify_size to avoid always being run. --- arduino-mk/Arduino.mk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 56204f9..6cbf133 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -719,9 +719,12 @@ show_boards: monitor: $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE) -verify_size: $(TARGET_HEX) +$(TARGET_HEX).sizeok: $(TARGET_HEX) $(ARDMK_PATH)/ard-verify-size $(TARGET_HEX) $(HEX_MAXIMUM_SIZE) + touch $@ -.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor verify_size +verify_size: $(TARGET_HEX) $(TARGET_HEX).sizeok + +.PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitorx verify_size include $(DEP_FILE)