Debian Codegraph @

bootloaders/optiboot/Makefile

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