From cf94b5a46a03a4d55ccf52f4c9b1f13c4a1b6dee Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 4 Mar 2024 16:53:03 +0100 Subject: [PATCH] Update fpgactl usage --- fpga/fpgactl | 84 ++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/fpga/fpgactl b/fpga/fpgactl index a0e9cf1..987c880 100755 --- a/fpga/fpgactl +++ b/fpga/fpgactl @@ -9,43 +9,12 @@ # Stop on first error 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() # {{{ { lsmod | grep -wq "$1" } # }}} - 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 echo "error: dma-ctl not found in PATH" >&2 exit 1 @@ -56,7 +25,6 @@ function check_environment() # {{{ exit 1 fi } # }}} - function create_qdma_queue() # {{{ { pcidir="/sys/bus/pci/devices/0000:08:00.0" @@ -97,7 +65,6 @@ function create_qdma_queue() # {{{ sleep 2 } # }}} - function do_system_reset() # {{{ { # UartBootEn (bit2) + system reset (bit0) @@ -107,13 +74,11 @@ function do_system_reset() # {{{ dma-ctl qdma08000 reg write bar 2 0x0 0x1 > /dev/null #sleep 5 } # }}} - function do_system_release() # {{{ { # Release Ariane's reset dma-ctl qdma08000 reg write bar 2 0x0 0x3 > /dev/null } # }}} - function copy_by_dma() # {{{ { ifile="$1" @@ -138,11 +103,11 @@ function copy_by_dma() # {{{ done } # }}} - function load_file_in_memory() # {{{ { file="$1" - address="$2" + address_hex="$2" + address=$(($address_hex)) # Previous tests... #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 } # }}} - function do_boot_only() # {{{ { 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 up } # }}} - function do_reload_fs() # {{{ { do_system_reset @@ -211,7 +174,6 @@ function do_reload_fs() # {{{ # uncomment to enable eth-over-pcie # sudo ifconfig onic${onicid}s0f0 10.0.2.2 netmask 255.255.255.0 mtu 9000 up } # }}} - function upload_bitstream_file() # {{{ { bitfile="$1" @@ -240,7 +202,6 @@ EOF killall hw_server } # }}} - function unload_modules() # {{{ { drvlist="$1" @@ -253,7 +214,6 @@ function unload_modules() # {{{ done } # }}} - function remove_pci_devices() # {{{ { for slot in $(lspci -mm -d 10ee: | awk '{printf "0000:%s\n",$1}'); do @@ -264,12 +224,10 @@ function remove_pci_devices() # {{{ done } # }}} - function rescan_pci_devices() # {{{ { echo 1 | sudo dd of=/sys/bus/pci/rescan } # }}} - function load_qdma_modules() # {{{ { 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" sleep 4 } # }}} - function load_bitstream() # {{{ { bitstream="$1" @@ -308,13 +265,36 @@ reloadfs= resetcpu= 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 + v) verbose=1 ;; w) bitstream="${OPTARG}" ;; b) bootloader="${OPTARG}"; resetcpu=1 ;; - k) kernelfile="${OPTARG}"; resetcpu=1 ;; - r) rootfs="${OPTARG}"; resetcpu=1 ;; - v) verbose=1 ;; + k) kernel="${OPTARG}"; resetcpu=1 ;; + i) initrd="${OPTARG}"; resetcpu=1 ;; + h) usage ;; *) usage ;; esac done @@ -325,9 +305,9 @@ check_environment test "$bitstream" && load_bitstream "$bitstream" test "$resetcpu" && do_system_reset -test "$bootloader" && load_file_in_memory "${bootloader}" $((0x80000000)) -test "$kernelfile" && load_file_in_memory "${kernelfile}" $((0x84000000)) -test "$rootfs" && load_file_in_memory "${rootfs}" $((0x8c300000)) +test "$bootloader" && load_file_in_memory "$bootloader" $bootloader_addr +test "$kernel" && load_file_in_memory "$kernel" $kernel_addr +test "$initrd" && load_file_in_memory "$initrd" $initrd_addr test "$resetcpu" && do_system_release # vim:ts=2:sw=2:ai:foldmethod=marker:foldlevel=0: