extend "spminterface.h" to additional checks on "BOOTLOADER_ADDRESS" (atmega8)
[pub/USBaspLoader.git] / firmware / Makefile
1 # Name: Makefile
2 # Project: USBaspLoader
3 # Author: Christian Starkjohann
4 # Creation Date: 2007-12-10
5 # Author: Stephan Bärwolf
6 # Improvement Date: 2012-07-31
7 # Tabsize: 4
8 # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
9 # License: GNU GPL v2 (see License.txt)
10
11 ###############################################################################
12 # Configure the following variables according to your AVR.
13 # Program the device with
14 # make fuse # to set the clock generator, boot section size etc.
15 # make flash # to load the boot loader into flash
16 # make lock # to protect the boot loader from overwriting
17
18 include ../Makefile.inc
19
20 # Options:
21 DEFINES = #-DDEBUG_LEVEL=2
22 # Remove the -fno-* options when you use gcc 3, it does not understand them
23 CFLAGS = -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -mmcu=$(DEVICE) -DBOOTLOADER_ADDRESS=$(BOOTLOADER_ADDRESS) -DF_CPU=$(F_CPU) $(DEFINES)
24 LDFLAGS = -Wl,--relax,--gc-sections -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
25
26 OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
27
28 # symbolic targets:
29 all: main.hex
30
31 install: main.hex
32 cp -Rvp main.hex ./hexfiles/usbasploader.hex
33
34 .c.o:
35 $(CC) $(CFLAGS) -c $< -o $@
36
37 .S.o:
38 $(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
39 # "-x assembler-with-cpp" should not be necessary since this is the default
40 # file type for the .S (with capital S) extension. However, upper case
41 # characters are not always preserved on Windows. To ensure WinAVR
42 # compatibility define the file type manually.
43
44 .c.s:
45 $(CC) $(CFLAGS) -S $< -o $@
46
47 flash: all
48 $(AVRDUDE) -U flash:w:main.hex:i
49
50 readflash:
51 $(AVRDUDE) -U flash:r:read.hex:i
52
53 fuse:
54 $(AVRDUDE) $(FUSEOPT)
55
56 lock:
57 $(AVRDUDE) $(LOCKOPT)
58
59 read_fuses:
60 $(UISP) --rd_fuses
61
62 deepclean: clean
63 $(RM) *~
64
65 clean:
66 $(RM) main.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
67
68 # file targets:
69 main.bin: $(OBJECTS)
70 $(CC) $(CFLAGS) -o main.bin $(OBJECTS) $(LDFLAGS)
71
72 main.hex: main.bin
73 $(RM) main.hex main.eep.hex
74 $(OBC) -j .text -j .data -O ihex main.bin main.hex
75 $(SIZ) main.bin
76
77 disasm: main.bin
78 $(OBD) -d main.bin
79
80 cpp:
81 $(CC) $(CFLAGS) -E main.c
82
83 # Special rules for generating hex files for various devices and clock speeds
84 ALLHEXFILES = hexfiles/mega8_12mhz.hex hexfiles/mega8_15mhz.hex hexfiles/mega8_16mhz.hex \
85 hexfiles/mega88_12mhz.hex hexfiles/mega88_15mhz.hex hexfiles/mega88_16mhz.hex hexfiles/mega88_20mhz.hex\
86 hexfiles/mega168_12mhz.hex hexfiles/mega168_15mhz.hex hexfiles/mega168_16mhz.hex hexfiles/mega168_20mhz.hex\
87 hexfiles/mega328p_12mhz.hex hexfiles/mega328p_15mhz.hex hexfiles/mega328p_16mhz.hex hexfiles/mega328p_20mhz.hex
88
89 allhexfiles: $(ALLHEXFILES)
90 $(MAKE) clean
91 $(SIZ) hexfiles/*.hex
92
93 $(ALLHEXFILES):
94 @[ -d hexfiles ] || mkdir hexfiles
95 @device=`echo $@ | sed -e 's|.*/mega||g' -e 's|_.*||g'`; \
96 clock=`echo $@ | sed -e 's|.*_||g' -e 's|mhz.*||g'`; \
97 addr=`echo $$device | sed -e 's/\([0-9]\)8/\1/g' | awk '{printf("%x", ($$1 - 2) * 1024)}'`; \
98 echo "### Make with F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr"; \
99 $(MAKE) clean; \
100 $(MAKE) main.hex F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr DEFINES=-DUSE_AUTOCONFIG=1
101 mv main.hex $@