-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathupdate
executable file
·195 lines (173 loc) · 5.03 KB
/
update
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
#!/bin/sh
# takes no arguments,
# updates the ./pluto.frm and ./boot.frm from the PlutoSDR firmware
# on a linix machine. Tested on debian.
# also assumes a default ./ssh/config file for Pluto (per the wiki)
pluto_dev()
{
echo $(ls -l /dev/disk/by-label/ 2>/dev/null | grep PlutoSDR | awk -F/ '{print $NF}')
}
# takes one argument - the number of seconds (as an int) to wait
wait_for_pluto()
{
time=$1
i=0
until grep -qs 'PlutoSDR' /proc/mounts ;
do
dev=$(pluto_dev)
if [ "`echo ${dev}| wc -c`" -gt "1" ] ; then
# try to mount it
udisksctl mount -b /dev/${dev} > /dev/null 2>&1
fi
# pause for a bit
sleep 1
i=$(expr $i + 1)
if [ "$i" -gt "$time" ] ; then
echo timed out waiting for PlutoSDR to be mounted $i
exit
fi
done
dev=/dev/$(pluto_dev | sed -e 's:[0-9]$::')
disk=$(grep ${dev} /proc/mounts | awk '{print $2}')
ipaddr=$(grep "^ipaddr =" ${disk}/config.txt | awk '{print $NF}')
# Just because the drive is up, doesn't mean the host kernel
# has loaded/initialized the network - which can come up later
# so we need to wait for that as well
while ! $(ping -c 1 -w 1 -W 1 ${ipaddr} 2>&1 > /dev/null)
do
i=$(expr $i + 1)
if [ "$i" -gt "$time" ] ; then
echo timed out waiting for network to come up $i
exit
fi
# do not need a sleep in this loop, the pause is in the ping command
done
}
ssh_cmd()
{
sshpass -v -panalog ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oCheckHostIP=no root@${ipaddr} "$1" 2>/dev/null
if [ "$?" -ne "0" ] ; then
echo ssh command $1 failed
exit
fi
}
reset_pluto()
{
echo resetting pluto at ${dev} ${disk} ${ipaddr}
ssh_cmd '/usr/sbin/pluto_reboot reset'
sleep 2
wait_for_pluto 10
}
# find the argument in the info.html file
pluto_value()
{
echo $(grep -A 1 "<td>${1}</td>" ${disk}/info.html | \
tail -1 | \
sed -e 's/^.*<td>//' -e 's/<\/td>//')
}
command sshpass >/dev/null 2>&1
if [ "$?" -ne "0" ] ; then
echo sorry, your distribution needs to have 'sshpass' installed
echo try \'sudo apt-get install sshpass\' OR \'sudo yum install sshpass\'
exit
fi
if [ ! -r ./pluto.frm ] ; then
echo "can not find the pluto.frm in the currect directory, attemping to download"
file=$(curl -s https://api.github.com/repos/analogdevicesinc/plutosdr-fw/releases/latest | grep 'browser_' | cut -d\" -f4)
if [ "x$file" != "x" ] ; then
wget -q $file
file=$(echo $file|awk -F/ '{print $NF}')
unzip -q ${file}
version=$(pluto_value "Build")
echo installed version is: ${version}
echo downloaded version is ${file}
echo -n "are you sure you want to upgrade? (y/n): "
read answer
finish="-1"
while [ "$finish" = '-1' ]
do
finish="1"
if [ "$answer" = '' ]; then
answer=""
else
case $answer in
y | Y | yes | YES ) answer="y";;
n | N | no | NO ) answer="n";;
*) finish="-1";
echo -n 'Invalid response -- please reenter:';
read answer;;
esac
fi
done
if [ "$answer" = "n" ] ; then
echo "OK, quiting without upgrade"
exit
fi
echo "upgrading"
else
echo failed to download
exit
fi
fi
if [ ! -r ./boot.frm ] ; then
echo "can not find the boot.frm in the currect directory"
exit
fi
#Make sure a device is plugged in, and you can find it
echo Please plug in a PlutoSDR
# try DFU, in case something is bricked
command dfu-util -V >/dev/null 2>&1
if [ "$?" = "0" ] ; then
if [ "$(dfu-util -l -d 0456:b673,0456:b674 | wc -l)" -gt "8" ] ; then
echo "recovering PlutoSDR via DFU"
echo "*** DO NOT UNPLUG"
dfu-util -d 0456:b673,0456:b674 -D pluto.dfu -a pluto.dfu >/dev/null
if [ "$?" -ne "0" ] ; then
echo "found, and tried programming dfu, and failed"
if [ "$(id -u)" != "0" ]; then
echo maybe you need to run as root?
fi
exit
fi
echo power cycle device, and then run again
exit
fi
else
echo dfu-util not installed, not checking for non-booting device
fi
wait_for_pluto 30
dd if=${dev} of=/dev/null count=1 bs=1 > /dev/null 2>&1
if [ "$?" -ne "0" ] ; then
echo you do not have permissions to eject the disk: $dev
if [ "$(id -u)" != "0" ]; then
echo maybe you need to run as root?
fi
exit
fi
SERIAL=$(pluto_value "Serial")
echo "Disk : $disk"
echo "Device : $dev"
echo "Serial : $SERIAL"
echo "IPaddr : $ipaddr"
echo updating kernel and ramfs
echo "*** DO NOT UNPLUG"
cp ./pluto.frm $disk && eject $dev && sleep 1
wait_for_pluto 300
reset_pluto
echo updating FPGA image and bootloaders on $disk $dev
echo "*** DO NOT UNPLUG"
cp ./boot.frm $disk && eject $dev && sleep 1
wait_for_pluto 120
reset_pluto
there=$(ssh_cmd '/usr/sbin/fw_printenv' | grep attr_name | wc -l)
if [ "$there" -gt "0" ] ; then
ssh_cmd 'echo 0x037 > /sys/kernel/debug/iio/iio:device1/direct_reg_access'
device_id=$(ssh_cmd 'cat /sys/kernel/debug/iio/iio:device1/direct_reg_access')
if [ "p${device_id}" = "p0xA" ] ; then
echo updating to AD9364
ssh_cmd '/usr/sbin/fw_setenv attr_name compatible'
ssh_cmd '/usr/sbin/fw_setenv attr_val ad9364'
reset_pluto
fi
fi
echo Done