-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraspduino-setup
175 lines (160 loc) · 5.26 KB
/
raspduino-setup
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
#!/bin/sh
#
# This script prepares avrdude for raspduino.
#
# This script is copyright 2012 (C) BitWizard B.V.
# You're granted the right to use this script with your
# raspduino that you buy from BitWizard B.V. You have the
# right to look at this copyright message at the top and
# then decide that you're not allowed to run or copy it.
# All other rights reserved.
#
myid=`id -u`
if [ $myid -ne 0 ] ; then
echo "You need to run this script as root. e.g. sudo $0"
exit 1
fi
echo "---------- checking required packages ---------"
need_update=true
required_programs="avrdude arduino"
for i in $required_programs ; do
if [ ! -f /usr/bin/$i ] ; then
# $i is not installed, lets install it.
echo "----- Installing $i -----"
if [ -z `which apt-get` ] ; then
# Lets hope this works! (on arch).
pacman -S --noconfirm $i
else
if $need_update ; then
apt-get update
need_update=false
fi
apt-get -y install $i
fi
else
echo "OK: You already have $i installed "
fi
done
echo "----------- checking/updating avrdude -----------"
avrdudefile=`file /usr/bin/avrdude`
case "$avrdudefile" in
*"ELF 32-bit LSB executable, ARM"*)
#
echo "Replacing avrdude with script to reset raspduino"
if [ ! -f /usr/bin/avrdude.bin ] ; then
mv /usr/bin/avrdude /usr/bin/avrdude.bin
else
echo "Avrdude.bin already exists. Cannot continue."
exit 1
fi
cat << EOF > /usr/bin/avrdude
#!/bin/sh
# This script replaces avrdude and resets the raspduino
# in case you don't have the software DTR patch.
[ -f /etc/have_software_DTR ] || sudo reset_raspduino
avrdude.bin "\$@"
EOF
chmod 755 /usr/bin/avrdude
;;
*"POSIX shell script"*)
echo "OK: It seems this script has already been run. No changes. Done!"
;;
*)
echo "Your avrdude is weird. Not an arm executeable but neither a shell script. "
echo "cannot continue."
exit 1
;;
esac
echo ---------- checking reset_raspduino ----------------
file=/usr/bin/reset_raspduino
if [ ! -f $file ] ; then
echo "Creating reset_raspduino"
cat << EOF > $file
#!/bin/sh
gpio_num=18
echo \$gpio_num > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio\$gpio_num/direction
echo 1 > /sys/class/gpio/gpio\$gpio_num/value
sleep 0.05
echo 0 > /sys/class/gpio/gpio\$gpio_num/value
echo \$gpio_num > /sys/class/gpio/unexport
EOF
chmod 755 $file
else
echo "OK: you allready have a reset_raspduino. "
fi
echo ------------- checking raspduino.rules -----------------
file=/etc/udev/rules.d/80-raspduino.rules
if [ ! -f $file ] ; then
echo "creating 80 raspduino rules (link ttyAMA to ttyS0)."
echo 'KERNEL=="ttyAMA0", SYMLINK+="ttyS0",GROUP="dialout",MODE:=0666' \
> $file
else
echo "OK: You already have a raspduino.rules."
fi
echo ------------- checking inittab -----------------
file=/etc/inittab
if grep -q ttyAMA0 $file ; then
# ttyAMA0 is present in inittab...
if grep -q ^[^#].*ttyAMA0 $file ; then
# ... and not commented out. Lets do that.
echo "removing getty entry for ttyAMA0 from /etc/inittab"
cp -p $file "$file".orig
sed -e 's/\(.*\)ttyAMA0/#\1ttyAMA0/' "$file".orig > $file
else
echo "OK: You already have ttyAMA commented out. Good."
fi
else
# No ttyAMA in inittab
echo "OK: You have no ttyAMA in your inittab. That's weird for a Raspberry pi system."
# Lets assume that's ok.
fi
echo ------------- checking upstart -----------------
file=/etc/init/ttyAMA0.conf
if [ -f $file ] ; then
if ! grep -q manual $file ; then
echo "Disable autostart of ttyAMA getty."
# the .orig extension causes the file to be ignored by upstart.
cp $file $file.orig
echo manual >> $file
else
echo "OK: Your ttyAMA upstart config is already disabled. Good."
fi
else
echo "OK: You seem to not have ttyAMA0 upstart config. Fine."
fi
echo ------------- checking cmdline.txt -----------------
if grep -q ttyAMA0 /boot/cmdline.txt ; then
echo "removing ttyAMA0 as console from cmdline."
mv /boot/cmdline.txt /boot/cmdline.txt.orig
# remove ttyAMA references from cmdline.txt. Usually console= and kgdboc= .
sed -e 's/[^ ]*ttyAMA0[^ ]*//g' /boot/cmdline.txt.orig > /boot/cmdline.txt
else
echo "OK: Your ttyAMA was already removed from cmdline.txt"
fi
echo ------------- checking boards.txt -----------------
file=/usr/share/arduino/hardware/arduino/boards.txt
if ! grep -q raspduino $file ; then
echo "... adding raspduino to arduino hardware list. "
cp $file $file.orig
cat <<EOF >> $file
##############################################################
raspduino.name=Raspduino
raspduino.upload.protocol=arduino
raspduino.upload.maximum_size=30720
raspduino.upload.speed=57600
raspduino.bootloader.low_fuses=0xff
raspduino.bootloader.high_fuses=0xda
raspduino.bootloader.extended_fuses=0x05
raspduino.bootloader.path=atmega
raspduino.bootloader.file=ATmegaBOOT_328_diecimila.hex
raspduino.bootloader.unlock_bits=0x3F
raspduino.bootloader.lock_bits=0x0F
raspduino.build.mcu=atmega328p
raspduino.build.f_cpu=16000000L
raspduino.build.core=arduino
raspduino.build.variant=standard
EOF
else
echo "OK: your boards.txt already has raspduino"
fi