diff mbox series

[canonical-kernel-snaps,RFC,1/1] nvidia hooks: add hooks for nvidia kernel components

Message ID 20241120000421.2961549-2-aaron.jauregui@canonical.com
State New
Headers show
Series add nvidia-550 driver | expand

Commit Message

Aaron Jauregui Nov. 20, 2024, 12:02 a.m. UTC
BugLink: https://bugs.launchpad.net/bugs/2088970

Add required hooks for kernel components. module install and remove
hooks should be generic with a special case for nouveau to be compatible
with nvidia drivers. Also adding kernel-gpu-2404 mangler script, meant
to set nvidia library paths for nvidia-550-user.

Signed-off-by: Aaron Jauregui <aaron.jauregui@canonical.com>
---
 hooks/install.module                   | 21 +++++++++++++++++++++
 hooks/install.nvidia-ko                | 25 +++++++++++++++++++++++++
 hooks/install.nvidia-user              | 18 ++++++++++++++++++
 hooks/install.pc-kernel                |  4 ++++
 hooks/kernel-gpu-2404-provider-mangler | 12 ++++++++++++
 hooks/remove.module                    | 13 +++++++++++++
 hooks/remove.nvidia-ko                 |  6 ++++++
 hooks/remove.nvidia-user               | 10 ++++++++++
 8 files changed, 109 insertions(+)
 create mode 100644 hooks/install.module
 create mode 100644 hooks/install.nvidia-ko
 create mode 100644 hooks/install.nvidia-user
 create mode 100644 hooks/install.pc-kernel
 create mode 100644 hooks/kernel-gpu-2404-provider-mangler
 create mode 100644 hooks/remove.module
 create mode 100644 hooks/remove.nvidia-ko
 create mode 100644 hooks/remove.nvidia-user
diff mbox series

Patch

diff --git a/hooks/install.module b/hooks/install.module
new file mode 100644
index 0000000..739c513
--- /dev/null
+++ b/hooks/install.module
@@ -0,0 +1,21 @@ 
+#!/bin/bash
+# Generic install hook for kernel modules
+
+set -eux
+
+name="$(echo $SNAP_COMPONENT_NAME | cut -d+ -f2)"
+
+# nouveau needs a special case to override nvidia modules
+if [ "$name" = "nouveau" ] ; then
+	dest="$SNAP_DATA/modules/$(uname -r)/graphics"
+else
+	dest="$SNAP_DATA/modules/$(uname -r)/$name"
+fi
+
+
+#clean up existing modules
+rm -rf "$dest"
+mkdir -p "$dest"
+
+find "$SNAP_COMPONENT" -name '*.ko' -exec cp '{}' "$dest" \;
+find "$SNAP_COMPONENT" -name '*.ko.zst' -exec cp '{}' "$dest" \;
diff --git a/hooks/install.nvidia-ko b/hooks/install.nvidia-ko
new file mode 100644
index 0000000..c4b5285
--- /dev/null
+++ b/hooks/install.nvidia-ko
@@ -0,0 +1,25 @@ 
+#!/bin/bash
+# install hook for nvidia drivers that require assembling
+
+set -eux
+
+# First setup the kernel modules
+tmp_dir="/tmp/nvidia-ko"
+rm -rf $tmp_dir
+mkdir $tmp_dir
+cp -r "$SNAP_COMPONENT"/bits $tmp_dir/bits
+
+cd $tmp_dir/bits
+
+sed -i "s|/usr/bin/ld.bfd|$SNAP_COMPONENT/bin/ld.bfd|" BUILD
+sed -i "s|make|$SNAP_COMPONENT/bin/make|" BUILD
+
+LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP_COMPONENT/lib/$(uname -m)-linux-gnu sh BUILD
+
+# Clean up directory before copying modules
+rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
+mkdir -p "$SNAP_DATA/modules/$(uname -r)/graphics"
+
+mv ../*.ko "$SNAP_DATA/modules/$(uname -r)/graphics/"
+
+rm -rf $tmp_dir
diff --git a/hooks/install.nvidia-user b/hooks/install.nvidia-user
new file mode 100644
index 0000000..176dc35
--- /dev/null
+++ b/hooks/install.nvidia-user
@@ -0,0 +1,18 @@ 
+#!/bin/bash
+# install hook for nvidia userspace drivers
+
+set -eux
+
+# Now setup the userspace libraries via kernel-gpu-2404 interface
+SENTINEL_FILE="$SNAP_COMMON"/kernel-gpu-2404/kernel-gpu-2404-sentinel
+
+mkdir -p "$SNAP_COMMON"/kernel-gpu-2404
+
+# Clean up existing installs
+rm -rf "$SNAP_COMMON"/kernel-gpu-2404/*
+
+cp -r "$SNAP_COMPONENT"/usr "$SNAP_COMMON"/kernel-gpu-2404
+cp "$SNAP_COMPONENT"/kernel-gpu-2404-provider-mangler "$SNAP_COMMON"/kernel-gpu-2404
+
+# put version information into sentinel file
+echo "$SNAP_COMPONENT_REVISION" > $SENTINEL_FILE
diff --git a/hooks/install.pc-kernel b/hooks/install.pc-kernel
new file mode 100644
index 0000000..32f3a78
--- /dev/null
+++ b/hooks/install.pc-kernel
@@ -0,0 +1,4 @@ 
+#!/bin/bash
+
+#install nouveau graphics as default
+snapctl install +nouveau
diff --git a/hooks/kernel-gpu-2404-provider-mangler b/hooks/kernel-gpu-2404-provider-mangler
new file mode 100644
index 0000000..ea032fd
--- /dev/null
+++ b/hooks/kernel-gpu-2404-provider-mangler
@@ -0,0 +1,12 @@ 
+#!/bin/bash
+
+
+ARCH_TRIPLET="$(arch)-linux-gnu"
+
+export OCL_ICD_VENDORS=${OCL_ICD_VENDORS:+$OCL_ICD_VENDORS:}${COMPONENT_PATH}/etc/OpenCL/vendors
+export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${COMPONENT_PATH}/usr/lib/${ARCH_TRIPLET}
+export __EGL_VENDOR_LIBRARY_DIRS=${__EGL_VENDOR_LIBRARY_DIRS:+$__EGL_VENDOR_LIBRARY_DIRS:}${COMPONENT_PATH}/usr/share/glvnd/egl_vendor.d
+export __EGL_EXTERNAL_PLATFORM_CONFIG_DIRS=${__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:+$__EGL_EXTERNAL_PLATFORM_CONFIG_DIRS:}${COMPONENT_PATH}/usr/share/egl/egl_external_platform.d
+export VK_LAYER_PATH=${VK_LAYER_PATH:+$VK_LAYER_PATH:}${COMPONENT_PATH}/usr/share/vulkan/implicit_layer.d/
+export XDG_DATA_DIRS=${XDG_DATA_DIRS:+$XDG_DATA_DIRS:}${COMPONENT_PATH}/usr/share
+export NVIDIA_DRIVER_ROOT=${COMPONENT_PATH}
diff --git a/hooks/remove.module b/hooks/remove.module
new file mode 100644
index 0000000..619bedf
--- /dev/null
+++ b/hooks/remove.module
@@ -0,0 +1,13 @@ 
+#!/bin/bash
+# Generic remove hook for kernel modules
+
+set -eux
+
+name="$(echo $SNAP_COMPONENT_NAME | cut -d+ -f2)"
+if [ "$name" = "nouveau" ] ; then
+	dest="$SNAP_DATA/modules/$(uname -r)/graphics"
+else
+	dest="$SNAP_DATA/modules/$(uname -r)/$name"
+fi
+
+rm -rf "$dest"
diff --git a/hooks/remove.nvidia-ko b/hooks/remove.nvidia-ko
new file mode 100644
index 0000000..5e2831d
--- /dev/null
+++ b/hooks/remove.nvidia-ko
@@ -0,0 +1,6 @@ 
+#!/bin/bash
+# Generic remove hook for kernel modules
+
+set -eux
+
+rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
diff --git a/hooks/remove.nvidia-user b/hooks/remove.nvidia-user
new file mode 100644
index 0000000..d7242b8
--- /dev/null
+++ b/hooks/remove.nvidia-user
@@ -0,0 +1,10 @@ 
+#!/bin/bash
+# Remove hook for nvidia drivers
+
+set -eux
+
+SENTINEL_FILE="$SNAP_COMMON"/kernel-gpu-2404/kernel-gpu-2404-sentinel
+
+rm $SENTINEL_FILE
+
+rm -rf "$SNAP_COMMON"/kernel-gpu-2404/*