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