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