A TWI / I2C bootloader for AVR MCUs
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.

72 lines
1.9KB

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