URL
https://opencores.org/ocsvn/radiohdl/radiohdl/trunk
Subversion Repositories radiohdl
[/] [radiohdl/] [trunk/] [quartus/] [run_sof] - Rev 4
Compare with Previous | Blame | View Log
#!/bin/bash -eu
# -------------------------------------------------------------------------- #
#
# Copyright (C) 2011
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
# JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------- #
#
# Run this tool with at least the commandline arguments:
# run_sof buildset design_name
# example:
# run_sof unb2 unb2_minimal
# read generic functions/definitions
. ${RADIOHDL_GEAR}/generic.sh
# helper function for command parsing
exit_with_error() {
hdl_error_noexit $0 "$@"
cat <<@EndOfHelp@
Usage: $(basename $0) [options] buildset project nodes [options]
Arguments: buildset Name of the buildset to create the app for.
project Project file to use for the build.
nodes A list of nodes: this can be:
- a list of node numbers (=boardnumber[0..3] and relative nodenr[0..7])
e.g: "03 04 17 23 35"
- 'magic' words like bn, fn or all where each of the words may be preceded
by a boardnumber([0..3]).
e.g: "0fn 1fn" or "3all"
- any combination of the above like e.g: "0fn 12 13 3fn"
Options: --timelimited: ???
--cable=*: ???
--sof=*: ???
--rev=*: ???
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
@EndOfHelp@
exit 1
}
# parse cmdline
POSITIONAL=()
timelimited=
cable=1
sof=
rev=
while [[ $# -gt 0 ]]
do
case $1 in
--timelimited)
timelimited="_time_limited"
;;
--cable=*)
cable=${1#*=}
;;
--rev=*)
rev=${1#*=}
;;
--sof=*)
sof=${1#*=}
;;
-*|--*)
exit_with_error "Unknown option: "$1
;;
*) POSITIONAL+=("$1")
;;
esac
shift
done
if [ ${#POSITIONAL[@]} -gt 0 ]; then
set -- "${POSITIONAL[@]}"
fi
# check the positional parameters
if [ $# -lt 3 ]; then
exit_with_error "Wrong number of arguments specified."
fi
buildset=$1
project=$2
nodelist=${@:3}
# Multi board node ID's
frontnodes0="00 01 02 03"
backnodes0="04 05 06 07"
frontnodes1="10 11 12 13"
backnodes1="14 15 16 17"
frontnodes2="20 21 22 23"
backnodes2="24 25 26 27"
frontnodes3="30 31 32 33"
backnodes3="34 35 36 37"
# Single board node ID's
frontnodes=${frontnodes1}
backnodes=${backnodes1}
nodes=
for node_spec in ${nodelist}
do
# if we encounter one of the "magic" strings ..
# we shortcircuit. stop commandlineprocessing
# and set nodes to whatever we take them to mean
# Single board arguments:
if [ "${node_spec}" = "all" ]; then
nodes="${nodes} ${frontnodes} ${backnodes}"
elif [ "${node_spec}" = "fn" ]; then
nodes="${nodes} ${frontnodes}"
elif [ "${node_spec}" = "bn" ]; then
nodes="${nodes} ${backnodes}"
# Multi board arguments:
elif [ "${node_spec}" = "0all" ]; then
nodes="${nodes} ${frontnodes0} ${backnodes0}"
elif [ "${node_spec}" = "0fn" ]; then
nodes="${nodes} ${frontnodes0}"
elif [ "${node_spec}" = "0bn" ]; then
nodes="${nodes} ${backnodes0}"
elif [ "${node_spec}" = "1all" ]; then
nodes="${nodes} ${frontnodes1} ${backnodes1}"
elif [ "${node_spec}" = "1fn" ]; then
nodes="${nodes} ${frontnodes1}"
elif [ "${node_spec}" = "1bn" ]; then
nodes="${nodes} ${backnodes1}"
elif [ "${node_spec}" = "2all" ]; then
nodes="${nodes} ${frontnodes2} ${backnodes2}"
elif [ "${node_spec}" = "2fn" ]; then
nodes="${nodes} ${frontnodes2}"
elif [ "${node_spec}" = "2bn" ]; then
nodes="${nodes} ${backnodes2}"
elif [ "${node_spec}" = "3all" ]; then
nodes="${nodes} ${frontnodes3} ${backnodes3}"
elif [ "${node_spec}" = "3fn" ]; then
nodes="${nodes} ${frontnodes3}"
elif [ "${node_spec}" = "3bn" ]; then
nodes="${nodes} ${backnodes3}"
else
if [ ${#node_spec} -eq 1 ]; then
nodes="${nodes} 1${node_spec}" # no board spec
else
nodes="${nodes} ${node_spec}"
fi
fi
done
# check projectfile
PRJS="${RADIOHDL_BUILD_DIR}"
PRJ=
for prj in ${PRJS}
do
if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
PRJ=${prj}
fi
done
if [ -z "${project}" -o -z "${PRJ}" ]; then
hdl_error $0 "Please enter a valid project name"
fi
# check if the quartusdirectory does exist
# (such that it won't fail with a cryptic error but with
# a readable one
quartusdir[1]="${PRJ}/${buildset}/quartus/${project}"
hdl_exec $0 msg=no test -d ${quartusdir[1]}
if [ -z "${rev}" ]; then
project_rev="${project}"
hdl_info $0 "No project revision passed, defaulting to ${project_rev}"
else
if [ -f "${quartusdir[1]}/${rev}.qsf" ]; then
project_rev="${rev}"
hdl_info $0 "Selecting project revision ${project_rev}"
else
hdl_error $0 "Invalid project revision"
fi
fi
if [ -z "${sof}" ]; then
:
else
if [ -f "${quartusdir[1]}/${sof}.sof" ]; then
project_rev="${sof}"
hdl_info $0 "Selecting programming file ${project_rev}.sof"
else
hdl_error $0 "Invalid programming file"
fi
fi
#Convert user passed node to actual FPGA JTAG ID
#===============================================
# In the UniRack, the JTAG board IDs for board 0 (JTAG ID 1..8) and board 1 (JTAG ID 9..16) are swapped.
# This makes it use counter loops and such, so we'll just use an associative array to map
# the multi-board IDs to actual FPGA JTAG ID.
declare -A node_jtag=(\
["00"]="9"\
["01"]="10"\
["02"]="11"\
["03"]="12"\
["04"]="13"\
["05"]="14"\
["06"]="15"\
["07"]="16"\
["10"]="1"\
["11"]="2"\
["12"]="3"\
["13"]="4"\
["14"]="5"\
["15"]="6"\
["16"]="7"\
["17"]="8"\
["20"]="17"\
["21"]="18"\
["22"]="19"\
["23"]="20"\
["24"]="21"\
["25"]="22"\
["26"]="23"\
["27"]="24"\
["30"]="25"\
["31"]="26"\
["32"]="27"\
["33"]="28"\
["34"]="29"\
["35"]="30"\
["36"]="31"\
["37"]="32"\
)
# Now append an fpga JTAG ID to our fpga list for every match between the list of passed
# nodes (e.g. '00 01 02') and our associative array
fpgas=
for node in ${nodes}
do
echo $node
if [ -z "${node_jtag[$node]:-}" ]; then
hdl_error $0 "Invalid node ID. Node IDs should be passed as [0..3][0..7]"
fi
fpgas="${fpgas} ${node_jtag[$node]:-}"
done
#Prepare command: '-o p;my_project.sof@1 -o p\;my_project.sof@2' etc.
command=
for fpga in ${fpgas}; do
command="${command} -o p;${quartusdir[1]}/${project_rev}${timelimited}.sof@${fpga}"
done
if [ "${timelimited}" != "_time_limited" ]; then
if [ -f "${quartusdir[1]}/${project_rev}_time_limited.sof" ]; then
hdl_warning $0 "Also a time-limited SOF file present. Add --timelimited to use that file"
fi
fi
hdl_info $0 "Programming FPGAs @ JTAG IDs:${fpgas} on cable ${cable}"
hdl_exec $0 quartus_pgm -m jtag ${command} --cable=${cable}
#Example of full command to program fpgas 1 and 2 with unb_mesh_nios.sof:
#quartus_pgm -c USB-BLASTER -m jtag -o p\;unb_mesh_nios.sof@1 -o p\;unb_mesh_nios.sof@2
# Wish list: multi SOF support:
# run_sof ${buildset} unb_mesh 1 unb_tr_nonbonded --rev=bn_tr_nonbonded bn