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