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