Commit | Line | Data |
---|---|---|
f3d8604b MJ |
1 | #!/bin/sh -exu |
2 | # | |
3 | # Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com> | |
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU General Public License as published by | |
7 | # the Free Software Foundation, either version 3 of the License, or | |
8 | # (at your option) any later version. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
339db64d MJ |
18 | ## FUNCTIONS ## |
19 | ||
f3d8604b MJ |
20 | # Kernel version compare functions |
21 | verlte() { | |
22 | [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | head -n1`" ] | |
23 | } | |
24 | ||
25 | verlt() { | |
26 | [ "$1" = "$2" ] && return 1 || verlte $1 $2 | |
27 | } | |
28 | ||
29 | vergte() { | |
30 | [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | tail -n1`" ] | |
31 | } | |
32 | ||
33 | vergt() { | |
34 | [ "$1" = "$2" ] && return 1 || vergte $1 $2 | |
35 | } | |
36 | ||
339db64d | 37 | |
7e02032c MJ |
38 | prepare_lnx_sources() { |
39 | ||
40 | outdir=$1 | |
41 | ||
42 | if [ "$outdir" = "." ]; then | |
43 | koutput="" | |
44 | else | |
45 | koutput="O=\"${outdir}\"" | |
46 | fi | |
47 | ||
48 | # Generate kernel configuration | |
49 | case "$kversion" in | |
50 | Ubuntu*) | |
51 | fakeroot debian/rules clean | |
52 | fakeroot debian/rules genconfigs | |
53 | cp CONFIGS/${ubuntu_config} "${outdir}"/.config | |
54 | ;; | |
55 | *) | |
a822250c MJ |
56 | # Que sera sera |
57 | make ${koutput} allyesconfig | |
7e02032c MJ |
58 | ;; |
59 | esac | |
60 | ||
61 | # GCC 4.8 | |
62 | sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config | |
63 | ||
64 | # Don't try to sign modules | |
65 | sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config | |
66 | ||
9ef18fa2 MJ |
67 | # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails |
68 | sed -i "s/CONFIG_STACK_VALIDATION=y/# CONFIG_STACK_VALIDATION is not set/g" "${outdir}"/.config | |
69 | ||
7e02032c MJ |
70 | # Enable CONFIG_KALLSYMS_ALL |
71 | echo "CONFIG_KPROBES=y" >> "${outdir}"/.config | |
72 | echo "CONFIG_FTRACE=y" >> "${outdir}"/.config | |
73 | echo "CONFIG_BLK_DEV_IO_TRACE=y" >> "${outdir}"/.config | |
74 | echo "CONFIG_TRACEPOINTS=y" >> "${outdir}"/.config | |
75 | echo "CONFIG_KALLSYMS_ALL=y" >> "${outdir}"/.config | |
76 | ||
77 | ||
78 | make ${koutput} silentoldconfig | |
79 | make ${koutput} modules_prepare | |
80 | ||
81 | # Version specific tasks | |
82 | case "$kversion" in | |
83 | Ubuntu*) | |
84 | # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code | |
85 | ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)') | |
86 | echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${outdir}/include/generated/utsrelease.h | |
87 | ;; | |
88 | esac | |
89 | ||
90 | # On powerpc this object is required to link modules | |
91 | if [ "${karch}" = "powerpc" ]; then | |
92 | make ${koutput} arch/powerpc/lib/crtsavres.o | |
93 | fi | |
94 | } | |
95 | ||
96 | ||
97 | ||
339db64d MJ |
98 | build_modules() { |
99 | ||
100 | kdir="$1" | |
101 | bdir="$2" | |
102 | ||
103 | # Get kernel version from source tree | |
104 | cd "${kdir}" | |
105 | kversion=$(make kernelversion) | |
106 | ||
107 | # Enter lttng-modules source dir | |
108 | cd "${LTTSRCDIR}" | |
109 | ||
110 | # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the | |
111 | # timekeeping subsystem. We want those build to fail. | |
112 | if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \ | |
113 | { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then | |
114 | ||
115 | set +e | |
116 | ||
117 | # Build modules | |
118 | KERNELDIR="${kdir}" make -j${NPROC} V=1 | |
119 | ||
120 | # We expect this build to fail, if it doesn't, fail the job. | |
121 | if [ "$?" -eq 0 ]; then | |
122 | exit 1 | |
123 | fi | |
124 | ||
125 | # We have to publish at least one file or the build will fail | |
7e02032c | 126 | echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko" |
339db64d MJ |
127 | |
128 | set -e | |
129 | ||
7e02032c MJ |
130 | KERNELDIR="${kdir}" make clean |
131 | ||
339db64d MJ |
132 | else # Regular build |
133 | ||
134 | # Build modules against full kernel sources | |
135 | KERNELDIR="${kdir}" make -j${NPROC} V=1 | |
136 | ||
137 | # Install modules to build dir | |
138 | KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install | |
139 | ||
140 | # Clean build dir | |
141 | KERNELDIR="${kdir}" make clean | |
142 | fi | |
143 | } | |
144 | ||
145 | ||
146 | ## MAIN ## | |
147 | ||
f3d8604b MJ |
148 | # Use all CPU cores |
149 | NPROC=$(nproc) | |
150 | ||
339db64d MJ |
151 | LTTSRCDIR="${WORKSPACE}/src/lttng-modules" |
152 | LNXSRCDIR="${WORKSPACE}/src/linux" | |
153 | ||
154 | LNXBUILDDIR="${WORKSPACE}/build/linux" | |
155 | LNXHDRDIR="${WORKSPACE}/build/linux-headers" | |
156 | ||
a822250c | 157 | LTTBUILDKSRCDIR="${WORKSPACE}/build/lttng-modules-ksrc" |
339db64d MJ |
158 | LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr" |
159 | ||
160 | ||
7e02032c MJ |
161 | # Setup cross compile env if available |
162 | if [ "x${cross_arch:-}" != "x" ]; then | |
163 | ||
164 | case "$cross_arch" in | |
165 | "armhf") | |
166 | karch="arm" | |
167 | cross_compile="arm-linux-gnueabihf-" | |
168 | ubuntu_config="armhf-config.flavour.generic" | |
169 | ;; | |
170 | ||
171 | "arm64") | |
172 | karch="arm64" | |
173 | cross_compile="aarch64-linux-gnu-" | |
174 | ubuntu_config="arm64-config.flavour.generic" | |
175 | ;; | |
176 | ||
177 | "powerpc") | |
178 | karch="powerpc" | |
179 | cross_compile="powerpc-linux-gnu-" | |
180 | ubuntu_config="powerpc-config.flavour.powerpc-smp" | |
181 | ;; | |
182 | ||
183 | "ppc64el") | |
184 | karch="powerpc" | |
185 | cross_compile="powerpc64le-linux-gnu-" | |
186 | ubuntu_config="ppc64el-config.flavour.generic" | |
187 | ;; | |
188 | ||
189 | *) | |
190 | echo "Unsupported cross arch $arch" | |
191 | exit 1 | |
192 | ;; | |
193 | esac | |
339db64d | 194 | |
7e02032c MJ |
195 | # Export variables used by Kbuild for cross compilation |
196 | export ARCH="${karch}" | |
197 | export CROSS_COMPILE="${cross_compile}" | |
339db64d | 198 | |
339db64d | 199 | |
7e02032c MJ |
200 | # Set arch specific values if we are not cross compiling |
201 | elif [ "x${arch:-}" != "x" ]; then | |
202 | case "$arch" in | |
203 | "x86-32") | |
204 | karch="x86" | |
205 | ubuntu_config="i386-config.flavour.generic" | |
206 | ;; | |
207 | ||
208 | "x86-64") | |
209 | karch="x86" | |
210 | ubuntu_config="amd64-config.flavour.generic" | |
211 | ;; | |
212 | ||
213 | "armhf") | |
214 | karch="arm" | |
215 | ubuntu_config="armhf-config.flavour.generic" | |
216 | ;; | |
217 | ||
218 | "arm64") | |
219 | karch="arm64" | |
220 | ubuntu_config="arm64-config.flavour.generic" | |
221 | ;; | |
222 | ||
223 | "powerpc") | |
224 | karch="powerpc" | |
225 | ubuntu_config="powerpc-config.flavour.powerpc-smp" | |
226 | ;; | |
227 | ||
228 | "ppc64el") | |
229 | karch="powerpc" | |
230 | ubuntu_config="ppc64el-config.flavour.generic" | |
231 | ;; | |
232 | ||
233 | *) | |
234 | echo "Unsupported arch $arch" | |
235 | exit 1 | |
236 | ;; | |
237 | esac | |
238 | else | |
239 | echo "Not arch or cross_arch specified" | |
240 | exit 1 | |
241 | fi | |
339db64d | 242 | |
339db64d | 243 | |
b214d997 | 244 | |
339db64d MJ |
245 | |
246 | # Create build directories | |
a822250c | 247 | mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}" |
7e02032c | 248 | |
339db64d MJ |
249 | |
250 | ||
251 | ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL | |
252 | ||
253 | # Enter linux source dir | |
254 | cd "${LNXSRCDIR}" | |
255 | ||
7e02032c | 256 | prepare_lnx_sources "." |
339db64d | 257 | |
b214d997 MJ |
258 | # For RT kernels, copy version file |
259 | if [ -s localversion-rt ]; then | |
260 | cp -a localversion-rt "${LNXHDRDIR}" | |
339db64d MJ |
261 | fi |
262 | ||
b214d997 MJ |
263 | # Copy all Makefile related stuff |
264 | find . -path './include/*' -prune \ | |
265 | -o -path './scripts/*' -prune -o -type f \ | |
266 | \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \ | |
267 | -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \ | |
268 | -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}" | |
339db64d | 269 | |
b214d997 MJ |
270 | # Copy base scripts and include dirs |
271 | cp -a scripts include "${LNXHDRDIR}" | |
339db64d | 272 | |
b214d997 MJ |
273 | # Copy arch includes |
274 | (find arch -name include -type d -print | \ | |
275 | xargs -n1 -i: find : -type f) | \ | |
276 | cpio -pd --preserve-modification-time "${LNXHDRDIR}" | |
339db64d | 277 | |
b214d997 MJ |
278 | # Copy arch scripts |
279 | (find arch -name scripts -type d -print | \ | |
280 | xargs -n1 -i: find : -type f) | \ | |
281 | cpio -pd --preserve-modification-time "${LNXHDRDIR}" | |
339db64d | 282 | |
b214d997 | 283 | # Cleanup scripts |
339db64d MJ |
284 | rm -f "${LNXHDRDIR}/scripts/*.o" |
285 | rm -f "${LNXHDRDIR}/scripts/*/*.o" | |
286 | ||
b214d997 | 287 | # On powerpc this object is required to link modules |
339db64d MJ |
288 | if [ "${karch}" = "powerpc" ]; then |
289 | cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/" | |
290 | fi | |
291 | ||
b214d997 MJ |
292 | # Copy modules related stuff, if available |
293 | if [ -s Module.symvers ]; then | |
294 | cp Module.symvers "${LNXHDRDIR}" | |
295 | fi | |
296 | ||
297 | if [ -s System.map ]; then | |
298 | cp System.map "${LNXHDRDIR}" | |
299 | fi | |
300 | ||
301 | if [ -s Module.markers ]; then | |
302 | cp Module.markers "${LNXHDRDIR}" | |
339db64d MJ |
303 | fi |
304 | ||
b214d997 MJ |
305 | # Copy config file |
306 | cp .config "${LNXHDRDIR}" | |
339db64d MJ |
307 | |
308 | # Make sure the Makefile and version.h have a matching timestamp so that | |
309 | # external modules can be built | |
310 | if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then | |
311 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h" | |
312 | elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then | |
313 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h" | |
314 | else | |
315 | echo "Missing version.h" | |
316 | exit 1 | |
317 | fi | |
318 | touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h" | |
319 | ||
320 | # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. | |
321 | cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf" | |
322 | ||
323 | ||
324 | ||
325 | ||
326 | ## PREPARE FULL LINUX SOURCE TREE | |
f3d8604b MJ |
327 | |
328 | # Enter linux source dir | |
329 | cd "${LNXSRCDIR}" | |
330 | ||
339db64d | 331 | # Make sure linux source dir is clean |
7e02032c | 332 | git clean -xdf |
f3d8604b | 333 | |
7e02032c | 334 | prepare_lnx_sources "${LNXBUILDDIR}" |
b214d997 | 335 | |
f3d8604b | 336 | |
7e02032c | 337 | ## BUILD modules |
f3d8604b | 338 | |
339db64d | 339 | # Build modules against full kernel sources |
a822250c | 340 | build_modules "${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}" |
f3d8604b | 341 | |
339db64d MJ |
342 | # Build modules against kernel headers |
343 | build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}" | |
f3d8604b | 344 | |
b214d997 | 345 | # Make sure modules were built |
a822250c MJ |
346 | tree "${LTTBUILDKSRCDIR}" |
347 | if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then | |
7e02032c MJ |
348 | echo "No modules built!" |
349 | exit 1 | |
350 | fi | |
351 | ||
a822250c MJ |
352 | tree "${LTTBUILDKHDRDIR}" |
353 | if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then | |
7e02032c MJ |
354 | echo "No modules built!" |
355 | exit 1 | |
356 | fi | |
b214d997 | 357 | |
f3d8604b | 358 | # EOF |