| # |
| # Copyright 2021 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 linux-mod |
| |
| # Get realtime / vanilla kernel indicator after numeric version digits. e.g. "v" or "r". |
| RT=$(ver_cut 4 ${PV}) |
| # Get pure digit version number e.g. from ice-1.3.2v we will get "1.3.2". |
| PV=$(ver_cut 1-3) |
| |
| DESCRIPTION="Mellanox NNT-Linux-driver (NVIDIA® networking tools driver)" |
| HOMEPAGE="https://github.com/Mellanox/NNT-Linux-driver" |
| REPO="NNT-Linux-driver" |
| MY_TAR="Mellanox-${REPO}-eff51062532f3bf356027deea484f2739567f737.tar.xz" |
| SRC_URI="gs://chromeos-localmirror/distfiles/${MY_TAR} -> ${PN}-${PV}.tar.xz" |
| |
| LICENSE="BSD-Google" |
| SLOT="vanilla" |
| case "${RT}" in |
| r) |
| SLOT="rt" |
| ;; |
| *) |
| ;; |
| esac |
| KEYWORDS="*" |
| IUSE="" |
| RESTRICT="mirror" |
| |
| DEPEND="virtual/linux-sources" |
| RDEPEND="${DEPEND}" |
| |
| SRC_DIR="${WORKDIR}/${REPO}/mst_backward_compatibility" |
| S="${SRC_DIR}" |
| |
| libdir="kernel/drivers/pci" |
| MODULES="mst_pci mst_pciconf" |
| |
| pkg_setup() { |
| ls "${ROOT}/usr/src" |
| # We cannot rely on auto detection because we have two kernels installed. |
| local KERNEL_PREFIX="lakitu-kernel" |
| case "${RT}" in |
| r) |
| KERNEL_PREFIX+="-rt" |
| ;; |
| *) |
| ;; |
| esac |
| KERNEL_DIR="$(find "${ROOT}/usr/src" -maxdepth 1 -name "${KERNEL_PREFIX}-[0-9]*")" |
| KBUILD_OUTPUT="${KERNEL_DIR}/build" |
| linux-mod_pkg_setup |
| } |
| |
| src_compile() { |
| # This abuses the linux-mod eclass, mostly because the kernel config does |
| # not live in the KERNEL_DIR. |
| for i in ${MODULES}; do |
| S="${SRC_DIR}/$i" |
| MODULE_NAMES="$i(${libdir}:${S})" |
| LIBELF="$("${CBUILD}-pkg-config" libelf --libs 2>/dev/null || echo -lelf)" |
| BUILD_PARAMS="HOST_LIBELF_LIBS=${LIBELF} CC=${CC}" |
| BUILD_PARAMS+=" -C ${KBUILD_OUTPUT} M=${S}/ LLVM=1 LLVM_IAS=1" |
| BUILD_TARGETS="modules" |
| linux-mod_src_compile |
| done |
| } |
| |
| src_install() { |
| # Sign the module first. |
| for i in ${MODULES}; do |
| S="${SRC_DIR}/$i" |
| cd ${S} |
| MODULE_NAMES="$i(${libdir}:${S})" |
| MODULE_OBJECT="$i.ko" |
| cp ${MODULE_OBJECT} ${MODULE_OBJECT}.orig |
| "${KBUILD_OUTPUT}"/scripts/sign-file \ |
| sha256 \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.pem \ |
| "${KBUILD_OUTPUT}"/certs/signing_key.x509 \ |
| ${MODULE_OBJECT} || die "signing failed" |
| |
| # Do not strip the module signature. |
| dostrip -x "/lib/modules/${KV_FULL}/${libdir}/${MODULE_OBJECT}" |
| linux-mod_src_install |
| done |
| |
| # Need to make sure we don't install file twice |
| # for vanilla and rt, or else the files will collide. |
| if [[ ${RT} = "v" ]]; then |
| insinto /etc/modprobe.d |
| doins ${FILESDIR}/mellanox-nnt-linux-driver.conf |
| fi |
| } |