35a8bb66217f7ca235a2a27b17451ed4dc08cbe7
[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
41 # PRE-ALPHA:
42 #  Bus protocols:
43 # i2c -- Turns GF into USB-to-i2c adapter
44 # jtagarm7 -- ARM7TDMI JTAG
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 #  Radios:
56 # nrf -- Nordic RF SPI
57 # ccspi -- Chipcon SPI
58
59 # Miscelaneous:
60 # glitch -- Glitch research tool
61 # smartcard -- Smartcard IO
62 # ps2 -- PS2 spy
63
64
65 # Configurations
66 # ==============
67 # This is what you need to customize to specify which apps you want in your
68 # firmware.  The "config" variable is just a space-delimited list of apps you
69 # want included.  The makefile will take the list of apps and include all of
70 # the proper code needed to build your desired firmware.
71
72 # bare minimum
73 # config = monitor
74
75 # basic JTAG adapter
76 # config = monitor jtag
77
78 # Chipcon hacking
79 # config = monitor chipcon ccspi
80
81 # Glitch research
82 # config = monitor glitch
83
84 # XScale PXA255 JTAG
85 # config = monitor jtagxscale
86
87 # OpenOCD bit-bang device
88 #config = monitor openocd
89
90 # Old Default Config
91 # config = monitor sbw  chipcon nrf ccspi spi jtagarm7 jtag430 jtag430x2 avr
92
93 # New default.
94 ifeq ($(platform),tilaunchpad)
95 config ?= monitor chipcon i2c
96 else
97 config ?= monitor chipcon spi jtag430 jtag430x2 avr openocd ccspi maxusb
98 endif
99
100
101 # Build the needed list of app and lib object files from the config
102 apps=
103
104 ifeq ($(platform),tilaunchpad)
105 libs= lib/$(platform).o lib/command.o lib/apps.o lib/msp430_serial.o
106 #libs+=lib/setjmp.o
107 else
108 libs= lib/$(mcu).o lib/command.o lib/dco_calib.o lib/apps.o lib/msp430.o lib/arduino.o
109 endif
110
111 hdrs=
112 ERR=
113
114 # include monitor app
115 ifeq ($(filter monitor, $(config)), monitor)
116         apps+= apps/monitor/monitor.o
117         hdrs+= monitor.h
118 endif
119
120 # include spi app
121 ifeq ($(filter spi, $(config)), spi)
122         apps+= apps/spi/spi.o
123         hdrs+= spi.h
124 endif
125
126 # include twe app
127 ifeq ($(filter twe, $(config)), twe)
128         apps+= apps/twe/twe.o
129         hdrs+= twe.h
130 endif
131
132 # include base jtag if they specified it explicitly
133 ifeq ($(filter jtag, $(config)), jtag)
134         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
135                 apps+= apps/jtag/jtag.o
136                 hdrs+= jtag.h
137         endif
138 endif
139
140 # include MAX342x USB drivers.
141 ifeq ($(filter maxusb, $(config)), maxusb)
142         ifneq ($(filter apps/usb/maxusb.o, $(apps)), apps/usb/maxusb.o)
143                 apps+= apps/usb/maxusb.o
144                 hdrs+= maxusb.h
145         endif
146 endif
147
148 # include the sbw defs if they specified it
149 ifeq ($(filter sbw, $(config)), sbw)
150         # if they only specify sbw, include jtag
151         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
152                 apps+= apps/jtag/jtag.o
153                 hdrs+= jtag.h
154         endif
155         apps+= apps/jtag/sbw.o
156         hdrs+= sbw.h
157 endif
158
159 # include jtag430 app
160 ifeq ($(filter jtag430, $(config)), jtag430)
161         # add in base jtag code if not already
162         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
163                 apps+= apps/jtag/jtag.o
164                 hdrs+= jtag.h
165         endif
166         # add in the jtag430asm code if needed
167         ifneq ($(filter apps/jtag/jtag430asm.o, $(libs)), apps/jtag/jtag430asm.o)
168                 apps+= apps/jtag/jtag430asm.o
169         endif
170         apps+= apps/jtag/jtag430.o
171         hdrs+= jtag430.h
172 endif
173
174 # include jtag430x2 app
175 ifeq ($(filter jtag430x2, $(config)), jtag430x2)
176         # add in base jtag code if not already
177         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
178                 apps+= apps/jtag/jtag.o
179                 hdrs+= jtag.h
180         endif
181         # add in the jtag430asm code if needed
182         ifneq ($(filter jtag430asm.o, $(libs)), jtag430asm.o)
183                 libs+= apps/jtag/jtag430asm.o
184         endif
185         #add in the jtag430 app if not already
186         ifneq ($(filter apps/jtag/jtag430.o, $(apps)), apps/jtag/jtag430.0)
187                 apps+= apps/jtag/jtag430.o
188                 hdrs+= jtag430.h
189         endif
190         apps+= apps/jtag/jtag430x2.o
191         hdrs+= jtag430x2.h
192 endif
193
194 # include i2c app
195 ifeq ($(filter i2c, $(config)), i2c)
196         apps+= apps/i2c/i2c.o
197         hdrs+= i2c.h
198 endif
199
200 # include jtagarm7 app
201 ifeq ($(filter jtagarm7, $(config)), jtagarm7)
202         # add in base jtag code if not already
203         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
204                 apps+= apps/jtag/jtag.o
205                 hdrs+= jtag.h
206         endif
207         apps+= apps/jtag/jtagarm7.o
208         hdrs+= jtagarm7.h
209 endif
210
211 # include jtagarm7tdmi app
212 #ifeq ($(filter jtagarm7tdmi, $(config)), jtagarm7tdmi)
213         # add in base jtag code if not already
214         #ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
215                 #apps+= apps/jtag/jtag.o
216                 #hdrs+= jtag.h
217         #endif
218         #apps+= apps/jtag/jtagarm7tdmi.o
219         #hdrs+= jtagarm7tdmi.h
220 #endif
221
222 # include ejtag app
223 ifeq ($(filter ejtag, $(config)), ejtag)
224         # add in base jtag code if not already
225         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
226                 apps+= apps/jtag/jtag.o
227                 hdrs+= jtag.h
228         endif
229         apps+= apps/jtag/ejtag.o
230         hdrs+= ejtag.h
231 endif
232
233 # include jtagxscale app
234 ifeq ($(filter jtagxscale, $(config)), jtagxscale)
235         # add in base jtag code if not already
236         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
237                 apps+= apps/jtag/jtag.o
238                 hdrs+= jtag.h
239         endif
240         apps+= apps/jtag/jtagxscale.o
241         hdrs+= jtagxscale.h
242 endif
243
244 # include openocd app
245 ifeq ($(filter openocd, $(config)), openocd)
246         # add in base jtag code if not already
247         ifneq ($(filter apps/jtag/jtag.o, $(apps)), apps/jtag/jtag.o)
248                 apps+= apps/jtag/jtag.o
249                 hdrs+= jtag.h
250         endif
251         apps+= apps/jtag/openocd.o
252         hdrs+= openocd.h
253 endif
254
255 # include chipcon app
256 ifeq ($(filter chipcon, $(config)), chipcon)
257         apps+= apps/chipcon/chipcon.o
258         hdrs+= chipcon.h
259 endif
260
261 # include avr app
262 ifeq ($(filter avr, $(config)), avr)
263         apps+= apps/avr/avr.o
264         hdrs+= avr.h
265 endif
266
267 # include pic app
268 ifeq ($(filter pic, $(config)), pic)
269         apps+= apps/pic/pic.o
270         hdrs+= pic.h
271 endif
272
273 # include adc app
274 ifeq ($(filter adc, $(config)), adc)
275         ifeq ($(mcu), msp430f2274)
276                 apps+= apps/adc/adc.o
277                 hdrs+= adc.h
278         else
279                 ERR= $(error The ADC app only works on GoodFET boards with the msp430x2274 processor)
280         endif
281 endif
282
283 # include chipcon radio spi app
284 ifeq ($(filter ccspi, $(config)), ccspi)
285         apps+= apps/radios/ccspi.o
286         hdrs+= ccspi.h
287 endif
288
289 # include nrf app
290 ifeq ($(filter nrf, $(config)), nrf)
291         apps+= apps/radios/nrf.o
292         hdrs+= nrf.h
293 endif
294
295 # include glitch app
296 ifeq ($(filter glitch, $(config)), glitch)
297         apps+= apps/glitch/glitch.o
298         hdrs+= glitch.h
299 endif
300
301 # include smartcard app
302 ifeq ($(filter smartcard, $(config)), smartcard)
303         apps+= apps/smartcard/smartcard.o
304         hdrs+= smartcard.h
305 endif
306
307 # include ps2 app
308 ifeq ($(filter ps2, $(config)), ps2)
309         apps+= apps/plugins/ps2.o
310         hdrs+= ps2.h
311 endif
312
313 # include jscan app
314 ifeq ($(filter jscan, $(config)), jscan)
315         apps+= apps/jscan/jscan.o
316         hdrs+= jscan.h
317 endif
318
319 # Rules
320
321 app= goodfet
322
323 all: $(app).hex
324
325 lib/.o: config
326         ./configure
327         false
328 lib/RUNCONFIG.o:
329         ./configure
330         false
331 config:
332         cp platforms/$(platform).h include/config.h
333 appsfiles:
334         ./gen_apps $(hdrs)
335 err:;$(ERR)
336 builddate:
337         ./gen_builddate_h
338 goodfet.hex: goodfet
339
340 run:
341         ../client/goodfet.msp430 test
342
343 avrinstall: $(app).hex
344         #to be merged
345         avrdude -V -F -c stk500v1 -p m328p -b 57600 -P $(GOODFET) -U flash:w:$(app).hex
346
347 ifeq ($(platform),tilaunchpad)
348 install: $(app).hex
349         $(JTAG) -e -p $(app).hex
350 verify:
351         $(JTAG) -v $(app).hex
352 erase:
353         $(JTAG) -e $(app).hex
354 else
355 install: $(app).hex
356         $(MSP430BSL) -e -p $(app).hex
357 installinfo:
358         $(MSP430BSL) -P $(app).hex -p info.txt || true  #MSP430F2xx targets only, inelegant.
359 verify:
360         $(MSP430BSL) -P $(app).hex -v $(app).hex
361 erase:
362         $(MSP430BSL) -e
363
364 endif
365 dumpinfo:
366         $(MSP430BSL) --dumpinfo
367 $(app).c: config builddate appsfiles err
368 $(app): $(libs) $(apps)
369
370 ifeq ($(platform),donbfet)
371 $(app).hex: $(app)
372         avr-objcopy -j .text -j .data -O ihex goodfet goodfet.hex
373 else
374 $(app).hex: $(app)
375         msp430-objcopy goodfet -O ihex goodfet.hex
376 endif
377 m4s: $(app).hex
378         msp430-objdump -D -m msp430 $(app).hex | m4s init
379 clean:
380         rm -f $(app) $(app).hex $(libs) $(apps) lib/apps.c include/config.h include/builddate.h include/apps.h
381 docs:
382         doxygen
383 pushdocs: docs
384         rsync --exclude .svn -ave ssh doc/html/* travisutk,goodfet@web.sourceforge.net:htdocs/docs/
385 .FAKE: docs
386