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.
 
 

141 lines
3.6 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = uartboot
  7. SOURCE = $(wildcard *.c)
  8. #CONFIG = ispprog
  9. #CONFIG = flightctrl
  10. #CONFIG = funkstuff88
  11. #CONFIG = funkstuff168
  12. #CONFIG = ispprog2
  13. #CONFIG = avrnetio
  14. CONFIG = funkbridge
  15. AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ispprog
  16. #AVRDUDE_PROG := -c dragon_isp -P usb
  17. # ---------------------------------------------------------------------------
  18. ifeq ($(CONFIG), ispprog)
  19. MCU=atmega16
  20. AVRDUDE_MCU=m16
  21. # (7.3728MHz ext. crystal)
  22. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xda:m
  23. BOOTLOADER_START=0x3C00
  24. endif
  25. # -------------------------
  26. ifeq ($(CONFIG), flightctrl)
  27. MCU=atmega644p
  28. AVRDUDE_MCU=m644p
  29. # (20MHz ext. Crystal, 2.7V BOD)
  30. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdc:m efuse:w:0xfd:m
  31. BOOTLOADER_START=0xF800
  32. endif
  33. # -------------------------
  34. ifeq ($(CONFIG), funkstuff88)
  35. MCU=atmega88
  36. AVRDUDE_MCU=m88 -F
  37. # (8MHz internal osc., 2.7V BOD)
  38. AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdd:m efuse:w:0x02:m
  39. BOOTLOADER_START=0x1C00
  40. endif
  41. # -------------------------
  42. ifeq ($(CONFIG), funkstuff168)
  43. MCU=atmega168
  44. AVRDUDE_MCU=m168 -F
  45. # (ext. crystal 16MHz, 2.7V BOD)
  46. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdd:m efuse:w:0x02:m
  47. BOOTLOADER_START=0x3C00
  48. endif
  49. # -------------------------
  50. ifeq ($(CONFIG), ispprog2)
  51. MCU=atmega328p
  52. AVRDUDE_MCU=m328p -F
  53. # (8MHz internal osc., 2.7V BOD)
  54. AVRDUDE_FUSES=lfuse:w:0xe2:m hfuse:w:0xdc:m efuse:w:0x02:m
  55. BOOTLOADER_START=0x7C00
  56. endif
  57. # -------------------------
  58. ifeq ($(CONFIG), avrnetio)
  59. MCU=atmega644
  60. AVRDUDE_MCU=m644
  61. # (16MHz ext. crystal, 2.7V BOD)
  62. AVRDUDE_FUSES=lfuse:w:0xd7:m hfuse:w:0xdc:m efuse:w:0xfd:m
  63. BOOTLOADER_START=0xF800
  64. endif
  65. # -------------------------
  66. ifeq ($(CONFIG), funkbridge)
  67. MCU=atmega328p
  68. AVRDUDE_MCU=m328p -F
  69. # (16MHz ext. crystal, 2.7V BOD)
  70. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdc:m efuse:w:0x02:m
  71. BOOTLOADER_START=0x7C00
  72. endif
  73. # ---------------------------------------------------------------------------
  74. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall
  75. CFLAGS += -fdata-sections -ffunction-sections
  76. CFLAGS += -Wa,-adhlns=$(*F).lst
  77. CFLAGS += -DBOOTLOADER_START=$(BOOTLOADER_START) -DCONFIG_$(CONFIG)=1
  78. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--section-start=.text=$(BOOTLOADER_START)
  79. LDFLAGS += -Wl,--relax,--gc-sections
  80. LDSCRIPT := $(shell LANG=C $(CC) $(CFLAGS) -Wl,--verbose 2> /dev/null | awk '/^opened script file (.*)$$/{ print $$4 }')
  81. LDSCRIPT_NOVECT := ldscript-no-vectors-$(notdir $(LDSCRIPT))
  82. # ---------------------------------------------------------------------------
  83. $(TARGET): $(TARGET).elf
  84. @$(SIZE) -B -x --mcu=$(MCU) $<
  85. $(TARGET).elf: $(SOURCE:.c=.o) | $(LDSCRIPT_NOVECT)
  86. @echo " Linking file: $@"
  87. @$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-T$(LDSCRIPT_NOVECT) -o $@ $^ 2> /dev/null
  88. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  89. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  90. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  91. %.o: %.c $(MAKEFILE_LIST)
  92. @echo " Building file: $<"
  93. @$(CC) $(CFLAGS) -o $@ -c $<
  94. # remove interrupt vector section from avr-libc linker script
  95. # (remove all lines with *vectors* and insert DISCARD line above .text declaration)
  96. $(LDSCRIPT_NOVECT): $(LDSCRIPT) $(MAKEFILE_LIST)
  97. @echo " Creating: $@"
  98. @sed -e '/.*vectors.*/d' -e 's/\(^[ \t]*\)\(.text[ \t]*\:\)$$/\1\/DISCARD\/ : { *(.vectors) }\n\1\2/g' $< > $@
  99. # -@diff -uNr $< $@ > $@.diff
  100. clean:
  101. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin) ldscript-no-vectors-*
  102. install: $(TARGET).elf
  103. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  104. fuses:
  105. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))