Add dynamic reloading driver and FPGA

Rebooting/power-cycle is not needed anymore!
This commit is contained in:
Xianjun Jiao 2022-05-13 17:01:41 +02:00
parent 1e86c1aa7d
commit 94847d8099
8 changed files with 351 additions and 237 deletions

View File

@ -53,6 +53,12 @@ set -ex
# check if user entered the right path to SDK
source $XILINX_DIR/SDK/2018.3/settings64.sh
# uncompress the system.hdf and system_top.bit for use
mkdir -p hdf_and_bit
tar -zxvf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/hdf_and_bit.tar.gz -C ./hdf_and_bit
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system.hdf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system_top.bit $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
cd $OPENWIFI_DIR/kernel_boot
./build_boot_bin.sh $OPENWIFI_HW_DIR $BOARD_NAME

View File

@ -53,6 +53,12 @@ set -ex
# check if user entered the right path to SDK
source $XILINX_DIR/SDK/2018.3/settings64.sh
# uncompress the system.hdf and system_top.bit for use
mkdir -p hdf_and_bit
tar -zxvf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/hdf_and_bit.tar.gz -C ./hdf_and_bit
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system.hdf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system_top.bit $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
cd $OPENWIFI_DIR/kernel_boot
./build_zynqmp_boot_bin.sh $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/system.hdf boards/$BOARD_NAME/u-boot-zcu.elf boards/$BOARD_NAME/bl31.elf

View File

@ -0,0 +1,104 @@
#!/bin/bash
# Author: Xianjun Jiao
# SPDX-FileCopyrightText: 2022 UGent
# SPDX-License-Identifier: AGPL-3.0-or-later
if [ "$#" -ne 3 ]; then
echo "You have input $# arguments."
echo "You must enter exactly 3 arguments: \$OPENWIFI_HW_DIR \$XILINX_DIR \$BOARD_NAME"
exit 1
fi
OPENWIFI_HW_DIR=$1
XILINX_DIR=$2
BOARD_NAME=$3
if [ -d "$XILINX_DIR/SDK" ]; then
echo "\$XILINX_DIR is found!"
else
echo "\$XILINX_DIR is not correct. Please check!"
exit 1
fi
if [ "$BOARD_NAME" != "antsdr" ] && [ "$BOARD_NAME" != "zc706_fmcs2" ] && [ "$BOARD_NAME" != "zc702_fmcs2" ] && [ "$BOARD_NAME" != "zed_fmcs2" ] && [ "$BOARD_NAME" != "adrv9361z7035" ] && [ "$BOARD_NAME" != "adrv9364z7020" ] && [ "$BOARD_NAME" != "zcu102_fmcs2" ] && [ "$BOARD_NAME" != "zcu102_9371" ]; then
echo "\$BOARD_NAME is not correct. Please check!"
exit 1
else
echo "\$BOARD_NAME is found!"
fi
if [ -d "$OPENWIFI_HW_DIR/boards/$BOARD_NAME" ]; then
echo "\$OPENWIFI_HW_DIR is found!"
else
echo "\$OPENWIFI_HW_DIR is not correct. Please check!"
exit 1
fi
# uncompress the system.hdf and system_top.bit for use
mkdir -p hdf_and_bit
tar -zxvf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/hdf_and_bit.tar.gz -C ./hdf_and_bit
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system.hdf $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
cp ./hdf_and_bit/$BOARD_NAME/sdk/system_top_hw_platform_0/system_top.bit $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/ -rf
BIT_FILENAME=$OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/system_top_hw_platform_0/system_top.bit
if [ -f "$BIT_FILENAME" ]; then
echo "\$BIT_FILENAME is found!"
else
echo "\$BIT_FILENAME does NOT exist. Please check!"
exit 1
fi
if [ "$BOARD_NAME" == "zcu102_fmcs2" ] || [ "$BOARD_NAME" == "zcu102_9371" ]; then
ARCH="zynqmp"
ARCH_BIT=64
else
ARCH="zynq"
ARCH_BIT=32
fi
# FINAL_BIT_FILENAME=$BOARD_NAME\_system_top_reload.bit.bin
source $XILINX_DIR/SDK/2018.3/settings64.sh
set -x
cp $BIT_FILENAME ./
bootgen -image system_top.bif -arch $ARCH -process_bitstream bin -w
# cp system_top_reload.bit.bin ./$FINAL_BIT_FILENAME
cd ../driver
./make_all.sh $XILINX_DIR $ARCH_BIT
cd ../user_space
mkdir -p drv_and_fpga
rm -rf drv_and_fpga/*
cp system_top.bit.bin ../driver/tx_intf/tx_intf.ko ../driver/rx_intf/rx_intf.ko ../driver/openofdm_tx/openofdm_tx.ko ../driver/openofdm_rx/openofdm_rx.ko ../driver/xpu/xpu.ko ../driver/sdr.ko ./drv_and_fpga -f
cp $OPENWIFI_HW_DIR/boards/$BOARD_NAME/sdk/git_info.txt ./drv_and_fpga -f
tar -cvf ./drv_and_fpga/driver.tar $(git ls-files ../driver/)
dir_save=$(pwd)
cd $OPENWIFI_HW_DIR/ip/
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-root.tar $(git ls-files ./ | grep -v -E "/|openofdm_rx")
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-xpu.tar $(git ls-files ./xpu)
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-tx_intf.tar $(git ls-files ./tx_intf)
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-rx_intf.tar $(git ls-files ./rx_intf)
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-openofdm_tx.tar $(git ls-files ./openofdm_tx)
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-ip-side_ch.tar $(git ls-files ./side_ch)
cd ../boards
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-boards-root.tar $(git ls-files ./ | grep -v "/")
cd ./$BOARD_NAME
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-boards-$BOARD_NAME-root.tar $(git ls-files ./ | grep -v "/")
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-boards-$BOARD_NAME-src.tar $(git ls-files ./src)
tar -cvf $dir_save/drv_and_fpga/openwifi-hw-boards-$BOARD_NAME-ip_repo.tar ip_repo
cd $dir_save
# tar -cvf drv_and_fpga.tar system_top.bit.bin tx_intf.ko rx_intf.ko openofdm_tx.ko openofdm_rx.ko xpu.ko sdr.ko git_info.txt
tar -zcvf drv_and_fpga.tar.gz drv_and_fpga
set +x

View File

@ -4,19 +4,19 @@
# SPDX-FileCopyrightText: 2019 UGent
# SPDX-License-Identifier: AGPL-3.0-or-later
test_mode=$1
if [ -z $test_mode ]
then
test_mode=0
fi
echo test_mode $test_mode
# test_mode=$1
# if [ -z $test_mode ]
# then
# test_mode=0
# fi
# echo test_mode $test_mode
killall hostapd
killall webfsd
cd ~/openwifi
service network-manager stop
./wgd.sh $test_mode
# ./wgd.sh $test_mode
ifconfig sdr0 192.168.13.1
route add default gw 192.168.10.1
service isc-dhcp-server restart

View File

@ -4,19 +4,19 @@
# SPDX-FileCopyrightText: 2019 UGent
# SPDX-License-Identifier: AGPL-3.0-or-later
test_mode=$1
if [ -z $test_mode ]
then
test_mode=0
fi
echo test_mode $test_mode
# test_mode=$1
# if [ -z $test_mode ]
# then
# test_mode=0
# fi
# echo test_mode $test_mode
killall hostapd
killall webfsd
cd ~/openwifi
service network-manager stop
./wgd.sh $test_mode
# ./wgd.sh $test_mode
ifconfig sdr0 192.168.13.1
route add default gw 192.168.10.1
service isc-dhcp-server restart

81
user_space/load_fpga_img.sh Executable file
View File

@ -0,0 +1,81 @@
#!/bin/bash
# Author: Xianjun Jiao
# SPDX-FileCopyrightText: 2022 UGent
# SPDX-License-Identifier: AGPL-3.0-or-later
# get fpga image file name
if [[ -n $1 ]]; then
fpga_img_filename=$1
else
fpga_img_filename=system_top.bit.bin
fi
fpga_type=$(cat /proc/device-tree/compatible)
fpga_img_filename_core=${fpga_img_filename##*/}
echo $fpga_type
echo $fpga_img_filename
echo $fpga_img_filename_core
set -x
ifconfig sdr0 down
rmmod sdr
# rmmod mac80211
# rmmod cfg80211
# rmmod ad9361_drv
# rmmod xilinx_dma.ko
rmmod openofdm_rx
rmmod openofdm_tx
rmmod rx_intf
rmmod tx_intf
rmmod xpu
sleep 1
echo 0 > /sys/class/fpga_manager/fpga0/flags
mkdir -p /lib/firmware
cp $fpga_img_filename /lib/firmware/
echo $fpga_img_filename_core > /sys/class/fpga_manager/fpga0/firmware
# insmod ad9361_drv.ko
# sleep 1
if [ "$fpga_type" != "xlnx,zynq-7000" ]; then
SPI_DEVNAME="spi1.0"
DDS_DEVNAME="99024000.cf-ad9361-dds-core-lpc"
ADC_DEVNAME="99020000.cf-ad9361-lpc"
else
SPI_DEVNAME="spi0.0"
DDS_DEVNAME="79024000.cf-ad9361-dds-core-lpc"
ADC_DEVNAME="79020000.cf-ad9361-lpc"
fi
while [ ! -d "/sys/bus/spi/drivers/ad9361/$SPI_DEVNAME" ]
do
echo "Waiting for /sys/bus/spi/drivers/ad9361/$SPI_DEVNAME"
sleep 0.2
done
cd /sys/bus/spi/drivers/ad9361/
echo $SPI_DEVNAME > unbind
echo $SPI_DEVNAME > bind
while [ ! -d "/sys/bus/platform/drivers/cf_axi_dds/$DDS_DEVNAME" ]
do
echo "Waiting for /sys/bus/platform/drivers/cf_axi_dds/$DDS_DEVNAME"
sleep 0.2
done
cd /sys/bus/platform/drivers/cf_axi_dds/
echo $DDS_DEVNAME > unbind
echo $DDS_DEVNAME > bind
while [ ! -d "/sys/bus/platform/drivers/cf_axi_adc/$ADC_DEVNAME" ]
do
echo "Waiting for /sys/bus/platform/drivers/cf_axi_adc/$ADC_DEVNAME"
sleep 0.2
done
cd /sys/bus/platform/drivers/cf_axi_adc/
echo $ADC_DEVNAME > unbind
echo $ADC_DEVNAME > bind
set +x

View File

@ -0,0 +1,4 @@
all:
{
system_top.bit /* Bitstream file name */
}

View File

@ -1,251 +1,167 @@
#!/bin/bash
# Author: Xianjun Jiao
# SPDX-FileCopyrightText: 2019 UGent
# 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="$1"
if lsmod | grep "$MODULE" &> /dev/null ; then
echo "$MODULE is loaded!"
MODULE_input="$1"
if lsmod | grep "$MODULE_input" &> /dev/null ; then
echo "$MODULE_input is loaded!"
return 0
else
echo "$MODULE is not loaded!"
echo "$MODULE_input is not loaded!"
return 1
fi
}
num_arg=$#
echo "num_arg " $num_arg
for input_var in "$@"
do
last_input=$input_var
# echo $last_input
done
if [ -z $last_input ]
then
last_input="unset"
test_mode=0
else
if [ $1 -eq 1 ]
then
test_mode=1
elif [ $1 -eq 2 ]
then
test_mode=2
elif [ $1 -eq 3 ]
then
test_mode=3
elif [ $1 -eq 4 ]
then
test_mode=4
elif [ $1 -eq 5 ]
then
test_mode=5
elif [ $1 -eq 6 ]
then
test_mode=6
elif [ $1 -eq 7 ]
then
test_mode=7
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
test_mode=0
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
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
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 last_input $last_input
echo test_mode $test_mode
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 " "
service network-manager stop
rmmod sdr
insert_check_module ./ ad9361_drv
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.
fi
./rf_init_11n.sh
insert_check_module ./ xilinx_dma
depmod
modprobe mac80211
lsmod
# dmesg -c
PROG=sdr
rmmod $PROG
# mv ad9361 driver to local folder, to prevent booting issue
if [ -f /lib/modules/$(uname -r)/ad9361_drv.ko ]; then
mv /lib/modules/$(uname -r)/ad9361_drv.ko .
fi
SUBMODULE=ad9361_drv
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
sleep 1
lsmod
# mv xilinx dma driver to local folder, to prevent booting issue
if [ -f /lib/modules/$(uname -r)/xilinx_dma.ko ]; then
mv /lib/modules/$(uname -r)/xilinx_dma.ko .
fi
SUBMODULE=xilinx_dma
rmmod $SUBMODULE
insmod $SUBMODULE.ko
#sleep 1
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
sleep 1
lsmod
# before drive ad9361, let's bring up duc and make sure dac is connected to ad9361 dma
SUBMODULE=tx_intf
if [ $last_input == "remote" ]
then
rm $SUBMODULE.ko
sync
wget ftp://192.168.10.1/driver/$SUBMODULE/$SUBMODULE.ko
sync
fi
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
sleep 0.5
echo "set RF frontend"
# if [ $last_input == "remote" ]
# then
# rm rf_init.sh
# sync
# wget ftp://192.168.10.1/user_space/rf_init.sh
# sync
# chmod +x rf_init.sh
# sync
# fi
# if [ $tx_offset_tuning_enable = "1" ]
# then
./rf_init_11n.sh
# else
# ./rf_init.sh tx_offset_tuning_disable
# fi
#sleep 1
SUBMODULE=rx_intf
if [ $last_input == "remote" ]
then
rm $SUBMODULE.ko
sync
wget ftp://192.168.10.1/driver/$SUBMODULE/$SUBMODULE.ko
sync
fi
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
SUBMODULE=openofdm_tx
if [ $last_input == "remote" ]
then
rm $SUBMODULE.ko
sync
wget ftp://192.168.10.1/driver/$SUBMODULE/$SUBMODULE.ko
sync
fi
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
SUBMODULE=openofdm_rx
if [ $last_input == "remote" ]
then
rm $SUBMODULE.ko
sync
wget ftp://192.168.10.1/driver/$SUBMODULE/$SUBMODULE.ko
sync
fi
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
SUBMODULE=xpu
if [ $last_input == "remote" ]
then
rm $SUBMODULE.ko
sync
wget ftp://192.168.10.1/driver/$SUBMODULE/$SUBMODULE.ko
sync
fi
rmmod $SUBMODULE
insmod $SUBMODULE.ko
echo check $SUBMODULE module is loaded or not
checkModule $SUBMODULE
if [ $? -eq 1 ]
then
return
fi
sleep 0.5
PROG=sdr
if [ $last_input == "remote" ]
then
rm $PROG.ko
sync
wget ftp://192.168.10.1/driver/$PROG.ko
sync
fi
rmmod $PROG
echo insert $PROG.ko test_mode=$test_mode
insmod $PROG.ko test_mode=$test_mode
echo check $PROG module is loaded or not
checkModule $PROG
if [ $? -eq 1 ]
then
return
fi
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
if ps -p $(</tmp/check_calib_inf.pid) > /dev/null
then
@ -254,8 +170,5 @@ fi
./check_calib_inf.sh
echo the end
dmesg
# dmesg -c
# sleep 0.1
# ifconfig sdr0 up
# dmesg
# lsmod