turn ftdi driver into echo server
[goodfet] / firmware / Makefile
1 -include config.mk
2
3
4 platform?=goodfet
5 mcu?=RUNCONFIG
6
7 #include `uname`.mak
8 GOODFET?=/dev/tty.usbser*
9
10 #For tos-bsl, use --invert-reset --invert-test
11 MSP430BSL?=goodfet.bsl --speed=38400
12 JTAG=msp430-jtag
13
14
15 GCCINC?=
16
17 #All of these are ?= in order ot allow overriding.
18 GCC?=msp430-gcc -mmcu=$(mcu)
19 LDFLAGS?=-mmcu=$(mcu) #-Wl,-dT ldscripts/$(mcu).x
20
21 CCEXTRA ?=  $(CFLAGS) -D$(mcu) -D$(platform) -Dplatform=$(platform) -Dboard=$(board) $(GCCINC) -I include -I platforms
22 CC =$(GCC) -Wall -O1 -fno-strict-aliasing -g   $(CCEXTRA)
23
24 # Available Applications
25 # ======================
26 # Below is a list of available applications and their descriptions.
27
28 # PRODUCTION:
29 # None have made it to production grade quality
30
31 # BETA:
32 # monitor -- Basic monitor
33 # spi -- Turns GF into USB-to-SPI adapter
34 # jtag -- Low level JTAG (needed by all other JTAG code)
35 # sbw -- Makes JTAG Spy-by-wire multiplexable
36
37 # ALPHA:
38 # jtag430 -- 16-bit MSP430 JTAG
39 # jtag430x2 -- 20-bit MSP430 JTAG
40 # jtagarm7 -- ARM7TDMI JTAG
41
42 # PRE-ALPHA:
43 #  Bus protocols:
44 # i2c -- Turns GF into USB-to-i2c adapter
45 # ejtag -- MIPS JTAG
46 # jtagxscale -- XScale JTAG
47 # openocd -- OpenOCD bitbang device
48
49 #  Microcontrollers:
50 # chipcon -- Chipcon radio 8051 debugging
51 # avr -- AVR debugger
52 # pic -- PIC24H/dsPIC33F debugger
53 # adc -- ADC10 (still specific to x2274, GoodFET32)
54
55 #  Radions:
56 # nrf -- Nordic RF SPI
57 # ccspi -- Chipcon SPI
58 # cc2500 -- Chipcon SPI CC2500
59 # atmel_radio -- Atmel radio
60
61 # Miscelaneous:
62 # glitch -- Glitch research tool
63 # smartcard -- Smartcard IO
64 # ps2 -- PS2 spy
65
66
67 # Configurations
68 # ==============
69 # This is what you need to customize to specify which apps you want in
70 # your firmware.  The "config" variable is just a space-delimited list
71 # of apps you want included.  The makefile will take the list of apps
72 # and include all of the proper code needed to build your desired
73 # firmware.  $(config) is generated by config.mk.
74
75
76
77 # Build the needed list of app and lib object files from the config
78 apps=
79
80 ifeq ($(platform),tilaunchpad)
81 libs= lib/$(platform).o lib/command.o lib/apps.o lib/msp430_serial.o
82 #libs+=lib/setjmp.o
83 else
84 libs= lib/$(mcu).o lib/command.o lib/dco_calib.o lib/apps.o lib/msp430.o lib/arduino.o $(extralibs)
85 endif
86
87 hdrs=
88 ERR=
89
90 # include monitor app
91 ifeq ($(filter monitor, $(config)), monitor)
92         apps+= apps/monitor/monitor.o
93         hdrs+= monitor.h
94 endif
95
96 # include spi app
97 ifeq ($(filter spi, $(config)), spi)
98         apps+= apps/spi/spi.o
99         hdrs+= spi.h
100 endif
101
102 # include twe app
103 ifeq ($(filter twe, $(config)), twe)
104         apps+= apps/twe/twe.o
105         hdrs+= twe.h
106 endif
107
108 # include base jtag if they specified it explicitly
109 ifeq ($(filter jtag, $(config)), jtag)
110         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
111                 apps+= apps/jtag/jtag.o
112                 hdrs+= jtag.h
113         endif
114 endif
115
116 # include MAX342x USB drivers.
117 ifeq ($(filter maxusb, $(config)), maxusb)
118         ifneq ($(filter apps/usb/maxusb.o, $(apps)), apps/usb/maxusb.o)
119                 apps+= apps/usb/maxusb.o
120                 hdrs+= maxusb.h
121         endif
122 endif
123
124 # include the sbw defs if they specified it
125 ifeq ($(filter sbw, $(config)), sbw)
126         # if they only specify sbw, include jtag
127         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
128                 apps+= apps/jtag/jtag.o
129                 hdrs+= jtag.h
130         endif
131         apps+= apps/jtag/sbw.o
132         hdrs+= sbw.h
133 endif
134
135 # include jtag430 app
136 ifeq ($(filter jtag430, $(config)), jtag430)
137         # add in base jtag code if not already
138         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
139                 apps+= apps/jtag/jtag.o
140                 hdrs+= jtag.h
141         endif
142         # add in the jtag430asm code if needed
143         ifneq ($(filter apps/jtag/jtag430asm.o, $(libs)), apps/jtag/jtag430asm.o)
144                 apps+= apps/jtag/jtag430asm.o
145         endif
146         apps+= apps/jtag/jtag430.o
147         hdrs+= jtag430.h
148 endif
149
150 # include jtag430x2 app
151 ifeq ($(filter jtag430x2, $(config)), jtag430x2)
152         # add in base jtag code if not already
153         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
154                 apps+= apps/jtag/jtag.o
155                 hdrs+= jtag.h
156         endif
157         # add in the jtag430asm code if needed
158         ifneq ($(filter jtag430asm.o, $(libs)), jtag430asm.o)
159                 libs+= apps/jtag/jtag430asm.o
160         endif
161         #add in the jtag430 app if not already
162         ifneq ($(filter apps/jtag/jtag430.o, $(apps)), apps/jtag/jtag430.0)
163                 apps+= apps/jtag/jtag430.o
164                 hdrs+= jtag430.h
165         endif
166         apps+= apps/jtag/jtag430x2.o
167         hdrs+= jtag430x2.h
168 endif
169
170 # include i2c app
171 ifeq ($(filter i2c, $(config)), i2c)
172         apps+= apps/i2c/i2c.o
173         hdrs+= i2c.h
174 endif
175
176 # include jtagarm7 app
177 ifeq ($(filter jtagarm7, $(config)), jtagarm7)
178         # add in base jtag code if not already
179         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
180                 apps+= apps/jtag/jtag.o
181                 hdrs+= jtag.h
182         endif
183         apps+= apps/jtag/jtagarm7.o
184         hdrs+= jtagarm7.h
185 endif
186
187 # include jtagarm7tdmi app
188 #ifeq ($(filter jtagarm7tdmi, $(config)), jtagarm7tdmi)
189         # add in base jtag code if not already
190         #ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
191                 #apps+= apps/jtag/jtag.o
192                 #hdrs+= jtag.h
193         #endif
194         #apps+= apps/jtag/jtagarm7tdmi.o
195         #hdrs+= jtagarm7tdmi.h
196 #endif
197
198 # include ejtag app
199 ifeq ($(filter ejtag, $(config)), ejtag)
200         # add in base jtag code if not already
201         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
202                 apps+= apps/jtag/jtag.o
203                 hdrs+= jtag.h
204         endif
205         apps+= apps/jtag/ejtag.o
206         hdrs+= ejtag.h
207 endif
208
209 # include jtagxscale app
210 ifeq ($(filter jtagxscale, $(config)), jtagxscale)
211         # add in base jtag code if not already
212         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
213                 apps+= apps/jtag/jtag.o
214                 hdrs+= jtag.h
215         endif
216         apps+= apps/jtag/jtagxscale.o
217         hdrs+= jtagxscale.h
218 endif
219
220 # include openocd app
221 ifeq ($(filter openocd, $(config)), openocd)
222         # add in base jtag code if not already
223         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
224                 apps+= apps/jtag/jtag.o
225                 hdrs+= jtag.h
226         endif
227         apps+= apps/jtag/openocd.o
228         hdrs+= openocd.h
229 endif
230
231 # include chipcon app
232 ifeq ($(filter chipcon, $(config)), chipcon)
233         apps+= apps/chipcon/chipcon.o
234         hdrs+= chipcon.h
235 endif
236
237 # include avr app
238 ifeq ($(filter avr, $(config)), avr)
239         apps+= apps/avr/avr.o
240         hdrs+= avr.h
241 endif
242
243 # include pic app
244 ifeq ($(filter pic, $(config)), pic)
245         apps+= apps/pic/pic.o
246         hdrs+= pic.h
247 endif
248
249 # include adc app
250 ifeq ($(filter adc, $(config)), adc)
251         ifeq ($(mcu), msp430f2274)
252                 apps+= apps/adc/adc.o
253                 hdrs+= adc.h
254         else
255                 ERR= $(error The ADC app only works on GoodFET boards with the msp430x2274 processor)
256         endif
257 endif
258
259 # include chipcon radio spi app
260 ifeq ($(filter ccspi, $(config)), ccspi)
261         apps+= apps/radios/ccspi.o
262         hdrs+= ccspi.h
263 endif
264
265 # include chipcon CC2500 radio spi app
266 ifeq ($(filter cc2500, $(config)), cc2500)
267         apps+= apps/radios/cc2500.o
268         hdrs+= cc2500.h
269 endif
270
271 # include nrf app
272 ifeq ($(filter nrf, $(config)), nrf)
273         apps+= apps/radios/nrf.o
274         hdrs+= nrf.h
275 endif
276
277 # include atmel_radio app
278 ifeq ($(filter atmel_radio, $(config)), atmel_radio)
279         apps+= apps/radios/atmel_radio.o
280         hdrs+= atmel_radio.h
281 endif
282
283 # include glitch app
284 ifeq ($(filter glitch, $(config)), glitch)
285         apps+= apps/glitch/glitch.o
286         hdrs+= glitch.h
287 endif
288
289 # include smartcard app
290 ifeq ($(filter smartcard, $(config)), smartcard)
291         apps+= apps/smartcard/smartcard.o
292         hdrs+= smartcard.h
293 endif
294
295 # include plugin app
296 ifeq ($(filter plugin, $(config)), plugin)
297         apps+= apps/plugin.o
298         hdrs+= plugin.h
299 endif
300
301 # include jscan app
302 ifeq ($(filter jscan, $(config)), jscan)
303         apps+= apps/jscan/jscan.o
304         hdrs+= jscan.h
305 endif
306
307 # Rules
308
309 app= goodfet
310
311 all: $(app).hex
312
313 lib/.o: config
314         ./configure
315         false
316 lib/RUNCONFIG.o:
317         ./configure
318         false
319 config:
320         cp platforms/$(platform).h include/config.h
321 appsfiles:
322         ./gen_apps $(hdrs)
323 err:;$(ERR)
324 builddate:
325         ./gen_builddate_h
326 goodfet.hex: goodfet
327
328 run:
329         ../client/goodfet.msp430 test
330
331 avrinstall: $(app).hex
332         #to be merged
333 ifdef AVR_PLATFORM
334         avrdude -V -F -c stk500v1 -p $(AVR_PLATFORM) -b 57600 -P $(GOODFET) -U flash:w:$(app).hex
335 else
336         avrdude -V -F -c stk500v1 -p m328p -b 57600 -P $(GOODFET) -U flash:w:$(app).hex
337 endif
338
339 ifeq ($(platform),tilaunchpad)
340 install: $(app).hex
341         $(JTAG) -e -p $(app).hex
342 verify:
343         $(JTAG) -v $(app).hex
344 erase:
345         $(JTAG) -e $(app).hex
346 else
347 install: $(app).hex
348         #Note that 'make install' no longer erases the chip.
349         #Use 'make reinstall' if you want that.
350         $(MSP430BSL) -p $(app).hex
351 reinstall: $(app).hex
352         $(MSP430BSL) -e -p $(app).hex
353 installinfo:
354         $(MSP430BSL) -P $(app).hex -p info.txt || true  #MSP430F2xx targets only, inelegant.
355 verify:
356         $(MSP430BSL) -P $(app).hex -v $(app).hex
357 erase:
358         $(MSP430BSL) -e
359
360 endif
361 dumpinfo:
362         $(MSP430BSL) --dumpinfo
363 $(app).c: config builddate appsfiles err
364 $(app): $(app).o $(libs) $(apps) 
365 armlink: $(app).o $(libs) $(apps) $(platformlibs)
366         arm-none-eabi-ld -v -Tlinkers/stm32f407.cmd -nostartfiles -o goodfet.elf $(app).o $(libs) $(apps)
367         arm-none-eabi-objcopy -Obinary goodfet.elf goodfet.bin
368 ifeq ($(platform),donbfet)
369 $(app).hex: $(app)
370         avr-objcopy -j .text -j .data -O ihex goodfet goodfet.hex
371 else
372 $(app).hex: $(app)
373         msp430-objcopy goodfet -O ihex goodfet.hex
374 endif
375 m4s: $(app).hex
376         msp430-objdump -D -m msp430 $(app).hex | m4s init
377 clean:
378         rm -f *.o $(app) $(app).hex $(libs) $(apps) lib/apps.c include/config.h include/builddate.h include/apps.h
379 docs:
380         doxygen
381 pushdocs: docs
382         rsync --exclude .svn -ave ssh doc/html/* travisutk,goodfet@web.sourceforge.net:htdocs/docs/
383 .FAKE: docs
384