From 2a0e3f1a4b41145331e6a2fb0f72495516ac12b5 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 12 Sep 2023 05:16:39 +0100 Subject: [PATCH] Remove 'Firmware size check does not yet support' message (#21977) --- builddefs/common_rules.mk | 26 +------------------------- builddefs/message.mk | 1 - platforms/avr/platform.mk | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index d20e9ad74d2c..261ab7da02cd 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -380,33 +380,9 @@ dump_vars: objs-size: for i in $(OBJ); do echo $$i; done | sort | xargs $(SIZE) -ifeq ($(findstring avr-gcc,$(CC)),avr-gcc) -SIZE_MARGIN = 1024 +# size check optionally implemented in its platform.mk 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 -else -check-size: - $(SILENT) || echo "$(MSG_CHECK_FILESIZE_SKIPPED)" -endif check-md5: $(MD5SUM) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) diff --git a/builddefs/message.mk b/builddefs/message.mk index bf39554dab77..c7cc5171e785 100644 --- a/builddefs/message.mk +++ b/builddefs/message.mk @@ -91,7 +91,6 @@ MSG_AVAILABLE_KEYMAPS = $(eval $(call GENERATE_MSG_AVAILABLE_KEYMAPS))$(MSG_AVAI MSG_BOOTLOADER_NOT_FOUND_BASE = Bootloader not found. Make sure the board is in bootloader mode. See https://docs.qmk.fm/\#/newbs_flashing\n MSG_CHECK_FILESIZE = Checking file size of $(TARGET).$(FIRMWARE_FORMAT) -MSG_CHECK_FILESIZE_SKIPPED = (Firmware size check does not yet support $(MCU_ORIG); skipping) MSG_FILE_TOO_BIG = $(ERROR_COLOR)The firmware is too large!$(NO_COLOR) $(CURRENT_SIZE)/$(MAX_SIZE) ($(OVER_SIZE) bytes over)\n MSG_FILE_TOO_SMALL = The firmware is too small! $(CURRENT_SIZE)/$(MAX_SIZE)\n MSG_FILE_JUST_RIGHT = The firmware size is fine - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n diff --git a/platforms/avr/platform.mk b/platforms/avr/platform.mk index 09028d80af36..aef449cadf76 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)