| # |
| # Copyright 2022 Google LLC |
| # |
| # This program is free software; you can redistribute it and/or |
| # modify it under the terms of the GNU General Public License |
| # version 2 as published by the Free Software Foundation. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| |
| EAPI=7 |
| |
| inherit eutils linux-mod udev |
| |
| DESCRIPTION="Snaggletooth kernel drivers" |
| HOMEPAGE="https://cloud.google.com/tpu" |
| GIT_COMMIT="cb119a8607ee9bb70542867579dc9b6e69a85c5a" |
| SRC_URI="https://github.com/tensorflow/tpu/archive/${GIT_COMMIT}.tar.gz -> ${P}.tar.gz" |
| |
| LICENSE="BSD-Google" |
| SLOT="0" |
| KEYWORDS="*" |
| IUSE="+clang kernel-5_10 kernel-5_15" |
| # Prevent kernel module signature being striped. |
| RESTRICT="strip" |
| |
| COMMON="" |
| DEPEND=" |
| ${COMMON} |
| kernel-5_10? ( sys-kernel/lakitu-kernel-5_10[kernel_sources] ) |
| kernel-5_15? ( sys-kernel/lakitu-kernel-5_15[kernel_sources] ) |
| " |
| RDEPEND=" |
| ${COMMON}" |
| |
| PATCHES=( |
| "${FILESDIR}"/${PN}-5.10-include-fix.patch |
| ) |
| |
| S="${WORKDIR}/tpu-${GIT_COMMIT}/tools/driver/" |
| |
| KBUILD_OUTPUT=${KERNEL_DIR}/build |
| |
| MODULE_NAMES=" |
| accel-class(kernel/drivers/accel:${S}) |
| asic_sw(kernel/drivers/asic_sw:${S}) |
| gasket(kernel/drivers/gasket:${S}) |
| tpu_common(kernel/drivers/tpu_common:${S}) |
| tpu_v2_core(kernel/drivers/tpu_common:${S}) |
| tpu_v2(kernel/drivers/tpu_common:${S}) |
| tpu_v3(kernel/drivers/tpu_common:${S}) |
| tpuv4common_common(kernel/drivers/tpu_common:${S}) |
| tpu_v4(kernel/drivers/tpu_common:${S}) |
| tpu_v4_lite(kernel/drivers/tpu_common:${S})" |
| |
| sign_module() { |
| local module_file="$1" |
| |
| "${KBUILD_OUTPUT}"/scripts/sign-file \ |
| sha256 \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.pem \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.x509 \ |
| ${module_file} |
| } |
| |
| src_prepare() { |
| use clang || cros_use_gcc |
| default |
| } |
| |
| src_compile() { |
| local kernel_arch=${CHROMEOS_KERNEL_ARCH:-$(tc-arch-kernel)} |
| LIBELF="$("${CBUILD}-pkg-config" libelf --libs 2>/dev/null || echo -lelf)" |
| eval "emake -C ${S} HOSTCC=\"$(tc-getBUILD_CC)\" \ |
| CROSS_COMPILE=${CHOST}- \ |
| CC=${CC} \ |
| LD=${LD} \ |
| LDFLAGS=\"$(get_abi_LDFLAGS)\" \ |
| ARCH=${kernel_arch} \ |
| HOST_LIBELF_LIBS=${LIBELF} \ |
| KERNELDIR=\"${KBUILD_OUTPUT}\" \ |
| -f Makefile.tpu_kernel_modules \ |
| all" \ |
| || die "Unable to emake -C ${S} HOSTCC=\"$(tc-getBUILD_CC)\" \ |
| CROSS_COMPILE=${CHOST}- \ |
| CC=${CC} \ |
| LD=${LD} \ |
| LDFLAGS=\"$(get_abi_LDFLAGS)\" \ |
| ARCH=${kernel_arch} \ |
| KERNELDIR=\"${KBUILD_OUTPUT}\" \ |
| -f Makefile.tpu_kernel_modules \ |
| all" |
| } |
| |
| src_install() { |
| for i in ${MODULE_NAMES} |
| do |
| unset libdir srcdir objdir |
| for n in $(find_module_params ${i}) |
| do |
| eval ${n/:*}=${n/*:/} |
| done |
| libdir=${libdir:-misc} |
| srcdir=${srcdir:-${S}} |
| objdir=${objdir:-${srcdir}} |
| |
| einfo "Signing ${modulename} module" |
| sign_module ${objdir}/${modulename}.${KV_OBJ} |
| done |
| linux-mod_src_install |
| udev_dorules "${FILESDIR}/99-tpu.rules" |
| } |