URL
https://opencores.org/ocsvn/radiohdl/radiohdl/trunk
Subversion Repositories radiohdl
[/] [radiohdl/] [trunk/] [quartus/] [run_rbf] - Rev 4
Compare with Previous | Blame | View Log
#!/bin/bash -eu
# -------------------------------------------------------------------------- #
#
# Copyright (C) 2012
# 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_rbf buildset design_name
# example:
# run_rbf 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) buildset project [options]
Arguments: buildset Name of the buildset to create the registermap for.
project Project file to use.
Options: --rev=* which revision to use.
--unb2_factory ???
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
@EndOfHelp@
exit 1
}
# parse cmdline
POSITIONAL=()
rev=
arg_unb2_factory=
while [[ $# -gt 0 ]]
do
case $1 in
--rev=*)
rev=${1#*=}
;;
--unb2_factory)
arg_unb2_factory=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 [ $# -ne 2 ]; then
exit_with_error "Wrong number of arguments specified."
fi
buildset=$1
project=$2
# read in the configuration based on the user arguments
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}
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
unb_error $0 "Please enter a valid project name"
fi
quartusdir="${PRJ}/${buildset}/quartus/${project}"
if [ -z "${rev}" ]; then
project_rev="${project}"
hdl_info $0 "No project revision passed, defaulting to ${project_rev}"
else
if [ -f "${PRJ}/Firmware/designs/${project}/build/synth/quartus/${rev}.qsf" ]; then
project_rev="${rev}"
hdl_info $0 "Selecting project revision ${project_rev}"
else
hdl_error $0 "Invalid project revision"
fi
fi
sof_file=${quartusdir}/${project_rev}.sof
if [ ! -f "${sof_file}" ]; then
hdl_error $0 "${project_rev}.sof not found in ${quartusdir}/"
exit 1
fi
echo "Bitstream_compression=on" > ${HOME}/.run_rbf_temp_options_file
hdl_info $0 "Converting ${quartusdir}/${project_rev}.sof to compressed Raw Binary File"
if [ -z "${arg_unb2_factory}" ]; then
hdl_exec $0 quartus_cpf -c --option=${HOME}/.run_rbf_temp_options_file ${quartusdir}/${project_rev}.sof ${quartusdir}/${project_rev}.rbf
else
hdl_info $0 "-> This is a factory image for Uniboard2: Convert .SOF -> .POF -> .HEXOUT -> .RBF"
# for more info see: ${RADIOHDL_WORK}/libraries/io/epcs/doc/README.txt
hdl_exec $0 quartus_cpf -d EPCQL1024 -m ASx4 --option=${HOME}/.run_rbf_temp_options_file -c ${quartusdir}/${project_rev}.sof ${quartusdir}/${project_rev}.pof
hdl_exec $0 quartus_cpf -c ${quartusdir}/${project_rev}.pof ${quartusdir}/${project_rev}.hexout
hdl_exec $0 nios2-elf-objcopy -I ihex -O binary ${quartusdir}/${project_rev}.hexout ${quartusdir}/${project_rev}.rbf
hdl_info $0 "Truncating RBF:"
echo "Size of .SOF is: "
du -h ${quartusdir}/${project_rev}.sof
echo "Truncating to 40M (FIXME find out if 40M is correct on different SOF files)"
hdl_exec $0 truncate -s 40M ${quartusdir}/${project_rev}.rbf
echo "Deleting temp files"
hdl_exec $0 rm -f ${quartusdir}/${project_rev}.pof
hdl_exec $0 rm -f ${quartusdir}/${project_rev}.hexout
fi
if [ -n "${HDL_GIT_REVISION_SHORT}" ]; then
git_revision=`echo ${HDL_GIT_REVISION_SHORT}` # ${HDL_GIT_REVISION_SHORT} looks like: "7d81650af"
echo "copy file ${quartusdir}/${project_rev}.rbf to ${quartusdir}/${project_rev}-r${git_revision}.rbf"
cp ${quartusdir}/${project_rev}.rbf ${quartusdir}/${project_rev}-r${git_revision}.rbf
fi
hdl_info $0 "Done"