root / trunk / toolbox / bootloader / Makefile @ 154
History | View | Annotate | Download (13.8 KB)
1 |
# Hey Emacs, this is a -*- makefile -*- |
---|---|
2 |
#---------------------------------------------------------------------------- |
3 |
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al. |
4 |
# |
5 |
# Released to the Public Domain |
6 |
# |
7 |
# Additional material for this makefile was written by: |
8 |
# Peter Fleury |
9 |
# Tim Henigan |
10 |
# Colin O'Flynn |
11 |
# Reiner Patommel |
12 |
# Markus Pfaff |
13 |
# Sander Pool |
14 |
# Frederik Rouleau |
15 |
# |
16 |
#---------------------------------------------------------------------------- |
17 |
# On command line: |
18 |
# |
19 |
# make all = Make software. |
20 |
# |
21 |
# make clean = Clean out built project files. |
22 |
# |
23 |
# make coff = Convert ELF to AVR COFF. |
24 |
# |
25 |
# make extcoff = Convert ELF to AVR Extended COFF. |
26 |
# |
27 |
# make program = Download the hex file to the device, using avrdude. |
28 |
# Please customize the avrdude settings below first! |
29 |
# |
30 |
# make debug = Start either simulavr or avarice as specified for debugging, |
31 |
# with avr-gdb or avr-insight as the front end for debugging. |
32 |
# |
33 |
# make filename.s = Just compile filename.c into the assembler code only. |
34 |
# |
35 |
# make filename.i = Create a preprocessed source file for use in submitting |
36 |
# bug reports to the GCC project. |
37 |
# |
38 |
# To rebuild project do "make clean" then "make all". |
39 |
#---------------------------------------------------------------------------- |
40 |
|
41 |
|
42 |
# MCU name |
43 |
MCU = attiny2313 |
44 |
|
45 |
# Processor frequency. |
46 |
# This will define a symbol, F_CPU, in all source code files equal to the |
47 |
# processor frequency. You can then use this symbol in your source code to |
48 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
49 |
# automatically to create a 32-bit value in your source code. |
50 |
F_CPU = 8000000 |
51 |
|
52 |
|
53 |
# Output format. (can be srec, ihex, binary) |
54 |
FORMAT = ihex |
55 |
|
56 |
# Target file name (without extension). |
57 |
TARGET = bootloader |
58 |
|
59 |
# List C source files here. (C dependencies are automatically generated.) |
60 |
SRC = $(wildcard *.c) |
61 |
|
62 |
# List Assembler source files here. |
63 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
64 |
# will not be considered source files but generated files (assembler |
65 |
# output from the compiler), and will be deleted upon "make clean"! |
66 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
67 |
# it will preserve the spelling of the filenames, and gcc itself does |
68 |
# care about how the name is spelled on its command-line. |
69 |
ASRC = |
70 |
|
71 |
|
72 |
# Optimization level, can be [0, 1, 2, 3, s]. |
73 |
# 0 = turn off optimization. s = optimize for size. |
74 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
75 |
OPT = s |
76 |
|
77 |
|
78 |
# Debugging format. |
79 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
80 |
# AVR Studio 4.10 requires dwarf-2. |
81 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
82 |
DEBUG = |
83 |
|
84 |
|
85 |
# List any extra directories to look for include files here. |
86 |
# Each directory must be seperated by a space. |
87 |
# Use forward slashes for directory separators. |
88 |
# For a directory that has spaces, enclose it in quotes. |
89 |
#EXTRAINCDIRS = C:\WinAVR\include\fwr |
90 |
|
91 |
|
92 |
# Compiler flag to set the C Standard level. |
93 |
# c89 = "ANSI" C |
94 |
# gnu89 = c89 plus GCC extensions |
95 |
# c99 = ISO C99 standard (not yet fully implemented) |
96 |
# gnu99 = c99 plus GCC extensions |
97 |
CSTANDARD = -std=gnu99 |
98 |
|
99 |
|
100 |
# Place -D or -U options here |
101 |
CDEFS = -DF_CPU=$(F_CPU)UL |
102 |
|
103 |
|
104 |
# Place -I options here |
105 |
CINCS = |
106 |
|
107 |
|
108 |
|
109 |
#---------------- Compiler Options ---------------- |
110 |
# -g*: generate debugging information |
111 |
# -O*: optimization level |
112 |
# -f...: tuning, see GCC manual and avr-libc documentation |
113 |
# -Wall...: warning level |
114 |
# -Wa,...: tell GCC to pass this to the assembler. |
115 |
# -adhlns...: create assembler listing |
116 |
#CFLAGS = -g$(DEBUG) |
117 |
CFLAGS += $(CDEFS) $(CINCS) |
118 |
CFLAGS += -O$(OPT) |
119 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
120 |
CFLAGS += -Wall -Wstrict-prototypes |
121 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
122 |
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
123 |
CFLAGS += $(CSTANDARD) |
124 |
|
125 |
|
126 |
#---------------- Assembler Options ---------------- |
127 |
# -Wa,...: tell GCC to pass this to the assembler. |
128 |
# -ahlms: create listing |
129 |
# -gstabs: have the assembler create line number information; note that |
130 |
# for use in COFF files, additional information about filenames |
131 |
# and function names needs to be present in the assembler source |
132 |
# files -- see avr-libc docs [FIXME: not yet described there] |
133 |
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs |
134 |
|
135 |
|
136 |
#---------------- Library Options ---------------- |
137 |
# Minimalistic printf version |
138 |
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min |
139 |
|
140 |
# Floating point printf version (requires MATH_LIB = -lm below) |
141 |
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt |
142 |
|
143 |
# If this is left blank, then it will use the Standard printf version. |
144 |
PRINTF_LIB = |
145 |
#PRINTF_LIB = $(PRINTF_LIB_MIN) |
146 |
#PRINTF_LIB = $(PRINTF_LIB_FLOAT) |
147 |
|
148 |
|
149 |
# Minimalistic scanf version |
150 |
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min |
151 |
|
152 |
# Floating point + %[ scanf version (requires MATH_LIB = -lm below) |
153 |
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt |
154 |
|
155 |
# If this is left blank, then it will use the Standard scanf version. |
156 |
SCANF_LIB = |
157 |
#SCANF_LIB = $(SCANF_LIB_MIN) |
158 |
#SCANF_LIB = $(SCANF_LIB_FLOAT) |
159 |
|
160 |
|
161 |
MATH_LIB = -lm |
162 |
|
163 |
|
164 |
|
165 |
#---------------- External Memory Options ---------------- |
166 |
|
167 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
168 |
# used for variables (.data/.bss) and heap (malloc()). |
169 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
170 |
|
171 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
172 |
# only used for heap (malloc()). |
173 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
174 |
|
175 |
EXTMEMOPTS = |
176 |
|
177 |
|
178 |
|
179 |
#---------------- Linker Options ---------------- |
180 |
# -Wl,...: tell GCC to pass this to linker. |
181 |
# -Map: create map file |
182 |
# --cref: add cross reference to map file |
183 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
184 |
LDFLAGS += $(EXTMEMOPTS) |
185 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
186 |
|
187 |
|
188 |
|
189 |
#---------------- Programming Options (avrdude) ---------------- |
190 |
|
191 |
# Programming hardware: alf avr910 avrisp bascom bsd |
192 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
193 |
# |
194 |
# Type: avrdude -c ? |
195 |
# to get a full listing. |
196 |
# |
197 |
AVRDUDE_PROGRAMMER = avrispmkII |
198 |
|
199 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
200 |
AVRDUDE_PORT = usb |
201 |
# programmer connected to serial device |
202 |
|
203 |
AVRDUDE_WRITE_FLASH = -b 4800 -U flash:w:$(TARGET).hex |
204 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
205 |
|
206 |
|
207 |
# Uncomment the following if you want avrdude's erase cycle counter. |
208 |
# Note that this counter needs to be initialized first using -Yn, |
209 |
# see avrdude manual. |
210 |
#AVRDUDE_ERASE_COUNTER = -y |
211 |
|
212 |
# Uncomment the following if you do /not/ wish a verification to be |
213 |
# performed after programming the device. |
214 |
#AVRDUDE_NO_VERIFY = -V |
215 |
|
216 |
# Increase verbosity level. Please use this when submitting bug |
217 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
218 |
# to submit bug reports. |
219 |
#AVRDUDE_VERBOSE = -v -v |
220 |
|
221 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
222 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
223 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
224 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
225 |
|
226 |
|
227 |
|
228 |
#---------------- Debugging Options ---------------- |
229 |
|
230 |
# For simulavr only - target MCU frequency. |
231 |
DEBUG_MFREQ = $(F_CPU) |
232 |
|
233 |
# Set the DEBUG_UI to either gdb or insight. |
234 |
# DEBUG_UI = gdb |
235 |
DEBUG_UI = insight |
236 |
|
237 |
# Set the debugging back-end to either avarice, simulavr. |
238 |
DEBUG_BACKEND = avarice |
239 |
#DEBUG_BACKEND = simulavr |
240 |
|
241 |
# GDB Init Filename. |
242 |
GDBINIT_FILE = __avr_gdbinit |
243 |
|
244 |
# When using avarice settings for the JTAG |
245 |
JTAG_DEV = /dev/com1 |
246 |
|
247 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
248 |
DEBUG_PORT = 4242 |
249 |
|
250 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
251 |
# just set to localhost unless doing some sort of crazy debugging when |
252 |
# avarice is running on a different computer. |
253 |
DEBUG_HOST = localhost |
254 |
|
255 |
|
256 |
|
257 |
#============================================================================ |
258 |
|
259 |
|
260 |
# Define programs and commands. |
261 |
SHELL = sh |
262 |
CC = avr-gcc |
263 |
OBJCOPY = avr-objcopy |
264 |
OBJDUMP = avr-objdump |
265 |
SIZE = avr-size |
266 |
NM = avr-nm |
267 |
AVRDUDE = avrdude |
268 |
REMOVE = rm -f |
269 |
COPY = cp |
270 |
WINSHELL = cmd |
271 |
|
272 |
|
273 |
# Define Messages |
274 |
# English |
275 |
MSG_ERRORS_NONE = Errors: none |
276 |
MSG_BEGIN = -------- begin -------- |
277 |
MSG_END = -------- end -------- |
278 |
MSG_SIZE_BEFORE = Size before: |
279 |
MSG_SIZE_AFTER = Size after: |
280 |
MSG_COFF = Converting to AVR COFF: |
281 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
282 |
MSG_FLASH = Creating load file for Flash: |
283 |
MSG_EEPROM = Creating load file for EEPROM: |
284 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
285 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
286 |
MSG_LINKING = Linking: |
287 |
MSG_COMPILING = Compiling: |
288 |
MSG_ASSEMBLING = Assembling: |
289 |
MSG_CLEANING = Cleaning project: |
290 |
|
291 |
|
292 |
|
293 |
|
294 |
# Define all object files. |
295 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
296 |
|
297 |
# Define all listing files. |
298 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
299 |
|
300 |
|
301 |
# Compiler flags to generate dependency files. |
302 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
303 |
|
304 |
|
305 |
# Combine all necessary flags and optional flags. |
306 |
# Add target processor to flags. |
307 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
308 |
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
# Default target. |
315 |
all: begin gccversion sizebefore build sizeafter end |
316 |
|
317 |
build: elf hex eep lss sym |
318 |
|
319 |
elf: $(TARGET).elf |
320 |
hex: $(TARGET).hex |
321 |
eep: $(TARGET).eep |
322 |
lss: $(TARGET).lss |
323 |
sym: $(TARGET).sym |
324 |
|
325 |
|
326 |
|
327 |
# Eye candy. |
328 |
# AVR Studio 3.x does not check make's exit code but relies on |
329 |
# the following magic strings to be generated by the compile job. |
330 |
begin: |
331 |
@echo |
332 |
@echo $(MSG_BEGIN) |
333 |
|
334 |
end: |
335 |
@echo $(MSG_END) |
336 |
@echo |
337 |
|
338 |
|
339 |
# Display size of file. |
340 |
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
341 |
ELFSIZE = $(SIZE) -A $(TARGET).elf |
342 |
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
343 |
|
344 |
sizebefore: |
345 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
346 |
$(AVRMEM) 2>/dev/null; echo; fi |
347 |
|
348 |
sizeafter: |
349 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
350 |
$(AVRMEM) 2>/dev/null; echo; fi |
351 |
|
352 |
|
353 |
|
354 |
# Display compiler version information. |
355 |
gccversion : |
356 |
@$(CC) --version |
357 |
|
358 |
|
359 |
|
360 |
# Program the device. |
361 |
program: $(TARGET).hex $(TARGET).eep |
362 |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
363 |
|
364 |
|
365 |
# Generate avr-gdb config/init file which does the following: |
366 |
# define the reset signal, load the target file, connect to target, and set |
367 |
# a breakpoint at main(). |
368 |
gdb-config: |
369 |
@$(REMOVE) $(GDBINIT_FILE) |
370 |
@echo define reset >> $(GDBINIT_FILE) |
371 |
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
372 |
@echo end >> $(GDBINIT_FILE) |
373 |
@echo file $(TARGET).elf >> $(GDBINIT_FILE) |
374 |
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
375 |
ifeq ($(DEBUG_BACKEND),simulavr) |
376 |
@echo load >> $(GDBINIT_FILE) |
377 |
endif |
378 |
@echo break main >> $(GDBINIT_FILE) |
379 |
|
380 |
debug: gdb-config $(TARGET).elf |
381 |
ifeq ($(DEBUG_BACKEND), avarice) |
382 |
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
383 |
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
384 |
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
385 |
@$(WINSHELL) /c pause |
386 |
|
387 |
else |
388 |
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
389 |
$(DEBUG_MFREQ) --port $(DEBUG_PORT) |
390 |
endif |
391 |
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
392 |
|
393 |
|
394 |
|
395 |
|
396 |
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
397 |
COFFCONVERT=$(OBJCOPY) --debugging \ |
398 |
--change-section-address .data-0x800000 \ |
399 |
--change-section-address .bss-0x800000 \ |
400 |
--change-section-address .noinit-0x800000 \ |
401 |
--change-section-address .eeprom-0x810000 |
402 |
|
403 |
|
404 |
coff: $(TARGET).elf |
405 |
@echo |
406 |
@echo $(MSG_COFF) $(TARGET).cof |
407 |
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
408 |
|
409 |
|
410 |
extcoff: $(TARGET).elf |
411 |
@echo |
412 |
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
413 |
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
414 |
|
415 |
|
416 |
|
417 |
# Create final output files (.hex, .eep) from ELF output file. |
418 |
%.hex: %.elf |
419 |
@echo |
420 |
@echo $(MSG_FLASH) $@ |
421 |
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
422 |
|
423 |
%.eep: %.elf |
424 |
@echo |
425 |
@echo $(MSG_EEPROM) $@ |
426 |
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
427 |
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
428 |
|
429 |
# Create extended listing file from ELF output file. |
430 |
%.lss: %.elf |
431 |
@echo |
432 |
@echo $(MSG_EXTENDED_LISTING) $@ |
433 |
$(OBJDUMP) -h -S $< > $@ |
434 |
|
435 |
# Create a symbol table from ELF output file. |
436 |
%.sym: %.elf |
437 |
@echo |
438 |
@echo $(MSG_SYMBOL_TABLE) $@ |
439 |
$(NM) -n $< > $@ |
440 |
|
441 |
|
442 |
|
443 |
# Link: create ELF output file from object files. |
444 |
.SECONDARY : $(TARGET).elf |
445 |
.PRECIOUS : $(OBJ) |
446 |
%.elf: $(OBJ) |
447 |
@echo |
448 |
@echo $(MSG_LINKING) $@ |
449 |
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
450 |
|
451 |
|
452 |
# Compile: create object files from C source files. |
453 |
%.o : %.c |
454 |
@echo |
455 |
@echo $(MSG_COMPILING) $< |
456 |
$(CC) -c $(ALL_CFLAGS) $< -o $@ |
457 |
|
458 |
|
459 |
# Compile: create assembler files from C source files. |
460 |
%.s : %.c |
461 |
$(CC) -S $(ALL_CFLAGS) $< -o $@ |
462 |
|
463 |
|
464 |
# Assemble: create object files from assembler source files. |
465 |
%.o : %.S |
466 |
@echo |
467 |
@echo $(MSG_ASSEMBLING) $< |
468 |
$(CC) -c $(ALL_ASFLAGS) $< -o $@ |
469 |
|
470 |
# Create preprocessed source for use in sending a bug report. |
471 |
%.i : %.c |
472 |
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
473 |
|
474 |
|
475 |
# Target: clean project. |
476 |
clean: begin clean_list end |
477 |
|
478 |
clean_list : |
479 |
@echo |
480 |
@echo $(MSG_CLEANING) |
481 |
$(REMOVE) $(TARGET).hex |
482 |
$(REMOVE) $(TARGET).eep |
483 |
$(REMOVE) $(TARGET).cof |
484 |
$(REMOVE) $(TARGET).elf |
485 |
$(REMOVE) $(TARGET).map |
486 |
$(REMOVE) $(TARGET).sym |
487 |
$(REMOVE) $(TARGET).lss |
488 |
$(REMOVE) $(OBJ) |
489 |
$(REMOVE) $(LST) |
490 |
$(REMOVE) $(SRC:.c=.s) |
491 |
$(REMOVE) $(SRC:.c=.d) |
492 |
$(REMOVE) .dep/* |
493 |
|
494 |
|
495 |
|
496 |
# Include the dependency files. |
497 |
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
498 |
|
499 |
|
500 |
# Listing of phony targets. |
501 |
.PHONY : all begin finish end sizebefore sizeafter gccversion \ |
502 |
build elf hex eep lss sym coff extcoff \ |
503 |
clean clean_list program debug gdb-config |
504 |
|