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