forked from Samsung/TizenRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdutils.sh
executable file
·374 lines (335 loc) · 9.09 KB
/
dutils.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
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/env bash
###########################################################################
#
# Copyright 2022 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
###########################################################################
# dutils.sh
OSDIR=`test -d ${0%/*} && cd ${0%/*}; pwd`
CONFIGFILE="${OSDIR}/.config"
TOPDIR="${OSDIR}/.."
BINDIR="${TOPDIR}/build/output/bin"
TRAPDIR="${TOPDIR}/tools/trap"
DOCKER_IMAGE=
DOCKER_PUBLIC_IMAGE="tizenrt/tizenrt"
DOCKER_VERSION="1.5.6"
OUTPUTFILE="dutils_output_"
# Checking docker is installed
nodocker() {
cat <<EOF
You don't have docker installed in your path.
Please find our quick start to build using docker client.
https://github.com/samsung/tizenrt#quick-start
EOF
}
if ! which docker > /dev/null; then
nodocker 1>&2
exit 1
fi
# check docker image and pull docker image
function GET_SPECIFIC_DOCKER_IMAGE()
{
# check existing docker image for specified version
echo "Check Docker Image"
DOCKER_IMAGES=`docker images | grep 'tizenrt' | awk '{print $1":"$2}'`
for im in ${DOCKER_IMAGES}; do
# check public image first
if [ "$im" == "$DOCKER_PUBLIC_IMAGE:$DOCKER_VERSION" ]; then
DOCKER_IMAGE=$DOCKER_PUBLIC_IMAGE
DOCKER_IMAGE_EXIST="true"
break
fi
# Can add other docker image
done
# pull the docker image with specified version
if [ "$DOCKER_IMAGE_EXIST" != "true" ]; then
# try to get public image first
docker pull ${DOCKER_PUBLIC_IMAGE}:${DOCKER_VERSION}
if [ $? -eq 0 ]; then
echo "success to pull docker image: ${DOCKER_PUBLIC_IMAGE}:${DOCKER_VERSION}"
DOCKER_IMAGE=$DOCKER_PUBLIC_IMAGE
return
fi
echo "failed to pull docker image: ${DOCKER_PUBLIC_IMAGE}:${DOCKER_VERSION}"
# Can add other docker image
exit 1
fi
}
KERNEL_DBG_BIN=
APP1_DBG_BIN=app1_dbg
APP2_DBG_BIN=app2_dbg
CMN_DBG_BIN=common_dbg
function FIND_DBGBINFILE()
{
source $CONFIGFILE
if [ ! -z $CONFIG_APP1_BIN_NAME ]; then
APP1_DBG_BIN="${CONFIG_APP1_BIN_NAME}_dbg"
fi
if [ ! -z $CONFIG_APP2_BIN_NAME ]; then
APP2_DBG_BIN="${CONFIG_APP2_BIN_NAME}_dbg"
fi
if [ ! -z $CONFIG_COMMON_BINARY_NAME ]; then
CMN_DBG_BIN="${CONFIG_COMMON_BINARY_NAME}_dbg"
fi
make -C "tools" -f Makefile.export TOPDIR=".." EXPORTDIR=".."
source "./makeinfo.sh"
rm -f "makeinfo.sh"
KERNEL_DBG_BIN="tinyara$EXEEXT"
}
function TRAP_MENU()
{
echo =============================================================================
echo " \"Select binary to debug crash with TRAP tool\""
echo =============================================================================
echo " \"1. Default binary from previous build at build/output/bin location\""
echo " \"2. Custom binary at any location\""
echo " \"x. Exit\""
echo =============================================================================
read SELECT_BIN
case ${SELECT_BIN,,} in
1|default)
if [ -z "$(ls -A $BINDIR)" ]; then
echo "No output file in $BINDIR, Build the code and run TRAP again."
return
fi
echo "Enter the crash log file name relative to os folder: (ex: ../tools/trap/testlogs)"
read LOG_FILE
if [ ! -f ${LOG_FILE} ]; then
echo "$LOG_FILE: No such file, try again"
return
fi
TRAP_RUN log $LOG_FILE
;;
2|manual)
echo "Enter the following wrt os directory"
echo ""
echo "Enter the binary folder name: (ex: ../../build/output/bin/)"
read EXT_BIN_DIR
if [ -z "$(ls -A $EXT_BIN_DIR)" ]; then
echo "$EXT_BIN_DIR Folder does not exit, try again"
return
fi
echo "Enter the configuration file name: (ex: .config)"
read CONFIG_FILE
if [ ! -f ${CONFIG_FILE} ]; then
echo "$CONFIG_FILE: No such file, try again"
return
fi
echo "Enter the crash log file name relative to os folder: (ex: ../tools/trap/testlogs)"
read LOG_FILE
if [ ! -f ${LOG_FILE} ]; then
echo "$LOG_FILE: No such file, try again"
return
fi
TRAP_RUN log $LOG_FILE $EXT_BIN_DIR $CONFIG_FILE
;;
x|exit)
exit 1
;;
esac
}
function TOOLCHAIN_MENU()
{
FIND_DBGBINFILE
TL_BIN=../build/output/bin/
echo ======================================================
echo " \"Select Binary for Toolchain Command\""
echo ======================================================
echo " \"1. Kernel\""
echo " \"2. App1\""
echo " \"3. App2\""
echo " \"4. Common\""
echo " \"5. Enter manually\""
echo " \"x. Exit\""
echo ======================================================
read SELECT_BIN
case ${SELECT_BIN,,} in
1|kernel)
TL_BIN+=$KERNEL_DBG_BIN
;;
2|app1)
TL_BIN+=$APP1_DBG_BIN
;;
3|app2)
TL_BIN+=$APP2_DBG_BIN
;;
4|common)
TL_BIN+=$CMN_DBG_BIN
;;
5|manual)
echo "Enter Debug binary Name"
read BIN_NAME
TL_BIN+=$BIN_NAME
;;
x|exit)
exit 1
;;
esac
echo ======================================================
echo " \"Select Toolchain Command\""
echo ======================================================
echo " \"1. nm\""
echo " \"2. addr2line\""
echo " \"3. Enter manually\""
echo " \"x. Exit\""
echo ======================================================
read SELECT_CMD
case ${SELECT_CMD,,} in
1|nm)
if [ ! -z ${TL_BIN} ];then
if [ ! -f ${TL_BIN} ]; then
echo "Binary file not found: $TL_BIN"
else
TOOLCHAIN tool nm $TL_BIN
fi
else
echo "Binary file not selected!!"
fi
;;
2|addr2line)
if [ ! -z ${TL_BIN} ];then
if [ ! -f ${TL_BIN} ]; then
echo "Binary file not found: $TL_BIN"
else
echo "Enter address: "
read ADDR
TOOLCHAIN tool addr2line -e $TL_BIN $ADDR
fi
else
echo "Binary file not selected!!"
fi
;;
3|manual)
echo "Enter Toolchain command. Ex. addr2line -e <path to bin file> <address>"
read CMD
TOOLCHAIN tool $CMD
;;
x|exit)
exit 1
;;
esac
}
function MENU()
{
unset SELECTED_START
while [ 1 ]; do
OUTPUTFILE="dutils_output_"
if [ ! -z "$1" ];then
SELECTED_START=$1
else
echo ======================================================
echo " \"Select Option\""
echo ======================================================
echo " \"1. Run TRAP Debug tool\""
echo " \"2. Run Toolchain Command\""
echo " \"h. Help\""
echo " \"x. Exit\""
echo ======================================================
read SELECTED_START
fi
case ${SELECTED_START,,} in
1|trap)
TRAP_MENU
;;
2|tool)
TOOLCHAIN_MENU
;;
h|help)
HELP
;;
x|exit)
exit 1
;;
*)
;;
esac
done
}
function TOOLCHAIN()
{
ARGS=arm-none-eabi-$2
OUTPUTFILE+="$2"
TIMESTAMP=$(date "+%Y.%m.%d-%H.%M.%S")
OUTPUTFILE=$OUTPUTFILE"_"$TIMESTAMP.txt
while test $# -gt 0; do
ARGS+=" "$3
shift
done
echo "Executing: $ARGS" | tee $OUTPUTFILE
echo "" >> $OUTPUTFILE
docker run --rm -v ${TOPDIR}:/root/tizenrt -w /root/tizenrt/os --privileged ${DOCKER_IMAGE}:${DOCKER_VERSION} $ARGS | tee -a $OUTPUTFILE
echo ">> Output is stored in $OUTPUTFILE"
}
function TRAP_RUN()
{
TRAPCMD="trap.py -t /root/tizenrt/os/$2"
if [ ! -z "$3" ]; then
# Append the binary path
TRAPCMD+=" -b ../../../os/"$3
fi
if [ ! -z "$4" ]; then
# Append the config path
TRAPCMD+=" -c ../../../os/"$4
fi
OUTPUTFILE+="trap"
TIMESTAMP=$(date "+%Y.%m.%d-%H.%M.%S")
OUTPUTFILE=$OUTPUTFILE"_"$TIMESTAMP.txt
# Parse kernel elf path
make -C "tools" -f Makefile.export TOPDIR=".." EXPORTDIR=".."
source "./makeinfo.sh"
rm -f "makeinfo.sh"
TRAPCMD+=" -e tinyara$EXEEXT"
echo "Executing: $TRAPCMD" | tee $OUTPUTFILE
echo "" >> $OUTPUTFILE
# execute TRAP script
docker run --rm ${DOCKER_OPT} -v ${TOPDIR}:/root/tizenrt -it -w /root/tizenrt/tools/trap/cli --privileged ${DOCKER_IMAGE}:${DOCKER_VERSION} python3.7 $TRAPCMD | tee -a $OUTPUTFILE
echo ">> Output is stored in $OUTPUTFILE"
}
function HELP()
{
echo "Usage: dutils.sh [menu] | [help] | [tool toolchain_cmd]"
echo ""
echo "menu Display interactive menu"
echo "help Display this help menu"
echo "tool Enter toolchain command which will be executed in docker"
echo " Ex: dutils.sh tool nm <relative path to binary file>"
echo "log Enter custom log file which will be execute TRAP in docker"
echo " Ex: dutils.sh log -t <relative path to log file>"
echo " : dutils.sh log -t logs"
echo " Ex: dutils.sh log -t <relative path to log file> -b <relative path to test binaries> -c <relative path to configuration file>"
echo " : dutils.sh log -t logs -b ../../os/testbin/ -c ../../os/cfile"
echo ""
}
GET_SPECIFIC_DOCKER_IMAGE
echo "Docker Image Version : ${DOCKER_IMAGE}:${DOCKER_VERSION}"
if [ -z "$1" ]; then
MENU
elif [ "$1" == "menu" ]; then
MENU
elif [ "$1" == "tool" ]; then
if [ $# -lt 2 ]; then
echo "Invalid arguments!!"
HELP
else
TOOLCHAIN $@
fi
elif [ "$1" == "log" ]; then
TRAP_RUN $@
elif [ "$1" == "help" ]; then
HELP
else
HELP
fi
exit 0