Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 1 | # 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 | |
| 6 | inherit binutils-funcs cros-board toolchain-funcs |
| 7 | |
| 8 | HOMEPAGE="http://www.chromium.org/" |
| 9 | LICENSE="GPL-2" |
| 10 | SLOT="0" |
| 11 | |
| 12 | DEPEND="sys-apps/debianutils |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 13 | initramfs? ( chromeos-base/chromeos-initramfs ) |
| 14 | " |
| 15 | |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 16 | # TODO(sque): Remove the "smatch" use flag once all boards have opted in to |
| 17 | # smatch testing. |
| 18 | IUSE="-device_tree -kernel_sources -smatch" |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 19 | STRIP_MASK="/usr/lib/debug/boot/vmlinux" |
Josh Triplett | 4c03559 | 2012-12-05 15:46:46 -0800 | [diff] [blame] | 20 | |
| 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 25 | |
| 26 | # Config fragments selected by USE flags |
Doug Anderson | 010887c | 2012-02-04 22:42:54 -0800 | [diff] [blame] | 27 | # ...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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 31 | |
| 32 | CONFIG_FRAGMENTS=( |
| 33 | blkdevram |
Dylan Reid | f0666ff | 2012-07-01 21:42:38 -0700 | [diff] [blame] | 34 | ca0132 |
Micah Catlin | 0dc2b97 | 2012-08-01 17:44:24 -0700 | [diff] [blame] | 35 | cifs |
Mike Frysinger | 1bddd68 | 2012-10-05 14:52:25 -0400 | [diff] [blame] | 36 | debug |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 37 | fbconsole |
Ben Chan | e0654d2 | 2012-05-12 00:09:53 -0700 | [diff] [blame] | 38 | gdmwimax |
Ben Chan | a179ebb | 2012-10-11 01:02:35 -0700 | [diff] [blame] | 39 | gobi |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 40 | highmem |
Vic Yang | 1541a70 | 2013-01-10 17:36:06 +0800 | [diff] [blame] | 41 | i2cdev |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 42 | initramfs |
Ronald G. Minnich | 6d888d4 | 2012-02-16 13:45:58 -0800 | [diff] [blame] | 43 | kvm |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 44 | nfs |
| 45 | pcserial |
Ben Chan | a179ebb | 2012-10-11 01:02:35 -0700 | [diff] [blame] | 46 | qmi |
Dave Parker | 9fb68c9 | 2012-05-04 10:34:00 -0700 | [diff] [blame] | 47 | realtekpstor |
Vic Yang | e0d659e | 2013-01-22 21:44:41 +0800 | [diff] [blame^] | 48 | samsung_serial |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 49 | systemtap |
Vic Yang | e0d659e | 2013-01-22 21:44:41 +0800 | [diff] [blame^] | 50 | tpm |
Vic Yang | 7cc29a9 | 2012-05-18 14:12:10 +0800 | [diff] [blame] | 51 | vfat |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 52 | ) |
| 53 | |
| 54 | blkdevram_desc="ram block device" |
| 55 | blkdevram_config=" |
| 56 | CONFIG_BLK_DEV_RAM=y |
| 57 | CONFIG_BLK_DEV_RAM_COUNT=16 |
| 58 | CONFIG_BLK_DEV_RAM_SIZE=16384 |
| 59 | " |
| 60 | |
Dylan Reid | f0666ff | 2012-07-01 21:42:38 -0700 | [diff] [blame] | 61 | ca0132_desc="CA0132 ALSA codec" |
| 62 | ca0132_config=" |
| 63 | CONFIG_SND_HDA_CODEC_CA0132=y |
Chih-Chung Chang | 2306b49 | 2012-09-04 19:52:18 +0800 | [diff] [blame] | 64 | CONFIG_SND_HDA_DSP_LOADER=y |
Dylan Reid | f0666ff | 2012-07-01 21:42:38 -0700 | [diff] [blame] | 65 | " |
| 66 | |
Micah Catlin | 0dc2b97 | 2012-08-01 17:44:24 -0700 | [diff] [blame] | 67 | cifs_desc="Samba/CIFS Support" |
| 68 | cifs_config=" |
| 69 | CONFIG_CIFS=m |
| 70 | " |
| 71 | |
Mike Frysinger | 1bddd68 | 2012-10-05 14:52:25 -0400 | [diff] [blame] | 72 | debug_desc="debug settings" |
| 73 | debug_config=" |
| 74 | CONFIG_DEBUG_INFO=y |
| 75 | " |
| 76 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 77 | fbconsole_desc="framebuffer console" |
| 78 | fbconsole_config=" |
| 79 | CONFIG_FRAMEBUFFER_CONSOLE=y |
| 80 | " |
| 81 | |
Ben Chan | e0654d2 | 2012-05-12 00:09:53 -0700 | [diff] [blame] | 82 | gdmwimax_desc="GCT GDM72xx WiMAX support" |
| 83 | gdmwimax_config=" |
| 84 | CONFIG_WIMAX_GDM72XX=m |
Ben Chan | e0654d2 | 2012-05-12 00:09:53 -0700 | [diff] [blame] | 85 | CONFIG_WIMAX_GDM72XX_USB=y |
| 86 | CONFIG_WIMAX_GDM72XX_USB_PM=y |
| 87 | " |
| 88 | |
Ben Chan | a179ebb | 2012-10-11 01:02:35 -0700 | [diff] [blame] | 89 | gobi_desc="Qualcomm Gobi modem driver" |
| 90 | gobi_config=" |
| 91 | CONFIG_USB_NET_GOBI=m |
| 92 | " |
| 93 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 94 | highmem_desc="highmem" |
| 95 | highmem_config=" |
| 96 | CONFIG_HIGHMEM64G=y |
| 97 | " |
| 98 | |
Vic Yang | 1541a70 | 2013-01-10 17:36:06 +0800 | [diff] [blame] | 99 | i2cdev_desc="I2C device interface" |
| 100 | i2cdev_config=" |
| 101 | CONFIG_I2C_CHARDEV=y |
| 102 | " |
| 103 | |
Vic Yang | e0d659e | 2013-01-22 21:44:41 +0800 | [diff] [blame^] | 104 | tpm_desc="TPM support" |
| 105 | tpm_config=" |
| 106 | CONFIG_TCG_TPM=y |
| 107 | CONFIG_TCG_TIS=y |
| 108 | " |
| 109 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 110 | initramfs_desc="initramfs" |
| 111 | initramfs_config=" |
Olof Johansson | 2290f06 | 2012-03-12 11:54:45 -0700 | [diff] [blame] | 112 | CONFIG_INITRAMFS_SOURCE=\"%ROOT%/var/lib/misc/initramfs.cpio.xz\" |
Anush Elangovan | f9b66d9 | 2012-12-20 12:16:15 -0800 | [diff] [blame] | 113 | CONFIG_INITRAMFS_COMPRESSION_XZ=y |
Vic Yang | 7cc29a9 | 2012-05-18 14:12:10 +0800 | [diff] [blame] | 114 | " |
| 115 | |
| 116 | vfat_desc="vfat" |
| 117 | vfat_config=" |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 118 | CONFIG_NLS_CODEPAGE_437=y |
| 119 | CONFIG_NLS_ISO8859_1=y |
| 120 | CONFIG_FAT_FS=y |
| 121 | CONFIG_VFAT_FS=y |
| 122 | " |
| 123 | |
Ronald G. Minnich | 6d888d4 | 2012-02-16 13:45:58 -0800 | [diff] [blame] | 124 | kvm_desc="KVM" |
| 125 | kvm_config=" |
| 126 | CONFIG_HAVE_KVM=y |
| 127 | CONFIG_HAVE_KVM_IRQCHIP=y |
| 128 | CONFIG_HAVE_KVM_EVENTFD=y |
| 129 | CONFIG_KVM_APIC_ARCHITECTURE=y |
| 130 | CONFIG_KVM_MMIO=y |
| 131 | CONFIG_KVM_ASYNC_PF=y |
| 132 | CONFIG_KVM=m |
| 133 | CONFIG_KVM_INTEL=m |
| 134 | # CONFIG_KVM_AMD is not set |
| 135 | # CONFIG_KVM_MMU_AUDIT is not set |
| 136 | CONFIG_VIRTIO=m |
| 137 | CONFIG_VIRTIO_BLK=m |
| 138 | CONFIG_VIRTIO_NET=m |
| 139 | CONFIG_VIRTIO_CONSOLE=m |
| 140 | CONFIG_VIRTIO_RING=m |
| 141 | CONFIG_VIRTIO_PCI=m |
| 142 | " |
| 143 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 144 | nfs_desc="NFS" |
| 145 | nfs_config=" |
| 146 | CONFIG_USB_NET_AX8817X=y |
| 147 | CONFIG_DNOTIFY=y |
| 148 | CONFIG_DNS_RESOLVER=y |
| 149 | CONFIG_LOCKD=y |
| 150 | CONFIG_LOCKD_V4=y |
| 151 | CONFIG_NETWORK_FILESYSTEMS=y |
| 152 | CONFIG_NFSD=m |
| 153 | CONFIG_NFSD_V3=y |
| 154 | CONFIG_NFSD_V4=y |
| 155 | CONFIG_NFS_COMMON=y |
| 156 | CONFIG_NFS_FS=y |
| 157 | CONFIG_NFS_USE_KERNEL_DNS=y |
| 158 | CONFIG_NFS_V3=y |
| 159 | CONFIG_NFS_V4=y |
| 160 | CONFIG_ROOT_NFS=y |
| 161 | CONFIG_RPCSEC_GSS_KRB5=y |
| 162 | CONFIG_SUNRPC=y |
| 163 | CONFIG_SUNRPC_GSS=y |
| 164 | CONFIG_USB_USBNET=y |
| 165 | CONFIG_IP_PNP=y |
| 166 | CONFIG_IP_PNP_DHCP=y |
| 167 | " |
| 168 | |
| 169 | pcserial_desc="PC serial" |
| 170 | pcserial_config=" |
| 171 | CONFIG_SERIAL_8250=y |
| 172 | CONFIG_SERIAL_8250_CONSOLE=y |
| 173 | CONFIG_SERIAL_8250_PCI=y |
| 174 | CONFIG_PARPORT=y |
| 175 | CONFIG_PARPORT_PC=y |
| 176 | CONFIG_PARPORT_SERIAL=y |
| 177 | " |
| 178 | |
Ben Chan | a179ebb | 2012-10-11 01:02:35 -0700 | [diff] [blame] | 179 | qmi_desc="QMI WWAN driver" |
| 180 | qmi_config=" |
| 181 | CONFIG_USB_NET_QMI_WWAN=m |
| 182 | " |
| 183 | |
Olof Johansson | 08268b0c | 2012-08-01 00:12:00 -0700 | [diff] [blame] | 184 | samsung_serial_desc="Samsung serialport" |
| 185 | samsung_serial_config=" |
| 186 | CONFIG_SERIAL_SAMSUNG=y |
| 187 | CONFIG_SERIAL_SAMSUNG_CONSOLE=y |
| 188 | " |
| 189 | |
Dave Parker | 9fb68c9 | 2012-05-04 10:34:00 -0700 | [diff] [blame] | 190 | realtekpstor_desc="Realtek PCI card reader" |
| 191 | realtekpstor_config=" |
| 192 | CONFIG_RTS_PSTOR=m |
| 193 | " |
| 194 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 195 | systemtap_desc="systemtap support" |
| 196 | systemtap_config=" |
| 197 | CONFIG_KPROBES=y |
| 198 | CONFIG_DEBUG_INFO=y |
| 199 | " |
| 200 | |
| 201 | # Add all config fragments as off by default |
| 202 | IUSE="${IUSE} ${CONFIG_FRAGMENTS[@]}" |
| 203 | |
Olof Johansson | cd9c9fe | 2012-06-27 20:58:10 -0700 | [diff] [blame] | 204 | # 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. |
| 208 | ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*} |
| 209 | defconfig_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 Frysinger | 330c023 | 2013-01-09 17:47:04 -0500 | [diff] [blame] | 217 | # @FUNCTION: kernelversion |
| 218 | # @DESCRIPTION: |
| 219 | # Returns the current compiled kernel version. |
| 220 | # Note: Only valid after src_configure has finished running. |
| 221 | kernelversion() { |
| 222 | kmake -s --no-print-directory kernelversion |
| 223 | } |
| 224 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 225 | # @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. |
| 229 | install_kernel_sources() { |
Mike Frysinger | 330c023 | 2013-01-09 17:47:04 -0500 | [diff] [blame] | 230 | local version=$(kernelversion) |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 231 | 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 Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 254 | cp -pPR "$(cros-workon_get_build_dir)"/{.config,.version,Makefile,Module.symvers,include} \ |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 255 | "${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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 264 | get_build_cfg() { |
Mike Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 265 | echo "$(cros-workon_get_build_dir)/.config" |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Olof Johansson | cd9c9fe | 2012-06-27 20:58:10 -0700 | [diff] [blame] | 268 | get_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 Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 286 | # @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. |
| 290 | cros_chkconfig_present() { |
| 291 | local config=$1 |
| 292 | grep -q "^CONFIG_$1=[ym]$" "$(get_build_cfg)" |
| 293 | } |
| 294 | |
Mike Frysinger | 3f4eaee | 2012-07-24 17:47:28 -0400 | [diff] [blame] | 295 | cros-kernel2_pkg_setup() { |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 296 | # 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 Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 300 | cros-workon_pkg_setup |
Mike Frysinger | 3f4eaee | 2012-07-24 17:47:28 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 303 | # @FUNCTION: emit_its_script |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 304 | # @USAGE: <output file> <boot_dir> <dtb_dir> <device trees> |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 305 | # @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 | |
| 310 | emit_its_script() { |
| 311 | local iter=1 |
| 312 | local its_out=${1} |
| 313 | shift |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 314 | local boot_dir=${1} |
| 315 | shift |
| 316 | local dtb_dir=${1} |
| 317 | shift |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 318 | 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 Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 342 | data = /incbin/("${dtb_dir}/${dtb}"); |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 343 | 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 374 | kmake() { |
| 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 Frysinger | 302df78 | 2012-12-23 13:22:25 -0500 | [diff] [blame] | 380 | if [[ "${ABI:-${ARCH}}" != "amd64" && "${kernel_arch}" == "x86_64" ]]; then |
Sonny Rao | 5ebd89f | 2012-08-05 20:31:23 -0700 | [diff] [blame] | 381 | cross=x86_64-cros-linux-gnu- |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 382 | 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 Frysinger | a8ef3cd | 2012-11-01 18:42:18 -0400 | [diff] [blame] | 394 | cw_emake \ |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 395 | ARCH=${kernel_arch} \ |
| 396 | LDFLAGS="$(raw-ldflags)" \ |
| 397 | CROSS_COMPILE="${cross}" \ |
Mike Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 398 | O="$(cros-workon_get_build_dir)" \ |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 399 | "$@" |
| 400 | } |
| 401 | |
Josh Triplett | 4c03559 | 2012-12-05 15:46:46 -0800 | [diff] [blame] | 402 | cros-kernel2_src_prepare() { |
| 403 | cros-workon_src_prepare |
| 404 | } |
| 405 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 406 | cros-kernel2_src_configure() { |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 407 | # 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 Johansson | cd9c9fe | 2012-06-27 20:58:10 -0700 | [diff] [blame] | 413 | local cfgarch="$(get_build_arch)" |
| 414 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 415 | if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then |
| 416 | config="${S}/${CHROMEOS_KERNEL_CONFIG}" |
| 417 | else |
Olof Johansson | cd9c9fe | 2012-06-27 20:58:10 -0700 | [diff] [blame] | 418 | config=${CHROMEOS_KERNEL_SPLITCONFIG:-"chromiumos-${cfgarch}"} |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 419 | fi |
| 420 | |
| 421 | elog "Using kernel config: ${config}" |
| 422 | |
Mike Frysinger | 3f4eaee | 2012-07-24 17:47:28 -0400 | [diff] [blame] | 423 | # 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 433 | if [ -n "${CHROMEOS_KERNEL_CONFIG}" ]; then |
| 434 | cp -f "${config}" "$(get_build_cfg)" || die |
| 435 | else |
Olof Johansson | cd9c9fe | 2012-06-27 20:58:10 -0700 | [diff] [blame] | 436 | 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 445 | 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 Anderson | 010887c | 2012-02-04 22:42:54 -0800 | [diff] [blame] | 454 | |
| 455 | echo "${!config}" | \ |
| 456 | sed -e "s|%ROOT%|${ROOT}|g" \ |
| 457 | >> "$(get_build_cfg)" || die |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 458 | done |
| 459 | |
| 460 | # Use default for any options not explitly set in splitconfig |
| 461 | yes "" | kmake oldconfig |
Mike Frysinger | 3f4eaee | 2012-07-24 17:47:28 -0400 | [diff] [blame] | 462 | |
| 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 469 | # @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 Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 474 | get_dtb_name() { |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 475 | local dtb_dir=${1} |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 476 | 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 Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 483 | echo tegra-harmony.dtb |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 484 | ;; |
| 485 | (tegra2_seaboard) |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 486 | echo tegra-seaboard.dtb |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 487 | ;; |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 488 | tegra*) |
| 489 | echo ${board_with_variant}.dtb |
Olof Johansson | beaf472 | 2012-04-16 16:57:36 -0700 | [diff] [blame] | 490 | ;; |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 491 | *) |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 492 | local f |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 493 | for f in ${dtb_dir}/*.dtb ; do |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 494 | basename ${f} |
| 495 | done |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 496 | ;; |
| 497 | esac |
| 498 | } |
| 499 | |
Olof Johansson | beaf472 | 2012-04-16 16:57:36 -0700 | [diff] [blame] | 500 | # 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 | |
| 505 | get_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 | |
| 516 | get_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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 527 | cros-kernel2_src_compile() { |
Chris Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 528 | local build_targets=() # use make default target |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 529 | if use arm; then |
Chris Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 530 | build_targets=( |
| 531 | "uImage" |
| 532 | $(cros_chkconfig_present MODULES && echo "modules") |
| 533 | ) |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 534 | fi |
| 535 | |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 536 | 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 Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 551 | kmake -k ${build_targets[@]} "${test_options[@]}" |& \ |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 552 | tee "${SMATCH_LOG_FILE}" |
| 553 | else |
Chris Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 554 | kmake -k ${build_targets[@]} |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 555 | fi |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 556 | |
| 557 | if use device_tree; then |
Olof Johansson | b62cf89 | 2012-04-27 14:50:24 -0700 | [diff] [blame] | 558 | kmake -k dtbs |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 559 | fi |
| 560 | } |
| 561 | |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 562 | cros-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 Que | 4851c09 | 2013-01-16 12:04:06 -0800 | [diff] [blame] | 569 | grep -w error: "${SMATCH_LOG_FILE}" | grep -o "kernel/files/.*" \ |
| 570 | | sed s:"kernel/files/"::g > "${SMATCH_LOG_FILE}.errors" |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 571 | 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 597 | cros-kernel2_src_install() { |
| 598 | dodir /boot |
| 599 | kmake INSTALL_PATH="${D}/boot" install |
Chris Masone | 6e9b821 | 2013-01-14 11:03:02 -0800 | [diff] [blame] | 600 | if cros_chkconfig_present MODULES; then |
| 601 | kmake INSTALL_MOD_PATH="${D}" modules_install |
| 602 | fi |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 603 | kmake INSTALL_MOD_PATH="${D}" firmware_install |
| 604 | |
Mike Frysinger | 330c023 | 2013-01-09 17:47:04 -0500 | [diff] [blame] | 605 | local version=$(kernelversion) |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 606 | if use arm; then |
Mike Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 607 | local boot_dir="$(cros-workon_get_build_dir)/arch/${ARCH}/boot" |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 608 | local kernel_bin="${D}/boot/vmlinuz-${version}" |
| 609 | local zimage_bin="${D}/boot/zImage-${version}" |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 610 | 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 Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 620 | if use device_tree; then |
Mike Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 621 | local its_script="$(cros-workon_get_build_dir)/its_script" |
Doug Anderson | f2bb288 | 2012-12-06 15:56:21 -0800 | [diff] [blame] | 622 | emit_its_script "${its_script}" "${boot_dir}" \ |
| 623 | "${dtb_dir}" $(get_dtb_name "${dtb_dir}") |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 624 | 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 Yang | 40fff21 | 2012-05-14 10:43:11 +0800 | [diff] [blame] | 641 | # 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 Johansson | cbbe887 | 2012-07-30 08:43:31 -0700 | [diff] [blame] | 645 | 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 Yang | 40fff21 | 2012-05-14 10:43:11 +0800 | [diff] [blame] | 649 | fi |
| 650 | |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 651 | # Install uncompressed kernel for debugging purposes. |
| 652 | insinto /usr/lib/debug/boot |
Mike Frysinger | 833d5f7 | 2012-08-07 18:11:59 -0400 | [diff] [blame] | 653 | doins "$(cros-workon_get_build_dir)/vmlinux" |
Doug Anderson | f291dba | 2012-01-19 14:26:10 -0800 | [diff] [blame] | 654 | |
| 655 | if use kernel_sources; then |
| 656 | install_kernel_sources |
| 657 | fi |
| 658 | } |
| 659 | |
Simon Que | 715e54f3 | 2012-12-20 15:53:13 -0800 | [diff] [blame] | 660 | EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_test src_install |