-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnutsetup
492 lines (410 loc) · 13.3 KB
/
nutsetup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
#! /bin/sh
if [ "x`uname`" != "xLinux" ]; then
if [ "x`uname`" != "xDarwin" ]; then
if [ "x`uname -o`" != "xCygwin" ]; then
echo "This is not a Linux, Cygwin or Mac OS X system."
echo "I'm so confused!"
exit 1
fi
fi
fi
# Ask user which device to target
unset HWDEF
unset DEV
while [ "x$DEV" = "x" ]
do
echo "Select a target device:"
echo ""
echo " 1) Atmel ATmega128"
echo " 2) Atmel ATmega103"
echo " 3) Atmel AT90CAN128"
echo " 4) Renesas H8/3068F"
echo " 5) UNIX Emulation"
# echo " 6) Renesas H8/3069F" # just an example
# echo " 7) Renesas H8S/2676F" # just an example
# echo " 8) OKI ML67Q5003" # just an example
echo " a) Atmel AT91R40008"
echo " b) Atmel AT91SAM7X(C)256"
echo " c) Atmel AT91SAM9260"
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
1) DEV=atmega128; ARCH=avr; CPU=m128 ;;
2) DEV=atmega103; ARCH=avr; CPU=m103 ;;
3) DEV=at90can128; ARCH=avr; CPU=c128; HWDEF="-DMCU_AT90CAN128 -DNUTMEM_STACKHEAP=4096" ;;
4) DEV=H8/3068F; ARCH=h8300h ;;
5) DEV=mac; ARCH=unix ;;
# 6) DEV=H8/3069F; ARCH=h8300h ;; # just an example
# 7) DEV=H8S/2676F; ARCH=h8300s ;; # just an example
# 8) DEV=ML67Q5003; ARCH=arm ;; # just an example
a) DEV=AT91R40008; ARCH=arm; CPU=arm7tdmi ;;
b) DEV=AT91SAM7X256; ARCH=arm; CPU=arm7tdmi ;;
c) DEV=AT91SAM9260; ARCH=arm; CPU=arm9 ;;
*)
echo "invalid choice" ;;
esac
done
# Set up environment for AVR microcontrollers
if [ "$ARCH" = "avr" ]; then
# Verify that avr-gcc is in the users PATH
if ! avr-gcc --version >/dev/null 2>&1
then
echo "Can't find avr-gcc. :-("
echo ""
echo "This could mean either of the following:"
echo " 1: You don't have avr-gcc installed."
echo " 2: You don't have your PATH environment variable set right."
echo "Here is your PATH variable:"
echo ""
echo $PATH
echo ""
exit 1
fi
# Make links to included make fragments
ln -s -f Makedefs.avr-gcc Makedefs
ln -s -f Makerules.avr-gcc Makerules
ln -s -f Makedefs.avr-gcc app/Makedefs
ln -s -f Makerules.avr-gcc app/Makerules
# Ask which target board is being used
unset PLATFORM
while [ "x$PLATFORM" = "x" ]
do
echo "Do you use a standard Ethernut board?"
echo ""
echo " 0) No standard"
echo " 1) Ethernut 1 (10 Mbit Realtek RTL8019AS)"
echo " 2) Ethernut 2 (10/100 Mbit SMSC LAN91C111)"
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
0) ;;
1) PLATFORM=ETHERNUT1 ;;
2) PLATFORM=ETHERNUT2 ;;
*)
echo "invalid choice" ;;
esac
done
# Ask which crystal is being used
unset CRYSTAL
while [ "x$CLOCKSEL" = "x" ]
do
echo "Do you want to set a fixed cpu clock?"
echo ""
echo " 1) don't set clock"
echo " 2) 7.3728 Mhz"
echo " 3) 8.0000 Mhz"
echo " 4) 12.0000 Mhz"
echo " 5) 14.7456 Mhz"
echo " 6) 16.0000 Mhz"
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
1) CLOCKSEL=1 ;;
2) CLOCKSEL=2 ; CLOCK=-DNUT_CPU_FREQ=7372800 ;;
3) CLOCKSEL=3 ; CLOCK=-DNUT_CPU_FREQ=8000000 ;;
4) CLOCKSEL=4 ; CLOCK=-DNUT_CPU_FREQ=12000000 ;;
5) CLOCKSEL=5 ; CLOCK=-DNUT_CPU_FREQ=14745600 ;;
6) CLOCKSEL=6 ; CLOCK=-DNUT_CPU_FREQ=16000000 ;;
*)
echo "invalid choice" ;;
esac
done
# Ask which isp programmer is being used
unset UISP_PROG
while [ "x$UISP_PROG" = "x" ]
do
echo "Which isp programmer are you using?"
echo ""
echo " 1) stk200, stk300 or compatible"
echo " 2) skt500"
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
1) UISP_PROG=stk200 ;;
2) UISP_PROG=stk500 ;;
*)
echo "invalid choice" ;;
esac
done
unset PROGRAMMER
while [ "x$PROGRAMMER" = "x" ]
do
echo "Which programming software are you using?"
echo ""
echo " 1) uisp"
echo " 2) avrdude"
echo " 9) mine is not listed here"
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
1) PROGRAMMER=usip ; BURNFLAGS="-dprog=$UISP_PROG --erase --upload --verify if=\$(TARG)" ;;
2) PROGRAMMER=avrdude ; BURNFLAGS="-p $CPU -c $UISP_PROG -U flash:w:\$(TARG) -E noreset" ;;
9) PROGRAMMER="echo" ; BURNFLAGS="See UserConf.mk" ;;
*)
echo "invalid choice" ;;
esac
done
# Generate the config file
cat <<EOF > UserConf.mk
PLATFORM=$PLATFORM
MCU=$DEV
ARCH=$ARCH
HWDEF=-D__HARVARD_ARCH__ $CLOCK -D\$(PLATFORM) $HWDEF
BURN=$PROGRAMMER
BURNFLAGS=$BURNFLAGS
CRUROM=crurom
EOF
echo "Your system is now configured to build for $DEV."
echo "Change to subdirectory lib and type \`make clean\` "
echo "and \`make install\` to build the system."
exit 0
fi
# Set up environment for H8/300H and H8S microcontrollers
if [ "$ARCH" = "h8300h" -o "$ARCH" = "h8300s" ]; then
# Verify if h8300-elf-gcc is in the users PATH
if ! h8300-elf-gcc --version >/dev/null 2>&1
then
echo "Can't find H8 gcc. :-("
echo ""
echo "This could mean either of the following:"
echo " 1: You don't have H8 gcc installed. Go to http://www.kpitgnutools.com"
echo " 2: You don't have your PATH environment variable set right."
echo "Here is your PATH variable:"
echo ""
echo $PATH
echo ""
exit 1
fi
# Set up device dependant compiler flags
if [ "$ARCH" = "h8300h" ]; then
# flags for H8/300H micros
MCUOPTS="-mh -mint32"
else
# flags for H8S micros
MCUOPTS="-ms -mint32"
fi
# Setup paths to libc and libgcc for linker
GCCVER=`h8300-elf-gcc --version|grep h8300-elf-gcc|cut -d ' ' -f 3`
GCCDIR=`dirname \`which h8300-elf-gcc\``
LIBGCCDIR="lib/gcc-lib/h8300-elf/$GCCVER/$ARCH/int32"
LIBCDIR="h8300-elf/lib/$ARCH/int32"
LDDIRS="-L $GCCDIR/../$LIBGCCDIR -L $GCCDIR/../$LIBCDIR"
# Select whether code is to be executed from ROM or RAM
CODEMEM="rom"
unset RUNFLAG
echo "Ethernut code can be run from RAM. This is useful when you are"
echo "debugging your application. Remember that your hardware must"
echo "have enough RAM to store data and program code."
echo ""
echo -n "Should Ethernut be executed from RAM (default=No)? Y(es)/N(o) "
read answ
if [ "$answ" = "y" -o "$answ" = "Y" ]; then
RUNFLAG="-DTEXT_IN_RAM"
CODEMEM="ram"
fi
echo ""
# Choose appropriate linker script
case "$DEV" in
# H8/300H micros
H8/3068F) LDSCRIPT=nut-h8-3068f-$CODEMEM.ld ;;
H8/3069F) LDSCRIPT=nut-h8-3069f-$CODEMEM.ld ;; # just an example
# H8S micros
H8S/2676F) LDSCRIPT=nut-h8s-2676f-$CODEMEM.ld ;; # just an example
esac
# Make links to included make fragments
ln -s -f Makedefs.h8-gcc Makedefs
ln -s -f Makerules.h8-gcc Makerules
ln -s -f Makedefs.h8-gcc app/Makedefs
ln -s -f Makerules.h8-gcc app/Makerules
# Generate config file
cat <<EOF > UserConf.mk
DEVICE=$DEV # for future use
MCU=$ARCH
ARCH=$ARCH
MCUOPTS=$MCUOPTS
RUNFLAG=$RUNFLAG
LDSCRIPT=\$(top_srcdir)/arch/$ARCH/ldscripts/$LDSCRIPT
LDDIRS=$LDDIRS
BURN=h8write
BURNFLAGS=-3068 \$(TARG)
CRUROM = \$(top_srcdir)/tools/crurom/crurom
EOF
echo "Your system is now configured to build for $DEV."
echo "Type \`make\` to build the system."
exit 0
fi
# Set up environment for ARM microcontrollers ======================================================
if [ "$ARCH" = "arm" ]; then
# Verify if arm-elf-gcc is in the users PATH
if ! arm-elf-gcc --version >/dev/null 2>&1
then
echo "Can't find ARM gcc. :-("
echo ""
echo "This could mean either of the following:"
echo " 1: You don't have ARM GCC installed."
echo " 2: You don't have your PATH environment variable set right."
echo "Here is your PATH variable:"
echo ""
echo $PATH
echo ""
exit 1
fi
# Set up device dependant compiler flags
# if [ "$ARCH" = "h8300h" ]; then
# # flags for H8/300H micros
# MCUOPTS="-mh -mint32"
# else
# # flags for H8S micros
# MCUOPTS="-ms -mint32"
# fi
MCUOPTS="-mcpu=$CPU"
# Setup paths to libc and libgcc for linker
# GCCVER=`arm-elf-gcc --version|grep arm-elf-gcc|cut -d ' ' -f 3`
# GCCDIR=`dirname \`which arm-elf-gcc\``
# LIBGCCDIR="lib/gcc-lib/arm-elf/$GCCVER/$ARCH"
# LIBCDIR="arm-elf/lib/$ARCH"
# LDDIRS="-L $GCCDIR/../$LIBGCCDIR -L $GCCDIR/../$LIBCDIR"
# Ask which target board is being used
unset PLATFORM
while [ "x$PLATFORM" = "x" ]
do
echo "Do you use a standard board?"
echo ""
echo " 0) No standard"
if [ "$DEV" = "AT91R40008" ]; then
echo " 1) Ethernut 3"
fi
if [ "$DEV" = "AT91SAM7X256" ]; then
echo " 2) Atmel AT91SAM7X Evaluation Kit"
fi
if [ "$DEV" = "AT91SAM9260" ]; then
echo " 3) Atmel AT91SAM9260 Evaluation Kit"
fi
echo ""
echo -n "Selection -> "
read answ
case "$answ" in
0) ;;
1) PLATFORM=ETHERNUT3 ;;
2) PLATFORM=AT91SAM7X_EK ;;
3) PLATFORM=AT91SAM9260_EK ;;
*)
echo "invalid choice" ;;
esac
done
# Select linker script
if [ "$DEV" = "AT91SAM7X256" ]; then
LDNAME="at91sam7x256_rom"
else
echo "Nut/OS can be run from RAM. This is useful when you are"
echo "using a TFTP bootloader or debugging your application."
echo "Remember that your hardware must have enough RAM"
echo "to store data and program code."
echo ""
echo -n "Should Nut/OS be executed from RAM (default=Yes)? Y(es)/N(o) "
read answ
if [ "$answ" = "n" -o "$answ" = "N" ]; then
if [ "$DEV" = "AT91SAM9260" ]; then
LDNAME="at91sam9260_ram"
else
LDNAME="at91_boot"
fi
else
if [ "$DEV" = "AT91SAM9260" ]; then
LDNAME="at91sam9260_ram"
else
LDNAME="at91_ram"
fi
fi
fi
echo ""
# Make links to included make fragments
ln -s -f Makedefs.arm-gcc Makedefs
ln -s -f Makerules.arm-gcc Makerules
ln -s -f Makedefs.arm-gcc app/Makedefs
ln -s -f Makerules.arm-gcc app/Makerules
# Generate config file
cat <<EOF > UserConf.mk
PLATFORM=$PLATFORM
HWDEF+=-D\$(PLATFORM)
DEVICE=$DEV
MCU=$CPU
ARCH=$ARCH
MCUOPTS=$MCUOPTS
RUNFLAG=$RUNFLAG
LDNAME=$LDNAME
LDSCRIPT=\$(top_srcdir)/arch/arm/ldscripts/\$(LDNAME).ld
#LDDIRS=$LDDIRS
#BURN=jtagomat
#BURNFLAGS=\$(TARG)
CRUROM=crurom
EOF
echo "Your system is now configured to build for $DEV."
echo "Change to subdirectory lib and type \`make clean\` "
echo "and \`make install\` to build the system."
exit 0
fi
if [ "$ARCH" = "unix" ]; then
# Verify that gcc is in the users PATH
if ! gcc --version >/dev/null 2>&1
then
echo "Can't find gcc. :-("
echo ""
echo "This could mean either of the following:"
echo " 1: You don't have gcc installed."
echo " 2: You don't have your PATH environment variable set right."
echo "Here is your PATH variable:"
echo ""
echo $PATH
echo ""
exit 1
fi
# Make links to included make fragments
ln -s -f Makedefs.unix-gcc Makedefs
ln -s -f Makerules.unix-gcc Makerules
ln -s -f Makedefs.unix-gcc app/Makedefs
ln -s -f Makerules.unix-gcc app/Makerules
# Generate the config file
cat <<EOF > UserConf.mk
CRUROM = \$(top_srcdir)/tools/crurom/crurom
ARCH=$ARCH
MCU=$ARCH
EOF
# Get system include paths for stdio.h, errno.h, sys/types.h, fcntl.h
echo "#include <stdio.h>" > include_test.c
echo "#include <fcntl.h>" >> include_test.c
echo "#include <errno.h>" >> include_test.c
echo "#include <unistd.h>" >> include_test.c
echo "#include <netdb.h>" >> include_test.c
echo "#include <netinet/in.h>" >> include_test.c
echo "#include <sys/types.h>" >> include_test.c
echo "#include <sys/socket.h>" >> include_test.c
gcc -E include_test.c | grep stdio | head -1 | \
sed 's/#....\(\/.*\/stdio.h\).*/#include "\1"/' > include/stdio_orig.h
gcc -E include_test.c | grep unistd | head -1 | \
sed 's/#....\(\/.*\/unistd.h\).*/#include "\1"/' > include/unistd_orig.h
gcc -E include_test.c | grep fcntl | head -1 | \
sed 's/#....\(\/.*\/fcntl.h\).*/#include "\1"/' > include/fcntl_orig.h
gcc -E include_test.c | grep errno | head -1 | \
sed 's/#....\(\/.*\/errno.h\).*/#include "\1"/' > include/errno_orig.h
gcc -E include_test.c | grep "sys/types.h" | head -1 | \
sed 's/#....\(\/.*\/sys\/types.h\).*/#include "\1"/' > include/sys/types_orig.h
gcc -E include_test.c | grep "sys/socket" | head -1 | \
sed 's/#....\(\/.*\/sys\/socket.h\).*/#include "\1"/' > include/sys/socket_orig.h
gcc -E include_test.c | grep netdb | head -1 | \
sed 's/#....\(\/.*\/netdb.h\).*/#include "\1"/' > include/netdb_orig.h
gcc -E include_test.c | grep "netinet/in" | head -1 | \
sed 's/#....\(\/.*\/netinet\/in.h\).*/#include "\1"/' > include/netinet/in_orig.h
rm include_test.c
# assert lib dirs
mkdir -p lib/gcc/$ARCH
# ready
echo "Your system is now configured to build for your native system."
echo "Change to lib and type \`make\` to build the system."
exit 0
fi