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 KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow" | 22 DEFAULT_KCONFIG="${KERNEL_DIR}/files/chromeos/config/chromeos-intel-menlow" |
23 | 23 |
24 # Flags | 24 # Flags |
25 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} | 25 DEFAULT_BUILD_ROOT=${BUILD_ROOT:-"${SRC_ROOT}/build"} |
26 DEFINE_string config "${KCONFIG}" \ | 26 DEFINE_string config "${DEFAULT_KCONFIG}" \ |
27 "The kernel configuration file to use. See src/platform/kernel/config/*" | 27 "The kernel configuration file to use." |
28 DEFINE_integer revision 002 \ | 28 DEFINE_integer revision 002 \ |
29 "The package revision to use" | 29 "The package revision to use" |
30 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ | 30 DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/x86/local_packages" \ |
31 "Directory in which to place the resulting .deb package" | 31 "Directory in which to place the resulting .deb package" |
32 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ | 32 DEFINE_string build_root "$DEFAULT_BUILD_ROOT" \ |
33 "Root of build output" | 33 "Root of build output" |
34 FLAGS_HELP="Usage: $0 [flags] <deb_patch1> <deb_patch2> ..." | 34 FLAGS_HELP="Usage: $0 [flags]" |
35 | 35 |
36 # Parse command line | 36 # Parse command line |
37 FLAGS "$@" || exit 1 | 37 FLAGS "$@" || exit 1 |
38 eval set -- "${FLAGS_ARGV}" | 38 eval set -- "${FLAGS_ARGV}" |
39 | 39 |
40 # Die on any errors. | 40 # Die on any errors. |
41 set -e | 41 set -e |
42 | 42 |
43 # TODO: We detect the ARCH below. We can sed the FLAGS_output_root to replace | 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. | 44 # an ARCH placeholder with the proper architecture rather than assuming x86. |
45 mkdir -p "$FLAGS_output_root" | 45 mkdir -p "$FLAGS_output_root" |
46 | 46 |
47 # Use remaining arguments passed into the script as patch names. These are | |
48 # for non-chromeos debian-style patches. The chromeos patches will be applied | |
49 # manually below. | |
50 PATCHES="$*" | |
51 | |
52 # Get kernel package configuration from repo. | 47 # Get kernel package configuration from repo. |
53 # 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 |
54 # to /tmp/kernel-pkg.conf when setting up the chroot env? | 49 # to /tmp/kernel-pkg.conf when setting up the chroot env? |
55 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 |
56 | 51 |
57 # Parse kernel config file for target architecture information. This is needed | 52 # Parse kernel config file for target architecture information. This is needed |
58 # 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 |
59 # kernel build scripts which use "uname -m" to autodetect architecture. | 54 # kernel build scripts which use "uname -m" to autodetect architecture. |
| 55 KCONFIG="$FLAGS_config" |
| 56 if [ ! -f "$KCONFIG" ]; then |
| 57 KCONFIG="$KERNEL_DIR"/files/chromeos/config/"$KCONFIG" |
| 58 fi |
60 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] | 59 if [ -n $(grep 'CONFIG_X86=y' "$KCONFIG") ] |
61 then | 60 then |
62 ARCH="i386" | 61 ARCH="i386" |
63 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] | 62 elif [ -n $(grep 'CONFIG_X86_64=y' "$KCONFIG") ] |
64 then | 63 then |
65 ARCH="x86_64" | 64 ARCH="x86_64" |
66 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] | 65 elif [ -n $(grep 'CONFIG_ARM=y' "$KCONFIG") ] |
67 then | 66 then |
68 ARCH="arm" | 67 ARCH="arm" |
69 else | 68 else |
(...skipping 27 matching lines...) Expand all Loading... |
97 PACKAGE="linux-image-${VER_MME}-${CHROMEOS_TAG}-${LOCAL}_${FLAGS_revision}_${ARC
H}.deb" | 96 PACKAGE="linux-image-${VER_MME}-${CHROMEOS_TAG}-${LOCAL}_${FLAGS_revision}_${ARC
H}.deb" |
98 | 97 |
99 # Set up kernel source tree and prepare to start the compilation. | 98 # Set up kernel source tree and prepare to start the compilation. |
100 # TODO: Decide on proper working directory when building kernels. It should | 99 # TODO: Decide on proper working directory when building kernels. It should |
101 # be somewhere under ${BUILD_ROOT}. | 100 # be somewhere under ${BUILD_ROOT}. |
102 SRCDIR="${FLAGS_build_root}/kernels/kernel-${ARCH}-${LOCAL}" | 101 SRCDIR="${FLAGS_build_root}/kernels/kernel-${ARCH}-${LOCAL}" |
103 rm -rf "$SRCDIR" | 102 rm -rf "$SRCDIR" |
104 mkdir -p "$SRCDIR" | 103 mkdir -p "$SRCDIR" |
105 cd "$SRCDIR" | 104 cd "$SRCDIR" |
106 | 105 |
107 # Get kernel sources and patches. | 106 # Get kernel sources |
108 if [ -d ${KERNEL_DIR}/linux-${VER_MME} ]; then | |
109 # TODO(msb): uncomment once git is available in the chroot | 107 # TODO(msb): uncomment once git is available in the chroot |
110 # git clone "${KERNEL_DIR}"/linux_${VER_MME} | 108 # git clone "${KERNEL_DIR}"/linux_${VER_MME} |
111 cp -a "${KERNEL_DIR}"/linux-${VER_MME} . | 109 mkdir linux-${VER_MME} |
112 else | 110 cd "linux-$VER_MME" |
113 # old way... | 111 cp -a "${KERNEL_DIR}"/files/* . |
114 # TODO: find a better source for the kernel source. Old versions of karmic | |
115 # aren't hosted on archive.ubuntu.com | |
116 #apt-get source linux-source-$MAJOR.$MINOR.$EXTRA | |
117 # Name directory to what the patches expect | |
118 mkdir linux-${VER_MME} | |
119 cp -a "${KERNEL_DIR}"/files/* linux-${VER_MME} | |
120 | |
121 if [ ! -z $PATCHES ] | |
122 then | |
123 # TODO: Get rid of sudo if possible. Maybe the non-chromeos kernel | |
124 » # patches will be infrequent enough that we can make them part of | |
125 » # the chroot env? | |
126 sudo apt-get install $PATCHES | |
127 fi | |
128 | |
129 # TODO: Remove a config option which references a non-existent directory in | |
130 # ubuntu kernel sources. | |
131 sed -i '/gfs/ d' linux-$VER_MME/ubuntu/Makefile | |
132 fi | |
133 | 112 |
134 # Move kernel config to kernel source tree and rename to .config so that | 113 # Move kernel config to kernel source tree and rename to .config so that |
135 # it can be used for "make oldconfig" by make-kpkg. | 114 # it can be used for "make oldconfig" by make-kpkg. |
136 cp "$KCONFIG" "linux-${VER_MME}/.config" | 115 cp "$KCONFIG" .config |
137 cd "linux-$VER_MME" | |
138 | 116 |
139 # Remove stale packages. make-kpkg will dump the package in the parent | 117 # Remove stale packages. make-kpkg will dump the package in the parent |
140 # directory. From there, it will be moved to the output directory. | 118 # directory. From there, it will be moved to the output directory. |
141 rm -f "../${PACKAGE}" | 119 rm -f "../${PACKAGE}" |
142 rm -f "${FLAGS_output_root}/${PACKAGE}" | 120 rm -f "${FLAGS_output_root}"/linux-image-*.deb |
143 | 121 |
144 # Speed up compilation by running parallel jobs. | 122 # Speed up compilation by running parallel jobs. |
145 if [ ! -e "/proc/cpuinfo" ] | 123 if [ ! -e "/proc/cpuinfo" ] |
146 then | 124 then |
147 # default to a reasonable level | 125 # default to a reasonable level |
148 CONCURRENCY_LEVEL=2 | 126 CONCURRENCY_LEVEL=2 |
149 else | 127 else |
150 # speed up compilation by running #cpus * 2 simultaneous jobs | 128 # speed up compilation by running #cpus * 2 simultaneous jobs |
151 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) | 129 CONCURRENCY_LEVEL=$(($(cat /proc/cpuinfo | grep "processor" | wc -l) * 2)) |
152 fi | 130 fi |
153 | 131 |
154 # The patch listing will be added into make-kpkg with --added-patches flag. | |
155 # We need to change the formatting so they are a comma-separated values list | |
156 # rather than whitespace separated. | |
157 PATCHES_CSV=$(echo $PATCHES | sed -e 's/ \{1,\}/,/g' | sed -e 's/,$//') | |
158 | |
159 # 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 |
160 # 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 |
161 # confused when cross-compiling. | 134 # confused when cross-compiling. |
162 make-kpkg clean | 135 make-kpkg clean |
163 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ | 136 MAKEFLAGS="CONCURRENCY_LEVEL=$CONCURRENCY_LEVEL" \ |
164 setarch $ARCH make-kpkg \ | 137 setarch $ARCH make-kpkg \ |
165 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ | 138 --append-to-version="-$CHROMEOS_TAG" --revision="$FLAGS_revision" \ |
166 --arch="$ARCH" \ | 139 --arch="$ARCH" \ |
167 --rootcmd fakeroot \ | 140 --rootcmd fakeroot \ |
168 --config oldconfig \ | 141 --config oldconfig \ |
169 --initrd --bzImage kernel_image \ | 142 --initrd --bzImage kernel_image |
170 --added-patches "$PATCHES_CSV" | |
171 | 143 |
172 # make-kpkg dumps the newly created package in the parent directory | 144 # make-kpkg dumps the newly created package in the parent directory |
173 if [ -e "../${PACKAGE}" ] | 145 if [ -e "../${PACKAGE}" ] |
174 then | 146 then |
175 rm -f "${FLAGS_output_root}"/linux-image-*.deb | |
176 mv "../${PACKAGE}" "${FLAGS_output_root}" | 147 mv "../${PACKAGE}" "${FLAGS_output_root}" |
177 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" | 148 echo "Kernel build successful, check ${FLAGS_output_root}/${PACKAGE}" |
178 else | 149 else |
179 echo "Kernel build failed" | 150 echo "Kernel build failed" |
180 exit 1 | 151 exit 1 |
181 fi | 152 fi |
OLD | NEW |