mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-09 14:06:58 +02:00
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:
parent
a809f10fc6
commit
a86aa9cce9
@ -21,16 +21,22 @@ SRC_ROOT=$(dirname $(readlink -f $(dirname "$0")))
|
||||
KERNEL_DIR="$SRC_ROOT/third_party/kernel"
|
||||
DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow"
|
||||
|
||||
CROSS_COMPILE_FLAG=""
|
||||
VERBOSE_FLAG=""
|
||||
|
||||
# Flags
|
||||
DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"}
|
||||
DEFINE_string config "${DEFAULT_KCONFIG}" \
|
||||
"The kernel configuration file to use."
|
||||
DEFINE_integer revision 002 \
|
||||
"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"
|
||||
DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \
|
||||
"Root of build output"
|
||||
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
|
||||
@ -40,10 +46,6 @@ eval set -- "${FLAGS_ARGV}"
|
||||
# Die on any errors.
|
||||
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.
|
||||
# TODO: Find a workaround for needing sudo for this. Maybe create a symlink
|
||||
# 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
|
||||
# to determine the full package name and also to setup the environment for
|
||||
# kernel build scripts which use "uname -m" to autodetect architecture.
|
||||
KCONFIG="$FLAGS_config"
|
||||
KCONFIG=`readlink -f "$FLAGS_config"`
|
||||
if [ ! -f "$KCONFIG" ]; then
|
||||
KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG"
|
||||
fi
|
||||
if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ]
|
||||
if [ $(grep 'CONFIG_X86=y' "$KCONFIG") ]
|
||||
then
|
||||
ARCH="i386"
|
||||
elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ]
|
||||
elif [ $(grep 'CONFIG_X86_64=y' "$KCONFIG") ]
|
||||
then
|
||||
ARCH="x86_64"
|
||||
elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ]
|
||||
elif [ $(grep 'CONFIG_ARM=y' "$KCONFIG") ]
|
||||
then
|
||||
ARCH="arm"
|
||||
ARCH="armel"
|
||||
KPKG_ARCH=arm
|
||||
else
|
||||
exit 1
|
||||
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)
|
||||
# and remove any leading text before the major number of the kernel version
|
||||
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))
|
||||
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
|
||||
# detect architecture (like the "oldconfig" rule in kernel Makefile) don't get
|
||||
# confused when cross-compiling.
|
||||
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" \
|
||||
setarch $ARCH make-kpkg \
|
||||
$SETARCH \
|
||||
make-kpkg \
|
||||
$VERBOSE_FLAG \
|
||||
$CROSS_COMPILE_FLAG \
|
||||
--append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \
|
||||
--arch="$ARCH" \
|
||||
--rootcmd fakeroot \
|
||||
|
Loading…
Reference in New Issue
Block a user