root/trunk/bootloader/Makefile

Revision 21, 14.1 kB (checked in by charlie, 3 years ago)

Added Peter Fleury's GPL licensed bootloader

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