mpmboot/Makefile

64 lines
1.7 KiB
Makefile
Raw Permalink Normal View History

2014-10-05 14:29:34 +02:00
CC := avr-gcc
LD := avr-ld
OBJCOPY := avr-objcopy
OBJDUMP := avr-objdump
SIZE := avr-size
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
TARGET = mpmboot
SOURCE = $(wildcard *.c)
2012-03-12 22:11:02 +01:00
2014-10-05 14:29:34 +02:00
# select MCU
MCU = atmega32
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
#AVRDUDE_PROG := -c dragon_isp -P usb
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
# ---------------------------------------------------------------------------
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
ifeq ($(MCU), atmega32)
# (8Mhz internal RC-Osz.)
AVRDUDE_MCU=m32
AVRDUDE_FUSES=lfuse:w:0xd4:m hfuse:w:0xda:m
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
BOOTLOADER_START=0x7800
endif
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
# ---------------------------------------------------------------------------
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
CFLAGS += -DOSCCAL_VALUE=0xA8 -DOSCCAL_CHECK=0 -DMPM_ADDRESS=0x11
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
# ---------------------------------------------------------------------------
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
$(TARGET): $(TARGET).elf
@$(SIZE) -B -x --mcu=$(MCU) $<
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
$(TARGET).elf: $(SOURCE:.c=.o)
@echo " Linking file: $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
@$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
@$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
@$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
%.o: %.c $(MAKEFILE_LIST)
@echo " Building file: $<"
@$(CC) $(CFLAGS) -o $@ -c $<
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
clean:
rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
2012-02-02 21:24:02 +01:00
2014-10-05 14:29:34 +02:00
install: $(TARGET).elf
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
2012-03-12 22:11:02 +01:00
fuses:
2014-10-05 14:29:34 +02:00
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))
2012-03-12 22:11:02 +01:00
osccal:
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U calibration:r:-:h
2012-02-02 21:24:02 +01:00
reset:
2012-03-12 22:11:02 +01:00
avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU)