amiro-blt / setup.sh @ 93933a75
History | View | Annotate | Download (13.662 KB)
1 |
################################################################################ |
---|---|
2 |
# AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
3 |
# Robot (AMiRo) platform. # |
4 |
# Copyright (C) 2016..2020 Thomas Schöpping et al. # |
5 |
# # |
6 |
# This program is free software: you can redistribute it and/or modify # |
7 |
# it under the terms of the GNU General Public License as published by # |
8 |
# the Free Software Foundation, either version 3 of the License, or # |
9 |
# (at your option) any later version. # |
10 |
# # |
11 |
# This program is distributed in the hope that it will be useful, # |
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
14 |
# GNU General Public License for more details. # |
15 |
# # |
16 |
# You should have received a copy of the GNU General Public License # |
17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
18 |
# # |
19 |
# This research/work was supported by the Cluster of Excellence Cognitive # |
20 |
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
21 |
# funded by the German Research Foundation (DFG). # |
22 |
################################################################################ |
23 |
|
24 |
#!/bin/bash |
25 |
|
26 |
# load library |
27 |
source "$(dirname ${BASH_SOURCE[0]})/tools/bash/setuplib.sh" |
28 |
|
29 |
### print welcome text ######################################################### |
30 |
# Prints a welcome message to standard out. |
31 |
# |
32 |
# usage: printWelcomeText |
33 |
# arguments: n/a |
34 |
# return: n/a |
35 |
# |
36 |
function printWelcomeText { |
37 |
printf "######################################################################\n" |
38 |
printf "# #\n" |
39 |
printf "# Welcome to the AMiRo-BLT setup! #\n" |
40 |
printf "# #\n" |
41 |
printf "######################################################################\n" |
42 |
printf "# #\n" |
43 |
printf "# Copyright (c) 2016..2020 Thomas Schöpping #\n" |
44 |
printf "# #\n" |
45 |
printf "# This is free software; see the source for copying conditions. #\n" |
46 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
47 |
printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
48 |
printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
49 |
printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
50 |
printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
51 |
printf "# Excellence Initiative. #\n" |
52 |
printf "# #\n" |
53 |
printf "######################################################################\n" |
54 |
} |
55 |
|
56 |
### print help ################################################################# |
57 |
# Prints a help text to standard out. |
58 |
# |
59 |
# usage: printHelp |
60 |
# arguments: n/a |
61 |
# return: n/a |
62 |
# |
63 |
function printHelp { |
64 |
printInfo "printing help text\n" |
65 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-f|--stm32flash] [-s|--SerialBoot] [-e|--IDE] [-c|--compiler] [-q|--quit] [--log=<file>]\n" |
66 |
printf "\n" |
67 |
printf "options: -h, --help\n" |
68 |
printf " Print this help text.\n" |
69 |
printf " -f, --stm32flash\n" |
70 |
printf " Run st,32flash tool setup.\n" |
71 |
printf " -s, --SerialBoot\n" |
72 |
printf " Run SerialBoot tool setup.\n" |
73 |
printf " -e, --IDE\n" |
74 |
printf " Enter IDE setup.\n" |
75 |
printf " -c, --compiler\n" |
76 |
printf " Enter compiler setup.\n" |
77 |
printf " -q, --quit\n" |
78 |
printf " Quit the script.\n" |
79 |
printf " --log=<file>\n" |
80 |
printf " Specify a log file.\n" |
81 |
} |
82 |
|
83 |
### stm32flash tool setup ###################################################### |
84 |
# Fetches the source code for the stm32flash tool and builds the binary. |
85 |
# If the tool was already initialized, it can be wiped and rebuilt. |
86 |
# |
87 |
# usage: stm32flashSetup |
88 |
# arguments: n/a |
89 |
# return: 0 |
90 |
# No error or warning occurred. |
91 |
# 1 |
92 |
# Warning: Setup aborted by user. |
93 |
# -1 |
94 |
# Error: Unexpected user input. |
95 |
# -2 |
96 |
# Error: Missing dependecny. |
97 |
# |
98 |
function stm32flashSetup { |
99 |
local amirobltdir=$(dirname $(realpath ${BASH_SOURCE[0]})) |
100 |
local stm32flashdir=${amirobltdir}/Host/Source/stm32flash |
101 |
local userdir=$(pwd) |
102 |
|
103 |
# check dependencies |
104 |
checkCommands git make gcc g++ |
105 |
if [ $? -ne 0 ]; then |
106 |
printError "Missing dependencies detected.\n" |
107 |
return -2 |
108 |
fi |
109 |
|
110 |
# if the stm32flash folder is not empty |
111 |
if [ ! -z "$(ls -A $stm32flashdir)" ]; then |
112 |
printWarning "$stm32flashdir is not empty. Delete and reinitialize? [y/n]\n" |
113 |
local userinput="" |
114 |
readUserInput "YyNn" userinput |
115 |
case "$userinput" in |
116 |
Y|y) |
117 |
printInfo "wiping ${stm32flashdir}...\n" |
118 |
# checkout base commit and delete all local branches |
119 |
cd $amirobltdir |
120 |
git submodule update --force --checkout $stm32flashdir | tee -a $LOG_FILE |
121 |
cd $stm32flashdir |
122 |
local git_branches=($(git for-each-ref --format="%(refname)")) |
123 |
for branch in $git_branches ; do |
124 |
if [[ $branch = *"heads/"* ]]; then |
125 |
git branch -D ${branch##*/} | tee -a $LOG_FILE |
126 |
fi |
127 |
done |
128 |
cd $amirobltdir |
129 |
# deinit stm32flash submodule and delete any remaining files |
130 |
git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE |
131 |
rm -rf $stm32flashdir/* |
132 |
cd $userdir |
133 |
;; |
134 |
N|n) |
135 |
printWarning "stm32flash setup aborted by user\n" |
136 |
return 1 |
137 |
;; |
138 |
*) # sanity check (return error) |
139 |
printError "unexpected input: $userinput\n"; |
140 |
return -1 |
141 |
;; |
142 |
esac |
143 |
fi |
144 |
|
145 |
# initialize submodule |
146 |
printInfo "initializing stm32flash submodule...\n" |
147 |
cd $amirobltdir |
148 |
git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE |
149 |
while [ ${PIPESTATUS[0]} -ne 0 ]; do |
150 |
printWarning "initialitaion failed. Retry? [y/n]\n" |
151 |
local userinput="" |
152 |
readUserInput "YyNn" userinput |
153 |
case "$userinput" in |
154 |
Y|y) |
155 |
git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE;; |
156 |
N|n) |
157 |
printWarning "stm32flash initialization aborted by user\n" |
158 |
cd $userdir |
159 |
return 1 |
160 |
;; |
161 |
*) # sanity check (return error) |
162 |
printError "unexpected input: $userinput\n"; return -1;; |
163 |
esac |
164 |
done |
165 |
cd $userdir |
166 |
|
167 |
# build the stm32flash tool |
168 |
printInfo "compiling stm32flash\n" |
169 |
cd $stm32flashdir |
170 |
make 2>&1 | tee -a $LOG_FILE |
171 |
cd $userdir |
172 |
|
173 |
# notify about udev rules |
174 |
printf "\n" |
175 |
printf "Using the AMiRo programming cable requires additional Linux udev rules (requires root).\n" |
176 |
printf "Please follow the instructions in ${amirobltdir}/README.txt file.\n" |
177 |
read -p " Understood!" |
178 |
|
179 |
return 0 |
180 |
} |
181 |
|
182 |
### SerialBoot tool setup ###################################################### |
183 |
# Builds the SerialBoot tool. |
184 |
# If the tool was built before, it can be deleted and rebuilt. |
185 |
# |
186 |
# usage: serialBootSetup |
187 |
# arguments: n/a |
188 |
# return: 0 |
189 |
# No errort or warning occurred. |
190 |
# 1 |
191 |
# Warning: Setup aborted by user. |
192 |
# -1 |
193 |
# Error: Unexpected user input. |
194 |
# -2 |
195 |
# Error: Missing dependecny. |
196 |
# |
197 |
function serialBootSetup { |
198 |
local amirobltdir=$(dirname $(realpath ${BASH_SOURCE[0]})) |
199 |
local serialbootdir=${amirobltdir}/Host/Source/SerialBoot |
200 |
local userdir=$(pwd) |
201 |
|
202 |
# check dependencies |
203 |
checkCommands make cmake gcc g++ |
204 |
if [ $? -ne 0 ]; then |
205 |
printError "Missing dependencies detected.\n" |
206 |
return -2 |
207 |
fi |
208 |
|
209 |
# if a build folder already exists |
210 |
if [ -d "${serialbootdir}/build/" ]; then |
211 |
printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n" |
212 |
local userinput="" |
213 |
readUserInput "YyNn" userinput |
214 |
case "$userinput" in |
215 |
Y|y) |
216 |
printInfo "deleting ${serialbootdir}/build/...\n" |
217 |
rm -rf "${serialbootdir}/build/" |
218 |
;; |
219 |
N|n) |
220 |
printWarning "SerialBoot setup aborted by user\n" |
221 |
return 1 |
222 |
;; |
223 |
*) # sanity check (return error) |
224 |
printError "unexpected input: $userinput\n"; |
225 |
return -1 |
226 |
;; |
227 |
esac |
228 |
fi |
229 |
|
230 |
# build SerialBoot |
231 |
printInfo "compiling SerialBoot...\n" |
232 |
mkdir ${serialbootdir}/build |
233 |
cd ${serialbootdir}/build |
234 |
cmake .. 2>&1 | tee -a $LOG_FILE |
235 |
make 2>&1 | tee -a $LOG_FILE |
236 |
cd $userdir |
237 |
|
238 |
# notify about udev rules |
239 |
printf "\n" |
240 |
printf "Using the AMiRo programming cable requires additional Linux udev rules (requires root).\n" |
241 |
printf "Please follow the instructions in ${amirobltdir}/README.txt file.\n" |
242 |
read -p " Understood!" |
243 |
|
244 |
return 0 |
245 |
} |
246 |
|
247 |
### IDE setup ################################################################## |
248 |
# Enter the IDE setup. |
249 |
# |
250 |
# usage: ideSetup |
251 |
# arguments: n/a |
252 |
# return: n/a |
253 |
# |
254 |
function ideSetup { |
255 |
printInfo "entering IDE setup\n" |
256 |
printf "\n" |
257 |
if [ -z "$LOG_FILE" ]; then |
258 |
$(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --noinfo |
259 |
else |
260 |
$(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo |
261 |
fi |
262 |
} |
263 |
|
264 |
### compiler setup ############################################################# |
265 |
# Enter the compiler setup. |
266 |
# |
267 |
# usage: compilerSetup |
268 |
# arguments: n/a |
269 |
# return: n/a |
270 |
# |
271 |
function compilerSetup { |
272 |
printInfo "entering compiler setup\n" |
273 |
printf "\n" |
274 |
if [ -z "$LOG_FILE" ]; then |
275 |
$(dirname $(realpath ${BASH_SOURCE[0]}))/tools/compiler/compilersetup.sh --noinfo |
276 |
else |
277 |
$(dirname $(realpath ${BASH_SOURCE[0]}))/tools/compiler/compilersetup.sh --LOG="$LOG_FILE" --noinfo |
278 |
fi |
279 |
} |
280 |
|
281 |
### main function of this script ############################################### |
282 |
# A setup to initialize dependencies, setup IDE projects and configure the |
283 |
# compiler setup. |
284 |
# |
285 |
# usage: see function printHelp |
286 |
# arguments: see function printHelp |
287 |
# return: 0 |
288 |
# No error or warning occurred. |
289 |
# |
290 |
function main { |
291 |
# print welcome/info text if not suppressed |
292 |
if [[ $@ != *"--noinfo"* ]]; then |
293 |
printWelcomeText |
294 |
else |
295 |
printf "######################################################################\n" |
296 |
fi |
297 |
printf "\n" |
298 |
|
299 |
# if --help or -h was specified, print the help text and exit |
300 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
301 |
printHelp |
302 |
printf "\n" |
303 |
quitScript |
304 |
fi |
305 |
|
306 |
# set log file if specified |
307 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
308 |
# get the parameter (file name) |
309 |
local cmdidx=1 |
310 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
311 |
cmdidx=$[cmdidx + 1] |
312 |
done |
313 |
local cmd="${!cmdidx}" |
314 |
local logfile="" |
315 |
if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
316 |
logfile=${cmd#*=} |
317 |
else |
318 |
local filenameidx=$((cmdidx + 1)) |
319 |
logfile="${!filenameidx}" |
320 |
fi |
321 |
# optionally force silent appending |
322 |
if [[ "$cmd" = "--LOG"* ]]; then |
323 |
setLogFile --option=c --quiet "$logfile" LOG_FILE |
324 |
else |
325 |
setLogFile "$logfile" LOG_FILE |
326 |
printf "\n" |
327 |
fi |
328 |
fi |
329 |
# log script name |
330 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
331 |
|
332 |
# parse arguments |
333 |
local otherargs=() |
334 |
while [ $# -gt 0 ]; do |
335 |
if ( parseIsOption $1 ); then |
336 |
case "$1" in |
337 |
-h|--help) # already handled; ignore |
338 |
shift 1;; |
339 |
-f|--stm32flash) |
340 |
stm32flashSetup; printf "\n"; shift 1;; |
341 |
-s|--SerialBoot) |
342 |
serialBootSetup; printf "\n"; shift 1;; |
343 |
-e|--IDE) |
344 |
ideSetup; printf "\n"; shift 1;; |
345 |
-c|--compiler) |
346 |
compilerSetup; printf "\n"; shift 1;; |
347 |
-q|--quit) |
348 |
quitScript; shift 1;; |
349 |
--log=*|--LOG=*) # already handled; ignore |
350 |
shift 1;; |
351 |
--log|--LOG) # already handled; ignore |
352 |
shift 2;; |
353 |
--noinfo) # already handled; ignore |
354 |
shift 1;; |
355 |
*) |
356 |
printError "invalid option: $1\n"; shift 1;; |
357 |
esac |
358 |
else |
359 |
otherargs+=("$1") |
360 |
shift 1 |
361 |
fi |
362 |
done |
363 |
|
364 |
# interactive menu |
365 |
while ( true ); do |
366 |
# main menu info prompt and selection |
367 |
printInfo "AMiRo-BLT setup main menu\n" |
368 |
printf "Please select one of the following actions:\n" |
369 |
printf " [F] - get and build stm32flash tool\n" |
370 |
printf " [S] - build SerialBoot tool\n" |
371 |
printf " [E] - IDE project setup\n" |
372 |
printf " [C] - enter compiler setup\n" |
373 |
printf " [Q] - quit this setup\n" |
374 |
local userinput="" |
375 |
readUserInput "FfSsEeCcQq" userinput |
376 |
printf "\n" |
377 |
|
378 |
# evaluate user selection |
379 |
case "$userinput" in |
380 |
F|f) |
381 |
stm32flashSetup; printf "\n";; |
382 |
S|s) |
383 |
serialBootSetup; printf "\n";; |
384 |
E|e) |
385 |
ideSetup; printf "\n";; |
386 |
C|c) |
387 |
compilerSetup; printf "\n";; |
388 |
Q|q) |
389 |
quitScript;; |
390 |
*) # sanity check (exit with error) |
391 |
printError "unexpected argument: $userinput\n";; |
392 |
esac |
393 |
done |
394 |
|
395 |
exit 0 |
396 |
} |
397 |
|
398 |
################################################################################ |
399 |
# SCRIPT ENTRY POINT # |
400 |
################################################################################ |
401 |
|
402 |
main "$@" |
403 |
|