nixos-riscv/fpga/load_image.sh

46 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2024-03-04 18:32:25 +01:00
#!/bin/bash
source /home/tools/ACME-EA-v1/setup.sh
if [ $# -ne 2 ]; then
>&2 echo "usage: load-fs.sh <file> <address>"
exit 1
fi
input=$1
#startaddr=$((0x00000000))
startaddr=$2
filesize=$(du -L -b $input | cut -f1)
#chunksize=$((0x10000000))
#chunksize=$((0x08000000))
chunksize=$((0x00800000))
nrchunk=$((filesize/chunksize + ((filesize%chunksize) != 0) ))
lastchunk=$((nrchunk - 1))
total=0
myid=$$
rm -f /tmp/sect.tmp.$myid
for i in `seq 0 $lastchunk`; do
echo "extracting section $i... "
dd if=$input of=/tmp/sect.tmp.$myid bs=$chunksize skip=$i count=1 status=none
from=$((i * chunksize))
to=$((startaddr + i * chunksize))
#copysize=$((i != lastchunk ? chunksize : (filesize - i * chunksize) ))
copysize=$(du -L -b /tmp/sect.tmp.$myid | cut -f1)
echo "copying section $i: from=$from to=$to size=$copysize ($((copysize/1024/1024)) MiB)"
dma-to-device -d /dev/qdma${ID}000-MM-1 -a $to -s $copysize -f /tmp/sect.tmp.$myid
#sleep 0.2
rm -f /tmp/sect.tmp.$myid
echo -e "done\n"
total=$((total + copysize))
done
if [ $filesize -ne $total ]; then
>&2 echo "Error: Copy failed"
exit 1
fi