atprogram.mk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # DMBS Build System
  3. # Released into the public domain.
  4. #
  5. # dean [at] fourwalledcubicle [dot] com
  6. # www.fourwalledcubicle.com
  7. #
  8. DMBS_BUILD_MODULES += ATPROGRAM
  9. DMBS_BUILD_TARGETS += atprogram atprogram-ee
  10. DMBS_BUILD_MANDATORY_VARS += MCU TARGET
  11. DMBS_BUILD_OPTIONAL_VARS += ATPROGRAM_PROGRAMMER ATPROGRAM_INTERFACE ATPROGRAM_PORT
  12. DMBS_BUILD_PROVIDED_VARS +=
  13. DMBS_BUILD_PROVIDED_MACROS +=
  14. # Conditionally import the CORE module of DMBS if it is not already imported
  15. DMBS_MODULE_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
  16. ifeq ($(findstring CORE, $(DMBS_BUILD_MODULES)),)
  17. include $(DMBS_MODULE_PATH)/core.mk
  18. endif
  19. # Default values of optionally user-supplied variables
  20. ATPROGRAM_PROGRAMMER ?= atmelice
  21. ATPROGRAM_INTERFACE ?= jtag
  22. ATPROGRAM_PORT ?=
  23. # Sanity check user supplied values
  24. $(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
  25. $(call ERROR_IF_EMPTY, MCU)
  26. $(call ERROR_IF_EMPTY, TARGET)
  27. $(call ERROR_IF_EMPTY, ATPROGRAM_PROGRAMMER)
  28. $(call ERROR_IF_EMPTY, ATPROGRAM_INTERFACE)
  29. # Output Messages
  30. MSG_ATPROGRAM_CMD := ' [ATPRGRM] :'
  31. # Construct base atprogram command flags
  32. BASE_ATPROGRAM_FLAGS := --tool $(ATPROGRAM_PROGRAMMER) --interface $(ATPROGRAM_INTERFACE) --device $(MCU)
  33. ifneq ($(ATPROGRAM_PORT),)
  34. BASE_ATPROGRAM_FLAGS += --port $(ATPROGRAM_PORT)
  35. endif
  36. # Construct the flags to use for the various memory spaces
  37. ifeq ($(ARCH), AVR8)
  38. ATPROGRAM_FLASH_FLAGS := --chiperase --flash
  39. ATPROGRAM_EEPROM_FLAGS := --eeprom
  40. else ifeq ($(ARCH), XMEGA)
  41. ATPROGRAM_FLASH_FLAGS := --erase --flash
  42. ATPROGRAM_EEPROM_FLAGS := --eeprom
  43. else ifeq ($(ARCH), UC3)
  44. ATPROGRAM_FLASH_FLAGS := --erase
  45. ATPROGRAM_EEPROM_FLAGS := --eeprom
  46. else
  47. $(error Unsupported architecture "$(ARCH)")
  48. endif
  49. # Programs in the target FLASH memory using ATPROGRAM
  50. atprogram: $(TARGET).elf $(MAKEFILE_LIST)
  51. @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" FLASH using \"$(ATPROGRAM_PROGRAMMER)\"
  52. atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_FLASH_FLAGS) --file $<
  53. # Programs in the target EEPROM memory using ATPROGRAM
  54. atprogram-ee: $(TARGET).elf $(MAKEFILE_LIST)
  55. @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" EEPROM using \"$(ATPROGRAM_PROGRAMMER)\"
  56. atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_EEPROM_FLAGS) --file $<
  57. # Phony build targets for this module
  58. .PHONY: $(DMBS_BUILD_TARGETS)