Move binary sketch size verification logic inside makefile

Earlier bin/ard-verify-size shell script was used to validate that the
binary hex file size is less than the flash memory of the target
microcontroller.

This commit removes the dependency on the external shell script, by
moving the binary size verification logic inside the makefile itself.

Fix #54
This commit is contained in:
Sudar 2013-07-01 21:54:56 +05:30
parent 45f230c5c8
commit 8a2e251e95
3 changed files with 15 additions and 19 deletions

View file

@ -11,6 +11,7 @@ The following is the rough list of changes that went into different versions. I
- Auto detect alternate core path from sketchbook folder. Fix issue #86
- Remove redundant checks for ARDUINO_DIR
- Improve avrdude and avrdude.conf path auto detection. Fix issue #48
- Move binary sketch size verification logic inside makefile. Fix issue #54
### 0.12.0 (2013-06-20)
- Fix "generated_assembly" target, which got broken earlier. Fix issue #76 (https://github.com/matthijskooijman)

View file

@ -879,8 +879,13 @@ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(COMMON_DEPS)
$(OBJCOPY) -O ihex -R .eeprom $< $@
@$(ECHO)
@$(ECHO)
$(call avr_size,$<,$@)
ifneq ($(strip $(HEX_MAXIMUM_SIZE)),)
@if [ `$(SIZE) $@ | awk 'FNR == 2 {print $$2}'` -le $(HEX_MAXIMUM_SIZE) ]; then touch $@.sizeok; fi
else
@$(ECHO) Maximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $@ is less than $(BOARD_TAG)\'s flash memory
@touch $@.sizeok
endif
$(OBJDIR)/%.eep: $(OBJDIR)/%.elf $(COMMON_DEPS)
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
@ -968,7 +973,7 @@ endif
# Explicit targets start here
#
all: $(TARGET_EEP) $(TARGET_HEX) verify_size
all: $(TARGET_EEP) $(TARGET_HEX)
# Rule to create $(OBJDIR) automatically. All rules with recipes that
# create a file within it, but do not already depend on a file within it
@ -1060,15 +1065,14 @@ 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)
ifneq ($(strip $(HEX_MAXIMUM_SIZE)),)
$(ARDMK_PATH)/ard-verify-size $(TARGET_HEX) $(HEX_MAXIMUM_SIZE)
touch $@
else
@$(ECHO) Maximum Hex size is not specified. Make sure the hex file that you are going to upload is less than microcontrollers flash memory
verify_size:
ifeq ($(strip $(HEX_MAXIMUM_SIZE)),)
@$(ECHO)
@$(ECHO) Maximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $(TARGET_HEX) is less than $(BOARD_TAG)\'s flash memory
@$(ECHO)
endif
verify_size: $(TARGET_HEX) $(TARGET_HEX).sizeok
@if [ ! -f $(TARGET_HEX).sizeok ]; then echo >&2 "\nThe size of the compiled binary file is greater than the $(BOARD_TAG)'s flash memory. \
See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."; false; fi
generate_assembly: $(OBJDIR)/$(TARGET).s
@$(ECHO) Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s

View file

@ -1,9 +0,0 @@
#!/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