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