-
Notifications
You must be signed in to change notification settings - Fork 12
/
build-module
executable file
·157 lines (132 loc) · 3.51 KB
/
build-module
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
#!/bin/bash
# Copyright 2012 Alexander Lochmann
#
# This file is part of SystemTap4Android.
#
# SystemTap4Android is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SystemTap4Android is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SystemTap4Android. If not, see <http://www.gnu.org/licenses/>.
CONF_DIR="config"
CONF_EXT=".conf"
MODULE_DIR="modules"
SCRIPT_DIR="scripts"
STAP="stap"
ARCHITECTURES=("x86" "arm")
COMPILER_PREFIX_LIST_ARM=("arm-eabi-" "arm-none-linux-gnueabi-" "arm-none-eabi-" "arm-unknown-linux-gnueabi-")
COMPILER_PREFIX_LIST_X86=("" "i686-linux-android-")
function listSupportedDevices()
{
echo -n "devices: "
ls ${CONF_DIR}/*${CONF_EXT} >/dev/null 2>&1
if [ $? -gt 0 ];
then
echo "no devices found"
return
fi
for device in `ls ${CONF_DIR}/*${CONF_EXT}`;
do
device=`basename ${device}`
echo -n ${device%${CONF_EXT}}","
done;
echo "."
}
function checkCompiler()
{
eval COMPILER_PREFIX_LIST=( \"\${COMPILER_PREFIX_LIST_`echo ${KERNEL_ARCH}| tr '[:lower:]' '[:upper:]'`[@]}\")
for cur_compiler_prefix in "${COMPILER_PREFIX_LIST[@]}"
do
CUR_GCC="${cur_compiler_prefix}gcc"
RET=`${CUR_GCC} --version 2>&1`
if [ $? -eq 0 ];
then
#COMPILER_PREFIX=`dirname \`which ${CUR_GCC}\``"/${cur_compiler_prefix}"
COMPILER_PREFIX=${cur_compiler_prefix}
return
fi
done;
echo "No suitable compiler found. Check your PATH" >&2
exit 1
}
function getKernelInfos()
{
if [ ! -d ${CONF_DIR} ];
then
echo "conf directory does not exist" >&2
exit 1
fi
DEVICE=$1
CONF_FILE=${CONF_DIR}/${DEVICE}${CONF_EXT}
if [ -f ${CONF_FILE} ];
then
#KERNEL_SRC=`cat ${CONF_FILE}`
. ${CONF_FILE}
ARCH_FOUND=0
for arch in ${ARCHITECTURES[@]}
do
if [ ${arch} = ${KERNEL_ARCH} ];
then
ARCH_FOUND=1
fi
done
if [ ${ARCH_FOUND} -eq 0 ];
then
echo "unknown kernel architecture '${KERNEL_ARCH}'. Check the corresponding file: ${CONF_FILE}" >&2
exit 1
fi
if [ ! -d ${KERNEL_SRC} ];
then
echo "kernel source tree (${KERNEL_SRC}) does not exit. Check the corresponding config file: ${CONF_FILE}" >&2
exit 1
fi
else
echo "config file (${CONF_FILE}) does not exist." >&2
exit 1
fi
}
function usage()
{
echo "usage: $1 <skriptname> <device> [stap arguments (forwardded to the stap compiler)]]"
listSupportedDevices
exit 1
}
if [ $# -lt 2 ];
then
usage $0
fi
getKernelInfos $2
checkCompiler
SCRIPT=$1
if [ ! -f ${SCRIPT_DIR}/${SCRIPT}".stp" ];
then
echo "The specifid script (${SCRIPT}.stp) does not exist" >&2
exit 1
fi
MODULE_NAME=${SCRIPT//./}
if [ ! -d ${MODULE_DIR} ]; then
echo "module directory does not exist. Creating it..."
mkdir ${MODULE_DIR}
fi
if [ ! -d ${MODULE_DIR}"/"${DEVICE} ]; then
mkdir ${MODULE_DIR}"/"${DEVICE}
fi
if [ -z ${COMPILER_PREFIX} ];
then
CROSS_COMPILE=""
else
CROSS_COMPILE="-B CROSS_COMPILE=${COMPILER_PREFIX}"
fi
STAP_CMD="${STAP} -p 4 -v ${3} -a ${KERNEL_ARCH} ${CROSS_COMPILE} -r ${KERNEL_SRC} -t -g -m ${MODULE_NAME} ${SCRIPT_DIR}/${SCRIPT}.stp"
echo "Executing: ${STAP_CMD}"
${STAP_CMD}
if [ -f ${MODULE_NAME}".ko" ]; then
mv ${MODULE_NAME}".ko" ${MODULE_DIR}"/"${DEVICE}"/"${MODULE_NAME}".ko"
fi;