-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkcc.sh
executable file
·151 lines (126 loc) · 4.2 KB
/
lkcc.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
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
#BASE_URL='ftp://ftp.kernel.org/pub/linux/kernel/v3.x/'
BASE_URL='ftp://www.mirrorservice.org/sites/ftp.kernel.org/pub/linux/kernel/v3.x/'
REPORTS_DIR='./reports/'
DUMPS_DIR='./dumps/'
TEMP_DIR='./temp/'
KERNEL_EXTENSION='.tar.xz'
DUMP_EXTENSION='.dump'
ABI_COMPLIANCE_CHECKER='./bin/abi-compliance-checker/abi-compliance-checker.pl'
ABI_DUMPER='./bin/abi-dumper/abi-dumper.pl'
PATH=./bin/vtable-dumper:$PATH
#Get list of kernels
get_kernels() {
#Download the list of available kernels, without any output
wget --quiet --no-remove-listing $BASE_URL
#Delete file
rm index.html
#Get all the lines from .listing
#Filter the ones that contain "patch"
#Filter the ones that don't contain ".xz"
#Replace one or more 'whitespace' with a single space
#Leave only the 9th column
local kernels=`cat .listing | grep -v "patch" | grep ".xz" | sed -e 's/\s\+/ /g' | cut -d ' ' -f 9`
#Delete file
rm .listing
#Replace 'whitespace' with 'new line'
#Then natural-sort lines
#Then replace 'new line' with 'space'
#Then invert all the lines (the last one becomes the first one, the last-1 becomes the second one, etc...)
local kernels=`echo $kernels | sed -e 's/\s/\n/g' | sort -V | sed -e 's/\n/ /g' | tac`
#Return
echo "$kernels"
}
#Download kernel
download_kernel() {
wget --quiet --output-document="$TEMP_DIR$1$KERNEL_EXTENSION" "$BASE_URL$1$KERNEL_EXTENSION"
echo "OK"
}
#Extract kernel
extract_kernel() {
tar -xJf "$TEMP_DIR$1$KERNEL_EXTENSION" -C "$TEMP_DIR"
echo "OK"
}
#Compile the kernel
compile_kernel() {
local kdir="$TEMP_DIR$1"
#Create a custom .config file
make -C "$kdir" O="`pwd`/$kdir" KCONFIG_CONFIG=custom.config defconfig 2>&1 > /dev/null
#Enable CONFIG_DEBUG_INFO
echo "CONFIG_DEBUG_INFO=y" >> "$kdir/custom.config"
echo "CONFIG_DEBUG_INFO_REDUCED=n" >> "$kdir/custom.config"
#Make the kernel say "No" to anything that doesn't have a default setting yet
make -C "$kdir" O="`pwd`/$kdir" KCONFIG_ALLCONFIG=custom.config allnoconfig 2>&1 > /dev/null
ncpu=`cat /proc/cpuinfo | grep processor | wc -l`
#Build
make -C "$kdir" 2>&1 > /dev/null # -j`expr $ncpu + 1`
echo "OK"
}
#Generate a dump
generate_dump() {
local kdir="$TEMP_DIR$1"
local version=`echo $1 | sed -e 's/linux-//g'`
"$ABI_DUMPER" "$kdir/vmlinux" -o "$kdir/vmlinux$DUMP_EXTENSION" -lver "$version"
}
#Clean
clean_temp() {
local kdir="$TEMP_DIR$1"
mv "$kdir/vmlinux$DUMP_EXTENSION" "$DUMPS_DIR$1_`uname -m`$DUMP_EXTENSION"
rm -rf "$TEMP_DIR$1" "$TEMP_DIR$1$KERNEL_EXTENSION"
}
#Generate a reports
generate_reports() {
local kernels=`ls -l $DUMPS_DIR | grep ".dump" | sed -e 's/\s\+/ /g' | cut -d ' ' -f 9 | sort -V`
mapfile -t kernels <<< "`echo $kernels | sed -e 's/.dump//g' | sed -e 's/\s/\n/g'`"
for kernel in "${kernels[@]}"
do
if [ $kernel == ${kernels[@]:(-1)} ]
then
break
fi
local sw=0
for kernel_lvl2 in "${kernels[@]}"
do
if [ $sw -eq 1 ]
then
local old_version_dump="$DUMPS_DIR${kernel}$DUMP_EXTENSION"
local new_version_dump="$DUMPS_DIR${kernel_lvl2}$DUMP_EXTENSION"
local report_name="$REPORTS_DIR${kernel}---${kernel_lvl2}.html"
if [ ! -f "$report_name" ]
then
"$ABI_COMPLIANCE_CHECKER" -l vmlinux -old "$old_version_dump" -new "$new_version_dump" -affected-limit 10 --report-path="$report_name"
fi
fi
if [ $kernel_lvl2 == $kernel ]
then
sw=1
fi
done
done
}
### Main ###
kernels=$(get_kernels)
mapfile -t kernels <<< "`echo $kernels | sed -e 's/\s/\n/g'`"
for kernel in "${kernels[@]}"
do
kernel_version=`echo $kernel | sed -e 's/.tar.xz//g'`
#Check if a kernel version has a dump file
if [ ! -f "$DUMPS_DIR${kernel_version}_`uname -m`$DUMP_EXTENSION" ]
then
echo "$kernel_version doesn't seem to have a dump!"
echo "Downloading $kernel_version ..."
ret=$(download_kernel "$kernel_version")
echo "Extracting $kernel_version ..."
ret=$(extract_kernel "$kernel_version")
echo "Compiling $kernel_version ..."
ret=$(compile_kernel "$kernel_version")
echo "Generating dump for $kernel_version ..."
ret=$(generate_dump "$kernel_version")
echo "Cleaning temp ..."
ret=$(clean_temp "$kernel_version")
echo "Generating reports for $kernel_version ..."
ret=$(generate_reports)
fi
done