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