From bd2b8b1bc5e8afd30b1b565ac5ac97b4994138ad Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Mon, 4 Mar 2024 16:31:07 +0100 Subject: [PATCH] Update fpgactl tool --- fpga/fpgactl | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/fpga/fpgactl b/fpga/fpgactl index d5f478a..a0e9cf1 100755 --- a/fpga/fpgactl +++ b/fpga/fpgactl @@ -101,27 +101,59 @@ function create_qdma_queue() # {{{ function do_system_reset() # {{{ { # UartBootEn (bit2) + system reset (bit0) - dma-ctl qdma08000 reg write bar 2 0x0 0x0 + dma-ctl qdma08000 reg write bar 2 0x0 0x0 > /dev/null sleep 0.2 # Release system reset, we must wait until the memory is filled with 0s - dma-ctl qdma08000 reg write bar 2 0x0 0x1 + 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 + dma-ctl qdma08000 reg write bar 2 0x0 0x3 > /dev/null +} # }}} + +function copy_by_dma() # {{{ +{ + ifile="$1" + address="$2" + + ofile="/dev/qdma08000-MM-1" + bs=$((8*1024*1024)) # 8 MiB + + total_size=$(stat --format "%s" "$ifile") + + nblocks=$(( ($total_size + $bs - 1) / $bs )) + skip=0 + + # Using just a single dd command doesn't seem to work. My hypothesis is that + # the driver doesn't allow multiple writes without setting the fseek position. + # So we keep copying blocks until the end of the file, one at a time. + + while [ "$skip" -lt "$nblocks" ]; do + dst=$(($address + $skip * $bs)) + dd if="$ifile" skip=$skip count=1 bs=$bs of="$ofile" seek=$dst oflag=seek_bytes + let skip=$skip+1 + done + } # }}} function load_file_in_memory() # {{{ { file="$1" address="$2" + + # Previous tests... #strace -f dma-to-device -d /dev/qdma08000-MM-1 -a "$address" -s $((8*1024*1024)) -f "$file" #strace -f dd if="$file" bs=16M seek="${address}" oflag=seek_bytes of=/dev/qdma08000-MM-1 status=progress conv=sync #strace -f fpgakit/fpgadd -i "$file" -a "$address" -d /dev/qdma08000-MM-1 -c 1024 -s 1024 - ID=08 ./load_image.sh "$file" "$address" + #ID=08 ./load_image.sh "$file" "$address" + + # Now dd seems to work fine, but I will leave this as fallback: + #copy_by_dma "$file" "$address" + + dd if="$file" bs=8M seek="${address}" oflag=seek_bytes of=/dev/qdma08000-MM-1 status=none } # }}} function do_boot_only() # {{{ @@ -190,9 +222,22 @@ function upload_bitstream_file() # {{{ exit 1 fi - vivado -nolog -nojournal -mode batch -source load-bitstream.tcl -tclargs "$bitfile" "$fpgajtag" + script=$(mktemp vivado-XXXXXXXXXX.tcl) + cat > "$script" <