blob: bfd7e92525b987538741587398e8845efa0042af [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
Doug Andersonf291dba2012-01-19 14:26:10 -080035 fbconsole
Ben Chane0654d22012-05-12 00:09:53 -070036 gdmwimax
Ben Chana179ebb2012-10-11 01:02:35 -070037 gobi
Doug Andersonf291dba2012-01-19 14:26:10 -080038 highmem
Vic Yang1541a702013-01-10 17:36:06 +080039 i2cdev
Doug Andersonf291dba2012-01-19 14:26:10 -080040 initramfs
Ronald G. Minnich6d888d42012-02-16 13:45:58 -080041 kvm
Vic Yang9aabf9c2013-01-23 20:47:59 +080042 netboot_ramfs
Doug Andersonf291dba2012-01-19 14:26:10 -080043 nfs
44 pcserial
Ben Chana179ebb2012-10-11 01:02:35 -070045 qmi
Dave Parker9fb68c92012-05-04 10:34:00 -070046 realtekpstor
Vic Yange0d659e2013-01-22 21:44:41 +080047 samsung_serial
Doug Andersonf291dba2012-01-19 14:26:10 -080048 systemtap
Vic Yange0d659e2013-01-22 21:44:41 +080049 tpm
Vic Yang7cc29a92012-05-18 14:12:10 +080050 vfat
Paul Stewart23ead5f2013-04-24 22:32:17 -070051 wifi_testbed_ap
Olof Johansson7921a5b2013-05-15 13:36:34 -070052 wireless34
Mike Frysinger34a55122013-02-05 14:01:39 -050053 x32
Doug Andersonf291dba2012-01-19 14:26:10 -080054)
55
56blkdevram_desc="ram block device"
57blkdevram_config="
58CONFIG_BLK_DEV_RAM=y
59CONFIG_BLK_DEV_RAM_COUNT=16
60CONFIG_BLK_DEV_RAM_SIZE=16384
61"
62
Dylan Reidf0666ff2012-07-01 21:42:38 -070063ca0132_desc="CA0132 ALSA codec"
64ca0132_config="
65CONFIG_SND_HDA_CODEC_CA0132=y
Chih-Chung Chang2306b492012-09-04 19:52:18 +080066CONFIG_SND_HDA_DSP_LOADER=y
Dylan Reidf0666ff2012-07-01 21:42:38 -070067"
68
Micah Catlin0dc2b972012-08-01 17:44:24 -070069cifs_desc="Samba/CIFS Support"
70cifs_config="
71CONFIG_CIFS=m
72"
73
Doug Andersonf291dba2012-01-19 14:26:10 -080074fbconsole_desc="framebuffer console"
75fbconsole_config="
76CONFIG_FRAMEBUFFER_CONSOLE=y
77"
78
Ben Chane0654d22012-05-12 00:09:53 -070079gdmwimax_desc="GCT GDM72xx WiMAX support"
80gdmwimax_config="
81CONFIG_WIMAX_GDM72XX=m
Ben Chane0654d22012-05-12 00:09:53 -070082CONFIG_WIMAX_GDM72XX_USB=y
83CONFIG_WIMAX_GDM72XX_USB_PM=y
84"
85
Ben Chana179ebb2012-10-11 01:02:35 -070086gobi_desc="Qualcomm Gobi modem driver"
87gobi_config="
88CONFIG_USB_NET_GOBI=m
89"
90
Doug Andersonf291dba2012-01-19 14:26:10 -080091highmem_desc="highmem"
92highmem_config="
93CONFIG_HIGHMEM64G=y
94"
95
Vic Yang1541a702013-01-10 17:36:06 +080096i2cdev_desc="I2C device interface"
97i2cdev_config="
98CONFIG_I2C_CHARDEV=y
99"
100
Vic Yange0d659e2013-01-22 21:44:41 +0800101tpm_desc="TPM support"
102tpm_config="
103CONFIG_TCG_TPM=y
104CONFIG_TCG_TIS=y
105"
106
Vic Yang9aabf9c2013-01-23 20:47:59 +0800107initramfs_desc="Initramfs for factory install shim and recovery image"
108initramfs_config='
109CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/initramfs.cpio.xz"
Anush Elangovanf9b66d92012-12-20 12:16:15 -0800110CONFIG_INITRAMFS_COMPRESSION_XZ=y
Vic Yang9aabf9c2013-01-23 20:47:59 +0800111'
112
113netboot_ramfs_desc="Network boot install initramfs"
114netboot_ramfs_config='
115CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/netboot_ramfs.cpio.xz"
116CONFIG_INITRAMFS_COMPRESSION_XZ=y
117'
Vic Yang7cc29a92012-05-18 14:12:10 +0800118
119vfat_desc="vfat"
120vfat_config="
Doug Andersonf291dba2012-01-19 14:26:10 -0800121CONFIG_NLS_CODEPAGE_437=y
122CONFIG_NLS_ISO8859_1=y
123CONFIG_FAT_FS=y
124CONFIG_VFAT_FS=y
125"
126
Ronald G. Minnich6d888d42012-02-16 13:45:58 -0800127kvm_desc="KVM"
128kvm_config="
129CONFIG_HAVE_KVM=y
130CONFIG_HAVE_KVM_IRQCHIP=y
131CONFIG_HAVE_KVM_EVENTFD=y
132CONFIG_KVM_APIC_ARCHITECTURE=y
133CONFIG_KVM_MMIO=y
134CONFIG_KVM_ASYNC_PF=y
135CONFIG_KVM=m
136CONFIG_KVM_INTEL=m
137# CONFIG_KVM_AMD is not set
138# CONFIG_KVM_MMU_AUDIT is not set
139CONFIG_VIRTIO=m
140CONFIG_VIRTIO_BLK=m
141CONFIG_VIRTIO_NET=m
142CONFIG_VIRTIO_CONSOLE=m
143CONFIG_VIRTIO_RING=m
144CONFIG_VIRTIO_PCI=m
145"
146
Doug Andersonf291dba2012-01-19 14:26:10 -0800147nfs_desc="NFS"
148nfs_config="
149CONFIG_USB_NET_AX8817X=y
150CONFIG_DNOTIFY=y
151CONFIG_DNS_RESOLVER=y
152CONFIG_LOCKD=y
153CONFIG_LOCKD_V4=y
154CONFIG_NETWORK_FILESYSTEMS=y
155CONFIG_NFSD=m
156CONFIG_NFSD_V3=y
157CONFIG_NFSD_V4=y
158CONFIG_NFS_COMMON=y
159CONFIG_NFS_FS=y
160CONFIG_NFS_USE_KERNEL_DNS=y
161CONFIG_NFS_V3=y
162CONFIG_NFS_V4=y
163CONFIG_ROOT_NFS=y
164CONFIG_RPCSEC_GSS_KRB5=y
165CONFIG_SUNRPC=y
166CONFIG_SUNRPC_GSS=y
167CONFIG_USB_USBNET=y
168CONFIG_IP_PNP=y
169CONFIG_IP_PNP_DHCP=y
170"
171
172pcserial_desc="PC serial"
173pcserial_config="
174CONFIG_SERIAL_8250=y
175CONFIG_SERIAL_8250_CONSOLE=y
176CONFIG_SERIAL_8250_PCI=y
177CONFIG_PARPORT=y
178CONFIG_PARPORT_PC=y
179CONFIG_PARPORT_SERIAL=y
180"
181
Ben Chana179ebb2012-10-11 01:02:35 -0700182qmi_desc="QMI WWAN driver"
183qmi_config="
184CONFIG_USB_NET_QMI_WWAN=m
185"
186
Olof Johansson08268b0c2012-08-01 00:12:00 -0700187samsung_serial_desc="Samsung serialport"
188samsung_serial_config="
189CONFIG_SERIAL_SAMSUNG=y
190CONFIG_SERIAL_SAMSUNG_CONSOLE=y
191"
192
Dave Parker9fb68c92012-05-04 10:34:00 -0700193realtekpstor_desc="Realtek PCI card reader"
194realtekpstor_config="
195CONFIG_RTS_PSTOR=m
196"
197
Doug Andersonf291dba2012-01-19 14:26:10 -0800198systemtap_desc="systemtap support"
199systemtap_config="
200CONFIG_KPROBES=y
201CONFIG_DEBUG_INFO=y
202"
203
Paul Stewart23ead5f2013-04-24 22:32:17 -0700204wifi_testbed_ap_desc="Defer ath9k EEPROM regulatory"
205wifi_testbed_ap_warning="
206Don't use the wifi_testbed_ap flag unless you know what you are doing!
207An image built with this flag set must never be run outside a
208sealed RF chamber!
209"
210wifi_testbed_ap_config="
211CONFIG_ATH_DEFER_EEPROM_REGULATORY=y
212"
213
Mike Frysinger34a55122013-02-05 14:01:39 -0500214x32_desc="x32 ABI support"
215x32_config="
216CONFIG_X86_X32=y
217"
218
Olof Johansson7921a5b2013-05-15 13:36:34 -0700219wireless34_desc="Wireless 3.4 stack"
220wireless34_config="
221CONFIG_ATH9K_BTCOEX=m
222CONFIG_ATH9K_BTCOEX_COMMON=m
223CONFIG_ATH9K_BTCOEX_HW=m
224"
225
Doug Andersonf291dba2012-01-19 14:26:10 -0800226# Add all config fragments as off by default
227IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}"
Vic Yang9aabf9c2013-01-23 20:47:59 +0800228REQUIRED_USE="
229 initramfs? ( !netboot_ramfs )
230 netboot_ramfs? ( !initramfs )
231 initramfs? ( i2cdev tpm )
232 netboot_ramfs? ( i2cdev tpm )
233"
Doug Andersonf291dba2012-01-19 14:26:10 -0800234
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700235# If an overlay has eclass overrides, but doesn't actually override this
236# eclass, we'll have ECLASSDIR pointing to the active overlay's
237# eclass/ dir, but this eclass is still in the main chromiumos tree. So
238# add a check to locate the cros-kernel/ regardless of what's going on.
239ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
240defconfig_dir() {
241 local d="${ECLASSDIR}/cros-kernel"
242 if [[ ! -d ${d} ]] ; then
243 d="${ECLASSDIR_LOCAL}/cros-kernel"
244 fi
245 echo "${d}"
246}
247
Josh Triplett6df77a72013-04-26 17:25:37 -0700248# @FUNCTION: kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500249# @DESCRIPTION:
250# Returns the current compiled kernel version.
251# Note: Only valid after src_configure has finished running.
Josh Triplett6df77a72013-04-26 17:25:37 -0700252kernelrelease() {
253 kmake -s --no-print-directory kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500254}
255
Doug Andersonf291dba2012-01-19 14:26:10 -0800256# @FUNCTION: install_kernel_sources
257# @DESCRIPTION:
258# Installs the kernel sources into ${D}/usr/src/${P} and fixes symlinks.
259# The package must have already installed a directory under ${D}/lib/modules.
260install_kernel_sources() {
Josh Triplett6df77a72013-04-26 17:25:37 -0700261 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800262 local dest_modules_dir=lib/modules/${version}
263 local dest_source_dir=usr/src/${P}
264 local dest_build_dir=${dest_source_dir}/build
265
266 # Fix symlinks in lib/modules
267 ln -sfvT "../../../${dest_build_dir}" \
268 "${D}/${dest_modules_dir}/build" || die
269 ln -sfvT "../../../${dest_source_dir}" \
270 "${D}/${dest_modules_dir}/source" || die
271
272 einfo "Installing kernel source tree"
273 dodir "${dest_source_dir}"
274 local f
275 for f in "${S}"/*; do
276 [[ "$f" == "${S}/build" ]] && continue
277 cp -pPR "${f}" "${D}/${dest_source_dir}" ||
278 die "Failed to copy kernel source tree"
279 done
280
281 dosym "${P}" "/usr/src/linux"
282
283 einfo "Installing kernel build tree"
284 dodir "${dest_build_dir}"
Mike Frysinger833d5f72012-08-07 18:11:59 -0400285 cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \
Doug Andersonf291dba2012-01-19 14:26:10 -0800286 "${D}/${dest_build_dir}" || die
287
288 # Modify Makefile to use the ROOT environment variable if defined.
289 # This path needs to be absolute so that the build directory will
290 # still work if copied elsewhere.
291 sed -i -e "s@${S}@\$(ROOT)/${dest_source_dir}@" \
292 "${D}/${dest_build_dir}/Makefile" || die
293}
294
Doug Andersonf291dba2012-01-19 14:26:10 -0800295get_build_cfg() {
Mike Frysinger833d5f72012-08-07 18:11:59 -0400296 echo "$(cros-workon_get_build_dir)/.config"
Doug Andersonf291dba2012-01-19 14:26:10 -0800297}
298
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700299get_build_arch() {
300 if [ "${ARCH}" = "arm" ] ; then
301 case "${CHROMEOS_KERNEL_SPLITCONFIG}" in
302 *tegra*)
303 echo "tegra"
304 ;;
305 *exynos*)
306 echo "exynos5"
307 ;;
308 *)
309 echo "arm"
310 ;;
311 esac
312 else
313 echo $(tc-arch-kernel)
314 fi
315}
316
Chris Masone6e9b8212013-01-14 11:03:02 -0800317# @FUNCTION: cros_chkconfig_present
318# @USAGE: <option to check config for>
319# @DESCRIPTION:
320# Returns success of the provided option is present in the build config.
321cros_chkconfig_present() {
322 local config=$1
323 grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)"
324}
325
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400326cros-kernel2_pkg_setup() {
Simon Que715e54f32012-12-20 15:53:13 -0800327 # This is needed for running src_test(). The kernel code will need to
328 # be rebuilt with `make check`. If incremental build were enabled,
329 # `make check` would have nothing left to build.
Simon Que6324b6f2013-02-01 14:56:05 -0800330 use test && export CROS_WORKON_INCREMENTAL_BUILD=0
Mike Frysinger833d5f72012-08-07 18:11:59 -0400331 cros-workon_pkg_setup
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500332 linux-info_pkg_setup
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400333}
334
Olof Johanssonb62cf892012-04-27 14:50:24 -0700335# @FUNCTION: emit_its_script
Doug Andersonf2bb2882012-12-06 15:56:21 -0800336# @USAGE: <output file> <boot_dir> <dtb_dir> <device trees>
Olof Johanssonb62cf892012-04-27 14:50:24 -0700337# @DESCRIPTION:
338# Emits the its script used to build the u-boot fitImage kernel binary
339# that contains the kernel as well as device trees used when booting
340# it.
341
342emit_its_script() {
343 local iter=1
344 local its_out=${1}
345 shift
Doug Andersonf2bb2882012-12-06 15:56:21 -0800346 local boot_dir=${1}
347 shift
348 local dtb_dir=${1}
349 shift
Olof Johanssonb62cf892012-04-27 14:50:24 -0700350 cat > "${its_out}" <<-EOF || die
351 /dts-v1/;
352
353 / {
354 description = "Chrome OS kernel image with one or more FDT blobs";
355 #address-cells = <1>;
356
357 images {
358 kernel@1 {
359 data = /incbin/("${boot_dir}/zImage");
360 type = "$(get_kernel_type)";
361 arch = "arm";
362 os = "linux";
363 compression = "none";
364 load = <$(get_load_addr)>;
365 entry = <$(get_load_addr)>;
366 };
367 EOF
368
369 local dtb
370 for dtb in "$@" ; do
371 cat >> "${its_out}" <<-EOF || die
372 fdt@${iter} {
373 description = "$(basename ${dtb})";
Doug Andersonf2bb2882012-12-06 15:56:21 -0800374 data = /incbin/("${dtb_dir}/${dtb}");
Olof Johanssonb62cf892012-04-27 14:50:24 -0700375 type = "flat_dt";
376 arch = "arm";
377 compression = "none";
378 hash@1 {
379 algo = "sha1";
380 };
381 };
382 EOF
383 ((++iter))
384 done
385
386 cat <<-EOF >>"${its_script}"
387 };
388 configurations {
389 default = "conf@1";
390 EOF
391
392 local i
393 for i in $(seq 1 $((iter-1))) ; do
394 cat >> "${its_out}" <<-EOF || die
395 conf@${i} {
396 kernel = "kernel@1";
397 fdt = "fdt@${i}";
398 };
399 EOF
400 done
401
402 echo " };" >> "${its_out}"
403 echo "};" >> "${its_out}"
404}
405
Doug Andersonf291dba2012-01-19 14:26:10 -0800406kmake() {
407 # Allow override of kernel arch.
408 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
409
410 local cross=${CHOST}-
Olof Johanssonc0f8a5d2013-04-11 18:36:40 -0700411
412 if use wireless34 ; then
413 set -- "$@" WIFIVERSION="-3.4"
414 fi
415
Doug Andersonf291dba2012-01-19 14:26:10 -0800416 # Hack for using 64-bit kernel with 32-bit user-space
Mike Frysinger0f008b22013-03-14 11:54:13 -0400417 if [[ "${ARCH}" == "x86" && "${kernel_arch}" == "x86_64" ]]; then
Sonny Rao5ebd89f2012-08-05 20:31:23 -0700418 cross=x86_64-cros-linux-gnu-
Doug Andersonf291dba2012-01-19 14:26:10 -0800419 else
420 # TODO(raymes): Force GNU ld over gold. There are still some
421 # gold issues to iron out. See: 13209.
422 tc-export LD CC CXX
423
424 set -- \
Mike Frysinger0f008b22013-03-14 11:54:13 -0400425 LD="$(get_binutils_path_ld)/ld $(usex x32 '-m elf_x86_64' '')" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800426 CC="${CC} -B$(get_binutils_path_ld)" \
427 CXX="${CXX} -B$(get_binutils_path_ld)" \
428 "$@"
429 fi
430
Mike Frysingera8ef3cd2012-11-01 18:42:18 -0400431 cw_emake \
Doug Andersonf291dba2012-01-19 14:26:10 -0800432 ARCH=${kernel_arch} \
433 LDFLAGS="$(raw-ldflags)" \
434 CROSS_COMPILE="${cross}" \
Mike Frysinger833d5f72012-08-07 18:11:59 -0400435 O="$(cros-workon_get_build_dir)" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800436 "$@"
437}
438
Josh Triplett4c035592012-12-05 15:46:46 -0800439cros-kernel2_src_prepare() {
440 cros-workon_src_prepare
441}
442
Doug Andersonf291dba2012-01-19 14:26:10 -0800443cros-kernel2_src_configure() {
Doug Andersonf291dba2012-01-19 14:26:10 -0800444 # Use a single or split kernel config as specified in the board or variant
445 # make.conf overlay. Default to the arch specific split config if an
446 # overlay or variant does not set either CHROMEOS_KERNEL_CONFIG or
447 # CHROMEOS_KERNEL_SPLITCONFIG. CHROMEOS_KERNEL_CONFIG is set relative
448 # to the root of the kernel source tree.
449 local config
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700450 local cfgarch="$(get_build_arch)"
451
Doug Andersonf291dba2012-01-19 14:26:10 -0800452 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
Chris Masonef888c382013-03-19 14:19:41 -0700453 case ${CHROMEOS_KERNEL_CONFIG} in
454 /*)
455 config="${CHROMEOS_KERNEL_CONFIG}"
456 ;;
457 *)
458 config="${S}/${CHROMEOS_KERNEL_CONFIG}"
459 ;;
460 esac
Doug Andersonf291dba2012-01-19 14:26:10 -0800461 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700462 config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"}
Doug Andersonf291dba2012-01-19 14:26:10 -0800463 fi
464
465 elog "Using kernel config: ${config}"
466
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400467 # Keep a handle on the old .config in case it hasn't changed. This way
468 # we can keep the old timestamp which will avoid regenerating stuff that
469 # hasn't actually changed.
470 local temp_config="${T}/old-kernel-config"
471 if [[ -e $(get_build_cfg) ]] ; then
472 cp -a "$(get_build_cfg)" "${temp_config}"
473 else
474 rm -f "${temp_config}"
475 fi
476
Doug Andersonf291dba2012-01-19 14:26:10 -0800477 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
478 cp -f "${config}" "$(get_build_cfg)" || die
479 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700480 if [ -e chromeos/scripts/prepareconfig ] ; then
481 chromeos/scripts/prepareconfig ${config} \
482 "$(get_build_cfg)" || die
483 else
484 config="$(defconfig_dir)/${cfgarch}_defconfig"
485 ewarn "Can't prepareconfig, falling back to default " \
486 "${config}"
487 cp "${config}" "$(get_build_cfg)" || die
488 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800489 fi
490
491 local fragment
492 for fragment in ${CONFIG_FRAGMENTS[@]}; do
493 use ${fragment} || continue
494
495 local msg="${fragment}_desc"
496 local config="${fragment}_config"
497 elog " - adding ${!msg} config"
Paul Stewart23ead5f2013-04-24 22:32:17 -0700498 local warning="${fragment}_warning"
499 local warning_msg="${!warning}"
500 if [[ -n "${warning_msg}" ]] ; then
501 ewarn "${warning_msg}"
502 fi
Doug Anderson010887c2012-02-04 22:42:54 -0800503
504 echo "${!config}" | \
505 sed -e "s|%ROOT%|${ROOT}|g" \
506 >> "$(get_build_cfg)" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800507 done
508
509 # Use default for any options not explitly set in splitconfig
510 yes "" | kmake oldconfig
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400511
512 # Restore the old config if it is unchanged.
513 if cmp -s "$(get_build_cfg)" "${temp_config}" ; then
514 touch -r "${temp_config}" "$(get_build_cfg)"
515 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800516}
517
Doug Andersonf2bb2882012-12-06 15:56:21 -0800518# @FUNCTION: get_dtb_name
519# @USAGE: <dtb_dir>
520# @DESCRIPTION:
521# Get the name(s) of the device tree binary file(s) to include.
522
Olof Johanssonb62cf892012-04-27 14:50:24 -0700523get_dtb_name() {
Doug Andersonf2bb2882012-12-06 15:56:21 -0800524 local dtb_dir=${1}
Doug Andersonf291dba2012-01-19 14:26:10 -0800525 local board_with_variant=$(get_current_board_with_variant)
526
527 # Do a simple mapping for device trees whose names don't match
528 # the board_with_variant format; default to just the
529 # board_with_variant format.
530 case "${board_with_variant}" in
531 (tegra2_dev-board)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700532 echo tegra-harmony.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800533 ;;
534 (tegra2_seaboard)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700535 echo tegra-seaboard.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800536 ;;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700537 tegra*)
538 echo ${board_with_variant}.dtb
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700539 ;;
Doug Andersonf291dba2012-01-19 14:26:10 -0800540 *)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700541 local f
Doug Andersonf2bb2882012-12-06 15:56:21 -0800542 for f in ${dtb_dir}/*.dtb ; do
Olof Johanssonb62cf892012-04-27 14:50:24 -0700543 basename ${f}
544 done
Doug Andersonf291dba2012-01-19 14:26:10 -0800545 ;;
546 esac
547}
548
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700549# All current tegra boards ship with an u-boot that won't allow
550# use of kernel_noload. Because of this, keep using the traditional
551# kernel type for those. This means kernel_type kernel and regular
552# load and entry point addresses.
553
554get_kernel_type() {
555 case "$(get_current_board_with_variant)" in
556 tegra*)
557 echo kernel
558 ;;
559 *)
560 echo kernel_noload
561 ;;
562 esac
563}
564
565get_load_addr() {
566 case "$(get_current_board_with_variant)" in
567 tegra*)
568 echo 0x03000000
569 ;;
570 *)
571 echo 0
572 ;;
573 esac
574}
575
Doug Andersonf291dba2012-01-19 14:26:10 -0800576cros-kernel2_src_compile() {
Chris Masone6e9b8212013-01-14 11:03:02 -0800577 local build_targets=() # use make default target
Doug Andersonf291dba2012-01-19 14:26:10 -0800578 if use arm; then
Chris Masone6e9b8212013-01-14 11:03:02 -0800579 build_targets=(
Olof Johanssond2242e12013-04-24 13:20:44 -0700580 $(use device_tree && echo "zImage")
Olof Johansson362863f2013-04-23 20:00:44 -0700581 $(use device_tree || echo "uImage")
Chris Masone6e9b8212013-01-14 11:03:02 -0800582 $(cros_chkconfig_present MODULES && echo "modules")
583 )
Doug Andersonf291dba2012-01-19 14:26:10 -0800584 fi
585
Simon Que715e54f32012-12-20 15:53:13 -0800586 local src_dir="$(cros-workon_get_build_dir)/source"
587 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
588 SMATCH_ERROR_FILE="${src_dir}/chromeos/check/smatch_errors.log"
589
Simon Que6324b6f2013-02-01 14:56:05 -0800590 if use test && [[ -e "${SMATCH_ERROR_FILE}" ]]; then
Simon Que715e54f32012-12-20 15:53:13 -0800591 local make_check_cmd="smatch -p=kernel"
592 local test_options=(
593 CHECK="${make_check_cmd}"
594 C=1
595 )
596 SMATCH_LOG_FILE="$(cros-workon_get_build_dir)/make.log"
597
598 # The path names in the log file are build-dependent. Strip out
599 # the part of the path before "kernel/files" and retains what
600 # comes after it: the file, line number, and error message.
Chris Masone6e9b8212013-01-14 11:03:02 -0800601 kmake -k ${build_targets[@]} "${test_options[@]}" |& \
Simon Que715e54f32012-12-20 15:53:13 -0800602 tee "${SMATCH_LOG_FILE}"
603 else
Chris Masone6e9b8212013-01-14 11:03:02 -0800604 kmake -k ${build_targets[@]}
Simon Que715e54f32012-12-20 15:53:13 -0800605 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800606
607 if use device_tree; then
Olof Johanssonb62cf892012-04-27 14:50:24 -0700608 kmake -k dtbs
Doug Andersonf291dba2012-01-19 14:26:10 -0800609 fi
610}
611
Simon Que715e54f32012-12-20 15:53:13 -0800612cros-kernel2_src_test() {
Simon Que715e54f32012-12-20 15:53:13 -0800613 [[ -e ${SMATCH_ERROR_FILE} ]] || \
614 die "smatch whitelist file ${SMATCH_ERROR_FILE} not found!"
615 [[ -e ${SMATCH_LOG_FILE} ]] || \
616 die "Log file from src_compile() ${SMATCH_LOG_FILE} not found!"
617
Simon Que4851c092013-01-16 12:04:06 -0800618 grep -w error: "${SMATCH_LOG_FILE}" | grep -o "kernel/files/.*" \
619 | sed s:"kernel/files/"::g > "${SMATCH_LOG_FILE}.errors"
Simon Que715e54f32012-12-20 15:53:13 -0800620 local num_errors=$(wc -l < "${SMATCH_LOG_FILE}.errors")
621 local num_warnings=$(egrep -wc "warn:|warning:" "${SMATCH_LOG_FILE}")
622 einfo "smatch found ${num_errors} errors and ${num_warnings} warnings."
623
624 # Create a version of the error database that doesn't have line numbers,
625 # since line numbers will shift as code is added or removed.
626 local build_dir="$(cros-workon_get_build_dir)"
627 local no_line_numbers_file="${build_dir}/no_line_numbers.log"
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800628 sed -r -e "s/(:[0-9]+){1,2}//" \
629 -e "s/\(see line [0-9]+\)//" \
630 "${SMATCH_ERROR_FILE}" > "${no_line_numbers_file}"
Simon Que715e54f32012-12-20 15:53:13 -0800631
632 # For every smatch error that came up during the build, check if it is
633 # in the error database file.
634 local num_unknown_errors=0
635 local line=""
636 while read line; do
Simon Quefc5fc9d2013-01-28 15:19:38 -0800637 local no_line_num=$(echo "${line}" | \
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800638 sed -r -e "s/(:[0-9]+){1,2}//" \
639 -e "s/\(see line [0-9]+\)//")
Simon Que715e54f32012-12-20 15:53:13 -0800640 if ! fgrep -q "${no_line_num}" "${no_line_numbers_file}"; then
641 eerror "Non-whitelisted error found: \"${line}\""
642 : $(( ++num_unknown_errors ))
643 fi
644 done < "${SMATCH_LOG_FILE}.errors"
645
646 [[ ${num_unknown_errors} -eq 0 ]] || \
647 die "smatch found ${num_unknown_errors} unknown errors."
648}
649
Doug Andersonf291dba2012-01-19 14:26:10 -0800650cros-kernel2_src_install() {
651 dodir /boot
652 kmake INSTALL_PATH="${D}/boot" install
Chris Masone6e9b8212013-01-14 11:03:02 -0800653 if cros_chkconfig_present MODULES; then
654 kmake INSTALL_MOD_PATH="${D}" modules_install
655 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800656 kmake INSTALL_MOD_PATH="${D}" firmware_install
657
Josh Triplett6df77a72013-04-26 17:25:37 -0700658 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800659 if use arm; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400660 local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot"
Doug Andersonf291dba2012-01-19 14:26:10 -0800661 local kernel_bin="${D}/boot/vmlinuz-${version}"
662 local zimage_bin="${D}/boot/zImage-${version}"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800663 local dtb_dir="${boot_dir}"
664
665 # Newer kernels (after linux-next 12/3/12) put dtbs in the dts
666 # dir. Use that if we we find no dtbs directly in boot_dir.
667 # Note that we try boot_dir first since the newer kernel will
668 # actually rm ${boot_dir}/*.dtb so we'll have no stale files.
669 if ! ls "${dtb_dir}"/*.dtb &> /dev/null; then
670 dtb_dir="${boot_dir}/dts"
671 fi
672
Doug Andersonf291dba2012-01-19 14:26:10 -0800673 if use device_tree; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400674 local its_script="$(cros-workon_get_build_dir)/its_script"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800675 emit_its_script "${its_script}" "${boot_dir}" \
676 "${dtb_dir}" $(get_dtb_name "${dtb_dir}")
Andrew Chewa0695422013-03-19 16:39:58 -0700677 mkimage -D "-I dts -O dtb -p 512" -f "${its_script}" "${kernel_bin}" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800678 else
679 cp -a "${boot_dir}/uImage" "${kernel_bin}" || die
680 fi
681 cp -a "${boot_dir}/zImage" "${zimage_bin}" || die
682
683 # TODO(vbendeb): remove the below .uimg link creation code
684 # after the build scripts have been modified to use the base
685 # image name.
686 cd $(dirname "${kernel_bin}")
687 ln -sf $(basename "${kernel_bin}") vmlinux.uimg || die
688 ln -sf $(basename "${zimage_bin}") zImage || die
689 fi
690 if [ ! -e "${D}/boot/vmlinuz" ]; then
691 ln -sf "vmlinuz-${version}" "${D}/boot/vmlinuz" || die
692 fi
693
Vic Yang40fff212012-05-14 10:43:11 +0800694 # Check the size of kernel image and issue warning when image size is near
Vic Yang9aabf9c2013-01-23 20:47:59 +0800695 # the limit. For factory install initramfs, we don't care about kernel
696 # size limit as the image is downloaded over network.
Vic Yang40fff212012-05-14 10:43:11 +0800697 local kernel_image_size=$(stat -c '%s' -L "${D}"/boot/vmlinuz)
698 einfo "Kernel image size is ${kernel_image_size} bytes."
Vic Yang9aabf9c2013-01-23 20:47:59 +0800699 if use netboot_ramfs; then
700 # No need to check kernel image size.
701 true
702 elif [[ ${kernel_image_size} -gt $((8 * 1024 * 1024)) ]]; then
Olof Johanssoncbbe8872012-07-30 08:43:31 -0700703 die "Kernel image is larger than 8 MB."
704 elif [[ ${kernel_image_size} -gt $((7 * 1024 * 1024)) ]]; then
705 ewarn "Kernel image is larger than 7 MB. Limit is 8 MB."
Vic Yang40fff212012-05-14 10:43:11 +0800706 fi
707
Doug Andersonf291dba2012-01-19 14:26:10 -0800708 # Install uncompressed kernel for debugging purposes.
709 insinto /usr/lib/debug/boot
Mike Frysinger833d5f72012-08-07 18:11:59 -0400710 doins "$(cros-workon_get_build_dir)/vmlinux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800711
712 if use kernel_sources; then
713 install_kernel_sources
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500714 else
715 dosym "$(cros-workon_get_build_dir)" "/usr/src/linux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800716 fi
717}
718
Simon Que715e54f32012-12-20 15:53:13 -0800719EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install