blob: dfec1fe74c12cb8a77c70d7d4ffe58bc47e82cc6 [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
6inherit binutils-funcs cros-board toolchain-funcs
7
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 )
14"
15
Simon Que715e54f32012-12-20 15:53:13 -080016# TODO(sque): Remove the "smatch" use flag once all boards have opted in to
17# smatch testing.
18IUSE="-device_tree -kernel_sources -smatch"
Doug Andersonf291dba2012-01-19 14:26:10 -080019STRIP_MASK="/usr/lib/debug/boot/vmlinux"
Josh Triplett4c035592012-12-05 15:46:46 -080020
21# Build out-of-tree and incremental by default, but allow an ebuild inheriting
22# this eclass to explicitly build in-tree.
23: ${CROS_WORKON_OUTOFTREE_BUILD:=1}
24: ${CROS_WORKON_INCREMENTAL_BUILD:=1}
Doug Andersonf291dba2012-01-19 14:26:10 -080025
26# Config fragments selected by USE flags
Doug Anderson010887c2012-02-04 22:42:54 -080027# ...fragments will have the following variables substitutions
28# applied later (needs to be done later since these values
29# aren't reliable when used in a global context like this):
30# %ROOT% => ${ROOT}
Doug Andersonf291dba2012-01-19 14:26:10 -080031
32CONFIG_FRAGMENTS=(
33 blkdevram
Dylan Reidf0666ff2012-07-01 21:42:38 -070034 ca0132
Micah Catlin0dc2b972012-08-01 17:44:24 -070035 cifs
Mike Frysinger1bddd682012-10-05 14:52:25 -040036 debug
Doug Andersonf291dba2012-01-19 14:26:10 -080037 fbconsole
Ben Chane0654d22012-05-12 00:09:53 -070038 gdmwimax
Ben Chana179ebb2012-10-11 01:02:35 -070039 gobi
Doug Andersonf291dba2012-01-19 14:26:10 -080040 highmem
Vic Yang1541a702013-01-10 17:36:06 +080041 i2cdev
Doug Andersonf291dba2012-01-19 14:26:10 -080042 initramfs
Ronald G. Minnich6d888d42012-02-16 13:45:58 -080043 kvm
Doug Andersonf291dba2012-01-19 14:26:10 -080044 nfs
45 pcserial
Ben Chana179ebb2012-10-11 01:02:35 -070046 qmi
Dave Parker9fb68c92012-05-04 10:34:00 -070047 realtekpstor
Vic Yange0d659e2013-01-22 21:44:41 +080048 samsung_serial
Doug Andersonf291dba2012-01-19 14:26:10 -080049 systemtap
Vic Yange0d659e2013-01-22 21:44:41 +080050 tpm
Vic Yang7cc29a92012-05-18 14:12:10 +080051 vfat
Doug Andersonf291dba2012-01-19 14:26:10 -080052)
53
54blkdevram_desc="ram block device"
55blkdevram_config="
56CONFIG_BLK_DEV_RAM=y
57CONFIG_BLK_DEV_RAM_COUNT=16
58CONFIG_BLK_DEV_RAM_SIZE=16384
59"
60
Dylan Reidf0666ff2012-07-01 21:42:38 -070061ca0132_desc="CA0132 ALSA codec"
62ca0132_config="
63CONFIG_SND_HDA_CODEC_CA0132=y
Chih-Chung Chang2306b492012-09-04 19:52:18 +080064CONFIG_SND_HDA_DSP_LOADER=y
Dylan Reidf0666ff2012-07-01 21:42:38 -070065"
66
Micah Catlin0dc2b972012-08-01 17:44:24 -070067cifs_desc="Samba/CIFS Support"
68cifs_config="
69CONFIG_CIFS=m
70"
71
Mike Frysinger1bddd682012-10-05 14:52:25 -040072debug_desc="debug settings"
73debug_config="
74CONFIG_DEBUG_INFO=y
75"
76
Doug Andersonf291dba2012-01-19 14:26:10 -080077fbconsole_desc="framebuffer console"
78fbconsole_config="
79CONFIG_FRAMEBUFFER_CONSOLE=y
80"
81
Ben Chane0654d22012-05-12 00:09:53 -070082gdmwimax_desc="GCT GDM72xx WiMAX support"
83gdmwimax_config="
84CONFIG_WIMAX_GDM72XX=m
Ben Chane0654d22012-05-12 00:09:53 -070085CONFIG_WIMAX_GDM72XX_USB=y
86CONFIG_WIMAX_GDM72XX_USB_PM=y
87"
88
Ben Chana179ebb2012-10-11 01:02:35 -070089gobi_desc="Qualcomm Gobi modem driver"
90gobi_config="
91CONFIG_USB_NET_GOBI=m
92"
93
Doug Andersonf291dba2012-01-19 14:26:10 -080094highmem_desc="highmem"
95highmem_config="
96CONFIG_HIGHMEM64G=y
97"
98
Vic Yang1541a702013-01-10 17:36:06 +080099i2cdev_desc="I2C device interface"
100i2cdev_config="
101CONFIG_I2C_CHARDEV=y
102"
103
Vic Yange0d659e2013-01-22 21:44:41 +0800104tpm_desc="TPM support"
105tpm_config="
106CONFIG_TCG_TPM=y
107CONFIG_TCG_TIS=y
108"
109
Doug Andersonf291dba2012-01-19 14:26:10 -0800110initramfs_desc="initramfs"
111initramfs_config="
Olof Johansson2290f062012-03-12 11:54:45 -0700112CONFIG_INITRAMFS_SOURCE=\"%ROOT%/var/lib/misc/initramfs.cpio.xz\"
Anush Elangovanf9b66d92012-12-20 12:16:15 -0800113CONFIG_INITRAMFS_COMPRESSION_XZ=y
Vic Yang7cc29a92012-05-18 14:12:10 +0800114"
115
116vfat_desc="vfat"
117vfat_config="
Doug Andersonf291dba2012-01-19 14:26:10 -0800118CONFIG_NLS_CODEPAGE_437=y
119CONFIG_NLS_ISO8859_1=y
120CONFIG_FAT_FS=y
121CONFIG_VFAT_FS=y
122"
123
Ronald G. Minnich6d888d42012-02-16 13:45:58 -0800124kvm_desc="KVM"
125kvm_config="
126CONFIG_HAVE_KVM=y
127CONFIG_HAVE_KVM_IRQCHIP=y
128CONFIG_HAVE_KVM_EVENTFD=y
129CONFIG_KVM_APIC_ARCHITECTURE=y
130CONFIG_KVM_MMIO=y
131CONFIG_KVM_ASYNC_PF=y
132CONFIG_KVM=m
133CONFIG_KVM_INTEL=m
134# CONFIG_KVM_AMD is not set
135# CONFIG_KVM_MMU_AUDIT is not set
136CONFIG_VIRTIO=m
137CONFIG_VIRTIO_BLK=m
138CONFIG_VIRTIO_NET=m
139CONFIG_VIRTIO_CONSOLE=m
140CONFIG_VIRTIO_RING=m
141CONFIG_VIRTIO_PCI=m
142"
143
Doug Andersonf291dba2012-01-19 14:26:10 -0800144nfs_desc="NFS"
145nfs_config="
146CONFIG_USB_NET_AX8817X=y
147CONFIG_DNOTIFY=y
148CONFIG_DNS_RESOLVER=y
149CONFIG_LOCKD=y
150CONFIG_LOCKD_V4=y
151CONFIG_NETWORK_FILESYSTEMS=y
152CONFIG_NFSD=m
153CONFIG_NFSD_V3=y
154CONFIG_NFSD_V4=y
155CONFIG_NFS_COMMON=y
156CONFIG_NFS_FS=y
157CONFIG_NFS_USE_KERNEL_DNS=y
158CONFIG_NFS_V3=y
159CONFIG_NFS_V4=y
160CONFIG_ROOT_NFS=y
161CONFIG_RPCSEC_GSS_KRB5=y
162CONFIG_SUNRPC=y
163CONFIG_SUNRPC_GSS=y
164CONFIG_USB_USBNET=y
165CONFIG_IP_PNP=y
166CONFIG_IP_PNP_DHCP=y
167"
168
169pcserial_desc="PC serial"
170pcserial_config="
171CONFIG_SERIAL_8250=y
172CONFIG_SERIAL_8250_CONSOLE=y
173CONFIG_SERIAL_8250_PCI=y
174CONFIG_PARPORT=y
175CONFIG_PARPORT_PC=y
176CONFIG_PARPORT_SERIAL=y
177"
178
Ben Chana179ebb2012-10-11 01:02:35 -0700179qmi_desc="QMI WWAN driver"
180qmi_config="
181CONFIG_USB_NET_QMI_WWAN=m
182"
183
Olof Johansson08268b0c2012-08-01 00:12:00 -0700184samsung_serial_desc="Samsung serialport"
185samsung_serial_config="
186CONFIG_SERIAL_SAMSUNG=y
187CONFIG_SERIAL_SAMSUNG_CONSOLE=y
188"
189
Dave Parker9fb68c92012-05-04 10:34:00 -0700190realtekpstor_desc="Realtek PCI card reader"
191realtekpstor_config="
192CONFIG_RTS_PSTOR=m
193"
194
Doug Andersonf291dba2012-01-19 14:26:10 -0800195systemtap_desc="systemtap support"
196systemtap_config="
197CONFIG_KPROBES=y
198CONFIG_DEBUG_INFO=y
199"
200
201# Add all config fragments as off by default
202IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}"
203
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700204# If an overlay has eclass overrides, but doesn't actually override this
205# eclass, we'll have ECLASSDIR pointing to the active overlay's
206# eclass/ dir, but this eclass is still in the main chromiumos tree. So
207# add a check to locate the cros-kernel/ regardless of what's going on.
208ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
209defconfig_dir() {
210 local d="${ECLASSDIR}/cros-kernel"
211 if [[ ! -d ${d} ]] ; then
212 d="${ECLASSDIR_LOCAL}/cros-kernel"
213 fi
214 echo "${d}"
215}
216
Mike Frysinger330c0232013-01-09 17:47:04 -0500217# @FUNCTION: kernelversion
218# @DESCRIPTION:
219# Returns the current compiled kernel version.
220# Note: Only valid after src_configure has finished running.
221kernelversion() {
222 kmake -s --no-print-directory kernelversion
223}
224
Doug Andersonf291dba2012-01-19 14:26:10 -0800225# @FUNCTION: install_kernel_sources
226# @DESCRIPTION:
227# Installs the kernel sources into ${D}/usr/src/${P} and fixes symlinks.
228# The package must have already installed a directory under ${D}/lib/modules.
229install_kernel_sources() {
Mike Frysinger330c0232013-01-09 17:47:04 -0500230 local version=$(kernelversion)
Doug Andersonf291dba2012-01-19 14:26:10 -0800231 local dest_modules_dir=lib/modules/${version}
232 local dest_source_dir=usr/src/${P}
233 local dest_build_dir=${dest_source_dir}/build
234
235 # Fix symlinks in lib/modules
236 ln -sfvT "../../../${dest_build_dir}" \
237 "${D}/${dest_modules_dir}/build" || die
238 ln -sfvT "../../../${dest_source_dir}" \
239 "${D}/${dest_modules_dir}/source" || die
240
241 einfo "Installing kernel source tree"
242 dodir "${dest_source_dir}"
243 local f
244 for f in "${S}"/*; do
245 [[ "$f" == "${S}/build" ]] && continue
246 cp -pPR "${f}" "${D}/${dest_source_dir}" ||
247 die "Failed to copy kernel source tree"
248 done
249
250 dosym "${P}" "/usr/src/linux"
251
252 einfo "Installing kernel build tree"
253 dodir "${dest_build_dir}"
Mike Frysinger833d5f72012-08-07 18:11:59 -0400254 cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \
Doug Andersonf291dba2012-01-19 14:26:10 -0800255 "${D}/${dest_build_dir}" || die
256
257 # Modify Makefile to use the ROOT environment variable if defined.
258 # This path needs to be absolute so that the build directory will
259 # still work if copied elsewhere.
260 sed -i -e "s@${S}@\$(ROOT)/${dest_source_dir}@" \
261 "${D}/${dest_build_dir}/Makefile" || die
262}
263
Doug Andersonf291dba2012-01-19 14:26:10 -0800264get_build_cfg() {
Mike Frysinger833d5f72012-08-07 18:11:59 -0400265 echo "$(cros-workon_get_build_dir)/.config"
Doug Andersonf291dba2012-01-19 14:26:10 -0800266}
267
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700268get_build_arch() {
269 if [ "${ARCH}" = "arm" ] ; then
270 case "${CHROMEOS_KERNEL_SPLITCONFIG}" in
271 *tegra*)
272 echo "tegra"
273 ;;
274 *exynos*)
275 echo "exynos5"
276 ;;
277 *)
278 echo "arm"
279 ;;
280 esac
281 else
282 echo $(tc-arch-kernel)
283 fi
284}
285
Chris Masone6e9b8212013-01-14 11:03:02 -0800286# @FUNCTION: cros_chkconfig_present
287# @USAGE: <option to check config for>
288# @DESCRIPTION:
289# Returns success of the provided option is present in the build config.
290cros_chkconfig_present() {
291 local config=$1
292 grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)"
293}
294
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400295cros-kernel2_pkg_setup() {
Simon Que715e54f32012-12-20 15:53:13 -0800296 # This is needed for running src_test(). The kernel code will need to
297 # be rebuilt with `make check`. If incremental build were enabled,
298 # `make check` would have nothing left to build.
299 use test && use smatch && export CROS_WORKON_INCREMENTAL_BUILD=0
Mike Frysinger833d5f72012-08-07 18:11:59 -0400300 cros-workon_pkg_setup
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400301}
302
Olof Johanssonb62cf892012-04-27 14:50:24 -0700303# @FUNCTION: emit_its_script
Doug Andersonf2bb2882012-12-06 15:56:21 -0800304# @USAGE: <output file> <boot_dir> <dtb_dir> <device trees>
Olof Johanssonb62cf892012-04-27 14:50:24 -0700305# @DESCRIPTION:
306# Emits the its script used to build the u-boot fitImage kernel binary
307# that contains the kernel as well as device trees used when booting
308# it.
309
310emit_its_script() {
311 local iter=1
312 local its_out=${1}
313 shift
Doug Andersonf2bb2882012-12-06 15:56:21 -0800314 local boot_dir=${1}
315 shift
316 local dtb_dir=${1}
317 shift
Olof Johanssonb62cf892012-04-27 14:50:24 -0700318 cat > "${its_out}" <<-EOF || die
319 /dts-v1/;
320
321 / {
322 description = "Chrome OS kernel image with one or more FDT blobs";
323 #address-cells = <1>;
324
325 images {
326 kernel@1 {
327 data = /incbin/("${boot_dir}/zImage");
328 type = "$(get_kernel_type)";
329 arch = "arm";
330 os = "linux";
331 compression = "none";
332 load = <$(get_load_addr)>;
333 entry = <$(get_load_addr)>;
334 };
335 EOF
336
337 local dtb
338 for dtb in "$@" ; do
339 cat >> "${its_out}" <<-EOF || die
340 fdt@${iter} {
341 description = "$(basename ${dtb})";
Doug Andersonf2bb2882012-12-06 15:56:21 -0800342 data = /incbin/("${dtb_dir}/${dtb}");
Olof Johanssonb62cf892012-04-27 14:50:24 -0700343 type = "flat_dt";
344 arch = "arm";
345 compression = "none";
346 hash@1 {
347 algo = "sha1";
348 };
349 };
350 EOF
351 ((++iter))
352 done
353
354 cat <<-EOF >>"${its_script}"
355 };
356 configurations {
357 default = "conf@1";
358 EOF
359
360 local i
361 for i in $(seq 1 $((iter-1))) ; do
362 cat >> "${its_out}" <<-EOF || die
363 conf@${i} {
364 kernel = "kernel@1";
365 fdt = "fdt@${i}";
366 };
367 EOF
368 done
369
370 echo " };" >> "${its_out}"
371 echo "};" >> "${its_out}"
372}
373
Doug Andersonf291dba2012-01-19 14:26:10 -0800374kmake() {
375 # Allow override of kernel arch.
376 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
377
378 local cross=${CHOST}-
379 # Hack for using 64-bit kernel with 32-bit user-space
Mike Frysinger302df782012-12-23 13:22:25 -0500380 if [[ "${ABI:-${ARCH}}" != "amd64" && "${kernel_arch}" == "x86_64" ]]; then
Sonny Rao5ebd89f2012-08-05 20:31:23 -0700381 cross=x86_64-cros-linux-gnu-
Doug Andersonf291dba2012-01-19 14:26:10 -0800382 else
383 # TODO(raymes): Force GNU ld over gold. There are still some
384 # gold issues to iron out. See: 13209.
385 tc-export LD CC CXX
386
387 set -- \
388 LD="$(get_binutils_path_ld)/ld" \
389 CC="${CC} -B$(get_binutils_path_ld)" \
390 CXX="${CXX} -B$(get_binutils_path_ld)" \
391 "$@"
392 fi
393
Mike Frysingera8ef3cd2012-11-01 18:42:18 -0400394 cw_emake \
Doug Andersonf291dba2012-01-19 14:26:10 -0800395 ARCH=${kernel_arch} \
396 LDFLAGS="$(raw-ldflags)" \
397 CROSS_COMPILE="${cross}" \
Mike Frysinger833d5f72012-08-07 18:11:59 -0400398 O="$(cros-workon_get_build_dir)" \
Doug Andersonf291dba2012-01-19 14:26:10 -0800399 "$@"
400}
401
Josh Triplett4c035592012-12-05 15:46:46 -0800402cros-kernel2_src_prepare() {
403 cros-workon_src_prepare
404}
405
Doug Andersonf291dba2012-01-19 14:26:10 -0800406cros-kernel2_src_configure() {
Doug Andersonf291dba2012-01-19 14:26:10 -0800407 # Use a single or split kernel config as specified in the board or variant
408 # make.conf overlay. Default to the arch specific split config if an
409 # overlay or variant does not set either CHROMEOS_KERNEL_CONFIG or
410 # CHROMEOS_KERNEL_SPLITCONFIG. CHROMEOS_KERNEL_CONFIG is set relative
411 # to the root of the kernel source tree.
412 local config
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700413 local cfgarch="$(get_build_arch)"
414
Doug Andersonf291dba2012-01-19 14:26:10 -0800415 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
416 config="${S}/${CHROMEOS_KERNEL_CONFIG}"
417 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700418 config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"}
Doug Andersonf291dba2012-01-19 14:26:10 -0800419 fi
420
421 elog "Using kernel config: ${config}"
422
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400423 # Keep a handle on the old .config in case it hasn't changed. This way
424 # we can keep the old timestamp which will avoid regenerating stuff that
425 # hasn't actually changed.
426 local temp_config="${T}/old-kernel-config"
427 if [[ -e $(get_build_cfg) ]] ; then
428 cp -a "$(get_build_cfg)" "${temp_config}"
429 else
430 rm -f "${temp_config}"
431 fi
432
Doug Andersonf291dba2012-01-19 14:26:10 -0800433 if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then
434 cp -f "${config}" "$(get_build_cfg)" || die
435 else
Olof Johanssoncd9c9fe2012-06-27 20:58:10 -0700436 if [ -e chromeos/scripts/prepareconfig ] ; then
437 chromeos/scripts/prepareconfig ${config} \
438 "$(get_build_cfg)" || die
439 else
440 config="$(defconfig_dir)/${cfgarch}_defconfig"
441 ewarn "Can't prepareconfig, falling back to default " \
442 "${config}"
443 cp "${config}" "$(get_build_cfg)" || die
444 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800445 fi
446
447 local fragment
448 for fragment in ${CONFIG_FRAGMENTS[@]}; do
449 use ${fragment} || continue
450
451 local msg="${fragment}_desc"
452 local config="${fragment}_config"
453 elog " - adding ${!msg} config"
Doug Anderson010887c2012-02-04 22:42:54 -0800454
455 echo "${!config}" | \
456 sed -e "s|%ROOT%|${ROOT}|g" \
457 >> "$(get_build_cfg)" || die
Doug Andersonf291dba2012-01-19 14:26:10 -0800458 done
459
460 # Use default for any options not explitly set in splitconfig
461 yes "" | kmake oldconfig
Mike Frysinger3f4eaee2012-07-24 17:47:28 -0400462
463 # Restore the old config if it is unchanged.
464 if cmp -s "$(get_build_cfg)" "${temp_config}" ; then
465 touch -r "${temp_config}" "$(get_build_cfg)"
466 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800467}
468
Doug Andersonf2bb2882012-12-06 15:56:21 -0800469# @FUNCTION: get_dtb_name
470# @USAGE: <dtb_dir>
471# @DESCRIPTION:
472# Get the name(s) of the device tree binary file(s) to include.
473
Olof Johanssonb62cf892012-04-27 14:50:24 -0700474get_dtb_name() {
Doug Andersonf2bb2882012-12-06 15:56:21 -0800475 local dtb_dir=${1}
Doug Andersonf291dba2012-01-19 14:26:10 -0800476 local board_with_variant=$(get_current_board_with_variant)
477
478 # Do a simple mapping for device trees whose names don't match
479 # the board_with_variant format; default to just the
480 # board_with_variant format.
481 case "${board_with_variant}" in
482 (tegra2_dev-board)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700483 echo tegra-harmony.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800484 ;;
485 (tegra2_seaboard)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700486 echo tegra-seaboard.dtb
Doug Andersonf291dba2012-01-19 14:26:10 -0800487 ;;
Olof Johanssonb62cf892012-04-27 14:50:24 -0700488 tegra*)
489 echo ${board_with_variant}.dtb
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700490 ;;
Doug Andersonf291dba2012-01-19 14:26:10 -0800491 *)
Olof Johanssonb62cf892012-04-27 14:50:24 -0700492 local f
Doug Andersonf2bb2882012-12-06 15:56:21 -0800493 for f in ${dtb_dir}/*.dtb ; do
Olof Johanssonb62cf892012-04-27 14:50:24 -0700494 basename ${f}
495 done
Doug Andersonf291dba2012-01-19 14:26:10 -0800496 ;;
497 esac
498}
499
Olof Johanssonbeaf4722012-04-16 16:57:36 -0700500# All current tegra boards ship with an u-boot that won't allow
501# use of kernel_noload. Because of this, keep using the traditional
502# kernel type for those. This means kernel_type kernel and regular
503# load and entry point addresses.
504
505get_kernel_type() {
506 case "$(get_current_board_with_variant)" in
507 tegra*)
508 echo kernel
509 ;;
510 *)
511 echo kernel_noload
512 ;;
513 esac
514}
515
516get_load_addr() {
517 case "$(get_current_board_with_variant)" in
518 tegra*)
519 echo 0x03000000
520 ;;
521 *)
522 echo 0
523 ;;
524 esac
525}
526
Doug Andersonf291dba2012-01-19 14:26:10 -0800527cros-kernel2_src_compile() {
Chris Masone6e9b8212013-01-14 11:03:02 -0800528 local build_targets=() # use make default target
Doug Andersonf291dba2012-01-19 14:26:10 -0800529 if use arm; then
Chris Masone6e9b8212013-01-14 11:03:02 -0800530 build_targets=(
531 "uImage"
532 $(cros_chkconfig_present MODULES && echo "modules")
533 )
Doug Andersonf291dba2012-01-19 14:26:10 -0800534 fi
535
Simon Que715e54f32012-12-20 15:53:13 -0800536 local src_dir="$(cros-workon_get_build_dir)/source"
537 local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)}
538 SMATCH_ERROR_FILE="${src_dir}/chromeos/check/smatch_errors.log"
539
540 if use test && use smatch && [[ -e "${SMATCH_ERROR_FILE}" ]]; then
541 local make_check_cmd="smatch -p=kernel"
542 local test_options=(
543 CHECK="${make_check_cmd}"
544 C=1
545 )
546 SMATCH_LOG_FILE="$(cros-workon_get_build_dir)/make.log"
547
548 # The path names in the log file are build-dependent. Strip out
549 # the part of the path before "kernel/files" and retains what
550 # comes after it: the file, line number, and error message.
Chris Masone6e9b8212013-01-14 11:03:02 -0800551 kmake -k ${build_targets[@]} "${test_options[@]}" |& \
Simon Que715e54f32012-12-20 15:53:13 -0800552 tee "${SMATCH_LOG_FILE}"
553 else
Chris Masone6e9b8212013-01-14 11:03:02 -0800554 kmake -k ${build_targets[@]}
Simon Que715e54f32012-12-20 15:53:13 -0800555 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800556
557 if use device_tree; then
Olof Johanssonb62cf892012-04-27 14:50:24 -0700558 kmake -k dtbs
Doug Andersonf291dba2012-01-19 14:26:10 -0800559 fi
560}
561
Simon Que715e54f32012-12-20 15:53:13 -0800562cros-kernel2_src_test() {
563 use smatch || return
564 [[ -e ${SMATCH_ERROR_FILE} ]] || \
565 die "smatch whitelist file ${SMATCH_ERROR_FILE} not found!"
566 [[ -e ${SMATCH_LOG_FILE} ]] || \
567 die "Log file from src_compile() ${SMATCH_LOG_FILE} not found!"
568
Simon Que4851c092013-01-16 12:04:06 -0800569 grep -w error: "${SMATCH_LOG_FILE}" | grep -o "kernel/files/.*" \
570 | sed s:"kernel/files/"::g > "${SMATCH_LOG_FILE}.errors"
Simon Que715e54f32012-12-20 15:53:13 -0800571 local num_errors=$(wc -l < "${SMATCH_LOG_FILE}.errors")
572 local num_warnings=$(egrep -wc "warn:|warning:" "${SMATCH_LOG_FILE}")
573 einfo "smatch found ${num_errors} errors and ${num_warnings} warnings."
574
575 # Create a version of the error database that doesn't have line numbers,
576 # since line numbers will shift as code is added or removed.
577 local build_dir="$(cros-workon_get_build_dir)"
578 local no_line_numbers_file="${build_dir}/no_line_numbers.log"
579 sed -r "s/:[0-9]+//" "${SMATCH_ERROR_FILE}" > "${no_line_numbers_file}"
580
581 # For every smatch error that came up during the build, check if it is
582 # in the error database file.
583 local num_unknown_errors=0
584 local line=""
585 while read line; do
586 local no_line_num=$(echo "${line}" | sed -r "s/:[0-9]+//")
587 if ! fgrep -q "${no_line_num}" "${no_line_numbers_file}"; then
588 eerror "Non-whitelisted error found: \"${line}\""
589 : $(( ++num_unknown_errors ))
590 fi
591 done < "${SMATCH_LOG_FILE}.errors"
592
593 [[ ${num_unknown_errors} -eq 0 ]] || \
594 die "smatch found ${num_unknown_errors} unknown errors."
595}
596
Doug Andersonf291dba2012-01-19 14:26:10 -0800597cros-kernel2_src_install() {
598 dodir /boot
599 kmake INSTALL_PATH="${D}/boot" install
Chris Masone6e9b8212013-01-14 11:03:02 -0800600 if cros_chkconfig_present MODULES; then
601 kmake INSTALL_MOD_PATH="${D}" modules_install
602 fi
Doug Andersonf291dba2012-01-19 14:26:10 -0800603 kmake INSTALL_MOD_PATH="${D}" firmware_install
604
Mike Frysinger330c0232013-01-09 17:47:04 -0500605 local version=$(kernelversion)
Doug Andersonf291dba2012-01-19 14:26:10 -0800606 if use arm; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400607 local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot"
Doug Andersonf291dba2012-01-19 14:26:10 -0800608 local kernel_bin="${D}/boot/vmlinuz-${version}"
609 local zimage_bin="${D}/boot/zImage-${version}"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800610 local dtb_dir="${boot_dir}"
611
612 # Newer kernels (after linux-next 12/3/12) put dtbs in the dts
613 # dir. Use that if we we find no dtbs directly in boot_dir.
614 # Note that we try boot_dir first since the newer kernel will
615 # actually rm ${boot_dir}/*.dtb so we'll have no stale files.
616 if ! ls "${dtb_dir}"/*.dtb &> /dev/null; then
617 dtb_dir="${boot_dir}/dts"
618 fi
619
Doug Andersonf291dba2012-01-19 14:26:10 -0800620 if use device_tree; then
Mike Frysinger833d5f72012-08-07 18:11:59 -0400621 local its_script="$(cros-workon_get_build_dir)/its_script"
Doug Andersonf2bb2882012-12-06 15:56:21 -0800622 emit_its_script "${its_script}" "${boot_dir}" \
623 "${dtb_dir}" $(get_dtb_name "${dtb_dir}")
Doug Andersonf291dba2012-01-19 14:26:10 -0800624 mkimage -f "${its_script}" "${kernel_bin}" || die
625 else
626 cp -a "${boot_dir}/uImage" "${kernel_bin}" || die
627 fi
628 cp -a "${boot_dir}/zImage" "${zimage_bin}" || die
629
630 # TODO(vbendeb): remove the below .uimg link creation code
631 # after the build scripts have been modified to use the base
632 # image name.
633 cd $(dirname "${kernel_bin}")
634 ln -sf $(basename "${kernel_bin}") vmlinux.uimg || die
635 ln -sf $(basename "${zimage_bin}") zImage || die
636 fi
637 if [ ! -e "${D}/boot/vmlinuz" ]; then
638 ln -sf "vmlinuz-${version}" "${D}/boot/vmlinuz" || die
639 fi
640
Vic Yang40fff212012-05-14 10:43:11 +0800641 # Check the size of kernel image and issue warning when image size is near
642 # the limit.
643 local kernel_image_size=$(stat -c '%s' -L "${D}"/boot/vmlinuz)
644 einfo "Kernel image size is ${kernel_image_size} bytes."
Olof Johanssoncbbe8872012-07-30 08:43:31 -0700645 if [[ ${kernel_image_size} -gt $((8 * 1024 * 1024)) ]]; then
646 die "Kernel image is larger than 8 MB."
647 elif [[ ${kernel_image_size} -gt $((7 * 1024 * 1024)) ]]; then
648 ewarn "Kernel image is larger than 7 MB. Limit is 8 MB."
Vic Yang40fff212012-05-14 10:43:11 +0800649 fi
650
Doug Andersonf291dba2012-01-19 14:26:10 -0800651 # Install uncompressed kernel for debugging purposes.
652 insinto /usr/lib/debug/boot
Mike Frysinger833d5f72012-08-07 18:11:59 -0400653 doins "$(cros-workon_get_build_dir)/vmlinux"
Doug Andersonf291dba2012-01-19 14:26:10 -0800654
655 if use kernel_sources; then
656 install_kernel_sources
657 fi
658}
659
Simon Que715e54f32012-12-20 15:53:13 -0800660EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install