| 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 | |
| 27 # Flags | 24 # Flags |
| 28 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} | 25 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} |
| 29 DEFINE_string config "${DEFAULT_KCONFIG}" \ | 26 DEFINE_string config "${DEFAULT_KCONFIG}" \ |
| 30 "The kernel configuration file to use." | 27 "The kernel configuration file to use." |
| 31 DEFINE_integer revision 002 \ | 28 DEFINE_integer revision 002 \ |
| 32 "The package revision to use" | 29 "The package revision to use" |
| 33 DEFINE_string output_root "" \ | 30 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ |
| 34 "Directory in which to place the resulting .deb package" | 31 "Directory in which to place the resulting .deb package" |
| 35 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | 32 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ |
| 36 "Root of build output" | 33 "Root of build output" |
| 37 DEFINE_string cross_compile "" \ | 34 FLAGS_HELP="Usage: $0 [flags]" |
| 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]" | |
| 41 | 35 |
| 42 # Parse command line | 36 # Parse command line |
| 43 FLAGS "$@" || exit 1 | 37 FLAGS "$@" || exit 1 |
| 44 eval set -- "${FLAGS_ARGV}" | 38 eval set -- "${FLAGS_ARGV}" |
| 45 | 39 |
| 46 # Die on any errors. | 40 # Die on any errors. |
| 47 set -e | 41 set -e |
| 48 | 42 |
| 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 |
| 49 # Get kernel package configuration from repo. | 47 # Get kernel package configuration from repo. |
| 50 # TODO: Find a workaround for needing sudo for this. Maybe create a symlink | 48 # TODO: Find a workaround for needing sudo for this. Maybe create a symlink |
| 51 # to /tmp/kernel-pkg.conf when setting up the chroot env? | 49 # to /tmp/kernel-pkg.conf when setting up the chroot env? |
| 52 sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf | 50 sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf |
| 53 | 51 |
| 54 # Parse kernel config file for target architecture information. This is needed | 52 # Parse kernel config file for target architecture information. This is needed |
| 55 # to determine the full package name and also to setup the environment for | 53 # to determine the full package name and also to setup the environment for |
| 56 # kernel build scripts which use "uname -m" to autodetect architecture. | 54 # kernel build scripts which use "uname -m" to autodetect architecture. |
| 57 KCONFIG=`readlink -f "$FLAGS_config"` | 55 KCONFIG="$FLAGS_config" |
| 58 if [ ! -f "$KCONFIG" ]; then | 56 if [ ! -f "$KCONFIG" ]; then |
| 59 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" | 57 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" |
| 60 fi | 58 fi |
| 61 if [ $(grep 'CONFIG_X86=y' "$KCONFIG") ] | 59 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] |
| 62 then | 60 then |
| 63 ARCH="i386" | 61 ARCH="i386" |
| 64 elif [ $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] | 62 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] |
| 65 then | 63 then |
| 66 ARCH="x86_64" | 64 ARCH="x86_64" |
| 67 elif [ $(grep 'CONFIG_ARM=y' "$KCONFIG") ] | 65 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] |
| 68 then | 66 then |
| 69 ARCH="armel" | 67 ARCH="arm" |
| 70 KPKG_ARCH=arm | |
| 71 else | 68 else |
| 72 exit 1 | 69 exit 1 |
| 73 fi | 70 fi |
| 74 | 71 |
| 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 | |
| 84 # Parse the config file for a line with "version" in it (in the header) | 72 # Parse the config file for a line with "version" in it (in the header) |
| 85 # and remove any leading text before the major number of the kernel version | 73 # and remove any leading text before the major number of the kernel version |
| 86 FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) | 74 FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) |
| 87 | 75 |
| 88 # FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this | 76 # FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this |
| 89 # example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is | 77 # example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is |
| 90 # asus-eeepc. RC is optional since it only shows up for release candidates. | 78 # asus-eeepc. RC is optional since it only shows up for release candidates. |
| 91 MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//') | 79 MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//') |
| 92 MIDDLE=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[^0-9].*//') | 80 MIDDLE=$(echo $FULLVERSION | sed -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].*//
') | 81 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... |
| 134 # Speed up compilation by running parallel jobs. | 122 # Speed up compilation by running parallel jobs. |
| 135 if [ ! -e "/proc/cpuinfo" ] | 123 if [ ! -e "/proc/cpuinfo" ] |
| 136 then | 124 then |
| 137 # default to a reasonable level | 125 # default to a reasonable level |
| 138 CONCURRENCY_LEVEL=2 | 126 CONCURRENCY_LEVEL=2 |
| 139 else | 127 else |
| 140 # speed up compilation by running #cpus * 2 simultaneous jobs | 128 # speed up compilation by running #cpus * 2 simultaneous jobs |
| 141 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) | 129 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) |
| 142 fi | 130 fi |
| 143 | 131 |
| 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 | |
| 156 # Build the kernel and make package. "setarch" is used so that scripts which | 132 # Build the kernel and make package. "setarch" is used so that scripts which |
| 157 # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get | 133 # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get |
| 158 # confused when cross-compiling. | 134 # confused when cross-compiling. |
| 159 make-kpkg clean | 135 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 | |
| 171 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ | 136 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ |
| 172 $SETARCH \ | 137 setarch $ARCH make-kpkg \ |
| 173 make-kpkg \ | |
| 174 $VERBOSE_FLAG \ | |
| 175 $CROSS_COMPILE_FLAG \ | |
| 176 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ | 138 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ |
| 177 --arch="$ARCH" \ | 139 --arch="$ARCH" \ |
| 178 --rootcmd fakeroot \ | 140 --rootcmd fakeroot \ |
| 179 --config oldconfig \ | 141 --config oldconfig \ |
| 180 --initrd --bzImage kernel_image | 142 --initrd --bzImage kernel_image |
| 181 | 143 |
| 182 # make-kpkg dumps the newly created package in the parent directory | 144 # make-kpkg dumps the newly created package in the parent directory |
| 183 if [ -e "../${PACKAGE}" ] | 145 if [ -e "../${PACKAGE}" ] |
| 184 then | 146 then |
| 185 mv "../${PACKAGE}" "${FLAGS_output_root}" | 147 mv "../${PACKAGE}" "${FLAGS_output_root}" |
| 186 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" | 148 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" |
| 187 else | 149 else |
| 188 echo "Kernel build failed" | 150 echo "Kernel build failed" |
| 189 exit 1 | 151 exit 1 |
| 190 fi | 152 fi |
| OLD | NEW |