1 |
4 |
danv |
#!/bin/bash -eu
|
2 |
|
|
# -------------------------------------------------------------------------- #
|
3 |
|
|
#
|
4 |
|
|
# Copyright (C) 2010
|
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 |
|
|
# This script calls the unb_create_bsp script,
|
25 |
|
|
# generates the HAL and
|
26 |
|
|
# compiles all files included in the [app].src file.
|
27 |
|
|
# default [app] == [project] but can override via
|
28 |
|
|
# "app=" commandline option
|
29 |
|
|
#
|
30 |
|
|
|
31 |
|
|
# Run this tool with at least the commandline arguments:
|
32 |
|
|
# run_app buildset design_name
|
33 |
|
|
# example:
|
34 |
|
|
# run_app unb2 unb2_minimal
|
35 |
|
|
#
|
36 |
|
|
|
37 |
|
|
# read generic functions/definitions
|
38 |
|
|
. ${RADIOHDL_GEAR}/generic.sh
|
39 |
|
|
|
40 |
|
|
# helper function for command parsing
|
41 |
|
|
exit_with_error() {
|
42 |
|
|
hdl_error_noexit $0 "$@"
|
43 |
|
|
cat <<@EndOfHelp@
|
44 |
|
|
Usage: $(basename $0) [options] buildset project [app]
|
45 |
|
|
Arguments: buildset Name of the buildset to create the app for.
|
46 |
|
|
project Project file to use for the build.
|
47 |
|
|
app The name of the app to produce (defaults to 'unb_osy' when omitted).
|
48 |
|
|
|
49 |
|
|
Options: --no-make: The make phase is skipped.
|
50 |
|
|
--nolib: The construction of the libfile is skipped.
|
51 |
|
|
--hexname=* The name of the hexfile to produce.
|
52 |
|
|
--userflags=* The (extra) flags to pass to the C compiler.
|
53 |
|
|
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
|
54 |
|
|
@EndOfHelp@
|
55 |
|
|
exit 1
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
# parse cmdline
|
59 |
|
|
POSITIONAL=()
|
60 |
|
|
app="unb_osy"
|
61 |
|
|
skip_make=
|
62 |
|
|
nolib=
|
63 |
|
|
hexname=
|
64 |
|
|
userflags="-DCOMPILE_FOR_SOPC"
|
65 |
|
|
while [[ $# -gt 0 ]]
|
66 |
|
|
do
|
67 |
|
|
case $1 in
|
68 |
|
|
--no-make)
|
69 |
|
|
skip_make="skip_make"
|
70 |
|
|
;;
|
71 |
|
|
--nolib)
|
72 |
|
|
nolib="nolib"
|
73 |
|
|
;;
|
74 |
|
|
--hexname=*)
|
75 |
|
|
# if app not already set, set it now
|
76 |
|
|
if [ -n "${hexname}" ]; then
|
77 |
|
|
hdl_error $0 "Do not pass more than one hex file name!"
|
78 |
|
|
fi
|
79 |
|
|
hexname=${1#*=}
|
80 |
|
|
;;
|
81 |
|
|
--userflags=*)
|
82 |
|
|
userflags=${1#*=}
|
83 |
|
|
;;
|
84 |
|
|
-*|--*)
|
85 |
|
|
exit_with_error "Unknown option: "$1
|
86 |
|
|
;;
|
87 |
|
|
*) POSITIONAL+=("$1")
|
88 |
|
|
;;
|
89 |
|
|
esac
|
90 |
|
|
shift
|
91 |
|
|
done
|
92 |
|
|
if [ ${#POSITIONAL[@]} -gt 0 ]; then
|
93 |
|
|
set -- "${POSITIONAL[@]}"
|
94 |
|
|
fi
|
95 |
|
|
|
96 |
|
|
# check the positional parameters
|
97 |
|
|
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
|
98 |
|
|
exit_with_error "Wrong number of arguments specified."
|
99 |
|
|
fi
|
100 |
|
|
buildset=$1
|
101 |
|
|
project=$2
|
102 |
|
|
app=${3:-$app}
|
103 |
|
|
|
104 |
|
|
hdl_info $0 "Going to build ${app} for project ${project} from buildset ${buildset}"
|
105 |
|
|
hdl_info $0 "Adding compiler option: ${userflags}"
|
106 |
|
|
|
107 |
|
|
# read in the configuration based on the user arguments
|
108 |
|
|
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}
|
109 |
|
|
|
110 |
|
|
# # First, check to see if $SOPC_KIT_NIOS2 environmental variable is set.
|
111 |
|
|
# # This variable is required for the command line tools to execute correctly.
|
112 |
|
|
# if [ -z "${SOPC_KIT_NIOS2}" ]; then
|
113 |
|
|
# hdl_error $0 "SOPC_KIT_NIOS2 environment variable is not set!!"
|
114 |
|
|
# fi
|
115 |
|
|
|
116 |
|
|
# First, check to see if $SOPC_KIT_NIOS2 environmental variable is set.
|
117 |
|
|
# This variable is required for the command line tools to execute correctly.
|
118 |
|
|
if [ -z "${NIOSDIR}" ]; then
|
119 |
|
|
hdl_error $0 "NIOSDIR environment variable is not set!!"
|
120 |
|
|
fi
|
121 |
|
|
|
122 |
|
|
# search for existing project directory
|
123 |
|
|
PRJS="${RADIOHDL_BUILD_DIR}"
|
124 |
|
|
PRJ=
|
125 |
|
|
for prj in ${PRJS}
|
126 |
|
|
do
|
127 |
|
|
if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
|
128 |
|
|
PRJ=${prj}
|
129 |
|
|
fi
|
130 |
|
|
done
|
131 |
|
|
if [ -z "${project}" -o -z "${PRJ}" ]; then
|
132 |
|
|
hdl_error $0 "Please enter a valid project name"
|
133 |
|
|
fi
|
134 |
|
|
|
135 |
|
|
# if no app given, default to [project] and inform user
|
136 |
|
|
if [ -z "${app}" ]; then
|
137 |
|
|
app=${project}
|
138 |
|
|
hdl_info $0 "SELECTING DEFAULT APP '${app}'"
|
139 |
|
|
fi
|
140 |
|
|
|
141 |
|
|
# Generate the paths we need
|
142 |
|
|
quartusdir="${PRJ}/${buildset}/quartus/${project}"
|
143 |
|
|
builddir="${quartusdir}/software"
|
144 |
|
|
bspdstdir="${builddir}/bsp"
|
145 |
|
|
unbsrcdir="${RADIOHDL_WORK}/libraries/unb_osy/modules"
|
146 |
|
|
unbdstdir="${builddir}/unb_lib"
|
147 |
|
|
appsrcdir="${RADIOHDL_WORK}/libraries/unb_osy"
|
148 |
|
|
appdstdir="${builddir}/${app}"
|
149 |
|
|
|
150 |
|
|
# Is the application available?
|
151 |
|
|
hdl_exec $0 msg=no test -d ${appsrcdir}
|
152 |
|
|
|
153 |
|
|
# Make sure BSP is up-to-date.
|
154 |
|
|
hdl_exec $0 msg="Calling run_bsp ${buildset} ${project}" run_bsp ${buildset} ${project}
|
155 |
|
|
|
156 |
|
|
if [ -z "${nolib}" ]; then
|
157 |
|
|
|
158 |
|
|
# For now, we always generate the unb_common library.
|
159 |
|
|
if [ -f "${unbdstdir}/public.mk" ]; then
|
160 |
|
|
# assume the lib was already configured
|
161 |
|
|
# reload all the sourcefiles to make sure the lib
|
162 |
|
|
# contains all code available at this moment.
|
163 |
|
|
# do this by first removing all sources and
|
164 |
|
|
# then re-adding them
|
165 |
|
|
hdl_exec $0 msg=no nios2-lib-update-makefile --lib-dir ${unbdstdir} --no-src
|
166 |
|
|
hdl_exec $0 msg=no nios2-lib-update-makefile --lib-dir ${unbdstdir} \
|
167 |
|
|
--add-src-dir ${unbsrcdir}
|
168 |
|
|
else
|
169 |
|
|
hdl_info $0 "Configuring unb_common library"
|
170 |
|
|
# because of b0rkage in the nios2-lib-generate-makefile program
|
171 |
|
|
# where it concerns the public include directory we set this
|
172 |
|
|
# path correct in two steps.
|
173 |
|
|
# If you specify a public include dir (so it will be exported
|
174 |
|
|
# to an app's makefile) in the -generate-makefile command
|
175 |
|
|
# the library source directory will be prepended unconditionally.
|
176 |
|
|
# However, if you later, via the -update-makefile specify an
|
177 |
|
|
# include dir it will be interpreted as-is, without automagic
|
178 |
|
|
# prepending of any paths whatsoever
|
179 |
|
|
hdl_exec $0 msg=no nios2-lib-generate-makefile --lib-name unb_lib \
|
180 |
|
|
--bsp-dir ${bspdstdir} \
|
181 |
|
|
--lib-dir ${unbdstdir} \
|
182 |
|
|
--src-dir ${unbsrcdir}
|
183 |
|
|
hdl_exec $0 msg=no nios2-lib-update-makefile --lib-dir ${unbdstdir} \
|
184 |
|
|
--add-public-inc-dir ${unbsrcdir}
|
185 |
|
|
fi
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
# If there is already an app makefile, let's reload the appsourcedir
|
189 |
|
|
# so it will pick up new sourcefiles added to ${appsrcdir} since
|
190 |
|
|
# the last invocation
|
191 |
|
|
if [ -d "${appdstdir}" -a -f "${appdstdir}/Makefile" ]; then
|
192 |
|
|
# makefile exists, remove sources and re-add them
|
193 |
|
|
hdl_exec $0 msg=no nios2-app-update-makefile --app-dir ${appdstdir} --no-src
|
194 |
|
|
hdl_exec $0 msg=no nios2-app-update-makefile --app-dir ${appdstdir} \
|
195 |
|
|
--add-src-dir ${appsrcdir}
|
196 |
|
|
else
|
197 |
|
|
# must generate the app makefile from scratch
|
198 |
|
|
hdl_info $0 "Configuring application ${app}"
|
199 |
|
|
hdl_exec $0 msg=no nios2-app-generate-makefile \
|
200 |
|
|
--elf-name ${app}.elf \
|
201 |
|
|
--bsp-dir ${bspdstdir} \
|
202 |
|
|
--app-dir ${appdstdir} \
|
203 |
|
|
--use-lib-dir ${unbdstdir} \
|
204 |
|
|
--src-dir ${appsrcdir} \
|
205 |
|
|
--set QUARTUS_PROJECT_DIR ${quartusdir} \
|
206 |
|
|
--set OBJDUMP_INCLUDE_SOURCE 1
|
207 |
|
|
hdl_exec $0 msg=no nios2-app-update-makefile \
|
208 |
|
|
--app-dir ${appdstdir} \
|
209 |
|
|
--add-inc-dir ${appsrcdir} \
|
210 |
|
|
--set-user-flags ${userflags}
|
211 |
|
|
fi
|
212 |
|
|
|
213 |
|
|
#If we just want to build an app and don't want to include all the software modules
|
214 |
|
|
#just include common_types.h and build the app:
|
215 |
|
|
else
|
216 |
|
|
hdl_info $0 "Configuring application ${app} - UNB library not included."
|
217 |
|
|
hdl_exec $0 msg=no nios2-app-generate-makefile \
|
218 |
|
|
--elf-name ${app}.elf \
|
219 |
|
|
--bsp-dir ${bspdstdir} \
|
220 |
|
|
--app-dir ${appdstdir} \
|
221 |
|
|
--src-dir ${appsrcdir} \
|
222 |
|
|
--set QUARTUS_PROJECT_DIR ${quartusdir} \
|
223 |
|
|
--set OBJDUMP_INCLUDE_SOURCE 1
|
224 |
|
|
hdl_exec $0 msg=no nios2-app-update-makefile \
|
225 |
|
|
--app-dir ${appdstdir} \
|
226 |
|
|
--add-inc-dir ${unbsrcdir}/common \
|
227 |
|
|
--set-user-flags ${userflags}
|
228 |
|
|
fi
|
229 |
|
|
|
230 |
|
|
if [ -z "${skip_make}" ]; then
|
231 |
|
|
hdl_exec $0 msg=no make -C ${appdstdir}
|
232 |
|
|
fi
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
#Create HEX from ELF
|
236 |
|
|
if [ -z "${hexname}" ]; then
|
237 |
|
|
hexname=onchip_memory2_0.hex
|
238 |
|
|
fi
|
239 |
|
|
|
240 |
|
|
# figure out the onchip memory's base + end address
|
241 |
|
|
system_h=${bspdstdir}/system.h
|
242 |
|
|
if [ ! -f "${system_h}" ]; then
|
243 |
|
|
hdl_error $0 "system.h file not found in BSP [${bspdstdir}]"
|
244 |
|
|
hdl_error $0 "#############################################"
|
245 |
|
|
hdl_error $0 " UNABLE TO RUN elf2hex"
|
246 |
|
|
exit 1
|
247 |
|
|
fi
|
248 |
|
|
|
249 |
|
|
onchip_base=`sed -n '/^[ ]*#define[ ]*ONCHIP_MEMORY2_0_BASE/{ s/^[ ]*#define[ ]*ONCHIP_MEMORY2_0_BASE[ ]*//; p}' ${system_h}`
|
250 |
|
|
onchip_span=`sed -n '/^[ ]*#define[ ]*ONCHIP_MEMORY2_0_SPAN/{ s/^[ ]*#define[ ]*ONCHIP_MEMORY2_0_SPAN[ ]*//; p}' ${system_h}`
|
251 |
|
|
|
252 |
|
|
if [ -z "${onchip_base}" -o -z "${onchip_span}" ]; then
|
253 |
|
|
hdl_error $0 "ONCHIP_MEMORY2_0_[BASE|SPAN] not found "
|
254 |
|
|
hdl_error $0 " in BSP [${bspdstdir}]"
|
255 |
|
|
hdl_error $0 "#############################################"
|
256 |
|
|
hdl_error $0 " UNABLE TO RUN elf2hex"
|
257 |
|
|
exit 1
|
258 |
|
|
fi
|
259 |
|
|
|
260 |
|
|
# we must compute the end address and give it to elf2hex in hex
|
261 |
|
|
# the *NIX commanline calculators
|
262 |
|
|
onchip_base_dec=`printf "%d" ${onchip_base}`
|
263 |
|
|
onchip_span_dec=`printf "%d" ${onchip_span}`
|
264 |
|
|
onchip_end_dec=`expr ${onchip_base_dec} + ${onchip_span_dec} - 1`
|
265 |
|
|
onchip_end_hex=`printf "0x%x" ${onchip_end_dec}`
|
266 |
|
|
onchip_base=`printf "0x%x" ${onchip_base}`
|
267 |
|
|
|
268 |
|
|
#Use user provided hex file name
|
269 |
|
|
hdl_exec $0 msg="Creating HEX from ELF: ${hexname} [${onchip_base} -> ${onchip_end_hex}]" \
|
270 |
|
|
elf2hex --input=${appdstdir}/${app}.elf \
|
271 |
|
|
--output=${quartusdir}/${hexname} \
|
272 |
|
|
--base=${onchip_base} --end=${onchip_end_hex} --width=32 \
|
273 |
|
|
--create-lanes=0
|
274 |
|
|
|
275 |
|
|
hdl_exec $0 msg="Calling run_reg ${buildset} ${project}" run_reg ${buildset} ${project}
|
276 |
|
|
|
277 |
|
|
hdl_info $0 "Done"
|