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