VirtualBox

source: vbox/trunk/tools/linux.x86/kmodbuild/build-kernel.sh@ 78140

最後變更 在這個檔案從78140是 78140,由 vboxsync 提交於 6 年 前

tools/linux.x86/kmodbuild: Some scripts bird uses to test build kmods. bugref:9172

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 15.0 KB
 
1#!/bin/bash
2# $Id: build-kernel.sh 78140 2019-04-16 02:20:36Z vboxsync $
3## @file
4# Script for build a linux kernel with a default configuration.
5#
6# This script assumes gcc-6, gcc-4.9 and gcc-3.3 are available on the system.
7#
8# For really old kernels make 3.80 and 3.76 will need to be built and put in
9# a specific place relative to the kernel sources.
10#
11# This script may patch the kernel source a little to work around issues with
12# newere binutils, perl, glibc and maybe compilers.
13#
14# It is recommended to use a overlayfs setup and kDeDup the kernel sources to
15# save disk space.
16#
17
18#
19# Copyright (C) 2019 Oracle Corporation
20#
21# This file is part of VirtualBox Open Source Edition (OSE), as
22# available from http://www.alldomusa.eu.org. This file is free software;
23# you can redistribute it and/or modify it under the terms of the GNU
24# General Public License (GPL) as published by the Free Software
25# Foundation, in version 2 as it comes in the "COPYING" file of the
26# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
27# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
28#
29
30if [ -z "${JOBS}" ]; then JOBS=42; fi
31
32#
33# The path argument.
34#
35if [ "$#" -lt "1" ]; then
36 echo "usage: build.sh <dir> [clean]"
37 exit 2
38fi
39
40set -e
41echo "********************************************************************************"
42echo "* $1"
43echo "********************************************************************************"
44set -x
45shopt -s extglob
46
47# Enter it.
48cd "$1"
49
50# Change the terminal title (ASSUMES xterm-like TERM).
51KERN_SUBDIR=`basename $1`
52export PS1="\$ ";
53echo -ne "\033]0;build.sh - ${KERN_SUBDIR}\007"
54
55# Derive the version from it.
56KERN_VER=`echo $1 | sed -e 's/^.*linux-\([0-9][0-9.]*\).*$/\1/'`
57case "${KERN_VER}" in
58 [0-9].[0-9]|[0-9].[0-9][0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9][0-9])
59 KERN_VER_3PLUS_DOTS="${KERN_VER}.0";;
60 *)
61 KERN_VER_3PLUS_DOTS=${KERN_VER};;
62esac
63echo "debug: KERN_VER=${KERN_VER} --> KERN_VER_3PLUS_DOTS=${KERN_VER_3PLUS_DOTS}"
64
65# Determin tool overrides.
66OVERRIDES=
67MAKE=/usr/bin/make
68case "${KERN_VER_3PLUS_DOTS}" in
69 4.9.*|4.1[0-7].*)
70 OVERRIDES="CC=gcc-6 CXX=g++-6"
71 ;;
72 2.6.3[789]*|3.*|4.[0-8].*)
73 OVERRIDES="CC=gcc-4.9 CXX=g++-4.9"
74 ;;
75 2.6.29*|2.6.3[0-9]*)
76 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
77 ;;
78 2.6.[89]*|2.6.12[0-9]*|2.6.2[0-8]*)
79 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
80 MAKE=../../make-3.80/installed/bin/make
81 ;;
82 2.6.*)
83 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
84 MAKE=../../make-3.80/installed/bin/make
85 ;;
86esac
87echo "debug: OVERRIDES=${OVERRIDES} MAKE=${MAKE}"
88
89echo "${OVERRIDES}" > .bird-overrides
90ln -sf "${MAKE}" .bird-make
91
92# Done with arg #1.
93shift
94
95
96#
97# Apply patches for newer tools and stuff.
98#
99
100# perl --annoying
101if [ -f kernel/timeconst.pl ]; then
102 if patch --output /tmp/build.$$ -Np1 <<EOF
103--- a/kernel/timeconst.pl 2019-04-15 13:44:55.434946090 +0200
104+++ b/kernel/timeconst.pl 2019-04-15 13:57:29.330140587 +0200
105@@ -372,5 +372,5 @@
106 @val = @{\$canned_values{\$hz}};
107- if (!defined(@val)) {
108+ if (!@val) {
109 @val = compute_values(\$hz);
110 }
111 output(\$hz, @val);
112EOF
113 then
114 cp /tmp/build.$$ kernel/timeconst.pl
115 fi
116fi
117
118# binutils PLT32
119case "${KERN_VER_3PLUS_DOTS}" in
120 4.10.*|4.11.*|4.12.*|4.13.*|4.14.*|4.15.*|4.16.*)
121 if patch --output /tmp/build.$$ -Np1 <<EOF
122diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
123index 1f790cf9d38f..3b7427aa7d85 100644
124--- a/arch/x86/kernel/machine_kexec_64.c
125+++ b/arch/x86/kernel/machine_kexec_64.c
126@@ -542,6 +542,7 @@ int arch_kexec_apply_relocations_add(const Elf64_Ehdr *ehdr,
127 goto overflow;
128 break;
129 case R_X86_64_PC32:
130+ case R_X86_64_PLT32:
131 value -= (u64)address;
132 *(u32 *)location = value;
133 break;
134EOF
135then
136 cp /tmp/build.$$ arch/x86/kernel/machine_kexec_64.c
137 fi
138 case "${KERN_VER}" in
139 4.10.*|4.11.*|4.12.*|4.13.*)
140 if patch --output /tmp/build.$$ -Np1 <<EOF
141diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
142index da0c160e5589..f58336af095c 100644
143--- a/arch/x86/kernel/module.c
144+++ b/arch/x86/kernel/module.c
145@@ -191,6 +191,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
146 goto overflow;
147 break;
148 case R_X86_64_PC32:
149+ case R_X86_64_PLT32:
150 val -= (u64)loc;
151 *(u32 *)loc = val;
152 #if 0
153EOF
154 then
155 cp /tmp/build.$$ arch/x86/kernel/module.c
156 fi;;
157 **)
158 if patch --output /tmp/build.$$ -Np1 <<EOF
159diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
160index da0c160e5589..f58336af095c 100644
161--- a/arch/x86/kernel/module.c
162+++ b/arch/x86/kernel/module.c
163@@ -191,6 +191,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
164 goto overflow;
165 break;
166 case R_X86_64_PC32:
167+ case R_X86_64_PLT32:
168 if (*(u32 *)loc != 0)
169 goto invalid_relocation;
170 val -= (u64)loc;
171EOF
172 then
173 cp /tmp/build.$$ arch/x86/kernel/module.c
174 fi;;
175 esac
176 if patch --output /tmp/build.$$ -Np1 <<EOF
177diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
178index 5d73c443e778..220e97841e49 100644
179--- a/arch/x86/tools/relocs.c
180+++ b/arch/x86/tools/relocs.c
181@@ -770,9 +770,12 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym,
182 break;
183
184 case R_X86_64_PC32:
185+ case R_X86_64_PLT32:
186 /*
187 * PC relative relocations don't need to be adjusted unless
188 * referencing a percpu symbol.
189+ *
190+ * NB: R_X86_64_PLT32 can be treated as R_X86_64_PC32.
191 */
192 if (is_percpu_sym(sym, symname))
193 add_reloc(&relocs32neg, offset);
194EOF
195 then
196 cp /tmp/build.$$ arch/x86/tools/relocs.c
197 fi
198 if patch --output /tmp/build.$$ -Np1 <<EOF
199--- linux-4.15/tools/lib/subcmd/pager.c 2017-11-12 19:46:13.000000000 +0100
200+++ linux-4.17/tools/lib/subcmd/pager.c 2018-06-03 23:15:21.000000000 +0200
201@@ -30,10 +30,13 @@
202 * have real input
203 */
204 fd_set in;
205+ fd_set exception;
206
207 FD_ZERO(&in);
208+ FD_ZERO(&exception);
209 FD_SET(0, &in);
210- select(1, &in, NULL, &in, NULL);
211+ FD_SET(0, &exception);
212+ select(1, &in, NULL, &exception, NULL);
213
214 setenv("LESS", "FRSX", 0);
215 }
216EOF
217 then
218 cp /tmp/build.$$ tools/lib/subcmd/pager.c
219 fi
220 if patch --output /tmp/build.$$ -Np1 <<EOF
221--- linux-4.16/tools/lib/str_error_r.c 2019-04-15 06:04:50.978464217 +0200
222+++ linux-4.17/tools/lib/str_error_r.c 2018-06-03 23:15:21.000000000 +0200
223@@ -22,6 +22,6 @@
224 {
225 int err = strerror_r(errnum, buf, buflen);
226 if (err)
227- snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
228+ snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
229 return buf;
230 }
231EOF
232 then
233 cp /tmp/build.$$ tools/lib/str_error_r.c
234 fi
235 ;;
236esac
237
238# Undefined ____ilog2_NaN symbol:
239if [ -f include/linux/log2.h ]; then
240 case "${KERN_VER_3PLUS_DOTS}" in
241 4.10.*|4.[9].*)
242 if patch --output /tmp/build.$$ -Np1 <<EOF
243--- linux-4.10/include/linux/log2.h 2017-02-19 23:34:00.000000000 +0100
244+++ linux-4.11/include/linux/log2.h 2017-11-12 19:46:13.000000000 +0100
245@@ -15,14 +15,8 @@
246 #include <linux/types.h>
247 #include <linux/bitops.h>
248
249 /*
250- * deal with unrepresentable constant logarithms
251- */
252-extern __attribute__((const, noreturn))
253-int ____ilog2_NaN(void);
254-
255-/*
256 * non-constant log of base 2 calculators
257 * - the arch may override these in asm/bitops.h if they can be implemented
258 * more efficiently than using fls() and fls64()
259 * - the arch is not required to handle n==0 if implementing the fallback
260@@ -84,9 +78,9 @@
261 */
262 #define ilog2(n) \\
263 ( \\
264 __builtin_constant_p(n) ? ( \\
265- (n) < 1 ? ____ilog2_NaN() : \\
266+ (n) < 2 ? 0 : \\
267 (n) & (1ULL << 63) ? 63 : \\
268 (n) & (1ULL << 62) ? 62 : \\
269 (n) & (1ULL << 61) ? 61 : \\
270 (n) & (1ULL << 60) ? 60 : \\
271@@ -147,12 +141,9 @@
272 (n) & (1ULL << 5) ? 5 : \\
273 (n) & (1ULL << 4) ? 4 : \\
274 (n) & (1ULL << 3) ? 3 : \\
275 (n) & (1ULL << 2) ? 2 : \\
276- (n) & (1ULL << 1) ? 1 : \\
277- (n) & (1ULL << 0) ? 0 : \\
278- ____ilog2_NaN() \\
279- ) : \\
280+ 1 ) : \\
281 (sizeof(n) <= 4) ? \\
282 __ilog2_u32(n) : \\
283 __ilog2_u64(n) \\
284 )
285EOF
286 then
287 cp /tmp/build.$$ include/linux/log2.h
288 fi
289 ;;
290 esac
291fi
292
293# extern then static current_menu.
294if [ -f scripts/kconfig/lkc.h -a -f scripts/kconfig/mconf.c ]; then
295 case "${KERN_VER_3PLUS_DOTS}" in
296 2.6.1[0-9]*|2.6.2[0-9]*|2.6.3[0-9]*|2.6.4[0-9]*)
297 ;;
298 2.5.*|2.6.[012345678])
299 if patch --output /tmp/build.$$ -Np1 <<EOF
300--- linux-2.6.8/scripts/kconfig/mconf.c 2004-08-14 07:36:32.000000000 +0200
301+++ linux-2.6.8/scripts/kconfig/mconf.c 2019-04-15 15:52:42.143587966 +0200
302@@ -88,5 +88,5 @@
303 static struct termios ios_org;
304 static int rows = 0, cols = 0;
305-static struct menu *current_menu;
306+struct menu *current_menu;
307 static int child_count;
308 static int do_resize;
309EOF
310 then
311 cp /tmp/build.$$ scripts/kconfig/mconf.c
312 fi
313 ;;
314 esac
315fi
316
317# Incorrect END label in arch/x86/lib/copy_user_64.S
318case "${KERN_VER_3PLUS_DOTS}" in
319 2.6.2[456]*)
320 if patch --output /tmp/build.$$ -Np1 <<EOF
321--- linux-2.6.26/arch/x86/lib/copy_user_64.S 2019-04-15 16:21:49.475846822 +0200
322+++ linux-2.6.26/arch/x86/lib/copy_user_64.S 2019-04-15 16:21:50.883863141 +0200
323@@ -341,7 +341,7 @@
324 11: pop %rax
325 7: ret
326 CFI_ENDPROC
327-END(copy_user_generic_c)
328+END(copy_user_generic_string)
329
330 .section __ex_table,"a"
331 .quad 1b,3b
332EOF
333 then
334 cp /tmp/build.$$ arch/x86/lib/copy_user_64.S
335 fi
336 ;;
337 2.6.2[0123]*|2.6.19*)
338 if patch --output /tmp/build.$$ -Np1 <<EOF
339--- linux-2.6.23/arch/x86_64/lib/copy_user.S 2019-04-15 16:42:16.898006203 +0200
340+++ linux-2.6.23/arch/x86_64/lib/copy_user.S 2019-04-15 16:42:25.906109885 +0200
341@@ -344,7 +344,7 @@
342 11: pop %rax
343 7: ret
344 CFI_ENDPROC
345-END(copy_user_generic_c)
346+END(copy_user_generic_string)
347
348 .section __ex_table,"a"
349 .quad 1b,3b
350EOF
351 then
352 cp /tmp/build.$$ arch/x86_64/lib/copy_user.S
353 fi
354 ;;
355esac
356
357# Increase vdso text segment limit as newer tools/whatever causes it to be too large.
358if [ -f arch/x86_64/vdso/vdso.lds.S ]; then
359 if patch --output /tmp/build.$$ -Np1 <<EOF
360--- linux-2.6.23/arch/x86_64/vdso/vdso.lds.S 2019-04-15 17:20:27.567440594 +0200
361+++ linux-2.6.23/arch/x86_64/vdso/vdso.lds.S 2019-04-15 17:20:29.635463886 +0200
362@@ -28,5 +28,5 @@
363 .text : { *(.text) } :text
364 .text.ptr : { *(.text.ptr) } :text
365- . = VDSO_PRELINK + 0x900;
366+ . = VDSO_PRELINK + 0xa00;
367 .data : { *(.data) } :text
368 .bss : { *(.bss) } :text
369EOF
370 then
371 cp /tmp/build.$$ arch/x86_64/vdso/vdso.lds.S
372 fi
373fi
374
375# glibc PATH_MAX cleanup affect 2.6.21 and earlier:
376if [ -f scripts/mod/sumversion.c ]; then
377 case "${KERN_VER_3PLUS_DOTS}" in
378 2.6.[0-9]!([0-9])*|2.6.1[0-9]*|2.6.2[01]*)
379 if patch --output /tmp/build.$$ -Np1 <<EOF
380--- linux-2.6.21/scripts/mod/sumversion.c 2007-02-04 19:44:54.000000000 +0100
381+++ linux-2.6.21/scripts/mod/sumversion.c 2019-02-15 16:10:12.956678862 +0100
382@@ -7,4 +7,5 @@
383 #include <ctype.h>
384 #include <errno.h>
385 #include <string.h>
386+#include <linux/limits.h>
387 #include "modpost.h"
388EOF
389 then
390 cp /tmp/build.$$ scripts/mod/sumversion.c
391 fi
392 esac
393fi
394
395# Problem with "System too big" messages in 2.6.17 and earlier:
396if [ -f arch/x86_64/boot/tools/build.c ]; then
397 case "${KERN_VER_3PLUS_DOTS}" in
398 2.6.[0-9]!([0-9])*|2.6.1[0-7]*)
399 if patch --output /tmp/build.$$ -Np1 <<EOF
400--- linux-2.6.17/arch/x86_64/boot/tools/build.c 2006-01-03 04:21:10.000000000 +0100
401+++ linux-2.6.18/arch/x86_64/boot/tools/build.c 2007-02-04 19:44:54.000000000 +0100
402@@ -149,9 +149,7 @@
403 sz = sb.st_size;
404 fprintf (stderr, "System is %d kB\n", sz/1024);
405 sys_size = (sz + 15) / 16;
406- /* 0x40000*16 = 4.0 MB, reasonable estimate for the current maximum */
407- if (sys_size > (is_big_kernel ? 0x40000 : DEF_SYSSIZE))
408- die("System is too big. Try using %smodules.",
409- is_big_kernel ? "" : "bzImage or ");
410+ if (!is_big_kernel && sys_size > DEF_SYSSIZE)
411+ die("System is too big. Try using bzImage or modules.");
412 while (sz > 0) {
413 int l, n;
414EOF
415 then
416 cp /tmp/build.$$ arch/x86_64/boot/tools/build.c
417 fi
418 esac
419fi
420
421# Problem with incorrect mov sizes for segments in 2.6.11 and earlier:
422if [ -f arch/x86_64/kernel/process.c ]; then
423 case "${KERN_VER_3PLUS_DOTS}" in
424 2.6.[0-9]!([0-9])*|2.6.1[01]*)
425 if patch --output /tmp/build.$$ -lNp1 <<EOF
426--- linux-2.6.11/arch/x86_64/kernel/process.c 2005-03-02 08:38:10.000000000 +0100
427+++ linux-2.6.11/arch/x86_64/kernel/process.c 2019-02-15 16:57:47.653585327 +0100
428@@ -390,10 +390,10 @@
429 p->thread.fs = me->thread.fs;
430 p->thread.gs = me->thread.gs;
431
432- asm("movl %%gs,%0" : "=m" (p->thread.gsindex));
433- asm("movl %%fs,%0" : "=m" (p->thread.fsindex));
434- asm("movl %%es,%0" : "=m" (p->thread.es));
435- asm("movl %%ds,%0" : "=m" (p->thread.ds));
436+ asm("movw %%gs,%0" : "=m" (p->thread.gsindex));
437+ asm("movw %%fs,%0" : "=m" (p->thread.fsindex));
438+ asm("movw %%es,%0" : "=m" (p->thread.es));
439+ asm("movw %%ds,%0" : "=m" (p->thread.ds));
440
441 if (unlikely(me->thread.io_bitmap_ptr != NULL)) {
442 p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
443@@ -456,11 +456,11 @@
444 * Switch DS and ES.
445 * This won't pick up thread selector changes, but I guess that is ok.
446 */
447- asm volatile("movl %%es,%0" : "=m" (prev->es));
448+ asm volatile("movw %%es,%0" : "=m" (prev->es));
449 if (unlikely(next->es | prev->es))
450 loadsegment(es, next->es);
451
452- asm volatile ("movl %%ds,%0" : "=m" (prev->ds));
453+ asm volatile ("movw %%ds,%0" : "=m" (prev->ds));
454 if (unlikely(next->ds | prev->ds))
455 loadsegment(ds, next->ds);
456EOF
457 then
458 cp /tmp/build.$$ arch/x86_64/kernel/process.c
459 fi
460 esac
461fi
462
463
464#
465# Other arguments.
466#
467while [ "$#" -gt 0 ];
468do
469 case "$1" in
470 clean)
471 time ./.bird-make ${OVERRIDES} -j ${JOBS} clean
472 ;;
473
474 *)
475 echo "syntax error: $1" 1>&2
476 ;;
477 esac
478 shift
479done
480
481#
482# Configure.
483#
484if [ -f .config ]; then
485 mv -f .config .bird-previous-config
486fi
487nice ./.bird-make ${OVERRIDES} -j ${JOBS} defconfig
488case "${KERN_VER_3PLUS_DOTS}" in
489 2.[012345].*|2.6.[0-9]!([0-9])*|2.6.[12][0-9]*)
490 ;;
491 *)
492 echo CONFIG_DRM_TTM=m >> .config;
493 echo CONFIG_DRM_RADEON=m >> .config
494 echo CONFIG_DRM_RADEON_UMS=y >> .config
495 echo CONFIG_DRM_RADEON_USERPTR=y >> .config
496 echo CONFIG_DRM_RADEON_KMS=y >> .config
497 ;;
498esac
499case "${KERN_VER_3PLUS_DOTS}" in
500 2.4.*) ;;
501 4.2[0-9].*|4.1[789].*|[5-9].*)
502 nice ./.bird-make ${OVERRIDES} syncconfig;;
503 *) nice ./.bird-make ${OVERRIDES} silentoldconfig;;
504esac
505if [ -f .bird-previous-config ]; then
506 if cmp -s .config .bird-previous-config; then
507 mv -f .bird-previous-config .config
508 fi
509fi
510
511#
512# Build all.
513#
514if time nice ./.bird-make ${OVERRIDES} -j ${JOBS} all -k; then
515 rm -f .bird-failed
516 echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - done\007"
517else
518 touch .bird-failed
519 echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - failed\007"
520 exit 1
521fi
522
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette