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 |
|
|
# Run this tool with at least the commandline arguments:
|
25 |
|
|
# run_bsp buildset design_name
|
26 |
|
|
# example:
|
27 |
|
|
# run_bsp unb2 unb2_minimal
|
28 |
|
|
|
29 |
|
|
# read generic functions/definitions
|
30 |
|
|
. ${RADIOHDL_GEAR}/generic.sh
|
31 |
|
|
|
32 |
|
|
# helper function for command parsing
|
33 |
|
|
exit_with_error() {
|
34 |
|
|
hdl_error_noexit $0 "$@"
|
35 |
|
|
cat <<@EndOfHelp@
|
36 |
|
|
Usage: $(basename $0) [options] buildset project [app]
|
37 |
|
|
Arguments: buildset Name of the buildset to create the app for.
|
38 |
|
|
project Project file to use for the build.
|
39 |
|
|
|
40 |
|
|
Options: --no-make: The make phase is skipped.
|
41 |
|
|
--force: Force full compilation.
|
42 |
|
|
--bloat: Compile fullfledged BSP.
|
43 |
|
|
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
|
44 |
|
|
@EndOfHelp@
|
45 |
|
|
exit 1
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
# parse cmdline
|
49 |
|
|
POSITIONAL=()
|
50 |
|
|
force=
|
51 |
|
|
skip_make=
|
52 |
|
|
# BSP HAL settings default to a reduced functionality BSP (but much less code+data footprint)
|
53 |
|
|
# use "--bloat" to compile a fullfledged BSP.
|
54 |
|
|
# NOTE: you'll never get C++ or (clean) exit support
|
55 |
|
|
hal_lightweight_driver=true
|
56 |
|
|
hal_enable_small_libc=1
|
57 |
|
|
|
58 |
|
|
# parse cmdline
|
59 |
|
|
while [[ $# -gt 0 ]]
|
60 |
|
|
do
|
61 |
|
|
case $1 in
|
62 |
|
|
--force)
|
63 |
|
|
force="force"
|
64 |
|
|
;;
|
65 |
|
|
--no-make)
|
66 |
|
|
skip_make="no-make"
|
67 |
|
|
;;
|
68 |
|
|
--bloat)
|
69 |
|
|
hal_lightweight_driver=false
|
70 |
|
|
hal_enable_small_libc=0
|
71 |
|
|
;;
|
72 |
|
|
-*|--*)
|
73 |
|
|
exit_with_error "Unknown option: "$1
|
74 |
|
|
;;
|
75 |
|
|
*) POSITIONAL+=("$1")
|
76 |
|
|
;;
|
77 |
|
|
esac
|
78 |
|
|
shift
|
79 |
|
|
done
|
80 |
|
|
if [ ${#POSITIONAL[@]} -gt 0 ]; then
|
81 |
|
|
set -- "${POSITIONAL[@]}"
|
82 |
|
|
fi
|
83 |
|
|
|
84 |
|
|
# check the positional parameters
|
85 |
|
|
if [ $# -ne 2 ]; then
|
86 |
|
|
exit_with_error "Wrong number of arguments specified."
|
87 |
|
|
fi
|
88 |
|
|
buildset=$1
|
89 |
|
|
project=$2
|
90 |
|
|
|
91 |
|
|
# read in the configuration based on the user arguments
|
92 |
|
|
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
# check projectfile
|
96 |
|
|
PRJS="${RADIOHDL_BUILD_DIR}"
|
97 |
|
|
PRJ=
|
98 |
|
|
for prj in ${PRJS}
|
99 |
|
|
do
|
100 |
|
|
if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
|
101 |
|
|
PRJ=${prj}
|
102 |
|
|
fi
|
103 |
|
|
done
|
104 |
|
|
if [ -z "${project}" -o -z "${PRJ}" ]; then
|
105 |
|
|
hdl_error $0 "Please enter a valid project name"
|
106 |
|
|
fi
|
107 |
|
|
|
108 |
|
|
# now we can generate paths
|
109 |
|
|
quartusdir="${PRJ}/${buildset}/quartus/${project}"
|
110 |
|
|
builddir="${quartusdir}/software"
|
111 |
|
|
bspdir="${builddir}/bsp"
|
112 |
|
|
|
113 |
|
|
# assert the quartusdir exists
|
114 |
|
|
hdl_exec $0 msg=no test -d ${quartusdir}
|
115 |
|
|
|
116 |
|
|
# If we have a makefile see if no-one changed the sopcinfo
|
117 |
|
|
# (since if they did we must re-generate files).
|
118 |
|
|
# Otherwise we must generate the BSP package
|
119 |
|
|
|
120 |
|
|
# if "--force" given we build from scratch
|
121 |
|
|
if [ -n "${force}" ]; then
|
122 |
|
|
rm -rf ${bspdir}
|
123 |
|
|
fi
|
124 |
|
|
|
125 |
|
|
if [ -d "${bspdir}" -a -f "${bspdir}/Makefile" ]; then
|
126 |
|
|
#Check if sopcinfo file is newer that current BSP
|
127 |
|
|
# Note: HV/DS We do this in this clumsy way since
|
128 |
|
|
# "make -C ${bspdir} -n" and checking the exitcode
|
129 |
|
|
# does not work on Windows. Winders cannot discriminate
|
130 |
|
|
# between "time-of-last-access" and "time-of-last-modification"
|
131 |
|
|
# whereas under Linux this works like a charm.
|
132 |
|
|
# The result was that under Windows "make -n" would
|
133 |
|
|
# always indicate that the target needed to be rebuilt.
|
134 |
|
|
# Maybe there is another reason - fact is that "make"
|
135 |
|
|
# didn't work on windows. This does.
|
136 |
|
|
sopcfile=$(ls ${quartusdir}/*sopcinfo 2>/dev/null | sed -n '1p')
|
137 |
|
|
if [ -z "${sopcfile}" ]; then
|
138 |
|
|
hdl_error $0 "No sopc(info) file?!!"
|
139 |
|
|
fi
|
140 |
|
|
if [ ${sopcfile} -nt ${bspdir}/settings.bsp ]; then
|
141 |
|
|
hdl_info $0 "Someone has been tinkering with .sopcinfo"
|
142 |
|
|
hdl_info $0 "Regenerating the BSP files"
|
143 |
|
|
hdl_exec $0 msg=no nios2-bsp-generate-files \
|
144 |
|
|
--bsp-dir ${bspdir} \
|
145 |
|
|
--settings ${bspdir}/settings.bsp
|
146 |
|
|
fi
|
147 |
|
|
else
|
148 |
|
|
# we must generate the BSP files
|
149 |
|
|
hdl_info $0 "Generating BSP files for ${project}"
|
150 |
|
|
hdl_exec $0 msg=no nios2-bsp hal ${bspdir} ${quartusdir}
|
151 |
|
|
fi
|
152 |
|
|
|
153 |
|
|
# check if we've already updated the BSP settings to our likings
|
154 |
|
|
if [ -f ${bspdir}/public.mk ]; then
|
155 |
|
|
updated_settings=`sed -n '/^ALT_CPPFLAGS *+= *-DALT_USE_DIRECT_DRIVERS/p' ${bspdir}/public.mk`
|
156 |
|
|
if [ -z "${updated_settings}" ]; then
|
157 |
|
|
# nope, not updated yet - set the settings we would like the bsp to have
|
158 |
|
|
hdl_exec $0 nios2-bsp-update-settings --settings ${bspdir}/settings.bsp \
|
159 |
|
|
--set hal.enable_lightweight_device_driver_api ${hal_lightweight_driver} \
|
160 |
|
|
--set hal.enable_c_plus_plus 0 \
|
161 |
|
|
--set hal.enable_clean_exit 0 \
|
162 |
|
|
--set hal.enable_exit 0 \
|
163 |
|
|
--set hal.enable_small_c_library ${hal_enable_small_libc}
|
164 |
|
|
hdl_exec $0 msg=no nios2-bsp-generate-files \
|
165 |
|
|
--bsp-dir ${bspdir} \
|
166 |
|
|
--settings ${bspdir}/settings.bsp
|
167 |
|
|
# to prevent the make to complain about settings.bsp newer than Makefile ...
|
168 |
|
|
touch ${bspdir}/Makefile
|
169 |
|
|
fi
|
170 |
|
|
fi
|
171 |
|
|
|
172 |
|
|
if [ -z "${skip_make}" ]; then
|
173 |
|
|
hdl_exec $0 msg=no make -C ${bspdir}
|
174 |
|
|
fi
|