logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

platform.mk (8848B)


  1. # Hey Emacs, this is a -*- makefile -*-
  2. ##############################################################################
  3. # Compiler settings
  4. #
  5. CC = $(CC_PREFIX) avr-gcc
  6. OBJCOPY = avr-objcopy
  7. OBJDUMP = avr-objdump
  8. SIZE = avr-size
  9. AR = avr-ar
  10. NM = avr-nm
  11. HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature
  12. EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT)
  13. BIN =
  14. COMPILEFLAGS += $(call cc-option,--param=min-pagesize=0)
  15. # Fix ICE's: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116389
  16. COMPILEFLAGS += $(call cc-option,-mlra)
  17. COMPILEFLAGS += -funsigned-char
  18. COMPILEFLAGS += -funsigned-bitfields
  19. COMPILEFLAGS += -ffunction-sections
  20. COMPILEFLAGS += -fdata-sections
  21. COMPILEFLAGS += -fpack-struct
  22. COMPILEFLAGS += -fshort-enums
  23. COMPILEFLAGS += -mcall-prologues
  24. COMPILEFLAGS += -fno-builtin-printf
  25. # On older compilers, linker relaxation is only possible if link time optimizations are not enabled.
  26. ifeq ($(strip $(LTO_ENABLE)), no)
  27. COMPILEFLAGS += -mrelax
  28. else
  29. # Newer compilers may support both, so quickly check before adding `-mrelax`.
  30. COMPILEFLAGS += $(call cc-option,-mrelax,,-flto=auto)
  31. endif
  32. ASFLAGS += $(AVR_ASFLAGS)
  33. CFLAGS += $(COMPILEFLAGS) $(AVR_CFLAGS)
  34. CFLAGS += -fno-inline-small-functions
  35. CFLAGS += -fno-strict-aliasing
  36. CXXFLAGS += $(COMPILEFLAGS)
  37. CXXFLAGS += -fno-exceptions $(CXXSTANDARD)
  38. LDFLAGS += -Wl,--gc-sections
  39. # Use AVR's libc minimal printf implementation which has less features
  40. # and thus can shave ~400 bytes. Usually we use the xprintf
  41. # implementation but keyboards that use s(n)printf automatically
  42. # pull in the AVR libc implementation, which is ~900 bytes heavy.
  43. AVR_USE_MINIMAL_PRINTF ?= no
  44. ifeq ($(strip $(AVR_USE_MINIMAL_PRINTF)), yes)
  45. LDFLAGS += -Wl,--whole-archive -lprintf_min -Wl,--no-whole-archive
  46. endif
  47. OPT_DEFS += -DF_CPU=$(F_CPU)UL
  48. MCUFLAGS = -mmcu=$(MCU)
  49. # List any extra directories to look for libraries here.
  50. # Each directory must be seperated by a space.
  51. # Use forward slashes for directory separators.
  52. # For a directory that has spaces, enclose it in quotes.
  53. EXTRALIBDIRS =
  54. #---------------- External Memory Options ----------------
  55. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  56. # used for variables (.data/.bss) and heap (malloc()).
  57. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  58. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  59. # only used for heap (malloc()).
  60. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  61. EXTMEMOPTS =
  62. #---------------- Debugging Options ----------------
  63. # Debugging format.
  64. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  65. # AVR Studio 4.10 requires dwarf-2.
  66. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  67. DEBUG = dwarf-2
  68. # For simulavr only - target MCU frequency.
  69. DEBUG_MFREQ = $(F_CPU)
  70. # Set the DEBUG_UI to either gdb or insight.
  71. # DEBUG_UI = gdb
  72. DEBUG_UI = insight
  73. # Set the debugging back-end to either avarice, simulavr.
  74. DEBUG_BACKEND = avarice
  75. #DEBUG_BACKEND = simulavr
  76. # GDB Init Filename.
  77. GDBINIT_FILE = __avr_gdbinit
  78. # When using avarice settings for the JTAG
  79. JTAG_DEV = /dev/com1
  80. # Debugging port used to communicate between GDB / avarice / simulavr.
  81. DEBUG_PORT = 4242
  82. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  83. # just set to localhost unless doing some sort of crazy debugging when
  84. # avarice is running on a different computer.
  85. DEBUG_HOST = localhost
  86. #============================================================================
  87. SIZE_MARGIN = 1024
  88. check-size:
  89. $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | $(SED) -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
  90. $(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi))
  91. $(eval FREE_SIZE=$(shell expr $(MAX_SIZE) - $(CURRENT_SIZE)))
  92. $(eval OVER_SIZE=$(shell expr $(CURRENT_SIZE) - $(MAX_SIZE)))
  93. $(eval PERCENT_SIZE=$(shell expr $(CURRENT_SIZE) \* 100 / $(MAX_SIZE)))
  94. if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \
  95. $(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \
  96. if [ $(CURRENT_SIZE) -gt $(MAX_SIZE) ]; then \
  97. $(REMOVE) $(TARGET).$(FIRMWARE_FORMAT); \
  98. $(REMOVE) $(BUILD_DIR)/$(TARGET).{hex,bin,uf2}; \
  99. printf "\n * $(MSG_FILE_TOO_BIG)"; $(PRINT_ERROR_PLAIN); \
  100. else \
  101. if [ $(FREE_SIZE) -lt $(SIZE_MARGIN) ]; then \
  102. $(PRINT_WARNING_PLAIN); printf " * $(MSG_FILE_NEAR_LIMIT)"; \
  103. else \
  104. $(PRINT_OK); $(SILENT) || printf " * $(MSG_FILE_JUST_RIGHT)"; \
  105. fi ; \
  106. fi ; \
  107. fi
  108. # Convert hex to bin.
  109. bin: $(BUILD_DIR)/$(TARGET).hex
  110. ifeq ($(BOOTLOADER),lufa-ms)
  111. $(eval BIN_PADDING=$(shell n=`expr 32768 - $(BOOTLOADER_SIZE)` && echo $$(($$n)) || echo 0))
  112. $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin --pad-to $(BIN_PADDING)
  113. else
  114. $(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  115. endif
  116. $(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
  117. # copy bin to FLASH.bin
  118. flashbin: bin
  119. $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin;
  120. # Generate avr-gdb config/init file which does the following:
  121. # define the reset signal, load the target file, connect to target, and set
  122. # a breakpoint at main().
  123. gdb-config:
  124. @$(REMOVE) $(GDBINIT_FILE)
  125. @echo define reset >> $(GDBINIT_FILE)
  126. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  127. @echo end >> $(GDBINIT_FILE)
  128. @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
  129. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  130. ifeq ($(DEBUG_BACKEND),simulavr)
  131. @echo load >> $(GDBINIT_FILE)
  132. endif
  133. @echo break main >> $(GDBINIT_FILE)
  134. debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
  135. ifeq ($(DEBUG_BACKEND), avarice)
  136. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  137. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  138. $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  139. @$(WINSHELL) /c pause
  140. else
  141. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  142. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  143. endif
  144. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  145. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  146. COFFCONVERT = $(OBJCOPY) --debugging
  147. COFFCONVERT += --change-section-address .data-0x800000
  148. COFFCONVERT += --change-section-address .bss-0x800000
  149. COFFCONVERT += --change-section-address .noinit-0x800000
  150. COFFCONVERT += --change-section-address .eeprom-0x810000
  151. coff: $(BUILD_DIR)/$(TARGET).elf
  152. @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
  153. $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
  154. extcoff: $(BUILD_DIR)/$(TARGET).elf
  155. @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
  156. $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
  157. ifeq ($(strip $(BOOTLOADER)), qmk-dfu)
  158. QMK_BOOTLOADER_TYPE = DFU
  159. else ifeq ($(strip $(BOOTLOADER)), qmk-hid)
  160. QMK_BOOTLOADER_TYPE = HID
  161. endif
  162. bootloader: cpfirmware
  163. ifeq ($(strip $(QMK_BOOTLOADER_TYPE)),)
  164. $(call CATASTROPHIC_ERROR,Invalid BOOTLOADER,Please set BOOTLOADER to "qmk-dfu" or "qmk-hid" first!)
  165. else
  166. make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ clean TARGET=Bootloader$(QMK_BOOTLOADER_TYPE)
  167. $(QMK_BIN) generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Keyboard.h
  168. $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) -D__ASSEMBLER__ $(CFLAGS) $(OPT_DEFS) platforms/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
  169. $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0))
  170. $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0))
  171. $(eval FLASH_SIZE_KB=$(shell n=`expr $(PROGRAM_SIZE_KB) + $(BOOT_SECTION_SIZE_KB)` && echo $$(($$n)) || echo 0))
  172. make -C lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/ MCU=$(MCU) ARCH=$(ARCH) F_CPU=$(F_CPU) FLASH_SIZE_KB=$(FLASH_SIZE_KB) BOOT_SECTION_SIZE_KB=$(BOOT_SECTION_SIZE_KB) TARGET=Bootloader$(QMK_BOOTLOADER_TYPE)
  173. printf "Bootloader$(QMK_BOOTLOADER_TYPE).hex copied to $(TARGET)_bootloader.hex\n"
  174. cp lib/lufa/Bootloaders/$(QMK_BOOTLOADER_TYPE)/Bootloader$(QMK_BOOTLOADER_TYPE).hex $(TARGET)_bootloader.hex
  175. endif
  176. production: $(BUILD_DIR)/$(TARGET).hex bootloader cpfirmware
  177. @cat $(BUILD_DIR)/$(TARGET).hex | awk '/^:00000001FF/ == 0' > $(TARGET)_production.hex
  178. @cat $(TARGET)_bootloader.hex >> $(TARGET)_production.hex
  179. echo "File sizes:"
  180. $(SIZE) $(TARGET).hex $(TARGET)_bootloader.hex $(TARGET)_production.hex