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