#!/bin/bash
# $Id: build-kernel.sh 78141 2019-04-16 02:32:16Z vboxsync $
## @file
# Script for build a linux kernel with a default configuration.
#
# This script assumes gcc-6, gcc-4.9 and gcc-3.3 are available on the system.
#
# For really old kernels make 3.80 and 3.76 will need to be built and put in
# a specific place relative to the kernel sources.
#
# This script may patch the kernel source a little to work around issues with
# newere binutils, perl, glibc and maybe compilers.
#
# It is recommended to use a overlayfs setup and kDeDup the kernel sources to
# save disk space.
#
#
# Copyright (C) 2019 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
#
# /etc/apt/sources.list clues:
#
# # for gcc-4.8
# deb http://deb.debian.org/debian/ oldstable main contrib non-free
# deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
#
# # for gcc-6
# deb http://deb.debian.org/debian/ stable main contrib non-free
# deb-src http://deb.debian.org/debian/ stable main contrib non-free
#
# # for gcc 3.4.x
# deb [ allow-insecure=yes ] http://archive.debian.org/debian/ lenny main contrib non-free
# deb-src [ allow-insecure=yes ] http://archive.debian.org/debian/ lenny main contrib non-free
#
# # for gcc 3.3.x
# deb [ allow-insecure=yes ] http://archive.debian.org/debian/ etch main contrib non-free
# deb-src [ allow-insecure=yes ] http://archive.debian.org/debian/ etch main contrib non-free
#
# # for gcc 3.2.x
# deb [ allow-insecure=yes arch=i386] http://archive.debian.org/debian/ woody main contrib non-free
# deb-src [ allow-insecure=yes arch=i386 ] http://archive.debian.org/debian/ woody main contrib non-free
#
#
# Clue for /etc/fstab:
# overlay /mnt/bldlnx/amd64 overlay lowerdir=/mnt/big/virgin-lnx/,upperdir=/mnt/big/bldlnx/amd64,workdir=/mnt/big/workdir/bldlnx-amd64,noauto 0 0
#
if [ -z "${JOBS}" ]; then JOBS=42; fi
#
# The path argument.
#
if [ "$#" -lt "1" ]; then
echo "usage: build.sh
[clean]"
exit 2
fi
set -e
echo "********************************************************************************"
echo "* $1"
echo "********************************************************************************"
set -x
shopt -s extglob
# Enter it.
cd "$1"
# Change the terminal title (ASSUMES xterm-like TERM).
KERN_SUBDIR=`basename $1`
export PS1="\$ ";
echo -ne "\033]0;build.sh - ${KERN_SUBDIR}\007"
# Derive the version from it.
KERN_VER=`echo $1 | sed -e 's/^.*linux-\([0-9][0-9.]*\).*$/\1/'`
case "${KERN_VER}" in
[0-9].[0-9]|[0-9].[0-9][0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9][0-9])
KERN_VER_3PLUS_DOTS="${KERN_VER}.0";;
*)
KERN_VER_3PLUS_DOTS=${KERN_VER};;
esac
echo "debug: KERN_VER=${KERN_VER} --> KERN_VER_3PLUS_DOTS=${KERN_VER_3PLUS_DOTS}"
# Determin tool overrides.
OVERRIDES=
MAKE=/usr/bin/make
case "${KERN_VER_3PLUS_DOTS}" in
4.9.*|4.1[0-7].*)
OVERRIDES="CC=gcc-6 CXX=g++-6"
;;
2.6.3[789]*|3.*|4.[0-8].*)
OVERRIDES="CC=gcc-4.9 CXX=g++-4.9"
;;
2.6.29*|2.6.3[0-9]*)
OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
;;
2.6.[89]*|2.6.12[0-9]*|2.6.2[0-8]*)
OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
MAKE=../../make-3.80/installed/bin/make
;;
2.6.*)
OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
MAKE=../../make-3.80/installed/bin/make
;;
esac
echo "debug: OVERRIDES=${OVERRIDES} MAKE=${MAKE}"
echo "${OVERRIDES}" > .bird-overrides
ln -sf "${MAKE}" .bird-make
# Done with arg #1.
shift
#
# Apply patches for newer tools and stuff.
#
# perl --annoying
if [ -f kernel/timeconst.pl ]; then
if patch --output /tmp/build.$$ -Np1 <
#include
/*
- * deal with unrepresentable constant logarithms
- */
-extern __attribute__((const, noreturn))
-int ____ilog2_NaN(void);
-
-/*
* non-constant log of base 2 calculators
* - the arch may override these in asm/bitops.h if they can be implemented
* more efficiently than using fls() and fls64()
* - the arch is not required to handle n==0 if implementing the fallback
@@ -84,9 +78,9 @@
*/
#define ilog2(n) \\
( \\
__builtin_constant_p(n) ? ( \\
- (n) < 1 ? ____ilog2_NaN() : \\
+ (n) < 2 ? 0 : \\
(n) & (1ULL << 63) ? 63 : \\
(n) & (1ULL << 62) ? 62 : \\
(n) & (1ULL << 61) ? 61 : \\
(n) & (1ULL << 60) ? 60 : \\
@@ -147,12 +141,9 @@
(n) & (1ULL << 5) ? 5 : \\
(n) & (1ULL << 4) ? 4 : \\
(n) & (1ULL << 3) ? 3 : \\
(n) & (1ULL << 2) ? 2 : \\
- (n) & (1ULL << 1) ? 1 : \\
- (n) & (1ULL << 0) ? 0 : \\
- ____ilog2_NaN() \\
- ) : \\
+ 1 ) : \\
(sizeof(n) <= 4) ? \\
__ilog2_u32(n) : \\
__ilog2_u64(n) \\
)
EOF
then
cp /tmp/build.$$ include/linux/log2.h
fi
;;
esac
fi
# extern then static current_menu.
if [ -f scripts/kconfig/lkc.h -a -f scripts/kconfig/mconf.c ]; then
case "${KERN_VER_3PLUS_DOTS}" in
2.6.1[0-9]*|2.6.2[0-9]*|2.6.3[0-9]*|2.6.4[0-9]*)
;;
2.5.*|2.6.[012345678])
if patch --output /tmp/build.$$ -Np1 <
#include
#include
+#include
#include "modpost.h"
EOF
then
cp /tmp/build.$$ scripts/mod/sumversion.c
fi
esac
fi
# Problem with "System too big" messages in 2.6.17 and earlier:
if [ -f arch/x86_64/boot/tools/build.c ]; then
case "${KERN_VER_3PLUS_DOTS}" in
2.6.[0-9]!([0-9])*|2.6.1[0-7]*)
if patch --output /tmp/build.$$ -Np1 < (is_big_kernel ? 0x40000 : DEF_SYSSIZE))
- die("System is too big. Try using %smodules.",
- is_big_kernel ? "" : "bzImage or ");
+ if (!is_big_kernel && sys_size > DEF_SYSSIZE)
+ die("System is too big. Try using bzImage or modules.");
while (sz > 0) {
int l, n;
EOF
then
cp /tmp/build.$$ arch/x86_64/boot/tools/build.c
fi
esac
fi
# Problem with incorrect mov sizes for segments in 2.6.11 and earlier:
if [ -f arch/x86_64/kernel/process.c ]; then
case "${KERN_VER_3PLUS_DOTS}" in
2.6.[0-9]!([0-9])*|2.6.1[01]*)
if patch --output /tmp/build.$$ -lNp1 <thread.fs = me->thread.fs;
p->thread.gs = me->thread.gs;
- asm("movl %%gs,%0" : "=m" (p->thread.gsindex));
- asm("movl %%fs,%0" : "=m" (p->thread.fsindex));
- asm("movl %%es,%0" : "=m" (p->thread.es));
- asm("movl %%ds,%0" : "=m" (p->thread.ds));
+ asm("movw %%gs,%0" : "=m" (p->thread.gsindex));
+ asm("movw %%fs,%0" : "=m" (p->thread.fsindex));
+ asm("movw %%es,%0" : "=m" (p->thread.es));
+ asm("movw %%ds,%0" : "=m" (p->thread.ds));
if (unlikely(me->thread.io_bitmap_ptr != NULL)) {
p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
@@ -456,11 +456,11 @@
* Switch DS and ES.
* This won't pick up thread selector changes, but I guess that is ok.
*/
- asm volatile("movl %%es,%0" : "=m" (prev->es));
+ asm volatile("movw %%es,%0" : "=m" (prev->es));
if (unlikely(next->es | prev->es))
loadsegment(es, next->es);
- asm volatile ("movl %%ds,%0" : "=m" (prev->ds));
+ asm volatile ("movw %%ds,%0" : "=m" (prev->ds));
if (unlikely(next->ds | prev->ds))
loadsegment(ds, next->ds);
EOF
then
cp /tmp/build.$$ arch/x86_64/kernel/process.c
fi
esac
fi
#
# Other arguments.
#
while [ "$#" -gt 0 ];
do
case "$1" in
clean)
time ./.bird-make ${OVERRIDES} -j ${JOBS} clean
;;
*)
echo "syntax error: $1" 1>&2
;;
esac
shift
done
#
# Configure.
#
if [ -f .config ]; then
mv -f .config .bird-previous-config
fi
nice ./.bird-make ${OVERRIDES} -j ${JOBS} defconfig
case "${KERN_VER_3PLUS_DOTS}" in
2.[012345].*|2.6.[0-9]!([0-9])*|2.6.[12][0-9]*)
;;
*)
echo CONFIG_DRM_TTM=m >> .config;
echo CONFIG_DRM_RADEON=m >> .config
echo CONFIG_DRM_RADEON_UMS=y >> .config
echo CONFIG_DRM_RADEON_USERPTR=y >> .config
echo CONFIG_DRM_RADEON_KMS=y >> .config
;;
esac
case "${KERN_VER_3PLUS_DOTS}" in
2.4.*) ;;
4.2[0-9].*|4.1[789].*|[5-9].*)
nice ./.bird-make ${OVERRIDES} syncconfig;;
*) nice ./.bird-make ${OVERRIDES} silentoldconfig;;
esac
if [ -f .bird-previous-config ]; then
if cmp -s .config .bird-previous-config; then
mv -f .bird-previous-config .config
fi
fi
#
# Build all.
#
if time nice ./.bird-make ${OVERRIDES} -j ${JOBS} all -k; then
rm -f .bird-failed
echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - done\007"
else
touch .bird-failed
echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - failed\007"
exit 1
fi