openwifi/user_space/wgd.sh

175 lines
4.2 KiB
Bash
Raw Normal View History

2019-12-10 13:03:47 +00:00
#!/bin/bash
2021-02-03 15:01:04 +00:00
# Author: Xianjun Jiao
# SPDX-FileCopyrightText: 2022 UGent
2021-01-20 12:30:12 +00:00
# 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 " "
}
2019-12-10 13:03:47 +00:00
checkModule () {
MODULE_input="$1"
if lsmod | grep "$MODULE_input" &> /dev/null ; then
echo "$MODULE_input is loaded!"
2019-12-10 13:03:47 +00:00
return 0
else
echo "$MODULE_input is not loaded!"
2019-12-10 13:03:47 +00:00
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
}
2019-12-10 13:03:47 +00:00
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)
2019-12-10 13:03:47 +00:00
else
(set -x; insmod $TARGET_DIR_input/$MODULE_input.ko)
fi
checkModule $MODULE_input
if [ $? -eq 1 ]; then
exit 1
fi
}
print_usage
sync
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
2019-12-10 13:03:47 +00:00
fi
fi
echo TARGET_DIR $TARGET_DIR
echo DOWNLOAD_FLAG $DOWNLOAD_FLAG
echo test_mode $test_mode
sync
#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
2019-12-10 13:03:47 +00:00
fi
echo " "
2019-12-10 13:03:47 +00:00
service network-manager stop
2019-12-10 13:03:47 +00:00
rmmod sdr
insert_check_module ./ ad9361_drv
2019-12-10 13:03:47 +00:00
if [ $DOWNLOAD_FLAG -eq 1 ]; then
download_module fpga $TARGET_DIR
2019-12-10 13:03:47 +00:00
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.
2019-12-10 13:03:47 +00:00
fi
./rf_init_11n.sh
insert_check_module ./ xilinx_dma
2019-12-10 13:03:47 +00:00
depmod
modprobe mac80211
lsmod
2019-12-10 13:03:47 +00:00
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
2019-12-10 13:03:47 +00:00
if ps -p $(</tmp/check_calib_inf.pid) > /dev/null
then
kill $(</tmp/check_calib_inf.pid)
fi
./check_calib_inf.sh
2019-12-10 13:03:47 +00:00
echo the end
# dmesg
# lsmod