Changes to support ARM cross compilation.

Added a flag to allow verbose make-kpkg and a flag to specify the
cross compile tools.

Changed the default output_root to use ARCH in the path.

Modified determination of ARCH and changed ARCH=arm to the more correct
ARCH=armel. Also set KPKG_ARCH=arm for compliance with kernel makefile.

Disabled the setarch command when it fails and instead alias uname to
echo ARCH.

A call to compile for arm will look like:
./build_kernel.sh --config=path/to/config --cross_compile=arm-linux-gnueabi- \
[--verbose]

Review URL: http://codereview.chromium.org/501019
This commit is contained in:
Brian Daugherty 2009-12-15 14:32:32 -07:00
parent a809f10fc6
commit a86aa9cce9

View File

@ -21,17 +21,23 @@ SRC_ROOT=$(dirname $(readlink -f $(dirname "$0")))
KERNEL_DIR="$SRC_ROOT/third_party/kernel" KERNEL_DIR="$SRC_ROOT/third_party/kernel"
DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow" DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow"
CROSS_COMPILE_FLAG=""
VERBOSE_FLAG=""
# Flags # Flags
DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"}
DEFINE_string config "${DEFAULT_KCONFIG}" \ DEFINE_string config "${DEFAULT_KCONFIG}" \
"The kernel configuration file to use." "The kernel configuration file to use."
DEFINE_integer revision 002 \ DEFINE_integer revision 002 \
"The package revision to use" "The package revision to use"
DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ DEFINE_string output_root "" \
"Directory in which to place the resulting .deb package" "Directory in which to place the resulting .deb package"
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
"Root of build output" "Root of build output"
FLAGS_HELP="Usage: $0 [flags]" DEFINE_string cross_compile "" \
"Prefix for cross compile build tools"
DEFINE_boolean verbose $FLAGS_FALSE "Print debugging information in addtion to normal processing."
FLAGS_HELP="Usage: $0 [flags]"
# Parse command line # Parse command line
FLAGS "$@" || exit 1 FLAGS "$@" || exit 1
@ -40,10 +46,6 @@ eval set -- "${FLAGS_ARGV}"
# Die on any errors. # Die on any errors.
set -e set -e
# TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace
# an ARCH placeholder with the proper architecture rather than assuming x86.
mkdir -p "$FLAGS_output_root"
# Get kernel package configuration from repo. # Get kernel package configuration from repo.
# TODO: Find a workaround for needing sudo for this. Maybe create a symlink # TODO: Find a workaround for needing sudo for this. Maybe create a symlink
# to /tmp/kernel-pkg.conf when setting up the chroot env? # to /tmp/kernel-pkg.conf when setting up the chroot env?
@ -52,23 +54,33 @@ sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf
# Parse kernel config file for target architecture information. This is needed # Parse kernel config file for target architecture information. This is needed
# to determine the full package name and also to setup the environment for # to determine the full package name and also to setup the environment for
# kernel build scripts which use "uname -m" to autodetect architecture. # kernel build scripts which use "uname -m" to autodetect architecture.
KCONFIG="$FLAGS_config" KCONFIG=`readlink -f "$FLAGS_config"`
if [ ! -f "$KCONFIG" ]; then if [ ! -f "$KCONFIG" ]; then
KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG"
fi fi
if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] if [ $(grep 'CONFIG_X86=y' "$KCONFIG") ]
then then
ARCH="i386" ARCH="i386"
elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] elif [ $(grep 'CONFIG_X86_64=y' "$KCONFIG") ]
then then
ARCH="x86_64" ARCH="x86_64"
elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] elif [ $(grep 'CONFIG_ARM=y' "$KCONFIG") ]
then then
ARCH="arm" ARCH="armel"
KPKG_ARCH=arm
else else
exit 1 exit 1
fi fi
if [ ! $FLAGS_output_root ]
then
FLAGS_output_root="${DEFAULT_BUILD_ROOT}/${ARCH}/local_packages"
fi
# TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace
# an ARCH placeholder with the proper architecture rather than assuming x86.
mkdir -p "$FLAGS_output_root"
# Parse the config file for a line with "version" in it (in the header) # Parse the config file for a line with "version" in it (in the header)
# and remove any leading text before the major number of the kernel version # and remove any leading text before the major number of the kernel version
FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG)
@ -129,12 +141,38 @@ else
CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2))
fi fi
# Setup the cross-compilation environment, if necessary, using the cross_compile
# Flag from the command line
if [ $FLAGS_cross_compile ]
then
CROSS_COMPILE_FLAG="--cross-compile $FLAGS_cross_compile"
fi
if [ $FLAGS_verbose -eq $FLAGS_TRUE ]
then
VERBOSE_FLAG="--verbose"
fi
# Build the kernel and make package. "setarch" is used so that scripts which # Build the kernel and make package. "setarch" is used so that scripts which
# detect architecture (like the "oldconfig" rule in kernel Makefile) don't get # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get
# confused when cross-compiling. # confused when cross-compiling.
make-kpkg clean make-kpkg clean
# Setarch does not support arm, so if we are compiling for arm we need to
# make sure that uname -m will return the appropriate architeture.
if [ ! -n "$(setarch $ARCH ls)" ]
then
alias uname="echo $ARCH"
SETARCH=""
else
SETARCH="setarch $ARCH"
fi
MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \
setarch $ARCH make-kpkg \ $SETARCH \
make-kpkg \
$VERBOSE_FLAG \
$CROSS_COMPILE_FLAG \
--append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \
--arch="$ARCH" \ --arch="$ARCH" \
--rootcmd fakeroot \ --rootcmd fakeroot \