1
0

Makefile.mega0 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. # Makefile for AVR Mega-0 (4809), Tiny-0, and Tiny-1 version of Optiboot
  2. # Bill Westfield, 2019
  3. # $Id$
  4. #
  5. # Edit History
  6. # Sep-2019 refactor from the normal AVR Makefile.
  7. # * Copyright 2013-2019 by Bill Westfield. Part of Optiboot.
  8. # * This software is licensed under version 2 of the Gnu Public Licence.
  9. # * See optiboot.c for details.
  10. HELPTEXT = "\n"
  11. #----------------------------------------------------------------------
  12. #
  13. # program name should not be changed...
  14. PROGRAM = optiboot_x
  15. MF:= $(MAKEFILE_LIST)
  16. # defaults
  17. MCU_TARGET = atmega4809
  18. ifdef BIGBOOT
  19. LDSECTIONS = -Wl,-section-start=.text=0 \
  20. -Wl,--section-start=.application=0x400 \
  21. -Wl,--section-start=.version=0x3fe
  22. else
  23. LDSECTIONS = -Wl,-section-start=.text=0 \
  24. -Wl,--section-start=.application=0x200 \
  25. -Wl,--section-start=.version=0x1fe
  26. endif
  27. BAUD_RATE=115200
  28. #AVRGCCROOT =
  29. AVRDUDE_CONF =
  30. # export symbols to recursive makes (for ISP)
  31. export
  32. #
  33. # End of build environment code.
  34. CC = $(AVRGCCROOT)avr-gcc
  35. RCC = $(abspath $(CC))
  36. #$(info wildcard ("$(wildcard $(CC))",""))
  37. ifndef PRODUCTION
  38. $(info Using Compiler at: ${RCC})
  39. endif
  40. # If we have a PACKS directory specified, we should use it...
  41. ifdef PACKS
  42. PACK_OPT= -I "$(PACKS)/include/" -B "$(PACKS)/gcc/dev/$*"
  43. ifndef PRODUCTION
  44. $(info and Chip-defining PACKS at ${PACKS})
  45. endif
  46. endif
  47. OPTIMIZE = -Os -fno-split-wide-types -mrelax
  48. # Override is only needed by avr-lib build system.
  49. override CFLAGS = -g -Wall $(OPTIMIZE)
  50. override LDFLAGS = $(LDSECTIONS) -Wl,--relax -nostartfiles -nostdlib
  51. OBJCOPY = $(AVRGCCROOT)avr-objcopy
  52. OBJDUMP = $(AVRGCCROOT)avr-objdump
  53. SIZE = $(AVRGCCROOT)avr-size
  54. include parse_options.mk
  55. .PRECIOUS: optiboot_%.elf
  56. ifndef PRODUCTION
  57. LISTING= $(OBJDUMP) -S
  58. else
  59. LISTING= @true
  60. endif
  61. #---------------------------------------------------------------------------
  62. # "Chip-level Platform" targets.
  63. # A "Chip-level Platform" compiles for a particular chip, but probably does
  64. # not have "standard" values for things like clock speed, LED pin, etc.
  65. # Makes for chip-level platforms should usually explicitly define their
  66. # options like: "make atmega4809 UARTTX=A4 LED=D0"
  67. #---------------------------------------------------------------------------
  68. #
  69. # Mega0, tiny0, tiny1 don't really have any chip-specific requirements.
  70. #
  71. # Note about fuses:
  72. # The fuses are defined in the source code. There are 9!
  73. # Be sure to use a programmer that will program the fuses from the object file.
  74. #
  75. #---------------------------------------------------------------------------
  76. #
  77. HELPTEXT += "\n-------------\n\n"
  78. optiboot_%.hex: optiboot_%.elf
  79. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@
  80. @echo Bare Bootloader size
  81. $(SIZE) $@
  82. #
  83. # Note that the .application section is not normally copied to the
  84. # .hex file. The .application section is useful for detecting growth
  85. # beyond 512 bytes, and for being a target for starting the
  86. # application, and for referencing certain otherwise-unused variables
  87. # so they aren't optimized away, but all of that happens during
  88. # compilation or link, and the code doesn't need to to actually be
  89. # present in the binary/hex files (where it might interfere with easy
  90. # merging with a real application.)
  91. # (including it in the .application may be useful for debugging, though)
  92. # $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -j .application -O ihex $< $@
  93. optiboot_%.elf: optiboot_x.c FORCE
  94. $(CC) $(CFLAGS) $(CPU_OPTIONS) $(LED_OPTIONS) $(UART_OPTIONS) $(COMMON_OPTIONS) $(LDFLAGS) $(PACK_OPT) -mmcu=$* -o $@ $<
  95. @echo Bootloader size with skeleton App
  96. @$(SIZE) $@
  97. $(LISTING) $@ > optiboot_$*.lst
  98. #---------------------------------------------------------------------------
  99. # "Board-level Platform" targets.
  100. # A "Board-level Platform" implies a manufactured platform with a particular
  101. # AVR_FREQ, LED, and so on. Parameters are not particularly changable from
  102. # the "make" command line.
  103. # Most of the board-level platform builds should envoke make recursively
  104. # appropriate specific options
  105. #---------------------------------------------------------------------------
  106. atmega%:
  107. $(MAKE) -f $(MF) optiboot_atmega$*.hex
  108. attiny%:
  109. $(MAKE) -f $(MF) optiboot_attiny$*.hex
  110. HELPTEXT += "target optiboot_*.hex - Any approriate mega-0, tiny-0, or tiny-1\n"
  111. HELPTEXT += " ie: optiboot_atmega4809\n"
  112. HELPTEXT += "target drazzy402,412 - Dr Azzy's 8pin dev boards.\n"
  113. drazzy%2:
  114. $(MAKE) -f $(MF) optiboot_attiny$*2.hex UARTTX=A1 TIMEOUT=8 LED=A7
  115. HELPTEXT += "target drazzy*4 - Dr Azzy's 14pin dev boards.\n"
  116. drazzy%4:
  117. $(MAKE) -f $(MF) optiboot_attiny$*4.hex UARTTX=B2 TIMEOUT=8 LED=A7
  118. HELPTEXT += "target drazzy*6 - Dr Azzy's 20pin dev boards.\n"
  119. drazzy%6:
  120. $(MAKE) -f $(MF) optiboot_attiny$*6.hex UARTTX=B2 TIMEOUT=8 LED=A7
  121. HELPTEXT += "target drazzy*7 - Dr Azzy's 24pin dev boards.\n"
  122. drazzy%7:
  123. $(MAKE) -f $(MF) optiboot_attiny$*7.hex UARTTX=B2 TIMEOUT=8 LED=A7
  124. HELPTEXT += "target curiosity1607 - Microchip ATtiny1607 Curiosity Nano.\n"
  125. curiosity1607:
  126. $(MAKE) -f $(MF) optiboot_attiny1607.hex UARTTX=B2 TIMEOUT=8 LED=B7 LED_INVERT=1
  127. HELPTEXT += "target curiosity4809 - Microchip ATmega4809 Curiosity Nano.\n"
  128. curiosity4809:
  129. $(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=B0 TIMEOUT=8 LED=F5 LED_INVERT=1
  130. HELPTEXT += "target xplained416 - Microchip ATtiny416 Xplained Nano.\n"
  131. xplained416:
  132. $(MAKE) -f $(MF) optiboot_attiny416.hex UARTTX=A1 TIMEOUT=8 LED=B5 LED_INVERT=1 BAUD_RATE=57600
  133. HELPTEXT += "target xplained817 - Microchip ATtiny817 Xplained Mini.\n"
  134. xplained817:
  135. $(MAKE) -f $(MF) optiboot_attiny817.hex UARTTX=B2 TIMEOUT=8 LED=C0 BAUD_RATE=57600
  136. HELPTEXT += "target xplained4809 - Microchip ATmega4809 Xplained Pro.\n"
  137. xplained4809:
  138. $(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=C0 TIMEOUT=8 LED=B5 LED_INVERT=1 BAUD_RATE=115200
  139. HELPTEXT += "target freeduino4809 - WestfW ATmega4809 Uno-style board.\n"
  140. freeduino4809:
  141. $(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=B4 TIMEOUT=1 LED=D6 RESETPIN=1
  142. HELPTEXT += "target freeduino4809chip - WestfW ATmega4809 40pin DIP boards.\n"
  143. freeduino4809chip:
  144. $(MAKE) -f $(MF) optiboot_atmega4809.hex UARTTX=A4 TIMEOUT=1 LED=A7 RESETPIN=1
  145. #---------------------------------------------------------------------------
  146. #
  147. # Generic build instructions
  148. #
  149. FORCE:
  150. isp: $(TARGET) FORCE
  151. "$(MAKE)" -f Makefile.isp isp TARGET=$(TARGET)
  152. isp-stk500: $(PROGRAM)_$(TARGET).hex
  153. $(STK500-1)
  154. $(STK500-2)
  155. #windows "rm" is dumb and objects to wildcards that don't exist
  156. clean:
  157. @touch __temp_.o __temp_.elf __temp_.lst __temp_.map
  158. @touch __temp_.sym __temp_.lss __temp_.eep __temp_.srec
  159. @touch __temp_.bin __temp_.hex __temp_.tmp.sh
  160. rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.tmp.sh
  161. version:
  162. $(CC) --version | head -1
  163. @grep "define OPTIBOOT_...VER" $(PROGRAM).c
  164. clean_asm:
  165. rm -rf *.lst
  166. %.lst: %.elf FORCE
  167. $(OBJDUMP) -h -S $< > $@
  168. %.srec: %.elf FORCE
  169. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O srec $< $@
  170. %.bin: %.elf FORCE
  171. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O binary $< $@
  172. help:
  173. @echo -e $(HELPTEXT)