summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2023-09-05 13:45:53 -0700
committerDrashna Jael're <drashna@live.com>2023-09-05 13:45:53 -0700
commit28ec5e412606449ac13e45050bcb999e4b76dac4 (patch)
treec917c90b613ecced30b1ebf188bc41abdc1ecd9c
parentcf87d88fb228d9118480a98c909508adacb64f26 (diff)
Calculate and print stack size on AVR builds (20526)add_mem_size_check
-rw-r--r--builddefs/common_rules.mk12
-rw-r--r--builddefs/message.mk5
2 files changed, 16 insertions, 1 deletions
diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk
index 22746b92a3..9f4e3cc20e 100644
--- a/builddefs/common_rules.mk
+++ b/builddefs/common_rules.mk
@@ -399,6 +399,18 @@ check-size:
fi ; \
fi ; \
fi
+ $(eval END_POINTER=$(shell printf "%d" $$(( 0xffff & 0x$$( if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then avr-objdump -t $(BUILD_DIR)/$(TARGET).elf | grep -e '\b_end\b' | cut -c -8; else printf 0; fi ) )) ))
+ $(eval STACK_POINTER=$(shell printf "%d" $$(( 0xffff & 0x$$( if [ -f $(BUILD_DIR)/$(TARGET).elf ]; then avr-objdump -t $(BUILD_DIR)/$(TARGET).elf | grep -e '\b__stack\b' | cut -c -8; else printf 0; fi ) )) ))
+ $(eval STACK_SIZE=$(shell expr $(STACK_POINTER) + 1 - $(END_POINTER)))
+ $(eval RAM_OVERFLOW_AMOUNT=$(shell expr 0 - $(STACK_SIZE)))
+ if [ $(STACK_POINTER) -gt 0 ] && [ $(END_POINTER) -gt 0 ]; then \
+ $(SILENT) || printf "$(MSG_CHECK_STACKSIZE)" | $(AWK_CMD); \
+ if [ $(STACK_SIZE) -lt 0 ] ; then \
+ printf "\n * $(MSG_MEMORY_OVERFLOW)"; $(PRINT_ERROR_PLAIN); \
+ else \
+ $(SILENT) || printf "\n * $(MSG_STACK_SIZE)"; \
+ fi ; \
+ fi
else
check-size:
$(SILENT) || echo "$(MSG_CHECK_FILESIZE_SKIPPED)"
diff --git a/builddefs/message.mk b/builddefs/message.mk
index 07d0e07ce8..32d11f77d9 100644
--- a/builddefs/message.mk
+++ b/builddefs/message.mk
@@ -91,10 +91,13 @@ 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_CHECK_STACKSIZE = Checking stack size of $(TARGET)
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
MSG_FILE_NEAR_LIMIT = The firmware size is approaching the maximum - $(CURRENT_SIZE)/$(MAX_SIZE) ($(PERCENT_SIZE)%%, $(FREE_SIZE) bytes free)\n
+MSG_MEMORY_OVERFLOW = $(ERROR_COLOR)RAM usage (not including stack) exceeds available RAM by $(RAM_OVERFLOW_AMOUNT) bytes\n
+MSG_STACK_SIZE = Available stack size: $(STACK_SIZE) bytes\n
MSG_PYTHON_MISSING = $(ERROR_COLOR)ERROR:$(NO_COLOR) Cannot run \"qmk hello\"!\n\n\
Please run $(BOLD)qmk setup$(NO_COLOR) to install all the dependencies QMK requires.\n\n
MSG_FLASH_BOOTLOADER = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's bootloader is not specified or is not supported by the \":flash\" target at this time.\n\n
@@ -106,4 +109,4 @@ MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY = $(MSG_BOOTLOADER_NOT_FOUND_BASE) Trying a
define CATASTROPHIC_ERROR
$(shell printf "\n * %-99s $(ERROR_STRING)\n" "$2" >&2)
$(error $1)
-endef \ No newline at end of file
+endef