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 KERNEL_FDIR="$KERNEL_DIR/files" |
| 23 DEFAULT_KFLAVOUR="chromeos-intel-menlow" |
23 | 24 |
24 # Flags | 25 # Flags |
25 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} | 26 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} |
26 DEFINE_string config "${DEFAULT_KCONFIG}" \ | 27 DEFINE_string flavour "${DEFAULT_KFLAVOUR}" \ |
27 "The kernel configuration file to use." | 28 "The kernel flavour to build." |
28 DEFINE_integer revision 002 \ | |
29 "The package revision to use" | |
30 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ | 29 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ |
31 "Directory in which to place the resulting .deb package" | 30 "Directory in which to place the resulting .deb package" |
32 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | 31 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ |
33 "Root of build output" | 32 "Root of build output" |
34 FLAGS_HELP="Usage: $0 [flags]" | 33 FLAGS_HELP="Usage: $0 [flags]" |
35 | 34 |
36 # Parse command line | 35 # Parse command line |
37 FLAGS "$@" || exit 1 | 36 FLAGS "$@" || exit 1 |
38 eval set -- "${FLAGS_ARGV}" | 37 eval set -- "${FLAGS_ARGV}" |
39 | 38 |
40 # Die on any errors. | 39 # Die on any errors. |
41 set -e | 40 set -e |
42 | 41 |
43 # TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace | 42 # 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. | 43 # an ARCH placeholder with the proper architecture rather than assuming x86. |
45 mkdir -p "$FLAGS_output_root" | 44 mkdir -p "$FLAGS_output_root" |
46 | 45 |
47 # Get kernel package configuration from repo. | 46 # Set up kernel source tree and prepare to start the compilation. |
48 # TODO: Find a workaround for needing sudo for this. Maybe create a symlink | 47 # TODO: Decide on proper working directory when building kernels. It should |
49 # to /tmp/kernel-pkg.conf when setting up the chroot env? | 48 # be somewhere under ${BUILD_ROOT}. |
50 sudo cp "$KERNEL_DIR"/package/kernel-pkg.conf /etc/kernel-pkg.conf | 49 SRCDIR="${FLAGS_build_root}/kernels/kernel-${FLAGS_flavour}" |
| 50 rm -rf "$SRCDIR" |
| 51 mkdir -p "$SRCDIR" |
| 52 cp -a "${KERNEL_FDIR}"/* "$SRCDIR" |
| 53 cd "$SRCDIR" |
| 54 |
| 55 # |
| 56 # Build the config file |
| 57 # |
| 58 fakeroot debian/rules clean prepare-$FLAGS_flavour |
51 | 59 |
52 # Parse kernel config file for target architecture information. This is needed | 60 # 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 | 61 # to setup the environment for kernel build scripts which use "uname -m" to auto
detect architecture. |
54 # kernel build scripts which use "uname -m" to autodetect architecture. | 62 KCONFIG="$SRCDIR/debian/build/build-$FLAGS_flavour/.config" |
55 KCONFIG="$FLAGS_config" | |
56 if [ ! -f "$KCONFIG" ]; then | 63 if [ ! -f "$KCONFIG" ]; then |
57 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" | 64 echo Total bummer. No config file was created. |
| 65 exit 1 |
58 fi | 66 fi |
59 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] | 67 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] |
60 then | 68 then |
61 ARCH="i386" | 69 ARCH="i386" |
62 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] | 70 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] |
63 then | 71 then |
64 ARCH="x86_64" | 72 ARCH="x86_64" |
65 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] | 73 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] |
66 then | 74 then |
67 ARCH="arm" | 75 ARCH="arm" |
68 else | 76 else |
69 exit 1 | 77 exit 1 |
70 fi | 78 fi |
71 | 79 |
72 # Parse the config file for a line with "version" in it (in the header) | 80 # 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 | 81 # and remove any leading text before the major number of the kernel version |
74 FULLVERSION=$(sed -e '/version/ !d' -e 's/^[^0-9]*//' $KCONFIG) | 82 FULLVERSION=$(dpkg-parsechangelog -l$SRCDIR/debian.chrome/changelog|grep "Versio
n:"|sed 's/^Version: //') |
75 | 83 |
76 # FULLVERSION should have the form "2.6.30-rc1-chromeos-asus-eeepc". In this | 84 # linux-image-2.6.31-0-chromeos-intel-menlow_2.6.31-0.1_i386.deb |
77 # example MAJOR is 2, MINOR is 6, EXTRA is 30, RELEASE is rc1, LOCAL is | 85 # FULLVERSION has the form "2.6.3x-ABI-MINOR" where x is {1,2}, ABI and MINOR ar
e an integers. |
78 # asus-eeepc. RC is optional since it only shows up for release candidates. | 86 #In this example MAJOR is 2.6.31, ABI is 0, MINOR is 1 |
79 MAJOR=$(echo $FULLVERSION | sed -e 's/[^0-9].*//') | 87 MAJOR=$(echo $FULLVERSION | sed -e 's/\(^.*\)-.*$/\1/') |
80 MIDDLE=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[^0-9].*//') | 88 ABI=$(echo $FULLVERSION | sed 's/^.*-\(.*\)\..*$/\1/') |
81 MINOR=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[0-9].//' -e 's/[^0-9].*//
') | 89 MINOR=$(echo $FULLVERSION | sed -e 's/^.*\.\([0-9]*$\)/\1/') |
82 EXTRA=$(echo $FULLVERSION | sed -e 's/[0-9].//' -e 's/[0-9].//' -e 's/[0-9]*.//'
-e 's/[^0-9].*//') | 90 PACKAGE="linux-image-${MAJOR}-${ABI}-${FLAGS_flavour}_${MAJOR}-${ABI}.${MINOR}_$
{ARCH}.deb" |
83 if [ ! -z $EXTRA ]; then | |
84 VER_MME="${MAJOR}.${MIDDLE}.${MINOR}.${EXTRA}" | |
85 else | |
86 VER_MME="${MAJOR}.${MIDDLE}.${MINOR}" | |
87 fi | |
88 | 91 |
89 LOCAL=$(sed -e '/CONFIG_LOCALVERSION=/ !d' -e 's/.*="-//' -e 's/"//' $KCONFIG) | 92 echo MAJOR $MAJOR |
90 RC=$(echo $FULLVERSION | sed -r \ | 93 echo ABI $ABI |
91 "s/${VER_MME}-([^-]*)-*${LOCAL}/\1/") | 94 echo MINOR $MINOR |
| 95 echo PACKAGE $PACKAGE |
92 | 96 |
93 # The tag will be appended by make-kpkg to the extra version and will show up | |
94 # in both the kernel and package names. | |
95 CHROMEOS_TAG="chromeos" | |
96 PACKAGE="linux-image-${VER_MME}-${CHROMEOS_TAG}-${LOCAL}_${FLAGS_revision}_${ARC
H}.deb" | |
97 | 97 |
98 # Set up kernel source tree and prepare to start the compilation. | 98 # Remove stale packages. debian/rules will dump the package in the parent |
99 # TODO: Decide on proper working directory when building kernels. It should | |
100 # be somewhere under ${BUILD_ROOT}. | |
101 SRCDIR="${FLAGS_build_root}/kernels/kernel-${ARCH}-${LOCAL}" | |
102 rm -rf "$SRCDIR" | |
103 mkdir -p "$SRCDIR" | |
104 cd "$SRCDIR" | |
105 | |
106 # Get kernel sources | |
107 # TODO(msb): uncomment once git is available in the chroot | |
108 # git clone "${KERNEL_DIR}"/linux_${VER_MME} | |
109 mkdir linux-${VER_MME} | |
110 cd "linux-$VER_MME" | |
111 cp -a "${KERNEL_DIR}"/files/* . | |
112 | |
113 # Move kernel config to kernel source tree and rename to .config so that | |
114 # it can be used for "make oldconfig" by make-kpkg. | |
115 cp "$KCONFIG" .config | |
116 | |
117 # Remove stale packages. make-kpkg will dump the package in the parent | |
118 # directory. From there, it will be moved to the output directory. | 99 # directory. From there, it will be moved to the output directory. |
119 rm -f "../${PACKAGE}" | 100 rm -f "../${PACKAGE}" |
120 rm -f "${FLAGS_output_root}"/linux-image-*.deb | 101 rm -f "${FLAGS_output_root}"/linux-image-*.deb |
121 | 102 |
122 # Speed up compilation by running parallel jobs. | 103 # Build the kernel package. |
123 if [ ! -e "/proc/cpuinfo" ] | 104 fakeroot debian/rules binary-debs flavours=${FLAGS_flavour} |
124 then | |
125 # default to a reasonable level | |
126 CONCURRENCY_LEVEL=2 | |
127 else | |
128 # speed up compilation by running #cpus * 2 simultaneous jobs | |
129 CONCURRENCY_LEVEL=$(($(grep -c "^processor" /proc/cpuinfo) * 2)) | |
130 fi | |
131 | 105 |
132 # Build the kernel and make package. "setarch" is used so that scripts which | 106 # debian/rules dumps the newly created package in the parent directory |
133 # detect architecture (like the "oldconfig" rule in kernel Makefile) don't get | |
134 # confused when cross-compiling. | |
135 make-kpkg clean | |
136 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ | |
137 setarch $ARCH make-kpkg \ | |
138 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ | |
139 --arch="$ARCH" \ | |
140 --rootcmd fakeroot \ | |
141 --config oldconfig \ | |
142 --initrd --bzImage kernel_image | |
143 | |
144 # make-kpkg dumps the newly created package in the parent directory | |
145 if [ -e "../${PACKAGE}" ] | 107 if [ -e "../${PACKAGE}" ] |
146 then | 108 then |
147 mv "../${PACKAGE}" "${FLAGS_output_root}" | 109 mv "../${PACKAGE}" "${FLAGS_output_root}" |
148 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" | 110 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" |
149 else | 111 else |
150 echo "Kernel build failed" | 112 echo "Kernel build failed" |
151 exit 1 | 113 exit 1 |
152 fi | 114 fi |
OLD | NEW |