| OLD | NEW |
| 1 #! /bin/sh | 1 #! /bin/sh |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # This script contains the set of commands to build a kernel package. | 7 # This script contains the set of commands to build a kernel package. |
| 8 # | 8 # |
| 9 # If successful, a new linux-image-*.deb file will appear in the specified | 9 # If successful, a new linux-image-*.deb file will appear in the specified |
| 10 # output directory. | 10 # output directory. |
| 11 # | 11 # |
| 12 # The user-provided kernel config file is parsed to obtain information about | 12 # The user-provided kernel config file is parsed to obtain information about |
| 13 # the desired kernel version and target platform. Here are the requirements: | 13 # the desired kernel version and target platform. Here are the requirements: |
| 14 # 1) Kernel version string in the header, e.g. "Linux kernel version: 2.6.30" | 14 # 1) Kernel version string in the header, e.g. "Linux kernel version: 2.6.30" |
| 15 # 2) Target architecture variables set up, e.g. CONFIG_X86, CONFIG_ARM, etc. | 15 # 2) Target architecture variables set up, e.g. CONFIG_X86, CONFIG_ARM, etc. |
| 16 # 3) LOCALVERSION set to describe target platform (e.g. intel-menlow). This is | 16 # 3) LOCALVERSION set to describe target platform (e.g. intel-menlow). This is |
| 17 # used for package naming. | 17 # used for package naming. |
| 18 SRC_ROOT=$(dirname $(readlink -f $(dirname "$0"))) | 18 SRC_ROOT=$(dirname $(readlink -f $(dirname "$0"))) |
| 19 . "${SRC_ROOT}/third_party/shflags/files/src/shflags" | 19 . "${SRC_ROOT}/third_party/shflags/files/src/shflags" |
| 20 | 20 |
| 21 KERNEL_DIR="$SRC_ROOT/third_party/kernel" | 21 KERNEL_DIR="$SRC_ROOT/third_party/kernel" |
| 22 DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow" | 22 DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow" |
| 23 | 23 |
| 24 CROSS_COMPILE_FLAG="" |
| 25 VERBOSE_FLAG="" |
| 26 |
| 24 # Flags | 27 # Flags |
| 25 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} | 28 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} |
| 26 DEFINE_string config "${DEFAULT_KCONFIG}" \ | 29 DEFINE_string config "${DEFAULT_KCONFIG}" \ |
| 27 "The kernel configuration file to use." | 30 "The kernel configuration file to use." |
| 28 DEFINE_integer revision 002 \ | 31 DEFINE_integer revision 002 \ |
| 29 "The package revision to use" | 32 "The package revision to use" |
| 30 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ | 33 DEFINE_string output_root "" \ |
| 31 "Directory in which to place the resulting .deb package" | 34 "Directory in which to place the resulting .deb package" |
| 32 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | 35 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ |
| 33 "Root of build output" | 36 "Root of build output" |
| 34 FLAGS_HELP="Usage: $0 [flags]" | 37 DEFINE_string cross_compile "" \ |
| 38 "Prefix for cross compile build tools" |
| 39 DEFINE_boolean verbose $FLAGS_FALSE "Print debugging information in addtion to n
ormal processing." |
| 40 FLAGS_HELP="Usage: $0 [flags]" |
| 35 | 41 |
| 36 # Parse command line | 42 # Parse command line |
| 37 FLAGS "$@" || exit 1 | 43 FLAGS "$@" || exit 1 |
| 38 eval set -- "${FLAGS_ARGV}" | 44 eval set -- "${FLAGS_ARGV}" |
| 39 | 45 |
| 40 # Die on any errors. | 46 # Die on any errors. |
| 41 set -e | 47 set -e |
| 42 | 48 |
| 43 # TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace | |
| 44 # an ARCH placeholder with the proper architecture rather than assuming x86. | |
| 45 mkdir -p "$FLAGS_output_root" | |
| 46 | |
| 47 # Get kernel package configuration from repo. | 49 # Get kernel package configuration from repo. |
| 48 # TODO: Find a workaround for needing sudo for this. Maybe create a symlink | 50 # TODO: Find a workaround for needing sudo for this. Maybe create a symlink |
| 49 # to /tmp/kernel-pkg.conf when setting up the chroot env? | 51 # to /tmp/kernel-pkg.conf when setting up the chroot env? |
| 50 sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf | 52 sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf |
| 51 | 53 |
| 52 # Parse kernel config file for target architecture information. This is needed | 54 # Parse kernel config file for target architecture information. This is needed |
| 53 # to determine the full package name and also to setup the environment for | 55 # to determine the full package name and also to setup the environment for |
| 54 # kernel build scripts which use "uname -m" to autodetect architecture. | 56 # kernel build scripts which use "uname -m" to autodetect architecture. |
| 55 KCONFIG="$FLAGS_config" | 57 KCONFIG=`readlink -f "$FLAGS_config"` |
| 56 if [ ! -f "$KCONFIG" ]; then | 58 if [ ! -f "$KCONFIG" ]; then |
| 57 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" | 59 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" |
| 58 fi | 60 fi |
| 59 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] | 61 if [ $(grep 'CONFIG_X86=y' "$KCONFIG") ] |
| 60 then | 62 then |
| 61 ARCH="i386" | 63 ARCH="i386" |
| 62 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] | 64 elif [ $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] |
| 63 then | 65 then |
| 64 ARCH="x86_64" | 66 ARCH="x86_64" |
| 65 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] | 67 elif [ $(grep 'CONFIG_ARM=y' "$KCONFIG") ] |
| 66 then | 68 then |
| 67 ARCH="arm" | 69 ARCH="armel" |
| 70 KPKG_ARCH=arm |
| 68 else | 71 else |
| 69 exit 1 | 72 exit 1 |
| 70 fi | 73 fi |
| 71 | 74 |
| 75 if [ ! $FLAGS_output_root ] |
| 76 then |
| 77 FLAGS_output_root="${DEFAULT_BUILD_ROOT}/${ARCH}/local_packages" |
| 78 fi |
| 79 |
| 80 # TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace |
| 81 # an ARCH placeholder with the proper architecture rather than assuming x86. |
| 82 mkdir -p "$FLAGS_output_root" |
| 83 |
| 72 # Parse the config file for a line with "version" in it (in the header) | 84 # Parse the config file for a line with "version" in it (in the header) |
| 73 # and remove any leading text before the major number of the kernel version | 85 # and remove any leading text before the major number of the kernel version |
| 74 FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) | 86 FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) |
| 75 | 87 |
| 76 # FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this | 88 # FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this |
| 77 # example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is | 89 # example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is |
| 78 # asus-eeepc. RC is optional since it only shows up for release candidates. | 90 # asus-eeepc. RC is optional since it only shows up for release candidates. |
| 79 MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//') | 91 MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//') |
| 80 MIDDLE=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[^0-9].*//') | 92 MIDDLE=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[^0-9].*//') |
| 81 MINOR=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[0-9].//' -e 's/[^0-9].*//
') | 93 MINOR=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[0-9].//' -e 's/[^0-9].*//
') |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 # Speed up compilation by running parallel jobs. | 134 # Speed up compilation by running parallel jobs. |
| 123 if [ ! -e "/proc/cpuinfo" ] | 135 if [ ! -e "/proc/cpuinfo" ] |
| 124 then | 136 then |
| 125 # default to a reasonable level | 137 # default to a reasonable level |
| 126 CONCURRENCY_LEVEL=2 | 138 CONCURRENCY_LEVEL=2 |
| 127 else | 139 else |
| 128 # speed up compilation by running #cpus * 2 simultaneous jobs | 140 # speed up compilation by running #cpus * 2 simultaneous jobs |
| 129 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) | 141 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) |
| 130 fi | 142 fi |
| 131 | 143 |
| 144 # Setup the cross-compilation environment, if necessary, using the cross_compile |
| 145 # Flag from the command line |
| 146 if [ $FLAGS_cross_compile ] |
| 147 then |
| 148 CROSS_COMPILE_FLAG="--cross-compile $FLAGS_cross_compile" |
| 149 fi |
| 150 |
| 151 if [ $FLAGS_verbose -eq $FLAGS_TRUE ] |
| 152 then |
| 153 VERBOSE_FLAG="--verbose" |
| 154 fi |
| 155 |
| 132 # Build the kernel and make package. "setarch" is used so that scripts which | 156 # Build the kernel and make package. "setarch" is used so that scripts which |
| 133 # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get | 157 # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get |
| 134 # confused when cross-compiling. | 158 # confused when cross-compiling. |
| 135 make-kpkg clean | 159 make-kpkg clean |
| 160 |
| 161 # Setarch does not support arm, so if we are compiling for arm we need to |
| 162 # make sure that uname -m will return the appropriate architeture. |
| 163 if [ ! -n "$(setarch $ARCH ls)" ] |
| 164 then |
| 165 alias uname="echo $ARCH" |
| 166 SETARCH="" |
| 167 else |
| 168 SETARCH="setarch $ARCH" |
| 169 fi |
| 170 |
| 136 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ | 171 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ |
| 137 setarch $ARCH make-kpkg \ | 172 $SETARCH \ |
| 173 make-kpkg \ |
| 174 $VERBOSE_FLAG \ |
| 175 $CROSS_COMPILE_FLAG \ |
| 138 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ | 176 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ |
| 139 --arch="$ARCH" \ | 177 --arch="$ARCH" \ |
| 140 --rootcmd fakeroot \ | 178 --rootcmd fakeroot \ |
| 141 --config oldconfig \ | 179 --config oldconfig \ |
| 142 --initrd --bzImage kernel_image | 180 --initrd --bzImage kernel_image |
| 143 | 181 |
| 144 # make-kpkg dumps the newly created package in the parent directory | 182 # make-kpkg dumps the newly created package in the parent directory |
| 145 if [ -e "../${PACKAGE}" ] | 183 if [ -e "../${PACKAGE}" ] |
| 146 then | 184 then |
| 147 mv "../${PACKAGE}" "${FLAGS_output_root}" | 185 mv "../${PACKAGE}" "${FLAGS_output_root}" |
| 148 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" | 186 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" |
| 149 else | 187 else |
| 150 echo "Kernel build failed" | 188 echo "Kernel build failed" |
| 151 exit 1 | 189 exit 1 |
| 152 fi | 190 fi |
| OLD | NEW |