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