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
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
68 # Force 32bit build on x86-32, default is 64bit
69 if [ "$arch" = "x86-32" ]; then
74 make "${vanilla_config}" CC
="$CC" ${koutput}
79 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
81 # Don't try to sign modules
82 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
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
87 # Set required options
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
97 #cat "${outdir}"/.config
99 make "$oldconf_target" CC
="$CC" ${koutput}
100 make modules_prepare CC
="$CC" ${koutput}
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}
107 # On arm64 between 4.13 and 4.15 this object is required to build with ftrace support
108 if [ "${karch}" = "arm64" ]; then
109 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
110 make arch
/arm64
/kernel
/ftrace-mod.o CC
="$CC" ${koutput}
114 # Version specific tasks
117 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
118 ABINUM
="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
119 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${outdir}"/include
/generated
/utsrelease.h
131 # Enter lttng-modules source dir
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.
136 if { vergte
"$KVERSION" "3.10" && verlte
"$KVERSION" "3.10.13"; } || \
137 { vergte
"$KVERSION" "3.11" && verlte
"$KVERSION" "3.11.2"; }; then
142 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
144 # We expect this build to fail, if it doesn't, fail the job.
145 if [ "$?" -eq 0 ]; then
146 echo "This build should have failed."
150 # We have to publish at least one file or the build will fail
151 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
155 KERNELDIR
="${kdir}" make clean CC
="$CC"
159 # Build modules against full kernel sources
160 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
162 # Install modules to build dir
163 KERNELDIR
="${kdir}" make INSTALL_MOD_PATH
="${bdir}" modules_install CC
="$CC"
166 KERNELDIR
="${kdir}" make clean CC
="$CC"
176 LTTSRCDIR
="${WORKSPACE}/src/lttng-modules"
177 LNXSRCDIR
="${WORKSPACE}/src/linux"
179 LNXBUILDDIR
="${WORKSPACE}/build/linux"
180 LNXHDRDIR
="${WORKSPACE}/build/linux-headers"
182 LTTBUILDKSRCDIR
="${WORKSPACE}/build/lttng-modules-ksrc"
183 LTTBUILDKHDRDIR
="${WORKSPACE}/build/lttng-modules-khdr"
186 # Setup cross compile env if available
187 if [ "x${cross_arch}" != "x" ]; then
189 case "$cross_arch" in
192 cross_compile
="arm-linux-gnueabihf-"
193 vanilla_config
="allyesconfig"
194 ubuntu_config
="armhf-config.flavour.generic"
199 cross_compile
="aarch64-linux-gnu-"
200 vanilla_config
="allyesconfig"
201 ubuntu_config
="arm64-config.flavour.generic"
206 cross_compile
="powerpc-linux-gnu-"
207 vanilla_config
="ppc44x_defconfig"
208 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
213 cross_compile
="powerpc64le-linux-gnu-"
214 vanilla_config
="pseries_le_defconfig"
215 ubuntu_config
="ppc64el-config.flavour.generic"
219 echo "Unsupported cross arch $cross_arch"
224 # Use gcc 4.9, older kernel don't build with gcc 5
225 CC
="${cross_compile}gcc-4.9"
227 # Export variables used by Kbuild for cross compilation
228 export ARCH
="${karch}"
229 export CROSS_COMPILE
="${cross_compile}"
231 oldconf_target
="olddefconfig"
233 # Set arch specific values if we are not cross compiling
234 elif [ "x${arch}" != "x" ]; then
239 vanilla_config
="allyesconfig"
240 ubuntu_config
="i386-config.flavour.generic"
245 vanilla_config
="allyesconfig"
246 ubuntu_config
="amd64-config.flavour.generic"
251 vanilla_config
="allyesconfig"
252 ubuntu_config
="armhf-config.flavour.generic"
257 vanilla_config
="allyesconfig"
258 ubuntu_config
="arm64-config.flavour.generic"
263 vanilla_config
="allyesconfig"
264 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
269 vanilla_config
="allyesconfig"
270 ubuntu_config
="ppc64el-config.flavour.generic"
274 echo "Unsupported arch $arch"
279 # Use gcc 4.9, older kernel don't build with gcc 5
282 oldconf_target
="silentoldconfig"
285 echo "Not arch or cross_arch specified"
292 # Create build directories
293 mkdir
-p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
297 ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
299 # Enter linux source dir
302 # Get kernel version from source tree
303 KVERSION
=$
(make kernelversion
)
305 prepare_lnx_sources
"."
307 # For RT kernels, copy version file
308 if [ -s localversion-rt
]; then
309 cp -a localversion-rt
"${LNXHDRDIR}"
312 # Copy all Makefile related stuff
313 find .
-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}"
319 # Copy base scripts and include dirs
320 cp -a scripts include
"${LNXHDRDIR}"
323 (find arch
-name include
-type d
-print0 | \
324 xargs -0 -n1 -i: find : -type f
) | \
325 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
328 (find arch
-name scripts
-type d
-print0 | \
329 xargs -0 -n1 -i: find : -type f
) | \
330 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
333 rm -f "${LNXHDRDIR}/scripts/*.o"
334 rm -f "${LNXHDRDIR}/scripts/*/*.o"
336 # On powerpc this object is required to link modules
337 if [ "${karch}" = "powerpc" ]; then
338 cp -a --parents arch
/powerpc
/lib
/crtsavres.
[So
] "${LNXHDRDIR}/"
341 # On arm64 between 4.13 and 1.15 this object is required to build with ftrace support
342 if [ "${karch}" = "arm64" ]; then
343 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
344 cp -a --parents arch
/arm64
/kernel
/ftrace-mod.
[So
] "${LNXHDRDIR}/"
348 # Newer kernels need objtool to build modules when CONFIG_STACK_VALIDATION=y
349 if [ -f tools
/objtool
/objtool
]; then
350 cp -a --parents tools
/objtool
/objtool
"${LNXHDRDIR}/"
353 # Copy modules related stuff, if available
354 if [ -s Module.symvers
]; then
355 cp Module.symvers
"${LNXHDRDIR}"
358 if [ -s System.map
]; then
359 cp System.map
"${LNXHDRDIR}"
362 if [ -s Module.markers
]; then
363 cp Module.markers
"${LNXHDRDIR}"
367 cp .config
"${LNXHDRDIR}"
369 # Make sure the Makefile and version.h have a matching timestamp so that
370 # external modules can be built
371 if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
372 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
373 elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
374 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
376 echo "Missing version.h"
379 touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
381 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
382 cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
387 ## PREPARE FULL LINUX SOURCE TREE
389 # Enter linux source dir
392 # Make sure linux source dir is clean
395 prepare_lnx_sources
"${LNXBUILDDIR}"
400 # Build modules against full kernel sources
401 build_modules
"${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
403 # Build modules against kernel headers
404 build_modules
"${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
406 # Make sure modules were built
407 tree
"${LTTBUILDKSRCDIR}"
408 if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
409 echo "No modules built!"
413 tree
"${LTTBUILDKHDRDIR}"
414 if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
415 echo "No modules built!"
This page took 0.043101 seconds and 4 git commands to generate.