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.

Makefile 2.4KB

5 years ago
12 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
11 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # atmega8:
  15. # Fuse L: 0x84 (8Mhz internal RC-Osz., 2.7V BOD)
  16. # Fuse H: 0xda (512 words bootloader)
  17. AVRDUDE_MCU=m8
  18. AVRDUDE_FUSES=lfuse:w:0x84:m hfuse:w:0xda:m
  19. BOOTLOADER_START=0x1C00
  20. endif
  21. ifeq ($(MCU), atmega88)
  22. # atmega88:
  23. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  24. # Fuse H: 0xdd (2.7V BOD)
  25. # Fuse E: 0xfa (512 words bootloader)
  26. AVRDUDE_MCU=m88
  27. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
  28. BOOTLOADER_START=0x1C00
  29. endif
  30. ifeq ($(MCU), atmega168)
  31. # atmega168:
  32. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  33. # Fuse H: 0xdd (2.7V BOD)
  34. # Fuse E: 0xfa (512 words bootloader)
  35. AVRDUDE_MCU=m168 -F
  36. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
  37. BOOTLOADER_START=0x3C00
  38. endif
  39. ifeq ($(MCU), atmega328p)
  40. # atmega328p:
  41. # Fuse L: 0xc2 (8Mhz internal RC-Osz.)
  42. # Fuse H: 0xdc (512 words bootloader)
  43. # Fuse E: 0xfd (2.7V BOD)
  44. AVRDUDE_MCU=m328p -F
  45. AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdc:m efuse:w:0xfd:m
  46. BOOTLOADER_START=0x7C00
  47. endif
  48. # ---------------------------------------------------------------------------
  49. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  50. CFLAGS += -Wa,-adhlns=$(*F).lst -DBOOTLOADER_START=$(BOOTLOADER_START)
  51. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
  52. LDFLAGS += -nostartfiles
  53. # ---------------------------------------------------------------------------
  54. $(TARGET): $(TARGET).elf
  55. @$(SIZE) -B -x --mcu=$(MCU) $<
  56. $(TARGET).elf: $(SOURCE:.c=.o)
  57. @echo " Linking file: $@"
  58. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  59. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  60. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  61. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  62. %.o: %.c $(MAKEFILE_LIST)
  63. @echo " Building file: $<"
  64. @$(CC) $(CFLAGS) -o $@ -c $<
  65. clean:
  66. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin)
  67. install: $(TARGET).elf
  68. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  69. fuses:
  70. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))