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:
parent
13c76244b6
commit
8c110da610
28
Makefile-AVR
28
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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue