-
Notifications
You must be signed in to change notification settings - Fork 659
/
wgd.sh
executable file
·175 lines (152 loc) · 4.42 KB
/
wgd.sh
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/bash
# Author: Xianjun Jiao
# SPDX-FileCopyrightText: 2022 UGent
# SPDX-License-Identifier: AGPL-3.0-or-later
print_usage () {
echo "usage:"
echo " Script for load (or download+load) different driver and FPGA img without rebooting"
echo " no argument: Load .ko driver files and FPGA img (if system_top.bit.bin exist) in current dir with test_mode=0."
echo " 1st argument: If it is a NUMBER, it will be assigned to test_mode. Then load everything from current dir."
echo " 1st argument: If it is a string called \"remote\", it will download driver/FPGA and load everything."
echo " - 2nd argument (if exist) is the target directory name for downloading and reloading"
echo " - 3rd argument (if exist) is the value for test_mode"
echo " 1st argument: neither NUMBER nor \"remote\" nor a .tar.gz file, it is regarded as a directory and load everything from it."
echo " - 2nd argument (if exist) is the value for test_mode"
echo " 1st argument: a .tar.gz file, it will be unpacked then load from that unpacked directory"
echo " - 2nd argument (if exist) is the value for test_mode"
echo " "
}
checkModule () {
MODULE_input="$1"
if lsmod | grep "$MODULE_input" &> /dev/null ; then
echo "$MODULE_input is loaded!"
return 0
else
echo "$MODULE_input is not loaded!"
return 1
fi
}
download_module () {
MODULE_input="$1"
TARGET_DIR_input="$2"
mkdir -p $TARGET_DIR_input
if [ "$MODULE_input" == "fpga" ]; then
wget -O $TARGET_DIR_input/system_top.bit.bin ftp://192.168.10.1/user_space/system_top.bit.bin
else
if [ "$MODULE_input" == "sdr" ]; then
wget -O $TARGET_DIR_input/$MODULE_input.ko ftp://192.168.10.1/driver/$MODULE_input.ko
else
wget -O $TARGET_DIR_input/$MODULE_input.ko ftp://192.168.10.1/driver/$MODULE_input/$MODULE_input.ko
fi
fi
sync
}
insert_check_module () {
TARGET_DIR_input="$1"
MODULE_input="$2"
rmmod $MODULE_input
if [[ -n $3 ]]; then
(set -x; insmod $TARGET_DIR_input/$MODULE_input.ko test_mode=$3)
else
(set -x; insmod $TARGET_DIR_input/$MODULE_input.ko)
fi
checkModule $MODULE_input
if [ $? -eq 1 ]; then
exit 1
fi
}
print_usage
insmod ad9361_drv.ko
insmod xilinx_dma.ko
# modprobe ad9361_drv
# modprobe xilinx_dma
modprobe mac80211
lsmod
TARGET_DIR=./
DOWNLOAD_FLAG=0
test_mode=0
if [[ -n $1 ]]; then
re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then # not a number
if [ "$1" == "remote" ]; then
DOWNLOAD_FLAG=1
if [[ -n $2 ]]; then
TARGET_DIR=$2
fi
if [[ -n $3 ]]; then
test_mode=$3
fi
else
if [[ "$1" == *".tar.gz"* ]]; then
set -x
tar_gz_filename=$1
TARGET_DIR=${tar_gz_filename%".tar.gz"}
mkdir -p $TARGET_DIR
rm -rf $TARGET_DIR/*
tar -zxvf $1 -C $TARGET_DIR
find $TARGET_DIR/ -name \*.ko -exec cp {} $TARGET_DIR/ \;
find $TARGET_DIR/ -name \*.bit.bin -exec cp {} $TARGET_DIR/ \;
set +x
else
TARGET_DIR=$1
fi
if [[ -n $2 ]]; then
test_mode=$2
fi
fi
else # is a number
test_mode=$1
fi
fi
echo TARGET_DIR $TARGET_DIR
echo DOWNLOAD_FLAG $DOWNLOAD_FLAG
echo test_mode $test_mode
#if ((($test_mode & 0x2) != 0)); then
tx_offset_tuning_enable=0
#else
# tx_offset_tuning_enable=1
#fi
echo tx_offset_tuning_enable $tx_offset_tuning_enable
if [ -d "$TARGET_DIR" ]; then
echo "\$TARGET_DIR is found!"
else
if [ $DOWNLOAD_FLAG -eq 0 ]; then
echo "\$TARGET_DIR is not correct. Please check!"
exit 1
fi
fi
echo " "
killall hostapd
service dhcpcd stop #dhcp client. it will get secondary ip for sdr0 which causes trouble
killall dhcpd
killall wpa_supplicant
#service network-manager stop
ifconfig sdr0 down
rmmod sdr
if [ $DOWNLOAD_FLAG -eq 1 ]; then
download_module fpga $TARGET_DIR
fi
if [ -f "$TARGET_DIR/system_top.bit.bin" ]; then
./load_fpga_img.sh $TARGET_DIR/system_top.bit.bin
else
echo $TARGET_DIR/system_top.bit.bin not found. Skip reloading FPGA.
# ./load_fpga_img.sh fjdo349ujtrueugjhj
fi
./rf_init_11n.sh
MODULE_ALL="tx_intf rx_intf openofdm_tx openofdm_rx xpu sdr"
for MODULE in $MODULE_ALL
do
if [ $DOWNLOAD_FLAG -eq 1 ]; then
download_module $MODULE $TARGET_DIR
fi
if [ "$MODULE" == "sdr" ]; then
insert_check_module $TARGET_DIR $MODULE $test_mode
else
insert_check_module $TARGET_DIR $MODULE
fi
done
# [ -e /tmp/check_calib_inf.pid ] && kill -0 $(</tmp/check_calib_inf.pid)
# ./check_calib_inf.sh
echo the end
# dmesg
# lsmod