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() { | |
51fa2ab3 | 22 | [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ] |
f3d8604b MJ |
23 | } |
24 | ||
25 | verlt() { | |
51fa2ab3 | 26 | [ "$1" = "$2" ] && return 1 || verlte "$1" "$2" |
f3d8604b MJ |
27 | } |
28 | ||
29 | vergte() { | |
51fa2ab3 | 30 | [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ] |
f3d8604b MJ |
31 | } |
32 | ||
33 | vergt() { | |
51fa2ab3 | 34 | [ "$1" = "$2" ] && return 1 || vergte "$1" "$2" |
f3d8604b MJ |
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 | |
51fa2ab3 | 53 | cp CONFIGS/"${ubuntu_config}" "${outdir}"/.config |
7e02032c MJ |
54 | ;; |
55 | *) | |
a822250c | 56 | # Que sera sera |
51fa2ab3 | 57 | make "${vanilla_config}" CC="$CC" ${koutput} |
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 | ||
51fa2ab3 MJ |
70 | # Set required options |
71 | { | |
72 | echo "CONFIG_KPROBES=y"; | |
73 | echo "CONFIG_FTRACE=y"; | |
74 | echo "CONFIG_BLK_DEV_IO_TRACE=y"; | |
75 | echo "CONFIG_TRACEPOINTS=y"; | |
76 | echo "CONFIG_KALLSYMS_ALL=y"; | |
77 | } >> "${outdir}"/.config | |
7e02032c MJ |
78 | |
79 | ||
51fa2ab3 MJ |
80 | make "$oldconf_target" CC="$CC" ${koutput} |
81 | make modules_prepare CC="$CC" ${koutput} | |
82 | ||
83 | # Debug | |
84 | #cat "${outdir}"/.config | |
7e02032c | 85 | |
d815b018 MJ |
86 | # On powerpc this object is required to link modules |
87 | if [ "${karch}" = "powerpc" ]; then | |
88 | make arch/powerpc/lib/crtsavres.o CC="$CC" ${koutput} | |
89 | fi | |
90 | ||
7e02032c MJ |
91 | # Version specific tasks |
92 | case "$kversion" in | |
93 | Ubuntu*) | |
94 | # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code | |
51fa2ab3 MJ |
95 | ABINUM="$(echo "$kversion" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')" |
96 | echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${outdir}"/include/generated/utsrelease.h | |
7e02032c MJ |
97 | ;; |
98 | esac | |
7e02032c MJ |
99 | } |
100 | ||
101 | ||
102 | ||
339db64d MJ |
103 | build_modules() { |
104 | ||
105 | kdir="$1" | |
106 | bdir="$2" | |
107 | ||
108 | # Get kernel version from source tree | |
109 | cd "${kdir}" | |
110 | kversion=$(make kernelversion) | |
111 | ||
112 | # Enter lttng-modules source dir | |
113 | cd "${LTTSRCDIR}" | |
114 | ||
115 | # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the | |
116 | # timekeeping subsystem. We want those build to fail. | |
117 | if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \ | |
118 | { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then | |
119 | ||
120 | set +e | |
121 | ||
122 | # Build modules | |
51fa2ab3 | 123 | KERNELDIR="${kdir}" make -j"${NPROC}" V=1 CC="$CC" |
339db64d MJ |
124 | |
125 | # We expect this build to fail, if it doesn't, fail the job. | |
126 | if [ "$?" -eq 0 ]; then | |
e9b44189 | 127 | echo "This build should have failed." |
339db64d MJ |
128 | exit 1 |
129 | fi | |
130 | ||
131 | # We have to publish at least one file or the build will fail | |
7e02032c | 132 | echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko" |
339db64d MJ |
133 | |
134 | set -e | |
135 | ||
51fa2ab3 | 136 | KERNELDIR="${kdir}" make clean CC="$CC" |
7e02032c | 137 | |
339db64d MJ |
138 | else # Regular build |
139 | ||
140 | # Build modules against full kernel sources | |
51fa2ab3 | 141 | KERNELDIR="${kdir}" make -j"${NPROC}" V=1 CC="$CC" |
339db64d MJ |
142 | |
143 | # Install modules to build dir | |
51fa2ab3 | 144 | KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install CC="$CC" |
339db64d MJ |
145 | |
146 | # Clean build dir | |
51fa2ab3 | 147 | KERNELDIR="${kdir}" make clean CC="$CC" |
339db64d MJ |
148 | fi |
149 | } | |
150 | ||
151 | ||
152 | ## MAIN ## | |
153 | ||
f3d8604b MJ |
154 | # Use all CPU cores |
155 | NPROC=$(nproc) | |
156 | ||
339db64d MJ |
157 | LTTSRCDIR="${WORKSPACE}/src/lttng-modules" |
158 | LNXSRCDIR="${WORKSPACE}/src/linux" | |
159 | ||
160 | LNXBUILDDIR="${WORKSPACE}/build/linux" | |
161 | LNXHDRDIR="${WORKSPACE}/build/linux-headers" | |
162 | ||
a822250c | 163 | LTTBUILDKSRCDIR="${WORKSPACE}/build/lttng-modules-ksrc" |
339db64d MJ |
164 | LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr" |
165 | ||
166 | ||
7e02032c MJ |
167 | # Setup cross compile env if available |
168 | if [ "x${cross_arch:-}" != "x" ]; then | |
169 | ||
170 | case "$cross_arch" in | |
171 | "armhf") | |
172 | karch="arm" | |
173 | cross_compile="arm-linux-gnueabihf-" | |
e9b44189 | 174 | vanilla_config="allyesconfig" |
7e02032c MJ |
175 | ubuntu_config="armhf-config.flavour.generic" |
176 | ;; | |
177 | ||
178 | "arm64") | |
179 | karch="arm64" | |
180 | cross_compile="aarch64-linux-gnu-" | |
e9b44189 | 181 | vanilla_config="allyesconfig" |
7e02032c MJ |
182 | ubuntu_config="arm64-config.flavour.generic" |
183 | ;; | |
184 | ||
185 | "powerpc") | |
186 | karch="powerpc" | |
187 | cross_compile="powerpc-linux-gnu-" | |
e9b44189 | 188 | vanilla_config="ppc44x_defconfig" |
7e02032c MJ |
189 | ubuntu_config="powerpc-config.flavour.powerpc-smp" |
190 | ;; | |
191 | ||
192 | "ppc64el") | |
193 | karch="powerpc" | |
194 | cross_compile="powerpc64le-linux-gnu-" | |
e9b44189 | 195 | vanilla_config="pseries_le_defconfig" |
7e02032c MJ |
196 | ubuntu_config="ppc64el-config.flavour.generic" |
197 | ;; | |
198 | ||
199 | *) | |
51fa2ab3 | 200 | echo "Unsupported cross arch $cross_arch" |
7e02032c MJ |
201 | exit 1 |
202 | ;; | |
203 | esac | |
339db64d | 204 | |
fca23c5a MJ |
205 | # Use gcc 4.9, older kernel don't build with gcc 5 |
206 | CC="${cross_compile}gcc-4.9" | |
e9b44189 | 207 | |
7e02032c MJ |
208 | # Export variables used by Kbuild for cross compilation |
209 | export ARCH="${karch}" | |
210 | export CROSS_COMPILE="${cross_compile}" | |
339db64d | 211 | |
e0552fd7 MJ |
212 | oldconf_target="olddefconfig" |
213 | ||
7e02032c MJ |
214 | # Set arch specific values if we are not cross compiling |
215 | elif [ "x${arch:-}" != "x" ]; then | |
e9b44189 | 216 | |
7e02032c MJ |
217 | case "$arch" in |
218 | "x86-32") | |
219 | karch="x86" | |
e9b44189 | 220 | vanilla_config="allyesconfig" |
7e02032c MJ |
221 | ubuntu_config="i386-config.flavour.generic" |
222 | ;; | |
223 | ||
224 | "x86-64") | |
225 | karch="x86" | |
e9b44189 | 226 | vanilla_config="allyesconfig" |
7e02032c MJ |
227 | ubuntu_config="amd64-config.flavour.generic" |
228 | ;; | |
229 | ||
230 | "armhf") | |
231 | karch="arm" | |
e9b44189 | 232 | vanilla_config="allyesconfig" |
7e02032c MJ |
233 | ubuntu_config="armhf-config.flavour.generic" |
234 | ;; | |
235 | ||
236 | "arm64") | |
237 | karch="arm64" | |
e9b44189 | 238 | vanilla_config="allyesconfig" |
7e02032c MJ |
239 | ubuntu_config="arm64-config.flavour.generic" |
240 | ;; | |
241 | ||
242 | "powerpc") | |
243 | karch="powerpc" | |
e9b44189 | 244 | vanilla_config="allyesconfig" |
7e02032c MJ |
245 | ubuntu_config="powerpc-config.flavour.powerpc-smp" |
246 | ;; | |
247 | ||
248 | "ppc64el") | |
249 | karch="powerpc" | |
e9b44189 | 250 | vanilla_config="allyesconfig" |
7e02032c MJ |
251 | ubuntu_config="ppc64el-config.flavour.generic" |
252 | ;; | |
253 | ||
254 | *) | |
255 | echo "Unsupported arch $arch" | |
256 | exit 1 | |
257 | ;; | |
258 | esac | |
e9b44189 MJ |
259 | |
260 | # Use gcc 4.9, older kernel don't build with gcc 5 | |
261 | CC=gcc-4.9 | |
262 | ||
e0552fd7 MJ |
263 | oldconf_target="silentoldconfig" |
264 | ||
7e02032c MJ |
265 | else |
266 | echo "Not arch or cross_arch specified" | |
267 | exit 1 | |
268 | fi | |
339db64d | 269 | |
339db64d | 270 | |
b214d997 | 271 | |
339db64d MJ |
272 | |
273 | # Create build directories | |
a822250c | 274 | mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}" |
7e02032c | 275 | |
339db64d MJ |
276 | |
277 | ||
278 | ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL | |
279 | ||
280 | # Enter linux source dir | |
281 | cd "${LNXSRCDIR}" | |
282 | ||
7e02032c | 283 | prepare_lnx_sources "." |
339db64d | 284 | |
b214d997 MJ |
285 | # For RT kernels, copy version file |
286 | if [ -s localversion-rt ]; then | |
287 | cp -a localversion-rt "${LNXHDRDIR}" | |
339db64d MJ |
288 | fi |
289 | ||
b214d997 MJ |
290 | # Copy all Makefile related stuff |
291 | find . -path './include/*' -prune \ | |
292 | -o -path './scripts/*' -prune -o -type f \ | |
293 | \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \ | |
294 | -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \ | |
295 | -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}" | |
339db64d | 296 | |
b214d997 MJ |
297 | # Copy base scripts and include dirs |
298 | cp -a scripts include "${LNXHDRDIR}" | |
339db64d | 299 | |
b214d997 | 300 | # Copy arch includes |
51fa2ab3 MJ |
301 | (find arch -name include -type d -print0 | \ |
302 | xargs -0 -n1 -i: find : -type f) | \ | |
b214d997 | 303 | cpio -pd --preserve-modification-time "${LNXHDRDIR}" |
339db64d | 304 | |
b214d997 | 305 | # Copy arch scripts |
51fa2ab3 MJ |
306 | (find arch -name scripts -type d -print0 | \ |
307 | xargs -0 -n1 -i: find : -type f) | \ | |
b214d997 | 308 | cpio -pd --preserve-modification-time "${LNXHDRDIR}" |
339db64d | 309 | |
b214d997 | 310 | # Cleanup scripts |
339db64d MJ |
311 | rm -f "${LNXHDRDIR}/scripts/*.o" |
312 | rm -f "${LNXHDRDIR}/scripts/*/*.o" | |
313 | ||
b214d997 | 314 | # On powerpc this object is required to link modules |
339db64d MJ |
315 | if [ "${karch}" = "powerpc" ]; then |
316 | cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/" | |
317 | fi | |
318 | ||
b214d997 MJ |
319 | # Copy modules related stuff, if available |
320 | if [ -s Module.symvers ]; then | |
321 | cp Module.symvers "${LNXHDRDIR}" | |
322 | fi | |
323 | ||
324 | if [ -s System.map ]; then | |
325 | cp System.map "${LNXHDRDIR}" | |
326 | fi | |
327 | ||
328 | if [ -s Module.markers ]; then | |
329 | cp Module.markers "${LNXHDRDIR}" | |
339db64d MJ |
330 | fi |
331 | ||
b214d997 MJ |
332 | # Copy config file |
333 | cp .config "${LNXHDRDIR}" | |
339db64d MJ |
334 | |
335 | # Make sure the Makefile and version.h have a matching timestamp so that | |
336 | # external modules can be built | |
337 | if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then | |
338 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h" | |
339 | elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then | |
340 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h" | |
341 | else | |
342 | echo "Missing version.h" | |
343 | exit 1 | |
344 | fi | |
345 | touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h" | |
346 | ||
347 | # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. | |
348 | cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf" | |
349 | ||
350 | ||
351 | ||
352 | ||
353 | ## PREPARE FULL LINUX SOURCE TREE | |
f3d8604b MJ |
354 | |
355 | # Enter linux source dir | |
356 | cd "${LNXSRCDIR}" | |
357 | ||
339db64d | 358 | # Make sure linux source dir is clean |
7e02032c | 359 | git clean -xdf |
f3d8604b | 360 | |
7e02032c | 361 | prepare_lnx_sources "${LNXBUILDDIR}" |
b214d997 | 362 | |
f3d8604b | 363 | |
7e02032c | 364 | ## BUILD modules |
f3d8604b | 365 | |
339db64d | 366 | # Build modules against full kernel sources |
a822250c | 367 | build_modules "${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}" |
f3d8604b | 368 | |
339db64d MJ |
369 | # Build modules against kernel headers |
370 | build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}" | |
f3d8604b | 371 | |
b214d997 | 372 | # Make sure modules were built |
a822250c MJ |
373 | tree "${LTTBUILDKSRCDIR}" |
374 | if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then | |
7e02032c MJ |
375 | echo "No modules built!" |
376 | exit 1 | |
377 | fi | |
378 | ||
a822250c MJ |
379 | tree "${LTTBUILDKHDRDIR}" |
380 | if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then | |
7e02032c MJ |
381 | echo "No modules built!" |
382 | exit 1 | |
383 | fi | |
b214d997 | 384 | |
f3d8604b | 385 | # EOF |