MPM bootloader for AVR
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = mpmboot
  7. SOURCE = $(wildcard *.c)
  8. # select MCU
  9. MCU = atmega32
  10. AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
  11. #AVRDUDE_PROG := -c dragon_isp -P usb
  12. # ---------------------------------------------------------------------------
  13. ifeq ($(MCU), atmega32)
  14. # (8Mhz internal RC-Osz.)
  15. AVRDUDE_MCU=m32
  16. AVRDUDE_FUSES=lfuse:w:0xd4:m hfuse:w:0xda:m
  17. BOOTLOADER_START=0x7800
  18. endif
  19. # ---------------------------------------------------------------------------
  20. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  21. CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
  22. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
  23. CFLAGS += -DOSCCAL_VALUE=0xA8 -DOSCCAL_CHECK=0 -DMPM_ADDRESS=0x11
  24. # ---------------------------------------------------------------------------
  25. $(TARGET): $(TARGET).elf
  26. @$(SIZE) -B -x --mcu=$(MCU) $<
  27. $(TARGET).elf: $(SOURCE:.c=.o)
  28. @echo " Linking file: $@"
  29. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  30. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  31. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  32. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  33. %.o: %.c $(MAKEFILE_LIST)
  34. @echo " Building file: $<"
  35. @$(CC) $(CFLAGS) -o $@ -c $<
  36. clean:
  37. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
  38. install: $(TARGET).elf
  39. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  40. fuses:
  41. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))
  42. osccal:
  43. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U calibration:r:-:h
  44. reset:
  45. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU)