Added sketch size verification.

This commit is contained in:
Fabio Pugliese Ornellas 2012-11-12 21:34:51 -02:00
parent 184230fcf2
commit b5448a64dc
2 changed files with 20 additions and 4 deletions

View file

@ -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)

9
bin/ard-verify-size Executable file
View file

@ -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