blob: 7b43db269a53448b35a0651f8930e794fc161a85 [file] [log] [blame]
#
# Copyright 2024 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
FEATURES="xattr"
MODULES_OPTIONAL_USE="driver"
inherit flag-o-matic cos-linux-fw cos-linux-mod linux-mod multilib readme.gentoo-r1 \
systemd toolchain-funcs unpacker user-info
NV_URI="https://us.download.nvidia.com/tesla/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/download/index.aspx"
SRC_URI="${NV_URI}${PV}/NVIDIA-Linux-x86_64-${PV}.run
https://github.com/NVIDIA/open-gpu-kernel-modules/archive/refs/tags/${PV}.tar.gz -> open-gpu-kernel-modules-${PV}.tar.gz"
INSTALLER_NAME="NVIDIA-Linux-x86_64-${PV}"
RUNFILE="${INSTALLER_NAME}.run"
S="${WORKDIR}"
LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT openssl"
KEYWORDS="*"
SLOT="3/${PV%%.*}"
IUSE="+driver +clang +llvm_ias +xattr"
REQUIRED_USE="
llvm_ias? ( clang )
"
DEPEND=""
RDEPEND="${DEPEND}"
BDEPEND="dev-libs/openssl"
QA_PREBUILT="lib/firmware/* opt/nvidia/*"
src_unpack() {
cp ${DISTDIR}/${RUNFILE} ${S}
sh "${RUNFILE}" --extract-only
unpack "open-gpu-kernel-modules-${PV}.tar.gz"
}
pkg_setup() {
MODULE_NAMES="
nvidia(nvidia/${PV}:kernel-module-source:kernel-module-source/kernel-open)
nvidia-drm(nvidia/${PV}:kernel-module-source:kernel-module-source/kernel-open)
nvidia-modeset(nvidia/${PV}:kernel-module-source:kernel-module-source/kernel-open)
nvidia-peermem(nvidia/${PV}:kernel-module-source:kernel-module-source/kernel-open)
nvidia-uvm(nvidia/${PV}:kernel-module-source:kernel-module-source/kernel-open)"
KBUILD_OUTPUT="${KERNEL_DIR}/build"
linux-mod_pkg_setup
CXX="${CBUILD}-gcc"
BUILD_PARAMS="CXX=${CXX} KERNEL_SOURCES=${KV_DIR} KBUILD_OUTPUT=${KBUILD_OUTPUT} NV_VERBOSE=1 IGNORE_CC_MISMATCH=yes SYSSRC=${KV_DIR} SYSOUT=${KV_OUT_DIR}"
BUILD_TARGETS="modules"
}
src_prepare() {
mv open-gpu-kernel-modules-${PV} kernel-module-source || die
eapply "${FILESDIR}"/nvidia-drivers-525.60.13-ld.patch
use clang || cros_use_gcc
default
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP
if use llvm_ias; then
export LLVM_IAS=1
fi
cros_allow_gnu_build_tools
BUILD_FIXES="CFLAGS_MODULE='-Wno-error=strict-prototypes'" linux-mod_src_compile
}
src_install() {
if use module_sign ; then
TMP_DIR=$(mktemp -d)
DRIVERS_DIR="${TMP_DIR}/drivers"
FIRMWARE_DIR="${TMP_DIR}/firmware/nvidia/${PV}"
mkdir -p "${DRIVERS_DIR}"
mkdir -p "${FIRMWARE_DIR}"
MODULE_OBJECTS=(nvidia.ko nvidia-drm.ko nvidia-modeset.ko nvidia-peermem.ko nvidia-uvm.ko)
pushd kernel-module-source/kernel-open || die
for MODULE_OBJECT in "${MODULE_OBJECTS[@]}"; do
# Sign the nvidia modules.
cos-linux-mod_sign "${MODULE_OBJECT}" "${KBUILD_OUTPUT}/certs" || die "signing failed"
# copy the object file with extended attributes.
cp --preserve=all "${MODULE_OBJECT}" "${DRIVERS_DIR}"/
done
popd || die
FIRMWARE_OBJECTS=(gsp_tu10x.bin gsp_ga10x.bin)
pushd "${INSTALLER_NAME}"/firmware || die
for FIRMWARE_OBJECT in "${FIRMWARE_OBJECTS[@]}"; do
# Sign GSP firmware modules.
cos-linux-fw_sign "${FIRMWARE_OBJECT}" || die "signing failed"
# copy the object file with extended attributes.
cp --preserve=all "${FIRMWARE_OBJECT}" "${FIRMWARE_DIR}"/
done
popd || die
# Nvidia drivers are stored as build artifacts and not installed in image.
local source_dir=opt/google/drivers
dodir ${source_dir}
# tar the files with extended attributes.
tar --xattrs --xattrs-include=* -czf "${D}/${source_dir}/nvidia-drivers-${PV}.tgz" -C "${TMP_DIR}"/ . || die
rm -rf "${TMP_DIR}"
fi
}