1 |
4 |
danv |
#!/bin/bash -eu
|
2 |
|
|
# -------------------------------------------------------------------------- #
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2012
|
5 |
|
|
# ASTRON (Netherlands Institute for Radio Astronomy)
|
6 |
|
|
# JIVE (Joint Institute for VLBI in Europe)
|
7 |
|
|
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
8 |
|
|
#
|
9 |
|
|
# This program is free software: you can redistribute it and/or modify
|
10 |
|
|
# it under the terms of the GNU General Public License as published by
|
11 |
|
|
# the Free Software Foundation, either version 3 of the License, or
|
12 |
|
|
# (at your option) any later version.
|
13 |
|
|
#
|
14 |
|
|
# This program is distributed in the hope that it will be useful,
|
15 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
# GNU General Public License for more details.
|
18 |
|
|
#
|
19 |
|
|
# You should have received a copy of the GNU General Public License
|
20 |
|
|
# along with this program. If not, see .
|
21 |
|
|
#
|
22 |
|
|
# -------------------------------------------------------------------------- #
|
23 |
|
|
|
24 |
|
|
# Run this tool with at least the commandline arguments:
|
25 |
|
|
# run_mif buildset design_name
|
26 |
|
|
# example:
|
27 |
|
|
# run_mif unb2 unb2_minimal
|
28 |
|
|
#
|
29 |
|
|
|
30 |
|
|
# Convert character to ascii decimal value, print as hex
|
31 |
|
|
ord ()
|
32 |
|
|
{
|
33 |
|
|
printf "%02x" $(( ( 256 + $(printf '%d' "'$1"))%256 ))
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
# read generic functions/definitions
|
37 |
|
|
. ${RADIOHDL_GEAR}/generic.sh
|
38 |
|
|
|
39 |
|
|
# helper function for command parsing
|
40 |
|
|
exit_with_error() {
|
41 |
|
|
hdl_error_noexit $0 "$@"
|
42 |
|
|
cat <<@EndOfHelp@
|
43 |
|
|
Usage: $(basename $0) buildset project [options]
|
44 |
|
|
Arguments: buildset Name of the buildset to create the registermap for.
|
45 |
|
|
project Project file to use.
|
46 |
|
|
|
47 |
|
|
Options: --rev=* which revision to use.
|
48 |
|
|
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
|
49 |
|
|
@EndOfHelp@
|
50 |
|
|
exit 1
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
# parse cmdline
|
54 |
|
|
POSITIONAL=()
|
55 |
|
|
rev=
|
56 |
|
|
while [[ $# -gt 0 ]]
|
57 |
|
|
do
|
58 |
|
|
case $1 in
|
59 |
|
|
--rev=*)
|
60 |
|
|
rev=${1#*=}
|
61 |
|
|
;;
|
62 |
|
|
-*|--*)
|
63 |
|
|
exit_with_error "Unknown option: "$1
|
64 |
|
|
;;
|
65 |
|
|
*) POSITIONAL+=("$1")
|
66 |
|
|
;;
|
67 |
|
|
esac
|
68 |
|
|
shift
|
69 |
|
|
done
|
70 |
|
|
if [ ${#POSITIONAL[@]} -gt 0 ]; then
|
71 |
|
|
set -- "${POSITIONAL[@]}"
|
72 |
|
|
fi
|
73 |
|
|
|
74 |
|
|
# check the positional parameters
|
75 |
|
|
if [ $# -ne 2 ]; then
|
76 |
|
|
exit_with_error "Wrong number of arguments specified."
|
77 |
|
|
fi
|
78 |
|
|
buildset=$1
|
79 |
|
|
project=$2
|
80 |
|
|
# read in the configuration based on the user arguments
|
81 |
|
|
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}
|
82 |
|
|
|
83 |
|
|
# check projectfile
|
84 |
|
|
PRJS="${RADIOHDL_BUILD_DIR}"
|
85 |
|
|
PRJ=
|
86 |
|
|
for prj in ${PRJS}
|
87 |
|
|
do
|
88 |
|
|
if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
|
89 |
|
|
PRJ=${prj}
|
90 |
|
|
fi
|
91 |
|
|
done
|
92 |
|
|
if [ -z "${project}" -o -z "${PRJ}" ]; then
|
93 |
|
|
hdl_error $0 "Please enter a valid project name"
|
94 |
|
|
fi
|
95 |
|
|
|
96 |
|
|
quartusdir="${PRJ}/${buildset}/quartus/${project}"
|
97 |
|
|
builddir="${quartusdir}/software"
|
98 |
|
|
bspdstdir="${builddir}/bsp"
|
99 |
|
|
|
100 |
|
|
if [ -z "${rev}" ]; then
|
101 |
|
|
project_rev="${project}"
|
102 |
|
|
hdl_info $0 "No project revision passed, defaulting to ${project_rev}"
|
103 |
|
|
else
|
104 |
|
|
if [ -f "${quartusdir}/${rev}.qsf" ]; then
|
105 |
|
|
project_rev="${rev}"
|
106 |
|
|
hdl_info $0 "Selecting project revision ${project_rev}"
|
107 |
|
|
else
|
108 |
|
|
hdl_error $0 "Invalid project revision"
|
109 |
|
|
fi
|
110 |
|
|
fi
|
111 |
|
|
|
112 |
|
|
reg_file=${quartusdir}/${project_rev}.reg
|
113 |
|
|
if [ ! -f "${reg_file}" ]; then
|
114 |
|
|
hdl_error $0 "${project_rev}.reg file not found in [${quartusdir}]."
|
115 |
|
|
fi
|
116 |
|
|
|
117 |
|
|
# TODO: make a template
|
118 |
|
|
echo "DEPTH = 1024;" > ${quartusdir}/${project_rev}.mif
|
119 |
|
|
echo "WIDTH = 32;" >> ${quartusdir}/${project_rev}.mif
|
120 |
|
|
echo "ADDRESS_RADIX = DEC;" >> ${quartusdir}/${project_rev}.mif
|
121 |
|
|
echo "DATA_RADIX = HEX;" >> ${quartusdir}/${project_rev}.mif
|
122 |
|
|
echo "CONTENT BEGIN" >> ${quartusdir}/${project_rev}.mif
|
123 |
|
|
|
124 |
|
|
hdl_info $0 "Writing ${quartusdir}/${project_rev}.reg contents to ${quartusdir}/${project_rev}.mif"
|
125 |
|
|
|
126 |
|
|
tr '\n' '\0' < ${quartusdir}/${project_rev}.reg > ${quartusdir}/${project_rev}.reg_tmp
|
127 |
|
|
cat ${quartusdir}/${project_rev}.reg_tmp > ${quartusdir}/${project_rev}.reg
|
128 |
|
|
rm -f ${quartusdir}/${project_rev}.reg_tmp
|
129 |
|
|
|
130 |
|
|
address=0
|
131 |
|
|
charcnt=0
|
132 |
|
|
while IFS= read -r -d $'\0' -n1 char
|
133 |
|
|
do
|
134 |
|
|
# 4 bytes per word address: print one address per 4 chars
|
135 |
|
|
if [ $charcnt -eq 0 ] ; then
|
136 |
|
|
printf "%s" "$address" >> ${quartusdir}/${project_rev}.mif
|
137 |
|
|
printf " : " >> ${quartusdir}/${project_rev}.mif
|
138 |
|
|
fi
|
139 |
|
|
|
140 |
|
|
ord "${char}" >> ${quartusdir}/${project_rev}.mif
|
141 |
|
|
charcnt=`expr $charcnt + 1`
|
142 |
|
|
|
143 |
|
|
# last char of word, print semicolon and newline, increment word address
|
144 |
|
|
if [ $(( $charcnt % 4 )) -eq 0 ] ; then
|
145 |
|
|
printf ";\n" >> ${quartusdir}/${project_rev}.mif
|
146 |
|
|
address=`expr $address + 1`
|
147 |
|
|
charcnt=0
|
148 |
|
|
fi
|
149 |
|
|
done < "${reg_file}"
|
150 |
|
|
|
151 |
|
|
printf "\n" >> ${quartusdir}/${project_rev}.mif
|
152 |
|
|
echo "END;" >> ${quartusdir}/${project_rev}.mif
|
153 |
|
|
|
154 |
|
|
hdl_info $0 "Done"
|
155 |
|
|
|