Update fpgactl usage

This commit is contained in:
Rodrigo Arias Mallo 2024-03-04 16:53:03 +01:00
parent bd2b8b1bc5
commit cf94b5a46a

View File

@ -9,43 +9,12 @@
# Stop on first error # Stop on first error
set -e set -e
function usage() # {{{
{
echo "Loads a bitstream CPU into an FPGA and boots an image" >&2
echo "Usage: $0 [-s slot] [-r] [-b] [-w bitstream]" >&2
echo "" >&2
echo "Loads a bitstream CPU into an FPGA and boots an image" >&2
echo "" >&2
echo "Options" >&2
echo " -s slot Use the given FPGA slot (default 8)" >&2
echo " -w bitfile Write the bitstream file to the FPGA" >&2
echo " -r Reload filesystem only" >&2
echo " -b Boot only" >&2
echo "Options" >&2
exit 1
} # }}}
function is_module_loaded() # {{{ function is_module_loaded() # {{{
{ {
lsmod | grep -wq "$1" lsmod | grep -wq "$1"
} # }}} } # }}}
function check_environment() # {{{ function check_environment() # {{{
{ {
# Check that all drivers are loaded and programs are available
# if ! lsmod | grep -q qdma_pf; then
# echo 'error: driver qdma_pf not loaded' >&2
# echo 'tip: sudo insmod /home/tools/drivers/cucu/dma_ip_drivers-onic-gamma/xilinx_pcie_drivers/QDMA/linux-kernel/bin/qdma-pf.ko' >&2
# exit 1
# fi
#
# if ! lsmod | grep -q qdma_vf; then
# echo 'error: driver qdma_vf not loaded' >&2
# echo 'tip: sudo insmod /home/tools/drivers/cucu/dma_ip_drivers-onic-gamma/xilinx_pcie_drivers/QDMA/linux-kernel/bin/qdma-vf.ko' >&2
# exit 1
# fi
if ! command -v dma-ctl &> /dev/null; then if ! command -v dma-ctl &> /dev/null; then
echo "error: dma-ctl not found in PATH" >&2 echo "error: dma-ctl not found in PATH" >&2
exit 1 exit 1
@ -56,7 +25,6 @@ function check_environment() # {{{
exit 1 exit 1
fi fi
} # }}} } # }}}
function create_qdma_queue() # {{{ function create_qdma_queue() # {{{
{ {
pcidir="/sys/bus/pci/devices/0000:08:00.0" pcidir="/sys/bus/pci/devices/0000:08:00.0"
@ -97,7 +65,6 @@ function create_qdma_queue() # {{{
sleep 2 sleep 2
} # }}} } # }}}
function do_system_reset() # {{{ function do_system_reset() # {{{
{ {
# UartBootEn (bit2) + system reset (bit0) # UartBootEn (bit2) + system reset (bit0)
@ -107,13 +74,11 @@ function do_system_reset() # {{{
dma-ctl qdma08000 reg write bar 2 0x0 0x1 > /dev/null dma-ctl qdma08000 reg write bar 2 0x0 0x1 > /dev/null
#sleep 5 #sleep 5
} # }}} } # }}}
function do_system_release() # {{{ function do_system_release() # {{{
{ {
# Release Ariane's reset # Release Ariane's reset
dma-ctl qdma08000 reg write bar 2 0x0 0x3 > /dev/null dma-ctl qdma08000 reg write bar 2 0x0 0x3 > /dev/null
} # }}} } # }}}
function copy_by_dma() # {{{ function copy_by_dma() # {{{
{ {
ifile="$1" ifile="$1"
@ -138,11 +103,11 @@ function copy_by_dma() # {{{
done done
} # }}} } # }}}
function load_file_in_memory() # {{{ function load_file_in_memory() # {{{
{ {
file="$1" file="$1"
address="$2" address_hex="$2"
address=$(($address_hex))
# Previous tests... # Previous tests...
#strace -f dma-to-device -d /dev/qdma08000-MM-1 -a "$address" -s $((8*1024*1024)) -f "$file" #strace -f dma-to-device -d /dev/qdma08000-MM-1 -a "$address" -s $((8*1024*1024)) -f "$file"
@ -155,7 +120,6 @@ function load_file_in_memory() # {{{
dd if="$file" bs=8M seek="${address}" oflag=seek_bytes of=/dev/qdma08000-MM-1 status=none dd if="$file" bs=8M seek="${address}" oflag=seek_bytes of=/dev/qdma08000-MM-1 status=none
} # }}} } # }}}
function do_boot_only() # {{{ function do_boot_only() # {{{
{ {
do_system_reset do_system_reset
@ -185,7 +149,6 @@ function do_boot_only() # {{{
#sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 mtu 9000 up #sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 mtu 9000 up
sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 up sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 up
} # }}} } # }}}
function do_reload_fs() # {{{ function do_reload_fs() # {{{
{ {
do_system_reset do_system_reset
@ -211,7 +174,6 @@ function do_reload_fs() # {{{
# uncomment to enable eth-over-pcie # uncomment to enable eth-over-pcie
# sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 mtu 9000 up # sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 mtu 9000 up
} # }}} } # }}}
function upload_bitstream_file() # {{{ function upload_bitstream_file() # {{{
{ {
bitfile="$1" bitfile="$1"
@ -240,7 +202,6 @@ EOF
killall hw_server killall hw_server
} # }}} } # }}}
function unload_modules() # {{{ function unload_modules() # {{{
{ {
drvlist="$1" drvlist="$1"
@ -253,7 +214,6 @@ function unload_modules() # {{{
done done
} # }}} } # }}}
function remove_pci_devices() # {{{ function remove_pci_devices() # {{{
{ {
for slot in $(lspci -mm -d 10ee: | awk '{printf "0000:%s\n",$1}'); do for slot in $(lspci -mm -d 10ee: | awk '{printf "0000:%s\n",$1}'); do
@ -264,12 +224,10 @@ function remove_pci_devices() # {{{
done done
} # }}} } # }}}
function rescan_pci_devices() # {{{ function rescan_pci_devices() # {{{
{ {
echo 1 | sudo dd of=/sys/bus/pci/rescan echo 1 | sudo dd of=/sys/bus/pci/rescan
} # }}} } # }}}
function load_qdma_modules() # {{{ function load_qdma_modules() # {{{
{ {
drv="$DMA_IP_DRIVERS/QDMA/linux-kernel/bin/qdma-pf.ko" drv="$DMA_IP_DRIVERS/QDMA/linux-kernel/bin/qdma-pf.ko"
@ -283,7 +241,6 @@ function load_qdma_modules() # {{{
sudo insmod "$drv" "hw_buffers=$hw_buffers" sudo insmod "$drv" "hw_buffers=$hw_buffers"
sleep 4 sleep 4
} # }}} } # }}}
function load_bitstream() # {{{ function load_bitstream() # {{{
{ {
bitstream="$1" bitstream="$1"
@ -308,13 +265,36 @@ reloadfs=
resetcpu= resetcpu=
verbose= verbose=
while getopts "s:w:k:r:b:v" opt; do bootloader_addr=0x80000000
kernel_addr=0x84000000
initrd_addr=0x8c300000
function usage()
{
echo "" >&2
echo "Usage: $0 [-v] [-w bitstream] [-b bootloader] [-k kernel] [-i initrd]" >&2
echo "" >&2
echo "First writes the bitstream if given. Then loads the rest of files" >&2
echo "into memory and restarts the CPU." >&2
echo "" >&2
echo "Options" >&2
echo " -w bitstream Write the bitstream file to the FPGA" >&2
echo " -b bootloader Load the bootloader file in $bootloader_addr" >&2
echo " -k kernel Load the kernel file in $kernel_addr" >&2
echo " -i initrd Load the initrd file in $initrd_addr" >&2
echo " -v Be verbose" >&2
echo "" >&2
exit 1
}
while getopts "hvw:b:k:i:" opt; do
case "${opt}" in case "${opt}" in
v) verbose=1 ;;
w) bitstream="${OPTARG}" ;; w) bitstream="${OPTARG}" ;;
b) bootloader="${OPTARG}"; resetcpu=1 ;; b) bootloader="${OPTARG}"; resetcpu=1 ;;
k) kernelfile="${OPTARG}"; resetcpu=1 ;; k) kernel="${OPTARG}"; resetcpu=1 ;;
r) rootfs="${OPTARG}"; resetcpu=1 ;; i) initrd="${OPTARG}"; resetcpu=1 ;;
v) verbose=1 ;; h) usage ;;
*) usage ;; *) usage ;;
esac esac
done done
@ -325,9 +305,9 @@ check_environment
test "$bitstream" && load_bitstream "$bitstream" test "$bitstream" && load_bitstream "$bitstream"
test "$resetcpu" && do_system_reset test "$resetcpu" && do_system_reset
test "$bootloader" && load_file_in_memory "${bootloader}" $((0x80000000)) test "$bootloader" && load_file_in_memory "$bootloader" $bootloader_addr
test "$kernelfile" && load_file_in_memory "${kernelfile}" $((0x84000000)) test "$kernel" && load_file_in_memory "$kernel" $kernel_addr
test "$rootfs" && load_file_in_memory "${rootfs}" $((0x8c300000)) test "$initrd" && load_file_in_memory "$initrd" $initrd_addr
test "$resetcpu" && do_system_release test "$resetcpu" && do_system_release
# vim:ts=2:sw=2:ai:foldmethod=marker:foldlevel=0: # vim:ts=2:sw=2:ai:foldmethod=marker:foldlevel=0: