update Makefile
This commit is contained in:
parent
6b836baeb0
commit
33fd6d1690
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,5 +3,6 @@
|
|||||||
*.bin
|
*.bin
|
||||||
*.hex
|
*.hex
|
||||||
*.lst
|
*.lst
|
||||||
|
*.lss
|
||||||
*.map
|
*.map
|
||||||
ldscript-no-vectors.x
|
ldscript-no-vectors-*.x
|
||||||
|
98
Makefile
98
Makefile
@ -1,54 +1,68 @@
|
|||||||
PRG = fc_boot
|
CC := avr-gcc
|
||||||
OBJ = main.o
|
LD := avr-ld
|
||||||
MCU_TARGET = atmega644p
|
OBJCOPY := avr-objcopy
|
||||||
OPTIMIZE = -Os
|
OBJDUMP := avr-objdump
|
||||||
|
SIZE := avr-size
|
||||||
|
|
||||||
DEFS =
|
TARGET = fc_boot
|
||||||
LIBS =
|
SOURCE = $(wildcard *.c)
|
||||||
|
|
||||||
LDSCRIPT_SRC := /usr/lib/ldscripts/avr5.x
|
# select MCU
|
||||||
LDSCRIPT_DST := ldscript-no-vectors.x
|
MCU = atmega644p
|
||||||
|
|
||||||
# Override is only needed by avr-lib build system.
|
AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
|
||||||
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
|
#AVRDUDE_PROG := -c dragon_isp -P usb
|
||||||
override LDFLAGS = -Wl,-Map,$(PRG).map,--section-start=.text=0xF800,-T$(LDSCRIPT_DST)
|
|
||||||
|
|
||||||
CC = avr-gcc
|
# ---------------------------------------------------------------------------
|
||||||
OBJCOPY = avr-objcopy
|
|
||||||
OBJDUMP = avr-objdump
|
|
||||||
SIZE = avr-size
|
|
||||||
|
|
||||||
#LDSCRIPT_SRC := $(shell LANG=C $(CC) $(CFLAGS) -Wl,--verbose 2> /dev/null | awk '/^opened script file (.*)$$/{ print $$4 }')
|
ifeq ($(MCU), atmega644p)
|
||||||
|
AVRDUDE_MCU=m644p
|
||||||
|
|
||||||
all: $(PRG).elf lst text
|
# (20MHz ext. Crystal, 2.7V BOD)
|
||||||
$(SIZE) -x -A $(PRG).elf
|
AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdc:m efuse:w:0xfd:m
|
||||||
|
BOOTLOADER_START=0xF800
|
||||||
|
endif
|
||||||
|
|
||||||
$(PRG).elf: $(OBJ) | $(LDSCRIPT_DST)
|
# ---------------------------------------------------------------------------
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
|
||||||
|
|
||||||
$(LDSCRIPT_DST): $(LDSCRIPT_SRC)
|
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall
|
||||||
# remove all lines with *vectors* and insert DISCARD line above .text declaration
|
CFLAGS += -fdata-sections -ffunction-sections
|
||||||
sed -e '/.*vectors.*/d' -e 's/\(^[ \t]*\)\(.text[ \t]*\:\)$$/\1\/DISCARD\/ : { *(.vectors) }\n\1\2/g' $^ > $@
|
CFLAGS += -Wa,-adhlns=$(*F).lst
|
||||||
# -diff -uNr $^ $@ > $@.diff
|
CFLAGS += -DBOOTLOADER_START=$(BOOTLOADER_START)
|
||||||
|
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--section-start=.text=$(BOOTLOADER_START)
|
||||||
|
LDFLAGS += -Wl,--relax,--gc-sections
|
||||||
|
|
||||||
|
LDSCRIPT := $(shell LANG=C $(CC) $(CFLAGS) -Wl,--verbose 2> /dev/null | awk '/^opened script file (.*)$$/{ print $$4 }')
|
||||||
|
LDSCRIPT_NOVECT := ldscript-no-vectors-$(notdir $(LDSCRIPT))
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
$(TARGET): $(TARGET).elf
|
||||||
|
@$(SIZE) -B -x --mcu=$(MCU) $<
|
||||||
|
|
||||||
|
$(TARGET).elf: $(SOURCE:.c=.o) | $(LDSCRIPT_NOVECT)
|
||||||
|
@echo " Linking file: $@"
|
||||||
|
@$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-T$(LDSCRIPT_NOVECT) -o $@ $^ 2> /dev/null
|
||||||
|
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
|
||||||
|
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
|
||||||
|
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
|
||||||
|
|
||||||
|
%.o: %.c $(MAKEFILE_LIST)
|
||||||
|
@echo " Building file: $<"
|
||||||
|
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
# remove interrupt vector section from avr-libc linker script
|
||||||
|
# (remove all lines with *vectors* and insert DISCARD line above .text declaration)
|
||||||
|
$(LDSCRIPT_NOVECT): $(LDSCRIPT) $(MAKEFILE_LIST)
|
||||||
|
@echo " Creating: $@"
|
||||||
|
@sed -e '/.*vectors.*/d' -e 's/\(^[ \t]*\)\(.text[ \t]*\:\)$$/\1\/DISCARD\/ : { *(.vectors) }\n\1\2/g' $< > $@
|
||||||
|
# -@diff -uNr $< $@ > $@.diff
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.o $(PRG).lst $(PRG).map $(PRG).elf $(PRG).hex $(PRG).bin $(LDSCRIPT_DST)
|
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin) $(LDSCRIPT_NOVECT)
|
||||||
|
|
||||||
lst: $(PRG).lst
|
install: $(TARGET).elf
|
||||||
|
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
|
||||||
|
|
||||||
%.lst: %.elf
|
fuses:
|
||||||
$(OBJDUMP) -h -S $< > $@
|
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))
|
||||||
|
|
||||||
text: hex bin
|
|
||||||
|
|
||||||
hex: $(PRG).hex
|
|
||||||
bin: $(PRG).bin
|
|
||||||
|
|
||||||
%.hex: %.elf
|
|
||||||
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
|
||||||
|
|
||||||
%.bin: %.elf
|
|
||||||
$(OBJCOPY) -j .text -j .data -O binary $< $@
|
|
||||||
|
|
||||||
install: text
|
|
||||||
avrdude -c dragon_isp -P usb -p m644p -V -U flash:w:$(PRG).hex
|
|
||||||
|
Loading…
Reference in New Issue
Block a user