Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / wireless_bootloader / Makefile @ 1439

History | View | Annotate | Download (16.6 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

    
43
# MCU name
44
MCU = atmega128
45

    
46

    
47
# Processor frequency.
48
#     This will define a symbol, F_CPU, in all source code files equal to the 
49
#     processor frequency. You can then use this symbol in your source code to 
50
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
51
#     automatically to create a 32-bit value in your source code.
52
F_CPU = 8000000
53

    
54

    
55
# Output format. (can be srec, ihex, binary)
56
FORMAT = ihex
57

    
58

    
59
# Target file name (without extension).
60
TARGET = wireless_bootloader
61
LDSECTION  = --section-start=.text=0x1E000
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
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
#This trick shows a percentage of how much flash and data space is used by your program. Very handy
140
#ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
141

    
142

    
143
#---------------- Library Options ----------------
144
# Minimalistic printf version
145
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
146

    
147
# Floating point printf version (requires MATH_LIB = -lm below)
148
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
149

    
150
# If this is left blank, then it will use the Standard printf version.
151
PRINTF_LIB = 
152
#PRINTF_LIB = $(PRINTF_LIB_MIN)
153
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
154

    
155

    
156
# Minimalistic scanf version
157
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
158

    
159
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
160
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
161

    
162
# If this is left blank, then it will use the Standard scanf version.
163
SCANF_LIB = 
164
#SCANF_LIB = $(SCANF_LIB_MIN)
165
#SCANF_LIB = $(SCANF_LIB_FLOAT)
166

    
167

    
168
MATH_LIB = -lm
169

    
170

    
171

    
172
#---------------- External Memory Options ----------------
173

    
174
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
175
# used for variables (.data/.bss) and heap (malloc()).
176
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
177

    
178
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
179
# only used for heap (malloc()).
180
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
181

    
182
EXTMEMOPTS =
183

    
184

    
185

    
186
#---------------- Linker Options ----------------
187
#  -Wl,...:     tell GCC to pass this to linker.
188
#    -Map:      create map file
189
#    --cref:    add cross reference to  map file
190
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
191
LDFLAGS += $(EXTMEMOPTS)
192
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
193

    
194

    
195

    
196
#---------------- Programming Options (avrdude serial bootloader) ----------------
197

    
198
#"C:\arduino\hardware\tools\avr\bin\avrdude" -PCOM2 -c stk500v1 -patmega168 -b19200 -Uflash:w:Simon.hex -V -F -C"C:\arduino\hardware\tools\avr\etc\avrdude.conf"
199
SERIAL_AVRDUDE = "C:\arduino\hardware\tools\avr\bin\avrdude"
200
SERIAL_AVRDUDE_CONFIG = "C:\arduino\hardware\tools\avr\etc\avrdude.conf"
201
SERIAL_AVRDUDE_PORT = COM3
202
SERIAL_AVRDUDE_SPEED = 19200
203
SERIAL_AVRDUDE_PROGRAMMER = stk500v1
204

    
205
SERIAL_AVRDUDE_FLAGS = -p $(MCU) -P $(SERIAL_AVRDUDE_PORT) -c $(SERIAL_AVRDUDE_PROGRAMMER) -b$(SERIAL_AVRDUDE_SPEED)
206
#SERIAL_AVRDUDE_FLAGS += -C$(SERIAL_AVRDUDE_CONFIG)
207
SERIAL_AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
208
SERIAL_AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
209
SERIAL_AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
210

    
211

    
212
#---------------- Programming Options (avrdude) ----------------
213

    
214
# Programming hardware: alf avr910 avrisp bascom bsd 
215
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
216
#
217
# Type: avrdude -c ?
218
# to get a full listing.
219
AVRDUDE_PROGRAMMER = avrispmkII
220
#AVRDUDE_PROGRAMMER = ponyser
221

    
222
# com1 = serial port. Use lpt1 to connect to parallel port.
223
AVRDUDE_PORT = usb
224
#AVRDUDE_PORT = COM1
225

    
226
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
227
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
228

    
229

    
230
# Uncomment the following if you want avrdude's erase cycle counter.
231
# Note that this counter needs to be initialized first using -Yn,
232
# see avrdude manual.
233
#AVRDUDE_ERASE_COUNTER = -y
234

    
235
# Uncomment the following if you do /not/ wish a verification to be
236
# performed after programming the device.
237
#AVRDUDE_NO_VERIFY = -V
238

    
239
# Increase verbosity level.  Please use this when submitting bug
240
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
241
# to submit bug reports.
242
#AVRDUDE_VERBOSE = -v -v
243

    
244
#HFUSE = DD Only use these if you are using an external osc!
245
#LFUSE = C6 Only use these if you are using an external osc!
246

    
247
#Internal OSC
248
HFUSE = DD
249
LFUSE = E2
250

    
251
ISPFUSES    = avrdude -c $(AVRDUDE_PROGRAMMER) -p atmega128 -P $(AVRDUDE_PORT) -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
252
ISPFLASHLOCK= avrdude -c $(AVRDUDE_PROGRAMMER) -p atmega128 -P $(AVRDUDE_PORT) -U flash:w:$(TARGET).hex -U lock:w:0x0f:m
253

    
254
#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
255
#AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
256
#AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
257
#AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
258

    
259
#---------------- Programming Options (STK500) ----------------
260
# Programming hardware: stk500 (the AVR MKII ISP version)
261

    
262
STK500 = stk500
263

    
264
# Location of STK500.exe - no trailing '\'
265
STK500_PATH = C:\Program Files\Atmel\AVR Tools\STK500
266

    
267
# The STK500 AVR ISP MKII is USB. The USB drivers must already be installed.
268
# Do this normally by installing AVR Studio. 
269
STK500_PORT = USB
270

    
271
#-erase chip -Program Flash -Verify Flash -File name -Serial programing(ISP) 
272
STK500_WRITE_FLASH = -e -pf -vf -if$(TARGET).hex -ms
273

    
274
STK500_FLAGS = -d$(MCU) -c$(STK500_PORT)
275

    
276
#-Set ISP frequency to 250kHz. Limit is 1/4 of internal osc which is default 1MHz
277
#Reduce this to 100kHz if you run into flash verification problems in low-voltage systems
278
STK500_FLAGS += -I250kHz
279

    
280
#---------------- Debugging Options ----------------
281

    
282
# For simulavr only - target MCU frequency.
283
DEBUG_MFREQ = $(F_CPU)
284

    
285
# Set the DEBUG_UI to either gdb or insight.
286
# DEBUG_UI = gdb
287
DEBUG_UI = insight
288

    
289
# Set the debugging back-end to either avarice, simulavr.
290
DEBUG_BACKEND = avarice
291
#DEBUG_BACKEND = simulavr
292

    
293
# GDB Init Filename.
294
GDBINIT_FILE = __avr_gdbinit
295

    
296
# When using avarice settings for the JTAG
297
JTAG_DEV = /dev/com1
298

    
299
# Debugging port used to communicate between GDB / avarice / simulavr.
300
DEBUG_PORT = 4242
301

    
302
# Debugging host used to communicate between GDB / avarice / simulavr, normally
303
#     just set to localhost unless doing some sort of crazy debugging when 
304
#     avarice is running on a different computer.
305
DEBUG_HOST = localhost
306

    
307

    
308

    
309
#============================================================================
310

    
311

    
312
# Define programs and commands.
313
SHELL = sh
314
CC = avr-gcc
315
OBJCOPY = avr-objcopy
316
OBJDUMP = avr-objdump
317
SIZE = avr-size
318
NM = avr-nm
319
AVRDUDE = avrdude
320
REMOVE = rm -f
321
COPY = cp
322
WINSHELL = cmd
323

    
324

    
325
# Define Messages
326
# English
327
MSG_ERRORS_NONE = Errors: none
328
MSG_BEGIN = -------- begin --------
329
MSG_END = --------  end  --------
330
MSG_SIZE_BEFORE = Size before: 
331
MSG_SIZE_AFTER = Size after:
332
MSG_COFF = Converting to AVR COFF:
333
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
334
MSG_FLASH = Creating load file for Flash:
335
MSG_EEPROM = Creating load file for EEPROM:
336
MSG_EXTENDED_LISTING = Creating Extended Listing:
337
MSG_SYMBOL_TABLE = Creating Symbol Table:
338
MSG_DOWNLOADER = Creating Downloader Client:
339
MSG_LINKING = Linking:
340
MSG_COMPILING = Compiling:
341
MSG_ASSEMBLING = Assembling:
342
MSG_CLEANING = Cleaning project:
343

    
344

    
345

    
346

    
347
# Define all object files.
348
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
349

    
350
# Define all listing files.
351
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
352

    
353

    
354
# Compiler flags to generate dependency files.
355
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
356

    
357
#This forces the program code into the upper bootloader memory block
358
override LDFLAGS       = -Wl,$(LDSECTION)
359

    
360

    
361
# Combine all necessary flags and optional flags.
362
# Add target processor to flags.
363
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
364
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
365

    
366

    
367
# Default target.
368
all: begin gccversion sizebefore build sizeafter end downloader
369

    
370
downloader: downloader.c
371
	@echo
372
	@echo $(MSG_DOWNLOADER) $@
373
	gcc -ansi $(CSTANDARD) -Wall -pedantic $^ --output $@
374
	@echo
375

    
376
build: elf hex eep lss sym
377

    
378
elf: $(TARGET).elf
379
hex: $(TARGET).hex
380
eep: $(TARGET).eep
381
lss: $(TARGET).lss 
382
sym: $(TARGET).sym
383

    
384

    
385

    
386
# Eye candy.
387
# AVR Studio 3.x does not check make's exit code but relies on
388
# the following magic strings to be generated by the compile job.
389
begin:
390
	@echo
391
	@echo $(MSG_BEGIN)
392

    
393
end:
394
	@echo $(MSG_END)
395
	@echo
396

    
397

    
398
# Display size of file.
399
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
400
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
401
#ELFSIZE = $(SIZE) -A $(TARGET).elf
402
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
403

    
404
sizebefore:
405
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
406
	$(AVRMEM) 2>/dev/null; echo; fi
407

    
408
sizeafter:
409
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
410
	$(AVRMEM) 2>/dev/null; echo; fi
411

    
412

    
413

    
414
# Display compiler version information.
415
gccversion : 
416
	@$(CC) --version
417

    
418

    
419

    
420
# Program the device.  
421
program: 
422
#$(TARGET).hex $(TARGET).eep
423
	#$(ISPFUSES)
424
	$(ISPFLASHLOCK)
425
	#$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
426

    
427
program_stk500: $(TARGET).hex $(TARGET).eep
428
	$(STK500_PATH)\$(STK500) $(STK500_FLAGS) $(STK500_WRITE_FLASH)
429
	
430
program_serial: $(TARGET).hex $(TARGET).eep
431
	$(SERIAL_AVRDUDE) $(SERIAL_AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
432

    
433
# Generate avr-gdb config/init file which does the following:
434
#     define the reset signal, load the target file, connect to target, and set 
435
#     a breakpoint at main().
436
gdb-config: 
437
	@$(REMOVE) $(GDBINIT_FILE)
438
	@echo define reset >> $(GDBINIT_FILE)
439
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
440
	@echo end >> $(GDBINIT_FILE)
441
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
442
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
443
ifeq ($(DEBUG_BACKEND),simulavr)
444
	@echo load  >> $(GDBINIT_FILE)
445
endif	
446
	@echo break main >> $(GDBINIT_FILE)
447
	
448
debug: gdb-config $(TARGET).elf
449
ifeq ($(DEBUG_BACKEND), avarice)
450
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
451
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
452
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
453
	@$(WINSHELL) /c pause
454
	
455
else
456
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
457
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
458
endif
459
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
460
	
461

    
462

    
463

    
464
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
465
COFFCONVERT=$(OBJCOPY) --debugging \
466
--change-section-address .data-0x800000 \
467
--change-section-address .bss-0x800000 \
468
--change-section-address .noinit-0x800000 \
469
--change-section-address .eeprom-0x810000 
470

    
471

    
472
coff: $(TARGET).elf
473
	@echo
474
	@echo $(MSG_COFF) $(TARGET).cof
475
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
476

    
477

    
478
extcoff: $(TARGET).elf
479
	@echo
480
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
481
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
482

    
483

    
484

    
485
# Create final output files (.hex, .eep) from ELF output file.
486
%.hex: %.elf
487
	@echo
488
	@echo $(MSG_FLASH) $@
489
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
490

    
491
%.eep: %.elf
492
	@echo
493
	@echo $(MSG_EEPROM) $@
494
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
495
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
496

    
497
# Create extended listing file from ELF output file.
498
%.lss: %.elf
499
	@echo
500
	@echo $(MSG_EXTENDED_LISTING) $@
501
	$(OBJDUMP) -h -S $< > $@
502

    
503
# Create a symbol table from ELF output file.
504
%.sym: %.elf
505
	@echo
506
	@echo $(MSG_SYMBOL_TABLE) $@
507
	$(NM) -n $< > $@
508

    
509

    
510

    
511
# Link: create ELF output file from object files.
512
.SECONDARY : $(TARGET).elf
513
.PRECIOUS : $(OBJ)
514
%.elf: $(OBJ)
515
	@echo
516
	@echo $(MSG_LINKING) $@
517
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
518

    
519

    
520
# Compile: create object files from C source files.
521
%.o : %.c
522
	@echo
523
	@echo $(MSG_COMPILING) $<
524
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
525

    
526

    
527
# Compile: create assembler files from C source files.
528
%.s : %.c
529
	$(CC) -S $(ALL_CFLAGS) $< -o $@
530

    
531

    
532
# Assemble: create object files from assembler source files.
533
%.o : %.S
534
	@echo
535
	@echo $(MSG_ASSEMBLING) $<
536
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
537

    
538
# Create preprocessed source for use in sending a bug report.
539
%.i : %.c
540
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
541

    
542

    
543
# Target: clean project.
544
clean: begin clean_list end
545

    
546
clean_list :
547
	@echo
548
	@echo $(MSG_CLEANING)
549
	$(REMOVE) $(TARGET).hex
550
	$(REMOVE) $(TARGET).eep
551
	$(REMOVE) $(TARGET).cof
552
	$(REMOVE) $(TARGET).elf
553
	$(REMOVE) $(TARGET).map
554
	$(REMOVE) $(TARGET).sym
555
	$(REMOVE) $(TARGET).lss
556
	$(REMOVE) $(OBJ)
557
	$(REMOVE) $(LST)
558
	$(REMOVE) $(SRC:.c=.s)
559
	$(REMOVE) $(SRC:.c=.d)
560
	$(REMOVE) .dep/*
561
	$(REMOVE) downloader
562

    
563

    
564

    
565
# Include the dependency files.
566
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
567

    
568

    
569
# Listing of phony targets.
570
.PHONY : all begin finish end sizebefore sizeafter gccversion \
571
build elf hex eep lss sym coff extcoff \
572
clean clean_list program debug gdb-config
573

    
574

    
575