blob: 709fa06f1a932dcc83a87dbf5feb190aac90aad1 [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
Mike Frysinger34a55122013-02-05 14:01:39 -050052 x32
Doug Andersonf291dba2012-01-19 14:26:10 -080053)
54
55blkdevram_desc="ram block device"
56blkdevram_config="
57CONFIG_BLK_DEV_RAM=y
58CONFIG_BLK_DEV_RAM_COUNT=16
59CONFIG_BLK_DEV_RAM_SIZE=16384
60"
61
Dylan Reidf0666ff2012-07-01 21:42:38 -070062ca0132_desc="CA0132 ALSA codec"
63ca0132_config="
64CONFIG_SND_HDA_CODEC_CA0132=y
Chih-Chung Chang2306b492012-09-04 19:52:18 +080065CONFIG_SND_HDA_DSP_LOADER=y
Dylan Reidf0666ff2012-07-01 21:42:38 -070066"
67
Micah Catlin0dc2b972012-08-01 17:44:24 -070068cifs_desc="Samba/CIFS Support"
69cifs_config="
70CONFIG_CIFS=m
71"
72
Doug Andersonf291dba2012-01-19 14:26:10 -080073fbconsole_desc="framebuffer console"
74fbconsole_config="
75CONFIG_FRAMEBUFFER_CONSOLE=y
76"
77
Ben Chane0654d22012-05-12 00:09:53 -070078gdmwimax_desc="GCT GDM72xx WiMAX support"
79gdmwimax_config="
80CONFIG_WIMAX_GDM72XX=m
Ben Chane0654d22012-05-12 00:09:53 -070081CONFIG_WIMAX_GDM72XX_USB=y
82CONFIG_WIMAX_GDM72XX_USB_PM=y
83"
84
Ben Chana179ebb2012-10-11 01:02:35 -070085gobi_desc="Qualcomm Gobi modem driver"
86gobi_config="
87CONFIG_USB_NET_GOBI=m
88"
89
Doug Andersonf291dba2012-01-19 14:26:10 -080090highmem_desc="highmem"
91highmem_config="
92CONFIG_HIGHMEM64G=y
93"
94
Vic Yang1541a702013-01-10 17:36:06 +080095i2cdev_desc="I2C device interface"
96i2cdev_config="
97CONFIG_I2C_CHARDEV=y
98"
99
Vic Yange0d659e2013-01-22 21:44:41 +0800100tpm_desc="TPM support"
101tpm_config="
102CONFIG_TCG_TPM=y
103CONFIG_TCG_TIS=y
104"
105
Vic Yang9aabf9c2013-01-23 20:47:59 +0800106initramfs_desc="Initramfs for factory install shim and recovery image"
107initramfs_config='
108CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/initramfs.cpio.xz"
Anush Elangovanf9b66d92012-12-20 12:16:15 -0800109CONFIG_INITRAMFS_COMPRESSION_XZ=y
Vic Yang9aabf9c2013-01-23 20:47:59 +0800110'
111
112netboot_ramfs_desc="Network boot install initramfs"
113netboot_ramfs_config='
114CONFIG_INITRAMFS_SOURCE="%ROOT%/var/lib/misc/netboot_ramfs.cpio.xz"
115CONFIG_INITRAMFS_COMPRESSION_XZ=y
116'
Vic Yang7cc29a92012-05-18 14:12:10 +0800117
118vfat_desc="vfat"
119vfat_config="
Doug Andersonf291dba2012-01-19 14:26:10 -0800120CONFIG_NLS_CODEPAGE_437=y
121CONFIG_NLS_ISO8859_1=y
122CONFIG_FAT_FS=y
123CONFIG_VFAT_FS=y
124"
125
Ronald G. Minnich6d888d42012-02-16 13:45:58 -0800126kvm_desc="KVM"
127kvm_config="
128CONFIG_HAVE_KVM=y
129CONFIG_HAVE_KVM_IRQCHIP=y
130CONFIG_HAVE_KVM_EVENTFD=y
131CONFIG_KVM_APIC_ARCHITECTURE=y
132CONFIG_KVM_MMIO=y
133CONFIG_KVM_ASYNC_PF=y
134CONFIG_KVM=m
135CONFIG_KVM_INTEL=m
136# CONFIG_KVM_AMD is not set
137# CONFIG_KVM_MMU_AUDIT is not set
138CONFIG_VIRTIO=m
139CONFIG_VIRTIO_BLK=m
140CONFIG_VIRTIO_NET=m
141CONFIG_VIRTIO_CONSOLE=m
142CONFIG_VIRTIO_RING=m
143CONFIG_VIRTIO_PCI=m
144"
145
Doug Andersonf291dba2012-01-19 14:26:10 -0800146nfs_desc="NFS"
147nfs_config="
148CONFIG_USB_NET_AX8817X=y
149CONFIG_DNOTIFY=y
150CONFIG_DNS_RESOLVER=y
151CONFIG_LOCKD=y
152CONFIG_LOCKD_V4=y
153CONFIG_NETWORK_FILESYSTEMS=y
154CONFIG_NFSD=m
155CONFIG_NFSD_V3=y
156CONFIG_NFSD_V4=y
157CONFIG_NFS_COMMON=y
158CONFIG_NFS_FS=y
159CONFIG_NFS_USE_KERNEL_DNS=y
160CONFIG_NFS_V3=y
161CONFIG_NFS_V4=y
162CONFIG_ROOT_NFS=y
163CONFIG_RPCSEC_GSS_KRB5=y
164CONFIG_SUNRPC=y
165CONFIG_SUNRPC_GSS=y
166CONFIG_USB_USBNET=y
167CONFIG_IP_PNP=y
168CONFIG_IP_PNP_DHCP=y
169"
170
171pcserial_desc="PC serial"
172pcserial_config="
173CONFIG_SERIAL_8250=y
174CONFIG_SERIAL_8250_CONSOLE=y
175CONFIG_SERIAL_8250_PCI=y
176CONFIG_PARPORT=y
177CONFIG_PARPORT_PC=y
178CONFIG_PARPORT_SERIAL=y
179"
180
Ben Chana179ebb2012-10-11 01:02:35 -0700181qmi_desc="QMI WWAN driver"
182qmi_config="
183CONFIG_USB_NET_QMI_WWAN=m
184"
185
Olof Johansson08268b0c2012-08-01 00:12:00 -0700186samsung_serial_desc="Samsung serialport"
187samsung_serial_config="
188CONFIG_SERIAL_SAMSUNG=y
189CONFIG_SERIAL_SAMSUNG_CONSOLE=y
190"
191
Dave Parker9fb68c92012-05-04 10:34:00 -0700192realtekpstor_desc="Realtek PCI card reader"
193realtekpstor_config="
194CONFIG_RTS_PSTOR=m
195"
196
Doug Andersonf291dba2012-01-19 14:26:10 -0800197systemtap_desc="systemtap support"
198systemtap_config="
199CONFIG_KPROBES=y
200CONFIG_DEBUG_INFO=y
201"
202
Paul Stewart23ead5f2013-04-24 22:32:17 -0700203wifi_testbed_ap_desc="Defer ath9k EEPROM regulatory"
204wifi_testbed_ap_warning="
205Don't use the wifi_testbed_ap flag unless you know what you are doing!
206An image built with this flag set must never be run outside a
207sealed RF chamber!
208"
209wifi_testbed_ap_config="
210CONFIG_ATH_DEFER_EEPROM_REGULATORY=y
211"
212
Mike Frysinger34a55122013-02-05 14:01:39 -0500213x32_desc="x32 ABI support"
214x32_config="
215CONFIG_X86_X32=y
216"
217
Doug Andersonf291dba2012-01-19 14:26:10 -0800218# Add all config fragments as off by default
219IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}"
Vic Yang9aabf9c2013-01-23 20:47:59 +0800220REQUIRED_USE="
221 initramfs? ( !netboot_ramfs )
222 netboot_ramfs? ( !initramfs )
223 initramfs? ( i2cdev tpm )
224 netboot_ramfs? ( i2cdev tpm )
225"
Doug Andersonf291dba2012-01-19 14:26:10 -0800226
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700227# If an overlay has eclass overrides, but doesn't actually override this
228# eclass, we'll have ECLASSDIR pointing to the active overlay's
229# eclass/ dir, but this eclass is still in the main chromiumos tree. So
230# add a check to locate the cros-kernel/ regardless of what's going on.
231ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
232defconfig_dir() {
233 local d="${ECLASSDIR}/cros-kernel"
234 if [[ ! -d ${d} ]] ; then
235 d="${ECLASSDIR_LOCAL}/cros-kernel"
236 fi
237 echo "${d}"
238}
239
Josh Triplett6df77a72013-04-26 17:25:37 -0700240# @FUNCTION: kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500241# @DESCRIPTION:
242# Returns the current compiled kernel version.
243# Note: Only valid after src_configure has finished running.
Josh Triplett6df77a72013-04-26 17:25:37 -0700244kernelrelease() {
245 kmake -s --no-print-directory kernelrelease
Mike Frysinger330c0232013-01-09 17:47:04 -0500246}
247
Doug Andersonf291dba2012-01-19 14:26:10 -0800248# @FUNCTION: install_kernel_sources
249# @DESCRIPTION:
250# Installs the kernel sources into ${D}/usr/src/${P} and fixes symlinks.
251# The package must have already installed a directory under ${D}/lib/modules.
252install_kernel_sources() {
Josh Triplett6df77a72013-04-26 17:25:37 -0700253 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800254 local dest_modules_dir=lib/modules/${version}
255 local dest_source_dir=usr/src/${P}
256 local dest_build_dir=${dest_source_dir}/build
257
258 # Fix symlinks in lib/modules
259 ln -sfvT "../../../${dest_build_dir}" \
260 "${D}/${dest_modules_dir}/build" || die
261 ln -sfvT "../../../${dest_source_dir}" \
262 "${D}/${dest_modules_dir}/source" || die
263
264 einfo "Installing kernel source tree"
265 dodir "${dest_source_dir}"
266 local f
267 for f in "${S}"/*; do
268 [[ "$f" == "${S}/build" ]] && continue
269 cp -pPR "${f}" "${D}/${dest_source_dir}" ||
270 die "Failed to copy kernel source tree"
271 done
272
273 dosym "${P}" "/usr/src/linux"
274
275 einfo "Installing kernel build tree"
276 dodir "${dest_build_dir}"
Mike Frysinger833d5f72012-08-07 18:11:59 -0400277 cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \
Doug Andersonf291dba2012-01-19 14:26:10 -0800278 "${D}/${dest_build_dir}" || die
279
280 # Modify Makefile to use the ROOT environment variable if defined.
281 # This path needs to be absolute so that the build directory will
282 # still work if copied elsewhere.
283 sed -i -e "s@${S}@\$(ROOT)/${dest_source_dir}@" \
284 "${D}/${dest_build_dir}/Makefile" || die
285}
286
Doug Andersonf291dba2012-01-19 14:26:10 -0800287get_build_cfg() {
Mike Frysinger833d5f72012-08-07 18:11:59 -0400288 echo "$(cros-workon_get_build_dir)/.config"
Doug Andersonf291dba2012-01-19 14:26:10 -0800289}
290
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700291get_build_arch() {
292 if [ "${ARCH}" = "arm" ] ; then
293 case "${CHROMEOS_KERNEL_SPLITCONFIG}" in
294 *tegra*)
295 echo "tegra"
296 ;;
297 *exynos*)
298 echo "exynos5"
299 ;;
300 *)
301 echo "arm"
302 ;;
303 esac
304 else
305 echo $(tc-arch-kernel)
306 fi
307}
308
Chris Masone6e9b8212013-01-14 11:03:02 -0800309# @FUNCTION: cros_chkconfig_present
310# @USAGE: <option to check config for>
311# @DESCRIPTION:
312# Returns success of the provided option is present in the build config.
313cros_chkconfig_present() {
314 local config=$1
315 grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)"
316}
317
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400318cros-kernel2_pkg_setup() {
Simon Que715e54f32012-12-20 15:53:13 -0800319 # This is needed for running src_test(). The kernel code will need to
320 # be rebuilt with `make check`. If incremental build were enabled,
321 # `make check` would have nothing left to build.
Simon Que6324b6f2013-02-01 14:56:05 -0800322 use test && export CROS_WORKON_INCREMENTAL_BUILD=0
Mike Frysinger833d5f72012-08-07 18:11:59 -0400323 cros-workon_pkg_setup
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500324 linux-info_pkg_setup
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400325}
326
Olof Johanssonb62cf892012-04-27 14:50:24 -0700327# @FUNCTION: emit_its_script
Doug Andersonf2bb2882012-12-06 15:56:21 -0800328# @USAGE: <output file> <boot_dir> <dtb_dir> <device trees>
Olof Johanssonb62cf892012-04-27 14:50:24 -0700329# @DESCRIPTION:
330# Emits the its script used to build the u-boot fitImage kernel binary
331# that contains the kernel as well as device trees used when booting
332# it.
333
334emit_its_script() {
335 local iter=1
336 local its_out=${1}
337 shift
Doug Andersonf2bb2882012-12-06 15:56:21 -0800338 local boot_dir=${1}
339 shift
340 local dtb_dir=${1}
341 shift
Olof Johanssonb62cf892012-04-27 14:50:24 -0700342 cat > "${its_out}" <<-EOF || die
343 /dts-v1/;
344
345 / {
346 description = "Chrome OS kernel image with one or more FDT blobs";
347 #address-cells = <1>;
348
349 images {
350 kernel@1 {
351 data = /incbin/("${boot_dir}/zImage");
352 type = "$(get_kernel_type)";
353 arch = "arm";
354 os = "linux";
355 compression = "none";
356 load = <$(get_load_addr)>;
357 entry = <$(get_load_addr)>;
358 };
359 EOF
360
361 local dtb
362 for dtb in "$@" ; do
363 cat >> "${its_out}" <<-EOF || die
364 fdt@${iter} {
365 description = "$(basename ${dtb})";
Doug Andersonf2bb2882012-12-06 15:56:21 -0800366 data = /incbin/("${dtb_dir}/${dtb}");
Olof Johanssonb62cf892012-04-27 14:50:24 -0700367 type = "flat_dt";
368 arch = "arm";
369 compression = "none";
370 hash@1 {
371 algo = "sha1";
372 };
373 };
374 EOF
375 ((++iter))
376 done
377
378 cat <<-EOF >>"${its_script}"
379 };
380 configurations {
381 default = "conf@1";
382 EOF
383
384 local i
385 for i in $(seq 1 $((iter-1))) ; do
386 cat >> "${its_out}" <<-EOF || die
387 conf@${i} {
388 kernel = "kernel@1";
389 fdt = "fdt@${i}";
390 };
391 EOF
392 done
393
394 echo " };" >> "${its_out}"
395 echo "};" >> "${its_out}"
396}
397
Doug Andersonf291dba2012-01-19 14:26:10 -0800398kmake() {
399 # Allow override of kernel arch.
400 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
401
402 local cross=${CHOST}-
Olof Johanssonc0f8a5d2013-04-11 18:36:40 -0700403
404 if use wireless34 ; then
405 set -- "$@" WIFIVERSION="-3.4"
406 fi
407
Doug Andersonf291dba2012-01-19 14:26:10 -0800408 # Hack for using 64-bit kernel with 32-bit user-space
Mike Frysinger0f008b22013-03-14 11:54:13 -0400409 if [[ "${ARCH}" == "x86" && "${kernel_arch}" == "x86_64" ]]; then
Sonny Rao5ebd89f2012-08-05 20:31:23 -0700410 cross=x86_64-cros-linux-gnu-
Doug Andersonf291dba2012-01-19 14:26:10 -0800411 else
412 # TODO(raymes): Force GNU ld over gold. There are still some
413 # gold issues to iron out. See: 13209.
414 tc-export LD CC CXX
415
416 set -- \
Mike Frysinger0f008b22013-03-14 11:54:13 -0400417 LD="$(get_binutils_path_ld)/ld $(usex x32 '-m elf_x86_64' '')" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800418 CC="${CC} -B$(get_binutils_path_ld)" \
419 CXX="${CXX} -B$(get_binutils_path_ld)" \
420 "$@"
421 fi
422
Mike Frysingera8ef3cd2012-11-01 18:42:18 -0400423 cw_emake \
Doug Andersonf291dba2012-01-19 14:26:10 -0800424 ARCH=${kernel_arch} \
425 LDFLAGS="$(raw-ldflags)" \
426 CROSS_COMPILE="${cross}" \
Mike Frysinger833d5f72012-08-07 18:11:59 -0400427 O="$(cros-workon_get_build_dir)" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800428 "$@"
429}
430
Josh Triplett4c035592012-12-05 15:46:46 -0800431cros-kernel2_src_prepare() {
432 cros-workon_src_prepare
433}
434
Doug Andersonf291dba2012-01-19 14:26:10 -0800435cros-kernel2_src_configure() {
Doug Andersonf291dba2012-01-19 14:26:10 -0800436 # Use a single or split kernel config as specified in the board or variant
437 # make.conf overlay. Default to the arch specific split config if an
438 # overlay or variant does not set either CHROMEOS_KERNEL_CONFIG or
439 # CHROMEOS_KERNEL_SPLITCONFIG. CHROMEOS_KERNEL_CONFIG is set relative
440 # to the root of the kernel source tree.
441 local config
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700442 local cfgarch="$(get_build_arch)"
443
Doug Andersonf291dba2012-01-19 14:26:10 -0800444 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
Chris Masonef888c382013-03-19 14:19:41 -0700445 case ${CHROMEOS_KERNEL_CONFIG} in
446 /*)
447 config="${CHROMEOS_KERNEL_CONFIG}"
448 ;;
449 *)
450 config="${S}/${CHROMEOS_KERNEL_CONFIG}"
451 ;;
452 esac
Doug Andersonf291dba2012-01-19 14:26:10 -0800453 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700454 config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"}
Doug Andersonf291dba2012-01-19 14:26:10 -0800455 fi
456
457 elog "Using kernel config: ${config}"
458
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400459 # Keep a handle on the old .config in case it hasn't changed. This way
460 # we can keep the old timestamp which will avoid regenerating stuff that
461 # hasn't actually changed.
462 local temp_config="${T}/old-kernel-config"
463 if [[ -e $(get_build_cfg) ]] ; then
464 cp -a "$(get_build_cfg)" "${temp_config}"
465 else
466 rm -f "${temp_config}"
467 fi
468
Doug Andersonf291dba2012-01-19 14:26:10 -0800469 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
470 cp -f "${config}" "$(get_build_cfg)" || die
471 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700472 if [ -e chromeos/scripts/prepareconfig ] ; then
473 chromeos/scripts/prepareconfig ${config} \
474 "$(get_build_cfg)" || die
475 else
476 config="$(defconfig_dir)/${cfgarch}_defconfig"
477 ewarn "Can't prepareconfig, falling back to default " \
478 "${config}"
479 cp "${config}" "$(get_build_cfg)" || die
480 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800481 fi
482
483 local fragment
484 for fragment in ${CONFIG_FRAGMENTS[@]}; do
485 use ${fragment} || continue
486
487 local msg="${fragment}_desc"
488 local config="${fragment}_config"
489 elog " - adding ${!msg} config"
Paul Stewart23ead5f2013-04-24 22:32:17 -0700490 local warning="${fragment}_warning"
491 local warning_msg="${!warning}"
492 if [[ -n "${warning_msg}" ]] ; then
493 ewarn "${warning_msg}"
494 fi
Doug Anderson010887c2012-02-04 22:42:54 -0800495
496 echo "${!config}" | \
497 sed -e "s|%ROOT%|${ROOT}|g" \
498 >> "$(get_build_cfg)" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800499 done
500
501 # Use default for any options not explitly set in splitconfig
502 yes "" | kmake oldconfig
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400503
504 # Restore the old config if it is unchanged.
505 if cmp -s "$(get_build_cfg)" "${temp_config}" ; then
506 touch -r "${temp_config}" "$(get_build_cfg)"
507 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800508}
509
Doug Andersonf2bb2882012-12-06 15:56:21 -0800510# @FUNCTION: get_dtb_name
511# @USAGE: <dtb_dir>
512# @DESCRIPTION:
513# Get the name(s) of the device tree binary file(s) to include.
514
Olof Johanssonb62cf892012-04-27 14:50:24 -0700515get_dtb_name() {
Doug Andersonf2bb2882012-12-06 15:56:21 -0800516 local dtb_dir=${1}
Doug Andersonf291dba2012-01-19 14:26:10 -0800517 local board_with_variant=$(get_current_board_with_variant)
518
519 # Do a simple mapping for device trees whose names don't match
520 # the board_with_variant format; default to just the
521 # board_with_variant format.
522 case "${board_with_variant}" in
523 (tegra2_dev-board)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700524 echo tegra-harmony.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800525 ;;
526 (tegra2_seaboard)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700527 echo tegra-seaboard.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800528 ;;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700529 tegra*)
530 echo ${board_with_variant}.dtb
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700531 ;;
Doug Andersonf291dba2012-01-19 14:26:10 -0800532 *)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700533 local f
Doug Andersonf2bb2882012-12-06 15:56:21 -0800534 for f in ${dtb_dir}/*.dtb ; do
Olof Johanssonb62cf892012-04-27 14:50:24 -0700535 basename ${f}
536 done
Doug Andersonf291dba2012-01-19 14:26:10 -0800537 ;;
538 esac
539}
540
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700541# All current tegra boards ship with an u-boot that won't allow
542# use of kernel_noload. Because of this, keep using the traditional
543# kernel type for those. This means kernel_type kernel and regular
544# load and entry point addresses.
545
546get_kernel_type() {
547 case "$(get_current_board_with_variant)" in
548 tegra*)
549 echo kernel
550 ;;
551 *)
552 echo kernel_noload
553 ;;
554 esac
555}
556
557get_load_addr() {
558 case "$(get_current_board_with_variant)" in
559 tegra*)
560 echo 0x03000000
561 ;;
562 *)
563 echo 0
564 ;;
565 esac
566}
567
Doug Andersonf291dba2012-01-19 14:26:10 -0800568cros-kernel2_src_compile() {
Chris Masone6e9b8212013-01-14 11:03:02 -0800569 local build_targets=() # use make default target
Doug Andersonf291dba2012-01-19 14:26:10 -0800570 if use arm; then
Chris Masone6e9b8212013-01-14 11:03:02 -0800571 build_targets=(
Olof Johanssond2242e12013-04-24 13:20:44 -0700572 $(use device_tree && echo "zImage")
Olof Johansson362863f2013-04-23 20:00:44 -0700573 $(use device_tree || echo "uImage")
Chris Masone6e9b8212013-01-14 11:03:02 -0800574 $(cros_chkconfig_present MODULES && echo "modules")
575 )
Doug Andersonf291dba2012-01-19 14:26:10 -0800576 fi
577
Simon Que715e54f32012-12-20 15:53:13 -0800578 local src_dir="$(cros-workon_get_build_dir)/source"
579 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
580 SMATCH_ERROR_FILE="${src_dir}/chromeos/check/smatch_errors.log"
581
Simon Que6324b6f2013-02-01 14:56:05 -0800582 if use test && [[ -e "${SMATCH_ERROR_FILE}" ]]; then
Simon Que715e54f32012-12-20 15:53:13 -0800583 local make_check_cmd="smatch -p=kernel"
584 local test_options=(
585 CHECK="${make_check_cmd}"
586 C=1
587 )
588 SMATCH_LOG_FILE="$(cros-workon_get_build_dir)/make.log"
589
590 # The path names in the log file are build-dependent. Strip out
591 # the part of the path before "kernel/files" and retains what
592 # comes after it: the file, line number, and error message.
Chris Masone6e9b8212013-01-14 11:03:02 -0800593 kmake -k ${build_targets[@]} "${test_options[@]}" |& \
Simon Que715e54f32012-12-20 15:53:13 -0800594 tee "${SMATCH_LOG_FILE}"
595 else
Chris Masone6e9b8212013-01-14 11:03:02 -0800596 kmake -k ${build_targets[@]}
Simon Que715e54f32012-12-20 15:53:13 -0800597 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800598
599 if use device_tree; then
Olof Johanssonb62cf892012-04-27 14:50:24 -0700600 kmake -k dtbs
Doug Andersonf291dba2012-01-19 14:26:10 -0800601 fi
602}
603
Simon Que715e54f32012-12-20 15:53:13 -0800604cros-kernel2_src_test() {
Simon Que715e54f32012-12-20 15:53:13 -0800605 [[ -e ${SMATCH_ERROR_FILE} ]] || \
606 die "smatch whitelist file ${SMATCH_ERROR_FILE} not found!"
607 [[ -e ${SMATCH_LOG_FILE} ]] || \
608 die "Log file from src_compile() ${SMATCH_LOG_FILE} not found!"
609
Simon Que4851c092013-01-16 12:04:06 -0800610 grep -w error: "${SMATCH_LOG_FILE}" | grep -o "kernel/files/.*" \
611 | sed s:"kernel/files/"::g > "${SMATCH_LOG_FILE}.errors"
Simon Que715e54f32012-12-20 15:53:13 -0800612 local num_errors=$(wc -l < "${SMATCH_LOG_FILE}.errors")
613 local num_warnings=$(egrep -wc "warn:|warning:" "${SMATCH_LOG_FILE}")
614 einfo "smatch found ${num_errors} errors and ${num_warnings} warnings."
615
616 # Create a version of the error database that doesn't have line numbers,
617 # since line numbers will shift as code is added or removed.
618 local build_dir="$(cros-workon_get_build_dir)"
619 local no_line_numbers_file="${build_dir}/no_line_numbers.log"
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800620 sed -r -e "s/(:[0-9]+){1,2}//" \
621 -e "s/\(see line [0-9]+\)//" \
622 "${SMATCH_ERROR_FILE}" > "${no_line_numbers_file}"
Simon Que715e54f32012-12-20 15:53:13 -0800623
624 # For every smatch error that came up during the build, check if it is
625 # in the error database file.
626 local num_unknown_errors=0
627 local line=""
628 while read line; do
Simon Quefc5fc9d2013-01-28 15:19:38 -0800629 local no_line_num=$(echo "${line}" | \
Chih-Chung Changf28e76e2013-04-08 11:53:29 +0800630 sed -r -e "s/(:[0-9]+){1,2}//" \
631 -e "s/\(see line [0-9]+\)//")
Simon Que715e54f32012-12-20 15:53:13 -0800632 if ! fgrep -q "${no_line_num}" "${no_line_numbers_file}"; then
633 eerror "Non-whitelisted error found: \"${line}\""
634 : $(( ++num_unknown_errors ))
635 fi
636 done < "${SMATCH_LOG_FILE}.errors"
637
638 [[ ${num_unknown_errors} -eq 0 ]] || \
639 die "smatch found ${num_unknown_errors} unknown errors."
640}
641
Doug Andersonf291dba2012-01-19 14:26:10 -0800642cros-kernel2_src_install() {
643 dodir /boot
644 kmake INSTALL_PATH="${D}/boot" install
Chris Masone6e9b8212013-01-14 11:03:02 -0800645 if cros_chkconfig_present MODULES; then
646 kmake INSTALL_MOD_PATH="${D}" modules_install
647 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800648 kmake INSTALL_MOD_PATH="${D}" firmware_install
649
Josh Triplett6df77a72013-04-26 17:25:37 -0700650 local version=$(kernelrelease)
Doug Andersonf291dba2012-01-19 14:26:10 -0800651 if use arm; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400652 local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot"
Doug Andersonf291dba2012-01-19 14:26:10 -0800653 local kernel_bin="${D}/boot/vmlinuz-${version}"
654 local zimage_bin="${D}/boot/zImage-${version}"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800655 local dtb_dir="${boot_dir}"
656
657 # Newer kernels (after linux-next 12/3/12) put dtbs in the dts
658 # dir. Use that if we we find no dtbs directly in boot_dir.
659 # Note that we try boot_dir first since the newer kernel will
660 # actually rm ${boot_dir}/*.dtb so we'll have no stale files.
661 if ! ls "${dtb_dir}"/*.dtb &> /dev/null; then
662 dtb_dir="${boot_dir}/dts"
663 fi
664
Doug Andersonf291dba2012-01-19 14:26:10 -0800665 if use device_tree; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400666 local its_script="$(cros-workon_get_build_dir)/its_script"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800667 emit_its_script "${its_script}" "${boot_dir}" \
668 "${dtb_dir}" $(get_dtb_name "${dtb_dir}")
Andrew Chewa0695422013-03-19 16:39:58 -0700669 mkimage -D "-I dts -O dtb -p 512" -f "${its_script}" "${kernel_bin}" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800670 else
671 cp -a "${boot_dir}/uImage" "${kernel_bin}" || die
672 fi
673 cp -a "${boot_dir}/zImage" "${zimage_bin}" || die
674
675 # TODO(vbendeb): remove the below .uimg link creation code
676 # after the build scripts have been modified to use the base
677 # image name.
678 cd $(dirname "${kernel_bin}")
679 ln -sf $(basename "${kernel_bin}") vmlinux.uimg || die
680 ln -sf $(basename "${zimage_bin}") zImage || die
681 fi
682 if [ ! -e "${D}/boot/vmlinuz" ]; then
683 ln -sf "vmlinuz-${version}" "${D}/boot/vmlinuz" || die
684 fi
685
Vic Yang40fff212012-05-14 10:43:11 +0800686 # Check the size of kernel image and issue warning when image size is near
Vic Yang9aabf9c2013-01-23 20:47:59 +0800687 # the limit. For factory install initramfs, we don't care about kernel
688 # size limit as the image is downloaded over network.
Vic Yang40fff212012-05-14 10:43:11 +0800689 local kernel_image_size=$(stat -c '%s' -L "${D}"/boot/vmlinuz)
690 einfo "Kernel image size is ${kernel_image_size} bytes."
Vic Yang9aabf9c2013-01-23 20:47:59 +0800691 if use netboot_ramfs; then
692 # No need to check kernel image size.
693 true
694 elif [[ ${kernel_image_size} -gt $((8 * 1024 * 1024)) ]]; then
Olof Johanssoncbbe8872012-07-30 08:43:31 -0700695 die "Kernel image is larger than 8 MB."
696 elif [[ ${kernel_image_size} -gt $((7 * 1024 * 1024)) ]]; then
697 ewarn "Kernel image is larger than 7 MB. Limit is 8 MB."
Vic Yang40fff212012-05-14 10:43:11 +0800698 fi
699
Doug Andersonf291dba2012-01-19 14:26:10 -0800700 # Install uncompressed kernel for debugging purposes.
701 insinto /usr/lib/debug/boot
Mike Frysinger833d5f72012-08-07 18:11:59 -0400702 doins "$(cros-workon_get_build_dir)/vmlinux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800703
704 if use kernel_sources; then
705 install_kernel_sources
Mike Frysingerb5ebdb52013-02-10 03:25:44 -0500706 else
707 dosym "$(cros-workon_get_build_dir)" "/usr/src/linux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800708 fi
709}
710
Simon Que715e54f32012-12-20 15:53:13 -0800711EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install