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 # Kernel version compare functions
22 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
26 [ "$1" = "$2" ] && return 1 || verlte
"$1" "$2"
30 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
34 [ "$1" = "$2" ] && return 1 || vergte
"$1" "$2"
38 prepare_lnx_sources
() {
42 if [ "$outdir" = "." ]; then
45 koutput
="O=\"${outdir}\""
48 # Generate kernel configuration
51 fakeroot debian
/rules clean
52 fakeroot debian
/rules genconfigs
53 cp CONFIGS
/"${ubuntu_config}" "${outdir}"/.config
57 make "${vanilla_config}" CC
="$CC" ${koutput}
62 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
64 # Don't try to sign modules
65 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
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
70 # Set required options
72 echo "CONFIG_KPROBES=y";
73 echo "CONFIG_FTRACE=y";
74 echo "CONFIG_BLK_DEV_IO_TRACE=y";
75 echo "CONFIG_TRACEPOINTS=y";
76 echo "CONFIG_KALLSYMS_ALL=y";
77 } >> "${outdir}"/.config
80 make "$oldconf_target" CC
="$CC" ${koutput}
81 make modules_prepare CC
="$CC" ${koutput}
84 #cat "${outdir}"/.config
86 # On powerpc this object is required to link modules
87 if [ "${karch}" = "powerpc" ]; then
88 make arch
/powerpc
/lib
/crtsavres.o CC
="$CC" ${koutput}
91 # On arm64 this object is required to build with ftrace support
92 if [ "${karch}" = "arm64" ]; then
93 if vergte
"$KVERSION" "4.13-rc1"; then
94 make arch
/arm64
/kernel
/ftrace-mod.o CC
="$CC" ${koutput}
98 # Version specific tasks
101 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
102 ABINUM
="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
103 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${outdir}"/include
/generated
/utsrelease.h
115 # Enter lttng-modules source dir
118 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
119 # timekeeping subsystem. We want those build to fail.
120 if { vergte
"$KVERSION" "3.10" && verlte
"$KVERSION" "3.10.13"; } || \
121 { vergte
"$KVERSION" "3.11" && verlte
"$KVERSION" "3.11.2"; }; then
126 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
128 # We expect this build to fail, if it doesn't, fail the job.
129 if [ "$?" -eq 0 ]; then
130 echo "This build should have failed."
134 # We have to publish at least one file or the build will fail
135 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
139 KERNELDIR
="${kdir}" make clean CC
="$CC"
143 # Build modules against full kernel sources
144 KERNELDIR
="${kdir}" make -j"${NPROC}" V
=1 CC
="$CC"
146 # Install modules to build dir
147 KERNELDIR
="${kdir}" make INSTALL_MOD_PATH
="${bdir}" modules_install CC
="$CC"
150 KERNELDIR
="${kdir}" make clean CC
="$CC"
160 LTTSRCDIR
="${WORKSPACE}/src/lttng-modules"
161 LNXSRCDIR
="${WORKSPACE}/src/linux"
163 LNXBUILDDIR
="${WORKSPACE}/build/linux"
164 LNXHDRDIR
="${WORKSPACE}/build/linux-headers"
166 LTTBUILDKSRCDIR
="${WORKSPACE}/build/lttng-modules-ksrc"
167 LTTBUILDKHDRDIR
="${WORKSPACE}/build/lttng-modules-khdr"
170 # Setup cross compile env if available
171 if [ "x${cross_arch:-}" != "x" ]; then
173 case "$cross_arch" in
176 cross_compile
="arm-linux-gnueabihf-"
177 vanilla_config
="allyesconfig"
178 ubuntu_config
="armhf-config.flavour.generic"
183 cross_compile
="aarch64-linux-gnu-"
184 vanilla_config
="allyesconfig"
185 ubuntu_config
="arm64-config.flavour.generic"
190 cross_compile
="powerpc-linux-gnu-"
191 vanilla_config
="ppc44x_defconfig"
192 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
197 cross_compile
="powerpc64le-linux-gnu-"
198 vanilla_config
="pseries_le_defconfig"
199 ubuntu_config
="ppc64el-config.flavour.generic"
203 echo "Unsupported cross arch $cross_arch"
208 # Use gcc 4.9, older kernel don't build with gcc 5
209 CC
="${cross_compile}gcc-4.9"
211 # Export variables used by Kbuild for cross compilation
212 export ARCH
="${karch}"
213 export CROSS_COMPILE
="${cross_compile}"
215 oldconf_target
="olddefconfig"
217 # Set arch specific values if we are not cross compiling
218 elif [ "x${arch:-}" != "x" ]; then
223 vanilla_config
="allyesconfig"
224 ubuntu_config
="i386-config.flavour.generic"
229 vanilla_config
="allyesconfig"
230 ubuntu_config
="amd64-config.flavour.generic"
235 vanilla_config
="allyesconfig"
236 ubuntu_config
="armhf-config.flavour.generic"
241 vanilla_config
="allyesconfig"
242 ubuntu_config
="arm64-config.flavour.generic"
247 vanilla_config
="allyesconfig"
248 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
253 vanilla_config
="allyesconfig"
254 ubuntu_config
="ppc64el-config.flavour.generic"
258 echo "Unsupported arch $arch"
263 # Use gcc 4.9, older kernel don't build with gcc 5
266 oldconf_target
="silentoldconfig"
269 echo "Not arch or cross_arch specified"
276 # Create build directories
277 mkdir
-p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
281 ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
283 # Enter linux source dir
286 # Get kernel version from source tree
287 KVERSION
=$
(make kernelversion
)
289 prepare_lnx_sources
"."
291 # For RT kernels, copy version file
292 if [ -s localversion-rt
]; then
293 cp -a localversion-rt
"${LNXHDRDIR}"
296 # Copy all Makefile related stuff
297 find .
-path './include/*' -prune \
298 -o -path './scripts/*' -prune -o -type f \
299 \
( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
300 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \
) \
301 -print |
cpio -pd --preserve-modification-time "${LNXHDRDIR}"
303 # Copy base scripts and include dirs
304 cp -a scripts include
"${LNXHDRDIR}"
307 (find arch
-name include
-type d
-print0 | \
308 xargs -0 -n1 -i: find : -type f
) | \
309 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
312 (find arch
-name scripts
-type d
-print0 | \
313 xargs -0 -n1 -i: find : -type f
) | \
314 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
317 rm -f "${LNXHDRDIR}/scripts/*.o"
318 rm -f "${LNXHDRDIR}/scripts/*/*.o"
320 # On powerpc this object is required to link modules
321 if [ "${karch}" = "powerpc" ]; then
322 cp -a --parents arch
/powerpc
/lib
/crtsavres.
[So
] "${LNXHDRDIR}/"
325 # On arm64 this object is required to build with ftrace support
326 if [ "${karch}" = "arm64" ]; then
327 if vergte
"$KVERSION" "4.13-rc1"; then
328 cp -a --parents arch
/arm64
/kernel
/ftrace-mod.
[So
] "${LNXHDRDIR}/"
332 # Copy modules related stuff, if available
333 if [ -s Module.symvers
]; then
334 cp Module.symvers
"${LNXHDRDIR}"
337 if [ -s System.map
]; then
338 cp System.map
"${LNXHDRDIR}"
341 if [ -s Module.markers
]; then
342 cp Module.markers
"${LNXHDRDIR}"
346 cp .config
"${LNXHDRDIR}"
348 # Make sure the Makefile and version.h have a matching timestamp so that
349 # external modules can be built
350 if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
351 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
352 elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
353 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
355 echo "Missing version.h"
358 touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
360 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
361 cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
366 ## PREPARE FULL LINUX SOURCE TREE
368 # Enter linux source dir
371 # Make sure linux source dir is clean
374 prepare_lnx_sources
"${LNXBUILDDIR}"
379 # Build modules against full kernel sources
380 build_modules
"${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
382 # Build modules against kernel headers
383 build_modules
"${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
385 # Make sure modules were built
386 tree
"${LTTBUILDKSRCDIR}"
387 if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
388 echo "No modules built!"
392 tree
"${LTTBUILDKHDRDIR}"
393 if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
394 echo "No modules built!"
This page took 0.043606 seconds and 4 git commands to generate.