3 # Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
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.
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.
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/>.
20 cross_arch
=${cross_arch:-}
26 # Kernel version compare functions
28 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
32 [ "$1" = "$2" ] && return 1 || verlte
"$1" "$2"
36 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
40 [ "$1" = "$2" ] && return 1 || vergte
"$1" "$2"
44 prepare_lnx_sources
() {
48 if [ "$outdir" = "." ]; then
51 koutput
="O=\"${outdir}\""
54 # Generate kernel configuration
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."
63 fakeroot debian
/rules clean
64 fakeroot debian
/rules genconfigs
65 cp CONFIGS
/"${ubuntu_config}" "${outdir}"/.config
69 make "${vanilla_config}" CC
="$CC" ${koutput}
74 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
76 # Don't try to sign modules
77 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
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
82 # Set required options
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
92 make "$oldconf_target" CC
="$CC" ${koutput}
93 make modules_prepare CC
="$CC" ${koutput}
96 #cat "${outdir}"/.config
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}
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}
110 # Version specific tasks
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
127 # Enter lttng-modules source dir
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
138 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
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."
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"
151 KERNELDIR
="${kdir}" make clean CC
="$CC"
155 # Build modules against full kernel sources
156 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
158 # Install modules to build dir
159 KERNELDIR
="${kdir}" make INSTALL_MOD_PATH
="${bdir}" modules_install CC
="$CC"
162 KERNELDIR
="${kdir}" make clean CC
="$CC"
172 LTTSRCDIR
="${WORKSPACE}/src/lttng-modules"
173 LNXSRCDIR
="${WORKSPACE}/src/linux"
175 LNXBUILDDIR
="${WORKSPACE}/build/linux"
176 LNXHDRDIR
="${WORKSPACE}/build/linux-headers"
178 LTTBUILDKSRCDIR
="${WORKSPACE}/build/lttng-modules-ksrc"
179 LTTBUILDKHDRDIR
="${WORKSPACE}/build/lttng-modules-khdr"
182 # Setup cross compile env if available
183 if [ "x${cross_arch}" != "x" ]; then
185 case "$cross_arch" in
188 cross_compile
="arm-linux-gnueabihf-"
189 vanilla_config
="allyesconfig"
190 ubuntu_config
="armhf-config.flavour.generic"
195 cross_compile
="aarch64-linux-gnu-"
196 vanilla_config
="allyesconfig"
197 ubuntu_config
="arm64-config.flavour.generic"
202 cross_compile
="powerpc-linux-gnu-"
203 vanilla_config
="ppc44x_defconfig"
204 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
209 cross_compile
="powerpc64le-linux-gnu-"
210 vanilla_config
="pseries_le_defconfig"
211 ubuntu_config
="ppc64el-config.flavour.generic"
215 echo "Unsupported cross arch $cross_arch"
220 # Use gcc 4.9, older kernel don't build with gcc 5
221 CC
="${cross_compile}gcc-4.9"
223 # Export variables used by Kbuild for cross compilation
224 export ARCH
="${karch}"
225 export CROSS_COMPILE
="${cross_compile}"
227 oldconf_target
="olddefconfig"
229 # Set arch specific values if we are not cross compiling
230 elif [ "x${arch}" != "x" ]; then
235 vanilla_config
="allyesconfig"
236 ubuntu_config
="i386-config.flavour.generic"
241 vanilla_config
="allyesconfig"
242 ubuntu_config
="amd64-config.flavour.generic"
247 vanilla_config
="allyesconfig"
248 ubuntu_config
="armhf-config.flavour.generic"
253 vanilla_config
="allyesconfig"
254 ubuntu_config
="arm64-config.flavour.generic"
259 vanilla_config
="allyesconfig"
260 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
265 vanilla_config
="allyesconfig"
266 ubuntu_config
="ppc64el-config.flavour.generic"
270 echo "Unsupported arch $arch"
275 # Use gcc 4.9, older kernel don't build with gcc 5
278 oldconf_target
="silentoldconfig"
281 echo "Not arch or cross_arch specified"
288 # Create build directories
289 mkdir
-p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
293 ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
295 # Enter linux source dir
298 # Get kernel version from source tree
299 KVERSION
=$
(make kernelversion
)
301 prepare_lnx_sources
"."
303 # For RT kernels, copy version file
304 if [ -s localversion-rt
]; then
305 cp -a localversion-rt
"${LNXHDRDIR}"
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}"
315 # Copy base scripts and include dirs
316 cp -a scripts include
"${LNXHDRDIR}"
319 (find arch
-name include
-type d
-print0 | \
320 xargs -0 -n1 -i: find : -type f
) | \
321 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
324 (find arch
-name scripts
-type d
-print0 | \
325 xargs -0 -n1 -i: find : -type f
) | \
326 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
329 rm -f "${LNXHDRDIR}/scripts/*.o"
330 rm -f "${LNXHDRDIR}/scripts/*/*.o"
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}/"
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}/"
344 # Copy modules related stuff, if available
345 if [ -s Module.symvers
]; then
346 cp Module.symvers
"${LNXHDRDIR}"
349 if [ -s System.map
]; then
350 cp System.map
"${LNXHDRDIR}"
353 if [ -s Module.markers
]; then
354 cp Module.markers
"${LNXHDRDIR}"
358 cp .config
"${LNXHDRDIR}"
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"
367 echo "Missing version.h"
370 touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
372 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
373 cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
378 ## PREPARE FULL LINUX SOURCE TREE
380 # Enter linux source dir
383 # Make sure linux source dir is clean
386 prepare_lnx_sources
"${LNXBUILDDIR}"
391 # Build modules against full kernel sources
392 build_modules
"${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
394 # Build modules against kernel headers
395 build_modules
"${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
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!"
404 tree
"${LTTBUILDKHDRDIR}"
405 if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
406 echo "No modules built!"
This page took 0.060066 seconds and 4 git commands to generate.