07324e7c1c0165b12530e6f13fe4f320795c4f47
[lttng-ci.git] / scripts / lttng-modules / param-build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2016-2023 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
18 set -exu
19
20 # Parameters
21 platform=${platforms:-}
22 cross_arch=${cross_arch:-}
23 ktag=${ktag:-}
24 kgitrepo=${kgitrepo:-}
25 mversion=${mversion:-}
26 mgitrepo=${mgitrepo:-}
27 make_args=()
28
29 DEBUG=${DEBUG:-}
30
31 # Derive arch from label if it isn't set
32 if [ -z "${arch:-}" ] ; then
33 # Labels may be platform specific, eg. jammy-amd64, deb12-armhf
34 regex='[[:alnum:]]+-([[:alnum:]]+)'
35 if [[ "${platform}" =~ ${regex} ]] ; then
36 arch="${BASH_REMATCH[1]}"
37 else
38 arch="${platform:-}"
39 fi
40 fi
41
42
43 ## FUNCTIONS ##
44
45 # Kernel version compare functions
46 verlte() {
47 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
48 }
49
50 verlt() {
51 # shellcheck disable=SC2015
52 [ "$1" = "$2" ] && return 1 || verlte "$1" "$2"
53 }
54
55 vergte() {
56 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
57 }
58
59 vergt() {
60 # shellcheck disable=SC2015
61 [ "$1" = "$2" ] && return 1 || vergte "$1" "$2"
62 }
63
64 print_header() {
65 set +x
66
67 local message=" $1 "
68 local message_len
69 local padding_len
70
71 message_len="${#message}"
72 padding_len=$(( (80 - (message_len)) / 2 ))
73
74 printf '\n'; printf -- '#%.0s' {1..80}; printf '\n'
75 printf -- '-%.0s' {1..80}; printf '\n'
76 printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n'
77 printf -- '-%.0s' {1..80}; printf '\n'
78 printf -- '#%.0s' {1..80}; printf '\n\n'
79
80 set -x
81 }
82
83 git_clone_modules_sources() {
84 mkdir -p "$MODULES_GIT_DIR"
85
86 # If the version starts with "refs/", checkout the specific git ref, otherwise treat it
87 # as a branch name.
88 if [ "${mversion:0:5}" = "refs/" ]; then
89 git clone --no-tags --depth=1 "${mgitrepo}" "$MODULES_GIT_DIR"
90 (cd "$MODULES_GIT_DIR" && git fetch origin "${mversion}" && git checkout FETCH_HEAD)
91 else
92 git clone --no-tags --depth=1 -b "${mversion}" "${mgitrepo}" "$MODULES_GIT_DIR"
93 fi
94 }
95
96 # Checkout a shallow kernel tree of the specified tag
97 git_clone_linux_sources() {
98 mkdir -p "$LINUX_GIT_DIR"
99 git clone --depth=1 -b "${ktag}" --reference "$LINUX_GIT_REF_REPO_DIR" "${kgitrepo}" "$LINUX_GIT_DIR"
100 }
101
102
103 # Export the kernel sources from the git repo
104 git_export_linux_sources() {
105 cd "$LINUX_GIT_DIR"
106 git archive "${ktag}" | tar -x -C "$LINUX_SRCOBJ_DIR"
107 }
108
109
110 # Upload the tar archive to the object store
111 upload_archive_obj() {
112 s3cmd -c "$WORKSPACE/.s3cfg" put "$WORKSPACE/$obj_name" "$obj_url_prefix/"
113 rm -f "$WORKSPACE/$obj_name"
114 }
115
116
117 extract_archive_obj() {
118 tar -xf "$WORKSPACE/$obj_name" -C "$LINUX_OBJ_DIR" -I pbzip2
119 rm -f "$WORKSPACE/$obj_name"
120 }
121
122
123 tar_archive_obj() {
124 cd "$LINUX_OBJ_DIR"
125 tar -cf "$WORKSPACE/$obj_name" -I pbzip2 .
126 cd -
127 }
128
129 # List all GCC versions present in the PATH
130 list_gccs() {
131 local gccs
132 gccs=()
133 IFS=: read -r -a path_array <<< "$PATH"
134 while read -r gcc ; do
135 gccs+=("$gcc")
136 done < <(find "${path_array[@]}" -maxdepth 1 -regex '.*/gcc-[0-9\.]+$' -printf '%f\n' | sort -t- -k2 -V -r)
137 echo "${gccs[@]}"
138 }
139
140 # Find the most recent GCC version supported by the kernel sources
141 select_compiler() {
142
143 # Enter linux source dir
144 cd "$LINUX_SRCOBJ_DIR"
145
146 # Get the kernel version using the host toolchain, some cross-compiled arch may be broken
147 kversion=$(unset ARCH; unset CROSS_COMPILE; make -s kernelversion)
148
149 if [ "${cross_arch}" = "riscv64" ] && verlt "${kversion}" "5.12"; then
150 echo "RISC-V support was upstreamed in kernel v4.19 but kprobes support was only added in v5.12. Don't try to build it."
151 exit 0
152 fi
153
154 if [ "${cross_arch}" = "arm64" ] && verlt "${kversion}" "3.7"; then
155 echo "ARM64 support was added as of v3.7. Don't try to build it."
156 exit 0
157 fi
158
159 if [ "${cross_arch}" = "arm64" ] && verlt "${kversion}" "3.18"; then
160 echo "lttng-modules requires gcc >= 5.1 for ARM64 due to compiler bugs in gcc."
161 echo "gcc-5 support was added to the kernel as of v3.18. Don't this to build it."
162 exit 0
163 fi
164
165 if { verlt "$kversion" "4.4"; }; then
166 # Force gcc-4.8 for kernels before 4.4
167 selected_cc='gcc-4.8'
168 # Due to compiler bugs in gcc on arm64, lttng-modules disallows
169 # compilation with gcc < 5.1.
170 if [[ "${cross_arch}" == "arm64" ]] ; then
171 selected_cc='gcc-5.5'
172 export PATH="${PATH:-}:/usr/local/gcc5.5/bin"
173 export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}:/usr/local/gcc5.5/lib"
174 fi
175 selected_cc_version=$(echo "${selected_cc}" | cut -d'-' -f2)
176 else
177 for cc in $(list_gccs) ; do
178 if "${CROSS_COMPILE:-}${cc}" -I include/ -D__LINUX_COMPILER_H -D__LINUX_COMPILER_TYPES_H -E include/linux/compiler-gcc.h; then
179 cc_version=$(echo "${cc}" | cut -d'-' -f2)
180 if { verlt "${kversion}" "5.17"; } && { vergt "${cc_version}" "11"; } ; then
181 # Using gcc-12+ with '-Wuse-after-free' breaks the build of older
182 # kernels (in particular, objtool). Some releases on LTS
183 # branches between 4.x and 5.15 can be built with gcc-12.
184 # @see https://lore.kernel.org/lkml/20494.1643237814@turing-police/
185 # @see https://gitlab.com/linux-kernel/stable/-/commit/52a9dab6d892763b2a8334a568bd4e2c1a6fde66
186 continue
187 fi
188 selected_cc="$cc"
189 selected_cc_version="$cc_version"
190 break
191 fi
192 done
193 fi
194
195 if [ -z "$selected_cc" ]; then
196 echo "Found no suitable compiler."
197 exit 1
198 fi
199
200 # lttng-modules requires gcc >= 5.1 for aarch64
201 # @see https://github.com/lttng/lttng-modules/commit/be06402dbdbea2f3394e60ec15c5d3356e2be416
202 if { verlt "${selected_cc_version}" "5.1"; } && [ "${cross_arch}" = "arm64" ] ; then
203 echo "Building lttng-modules on aarch64 requires gcc >= 5.1"
204 exit 1
205 fi
206
207 cd -
208 }
209
210 export_kbuild_flags() {
211 local _KAFLAGS
212 local _KCFLAGS
213 local _KCPPFLAGS
214 local _HOSTCFLAGS
215
216 _KAFLAGS=()
217 _KCFLAGS=()
218 _KCPPFLAGS=()
219 _HOSTCFLAGS=()
220
221 if { vergte "$selected_cc_version" "6"; }; then
222 # Older kernel Makefiles do not expect the compiler to default to PIE
223 _KAFLAGS+=(-fno-pie)
224 _KCFLAGS+=(
225 -fno-pie
226 -no-pie
227 -fno-stack-protector
228 )
229 _KCPPFLAGS+=(-fno-pie)
230 fi
231
232 if { vergte "${selected_cc_version}" "10"; } && { verlt "${kversion}" "5.10"; } ; then
233 # gcc-10 changed the default from '-fcommon' to '-fno-common', which
234 # causes a linker failure. '-fcommon' can be set on the HOSTCFLAGS
235 # to avoid the issue.
236 # @see https://gitlab.com/linux-kernel/stable/-/commit/e33a814e772cdc36436c8c188d8c42d019fda639
237 _HOSTCFLAGS+=(-fcommon)
238 fi
239
240 if { verlt "${kversion}" "5.14"; } && [ "${cross_arch:-}" == "armhf" ] ; then
241 # Work-around for producing instructions that aren't valid for the
242 # default architectures.
243 # Eg. Error: selected processor does not support `cpsid i' in ARM mode
244 _KCFLAGS+=(-march=armv7-a -mfpu=vfpv3-d16)
245 _KCPPFLAGS+=(-march=armv7-a -mfpu=vfpv3-d16)
246 fi
247
248 if { vergt "${selected_cc_version}" "8"; } && { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.17"; } ; then
249 # This was added to -Wall in gcc 9 but some kernels do not include the fixes
250 # @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88583
251 _KCFLAGS+=(-Wno-error=packed-not-aligned)
252 fi
253
254 export KAFLAGS="${_KAFLAGS[*]}"
255 export KCFLAGS="${_KCFLAGS[*]}"
256 export KCPPFLAGS="${_KCPPFLAGS[*]}"
257 export HOSTCFLAGS="${_HOSTCFLAGS[*]}"
258 export CC="${CROSS_COMPILE:-}${selected_cc}"
259 export HOSTCC="${selected_cc}"
260
261 make_args=(
262 CC="${CC}"
263 HOSTCC="${HOSTCC}"
264 HOSTCFLAGS="${HOSTCFLAGS:-}"
265 )
266
267 if [ -n "${DEBUG}" ] ; then
268 make_args+=(
269 V=1
270 )
271 fi
272 }
273
274 patch_linux_kernel() {
275 local commit_hash
276 commit_hash="$1"
277
278 # Show the title of the patch in the build log
279 git -C "${LINUX_GIT_REF_REPO_DIR}" show --oneline -s "${commit_hash}"
280
281 # Apply patch, don't fail if it doesn't apply cleanly
282 set +e
283 git -C "${LINUX_GIT_REF_REPO_DIR}" format-patch -n1 --stdout "${commit_hash}" | patch -p1
284 set -e
285
286 if [ "$?" -gt 1 ] ; then
287 echo "Serious issue patching"
288 exit 1
289 fi
290 }
291
292 build_linux_kernel() {
293 cd "$LINUX_SRCOBJ_DIR"
294
295 kversion=$(make -s kernelversion "${make_args[@]}")
296 pahole_version="$(pahole --version | tr -d 'v')"
297
298 if { verlt "${kversion}" "3.3"; } && [ "${vanilla_config}" = "imx_v6_v7_defconfig" ] ; then
299 # imx_v6_v7 didn't exist before 06965c39b4c63933fa0a1cde2237ef85477c5655
300 if { verlt "${kversion}" "3.2"; } ; then
301 vanilla_config='mx5_defconfig'
302 else
303 vanilla_config='mx51_defconfig'
304 fi
305 fi
306
307 if { verlt "${kversion}" "3.13"; } && [ "${vanilla_config}" = "pseries_le_defconfig" ] ; then
308 # pseries_le_deconfig was introduced in f53e462e907cbaed29c49c0f10f5b8f614e1bf1d
309 vanilla_config='pseries_defconfig'
310 fi
311
312 # Generate kernel configuration
313 case "$ktag" in
314 Ubuntu*)
315 if [ "${cross_arch}" = "powerpc" ] && vergte "${kversion}" "4.10"; then
316 echo "Ubuntu removed big endian powerpc configuration from kernel >= 4.10. Don't try to build it."
317 exit 0
318 fi
319
320 if [ "${cross_arch}" = "riscv64" ] && verlt "${kversion}" "6.2"; then
321 echo "Ubuntu added RISC-V config to their 'regular' kernels in v6.2. Don't try to build it."
322 exit 0
323 fi
324
325 fakeroot debian/rules clean KW_DEFCONFIG_DIR=.
326
327 # Hack for kernel Ubuntu-hwe-5.8
328 # The debian/control file is produced by the clean target above, so this
329 # check needs to happen afterwards.
330 if [ ! -f "debian/compat" ] && ! grep -q debhelper-compat debian/control; then
331 echo "10" > "debian/compat"
332 fi
333
334 # genconfigs check can fail in certain cases, eg. when a more recent
335 # compiler exposes kernel configuration flags which aren't set in the
336 # Ubuntu annotations.
337 # In any case, the configuration will be updated with any missing values
338 # later in our build script.
339 fakeroot debian/rules genconfigs KW_DEFCONFIG_DIR=. do_skip_checks=true
340 cp CONFIGS/"${ubuntu_config}" .config
341 ;;
342
343 *)
344 # Force 32bit build on i386, default is 64bit
345 if [ "$arch" = "i386" ]; then
346 export ARCH="i386"
347 fi
348
349 make "${vanilla_config}" "${make_args[@]}"
350 ;;
351 esac
352
353 if [ "${vanilla_config}" = "pseries_defconfig" ] && [ "${cross_arch}" = "ppc64el" ] ; then
354 # @see diff <(git show v3.13:arch/powerpc/configs/pseries_defconfig) <(git show v3.13:arch/powerpc/configs/pseries_le_defconfig)
355 scripts/config --enable CONFIG_CPU_LITTLE_ENDIAN
356 scripts/config --enable CONFIG_CMA
357 scripts/config --disable CONFIG_XMON_DEFAULT
358 # scripts/config --disable CONFIG_VIRTUALIZATION
359 # scripts/config --disable CONFIG_KVM_BOOK3S_64
360 scripts/config --disable CONFIG_KVM_BOOK3S_64_HV
361 fi
362
363 # oldnoconfig was renamed in 4.19
364 if vergte "$kversion" "4.19"; then
365 update_conf_target="olddefconfig"
366 else
367 update_conf_target="oldnoconfig"
368 fi
369
370 # Fix 'defined(@array)' was removed from recent perl
371 if [ -f "kernel/timeconst.pl" ]; then
372 sed -i 's/defined(\@\(.*\))/@\1/' kernel/timeconst.pl
373 fi
374
375 # Fix syntax of inline assembly which is confused with C++11 raw strings on gcc >= 5
376 if [ "$HOSTCC" != "gcc-4.8" ]; then
377 if [ -f "arch/x86/kvm/svm.c" ]; then
378 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch/x86/kvm/svm.c
379 fi
380
381 if [ -f "arch/x86/kvm/vmx.c" ]; then
382 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch/x86/kvm/vmx.c
383 fi
384 fi
385
386 if { verlt "${kversion}" "5.11"; } && { vergte "${kversion}" "4.10"; } ; then
387 # Binutils > 2.35 strips empty symbol tables, causing obltool to fail
388 # in certain cases when files are empty.
389 # @see https://gitlab.com/linux-kernel/stable/-/commit/1d489151e9f9d1647110277ff77282fe4d96d09b
390 #
391 # There doesn't seem to be any LD/AS/AR flags to control this behaviour,
392 # therefore patching tools/objtool/elf.c is attempted.
393 patch_linux_kernel 1d489151e9f9d1647110277ff77282fe4d96d09b
394 if { verlt "${kversion}" "4.18"; } ; then
395 patch_linux_kernel e81e0724432542af8d8c702c31e9d82f57b1ff31
396 fi
397 fi
398
399 if { vergt "${selected_cc_version}" "7"; } && { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.17"; } ; then
400 # Builds fail due to -Werror=restrict in pager.o and str_error_r.o
401 if { verlt "${kversion}" "4.16"; } ; then
402 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
403 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ad343a98e74e85aa91d844310e797f96fee6983b
404 patch_linux_kernel ad343a98e74e85aa91d844310e797f96fee6983b
405 fi
406 if { verlt "${kversion}" "4.17"; } ; then
407 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
408 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=854e55ad289ef8888e7991f0ada85d5846f5afb9
409 patch_linux_kernel 854e55ad289ef8888e7991f0ada85d5846f5afb9
410 fi
411
412 fi
413
414 if { vergt "${selected_cc_version}" "9"; } && { verlt "${kversion}" "5.6"; } ; then
415 # Duplicate decalarations of __force_order
416 # @see https://gitlab.com/linux-kernel/stable/-/commit/df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
417 # However, kaslr_64.c doesn't exit in 4.15, 4.16, it's named pagetable.c
418 if [ -f arch/x86/boot/compressed/pagetable.c ] ; then
419 sed -i '/^unsigned long __force_order;$/d' arch/x86/boot/compressed/pagetable.c
420 fi
421 if [ -f arch/x86/boot/compressed/kaslr_64.c ] ; then
422 patch_linux_kernel df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
423 fi
424 fi
425
426 if { vergte "${kversion}" "4.18"; } && { verlt "${kversion}" "4.19"; } ; then
427 # In some cases, compiling net/bpfilter can fail with the following error:
428 # net/bpfilter/main.c:9:10: fatal error: include/uapi/linux/bpf.h: No such file or directory
429 # make[2]: *** [scripts/Makefile.host:107: net/bpfilter/main.o] Error 1
430 #
431 # While the issue is potentially in a number of old versions, it has only
432 # been observed in v4.18-rt
433 #
434 patch_linux_kernel 303a339f30a9441c4695d3d2cc78f1b33cd959ff
435 fi
436
437 if { vergte "${kversion}" "4.18"; } && { verlt "${kversion}" "4.19"; } ; then
438 # In some cases, compiling net/bpfilter can fail with the following error:
439 # net/bpfilter/main.c:9:10: fatal error: include/uapi/linux/bpf.h: No such file or directory
440 # make[2]: *** [scripts/Makefile.host:107: net/bpfilter/main.o] Error 1
441 #
442 # While the issue is potentially in a number of old versions, it has only
443 # been observed in v4.18-rt
444 #
445 patch_linux_kernel 303a339f30a9441c4695d3d2cc78f1b33cd959ff
446 fi
447
448 if { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.18"; } ; then
449 # Some old kernels fail to build when make is too new
450 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
451 patch_linux_kernel 9564a8cf422d7b58f6e857e3546d346fa970191e
452 fi
453
454 if { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.55"; } ; then
455 # Some old kernels fail to build when make is too new
456 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
457 patch_linux_kernel e82885490a611f2b75a6c27cd7bb09665c1740be
458 fi
459
460 if ( { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.18"; } ) || \
461 ( { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.56"; } ) ; then
462 # Some old kernels fail to build when make is too new
463 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
464 patch_linux_kernel 9feeb638cde083c737e295c0547f1b4f28e99583
465 fi
466
467 if ( { vergte "${kversion}" "4.12"; } && { verlt "${kversion}" "4.20.17"; } ) || \
468 ( { vergte "${kversion}" "5.0"; } && { verlt "${kversion}" "5.0.12"; } ) ; then
469 # Old kernels can fail to build while on newer host kernels with errors
470 # such as:
471 # In file included from scripts/selinux/genheaders/genheaders.c:19:
472 # ./security/selinux/include/classmap.h:249:2: error: #error New address family defined, please update secclass_map.
473 # @see https://gitlab.com/linux-kernel/stable/-/commit/dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
474 #
475 patch_linux_kernel dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
476 fi
477
478 # Compatibility with binutils >= ~ 2.31
479 if { vergte "${kversion}" "3.19"; } && { verlt "${kversion}" "4.16"; } ; then
480 patch_linux_kernel b21ebf2fb4cde1618915a97cc773e287ff49173e
481 fi
482 if { vergte "${kversion}" "3.17"; } && { verlt "${kversion}" "3.18.69"; } ; then
483 patch_linux_kernel edb9d2d5e647e7a8521b0d35f8452deb02dfd138
484 fi
485 if { vergte "${kversion}" "3.17"; } && { verlt "${kversion}" "3.18.100"; } ; then
486 patch_linux_kernel 3be6583f0b6f1bf1ee650ebf473d9dee36836527
487 patch_linux_kernel 12d839211d080f6a9c370398c41a260365d34c62
488 fi
489 if { vergte "${kversion}" "3.16"; } && { verlt "${kversion}" "3.16.82"; } ; then
490 patch_linux_kernel ad10e6d464796f2a481de4039a43b9cfca034e1c
491 fi
492
493 if ( { vergte "${kversion}" "3.14"; } && { verlt "${kversion}" "4.4"; } ) ||
494 ( { vergte "${kversion}" "4.8"; } && { verlt "${kversion}" "4.18"; } ); then
495 # While the original motivation of this patch is for fixing builds using
496 # clang, the same error occurs between linux >= 3.14 and < 4.4, and in
497 # 4.15, 4.16.
498 # For rt-linux, the error has been observed in 4.8, 4.11, and 4.13.
499 #
500 # This patch only partially applies due to changes in kernel/Makefile,
501 # so a supplementary patch is needed
502 #
503 # Without this patch, builds fail with
504 # Cannot find symbol for section 2: .text.
505 # kernel/elfcore.o: failed
506 #
507 # @see https://github.com/linuxppc/issues/issues/388
508 # @see https://lore.kernel.org/lkml/20201204165742.3815221-2-arnd@kernel.org/
509 #
510 patch_linux_kernel 6e7b64b9dd6d96537d816ea07ec26b7dedd397b9
511 if grep -q elfcore.o kernel/Makefile ; then
512 sed -i '/^.* += elfcore.o$/d' kernel/Makefile
513 fi
514 fi
515 # Same as above for the v4.4 branch
516 if ( { vergte "${kversion}" "4.4"; } && { verlt "${kversion}" "4.4.257"; } ); then
517 patch_linux_kernel 3140b0740b31cc63cf2ee08bc3f746b423eb068d
518 if grep -q elfcore.o kernel/Makefile ; then
519 sed -i '/^.* += elfcore.o$/d' kernel/Makefile
520 fi
521 fi
522
523 if { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.8"; } ; then
524 # Kernels between v4.5 and v4.8 built with gcc >= 8 on arm will hit an
525 # assembler error :
526 #
527 # kernel/.tmp_fork.s: Assembler messages:
528 # kernel/.tmp_fork.s:1790: Error: .err encountered
529 #
530 # @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85745
531 #
532 patch_linux_kernel 9f73bd8bb445e0cbe4bcef6d4cfc788f1e184007
533 fi
534
535 if ( { vergte "${kversion}" "4.4"; } && { verlt "${kversion}" "4.4.136"; } ) ||
536 ( { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.8"; } ); then
537 # Hacky patch to deal with the following build error:
538 # Cannot find symbol for section 7: .text.unlikely.
539 # kernel/kexec_file.o: failed
540 # make[1]: *** [scripts/Makefile.build:291: kernel/kexec_file.o] Error 1
541 #
542 # This error happens with binutils 2.36 and 2.37, but should probably not
543 # be an issue with binutils 2.38.
544 # @see https://github.com/linuxppc/issues/issues/388
545 # @see https://github.com/bminor/binutils-gdb/commit/c09c8b42021180eee9495bd50d8b35e683d3901b
546 #
547 # There is some sort of config (unspecified in past discussions) which
548 # provokes the error, and there was never a potential fix merged in
549 # this discussion, in part because the build systems of the kernel
550 # switched to objtool instead.
551 #
552 # @see https://lore.kernel.org/all/20210215162209.5e2a475b@gandalf.local.home/
553 #
554 sed -i 's/return txtname;/return shdr0->sh_size ? txtname : NULL;/' scripts/recordmcount.h
555
556 # After applying the above patch, the build continues but fails with
557 # head64.c:(.text.exit+0x5): undefined reference to `__gcov_exit'
558 #
559 scripts/config --disable CONFIG_GCOV_KERNEL
560 fi
561
562 if { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.5.5"; } ; then
563 # drivers/staging/wilc1000/wilc_spi.c:123:34: error: storage size of ‘wilc1000_spi_ops’ isn’t known
564 patch_linux_kernel ce7b516f3f9e11fe4ee06fad0d7e853bb6e8f160
565 fi
566
567 # Newer binutils don't accept 3 operand 'cmp' instructions on ppc64
568 # Convert them to 'cmpw' which was previously done silently
569 if verlt "$kversion" "4.9"; then
570 find arch/powerpc/ -name "*.S" -print0 | xargs -0 sed -i "s/\(cmp\)\(\s\+[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+\)/cmpw\2/"
571 find arch/powerpc/ -name "*.S" -print0 | xargs -0 sed -i "s/\(cmpli\)\(\s\+[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+\)/cmplwi\2/"
572 sed -i "s/\$pie \-o \"\$ofile\"/\$pie --no-dynamic-linker -o \"\$ofile\"/" arch/powerpc/boot/wrapper
573 fi
574
575 if [ "$(scripts/config --state CONFIG_EXTCON_ADC_JACK)" != "n" ] &&
576 ( { vergte "${kversion}" "4.2"; } && { verlt "${kversion}" "4.12"; } ); then
577 # 73b6ecdb93e8e77752cae9077c424fcdc6f23c39 introduced a change where
578 # extcon-adc-jack.h has an incompatible pointer type.
579 # In GCC >= 5 this will provoke a warning and build failure.
580 # Eg.
581 # drivers/extcon/extcon-adc-jack.c: In function ‘adc_jack_probe’:
582 # drivers/extcon/extcon-adc-jack.c:111:64: error: passing argument 2 of ‘devm_extcon_dev_allocate’ from incompatible pointer type [-Werror=incompatible-pointer-types]
583 # make[2]: *** [scripts/Makefile.build:295: drivers/extcon/extcon-adc-jack.o] Error 1
584 #
585 # 8a522bf2d4f788306443d36b26b54f0aedcdfdbe (in 4.11) has a fix for this warning
586 #
587 patch_linux_kernel 8a522bf2d4f788306443d36b26b54f0aedcdfdbe
588 fi
589
590 if ( { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.15.2"; } ) || \
591 ( { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.18"; } ) ; then
592 # Fix an objtool Segmentation fault
593 patch_linux_kernel dd12561854824fd1f05baf2a1b794faa046e2425
594 fi
595
596 if { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.268"; } ; then
597 # Builds fail due to -Werror=use-after-free in sigchain.o and help.o
598 patch_linux_kernel e89bb266b710ce056f141f29f091fd468a4a8185
599 fi
600
601 # Fix a typo in v2.6.36.x
602 if [ -f "arch/x86/kernel/entry_64.S" ]; then
603 sed -i 's/END(do_hypervisor_callback)/END(xen_do_hypervisor_callback)/' arch/x86/kernel/entry_64.S
604 fi
605
606 # Fix compiler switch in vdso Makefile for 2.6.36 to 2.6.36.2
607 if { vergte "$kversion" "2.6.36" && verlte "$kversion" "2.6.36.3"; }; then
608 sed -i 's/-m elf_x86_64/-m64/' arch/x86/vdso/Makefile
609 sed -i 's/-m elf_i386/-m32/' arch/x86/vdso/Makefile
610 fi
611
612 # Fix kernel < 3.0 with gcc >= 4.7
613 if verlt "$kversion" "3.0"; then
614 sed -i '/linux\/compiler.h/a #include <linux\/linkage.h> \/* For asmregparm *\/' arch/x86/include/asm/ptrace.h
615 sed -i 's/extern long syscall_trace_enter/extern asmregparm long syscall_trace_enter/' arch/x86/include/asm/ptrace.h
616 sed -i 's/extern void syscall_trace_leave/extern asmregparm void syscall_trace_leave/' arch/x86/include/asm/ptrace.h
617 echo "header-y += linkage.h" >> include/linux/Kbuild
618 fi
619
620 if [ "${cross_arch}" = "powerpc" ] ; then
621 if { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.16"; } ; then
622 # Avoid register errors such as
623 # aes_generic.c:(.text+0x4e0): undefined reference to `_restgpr_31_x'
624 # @see https://gitlab.com/linux-kernel/stable/-/commit/148b974deea927f5dbb6c468af2707b488bfa2de
625 make_args+=(
626 CFLAGS_aes_generic.o=''
627 )
628 fi
629 fi
630
631 if [ "$(scripts/config --state CONFIG_DEBUG_INFO_BTF)" == "y" ] &&
632 { vergte "${pahole_version}" "1.24"; } &&
633 { vergte "${kversion}" "5.10"; } && { verlt "${kversion}" "6.0"; } ;then
634 # Some kernels Eg. Ubuntu-hwe-5.13-5.13.0-52.59_20.04.1
635 # fail with the following error:
636 # BTFIDS vmlinux
637 # FAILED: load BTF from vmlinux: Invalid argument
638 #
639 # When CONFIG_DEBUG_INFO_BTF is set, certain versions of pahole require
640 # `--skip_encoding_btf_enum64` to be passed as the kernel doesn't define
641 # BTF_KIND_ENUM64.
642 #
643 # Introduced in 341dfcf8d78eaa3a2dc96dea06f0392eb2978364 (~v5.10)
644 # @see https://lore.kernel.org/bpf/20220825171620.cioobudss6ovyrkc@altlinux.org/t/
645 #
646 if [ -f "scripts/pahole-flags.sh" ] ; then
647 # shellcheck disable=SC2016
648 sed -i 's/ -J ${PAHOLE_FLAGS} / -J ${PAHOLE_FLAGS} --skip_encoding_btf_enum64 /' scripts/link-vmlinux.sh
649 else
650 # shellcheck disable=SC2016
651 sed -i 's/ -J ${extra_paholeopt} / -J ${extra_paholeopt} --skip_encoding_btf_enum64 /' scripts/link-vmlinux.sh
652 fi
653 fi
654
655 # GCC 4.8
656 if [ "$HOSTCC" == "gcc-4.8" ]; then
657 scripts/config --disable CONFIG_CC_STACKPROTECTOR_STRONG
658 scripts/config --disable CONFIG_PPC_OF_BOOT_TRAMPOLINE
659 fi
660
661 # Don't try to sign modules
662 scripts/config --disable CONFIG_MODULE_SIG
663
664 # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
665 scripts/config --disable CONFIG_STACK_VALIDATION
666
667 # Cause problems with inline assembly on i386
668 scripts/config --disable CONFIG_DEBUG_SECTION_MISMATCH
669
670 # Don't build samples, they are broken on some kernel releases
671 scripts/config --disable CONFIG_SAMPLES
672 scripts/config --disable CONFIG_BUILD_DOCSRC
673
674 # Disable kcov
675 scripts/config --disable CONFIG_KCOV
676
677 # Broken on some RT kernels
678 scripts/config --disable CONFIG_HYPERV
679
680 # Broken drivers
681 scripts/config --disable CONFIG_RAPIDIO_TSI721
682 scripts/config --disable CONFIG_SGI_XP
683 scripts/config --disable CONFIG_MFD_WM8994
684 scripts/config --disable CONFIG_DRM_RADEON
685 scripts/config --disable CONFIG_SND_SOC_WM5100
686 # More recent compiler optimizations (from gcc 8 onwards )expose build errors
687 # with netronome on older kernels.
688 # Observed in 4.11-rt, 4.15-4.17, 5.0-rt - 5.16-rt
689 # It seems easier to disable the driver than to attempt patching.
690 # Eg.
691 # In function ‘ur_load_imm_any’,
692 # inlined from ‘jeq_imm’ at drivers/net/ethernet/netronome/nfp/bpf/jit.c:3146:13:
693 # ./include/linux/compiler.h:350:45: error: call to ‘__compiletime_assert_1062’ declared with attribute error: FIELD_FIT: value too large for the field
694 # 350 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
695 #
696 scripts/config --disable CONFIG_NET_VENDOR_NETRONOME
697 # Eg.
698 # In function ‘memcpy’,
699 # inlined from ‘kszphy_get_strings’ at drivers/net/phy/micrel.c:664:3:
700 # ./include/linux/string.h:305:25: error: call to ‘__read_overflow2’ declared with attribute error: detected read beyond size of object passed as 2nd parameter
701 # 305 | __read_overflow2();
702 # | ^~~~~~~~~~~~~~~~~~
703 # make[3]: *** [scripts/Makefile.build:308: drivers/net/phy/micrel.o] Error 1
704 #
705 scripts/config --disable CONFIG_MICREL_PHY
706
707
708 # IGBVF won't build with recent gcc on 2.6.38.x
709 if { vergte "$kversion" "2.6.37" && verlt "$kversion" "2.6.38"; }; then
710 scripts/config --disable CONFIG_IGBVF
711 fi
712
713 # Don't fail the build on warnings
714 scripts/config --disable CONFIG_WERROR
715 scripts/config --enable CONFIG_PPC_DISABLE_WERROR
716
717 # Set required options
718 scripts/config --enable CONFIG_TRACEPOINTS
719 scripts/config --enable CONFIG_KALLSYMS
720 scripts/config --enable CONFIG_HIGH_RES_TIMERS
721 scripts/config --enable CONFIG_KPROBES
722 scripts/config --enable CONFIG_FTRACE
723 scripts/config --enable CONFIG_BLK_DEV_IO_TRACE
724 scripts/config --enable CONFIG_KALLSYMS_ALL
725 scripts/config --enable CONFIG_HAVE_SYSCALL_TRACEPOINTS
726 scripts/config --enable CONFIG_PERF_EVENTS
727 scripts/config --enable CONFIG_EVENT_TRACING
728 scripts/config --enable CONFIG_KRETPROBES
729
730 if [ -n "${DEBUG}" ] ; then
731 cat .config
732 fi
733
734 make "$update_conf_target" "${make_args[@]}"
735 make -j"$NPROC" "${make_args[@]}"
736
737 krelease=$(make -s kernelrelease "${make_args[@]}")
738
739 # Save the kernel and modules
740 mkdir -p "$LINUX_INSTOBJ_DIR/boot"
741 make INSTALL_MOD_PATH="$LINUX_INSTOBJ_DIR" INSTALL_MOD_STRIP=1 modules_install "${make_args[@]}"
742 make INSTALL_MOD_PATH="$LINUX_INSTOBJ_DIR" INSTALL_PATH="$LINUX_INSTOBJ_DIR/boot" install "${make_args[@]}"
743 rm -f "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source" "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/build"
744 ln -s ../../../../sources "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
745 ln -s ../../../../sources "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
746 }
747
748
749 extract_distro_headers() {
750
751 # Enter linux source dir
752 cd "${LINUX_SRCOBJ_DIR}"
753
754
755 # For RT kernels, copy version file
756 if [ -s localversion-rt ]; then
757 cp -a localversion-rt "${LINUX_HDROBJ_DIR}"
758 fi
759
760 # Copy all Makefile related stuff
761 find . -path './include/*' -prune \
762 -o -path './scripts/*' -prune -o -type f \
763 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
764 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
765 -print | cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
766
767 # Copy base scripts and include dirs
768 cp -a scripts include "${LINUX_HDROBJ_DIR}"
769
770 # Copy arch includes
771 (find arch -name include -type d -print0 | \
772 xargs -0 -n1 -I '{}' find '{}' -type f) | \
773 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
774
775 # Copy arch scripts
776 (find arch -name scripts -type d -print0 | \
777 xargs -0 -n1 -I '{}' find '{}' -type f) | \
778 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
779
780 # Cleanup scripts
781 rm -f "${LINUX_HDROBJ_DIR}/scripts/*.o"
782 rm -f "${LINUX_HDROBJ_DIR}/scripts/*/*.o"
783
784 # On powerpc 32bits this object is required to link modules
785 if [ "${karch}" = "powerpc" ]; then
786 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte "${kversion}" "5.4"; then
787 :
788 else
789 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LINUX_HDROBJ_DIR}/"
790 fi
791 fi
792
793 # On arm64 between 4.13 and 1.15 this object is required to build with ftrace support
794 if [ "${karch}" = "arm64" ]; then
795 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
796 cp -a --parents arch/arm64/kernel/ftrace-mod.[So] "${LINUX_HDROBJ_DIR}/"
797 fi
798 fi
799
800 # On riscv with 5.14 the vsdo objects are required
801 if [ "${karch}" = "riscv" ] && \
802 ( { vergte "${kversion}" "5.14"; } && { verlt "${kversion}" "5.15"; } ); then
803 cp -a --parents arch/riscv/kernel/vdso/*.o "${LINUX_HDROBJ_DIR}/"
804 fi
805
806 # Newer kernels need objtool to build modules when CONFIG_STACK_VALIDATION=y
807 if [ -f tools/objtool/objtool ]; then
808 cp -a --parents tools/objtool/objtool "${LINUX_HDROBJ_DIR}/"
809 fi
810
811 if [ -f "arch/x86/kernel/macros.s" ]; then
812 cp -a --parents arch/x86/kernel/macros.s "${LINUX_HDROBJ_DIR}/"
813 fi
814
815 # Copy modules related stuff, if available
816 if [ -s Module.symvers ]; then
817 cp Module.symvers "${LINUX_HDROBJ_DIR}"
818 fi
819
820 if [ -s System.map ]; then
821 cp System.map "${LINUX_HDROBJ_DIR}"
822 fi
823
824 if [ -s Module.markers ]; then
825 cp Module.markers "${LINUX_HDROBJ_DIR}"
826 fi
827
828 # Copy config file
829 cp .config "${LINUX_HDROBJ_DIR}"
830
831 # Make sure the Makefile and version.h have a matching timestamp so that
832 # external modules can be built
833 if [ -s "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h" ]; then
834 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h"
835 elif [ -s "${LINUX_HDROBJ_DIR}/include/linux/version.h" ]; then
836 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/linux/version.h"
837 else
838 echo "Missing version.h"
839 exit 1
840 fi
841 touch -r "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/generated/autoconf.h"
842
843 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
844 if [ ! -f "${LINUX_HDROBJ_DIR}/include/config/auto.conf" ]; then
845 cp "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/config/auto.conf"
846 fi
847
848 # Finally clean the object files from the full source tree
849 make clean
850
851 # And regen the modules support files
852 make modules_prepare "${make_args[@]}"
853
854 # On powerpc 32bits this object is required to link modules
855 if [ "${karch}" = "powerpc" ]; then
856 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte "${kversion}" "5.4"; then
857 :
858 else
859 make arch/powerpc/lib/crtsavres.o "${make_args[@]}"
860 fi
861 fi
862
863 # On arm64 between 4.13 and 4.15 this object is required to build with ftrace support
864 if [ "${karch}" = "arm64" ]; then
865 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
866 make arch/arm64/kernel/ftrace-mod.o "${make_args[@]}"
867 fi
868 fi
869
870 # Version specific tasks
871 case "$ktag" in
872 Ubuntu*)
873 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
874 ABINUM="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
875 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> include/generated/utsrelease.h
876 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${LINUX_HDROBJ_DIR}/include/generated/utsrelease.h"
877 ;;
878 esac
879 }
880
881
882 build_modules() {
883
884 local kdir="$1"
885 local outdir="$2"
886 local kversion
887
888 kversion=$(make -C "$LINUX_HDROBJ_DIR" -s kernelversion)
889
890 # Try to catch some compatibility problems by turning some
891 # warnings into errors.
892 #export KCFLAGS="$KCFLAGS -Wall -Werror"
893
894 # Enter lttng-modules source dir
895 cd "${MODULES_GIT_DIR}"
896
897 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
898 # timekeeping subsystem. We want those build to fail.
899 if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
900 { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
901
902 set +e
903
904 # Build modules
905 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
906 ret=$?
907
908 set -e
909
910 # We expect this build to fail, if it doesn't, fail the job.
911 if [ "$ret" -eq 0 ]; then
912 echo "This build should have failed."
913 exit 1
914 fi
915
916 # We have to publish at least one file or the build will fail
917 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${outdir}/BROKEN.txt.ko"
918
919 KERNELDIR="${kdir}" make clean
920
921 else # Regular build
922
923 # Build modules against full kernel sources
924 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
925
926 # Install modules to build dir
927 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${outdir}" modules_install
928
929 # Clean build dir
930 KERNELDIR="${kdir}" make clean
931 fi
932 }
933
934
935 ## MAIN ##
936
937 # Use all CPU cores
938 NPROC=$(nproc)
939
940 MODULES_GIT_DIR="${WORKSPACE}/src/lttng-modules"
941 LINUX_GIT_DIR="${WORKSPACE}/src/linux"
942
943 LINUX_OBJ_DIR="${WORKSPACE}/linux"
944 LINUX_SRCOBJ_DIR="${LINUX_OBJ_DIR}/sources"
945 LINUX_HDROBJ_DIR="${LINUX_OBJ_DIR}/headers"
946 LINUX_INSTOBJ_DIR="${LINUX_OBJ_DIR}/install"
947
948 MODULES_OUTPUT_KSRC_DIR="${WORKSPACE}/build/lttng-modules-ksrc"
949 MODULES_OUTPUT_KHDR_DIR="${WORKSPACE}/build/lttng-modules-khdr"
950
951 LINUX_GIT_REF_REPO_DIR="$HOME/gitcache/linux-stable.git/"
952
953 OBJ_STORE_URL="s3://jenkins"
954
955 cd "$WORKSPACE"
956
957 # Create build directories
958 mkdir -p "${LINUX_SRCOBJ_DIR}" "${LINUX_HDROBJ_DIR}" "${LINUX_INSTOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
959
960 print_header "Clone LTTng-modules sources"
961 git_clone_modules_sources
962
963 # Setup cross compile env if available
964 if [ "x${cross_arch}" != "x" ]; then
965
966 case "$cross_arch" in
967 "armhf")
968 karch="arm"
969 cross_compile="arm-linux-gnueabihf-"
970 vanilla_config="imx_v6_v7_defconfig"
971 ubuntu_config="armhf-config.flavour.generic"
972 ;;
973
974 "arm64")
975 karch="arm64"
976 cross_compile="aarch64-linux-gnu-"
977 vanilla_config="defconfig"
978 ubuntu_config="arm64-config.flavour.generic"
979 ;;
980
981 "powerpc")
982 karch="powerpc"
983 cross_compile="powerpc-linux-gnu-"
984 vanilla_config="ppc44x_defconfig"
985 ubuntu_config="powerpc-config.flavour.powerpc-smp"
986 ;;
987
988 "ppc64el")
989 karch="powerpc"
990 cross_compile="powerpc64le-linux-gnu-"
991 vanilla_config="pseries_le_defconfig"
992 ubuntu_config="ppc64el-config.flavour.generic"
993 ;;
994
995 "riscv64")
996 karch="riscv"
997 cross_compile="riscv64-linux-gnu-"
998 vanilla_config="defconfig"
999 ubuntu_config="riscv64-config.flavour.generic"
1000 ;;
1001
1002 *)
1003 echo "Unsupported cross arch $cross_arch"
1004 exit 1
1005 ;;
1006 esac
1007
1008 # Export variables used by Kbuild for cross compilation
1009 export ARCH="${karch}"
1010 export CROSS_COMPILE="${cross_compile}"
1011
1012 # Set arch specific values if we are not cross compiling
1013 elif [ "x${arch}" != "x" ]; then
1014
1015 case "$arch" in
1016 "i386")
1017 karch="x86"
1018 vanilla_config="allmodconfig"
1019 ubuntu_config="i386-config.flavour.generic"
1020 ;;
1021
1022 "amd64")
1023 karch="x86"
1024 vanilla_config="allmodconfig"
1025 ubuntu_config="amd64-config.flavour.generic"
1026 ;;
1027
1028 "armhf")
1029 karch="arm"
1030 vanilla_config="allmodconfig"
1031 ubuntu_config="armhf-config.flavour.generic"
1032 ;;
1033
1034 "arm64")
1035 karch="arm64"
1036 vanilla_config="allmodconfig"
1037 ubuntu_config="arm64-config.flavour.generic"
1038 ;;
1039
1040 "powerpc")
1041 karch="powerpc"
1042 vanilla_config="allmodconfig"
1043 ubuntu_config="powerpc-config.flavour.powerpc-smp"
1044 ;;
1045
1046 "ppc64el")
1047 karch="powerpc"
1048 vanilla_config="allmodconfig"
1049 ubuntu_config="ppc64el-config.flavour.generic"
1050 ;;
1051
1052 "riscv64")
1053 karch="riscv"
1054 vanilla_config="allmodconfig"
1055 ubuntu_config="riscv64-config.flavour.generic"
1056 ;;
1057
1058 *)
1059 echo "Unsupported arch $arch"
1060 exit 1
1061 ;;
1062 esac
1063 else
1064 echo "No arch or cross_arch specified"
1065 exit 1
1066 fi
1067
1068
1069
1070 # First get the kernel build from the object store, or build it, if it's
1071 # not available.
1072
1073 set +x
1074 echo "# Setup endpoint
1075 host_base = obj.internal.efficios.com
1076 host_bucket = obj.internal.efficios.com
1077 bucket_location = us-east-1
1078 use_https = True
1079
1080 # Setup access keys
1081 access_key = jenkins
1082 secret_key = echo123456
1083
1084 # Enable S3 v4 signature APIs
1085 signature_v2 = False" > "$WORKSPACE/.s3cfg"
1086 set -x
1087
1088 url_hash="$(echo -n "$kgitrepo" | md5sum | awk '{ print $1 }')"
1089 obj_name="linux.tar.bz2"
1090
1091 if [ -z "${cross_arch}" ]; then
1092 obj_url_prefix="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platform}/$arch/native"
1093 else
1094 obj_url_prefix="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platform}/${cross_arch}"
1095 fi
1096
1097 obj_url="$obj_url_prefix/$obj_name"
1098
1099 set +e
1100 # In s3cmd 2.3, the return code of get when an object does not exist (64)
1101 # is different than in 2.2 (12). The return codes of 's3cmd info' are
1102 # consistent between 2.2 and 2.3.
1103 s3cmd -c "$WORKSPACE/.s3cfg" info "$obj_url"
1104 ret=$?
1105 set -e
1106
1107 case "$ret" in
1108 "0")
1109 print_header "Get sources and prebuilt kernel"
1110 s3cmd -c "$WORKSPACE/.s3cfg" get "$obj_url"
1111 extract_archive_obj
1112
1113 print_header "Select compiler and set build flags"
1114 select_compiler
1115 export_kbuild_flags
1116 ;;
1117
1118 "12")
1119 print_header "Clone kernel sources"
1120
1121 # Build all the things and upload
1122 # then finish the module build...
1123
1124 git_clone_linux_sources
1125 git_export_linux_sources
1126
1127 print_header "Select compiler and set build flags"
1128 select_compiler
1129 export_kbuild_flags
1130
1131 ## PREPARE FULL LINUX SOURCE TREE
1132 print_header "Build kernel from source"
1133 build_linux_kernel
1134
1135 ## EXTRACT DISTRO STYLE KERNEL HEADERS / DEVEL
1136 extract_distro_headers
1137
1138 print_header "Upload kernel to object storage"
1139 tar_archive_obj
1140 upload_archive_obj
1141
1142 ;;
1143
1144 *)
1145 echo "Unknown error? Abort"
1146 exit 1
1147 ;;
1148 esac
1149
1150
1151 ## BUILD modules
1152 # Either we downloaded a pre-build kernel or we built it and uploaded
1153 # the archive for future builds.
1154
1155 cd "$WORKSPACE"
1156
1157 print_header "Build modules against full kernel sources"
1158 build_modules "${LINUX_SRCOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}"
1159
1160 print_header "Build modules against kernel headers"
1161 build_modules "${LINUX_HDROBJ_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
1162
1163
1164 print_header "Check for built modules in install directory"
1165
1166 # Make sure some modules were actually built
1167 tree "${MODULES_OUTPUT_KSRC_DIR}"
1168 if [ "x$(find "${MODULES_OUTPUT_KSRC_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
1169 echo "No modules built!"
1170 exit 1
1171 fi
1172
1173 tree "${MODULES_OUTPUT_KHDR_DIR}"
1174 if [ "x$(find "${MODULES_OUTPUT_KHDR_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
1175 echo "No modules built!"
1176 exit 1
1177 fi
1178
1179 # EOF
This page took 0.066156 seconds and 3 git commands to generate.