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.

Makefile 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ifeq ($(MCU), atmega328p)
  32. # (8Mhz internal RC-Osz., 2.7V BOD)
  33. AVRDUDE_MCU=m328p -F
  34. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdc:m efuse:w:0xfd:m
  35. BOOTLOADER_START=0x7C00
  36. endif
  37. # ---------------------------------------------------------------------------
  38. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  39. CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
  40. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
  41. # ---------------------------------------------------------------------------
  42. $(TARGET): $(TARGET).elf
  43. @$(SIZE) -B -x --mcu=$(MCU) $<
  44. $(TARGET).elf: $(SOURCE:.c=.o)
  45. @echo " Linking file: $@"
  46. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  47. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  48. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  49. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  50. %.o: %.c $(MAKEFILE_LIST)
  51. @echo " Building file: $<"
  52. @$(CC) $(CFLAGS) -o $@ -c $<
  53. clean:
  54. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
  55. install: $(TARGET).elf
  56. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  57. fuses:
  58. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))