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...
19PROGRAM    = ATmegaBOOT_168
20
21# enter the parameters for the avrdude isp tool
22ISPTOOL	   = stk500v2
23ISPPORT	   = usb
24ISPSPEED   = -b 115200
25
26MCU_TARGET = atmega168
27LDSECTION  = --section-start=.text=0x3800
28
29# the efuse should really be 0xf8; since, however, only the lower
30# three bits of that byte are used on the atmega168, avrdude gets
31# confused if you specify 1's for the higher bits, see:
32# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
33#
34# similarly, the lock bits should be 0xff instead of 0x3f (to
35# unlock the bootloader section) and 0xcf instead of 0x0f (to
36# lock it), but since the high two bits of the lock byte are
37# unused, avrdude would get confused.
38
39ISPFUSES    = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
40-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
41ISPFLASH    = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
42-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
43
44STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
45STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
46-lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
47STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
48
49
50OBJ        = $(PROGRAM).o
51OPTIMIZE   = -O2
52
53DEFS       =
54LIBS       =
55
56CC         = avr-gcc
57
58# Override is only needed by avr-lib build system.
59
60override CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
61override LDFLAGS       = -Wl,$(LDSECTION)
62#override LDFLAGS       = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
63
64OBJCOPY        = avr-objcopy
65OBJDUMP        = avr-objdump
66
67all:
68
69atmega328_bt: TARGET = atmega328_bt
70atmega328_bt: MCU_TARGET = atmega328p
71atmega328_bt: AVR_FREQ = 16000000L
72atmega328_bt: LDSECTION  = --section-start=.text=0x7000
73atmega328_bt: $(PROGRAM)_atmega328_bt.hex
74
75atmega328_bt_isp: atmega328_bt
76atmega328_bt_isp: TARGET = atmega328_bt
77atmega328_bt_isp: MCU_TARGET = atmega328p
78atmega328_bt_isp: HFUSE = D8
79atmega328_bt_isp: LFUSE = FF
80atmega328_bt_isp: EFUSE = 05
81atmega328_bt_isp: isp
82
83isp: $(TARGET)
84	$(ISPFUSES)
85	$(ISPFLASH)
86
87isp-stk500: $(PROGRAM)_$(TARGET).hex
88	$(STK500-1)
89	$(STK500-2)
90
91%.elf: $(OBJ)
92	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
93
94clean:
95	rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
96
97%.lst: %.elf
98	$(OBJDUMP) -h -S $< > $@
99
100%.hex: %.elf
101	$(OBJCOPY) -j .text -j .data -O ihex $< $@
102
103%.srec: %.elf
104	$(OBJCOPY) -j .text -j .data -O srec $< $@
105
106%.bin: %.elf
107	$(OBJCOPY) -j .text -j .data -O binary $< $@
108
109