From 8c110da6106e936af112a3e499b074dbf1d652c4 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Wed, 20 Apr 2016 23:43:40 +0200 Subject: [PATCH] Makefile-AVR: correct reported program sizes. What 'make size' previously reported was misleading, because it didn't count the .data section as Flash usage. However, this section is actually written to Flash. The .data section holds the data needed for inititalising variables. As such it counts to both, Flash and RAM usage. Nice verification: reported 'Program' size now matches upload size reported by avrdude exactly. There's now the tool 'avr-size', which makes reading such stuff much easier: avr-size -C build/teacup.elf Example output: AVR Memory Usage ---------------- Device: Unknown Program: 23704 bytes (.text + .data + .bootloader) Data: 1543 bytes (.data + .bss + .noinit) EEPROM: 32 bytes (.eeprom) --- Makefile-AVR | 28 +++++++++++++--------------- Makefile-common | 1 + 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Makefile-AVR b/Makefile-AVR index 28e61ec..a35ff36 100644 --- a/Makefile-AVR +++ b/Makefile-AVR @@ -159,22 +159,20 @@ all: $(PROGRAM).hex $(BUILDDIR)/$(PROGRAM).lst $(BUILDDIR)/$(PROGRAM).sym size program: $(PROGRAM).hex config.h $(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$(PROGRAM).hex -## Interpret TARGET section sizes wrt different AVR chips -## Usage: $(call show_size,section-name,section-regex,Atmega168-size-in-k,Atmega328p-size-in-k,Atmega644p-size-in-k,Atmega1280-size-in-k) +## Interpret TARGET section sizes wrt different AVR chips. +## Usage: $(call show_size,section-name,168-size,328p-size,644p-size,1280-size) define show_size - @$(OBJDUMP) -h $^ | \ - perl -MPOSIX -ne \ - '/.($2)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; \ - END { printf " %-7s: %5d bytes %3d%% %3d%% %3d%% %3d%%\n", "$1", $$a, \ - ceil($$a * 100 / ($3 * 1024)), \ - ceil($$a * 100 / ($4 * 1024)), \ - ceil($$a * 100 / ($5 * 1024)), \ - ceil($$a * 100 / ($6 * 1024)) \ - }' + @$(SIZE) -C $^ | awk '/$1/ { \ + printf("%8s %6d bytes %3d%% %3d%% %3d%% %3d%%\n", \ + $$1, $$2, \ + ($$2 * 100 / ($2 * 1024)) + 1, \ + ($$2 * 100 / ($3 * 1024)) + 1, \ + ($$2 * 100 / ($4 * 1024)) + 1, \ + ($$2 * 100 / ($5 * 1024)) + 1); }' endef size: $(BUILDDIR)/$(PROGRAM).elf - @echo " SIZES ATmega... '168 '328(P) '644(P) '1280" - $(call show_size,FLASH,text,14,30,62,126) - $(call show_size,RAM,data|bss,1,2,4,8) - $(call show_size,EEPROM,eeprom,1,2,2,4) + @echo "ATmega sizes '168 '328(P) '644(P) '1280" + $(call show_size,Program,14,30,62,126) + $(call show_size,Data,1,2,4,8) + $(call show_size,EEPROM,1,2,2,4) diff --git a/Makefile-common b/Makefile-common index 461f9b0..e7be5eb 100644 --- a/Makefile-common +++ b/Makefile-common @@ -47,6 +47,7 @@ CFLAGS += -save-temps=obj -DUSER_CONFIG='"$(USER_CONFIG)"' CC = $(TOOLCHAIN)gcc OBJDUMP = $(TOOLCHAIN)objdump OBJCOPY = $(TOOLCHAIN)objcopy +SIZE = $(TOOLCHAIN)size OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))