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