1 # $Id: Makefile.avr,v 1.22 2010/03/15 18:52:55 dak664 Exp $
3 ### Check if we are running under Windows
7 ifneq (,$(findstring Windows,$(OS)))
15 ### Optimization setting. $make OPTI=0 for easier debugging of changed source file(s)
20 ### Define the CPU directory of the AVR port
21 CONTIKI_CPU=$(CONTIKI)/cpu/avr
23 ### These directories will be searched for the specified source files
24 ### TARGETLIBS are platform-specific routines in the contiki library path
25 CONTIKI_CPU_DIRS = . dev
26 AVR = clock.c mtarch.c eeprom.c flash.c rs232.c leds-arch.c watchdog.c rtimer-arch.c
27 ELFLOADER = elfloader.c elfloader-avr.c symtab-avr.c
28 TARGETLIBS = random.c leds.c
31 ### Add the directories for the USB stick and remove the default rs232 driver
32 CONTIKI_CPU_DIRS += dev/usb dev/usb/serial dev/usb/rndis dev/usb/storage
33 CONTIKI_TARGET_SOURCEFILES += $(USB)
34 //AVR = clock.c mtarch.c eeprom.c flash.c leds-arch.c watchdog.c rtimer-arch.c
37 #For a coffee file system, the application makefile can define COFFEE_FILES=n
38 #to select the type and COFFEE_ADDRESS=0xaaaaaaaa as the starting byte address.
39 #If only one is define the other will use the (Raven webserver 1284p) defaults
40 #of a static file system in program flash starting at 0x10000 (word address=0x8000)
41 #For program flash the starting address is rounded down to a page boundary in cfs-coffee-arch.h
42 #It should be rounded down here too if someone can figure out how :)
44 ifdef COFFEE_ADDRESS #if address is passed force definition of COFFEE_FILES
45 ifndef COFFEE_FILES #use program flash for static file system if not specified
50 ifdef COFFEE_FILES #if files are defined force definition of COFFEE_ADDRESS
52 ifeq ($(COFFEE_FILES), 1) #1=eeprom static
53 COFFEE_ADDRESS=DEFAULT
54 else ifeq ($(COFFEE_FILES), 2) #2=eeprom dynamic
55 COFFEE_ADDRESS=DEFAULT
56 else ifeq ($(COFFEE_FILES), 3) #3=program flash static
57 COFFEE_ADDRESS=0x14000
58 else ifeq ($(COFFEE_FILES), 4) #4=program flash dynamic
59 COFFEE_ADDRESS=0x10000
61 print "Unsupported coffee file type!"
64 COFFEE_ADDRESS1 = $(shell echo $$(( $(COFFEE_ADDRESS) + 1 )))
65 CONTIKI_TARGET_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c
66 CFLAGS += -DCOFFEE_FILES=$(COFFEE_FILES) -DCOFFEE_ADDRESS=$(COFFEE_ADDRESS)
67 ifneq ($(COFFEE_ADDRESS), DEFAULT)
68 LDFLAGS+= -Wl,--section-start=.coffeefiles=$(COFFEE_ADDRESS)
71 #If $make invokation passed starting address use phony target to force synchronization of source to .coffeefiles section
72 #Warning: recompilation will not be forced if the starting address is then dropped, with dire consequences:
73 # -->Source that uses COFFEE_FILES and read macros for conditional compilation will be left hanging!
74 # -->Object modules that used .coffeesection will overlap the .data section.
75 # -->$make clean is safest.
76 #ifeq ($(origin COFFEE_ADDRESS), command line)
77 # ifeq ($(COFFEE_FILES), 2) #safest to force recompilation even if eeprom address is changed, might have been switched from flash
80 $(OBJECTDIR)/cfs-coffee-arch.o : coffee #cfs-coffee-arch uses COFFEE_FILES, COFFEE_ADDRESS
81 $(OBJECTDIR)/contiki-raven-main.o : coffee #Raven Webserver uses COFFEE_FILES
82 $(OBJECTDIR)/httpd-fs.o : coffee #this file contains httpd-fsdata.c which has the .coffeesection data
83 $(OBJECTDIR)/httpd.c.o : coffee #uses defines to read from file system
84 $(OBJECTDIR)/httpd-cgi.o : coffee #uses defines to read from file system
85 $(OBJECTDIR)/cfs-coffee.o : coffee #core routine requires recompilation
92 CONTIKI_TARGET_SOURCEFILES += $(AVR) $(SENSORS) \
93 $(SYSAPPS) $(ELFLOADER) \
96 CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
99 ### Compiler definitions
104 OBJCOPY = avr-objcopy
106 CFLAGSNO = -Wall -mmcu=$(MCU) -gdwarf-2 \
107 -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) $(USB_INCLUDES) \
108 -I$(CONTIKI)/platform/$(TARGET) \
110 CFLAGS += $(CFLAGSNO) -O$(OPTI)
111 ifndef BOOTLOADER_START
112 BOOTLOADER_START = 0x1FC00
115 LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map \
116 -Wl,--section-start=.bootloader=$(BOOTLOADER_START)
118 ### Setup directory search path for source files
120 CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
121 $(CONTIKI_TARGET_DIRS)}
123 ### Compilation rules
125 $(OBJECTDIR)/%.o: %.c
126 $(CC) $(CFLAGS) -c $< -o $@
129 $(CC) $(CFLAGS) -c $< -o $@
132 $(STRIP) -K _init -K _fini --strip-unneeded -g -x $< -o $@
134 %.elf: %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a symbols.o
135 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter-out %.a,$^) $(filter %.a,$^) $(LDLIBS)
138 $(OBJCOPY) $^ -O ihex $@
141 $(OBJCOPY) $^ -O ihex $@
143 # Add a namelist to the kernel
144 %.out: %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a
145 $(CONTIKI)/tools/make-empty-symbols
146 $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) symbols.c
148 $(CONTIKI)/tools/avr-make-symbols $@
149 $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) symbols.c
150 $(CONTIKI)/tools/avr-make-symbols $@
151 $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) symbols.c
155 # $(OBJCOPY) -R .eeprom $^ -O ihex $@
158 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
159 --change-section-lma .eeprom=0 -O ihex $^ $@
163 $(CC) $(CFLAGS) -c $< -o $@
164 $(STRIP) --strip-unneeded -g -x $@
167 # $(CC) $(CFLAGS) -c $< -o $@
168 # $(STRIP) --strip-unneeded -g -x $@
171 # $(LD) -i -r --unresolved-symbols=ignore-in-object-files -mavr5 -o $@ $^
172 # $(STRIP) --strip-unneeded -g -x $@
175 $(CONTIKI)/tools/make-empty-symbols
176 $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
179 $(STRIP) --strip-unneeded -g -x -o $@ $<
181 %.o: ${CONTIKI_TARGET}/loader/%.S
182 $(AS) -o $(notdir $(<:.S=.o)) $<
185 $(OBJCOPY) -O srec $< $@
189 avrdude ${AVRDUDE_OPTIONS} -P ${AVRDUDE_PORT} -c ${AVRDUDE_PROGRAMMER} -p ${MCU} -U flash:w:$<
192 @${CONTIKI}/tools/make-empty-symbols