Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. # Makefile for ATmegaBOOT
  2. # E.Lins, 18.7.2005
  3. #
  4. # Instructions
  5. #
  6. # To make bootloader .hex file:
  7. # make diecimila
  8. # make lilypad
  9. # make ng
  10. # etc...
  11. #
  12. # To burn bootloader .hex file:
  13. # make diecimila_isp
  14. # make lilypad_isp
  15. # make ng_isp
  16. # etc...
  17. # program name should not be changed...
  18. PROGRAM = optiboot
  19. # The default behavior is to build using tools that are in the users
  20. # current path variables, but we can also build using an installed
  21. # Arduino user IDE setup, or the Arduino source tree.
  22. # Uncomment this next lines to build within the arduino environment,
  23. # using the arduino-included avrgcc toolset (mac and pc)
  24. # ENV ?= arduino
  25. # ENV ?= arduinodev
  26. # OS ?= macosx
  27. # OS ?= windows
  28. # enter the parameters for the avrdude isp tool
  29. ISPTOOL = stk500v2
  30. ISPPORT = usb
  31. ISPSPEED = -b 115200
  32. MCU_TARGET = atmega168
  33. LDSECTIONS = -Wl,--section-start=.text=0x3e00 -Wl,--section-start=.version=0x3ffe
  34. # Build environments
  35. # Start of some ugly makefile-isms to allow optiboot to be built
  36. # in several different environments. See the README.TXT file for
  37. # details.
  38. # default
  39. fixpath = $(1)
  40. ifeq ($(ENV), arduino)
  41. # For Arduino, we assume that we're connected to the optiboot directory
  42. # included with the arduino distribution, which means that the full set
  43. # of avr-tools are "right up there" in standard places.
  44. TOOLROOT = ../../../tools
  45. GCCROOT = $(TOOLROOT)/avr/bin/
  46. AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
  47. ifeq ($(OS), windows)
  48. # On windows, SOME of the tool paths will need to have backslashes instead
  49. # of forward slashes (because they use windows cmd.exe for execution instead
  50. # of a unix/mingw shell?) We also have to ensure that a consistent shell
  51. # is used even if a unix shell is installed (ie as part of WINAVR)
  52. fixpath = $(subst /,\,$1)
  53. SHELL = cmd.exe
  54. endif
  55. else ifeq ($(ENV), arduinodev)
  56. # Arduino IDE source code environment. Use the unpacked compilers created
  57. # by the build (you'll need to do "ant build" first.)
  58. ifeq ($(OS), macosx)
  59. TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
  60. endif
  61. ifeq ($(OS), windows)
  62. TOOLROOT = ../../../../build/windows/work/hardware/tools
  63. endif
  64. GCCROOT = $(TOOLROOT)/avr/bin/
  65. AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
  66. else
  67. GCCROOT =
  68. AVRDUDE_CONF =
  69. endif
  70. #
  71. # End of build environment code.
  72. # the efuse should really be 0xf8; since, however, only the lower
  73. # three bits of that byte are used on the atmega168, avrdude gets
  74. # confused if you specify 1's for the higher bits, see:
  75. # http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
  76. #
  77. # similarly, the lock bits should be 0xff instead of 0x3f (to
  78. # unlock the bootloader section) and 0xcf instead of 0x2f (to
  79. # lock it), but since the high two bits of the lock byte are
  80. # unused, avrdude would get confused.
  81. ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
  82. -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
  83. -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \
  84. -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
  85. ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
  86. -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
  87. -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x2f:m
  88. STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
  89. STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
  90. -lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
  91. STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
  92. OBJ = $(PROGRAM).o
  93. OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls
  94. DEFS =
  95. LIBS =
  96. CC = $(GCCROOT)avr-gcc
  97. # Override is only needed by avr-lib build system.
  98. override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
  99. override LDFLAGS = $(LDSECTIONS) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib
  100. OBJCOPY = $(GCCROOT)avr-objcopy
  101. OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump)
  102. SIZE = $(GCCROOT)avr-size
  103. # Test platforms
  104. # Virtual boot block test
  105. virboot328: TARGET = atmega328
  106. virboot328: MCU_TARGET = atmega328p
  107. virboot328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DVIRTUAL_BOOT'
  108. virboot328: AVR_FREQ = 16000000L
  109. virboot328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
  110. virboot328: $(PROGRAM)_atmega328.hex
  111. virboot328: $(PROGRAM)_atmega328.lst
  112. # 20MHz clocked platforms
  113. #
  114. # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
  115. #
  116. pro20: TARGET = pro_20mhz
  117. pro20: MCU_TARGET = atmega168
  118. pro20: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  119. pro20: AVR_FREQ = 20000000L
  120. pro20: $(PROGRAM)_pro_20mhz.hex
  121. pro20: $(PROGRAM)_pro_20mhz.lst
  122. pro20_isp: pro20
  123. pro20_isp: TARGET = pro_20mhz
  124. # 2.7V brownout
  125. pro20_isp: HFUSE = DD
  126. # Full swing xtal (20MHz) 258CK/14CK+4.1ms
  127. pro20_isp: LFUSE = C6
  128. # 512 byte boot
  129. pro20_isp: EFUSE = 04
  130. pro20_isp: isp
  131. # 16MHz clocked platforms
  132. #
  133. # These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
  134. #
  135. pro16: TARGET = pro_16MHz
  136. pro16: MCU_TARGET = atmega168
  137. pro16: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  138. pro16: AVR_FREQ = 16000000L
  139. pro16: $(PROGRAM)_pro_16MHz.hex
  140. pro16: $(PROGRAM)_pro_16MHz.lst
  141. pro16_isp: pro16
  142. pro16_isp: TARGET = pro_16MHz
  143. # 2.7V brownout
  144. pro16_isp: HFUSE = DD
  145. # Full swing xtal (20MHz) 258CK/14CK+4.1ms
  146. pro16_isp: LFUSE = C6
  147. # 512 byte boot
  148. pro16_isp: EFUSE = 04
  149. pro16_isp: isp
  150. # Diecimila, Duemilanove with m168, and NG use identical bootloaders
  151. # Call it "atmega168" for generality and clarity, keep "diecimila" for
  152. # backward compatibility of makefile
  153. #
  154. atmega168: TARGET = atmega168
  155. atmega168: MCU_TARGET = atmega168
  156. atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  157. atmega168: AVR_FREQ = 16000000L
  158. atmega168: $(PROGRAM)_atmega168.hex
  159. atmega168: $(PROGRAM)_atmega168.lst
  160. atmega168_isp: atmega168
  161. atmega168_isp: TARGET = atmega168
  162. # 2.7V brownout
  163. atmega168_isp: HFUSE = DD
  164. # Low power xtal (16MHz) 16KCK/14CK+65ms
  165. atmega168_isp: LFUSE = FF
  166. # 512 byte boot
  167. atmega168_isp: EFUSE = 04
  168. atmega168_isp: isp
  169. diecimila: TARGET = diecimila
  170. diecimila: MCU_TARGET = atmega168
  171. diecimila: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  172. diecimila: AVR_FREQ = 16000000L
  173. diecimila: $(PROGRAM)_diecimila.hex
  174. diecimila: $(PROGRAM)_diecimila.lst
  175. diecimila_isp: diecimila
  176. diecimila_isp: TARGET = diecimila
  177. # 2.7V brownout
  178. diecimila_isp: HFUSE = DD
  179. # Low power xtal (16MHz) 16KCK/14CK+65ms
  180. diecimila_isp: LFUSE = FF
  181. # 512 byte boot
  182. diecimila_isp: EFUSE = 04
  183. diecimila_isp: isp
  184. atmega328: TARGET = atmega328
  185. atmega328: MCU_TARGET = atmega328p
  186. atmega328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  187. atmega328: AVR_FREQ = 16000000L
  188. atmega328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
  189. atmega328: $(PROGRAM)_atmega328.hex
  190. atmega328: $(PROGRAM)_atmega328.lst
  191. atmega328_isp: atmega328
  192. atmega328_isp: TARGET = atmega328
  193. atmega328_isp: MCU_TARGET = atmega328p
  194. # 512 byte boot, SPIEN
  195. atmega328_isp: HFUSE = DE
  196. # Low power xtal (16MHz) 16KCK/14CK+65ms
  197. atmega328_isp: LFUSE = FF
  198. # 2.7V brownout
  199. atmega328_isp: EFUSE = 05
  200. atmega328_isp: isp
  201. # Sanguino has a minimum boot size of 1024 bytes, so enable extra functions
  202. #
  203. sanguino: TARGET = atmega644p
  204. sanguino: MCU_TARGET = atmega644p
  205. sanguino: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
  206. sanguino: AVR_FREQ = 16000000L
  207. sanguino: LDSECTIONS = -Wl,--section-start=.text=0xfc00
  208. sanguino: $(PROGRAM)_atmega644p.hex
  209. sanguino: $(PROGRAM)_atmega644p.lst
  210. sanguino_isp: sanguino
  211. sanguino_isp: TARGET = atmega644p
  212. sanguino_isp: MCU_TARGET = atmega644p
  213. # 1024 byte boot
  214. sanguino_isp: HFUSE = DE
  215. # Low power xtal (16MHz) 16KCK/14CK+65ms
  216. sanguino_isp: LFUSE = FF
  217. # 2.7V brownout
  218. sanguino_isp: EFUSE = 05
  219. sanguino_isp: isp
  220. # Mega has a minimum boot size of 1024 bytes, so enable extra functions
  221. #mega: TARGET = atmega1280
  222. mega: MCU_TARGET = atmega1280
  223. mega: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
  224. mega: AVR_FREQ = 16000000L
  225. mega: LDSECTIONS = -Wl,--section-start=.text=0x1fc00
  226. mega: $(PROGRAM)_atmega1280.hex
  227. mega: $(PROGRAM)_atmega1280.lst
  228. mega_isp: mega
  229. mega_isp: TARGET = atmega1280
  230. mega_isp: MCU_TARGET = atmega1280
  231. # 1024 byte boot
  232. mega_isp: HFUSE = DE
  233. # Low power xtal (16MHz) 16KCK/14CK+65ms
  234. mega_isp: LFUSE = FF
  235. # 2.7V brownout
  236. mega_isp: EFUSE = 05
  237. mega_isp: isp
  238. # ATmega8
  239. #
  240. atmega8: TARGET = atmega8
  241. atmega8: MCU_TARGET = atmega8
  242. atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  243. atmega8: AVR_FREQ = 16000000L
  244. atmega8: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
  245. atmega8: $(PROGRAM)_atmega8.hex
  246. atmega8: $(PROGRAM)_atmega8.lst
  247. atmega8_isp: atmega8
  248. atmega8_isp: TARGET = atmega8
  249. atmega8_isp: MCU_TARGET = atmega8
  250. # SPIEN, CKOPT, Bootsize=512B
  251. atmega8_isp: HFUSE = CC
  252. # 2.7V brownout, Low power xtal (16MHz) 16KCK/14CK+65ms
  253. atmega8_isp: LFUSE = BF
  254. atmega8_isp: isp
  255. # ATmega88
  256. #
  257. atmega88: TARGET = atmega88
  258. atmega88: MCU_TARGET = atmega88
  259. atmega88: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  260. atmega88: AVR_FREQ = 16000000L
  261. atmega88: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
  262. atmega88: $(PROGRAM)_atmega88.hex
  263. atmega88: $(PROGRAM)_atmega88.lst
  264. atmega88_isp: atmega88
  265. atmega88_isp: TARGET = atmega88
  266. atmega88_isp: MCU_TARGET = atmega88
  267. # 2.7V brownout
  268. atmega88_isp: HFUSE = DD
  269. # Low power xtal (16MHz) 16KCK/14CK+65ms
  270. atemga88_isp: LFUSE = FF
  271. # 512 byte boot
  272. atmega88_isp: EFUSE = 04
  273. atmega88_isp: isp
  274. # 8MHz clocked platforms
  275. #
  276. # These are capable of 115200 baud
  277. #
  278. lilypad: TARGET = lilypad
  279. lilypad: MCU_TARGET = atmega168
  280. lilypad: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  281. lilypad: AVR_FREQ = 8000000L
  282. lilypad: $(PROGRAM)_lilypad.hex
  283. lilypad: $(PROGRAM)_lilypad.lst
  284. lilypad_isp: lilypad
  285. lilypad_isp: TARGET = lilypad
  286. # 2.7V brownout
  287. lilypad_isp: HFUSE = DD
  288. # Internal 8MHz osc (8MHz) Slow rising power
  289. lilypad_isp: LFUSE = E2
  290. # 512 byte boot
  291. lilypad_isp: EFUSE = 04
  292. lilypad_isp: isp
  293. lilypad_resonator: TARGET = lilypad_resonator
  294. lilypad_resonator: MCU_TARGET = atmega168
  295. lilypad_resonator: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  296. lilypad_resonator: AVR_FREQ = 8000000L
  297. lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
  298. lilypad_resonator: $(PROGRAM)_lilypad_resonator.lst
  299. lilypad_resonator_isp: lilypad_resonator
  300. lilypad_resonator_isp: TARGET = lilypad_resonator
  301. # 2.7V brownout
  302. lilypad_resonator_isp: HFUSE = DD
  303. # Full swing xtal (20MHz) 258CK/14CK+4.1ms
  304. lilypad_resonator_isp: LFUSE = C6
  305. # 512 byte boot
  306. lilypad_resonator_isp: EFUSE = 04
  307. lilypad_resonator_isp: isp
  308. pro8: TARGET = pro_8MHz
  309. pro8: MCU_TARGET = atmega168
  310. pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  311. pro8: AVR_FREQ = 8000000L
  312. pro8: $(PROGRAM)_pro_8MHz.hex
  313. pro8: $(PROGRAM)_pro_8MHz.lst
  314. pro8_isp: pro8
  315. pro8_isp: TARGET = pro_8MHz
  316. # 2.7V brownout
  317. pro8_isp: HFUSE = DD
  318. # Full swing xtal (20MHz) 258CK/14CK+4.1ms
  319. pro8_isp: LFUSE = C6
  320. # 512 byte boot
  321. pro8_isp: EFUSE = 04
  322. pro8_isp: isp
  323. atmega328_pro8: TARGET = atmega328_pro_8MHz
  324. atmega328_pro8: MCU_TARGET = atmega328p
  325. atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
  326. atmega328_pro8: AVR_FREQ = 8000000L
  327. atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
  328. atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
  329. atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.lst
  330. atmega328_pro8_isp: atmega328_pro8
  331. atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
  332. atmega328_pro8_isp: MCU_TARGET = atmega328p
  333. # 512 byte boot, SPIEN
  334. atmega328_pro8_isp: HFUSE = DE
  335. # Low power xtal (16MHz) 16KCK/14CK+65ms
  336. atmega328_pro8_isp: LFUSE = FF
  337. # 2.7V brownout
  338. atmega328_pro8_isp: EFUSE = 05
  339. atmega328_pro8_isp: isp
  340. # 1MHz clocked platforms
  341. #
  342. # These are capable of 9600 baud
  343. #
  344. luminet: TARGET = luminet
  345. luminet: MCU_TARGET = attiny84
  346. luminet: CFLAGS += '-DLED_START_FLASHES=3' '-DSOFT_UART' '-DBAUD_RATE=9600'
  347. luminet: CFLAGS += '-DVIRTUAL_BOOT_PARTITION'
  348. luminet: AVR_FREQ = 1000000L
  349. luminet: LDSECTIONS = -Wl,--section-start=.text=0x1d00 -Wl,--section-start=.version=0x1efe
  350. luminet: $(PROGRAM)_luminet.hex
  351. luminet: $(PROGRAM)_luminet.lst
  352. luminet_isp: luminet
  353. luminet_isp: TARGET = luminet
  354. luminet_isp: MCU_TARGET = attiny84
  355. # Brownout disabled
  356. luminet_isp: HFUSE = DF
  357. # 1MHz internal oscillator, slowly rising power
  358. luminet_isp: LFUSE = 62
  359. # Self-programming enable
  360. luminet_isp: EFUSE = FE
  361. luminet_isp: isp
  362. #
  363. # Generic build instructions
  364. #
  365. #
  366. isp: $(TARGET)
  367. $(ISPFUSES)
  368. $(ISPFLASH)
  369. isp-stk500: $(PROGRAM)_$(TARGET).hex
  370. $(STK500-1)
  371. $(STK500-2)
  372. %.elf: $(OBJ)
  373. $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
  374. $(SIZE) $@
  375. clean:
  376. rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
  377. %.lst: %.elf
  378. $(OBJDUMP) -h -S $< > $@
  379. %.hex: %.elf
  380. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@
  381. %.srec: %.elf
  382. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O srec $< $@
  383. %.bin: %.elf
  384. $(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O binary $< $@