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.
 
 

61 lines
1.8 KiB

  1. CC := avr-gcc
  2. LD := avr-ld
  3. OBJCOPY := avr-objcopy
  4. OBJDUMP := avr-objdump
  5. SIZE := avr-size
  6. TARGET = funkboot
  7. SOURCE = $(wildcard *.c)
  8. BUILD_DIR = build
  9. CONFIG = funkstuff168
  10. AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ispprog
  11. #AVRDUDE_PROG := -c dragon_isp -P usb
  12. # ---------------------------------------------------------------------------
  13. ifeq ($(CONFIG), funkstuff168)
  14. # (ext. crystal 16MHz, 2.7V BOD)
  15. MCU = atmega168
  16. AVRDUDE_MCU=m168 -F
  17. AVRDUDE_FUSES=lfuse:w:0xff:m hfuse:w:0xdd:m efuse:w:0x00:m
  18. BOOTLOADER_START=0x3800
  19. endif
  20. # ---------------------------------------------------------------------------
  21. CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections
  22. CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d
  23. CFLAGS += -DBOOTLOADER_START=$(BOOTLOADER_START) -DCONFIG_$(CONFIG)=1
  24. LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections,--section-start=.text=$(BOOTLOADER_START)
  25. # ---------------------------------------------------------------------------
  26. $(TARGET): $(BUILD_DIR)/$(TARGET).elf
  27. @$(SIZE) -B -x --mcu=$(MCU) $<
  28. $(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o))
  29. @echo " Linking file: $@"
  30. @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
  31. @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss)
  32. @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex)
  33. @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin)
  34. $(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST)
  35. @echo " Building file: $<"
  36. @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D))
  37. @$(CC) $(CFLAGS) -o $@ -c $<
  38. include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)
  39. clean:
  40. rm -rf $(BUILD_DIR)
  41. install: $(BUILD_DIR)/$(TARGET).elf
  42. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex)
  43. fuses:
  44. avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES))