AVR Bootloader for MK-FlightCtrl
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.2KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = fc_boot
  7. SOURCE = $(wildcard *.c)
  8. # select MCU
  9. MCU = atmega644p
  10. AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ttyUSB0
  11. #AVRDUDE_PROG := -c dragon_isp -P usb
  12. # ---------------------------------------------------------------------------
  13. ifeq ($(MCU), atmega644p)
  14. AVRDUDE_MCU=m644p
  15. # (20MHz ext. Crystal, 2.7V BOD)
  16. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdc:m efuse:w:0xfd:m
  17. BOOTLOADER_START=0xF800
  18. endif
  19. # ---------------------------------------------------------------------------
  20. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall
  21. CFLAGS += -fdata-sections -ffunction-sections
  22. CFLAGS += -Wa,-adhlns=$(*F).lst
  23. CFLAGS += -DBOOTLOADER_START=$(BOOTLOADER_START)
  24. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--section-start=.text=$(BOOTLOADER_START)
  25. LDFLAGS += -Wl,--relax,--gc-sections
  26. LDSCRIPT := $(shell LANG=C $(CC) $(CFLAGS) -Wl,--verbose 2> /dev/null | awk '/^opened script file (.*)$$/{ print $$4 }')
  27. LDSCRIPT_NOVECT := ldscript-no-vectors-$(notdir $(LDSCRIPT))
  28. # ---------------------------------------------------------------------------
  29. $(TARGET): $(TARGET).elf
  30. @$(SIZE) -B -x --mcu=$(MCU) $<
  31. $(TARGET).elf: $(SOURCE:.c=.o) | $(LDSCRIPT_NOVECT)
  32. @echo " Linking file: $@"
  33. @$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-T$(LDSCRIPT_NOVECT) -o $@ $^ 2> /dev/null
  34. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  35. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  36. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  37. %.o: %.c $(MAKEFILE_LIST)
  38. @echo " Building file: $<"
  39. @$(CC) $(CFLAGS) -o $@ -c $<
  40. # remove interrupt vector section from avr-libc linker script
  41. # (remove all lines with *vectors* and insert DISCARD line above .text declaration)
  42. $(LDSCRIPT_NOVECT): $(LDSCRIPT) $(MAKEFILE_LIST)
  43. @echo " Creating: $@"
  44. @sed -e '/.*vectors.*/d' -e 's/\(^[ \t]*\)\(.text[ \t]*\:\)$$/\1\/DISCARD\/ : { *(.vectors) }\n\1\2/g' $< > $@
  45. # -@diff -uNr $< $@ > $@.diff
  46. clean:
  47. rm -rf $(SOURCE:.c=.o) $(SOURCE:.c=.lst) $(addprefix $(TARGET), .elf .map .lss .hex .bin) $(LDSCRIPT_NOVECT)
  48. install: $(TARGET).elf
  49. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  50. fuses:
  51. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))