summaryrefslogtreecommitdiff
path: root/platforms/avr/platform.mk
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/avr/platform.mk')
-rw-r--r--platforms/avr/platform.mk23
1 files changed, 23 insertions, 0 deletions
diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk
index 09028d80af..aef449cadf 100644
--- a/platforms/avr/platform.mk
+++ b/platforms/avr/platform.mk
@@ -109,6 +109,29 @@ DEBUG_HOST = localhost
#============================================================================
+SIZE_MARGIN = 1024
+
+check-size:
+ $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | $(SED) -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
+ $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi))
+ $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE)))
+ $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE)))
+ $(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE)))
+ if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \
+ $(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \
+ if [ $(CURRENT_SIZE) -gt $(MAX_SIZE) ]; then \
+ $(REMOVE) $(TARGET).$(FIRMWARE_FORMAT); \
+ $(REMOVE) $(BUILD_DIR)/$(TARGET).{hex,bin,uf2}; \
+ printf "\n * $(MSG_FILE_TOO_BIG)"; $(PRINT_ERROR_PLAIN); \
+ else \
+ if [ $(FREE_SIZE) -lt $(SIZE_MARGIN) ]; then \
+ $(PRINT_WARNING_PLAIN); printf " * $(MSG_FILE_NEAR_LIMIT)"; \
+ else \
+ $(PRINT_OK); $(SILENT) || printf " * $(MSG_FILE_JUST_RIGHT)"; \
+ fi ; \
+ fi ; \
+ fi
+
# Convert hex to bin.
bin: $(BUILD_DIR)/$(TARGET).hex
ifeq ($(BOOTLOADER),lufa-ms)