blob: b9b5ed9974c73ac5e6f1f12f927168b02288d043 [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
Mike Frysingerb5ebdb52013-02-10 03:25:44 -05006inherit binutils-funcs cros-board toolchain-funcs linux-info
Doug Andersonf291dba2012-01-19 14:26:10 -08007
8HOMEPAGE="http://www.chromium.org/"
9LICENSE="GPL-2"
10SLOT="0"
11
12DEPEND="sys-apps/debianutils
Doug Andersonf291dba2012-01-19 14:26:10 -080013 initramfs? ( chromeos-base/chromeos-initramfs )
Vic Yang9aabf9c2013-01-23 20:47:59 +080014 netboot_ramfs? ( chromeos-base/chromeos-initramfs )
Doug Andersonf291dba2012-01-19 14:26:10 -080015"
16
Paul Stewart23ead5f2013-04-24 22:32:17 -070017IUSE="-device_tree -kernel_sources -wireless34 -wifi_testbed_ap"
Doug Andersonf291dba2012-01-19 14:26:10 -080018STRIP_MASK="/usr/lib/debug/boot/vmlinux"
Josh Triplett4c035592012-12-05 15:46:46 -080019
20# Build out-of-tree and incremental by default, but allow an ebuild inheriting
21# this eclass to explicitly build in-tree.
22: ${CROS_WORKON_OUTOFTREE_BUILD:=1}
23: ${CROS_WORKON_INCREMENTAL_BUILD:=1}
Doug Andersonf291dba2012-01-19 14:26:10 -080024
25# Config fragments selected by USE flags
Doug Anderson010887c2012-02-04 22:42:54 -080026# ...fragments will have the following variables substitutions
27# applied later (needs to be done later since these values
28# aren't reliable when used in a global context like this):
29# %ROOT% => ${ROOT}
Doug Andersonf291dba2012-01-19 14:26:10 -080030
31CONFIG_FRAGMENTS=(
32 blkdevram
Dylan Reidf0666ff2012-07-01 21:42:38 -070033 ca0132
Micah Catlin0dc2b972012-08-01 17:44:24 -070034 cifs
Sonny Rao964708e2013-05-22 18:18:07 -070035 dyndebug
Doug Andersonf291dba2012-01-19 14:26:10 -080036 fbconsole
Ben Chane0654d22012-05-12 00:09:53 -070037 gdmwimax
Ben Chana179ebb2012-10-11 01:02:35 -070038 gobi
Doug Andersonf291dba2012-01-19 14:26:10 -080039 highmem
Vic Yang1541a702013-01-10 17:36:06 +080040 i2cdev
Doug Andersonf291dba2012-01-19 14:26:10 -080041 initramfs
Doug Andersondd0f35f2013-04-15 10:57:54 -070042 kgdb
Ronald G. Minnich6d888d42012-02-16 13:45:58 -080043 kvm
Ben Chan412abea2013-06-26 11:04:17 -070044 mbim
Vic Yang9aabf9c2013-01-23 20:47:59 +080045 netboot_ramfs
Doug Andersonf291dba2012-01-19 14:26:10 -080046 nfs
47 pcserial
Ben Chana179ebb2012-10-11 01:02:35 -070048 qmi
Dave Parker9fb68c92012-05-04 10:34:00 -070049 realtekpstor
Vic Yange0d659e2013-01-22 21:44:41 +080050 samsung_serial
Doug Andersonf291dba2012-01-19 14:26:10 -080051 systemtap
Vic Yange0d659e2013-01-22 21:44:41 +080052 tpm
Vic Yang7cc29a92012-05-18 14:12:10 +080053 vfat
Paul Stewart23ead5f2013-04-24 22:32:17 -070054 wifi_testbed_ap
Olof Johansson7921a5b2013-05-15 13:36:34 -070055 wireless34
Mike Frysinger34a55122013-02-05 14:01:39 -050056 x32
Doug Andersonf291dba2012-01-19 14:26:10 -080057)
58
59blkdevram_desc="ram block device"
60blkdevram_config="
61CONFIG_BLK_DEV_RAM=y
62CONFIG_BLK_DEV_RAM_COUNT=16
63CONFIG_BLK_DEV_RAM_SIZE=16384
64"
65
Dylan Reidf0666ff2012-07-01 21:42:38 -070066ca0132_desc="CA0132 ALSA codec"
67ca0132_config="
68CONFIG_SND_HDA_CODEC_CA0132=y
Chih-Chung Chang2306b492012-09-04 19:52:18 +080069CONFIG_SND_HDA_DSP_LOADER=y
Dylan Reidf0666ff2012-07-01 21:42:38 -070070"
71
Micah Catlin0dc2b972012-08-01 17:44:24 -070072cifs_desc="Samba/CIFS Support"
73cifs_config="
74CONFIG_CIFS=m
75"
76
Sonny Rao964708e2013-05-22 18:18:07 -070077dyndebug_desc="Enable Dynamic Debug"
78dyndebug_config="
79CONFIG_DYNAMIC_DEBUG=y
80"
81
Doug Andersonf291dba2012-01-19 14:26:10 -080082fbconsole_desc="framebuffer console"
83fbconsole_config="
84CONFIG_FRAMEBUFFER_CONSOLE=y
85"
86
Ben Chane0654d22012-05-12 00:09:53 -070087gdmwimax_desc="GCT GDM72xx WiMAX support"
88gdmwimax_config="
89CONFIG_WIMAX_GDM72XX=m
Ben Chane0654d22012-05-12 00:09:53 -070090CONFIG_WIMAX_GDM72XX_USB=y
91CONFIG_WIMAX_GDM72XX_USB_PM=y
92"
93
Ben Chana179ebb2012-10-11 01:02:35 -070094gobi_desc="Qualcomm Gobi modem driver"
95gobi_config="
96CONFIG_USB_NET_GOBI=m
97"
98
Doug Andersonf291dba2012-01-19 14:26:10 -080099highmem_desc="highmem"
100highmem_config="
101CONFIG_HIGHMEM64G=y
102"
103
Vic Yang1541a702013-01-10 17:36:06 +0800104i2cdev_desc="I2C device interface"
105i2cdev_config="
106CONFIG_I2C_CHARDEV=y
107"
108
Doug Andersondd0f35f2013-04-15 10:57:54 -0700109kgdb_desc="Enable kgdb"
110kgdb_config="
111CONFIG_KGDB=y
112CONFIG_KGDB_KDB=y
113"""
114
Vic Yange0d659e2013-01-22 21:44:41 +0800115tpm_desc="TPM support"
116tpm_config="
117CONFIG_TCG_TPM=y
118CONFIG_TCG_TIS=y
119"
120
Vic Yang9aabf9c2013-01-23 20:47:59 +0800121initramfs_desc="Initramfs for factory install shim and recovery image"
122initramfs_config='
123CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/initramfs.cpio.xz"
Anush Elangovanf9b66d92012-12-20 12:16:15 -0800124CONFIG_INITRAMFS_COMPRESSION_XZ=y
Vic Yang9aabf9c2013-01-23 20:47:59 +0800125'
126
127netboot_ramfs_desc="Network boot install initramfs"
128netboot_ramfs_config='
129CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/netboot_ramfs.cpio.xz"
130CONFIG_INITRAMFS_COMPRESSION_XZ=y
131'
Vic Yang7cc29a92012-05-18 14:12:10 +0800132
133vfat_desc="vfat"
134vfat_config="
Doug Andersonf291dba2012-01-19 14:26:10 -0800135CONFIG_NLS_CODEPAGE_437=y
136CONFIG_NLS_ISO8859_1=y
137CONFIG_FAT_FS=y
138CONFIG_VFAT_FS=y
139"
140
Ronald G. Minnich6d888d42012-02-16 13:45:58 -0800141kvm_desc="KVM"
142kvm_config="
143CONFIG_HAVE_KVM=y
144CONFIG_HAVE_KVM_IRQCHIP=y
145CONFIG_HAVE_KVM_EVENTFD=y
146CONFIG_KVM_APIC_ARCHITECTURE=y
147CONFIG_KVM_MMIO=y
148CONFIG_KVM_ASYNC_PF=y
149CONFIG_KVM=m
150CONFIG_KVM_INTEL=m
151# CONFIG_KVM_AMD is not set
152# CONFIG_KVM_MMU_AUDIT is not set
153CONFIG_VIRTIO=m
154CONFIG_VIRTIO_BLK=m
155CONFIG_VIRTIO_NET=m
156CONFIG_VIRTIO_CONSOLE=m
157CONFIG_VIRTIO_RING=m
158CONFIG_VIRTIO_PCI=m
159"
160
Ben Chan412abea2013-06-26 11:04:17 -0700161# TODO(benchan): Remove the 'mbim' use flag and unconditionally enable the
162# CDC MBIM driver once Chromium OS fully supports MBIM.
163mbim_desc="CDC MBIM driver"
164mbim_config="
165CONFIG_USB_NET_CDC_MBIM=m
166"
167
Doug Andersonf291dba2012-01-19 14:26:10 -0800168nfs_desc="NFS"
169nfs_config="
170CONFIG_USB_NET_AX8817X=y
171CONFIG_DNOTIFY=y
172CONFIG_DNS_RESOLVER=y
173CONFIG_LOCKD=y
174CONFIG_LOCKD_V4=y
175CONFIG_NETWORK_FILESYSTEMS=y
176CONFIG_NFSD=m
177CONFIG_NFSD_V3=y
178CONFIG_NFSD_V4=y
179CONFIG_NFS_COMMON=y
180CONFIG_NFS_FS=y
181CONFIG_NFS_USE_KERNEL_DNS=y
182CONFIG_NFS_V3=y
183CONFIG_NFS_V4=y
184CONFIG_ROOT_NFS=y
185CONFIG_RPCSEC_GSS_KRB5=y
186CONFIG_SUNRPC=y
187CONFIG_SUNRPC_GSS=y
188CONFIG_USB_USBNET=y
189CONFIG_IP_PNP=y
190CONFIG_IP_PNP_DHCP=y
191"
192
193pcserial_desc="PC serial"
194pcserial_config="
195CONFIG_SERIAL_8250=y
196CONFIG_SERIAL_8250_CONSOLE=y
197CONFIG_SERIAL_8250_PCI=y
198CONFIG_PARPORT=y
199CONFIG_PARPORT_PC=y
200CONFIG_PARPORT_SERIAL=y
201"
202
Ben Chana179ebb2012-10-11 01:02:35 -0700203qmi_desc="QMI WWAN driver"
204qmi_config="
205CONFIG_USB_NET_QMI_WWAN=m
206"
207
Olof Johansson08268b0c2012-08-01 00:12:00 -0700208samsung_serial_desc="Samsung serialport"
209samsung_serial_config="
210CONFIG_SERIAL_SAMSUNG=y
211CONFIG_SERIAL_SAMSUNG_CONSOLE=y
212"
213
Dave Parker9fb68c92012-05-04 10:34:00 -0700214realtekpstor_desc="Realtek PCI card reader"
215realtekpstor_config="
216CONFIG_RTS_PSTOR=m
217"
218
Doug Andersonf291dba2012-01-19 14:26:10 -0800219systemtap_desc="systemtap support"
220systemtap_config="
221CONFIG_KPROBES=y
222CONFIG_DEBUG_INFO=y
223"
224
Paul Stewart23ead5f2013-04-24 22:32:17 -0700225wifi_testbed_ap_desc="Defer ath9k EEPROM regulatory"
226wifi_testbed_ap_warning="
227Don't use the wifi_testbed_ap flag unless you know what you are doing!
228An image built with this flag set must never be run outside a
229sealed RF chamber!
230"
231wifi_testbed_ap_config="
232CONFIG_ATH_DEFER_EEPROM_REGULATORY=y
233"
234
Mike Frysinger34a55122013-02-05 14:01:39 -0500235x32_desc="x32 ABI support"
236x32_config="
237CONFIG_X86_X32=y
238"
239
Olof Johansson7921a5b2013-05-15 13:36:34 -0700240wireless34_desc="Wireless 3.4 stack"
241wireless34_config="
242CONFIG_ATH9K_BTCOEX=m
243CONFIG_ATH9K_BTCOEX_COMMON=m
244CONFIG_ATH9K_BTCOEX_HW=m
245"
246
Doug Andersonf291dba2012-01-19 14:26:10 -0800247# Add all config fragments as off by default
248IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}"
Vic Yang9aabf9c2013-01-23 20:47:59 +0800249REQUIRED_USE="
250 initramfs? ( !netboot_ramfs )
251 netboot_ramfs? ( !initramfs )
252 initramfs? ( i2cdev tpm )
253 netboot_ramfs? ( i2cdev tpm )
254"
Doug Andersonf291dba2012-01-19 14:26:10 -0800255
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700256# If an overlay has eclass overrides, but doesn't actually override this
257# eclass, we'll have ECLASSDIR pointing to the active overlay's
258# eclass/ dir, but this eclass is still in the main chromiumos tree. So
259# add a check to locate the cros-kernel/ regardless of what's going on.
260ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
261defconfig_dir() {
262 local d="${ECLASSDIR}/cros-kernel"
263 if [[ ! -d ${d} ]] ; then
264 d="${ECLASSDIR_LOCAL}/cros-kernel"
265 fi
266 echo "${d}"
267}
268
Josh Triplett6df77a72013-04-26 17:25:37 -0700269# @FUNCTION: kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500270# @DESCRIPTION:
271# Returns the current compiled kernel version.
272# Note: Only valid after src_configure has finished running.
Josh Triplett6df77a72013-04-26 17:25:37 -0700273kernelrelease() {
274 kmake -s --no-print-directory kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500275}
276
Doug Andersonf291dba2012-01-19 14:26:10 -0800277# @FUNCTION: install_kernel_sources
278# @DESCRIPTION:
279# Installs the kernel sources into ${D}/usr/src/${P} and fixes symlinks.
280# The package must have already installed a directory under ${D}/lib/modules.
281install_kernel_sources() {
Josh Triplett6df77a72013-04-26 17:25:37 -0700282 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800283 local dest_modules_dir=lib/modules/${version}
284 local dest_source_dir=usr/src/${P}
285 local dest_build_dir=${dest_source_dir}/build
286
287 # Fix symlinks in lib/modules
288 ln -sfvT "../../../${dest_build_dir}" \
289 "${D}/${dest_modules_dir}/build" || die
290 ln -sfvT "../../../${dest_source_dir}" \
291 "${D}/${dest_modules_dir}/source" || die
292
293 einfo "Installing kernel source tree"
294 dodir "${dest_source_dir}"
295 local f
296 for f in "${S}"/*; do
297 [[ "$f" == "${S}/build" ]] && continue
298 cp -pPR "${f}" "${D}/${dest_source_dir}" ||
299 die "Failed to copy kernel source tree"
300 done
301
302 dosym "${P}" "/usr/src/linux"
303
304 einfo "Installing kernel build tree"
305 dodir "${dest_build_dir}"
Mike Frysinger833d5f72012-08-07 18:11:59 -0400306 cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \
Doug Andersonf291dba2012-01-19 14:26:10 -0800307 "${D}/${dest_build_dir}" || die
308
309 # Modify Makefile to use the ROOT environment variable if defined.
310 # This path needs to be absolute so that the build directory will
311 # still work if copied elsewhere.
312 sed -i -e "s@${S}@\$(ROOT)/${dest_source_dir}@" \
313 "${D}/${dest_build_dir}/Makefile" || die
314}
315
Doug Andersonf291dba2012-01-19 14:26:10 -0800316get_build_cfg() {
Mike Frysinger833d5f72012-08-07 18:11:59 -0400317 echo "$(cros-workon_get_build_dir)/.config"
Doug Andersonf291dba2012-01-19 14:26:10 -0800318}
319
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700320get_build_arch() {
321 if [ "${ARCH}" = "arm" ] ; then
322 case "${CHROMEOS_KERNEL_SPLITCONFIG}" in
323 *tegra*)
324 echo "tegra"
325 ;;
326 *exynos*)
327 echo "exynos5"
328 ;;
329 *)
330 echo "arm"
331 ;;
332 esac
333 else
334 echo $(tc-arch-kernel)
335 fi
336}
337
Chris Masone6e9b8212013-01-14 11:03:02 -0800338# @FUNCTION: cros_chkconfig_present
339# @USAGE: <option to check config for>
340# @DESCRIPTION:
341# Returns success of the provided option is present in the build config.
342cros_chkconfig_present() {
343 local config=$1
344 grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)"
345}
346
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400347cros-kernel2_pkg_setup() {
Simon Que715e54f32012-12-20 15:53:13 -0800348 # This is needed for running src_test(). The kernel code will need to
349 # be rebuilt with `make check`. If incremental build were enabled,
350 # `make check` would have nothing left to build.
Simon Que6324b6f2013-02-01 14:56:05 -0800351 use test && export CROS_WORKON_INCREMENTAL_BUILD=0
Mike Frysinger833d5f72012-08-07 18:11:59 -0400352 cros-workon_pkg_setup
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500353 linux-info_pkg_setup
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400354}
355
Olof Johanssonb62cf892012-04-27 14:50:24 -0700356# @FUNCTION: emit_its_script
Doug Andersonf2bb2882012-12-06 15:56:21 -0800357# @USAGE: <output file> <boot_dir> <dtb_dir> <device trees>
Olof Johanssonb62cf892012-04-27 14:50:24 -0700358# @DESCRIPTION:
359# Emits the its script used to build the u-boot fitImage kernel binary
360# that contains the kernel as well as device trees used when booting
361# it.
362
363emit_its_script() {
364 local iter=1
365 local its_out=${1}
366 shift
Doug Andersonf2bb2882012-12-06 15:56:21 -0800367 local boot_dir=${1}
368 shift
369 local dtb_dir=${1}
370 shift
Olof Johanssonb62cf892012-04-27 14:50:24 -0700371 cat > "${its_out}" <<-EOF || die
372 /dts-v1/;
373
374 / {
375 description = "Chrome OS kernel image with one or more FDT blobs";
376 #address-cells = <1>;
377
378 images {
379 kernel@1 {
380 data = /incbin/("${boot_dir}/zImage");
Doug Anderson21b44202013-06-24 14:31:18 -0700381 type = "kernel_noload";
Olof Johanssonb62cf892012-04-27 14:50:24 -0700382 arch = "arm";
383 os = "linux";
384 compression = "none";
Doug Anderson21b44202013-06-24 14:31:18 -0700385 load = <0>;
386 entry = <0>;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700387 };
388 EOF
389
390 local dtb
391 for dtb in "$@" ; do
392 cat >> "${its_out}" <<-EOF || die
393 fdt@${iter} {
394 description = "$(basename ${dtb})";
Doug Andersonf2bb2882012-12-06 15:56:21 -0800395 data = /incbin/("${dtb_dir}/${dtb}");
Olof Johanssonb62cf892012-04-27 14:50:24 -0700396 type = "flat_dt";
397 arch = "arm";
398 compression = "none";
399 hash@1 {
400 algo = "sha1";
401 };
402 };
403 EOF
404 ((++iter))
405 done
406
407 cat <<-EOF >>"${its_script}"
408 };
409 configurations {
410 default = "conf@1";
411 EOF
412
413 local i
414 for i in $(seq 1 $((iter-1))) ; do
415 cat >> "${its_out}" <<-EOF || die
416 conf@${i} {
417 kernel = "kernel@1";
418 fdt = "fdt@${i}";
419 };
420 EOF
421 done
422
423 echo " };" >> "${its_out}"
424 echo "};" >> "${its_out}"
425}
426
Doug Andersonf291dba2012-01-19 14:26:10 -0800427kmake() {
428 # Allow override of kernel arch.
429 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
430
431 local cross=${CHOST}-
Olof Johanssonc0f8a5d2013-04-11 18:36:40 -0700432
433 if use wireless34 ; then
434 set -- "$@" WIFIVERSION="-3.4"
435 fi
436
Doug Andersonf291dba2012-01-19 14:26:10 -0800437 # Hack for using 64-bit kernel with 32-bit user-space
Mike Frysinger0f008b22013-03-14 11:54:13 -0400438 if [[ "${ARCH}" == "x86" && "${kernel_arch}" == "x86_64" ]]; then
Sonny Rao5ebd89f2012-08-05 20:31:23 -0700439 cross=x86_64-cros-linux-gnu-
Doug Andersonf291dba2012-01-19 14:26:10 -0800440 else
441 # TODO(raymes): Force GNU ld over gold. There are still some
442 # gold issues to iron out. See: 13209.
443 tc-export LD CC CXX
444
445 set -- \
Mike Frysinger0f008b22013-03-14 11:54:13 -0400446 LD="$(get_binutils_path_ld)/ld $(usex x32 '-m elf_x86_64' '')" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800447 CC="${CC} -B$(get_binutils_path_ld)" \
448 CXX="${CXX} -B$(get_binutils_path_ld)" \
449 "$@"
450 fi
451
Mike Frysingera8ef3cd2012-11-01 18:42:18 -0400452 cw_emake \
Doug Andersonf291dba2012-01-19 14:26:10 -0800453 ARCH=${kernel_arch} \
454 LDFLAGS="$(raw-ldflags)" \
455 CROSS_COMPILE="${cross}" \
Mike Frysinger833d5f72012-08-07 18:11:59 -0400456 O="$(cros-workon_get_build_dir)" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800457 "$@"
458}
459
Josh Triplett4c035592012-12-05 15:46:46 -0800460cros-kernel2_src_prepare() {
461 cros-workon_src_prepare
462}
463
Doug Andersonf291dba2012-01-19 14:26:10 -0800464cros-kernel2_src_configure() {
Doug Andersonf291dba2012-01-19 14:26:10 -0800465 # Use a single or split kernel config as specified in the board or variant
466 # make.conf overlay. Default to the arch specific split config if an
467 # overlay or variant does not set either CHROMEOS_KERNEL_CONFIG or
468 # CHROMEOS_KERNEL_SPLITCONFIG. CHROMEOS_KERNEL_CONFIG is set relative
469 # to the root of the kernel source tree.
470 local config
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700471 local cfgarch="$(get_build_arch)"
472
Doug Andersonf291dba2012-01-19 14:26:10 -0800473 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
Chris Masonef888c382013-03-19 14:19:41 -0700474 case ${CHROMEOS_KERNEL_CONFIG} in
475 /*)
476 config="${CHROMEOS_KERNEL_CONFIG}"
477 ;;
478 *)
479 config="${S}/${CHROMEOS_KERNEL_CONFIG}"
480 ;;
481 esac
Doug Andersonf291dba2012-01-19 14:26:10 -0800482 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700483 config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"}
Doug Andersonf291dba2012-01-19 14:26:10 -0800484 fi
485
486 elog "Using kernel config: ${config}"
487
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400488 # Keep a handle on the old .config in case it hasn't changed. This way
489 # we can keep the old timestamp which will avoid regenerating stuff that
490 # hasn't actually changed.
491 local temp_config="${T}/old-kernel-config"
492 if [[ -e $(get_build_cfg) ]] ; then
493 cp -a "$(get_build_cfg)" "${temp_config}"
494 else
495 rm -f "${temp_config}"
496 fi
497
Doug Andersonf291dba2012-01-19 14:26:10 -0800498 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
499 cp -f "${config}" "$(get_build_cfg)" || die
500 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700501 if [ -e chromeos/scripts/prepareconfig ] ; then
502 chromeos/scripts/prepareconfig ${config} \
503 "$(get_build_cfg)" || die
504 else
505 config="$(defconfig_dir)/${cfgarch}_defconfig"
506 ewarn "Can't prepareconfig, falling back to default " \
507 "${config}"
508 cp "${config}" "$(get_build_cfg)" || die
509 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800510 fi
511
512 local fragment
513 for fragment in ${CONFIG_FRAGMENTS[@]}; do
514 use ${fragment} || continue
515
516 local msg="${fragment}_desc"
517 local config="${fragment}_config"
518 elog " - adding ${!msg} config"
Paul Stewart23ead5f2013-04-24 22:32:17 -0700519 local warning="${fragment}_warning"
520 local warning_msg="${!warning}"
521 if [[ -n "${warning_msg}" ]] ; then
522 ewarn "${warning_msg}"
523 fi
Doug Anderson010887c2012-02-04 22:42:54 -0800524
525 echo "${!config}" | \
526 sed -e "s|%ROOT%|${ROOT}|g" \
527 >> "$(get_build_cfg)" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800528 done
529
530 # Use default for any options not explitly set in splitconfig
531 yes "" | kmake oldconfig
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400532
533 # Restore the old config if it is unchanged.
534 if cmp -s "$(get_build_cfg)" "${temp_config}" ; then
535 touch -r "${temp_config}" "$(get_build_cfg)"
536 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800537}
538
Doug Andersonf2bb2882012-12-06 15:56:21 -0800539# @FUNCTION: get_dtb_name
540# @USAGE: <dtb_dir>
541# @DESCRIPTION:
542# Get the name(s) of the device tree binary file(s) to include.
543
Olof Johanssonb62cf892012-04-27 14:50:24 -0700544get_dtb_name() {
Doug Andersonf2bb2882012-12-06 15:56:21 -0800545 local dtb_dir=${1}
Doug Andersonf291dba2012-01-19 14:26:10 -0800546 local board_with_variant=$(get_current_board_with_variant)
547
548 # Do a simple mapping for device trees whose names don't match
549 # the board_with_variant format; default to just the
550 # board_with_variant format.
551 case "${board_with_variant}" in
552 (tegra2_dev-board)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700553 echo tegra-harmony.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800554 ;;
555 (tegra2_seaboard)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700556 echo tegra-seaboard.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800557 ;;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700558 tegra*)
559 echo ${board_with_variant}.dtb
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700560 ;;
Doug Andersonf291dba2012-01-19 14:26:10 -0800561 *)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700562 local f
Doug Andersonf2bb2882012-12-06 15:56:21 -0800563 for f in ${dtb_dir}/*.dtb ; do
Olof Johanssonb62cf892012-04-27 14:50:24 -0700564 basename ${f}
565 done
Doug Andersonf291dba2012-01-19 14:26:10 -0800566 ;;
567 esac
568}
569
570cros-kernel2_src_compile() {
Chris Masone6e9b8212013-01-14 11:03:02 -0800571 local build_targets=() # use make default target
Doug Andersonf291dba2012-01-19 14:26:10 -0800572 if use arm; then
Chris Masone6e9b8212013-01-14 11:03:02 -0800573 build_targets=(
Doug Andersonf099c852013-06-24 16:26:43 -0700574 $(usex device_tree 'zImage dtbs' uImage)
Chris Masone6e9b8212013-01-14 11:03:02 -0800575 $(cros_chkconfig_present MODULES && echo "modules")
576 )
Doug Andersonf291dba2012-01-19 14:26:10 -0800577 fi
578
Simon Que715e54f32012-12-20 15:53:13 -0800579 local src_dir="$(cros-workon_get_build_dir)/source"
580 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
581 SMATCH_ERROR_FILE="${src_dir}/chromeos/check/smatch_errors.log"
582
Simon Que6324b6f2013-02-01 14:56:05 -0800583 if use test && [[ -e "${SMATCH_ERROR_FILE}" ]]; then
Simon Que715e54f32012-12-20 15:53:13 -0800584 local make_check_cmd="smatch -p=kernel"
585 local test_options=(
586 CHECK="${make_check_cmd}"
587 C=1
588 )
589 SMATCH_LOG_FILE="$(cros-workon_get_build_dir)/make.log"
590
591 # The path names in the log file are build-dependent. Strip out
592 # the part of the path before "kernel/files" and retains what
593 # comes after it: the file, line number, and error message.
Chris Masone6e9b8212013-01-14 11:03:02 -0800594 kmake -k ${build_targets[@]} "${test_options[@]}" |& \
Simon Que715e54f32012-12-20 15:53:13 -0800595 tee "${SMATCH_LOG_FILE}"
596 else
Chris Masone6e9b8212013-01-14 11:03:02 -0800597 kmake -k ${build_targets[@]}
Simon Que715e54f32012-12-20 15:53:13 -0800598 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800599}
600
Simon Que715e54f32012-12-20 15:53:13 -0800601cros-kernel2_src_test() {
Simon Que715e54f32012-12-20 15:53:13 -0800602 [[ -e ${SMATCH_ERROR_FILE} ]] || \
603 die "smatch whitelist file ${SMATCH_ERROR_FILE} not found!"
604 [[ -e ${SMATCH_LOG_FILE} ]] || \
605 die "Log file from src_compile() ${SMATCH_LOG_FILE} not found!"
606
Paul Taysom98a54362013-06-12 16:30:25 -0700607 local prefix="$(realpath "${S}")/"
608 grep -w error: "${SMATCH_LOG_FILE}" | grep -o "${prefix}.*" \
609 | sed s:"${prefix}"::g > "${SMATCH_LOG_FILE}.errors"
Simon Que715e54f32012-12-20 15:53:13 -0800610 local num_errors=$(wc -l < "${SMATCH_LOG_FILE}.errors")
611 local num_warnings=$(egrep -wc "warn:|warning:" "${SMATCH_LOG_FILE}")
612 einfo "smatch found ${num_errors} errors and ${num_warnings} warnings."
613
614 # Create a version of the error database that doesn't have line numbers,
615 # since line numbers will shift as code is added or removed.
616 local build_dir="$(cros-workon_get_build_dir)"
617 local no_line_numbers_file="${build_dir}/no_line_numbers.log"
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800618 sed -r -e "s/(:[0-9]+){1,2}//" \
619 -e "s/\(see line [0-9]+\)//" \
620 "${SMATCH_ERROR_FILE}" > "${no_line_numbers_file}"
Simon Que715e54f32012-12-20 15:53:13 -0800621
622 # For every smatch error that came up during the build, check if it is
623 # in the error database file.
624 local num_unknown_errors=0
625 local line=""
626 while read line; do
Simon Quefc5fc9d2013-01-28 15:19:38 -0800627 local no_line_num=$(echo "${line}" | \
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800628 sed -r -e "s/(:[0-9]+){1,2}//" \
629 -e "s/\(see line [0-9]+\)//")
Simon Que715e54f32012-12-20 15:53:13 -0800630 if ! fgrep -q "${no_line_num}" "${no_line_numbers_file}"; then
631 eerror "Non-whitelisted error found: \"${line}\""
632 : $(( ++num_unknown_errors ))
633 fi
634 done < "${SMATCH_LOG_FILE}.errors"
635
636 [[ ${num_unknown_errors} -eq 0 ]] || \
637 die "smatch found ${num_unknown_errors} unknown errors."
638}
639
Doug Andersonf291dba2012-01-19 14:26:10 -0800640cros-kernel2_src_install() {
Doug Andersone3a867e2013-06-24 16:26:43 -0700641 local build_targets=(
642 install
643 firmware_install
644 $(cros_chkconfig_present MODULES && echo "modules_install")
645 )
646
Doug Andersonf291dba2012-01-19 14:26:10 -0800647 dodir /boot
Doug Andersone3a867e2013-06-24 16:26:43 -0700648 kmake INSTALL_PATH="${D}/boot" INSTALL_MOD_PATH="${D}" \
649 "${build_targets[@]}"
Doug Andersonf291dba2012-01-19 14:26:10 -0800650
Josh Triplett6df77a72013-04-26 17:25:37 -0700651 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800652 if use arm; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400653 local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot"
Doug Andersonf291dba2012-01-19 14:26:10 -0800654 local kernel_bin="${D}/boot/vmlinuz-${version}"
655 local zimage_bin="${D}/boot/zImage-${version}"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800656 local dtb_dir="${boot_dir}"
657
658 # Newer kernels (after linux-next 12/3/12) put dtbs in the dts
659 # dir. Use that if we we find no dtbs directly in boot_dir.
660 # Note that we try boot_dir first since the newer kernel will
661 # actually rm ${boot_dir}/*.dtb so we'll have no stale files.
662 if ! ls "${dtb_dir}"/*.dtb &> /dev/null; then
663 dtb_dir="${boot_dir}/dts"
664 fi
665
Doug Andersonf291dba2012-01-19 14:26:10 -0800666 if use device_tree; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400667 local its_script="$(cros-workon_get_build_dir)/its_script"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800668 emit_its_script "${its_script}" "${boot_dir}" \
669 "${dtb_dir}" $(get_dtb_name "${dtb_dir}")
Andrew Chewa0695422013-03-19 16:39:58 -0700670 mkimage -D "-I dts -O dtb -p 512" -f "${its_script}" "${kernel_bin}" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800671 else
672 cp -a "${boot_dir}/uImage" "${kernel_bin}" || die
673 fi
674 cp -a "${boot_dir}/zImage" "${zimage_bin}" || die
675
676 # TODO(vbendeb): remove the below .uimg link creation code
677 # after the build scripts have been modified to use the base
678 # image name.
679 cd $(dirname "${kernel_bin}")
680 ln -sf $(basename "${kernel_bin}") vmlinux.uimg || die
681 ln -sf $(basename "${zimage_bin}") zImage || die
682 fi
683 if [ ! -e "${D}/boot/vmlinuz" ]; then
684 ln -sf "vmlinuz-${version}" "${D}/boot/vmlinuz" || die
685 fi
686
Vic Yang40fff212012-05-14 10:43:11 +0800687 # Check the size of kernel image and issue warning when image size is near
Vic Yang9aabf9c2013-01-23 20:47:59 +0800688 # the limit. For factory install initramfs, we don't care about kernel
689 # size limit as the image is downloaded over network.
Vic Yang40fff212012-05-14 10:43:11 +0800690 local kernel_image_size=$(stat -c '%s' -L "${D}"/boot/vmlinuz)
691 einfo "Kernel image size is ${kernel_image_size} bytes."
Vic Yang9aabf9c2013-01-23 20:47:59 +0800692 if use netboot_ramfs; then
693 # No need to check kernel image size.
694 true
695 elif [[ ${kernel_image_size} -gt $((8 * 1024 * 1024)) ]]; then
Olof Johanssoncbbe8872012-07-30 08:43:31 -0700696 die "Kernel image is larger than 8 MB."
697 elif [[ ${kernel_image_size} -gt $((7 * 1024 * 1024)) ]]; then
698 ewarn "Kernel image is larger than 7 MB. Limit is 8 MB."
Vic Yang40fff212012-05-14 10:43:11 +0800699 fi
700
Doug Andersonf291dba2012-01-19 14:26:10 -0800701 # Install uncompressed kernel for debugging purposes.
702 insinto /usr/lib/debug/boot
Mike Frysinger833d5f72012-08-07 18:11:59 -0400703 doins "$(cros-workon_get_build_dir)/vmlinux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800704
705 if use kernel_sources; then
706 install_kernel_sources
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500707 else
708 dosym "$(cros-workon_get_build_dir)" "/usr/src/linux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800709 fi
710}
711
Simon Que715e54f32012-12-20 15:53:13 -0800712EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install