forked from Semihalf/deku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
166 lines (145 loc) · 3.43 KB
/
common.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
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) Semihalf, 2022
# Author: Marek Maślanka <[email protected]>
#
# Common functions
logDebug()
{
[[ "$LOG_LEVEL" > 0 ]] && return
echo "[DEBUG] $1"
}
export -f logDebug
logInfo()
{
[[ "$LOG_LEVEL" > 1 ]] && return
echo "$1"
}
export -f logInfo
logWarn()
{
[[ "$LOG_LEVEL" > 2 ]] && return
echo -e "$ORANGE$1$NC"
}
export -f logWarn
logErr()
{
echo -e "$1" >&2
}
export -f logErr
logFatal()
{
echo -e "$RED$1$NC" >&2
}
export -f logFatal
filenameNoExt()
{
[[ $# = 0 ]] && set -- "$(cat -)" "${@:2}"
local basename=`basename "$1"`
echo ${basename%.*}
}
export -f filenameNoExt
generateSymbols()
{
local kofile=$1
local path=`dirname $kofile`
path=${path#*$MODULES_DIR}
local outfile="$SYMBOLS_DIR/$path/"
mkdir -p "$outfile"
outfile+=$(filenameNoExt "$kofile")
nm -f posix "$kofile" | cut -d ' ' -f 1,2 > "$outfile"
}
export -f generateSymbols
findObjWithSymbol()
{
local sym=$1
local srcfile=$2
#TODO: For module objects try to find symbol in the same module
#TODO: Consider checking type of the symbol
grep -q "\b$sym\b" "$SYSTEM_MAP" && { echo vmlinux; return $NO_ERROR; }
local out=`grep -lr "\b$sym\b" $SYMBOLS_DIR`
[ "$out" != "" ] && { echo $(filenameNoExt "$out"); return $NO_ERROR; }
local srcpath=$SOURCE_DIR/
local modulespath=$MODULES_DIR/
srcpath+=`dirname $srcfile`
modulespath+=`dirname $srcfile`
while true; do
local files=`find "$modulespath" -maxdepth 1 -type f -name "*.ko"`
if [ "$files" != "" ]; then
while read -r file; do
symfile=$(filenameNoExt "$file")
[ -f "$SYMBOLS_DIR/$symfile" ] && continue
generateSymbols $file
done <<< "$files"
out=`grep -lr "\b$sym\b" $SYMBOLS_DIR`
[ "$out" != "" ] && { echo $(filenameNoExt "$out"); return $NO_ERROR; }
fi
[ -f "$srcpath/Kconfig" ] && break
srcpath+="/.."
modulespath+="/.."
done
exit $ERROR_CANT_FIND_SYMBOL
}
export -f findObjWithSymbol
getKernelVersion()
{
grep -r UTS_VERSION "$LINUX_HEADERS/include/generated/" | \
sed -n "s/.*UTS_VERSION\ \"\(.\+\)\"$/\1/p"
}
export -f getKernelVersion
getKernelReleaseVersion()
{
grep -r UTS_RELEASE "$LINUX_HEADERS/include/generated/" | \
sed -n "s/.*UTS_RELEASE\ \"\(.\+\)\"$/\1/p"
}
export -f getKernelReleaseVersion
# find modified files
modifiedFiles()
{
if [[ "$CASHED_MODIFIED_FILES" ]]; then
echo "$CASHED_MODIFIED_FILES"
return
fi
if [ ! "$KERN_SRC_INSTALL_DIR" ]; then
git -C "$workdir" diff --name-only | grep -E ".+\.[ch]$"
return
fi
cd "$SOURCE_DIR/"
local files=`find . -type f -name "*.c" -o -name "*.h"`
cd $OLDPWD
while read -r file; do
if [ "$SOURCE_DIR/$file" -nt "$KERN_SRC_INSTALL_DIR/$file" ]; then
cmp --silent "$SOURCE_DIR/$file" "$KERN_SRC_INSTALL_DIR/$file" || \
echo "${file:2}"
fi
done <<< "$files"
}
export -f modifiedFiles
generateModuleName()
{
local file=$1
local crc=`cksum <<< "$file" | cut -d' ' -f1`
crc=$( printf "%08x" $crc );
local module="$(filenameNoExt $file)"
local modulename=${module/-/_}
echo deku_${crc}_$modulename
}
export -f generateModuleName
generateDEKUHash()
{
local files=`
find command -type f -name "*"; \
find deploy -type f -name "*"; \
find integration -type f -name "*"; \
find . -maxdepth 1 -type f -name "*.sh"; \
find . -maxdepth 1 -type f -name "*.c"; \
echo ./deku \
`
local sum=
while read -r file; do
sum+=`md5sum $file`
done <<< "$files"
sum=`md5sum <<< "$sum" | cut -d" " -f1`
echo "$sum"
}
export -f generateDEKUHash