Skip to content

Commit

Permalink
NVIDIA OOT modules
Browse files Browse the repository at this point in the history
Signed-off-by: Tanel Dettenborn <[email protected]>
  • Loading branch information
Tanel Dettenborn committed Oct 30, 2024
1 parent 0207766 commit 3602353
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 55 deletions.
113 changes: 70 additions & 43 deletions kernel/nvidia-oot.nix
Original file line number Diff line number Diff line change
@@ -1,58 +1,85 @@
# TODO: Should try to merge with upstream nixpkgs's open.nix nvidia driver
{ stdenv
, lib
, kernel
, gitRepos
, l4tVersion
{
stdenv,
kernel,
runCommand,
fetchurl,
lib,
buildPackages
}:
let
src = fetchurl {
url = "https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v3.0/sources/public_sources.tbz2";
hash = "sha256-6U2+ACWuMT7rYDBhaXr+13uWQdKgbfAiiIV0Vi3R9sU=";
};

source = runCommand "source" { } ''
tar xf ${src}
cd Linux_for_Tegra/source
mkdir $out
tar -C $out -xf kernel_oot_modules_src.tbz2
tar -C $out -xf nvidia_kernel_display_driver_source.tbz2
'';

stdenv.mkDerivation rec {
# unclear why we need this, but some part of nvidia's conftest doesn't pick up the headers otherwise
kernelIncludes = x: [
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include"
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/arch/${stdenv.hostPlatform.linuxArch}/include"
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include/uapi/"
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/arch/${stdenv.hostPlatform.linuxArch}/include/uapi/"
];
in
stdenv.mkDerivation {
pname = "nvidia-oot";
version = "jetson_${l4tVersion}";
inherit (kernel) version;

src = gitRepos."nvidia-oot";
src = source;
# Patch created like that:
# nix-build ./packages.nix -A nvidia-oot-cross.src
# mkdir source
# cp -r result/* source
# chmod -R +w source
# cd source
# git init .
# git add .
# git commit -m "Initial commit"
# <make changes>
# git diff > ../0001-build-fixes.patch
patches = [ ./0001-build-fixes.patch ];

#setSourceRoot = "sourceRoot=$(echo /build/linux-nv-oot-*)";
sourceRoot="linux-nv-oot-564ce2a";
postUnpack = ''
# make kernel headers readable for the nvidia build system.
cp -r ${kernel.dev} linux-dev
chmod -R u+w linux-dev
export KERNEL_HEADERS=$(pwd)/linux-dev/lib/modules/${kernel.modDirVersion}/build
nativeBuildInputs = kernel.moduleBuildDependencies;
'';

# makeFlags = kernel.makeFlags ++ [
makeFlags = [
"SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
"SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
"MODLIB=$(out)/lib/modules/${kernel.modDirVersion}"
"O=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
] ++ lib.optionals ((stdenv.buildPlatform != stdenv.hostPlatform) && stdenv.hostPlatform.isAarch64) [
"TARGET_ARCH=aarch64"
];
nativeBuildInputs = kernel.moduleBuildDependencies ++ [ ];

# Avoid an error in modpost: "__stack_chk_guard" [.../nvidia.ko] undefined
# NIX_CFLAGS_COMPILE = "-fno-stack-protector";
# some calls still go to `gcc` in the build
depsBuildBuild = [ buildPackages.stdenv.cc ];

postUnpack = ''
cd linux-nv-oot-564ce2a
sourceRoot=$(pwd -P)
cat >> Makefile <<EOF
makeFlags =
[
"ARCH=${stdenv.hostPlatform.linuxArch}"
"INSTALL_MOD_PATH=${placeholder "out"}"
"modules"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"CROSS_COMPILE=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}"
];

all:
env > /dev/stdout
make -C $SYSOUT
CROSS_COMPILE = lib.optionalString (
stdenv.hostPlatform != stdenv.buildPlatform
) "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}";

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
hardeningDisable = [ "pic" ];

EOF
'';
preBuildPhase = ''
echo prebuildphase
'';
# unclear why we need to add nvidia-oot/sound/soc/tegra-virt-alt/include
# this only happens in the nix-sandbox and not in the nix-shell
NIX_CFLAGS_COMPILE = "-fno-stack-protector -Wno-error=attribute-warning -I ${source}/nvidia-oot/sound/soc/tegra-virt-alt/include ${
lib.concatMapStrings (x: "-isystem ${x} ") (kernelIncludes kernel.dev)
}";

installTargets = [ "modules_install" ];
enableParallelBuilding = true;

passthru.meta = {
license = with lib.licenses; [ mit /* OR */ gpl2Only ];
};
}
14 changes: 5 additions & 9 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,11 @@ in
'';

# For Orin. Unsupported with PREEMPT_RT.
# boot.extraModulePackages = lib.optional
# (
# !cfg.kernel.realtime
# )
# config.boot.kernelPackages.nvidia-oot ;
# # FIXME
# # config.boot.kernelPackages.nvgpu
# #config.boot.kernelPackages.nvidia-display-driver

boot.extraModulePackages = lib.optional
(
!cfg.kernel.realtime
)
config.boot.kernelPackages.nvidia-oot ;

hardware.firmware = with pkgs.nvidia-jetpack; [
l4t-firmware
Expand Down
4 changes: 1 addition & 3 deletions overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ in
tests = prev.callPackages ./pkgs/tests { inherit l4tVersion; };

kernelPackagesOverlay = final: prev: {
# nvidia-display-driver = self.callPackage ./kernel/display-driver.nix { };
#nvgpu = self.callPackage ./kernel/nvgpu.nix { };
# nvidia-oot = self.callPackage ./kernel/nvidia-oot.nix { };
nvidia-oot = self.callPackage ./kernel/nvidia-oot.nix { };
};

kernel = self.callPackage ./kernel { kernelPatches = [ ]; };
Expand Down

0 comments on commit 3602353

Please sign in to comment.