-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·365 lines (318 loc) · 8.8 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
#
#
# get cpu core number
export CPU_JOB_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+2}')
export ARCH=arm
export BUILD_TARGET=""
export TARGET_BOARD=""
export BUILD_DEBUG=0
export BUILD_TOOLCHAIN=""
# for betaflight
export MAJOR_VERSION=3
export MINOR_VERSION=1
export SUB_VERSION=0
# toolchain name
export TOOLCHAIN_4_9_3_PATH_NAME="gcc-arm-none-eabi-4_9-2015q3"
export TOOLCHAIN_4_9_3_PREFIX="arm-none-eabi"
export TOOLCHAIN_5_4_1_PATH_NAME="gcc-arm-none-eabi-5_4-2016q3"
export TOOLCHAIN_5_4_1_PREFIX="arm-none-eabi"
export TOOLCHAIN_6_3_1_PATH_NAME="gcc-arm-none-eabi-6-2017-q1-update"
export TOOLCHAIN_6_3_1_PREFIX="arm-none-eabi"
export TOOLCHAIN_FULL_PATH=""
export TOOLCHAIN_PREFIX_NAME=""
export PLATFORM=""
export BUILD_ROOT_PATH=`pwd`
# -----------------------------------------------------------------
function usage()
{
echo
echo "./build.sh buid=[BUILD_TARGET] target=[TARGET_BOARD] toolchain=[TOOLCHAIN_VERSION] debug "
echo " [BUILD_TARGET]"
echo " cleanflight"
echo " [TARGET_BOARD]"
echo " LUX_RACE : "
echo " SPARKY : "
echo " SPRACINGF3 : "
echo " STM32F3DISCOVERY :"
echo " betaflight"
echo " [TARGET_BOARD]"
echo " LUX_RACE : "
echo " SPARKY : "
echo " SPRACINGF3 : "
echo " STM32F3DISCOVERY :"
echo " nordic"
echo " [TARGET_BOARD]"
echo " s130_central : "
echo " s130_peripheral : "
echo " s130_all : "
echo " s130_beacon : "
echo " [TOOLCHAIN_VERSION]"
echo " 4.9.3 : "
echo " 5.4.1 : "
echo " 6.3.1 : "
echo " debug : "
echo
}
function build()
{
echo "$1 $2"
if [ ! -e "./output/$1" ]
then
echo "mkdir -p ./output/$1"
mkdir -p ./output/$1/
else
echo "rm -rf ./output/$1/*"
rm -rf ./output/$1/*
fi
pushd .
cd $1
{
START_TIME=`date +%s`
make clean TARGET=$2
if [ ${BUILD_DEBUG} == 1 ]
then
echo "build : gdb mode"
make -j$CPU_JOB_NUM TARGET=$2 DEBUG=GDB DEBUG_PORT=DEBUG_SERIAL_UART1
else
echo "build : none gdb mode"
make -j$CPU_JOB_NUM TARGET=$2
fi
if [ $? != 0 ]
then
echo "Build Errror !!!"
return 1
fi
for hex_file in ./obj/*.hex
do
echo "cp $hex_file $BUILD_ROOT_PATH/output/$1/."
cp $hex_file $BUILD_ROOT_PATH/output/$1/.
done
# for cleanflight
# if [ -e "./obj/$1_$2.hex" ]
# then
# echo "cp \"./obj/$1_$2.hex\" $BUILD_ROOT_PATH/output/$1/."
# cp "./obj/$1_$2.hex" $BUILD_ROOT_PATH/output/$1/.
# fi
# for betaflight
# if [ -e "./obj/$1_${MAJOR_VERSION}.${MINOR_VERSION}.${SUB_VERSION}_$2.hex" ]
# then
# echo "cp \"./obj/$1_${MAJOR_VERSION}.${MINOR_VERSION}.${SUB_VERSION}_$2.hex\" $BUILD_ROOT_PATH/output/$1/."
# cp "./obj/$1_${MAJOR_VERSION}.${MINOR_VERSION}.${SUB_VERSION}_$2.hex" $BUILD_ROOT_PATH/output/$1/.
# fi
# for cleanflight & betaflight
if [ -e "./obj/main/$1_$2.elf" ]
then
echo "cp \"./obj/main/$1_$2.elf\" $BUILD_ROOT_PATH/output/$1/."
cp "./obj/main/$1_$2.elf" $BUILD_ROOT_PATH/output/$1/.
echo "cp \"./obj/main/$1_$2.map\" $BUILD_ROOT_PATH/output/$1/."
cp "./obj/main/$1_$2.map" $BUILD_ROOT_PATH/output/$1/.
fi
# for central of nordic
if [ -e "./_build/nrf51_uart_central.hex" ]
then
echo "cp ./_build/nrf51_uart_central.hex $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_central.hex $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/nrf51_uart_central.map $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_central.map $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/nrf51_uart_central.out $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_central.out $BUILD_ROOT_PATH/output/$1/.
fi
# for central of nordic
if [ -e "./_build/nrf51_uart_peripheral.hex" ]
then
echo "cp ./_build/nrf51_uart_peripheral.hex $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_peripheral.hex $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/nrf51_uart_peripheral.map $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_peripheral.map $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/nrf51_uart_peripheral.out $BUILD_ROOT_PATH/output/$1/."
cp ./_build/nrf51_uart_peripheral.out $BUILD_ROOT_PATH/output/$1/.
fi
# for bt_transmitter of nordic
if [ -e "./_build/bt_transmitter.hex" ]
then
echo "cp ./_build/bt_transmitter.hex $BUILD_ROOT_PATH/output/$1/."
cp ./_build/bt_transmitter.hex $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/bt_transmitter.map $BUILD_ROOT_PATH/output/$1/."
cp ./_build/bt_transmitter.map $BUILD_ROOT_PATH/output/$1/.
echo "cp ./_build/bt_transmitter.out $BUILD_ROOT_PATH/output/$1/."
cp ./_build/bt_transmitter.out $BUILD_ROOT_PATH/output/$1/.
fi
# for nordic
if [ -e "../components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex" ]
then
echo "cp ../components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex $BUILD_ROOT_PATH/output/$1/."
cp ../components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex $BUILD_ROOT_PATH/output/$1/.
fi
END_TIME=`date +%s`
echo "============================================================================="
echo "Build time : $((($END_TIME-$START_TIME)/60)) minutes $((($END_TIME-$START_TIME)%60)) seconds"
echo "============================================================================="
} 2>&1 |tee $BUILD_ROOT_PATH/output/$1/build.out
popd
}
# main routine
# ----------------------------------------------
{
clear
# check_param
while [ $# -ge 1 ]
do
key="$1"
case $key in
"build="*)
BUILD_TARGET=${key#build=}
;;
"target="*)
TARGET_BOARD=${key#target=}
;;
"debug"*)
BUILD_DEBUG=1
;;
"toolchain="*)
BUILD_TOOLCHAIN=${key#toolchain=}
;;
*)
echo "Unknown Param : $key"
;;
esac
shift
done
# check Target
case ${BUILD_TARGET} in
"cleanflight")
case ${TARGET_BOARD} in
"LUX_RACE")
;;
"SPARKY")
;;
"SPRACINGF3")
;;
"STM32F3DISCOVERY")
;;
*)
echo "Unknown TARGET BOARD : ${BUILD_TARGET}"
usage
exit 1
;;
esac
;;
"betaflight")
case ${TARGET_BOARD} in
"LUX_RACE")
;;
"SPARKY")
;;
"SPRACINGF3")
;;
"STM32F3DISCOVERY")
;;
*)
echo "Unknown TARGET BOARD : ${BUILD_TARGET}"
usage
exit 1
;;
esac
;;
"nordic")
case ${TARGET_BOARD} in
"s130_central")
;;
"s130_peripheral")
;;
"transmitter")
;;
"s130_all")
;;
"s130_beacon")
;;
*)
echo "Unknown TARGET BOARD : ${BUILD_TARGET}"
usage
exit 1
;;
esac
;;
*)
echo "Unkown target : ${BUILD_TARGET}"
usage
exit 1
;;
esac
# for check platform, default is linux
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
echo "Select Linux platform"
PLATFORM='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
# os x
PLATFORM='mac'
echo "Select Darwin platform"
else
echo "Not supported platform : $unamestr"
exit 1
fi
# check toolchain
case ${BUILD_TOOLCHAIN} in
"4.9.3")
TOOLCHAIN_FULL_PATH=${BUILD_ROOT_PATH}/toolchain/${PLATFORM}/${TOOLCHAIN_4_9_3_PATH_NAME}
TOOLCHAIN_PREFIX_NAME=${TOOLCHAIN_4_9_3_PREFIX}
;;
"5.4.1")
TOOLCHAIN_FULL_PATH=${BUILD_ROOT_PATH}/toolchain/${PLATFORM}/${TOOLCHAIN_5_4_1_PATH_NAME}
TOOLCHAIN_PREFIX_NAME=${TOOLCHAIN_5_4_1_PREFIX}
;;
"6.3.1")
TOOLCHAIN_FULL_PATH=${BUILD_ROOT_PATH}/toolchain/${PLATFORM}/${TOOLCHAIN_6_3_1_PATH_NAME}
TOOLCHAIN_PREFIX_NAME=${TOOLCHAIN_6_3_1_PREFIX}
;;
*)
TOOLCHAIN_FULL_PATH=${BUILD_ROOT_PATH}/toolchain/${PLATFORM}/${TOOLCHAIN_6_3_1_PATH_NAME}
TOOLCHAIN_PREFIX_NAME=${TOOLCHAIN_6_3_1_PREFIX}
;;
esac
# add tool-chain bin directory to PATH
echo $TOOLCHAIN_FULL_PATH
export PATH=${TOOLCHAIN_FULL_PATH}/bin:$PATH
# check gcc compiler
${TOOLCHAIN_PREFIX_NAME}-gcc -v
if [ $? != 0 ]
then
echo
echo "Not found tool-chain for ARM Cortex-M !!!"
echo
exit 1
fi
# check Target
case ${BUILD_TARGET} in
"cleanflight")
build "cleanflight" ${TARGET_BOARD}
;;
"betaflight")
build "betaflight" ${TARGET_BOARD}
;;
"nordic")
export GNU_INSTALL_ROOT=${TOOLCHAIN_FULL_PATH}
export GNU_VERSION=${BUILD_TOOLCHAIN}
export GNU_PREFIX=${TOOLCHAIN_PREFIX_NAME}
case ${TARGET_BOARD} in
"s130_central")
build "nRF51_SDK_v11/nrf51_uart_central"
;;
"s130_peripheral")
build "nRF51_SDK_v11/nrf51_uart_peripheral"
;;
"transmitter")
build "nRF51_SDK_v11/bt_transmitter"
;;
"s130_beacon")
build "nRF51_SDK_v11/nrf51_beacon"
;;
"s130_all")
build "nRF51_SDK_v11/nrf51_uart_central"
build "nRF51_SDK_v11/nrf51_uart_peripheral"
;;
esac
esac
}
# ----------------------------------------------