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)
This commit is contained in:
Markus Hitter 2016-04-20 23:43:40 +02:00
parent 13c76244b6
commit 8c110da610
2 changed files with 14 additions and 15 deletions

View File

@ -159,22 +159,20 @@ all: $(PROGRAM).hex $(BUILDDIR)/$(PROGRAM).lst $(BUILDDIR)/$(PROGRAM).sym size
program: $(PROGRAM).hex config.h program: $(PROGRAM).hex config.h
$(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$(PROGRAM).hex $(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$(PROGRAM).hex
## Interpret TARGET section sizes wrt different AVR chips ## 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) ## Usage: $(call show_size,section-name,168-size,328p-size,644p-size,1280-size)
define show_size define show_size
@$(OBJDUMP) -h $^ | \ @$(SIZE) -C $^ | awk '/$1/ { \
perl -MPOSIX -ne \ printf("%8s %6d bytes %3d%% %3d%% %3d%% %3d%%\n", \
'/.($2)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; \ $$1, $$2, \
END { printf " %-7s: %5d bytes %3d%% %3d%% %3d%% %3d%%\n", "$1", $$a, \ ($$2 * 100 / ($2 * 1024)) + 1, \
ceil($$a * 100 / ($3 * 1024)), \ ($$2 * 100 / ($3 * 1024)) + 1, \
ceil($$a * 100 / ($4 * 1024)), \ ($$2 * 100 / ($4 * 1024)) + 1, \
ceil($$a * 100 / ($5 * 1024)), \ ($$2 * 100 / ($5 * 1024)) + 1); }'
ceil($$a * 100 / ($6 * 1024)) \
}'
endef endef
size: $(BUILDDIR)/$(PROGRAM).elf size: $(BUILDDIR)/$(PROGRAM).elf
@echo " SIZES ATmega... '168 '328(P) '644(P) '1280" @echo "ATmega sizes '168 '328(P) '644(P) '1280"
$(call show_size,FLASH,text,14,30,62,126) $(call show_size,Program,14,30,62,126)
$(call show_size,RAM,data|bss,1,2,4,8) $(call show_size,Data,1,2,4,8)
$(call show_size,EEPROM,eeprom,1,2,2,4) $(call show_size,EEPROM,1,2,2,4)

View File

@ -47,6 +47,7 @@ CFLAGS += -save-temps=obj -DUSER_CONFIG='"$(USER_CONFIG)"'
CC = $(TOOLCHAIN)gcc CC = $(TOOLCHAIN)gcc
OBJDUMP = $(TOOLCHAIN)objdump OBJDUMP = $(TOOLCHAIN)objdump
OBJCOPY = $(TOOLCHAIN)objcopy OBJCOPY = $(TOOLCHAIN)objcopy
SIZE = $(TOOLCHAIN)size
OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES)) OBJ = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))