blob: 3d58186fe9b0c0bf1c3d7ca3b5bef91247db5afe [file] [log] [blame]
Doug Andersonf291dba2012-01-19 14:26:10 -08001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Distributed under the terms of the GNU General Public License v2
3
4[[ ${EAPI} != "4" ]] && die "Only EAPI=4 is supported"
5
David Jamesd4130ab2013-09-19 11:26:39 -07006# Since we use CHROMEOS_KERNEL_CONFIG and CHROMEOS_KERNEL_SPLITCONFIG here,
7# it is not safe to reuse the kernel prebuilts across different boards. Inherit
8# the cros-board eclass to make sure that doesn't happen.
9inherit binutils-funcs cros-board linux-info toolchain-funcs
Doug Andersonf291dba2012-01-19 14:26:10 -080010
11HOMEPAGE="http://www.chromium.org/"
12LICENSE="GPL-2"
13SLOT="0"
14
15DEPEND="sys-apps/debianutils
Doug Andersonf291dba2012-01-19 14:26:10 -080016 initramfs? ( chromeos-base/chromeos-initramfs )
Vic Yang9aabf9c2013-01-23 20:47:59 +080017 netboot_ramfs? ( chromeos-base/chromeos-initramfs )
Doug Andersonf291dba2012-01-19 14:26:10 -080018"
19
Paul Stewart23ead5f2013-04-24 22:32:17 -070020IUSE="-device_tree -kernel_sources -wireless34 -wifi_testbed_ap"
Doug Andersonf291dba2012-01-19 14:26:10 -080021STRIP_MASK="/usr/lib/debug/boot/vmlinux"
Josh Triplett4c035592012-12-05 15:46:46 -080022
23# Build out-of-tree and incremental by default, but allow an ebuild inheriting
24# this eclass to explicitly build in-tree.
25: ${CROS_WORKON_OUTOFTREE_BUILD:=1}
26: ${CROS_WORKON_INCREMENTAL_BUILD:=1}
Doug Andersonf291dba2012-01-19 14:26:10 -080027
28# Config fragments selected by USE flags
Doug Anderson010887c2012-02-04 22:42:54 -080029# ...fragments will have the following variables substitutions
30# applied later (needs to be done later since these values
31# aren't reliable when used in a global context like this):
32# %ROOT% => ${ROOT}
Doug Andersonf291dba2012-01-19 14:26:10 -080033
34CONFIG_FRAGMENTS=(
35 blkdevram
Dylan Reidf0666ff2012-07-01 21:42:38 -070036 ca0132
Micah Catlin0dc2b972012-08-01 17:44:24 -070037 cifs
Sonny Rao964708e2013-05-22 18:18:07 -070038 dyndebug
Doug Andersonf291dba2012-01-19 14:26:10 -080039 fbconsole
Ben Chane0654d22012-05-12 00:09:53 -070040 gdmwimax
Ben Chana179ebb2012-10-11 01:02:35 -070041 gobi
Doug Andersonf291dba2012-01-19 14:26:10 -080042 highmem
Vic Yang1541a702013-01-10 17:36:06 +080043 i2cdev
Doug Andersonf291dba2012-01-19 14:26:10 -080044 initramfs
Doug Andersondd0f35f2013-04-15 10:57:54 -070045 kgdb
Ronald G. Minnich6d888d42012-02-16 13:45:58 -080046 kvm
Ben Chan412abea2013-06-26 11:04:17 -070047 mbim
Vic Yang9aabf9c2013-01-23 20:47:59 +080048 netboot_ramfs
Doug Andersonf291dba2012-01-19 14:26:10 -080049 nfs
50 pcserial
Ben Chana179ebb2012-10-11 01:02:35 -070051 qmi
Dave Parker9fb68c92012-05-04 10:34:00 -070052 realtekpstor
Vic Yange0d659e2013-01-22 21:44:41 +080053 samsung_serial
Doug Andersonf291dba2012-01-19 14:26:10 -080054 systemtap
Vic Yange0d659e2013-01-22 21:44:41 +080055 tpm
Vic Yang7cc29a92012-05-18 14:12:10 +080056 vfat
Paul Stewart23ead5f2013-04-24 22:32:17 -070057 wifi_testbed_ap
Olof Johansson7921a5b2013-05-15 13:36:34 -070058 wireless34
Mike Frysinger34a55122013-02-05 14:01:39 -050059 x32
Doug Andersonf291dba2012-01-19 14:26:10 -080060)
61
62blkdevram_desc="ram block device"
63blkdevram_config="
64CONFIG_BLK_DEV_RAM=y
65CONFIG_BLK_DEV_RAM_COUNT=16
66CONFIG_BLK_DEV_RAM_SIZE=16384
67"
68
Dylan Reidf0666ff2012-07-01 21:42:38 -070069ca0132_desc="CA0132 ALSA codec"
70ca0132_config="
71CONFIG_SND_HDA_CODEC_CA0132=y
Chih-Chung Chang2306b492012-09-04 19:52:18 +080072CONFIG_SND_HDA_DSP_LOADER=y
Dylan Reidf0666ff2012-07-01 21:42:38 -070073"
74
Micah Catlin0dc2b972012-08-01 17:44:24 -070075cifs_desc="Samba/CIFS Support"
76cifs_config="
77CONFIG_CIFS=m
78"
79
Sonny Rao964708e2013-05-22 18:18:07 -070080dyndebug_desc="Enable Dynamic Debug"
81dyndebug_config="
82CONFIG_DYNAMIC_DEBUG=y
83"
84
Doug Andersonf291dba2012-01-19 14:26:10 -080085fbconsole_desc="framebuffer console"
86fbconsole_config="
87CONFIG_FRAMEBUFFER_CONSOLE=y
88"
89
Ben Chane0654d22012-05-12 00:09:53 -070090gdmwimax_desc="GCT GDM72xx WiMAX support"
91gdmwimax_config="
92CONFIG_WIMAX_GDM72XX=m
Ben Chane0654d22012-05-12 00:09:53 -070093CONFIG_WIMAX_GDM72XX_USB=y
94CONFIG_WIMAX_GDM72XX_USB_PM=y
95"
96
Ben Chana179ebb2012-10-11 01:02:35 -070097gobi_desc="Qualcomm Gobi modem driver"
98gobi_config="
99CONFIG_USB_NET_GOBI=m
100"
101
Doug Andersonf291dba2012-01-19 14:26:10 -0800102highmem_desc="highmem"
103highmem_config="
104CONFIG_HIGHMEM64G=y
105"
106
Vic Yang1541a702013-01-10 17:36:06 +0800107i2cdev_desc="I2C device interface"
108i2cdev_config="
109CONFIG_I2C_CHARDEV=y
110"
111
Doug Andersondd0f35f2013-04-15 10:57:54 -0700112kgdb_desc="Enable kgdb"
113kgdb_config="
114CONFIG_KGDB=y
115CONFIG_KGDB_KDB=y
116"""
117
Vic Yange0d659e2013-01-22 21:44:41 +0800118tpm_desc="TPM support"
119tpm_config="
120CONFIG_TCG_TPM=y
121CONFIG_TCG_TIS=y
122"
123
Vic Yang9aabf9c2013-01-23 20:47:59 +0800124initramfs_desc="Initramfs for factory install shim and recovery image"
125initramfs_config='
126CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/initramfs.cpio.xz"
Anush Elangovanf9b66d92012-12-20 12:16:15 -0800127CONFIG_INITRAMFS_COMPRESSION_XZ=y
Vic Yang9aabf9c2013-01-23 20:47:59 +0800128'
129
130netboot_ramfs_desc="Network boot install initramfs"
131netboot_ramfs_config='
132CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/netboot_ramfs.cpio.xz"
133CONFIG_INITRAMFS_COMPRESSION_XZ=y
134'
Vic Yang7cc29a92012-05-18 14:12:10 +0800135
136vfat_desc="vfat"
137vfat_config="
Doug Andersonf291dba2012-01-19 14:26:10 -0800138CONFIG_NLS_CODEPAGE_437=y
139CONFIG_NLS_ISO8859_1=y
140CONFIG_FAT_FS=y
141CONFIG_VFAT_FS=y
142"
143
Ronald G. Minnich6d888d42012-02-16 13:45:58 -0800144kvm_desc="KVM"
145kvm_config="
146CONFIG_HAVE_KVM=y
147CONFIG_HAVE_KVM_IRQCHIP=y
148CONFIG_HAVE_KVM_EVENTFD=y
149CONFIG_KVM_APIC_ARCHITECTURE=y
150CONFIG_KVM_MMIO=y
151CONFIG_KVM_ASYNC_PF=y
152CONFIG_KVM=m
153CONFIG_KVM_INTEL=m
154# CONFIG_KVM_AMD is not set
155# CONFIG_KVM_MMU_AUDIT is not set
156CONFIG_VIRTIO=m
157CONFIG_VIRTIO_BLK=m
158CONFIG_VIRTIO_NET=m
159CONFIG_VIRTIO_CONSOLE=m
160CONFIG_VIRTIO_RING=m
161CONFIG_VIRTIO_PCI=m
162"
163
Ben Chan412abea2013-06-26 11:04:17 -0700164# TODO(benchan): Remove the 'mbim' use flag and unconditionally enable the
165# CDC MBIM driver once Chromium OS fully supports MBIM.
166mbim_desc="CDC MBIM driver"
167mbim_config="
168CONFIG_USB_NET_CDC_MBIM=m
169"
170
Doug Andersonf291dba2012-01-19 14:26:10 -0800171nfs_desc="NFS"
172nfs_config="
173CONFIG_USB_NET_AX8817X=y
174CONFIG_DNOTIFY=y
175CONFIG_DNS_RESOLVER=y
176CONFIG_LOCKD=y
177CONFIG_LOCKD_V4=y
178CONFIG_NETWORK_FILESYSTEMS=y
179CONFIG_NFSD=m
180CONFIG_NFSD_V3=y
181CONFIG_NFSD_V4=y
182CONFIG_NFS_COMMON=y
183CONFIG_NFS_FS=y
184CONFIG_NFS_USE_KERNEL_DNS=y
185CONFIG_NFS_V3=y
186CONFIG_NFS_V4=y
187CONFIG_ROOT_NFS=y
188CONFIG_RPCSEC_GSS_KRB5=y
189CONFIG_SUNRPC=y
190CONFIG_SUNRPC_GSS=y
191CONFIG_USB_USBNET=y
192CONFIG_IP_PNP=y
193CONFIG_IP_PNP_DHCP=y
194"
195
196pcserial_desc="PC serial"
197pcserial_config="
198CONFIG_SERIAL_8250=y
199CONFIG_SERIAL_8250_CONSOLE=y
200CONFIG_SERIAL_8250_PCI=y
201CONFIG_PARPORT=y
202CONFIG_PARPORT_PC=y
203CONFIG_PARPORT_SERIAL=y
204"
205
Ben Chana179ebb2012-10-11 01:02:35 -0700206qmi_desc="QMI WWAN driver"
207qmi_config="
208CONFIG_USB_NET_QMI_WWAN=m
209"
210
Olof Johansson08268b0c2012-08-01 00:12:00 -0700211samsung_serial_desc="Samsung serialport"
212samsung_serial_config="
213CONFIG_SERIAL_SAMSUNG=y
214CONFIG_SERIAL_SAMSUNG_CONSOLE=y
215"
216
Dave Parker9fb68c92012-05-04 10:34:00 -0700217realtekpstor_desc="Realtek PCI card reader"
218realtekpstor_config="
219CONFIG_RTS_PSTOR=m
220"
221
Doug Andersonf291dba2012-01-19 14:26:10 -0800222systemtap_desc="systemtap support"
223systemtap_config="
224CONFIG_KPROBES=y
225CONFIG_DEBUG_INFO=y
226"
227
Paul Stewart23ead5f2013-04-24 22:32:17 -0700228wifi_testbed_ap_desc="Defer ath9k EEPROM regulatory"
229wifi_testbed_ap_warning="
230Don't use the wifi_testbed_ap flag unless you know what you are doing!
231An image built with this flag set must never be run outside a
232sealed RF chamber!
233"
234wifi_testbed_ap_config="
235CONFIG_ATH_DEFER_EEPROM_REGULATORY=y
236"
237
Mike Frysinger34a55122013-02-05 14:01:39 -0500238x32_desc="x32 ABI support"
239x32_config="
240CONFIG_X86_X32=y
241"
242
Olof Johansson7921a5b2013-05-15 13:36:34 -0700243wireless34_desc="Wireless 3.4 stack"
244wireless34_config="
245CONFIG_ATH9K_BTCOEX=m
246CONFIG_ATH9K_BTCOEX_COMMON=m
247CONFIG_ATH9K_BTCOEX_HW=m
248"
249
Doug Andersonf291dba2012-01-19 14:26:10 -0800250# Add all config fragments as off by default
251IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}"
Vic Yang9aabf9c2013-01-23 20:47:59 +0800252REQUIRED_USE="
253 initramfs? ( !netboot_ramfs )
254 netboot_ramfs? ( !initramfs )
255 initramfs? ( i2cdev tpm )
256 netboot_ramfs? ( i2cdev tpm )
257"
Doug Andersonf291dba2012-01-19 14:26:10 -0800258
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700259# If an overlay has eclass overrides, but doesn't actually override this
260# eclass, we'll have ECLASSDIR pointing to the active overlay's
261# eclass/ dir, but this eclass is still in the main chromiumos tree. So
262# add a check to locate the cros-kernel/ regardless of what's going on.
263ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
264defconfig_dir() {
Michael Spangc4f2fc02013-09-18 12:17:32 -0400265 local d="${ECLASSDIR}/cros-kernel"
266 if [[ ! -d ${d} ]] ; then
267 d="${ECLASSDIR_LOCAL}/cros-kernel"
268 fi
269 echo "${d}"
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700270}
271
Josh Triplett6df77a72013-04-26 17:25:37 -0700272# @FUNCTION: kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500273# @DESCRIPTION:
274# Returns the current compiled kernel version.
275# Note: Only valid after src_configure has finished running.
Josh Triplett6df77a72013-04-26 17:25:37 -0700276kernelrelease() {
277 kmake -s --no-print-directory kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500278}
279
Doug Andersonf291dba2012-01-19 14:26:10 -0800280# @FUNCTION: install_kernel_sources
281# @DESCRIPTION:
282# Installs the kernel sources into ${D}/usr/src/${P} and fixes symlinks.
283# The package must have already installed a directory under ${D}/lib/modules.
284install_kernel_sources() {
Josh Triplett6df77a72013-04-26 17:25:37 -0700285 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800286 local dest_modules_dir=lib/modules/${version}
287 local dest_source_dir=usr/src/${P}
288 local dest_build_dir=${dest_source_dir}/build
289
290 # Fix symlinks in lib/modules
291 ln -sfvT "../../../${dest_build_dir}" \
292 "${D}/${dest_modules_dir}/build" || die
293 ln -sfvT "../../../${dest_source_dir}" \
294 "${D}/${dest_modules_dir}/source" || die
295
296 einfo "Installing kernel source tree"
297 dodir "${dest_source_dir}"
298 local f
299 for f in "${S}"/*; do
300 [[ "$f" == "${S}/build" ]] && continue
301 cp -pPR "${f}" "${D}/${dest_source_dir}" ||
302 die "Failed to copy kernel source tree"
303 done
304
305 dosym "${P}" "/usr/src/linux"
306
307 einfo "Installing kernel build tree"
308 dodir "${dest_build_dir}"
Mike Frysinger833d5f72012-08-07 18:11:59 -0400309 cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \
Doug Andersonf291dba2012-01-19 14:26:10 -0800310 "${D}/${dest_build_dir}" || die
311
312 # Modify Makefile to use the ROOT environment variable if defined.
313 # This path needs to be absolute so that the build directory will
314 # still work if copied elsewhere.
315 sed -i -e "s@${S}@\$(ROOT)/${dest_source_dir}@" \
316 "${D}/${dest_build_dir}/Makefile" || die
317}
318
Doug Andersonf291dba2012-01-19 14:26:10 -0800319get_build_cfg() {
Mike Frysinger833d5f72012-08-07 18:11:59 -0400320 echo "$(cros-workon_get_build_dir)/.config"
Doug Andersonf291dba2012-01-19 14:26:10 -0800321}
322
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700323get_build_arch() {
324 if [ "${ARCH}" = "arm" ] ; then
325 case "${CHROMEOS_KERNEL_SPLITCONFIG}" in
326 *tegra*)
327 echo "tegra"
328 ;;
329 *exynos*)
330 echo "exynos5"
331 ;;
332 *)
333 echo "arm"
334 ;;
335 esac
336 else
Mike Frysingerdde5f6a2013-09-25 22:08:25 -0400337 tc-arch-kernel
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700338 fi
339}
340
Chris Masone6e9b8212013-01-14 11:03:02 -0800341# @FUNCTION: cros_chkconfig_present
342# @USAGE: <option to check config for>
343# @DESCRIPTION:
344# Returns success of the provided option is present in the build config.
345cros_chkconfig_present() {
346 local config=$1
347 grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)"
348}
349
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400350cros-kernel2_pkg_setup() {
Simon Que715e54f32012-12-20 15:53:13 -0800351 # This is needed for running src_test(). The kernel code will need to
352 # be rebuilt with `make check`. If incremental build were enabled,
353 # `make check` would have nothing left to build.
Simon Que6324b6f2013-02-01 14:56:05 -0800354 use test && export CROS_WORKON_INCREMENTAL_BUILD=0
Mike Frysinger833d5f72012-08-07 18:11:59 -0400355 cros-workon_pkg_setup
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500356 linux-info_pkg_setup
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400357}
358
Olof Johanssonb62cf892012-04-27 14:50:24 -0700359# @FUNCTION: emit_its_script
Doug Andersonf2bb2882012-12-06 15:56:21 -0800360# @USAGE: <output file> <boot_dir> <dtb_dir> <device trees>
Olof Johanssonb62cf892012-04-27 14:50:24 -0700361# @DESCRIPTION:
362# Emits the its script used to build the u-boot fitImage kernel binary
363# that contains the kernel as well as device trees used when booting
364# it.
365
366emit_its_script() {
367 local iter=1
368 local its_out=${1}
369 shift
Doug Andersonf2bb2882012-12-06 15:56:21 -0800370 local boot_dir=${1}
371 shift
372 local dtb_dir=${1}
373 shift
Olof Johanssonb62cf892012-04-27 14:50:24 -0700374 cat > "${its_out}" <<-EOF || die
375 /dts-v1/;
376
377 / {
378 description = "Chrome OS kernel image with one or more FDT blobs";
379 #address-cells = <1>;
380
381 images {
382 kernel@1 {
383 data = /incbin/("${boot_dir}/zImage");
Doug Anderson21b44202013-06-24 14:31:18 -0700384 type = "kernel_noload";
Olof Johanssonb62cf892012-04-27 14:50:24 -0700385 arch = "arm";
386 os = "linux";
387 compression = "none";
Doug Anderson21b44202013-06-24 14:31:18 -0700388 load = <0>;
389 entry = <0>;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700390 };
391 EOF
392
393 local dtb
394 for dtb in "$@" ; do
395 cat >> "${its_out}" <<-EOF || die
396 fdt@${iter} {
397 description = "$(basename ${dtb})";
Doug Andersonf2bb2882012-12-06 15:56:21 -0800398 data = /incbin/("${dtb_dir}/${dtb}");
Olof Johanssonb62cf892012-04-27 14:50:24 -0700399 type = "flat_dt";
400 arch = "arm";
401 compression = "none";
402 hash@1 {
403 algo = "sha1";
404 };
405 };
406 EOF
407 ((++iter))
408 done
409
410 cat <<-EOF >>"${its_script}"
411 };
412 configurations {
413 default = "conf@1";
414 EOF
415
416 local i
417 for i in $(seq 1 $((iter-1))) ; do
418 cat >> "${its_out}" <<-EOF || die
419 conf@${i} {
420 kernel = "kernel@1";
421 fdt = "fdt@${i}";
422 };
423 EOF
424 done
425
426 echo " };" >> "${its_out}"
427 echo "};" >> "${its_out}"
428}
429
Doug Andersonf291dba2012-01-19 14:26:10 -0800430kmake() {
431 # Allow override of kernel arch.
432 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
433
434 local cross=${CHOST}-
Olof Johanssonc0f8a5d2013-04-11 18:36:40 -0700435
436 if use wireless34 ; then
437 set -- "$@" WIFIVERSION="-3.4"
438 fi
439
Kees Cookaaff8412013-07-12 10:46:50 -0700440 # TODO(raymes): Force GNU ld over gold. There are still some
441 # gold issues to iron out. See: 13209.
442 tc-export LD CC CXX
443
444 local binutils_path=$(get_binutils_path_ld)
445
Doug Andersonf291dba2012-01-19 14:26:10 -0800446 # Hack for using 64-bit kernel with 32-bit user-space
Mike Frysinger0f008b22013-03-14 11:54:13 -0400447 if [[ "${ARCH}" == "x86" && "${kernel_arch}" == "x86_64" ]]; then
Sonny Rao5ebd89f2012-08-05 20:31:23 -0700448 cross=x86_64-cros-linux-gnu-
Kees Cookaaff8412013-07-12 10:46:50 -0700449 binutils_path=$(echo "$binutils_path" | sed -e \
450 's/i686-pc-linux-gnu/x86_64-cros-linux-gnu/g')
451 LD=$(echo "$LD" | sed -e \
452 's/i686-pc-linux-gnu/x86_64-cros-linux-gnu/g')
453 CC=$(echo "$CC" | sed -e \
454 's/i686-pc-linux-gnu/x86_64-cros-linux-gnu/g')
455 CXX=$(echo "$CXX" | sed -e \
456 's/i686-pc-linux-gnu/x86_64-cros-linux-gnu/g')
Doug Andersonf291dba2012-01-19 14:26:10 -0800457 fi
458
Kees Cookaaff8412013-07-12 10:46:50 -0700459 set -- \
460 LD="${binutils_path}/ld $(usex x32 '-m elf_x86_64' '')" \
461 CC="${CC} -B${binutils_path}" \
462 CXX="${CXX} -B${binutils_path}" \
463 "$@"
464
Mike Frysingera8ef3cd2012-11-01 18:42:18 -0400465 cw_emake \
Doug Andersonf291dba2012-01-19 14:26:10 -0800466 ARCH=${kernel_arch} \
467 LDFLAGS="$(raw-ldflags)" \
468 CROSS_COMPILE="${cross}" \
Mike Frysinger833d5f72012-08-07 18:11:59 -0400469 O="$(cros-workon_get_build_dir)" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800470 "$@"
471}
472
Josh Triplett4c035592012-12-05 15:46:46 -0800473cros-kernel2_src_prepare() {
474 cros-workon_src_prepare
475}
476
Doug Andersonf291dba2012-01-19 14:26:10 -0800477cros-kernel2_src_configure() {
Doug Andersonf291dba2012-01-19 14:26:10 -0800478 # Use a single or split kernel config as specified in the board or variant
479 # make.conf overlay. Default to the arch specific split config if an
480 # overlay or variant does not set either CHROMEOS_KERNEL_CONFIG or
481 # CHROMEOS_KERNEL_SPLITCONFIG. CHROMEOS_KERNEL_CONFIG is set relative
482 # to the root of the kernel source tree.
483 local config
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700484 local cfgarch="$(get_build_arch)"
485
Doug Andersonf291dba2012-01-19 14:26:10 -0800486 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
Chris Masonef888c382013-03-19 14:19:41 -0700487 case ${CHROMEOS_KERNEL_CONFIG} in
488 /*)
489 config="${CHROMEOS_KERNEL_CONFIG}"
490 ;;
491 *)
492 config="${S}/${CHROMEOS_KERNEL_CONFIG}"
493 ;;
494 esac
Doug Andersonf291dba2012-01-19 14:26:10 -0800495 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700496 config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"}
Doug Andersonf291dba2012-01-19 14:26:10 -0800497 fi
498
499 elog "Using kernel config: ${config}"
500
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400501 # Keep a handle on the old .config in case it hasn't changed. This way
502 # we can keep the old timestamp which will avoid regenerating stuff that
503 # hasn't actually changed.
504 local temp_config="${T}/old-kernel-config"
505 if [[ -e $(get_build_cfg) ]] ; then
506 cp -a "$(get_build_cfg)" "${temp_config}"
507 else
508 rm -f "${temp_config}"
509 fi
510
Doug Andersonf291dba2012-01-19 14:26:10 -0800511 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
512 cp -f "${config}" "$(get_build_cfg)" || die
513 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700514 if [ -e chromeos/scripts/prepareconfig ] ; then
515 chromeos/scripts/prepareconfig ${config} \
516 "$(get_build_cfg)" || die
517 else
518 config="$(defconfig_dir)/${cfgarch}_defconfig"
519 ewarn "Can't prepareconfig, falling back to default " \
520 "${config}"
521 cp "${config}" "$(get_build_cfg)" || die
522 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800523 fi
524
525 local fragment
526 for fragment in ${CONFIG_FRAGMENTS[@]}; do
527 use ${fragment} || continue
528
529 local msg="${fragment}_desc"
530 local config="${fragment}_config"
531 elog " - adding ${!msg} config"
Paul Stewart23ead5f2013-04-24 22:32:17 -0700532 local warning="${fragment}_warning"
533 local warning_msg="${!warning}"
534 if [[ -n "${warning_msg}" ]] ; then
535 ewarn "${warning_msg}"
536 fi
Doug Anderson010887c2012-02-04 22:42:54 -0800537
538 echo "${!config}" | \
539 sed -e "s|%ROOT%|${ROOT}|g" \
540 >> "$(get_build_cfg)" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800541 done
542
543 # Use default for any options not explitly set in splitconfig
544 yes "" | kmake oldconfig
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400545
546 # Restore the old config if it is unchanged.
547 if cmp -s "$(get_build_cfg)" "${temp_config}" ; then
548 touch -r "${temp_config}" "$(get_build_cfg)"
549 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800550}
551
Doug Andersonf2bb2882012-12-06 15:56:21 -0800552# @FUNCTION: get_dtb_name
553# @USAGE: <dtb_dir>
554# @DESCRIPTION:
555# Get the name(s) of the device tree binary file(s) to include.
556
Olof Johanssonb62cf892012-04-27 14:50:24 -0700557get_dtb_name() {
Doug Andersonf2bb2882012-12-06 15:56:21 -0800558 local dtb_dir=${1}
David Jamesd4130ab2013-09-19 11:26:39 -0700559 local f
560 for f in ${dtb_dir}/*.dtb ; do
561 basename ${f}
562 done
Doug Andersonf291dba2012-01-19 14:26:10 -0800563}
564
565cros-kernel2_src_compile() {
Chris Masone6e9b8212013-01-14 11:03:02 -0800566 local build_targets=() # use make default target
Doug Andersonf291dba2012-01-19 14:26:10 -0800567 if use arm; then
Chris Masone6e9b8212013-01-14 11:03:02 -0800568 build_targets=(
Michael Spangc4f2fc02013-09-18 12:17:32 -0400569 $(usex device_tree 'zImage dtbs' uImage)
Chris Masone6e9b8212013-01-14 11:03:02 -0800570 $(cros_chkconfig_present MODULES && echo "modules")
571 )
Doug Andersonf291dba2012-01-19 14:26:10 -0800572 fi
573
Simon Que715e54f32012-12-20 15:53:13 -0800574 local src_dir="$(cros-workon_get_build_dir)/source"
575 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
576 SMATCH_ERROR_FILE="${src_dir}/chromeos/check/smatch_errors.log"
577
Simon Que6324b6f2013-02-01 14:56:05 -0800578 if use test && [[ -e "${SMATCH_ERROR_FILE}" ]]; then
Simon Que715e54f32012-12-20 15:53:13 -0800579 local make_check_cmd="smatch -p=kernel"
580 local test_options=(
581 CHECK="${make_check_cmd}"
582 C=1
583 )
584 SMATCH_LOG_FILE="$(cros-workon_get_build_dir)/make.log"
585
586 # The path names in the log file are build-dependent. Strip out
587 # the part of the path before "kernel/files" and retains what
588 # comes after it: the file, line number, and error message.
Chris Masone6e9b8212013-01-14 11:03:02 -0800589 kmake -k ${build_targets[@]} "${test_options[@]}" |& \
Simon Que715e54f32012-12-20 15:53:13 -0800590 tee "${SMATCH_LOG_FILE}"
591 else
Chris Masone6e9b8212013-01-14 11:03:02 -0800592 kmake -k ${build_targets[@]}
Simon Que715e54f32012-12-20 15:53:13 -0800593 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800594}
595
Simon Que715e54f32012-12-20 15:53:13 -0800596cros-kernel2_src_test() {
Simon Que715e54f32012-12-20 15:53:13 -0800597 [[ -e ${SMATCH_ERROR_FILE} ]] || \
598 die "smatch whitelist file ${SMATCH_ERROR_FILE} not found!"
599 [[ -e ${SMATCH_LOG_FILE} ]] || \
600 die "Log file from src_compile() ${SMATCH_LOG_FILE} not found!"
601
Paul Taysom98a54362013-06-12 16:30:25 -0700602 local prefix="$(realpath "${S}")/"
603 grep -w error: "${SMATCH_LOG_FILE}" | grep -o "${prefix}.*" \
604 | sed s:"${prefix}"::g > "${SMATCH_LOG_FILE}.errors"
Simon Que715e54f32012-12-20 15:53:13 -0800605 local num_errors=$(wc -l < "${SMATCH_LOG_FILE}.errors")
606 local num_warnings=$(egrep -wc "warn:|warning:" "${SMATCH_LOG_FILE}")
607 einfo "smatch found ${num_errors} errors and ${num_warnings} warnings."
608
609 # Create a version of the error database that doesn't have line numbers,
610 # since line numbers will shift as code is added or removed.
611 local build_dir="$(cros-workon_get_build_dir)"
612 local no_line_numbers_file="${build_dir}/no_line_numbers.log"
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800613 sed -r -e "s/(:[0-9]+){1,2}//" \
614 -e "s/\(see line [0-9]+\)//" \
615 "${SMATCH_ERROR_FILE}" > "${no_line_numbers_file}"
Simon Que715e54f32012-12-20 15:53:13 -0800616
617 # For every smatch error that came up during the build, check if it is
618 # in the error database file.
619 local num_unknown_errors=0
620 local line=""
621 while read line; do
Simon Quefc5fc9d2013-01-28 15:19:38 -0800622 local no_line_num=$(echo "${line}" | \
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800623 sed -r -e "s/(:[0-9]+){1,2}//" \
624 -e "s/\(see line [0-9]+\)//")
Simon Que715e54f32012-12-20 15:53:13 -0800625 if ! fgrep -q "${no_line_num}" "${no_line_numbers_file}"; then
626 eerror "Non-whitelisted error found: \"${line}\""
627 : $(( ++num_unknown_errors ))
628 fi
629 done < "${SMATCH_LOG_FILE}.errors"
630
631 [[ ${num_unknown_errors} -eq 0 ]] || \
632 die "smatch found ${num_unknown_errors} unknown errors."
633}
634
Doug Andersonf291dba2012-01-19 14:26:10 -0800635cros-kernel2_src_install() {
Doug Andersone3a867e2013-06-24 16:26:43 -0700636 local build_targets=(
637 install
638 firmware_install
639 $(cros_chkconfig_present MODULES && echo "modules_install")
640 )
641
Doug Andersonf291dba2012-01-19 14:26:10 -0800642 dodir /boot
Doug Andersone3a867e2013-06-24 16:26:43 -0700643 kmake INSTALL_PATH="${D}/boot" INSTALL_MOD_PATH="${D}" \
644 "${build_targets[@]}"
Doug Andersonf291dba2012-01-19 14:26:10 -0800645
Josh Triplett6df77a72013-04-26 17:25:37 -0700646 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800647 if use arm; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400648 local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot"
Doug Andersonf291dba2012-01-19 14:26:10 -0800649 local kernel_bin="${D}/boot/vmlinuz-${version}"
650 local zimage_bin="${D}/boot/zImage-${version}"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800651 local dtb_dir="${boot_dir}"
652
653 # Newer kernels (after linux-next 12/3/12) put dtbs in the dts
654 # dir. Use that if we we find no dtbs directly in boot_dir.
655 # Note that we try boot_dir first since the newer kernel will
656 # actually rm ${boot_dir}/*.dtb so we'll have no stale files.
657 if ! ls "${dtb_dir}"/*.dtb &> /dev/null; then
658 dtb_dir="${boot_dir}/dts"
659 fi
660
Doug Andersonf291dba2012-01-19 14:26:10 -0800661 if use device_tree; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400662 local its_script="$(cros-workon_get_build_dir)/its_script"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800663 emit_its_script "${its_script}" "${boot_dir}" \
664 "${dtb_dir}" $(get_dtb_name "${dtb_dir}")
Isaac Simha4a2c1b52013-07-05 16:15:26 -0700665 mkimage -D "-I dts -O dtb -p 1024" -f "${its_script}" "${kernel_bin}" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800666 else
667 cp -a "${boot_dir}/uImage" "${kernel_bin}" || die
668 fi
669 cp -a "${boot_dir}/zImage" "${zimage_bin}" || die
670
671 # TODO(vbendeb): remove the below .uimg link creation code
672 # after the build scripts have been modified to use the base
673 # image name.
674 cd $(dirname "${kernel_bin}")
675 ln -sf $(basename "${kernel_bin}") vmlinux.uimg || die
676 ln -sf $(basename "${zimage_bin}") zImage || die
677 fi
678 if [ ! -e "${D}/boot/vmlinuz" ]; then
679 ln -sf "vmlinuz-${version}" "${D}/boot/vmlinuz" || die
680 fi
681
Vic Yang40fff212012-05-14 10:43:11 +0800682 # Check the size of kernel image and issue warning when image size is near
Vic Yang9aabf9c2013-01-23 20:47:59 +0800683 # the limit. For factory install initramfs, we don't care about kernel
684 # size limit as the image is downloaded over network.
Vic Yang40fff212012-05-14 10:43:11 +0800685 local kernel_image_size=$(stat -c '%s' -L "${D}"/boot/vmlinuz)
686 einfo "Kernel image size is ${kernel_image_size} bytes."
Vic Yang9aabf9c2013-01-23 20:47:59 +0800687 if use netboot_ramfs; then
688 # No need to check kernel image size.
689 true
690 elif [[ ${kernel_image_size} -gt $((8 * 1024 * 1024)) ]]; then
Olof Johanssoncbbe8872012-07-30 08:43:31 -0700691 die "Kernel image is larger than 8 MB."
692 elif [[ ${kernel_image_size} -gt $((7 * 1024 * 1024)) ]]; then
693 ewarn "Kernel image is larger than 7 MB. Limit is 8 MB."
Vic Yang40fff212012-05-14 10:43:11 +0800694 fi
695
Doug Andersonf291dba2012-01-19 14:26:10 -0800696 # Install uncompressed kernel for debugging purposes.
697 insinto /usr/lib/debug/boot
Mike Frysinger833d5f72012-08-07 18:11:59 -0400698 doins "$(cros-workon_get_build_dir)/vmlinux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800699
Mike Frysingerdde5f6a2013-09-25 22:08:25 -0400700 # Also install the vdso shared ELFs for crash reporting.
Mike Frysinger02d20012013-09-26 17:00:20 -0400701 # We use slightly funky filenames so as to better integrate with
702 # debugging processes (crash reporter/gdb/etc...). The basename
703 # will be the SONAME (what the runtime process sees), but since
704 # that is not unique among all inputs, we also install into a dir
705 # with the original filename. e.g. we will install:
706 # /lib/modules/3.8.11/vdso/vdso32-syscall.so/linux-gate.so
Mike Frysingerdde5f6a2013-09-25 22:08:25 -0400707 if use x86 || use amd64; then
Mike Frysinger02d20012013-09-26 17:00:20 -0400708 local d f soname
709 # Use the debug versions (.so.dbg) so portage can run splitdebug on them.
710 for f in "$(cros-workon_get_build_dir)/arch/x86/vdso"/vdso*.so.dbg; do
711 d="/lib/modules/${version}/vdso/${f##*/}"
712
713 exeinto "${d}"
714 newexe "${f}" "linux-gate.so"
715
716 soname=$(scanelf -qF'%S#f' "${f}")
717 dosym "linux-gate.so" "${d}/${soname}"
Mike Frysingerdde5f6a2013-09-25 22:08:25 -0400718 done
719 fi
720
Doug Andersonf291dba2012-01-19 14:26:10 -0800721 if use kernel_sources; then
722 install_kernel_sources
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500723 else
724 dosym "$(cros-workon_get_build_dir)" "/usr/src/linux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800725 fi
726}
727
Simon Que715e54f32012-12-20 15:53:13 -0800728EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install