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