mirror of
https://github.com/keylase/nvidia-patch.git
synced 2024-11-23 05:57:21 +00:00
linux: support patching the Flatpak NVIDIA driver
This adds support for patching the Flatpak version of NVIDIA driver by passing the `-f` flag to either patch.sh or patch-fbc.sh. Just like when patching the host driver, patching the Flatpak driver also creates a backup file automatically (with the .flatpak suffix)
This commit is contained in:
parent
a8ad07af8e
commit
e2f7ad79cc
49
patch-fbc.sh
49
patch-fbc.sh
@ -7,10 +7,12 @@ set -euo pipefail ; # <- this semicolon and comment make options apply
|
|||||||
backup_path="/opt/nvidia/libnvidia-fbc-backup"
|
backup_path="/opt/nvidia/libnvidia-fbc-backup"
|
||||||
silent_flag=''
|
silent_flag=''
|
||||||
manual_driver_version=''
|
manual_driver_version=''
|
||||||
|
flatpak_flag=''
|
||||||
|
backup_suffix=''
|
||||||
|
|
||||||
print_usage() { printf '
|
print_usage() { printf '
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
patch-fbc.sh [-s] [-r|-h|-c VERSION|-l]
|
patch-fbc.sh [-s] [-r|-h|-c VERSION|-l|-f]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
The patch for Nvidia drivers to allow FBC on consumer devices
|
The patch for Nvidia drivers to allow FBC on consumer devices
|
||||||
@ -23,14 +25,14 @@ DESCRIPTION
|
|||||||
-l List supported driver versions
|
-l List supported driver versions
|
||||||
-d VERSION Use VERSION driver version when looking for libraries
|
-d VERSION Use VERSION driver version when looking for libraries
|
||||||
instead of using nvidia-smi to detect it.
|
instead of using nvidia-smi to detect it.
|
||||||
|
-f Enable support for Flatpak NVIDIA drivers.
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2209
|
# shellcheck disable=SC2209
|
||||||
opmode="patch"
|
opmode="patch"
|
||||||
|
|
||||||
while getopts 'rshc:ld:' flag; do
|
while getopts 'rshc:ld:f' flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
r) opmode="${opmode}rollback" ;;
|
r) opmode="${opmode}rollback" ;;
|
||||||
s) silent_flag='true' ;;
|
s) silent_flag='true' ;;
|
||||||
@ -38,6 +40,7 @@ while getopts 'rshc:ld:' flag; do
|
|||||||
c) opmode="${opmode}checkversion" ; checked_version="$OPTARG" ;;
|
c) opmode="${opmode}checkversion" ; checked_version="$OPTARG" ;;
|
||||||
l) opmode="${opmode}listversions" ;;
|
l) opmode="${opmode}listversions" ;;
|
||||||
d) manual_driver_version="$OPTARG" ;;
|
d) manual_driver_version="$OPTARG" ;;
|
||||||
|
f) flatpak_flag='true' ;;
|
||||||
*) echo "Incorrect option specified in command line" ; exit 2 ;;
|
*) echo "Incorrect option specified in command line" ; exit 2 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -46,6 +49,11 @@ if [[ $silent_flag ]]; then
|
|||||||
exec 1> /dev/null
|
exec 1> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $flatpak_flag ]]; then
|
||||||
|
backup_suffix='.flatpak'
|
||||||
|
echo "WARNING: Flatpak flag enabled (-f), modifying ONLY the Flatpak driver."
|
||||||
|
fi
|
||||||
|
|
||||||
declare -A patch_list=(
|
declare -A patch_list=(
|
||||||
["435.27.08"]='s/\x85\xc0\x89\xc3\x0f\x85\x68\xfa\xff\xff/\x31\xc0\x89\xc3\x0f\x85\x68\xfa\xff\xff/'
|
["435.27.08"]='s/\x85\xc0\x89\xc3\x0f\x85\x68\xfa\xff\xff/\x31\xc0\x89\xc3\x0f\x85\x68\xfa\xff\xff/'
|
||||||
["440.26"]='s/\x85\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/\x31\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/'
|
["440.26"]='s/\x85\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/\x31\xc0\x89\xc3\x0f\x85\xa9\xfa\xff\xff/'
|
||||||
@ -203,6 +211,14 @@ check_version_supported () {
|
|||||||
[[ "${patch_list[$ver]+isset}" && "${object_list[$ver]+isset}" ]]
|
[[ "${patch_list[$ver]+isset}" && "${object_list[$ver]+isset}" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_flatpak_driver_path () {
|
||||||
|
# Flatpak's package versioning replaces '.' by '-'
|
||||||
|
version="$(echo "$1" | tr '.' '-')"
|
||||||
|
if path=$(flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-${version}" 2>/dev/null); then
|
||||||
|
echo "$path/files/lib"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
get_supported_versions () {
|
get_supported_versions () {
|
||||||
for drv in "${!patch_list[@]}"; do
|
for drv in "${!patch_list[@]}"; do
|
||||||
[[ "${object_list[$drv]+isset}" ]] && echo "$drv"
|
[[ "${object_list[$drv]+isset}" ]] && echo "$drv"
|
||||||
@ -246,6 +262,17 @@ patch_common () {
|
|||||||
patch="${patch_list[$driver_version]}"
|
patch="${patch_list[$driver_version]}"
|
||||||
object="${object_list[$driver_version]}"
|
object="${object_list[$driver_version]}"
|
||||||
|
|
||||||
|
if [[ $flatpak_flag ]]; then
|
||||||
|
driver_dir=$(get_flatpak_driver_path "$driver_version")
|
||||||
|
if [ -z "$driver_dir" ]; then
|
||||||
|
echo "ERROR: Flatpak package for driver $driver_version does not appear to be installed."
|
||||||
|
echo "Try rebooting your computer and/or running 'flatpak update'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# return early because the code below is out of scope for the Flatpak driver
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
declare -a driver_locations=(
|
declare -a driver_locations=(
|
||||||
'/usr/lib/x86_64-linux-gnu'
|
'/usr/lib/x86_64-linux-gnu'
|
||||||
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
|
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
|
||||||
@ -267,10 +294,10 @@ patch_common () {
|
|||||||
|
|
||||||
rollback () {
|
rollback () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
cp -p "$backup_path/$object.$driver_version" \
|
cp -p "$backup_path/$object.$driver_version$backup_suffix" \
|
||||||
"$driver_dir/$object.$driver_version"
|
"$driver_dir/$object.$driver_version"
|
||||||
echo "Restore from backup $object.$driver_version"
|
echo "Restore from backup $object.$driver_version$backup_suffix"
|
||||||
else
|
else
|
||||||
echo "Backup not found. Try to patch first."
|
echo "Backup not found. Try to patch first."
|
||||||
exit 1
|
exit 1
|
||||||
@ -279,8 +306,8 @@ rollback () {
|
|||||||
|
|
||||||
patch () {
|
patch () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version" | cut -f1 -d\ )"
|
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
||||||
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
||||||
if [[ "$bkp_hash" != "$drv_hash" ]] ; then
|
if [[ "$bkp_hash" != "$drv_hash" ]] ; then
|
||||||
echo "Backup exists and driver file differ from backup. Skipping patch."
|
echo "Backup exists and driver file differ from backup. Skipping patch."
|
||||||
@ -290,10 +317,10 @@ patch () {
|
|||||||
echo "Attention! Backup not found. Copying current $object to backup."
|
echo "Attention! Backup not found. Copying current $object to backup."
|
||||||
mkdir -p "$backup_path"
|
mkdir -p "$backup_path"
|
||||||
cp -p "$driver_dir/$object.$driver_version" \
|
cp -p "$driver_dir/$object.$driver_version" \
|
||||||
"$backup_path/$object.$driver_version"
|
"$backup_path/$object.$driver_version$backup_suffix"
|
||||||
fi
|
fi
|
||||||
sha1sum "$backup_path/$object.$driver_version"
|
sha1sum "$backup_path/$object.$driver_version$backup_suffix"
|
||||||
sed "$patch" "$backup_path/$object.$driver_version" > \
|
sed "$patch" "$backup_path/$object.$driver_version$backup_suffix" > \
|
||||||
"${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
"${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
||||||
sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
||||||
ldconfig
|
ldconfig
|
||||||
|
48
patch.sh
48
patch.sh
@ -7,10 +7,12 @@ set -euo pipefail ; # <- this semicolon and comment make options apply
|
|||||||
backup_path="/opt/nvidia/libnvidia-encode-backup"
|
backup_path="/opt/nvidia/libnvidia-encode-backup"
|
||||||
silent_flag=''
|
silent_flag=''
|
||||||
manual_driver_version=''
|
manual_driver_version=''
|
||||||
|
flatpak_flag=''
|
||||||
|
backup_suffix=''
|
||||||
|
|
||||||
print_usage() { printf '
|
print_usage() { printf '
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
patch.sh [-s] [-r|-h|-c VERSION|-l]
|
patch.sh [-s] [-r|-h|-c VERSION|-l|-f]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
The patch for Nvidia drivers to remove NVENC session limit
|
The patch for Nvidia drivers to remove NVENC session limit
|
||||||
@ -23,13 +25,14 @@ DESCRIPTION
|
|||||||
-l List supported driver versions
|
-l List supported driver versions
|
||||||
-d VERSION Use VERSION driver version when looking for libraries
|
-d VERSION Use VERSION driver version when looking for libraries
|
||||||
instead of using nvidia-smi to detect it.
|
instead of using nvidia-smi to detect it.
|
||||||
|
-f Enable support for Flatpak NVIDIA drivers.
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2209
|
# shellcheck disable=SC2209
|
||||||
opmode="patch"
|
opmode="patch"
|
||||||
|
|
||||||
while getopts 'rshc:ld:' flag; do
|
while getopts 'rshc:ld:f' flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
r) opmode="${opmode}rollback" ;;
|
r) opmode="${opmode}rollback" ;;
|
||||||
s) silent_flag='true' ;;
|
s) silent_flag='true' ;;
|
||||||
@ -37,6 +40,7 @@ while getopts 'rshc:ld:' flag; do
|
|||||||
c) opmode="${opmode}checkversion" ; checked_version="$OPTARG" ;;
|
c) opmode="${opmode}checkversion" ; checked_version="$OPTARG" ;;
|
||||||
l) opmode="${opmode}listversions" ;;
|
l) opmode="${opmode}listversions" ;;
|
||||||
d) manual_driver_version="$OPTARG" ;;
|
d) manual_driver_version="$OPTARG" ;;
|
||||||
|
f) flatpak_flag='true' ;;
|
||||||
*) echo "Incorrect option specified in command line" ; exit 2 ;;
|
*) echo "Incorrect option specified in command line" ; exit 2 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -45,6 +49,11 @@ if [[ $silent_flag ]]; then
|
|||||||
exec 1> /dev/null
|
exec 1> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $flatpak_flag ]]; then
|
||||||
|
backup_suffix='.flatpak'
|
||||||
|
echo "WARNING: Flatpak flag enabled (-f), modifying ONLY the Flatpak driver."
|
||||||
|
fi
|
||||||
|
|
||||||
declare -A patch_list=(
|
declare -A patch_list=(
|
||||||
["375.39"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
|
["375.39"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
|
||||||
["390.77"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
|
["390.77"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
|
||||||
@ -276,6 +285,14 @@ check_version_supported () {
|
|||||||
[[ "${patch_list[$ver]+isset}" && "${object_list[$ver]+isset}" ]]
|
[[ "${patch_list[$ver]+isset}" && "${object_list[$ver]+isset}" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_flatpak_driver_path () {
|
||||||
|
# Flatpak's package versioning replaces '.' by '-'
|
||||||
|
version="$(echo "$1" | tr '.' '-')"
|
||||||
|
if path=$(flatpak info --show-location "org.freedesktop.Platform.GL.nvidia-${version}" 2>/dev/null); then
|
||||||
|
echo "$path/files/lib"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
get_supported_versions () {
|
get_supported_versions () {
|
||||||
for drv in "${!patch_list[@]}"; do
|
for drv in "${!patch_list[@]}"; do
|
||||||
[[ "${object_list[$drv]+isset}" ]] && echo "$drv"
|
[[ "${object_list[$drv]+isset}" ]] && echo "$drv"
|
||||||
@ -319,6 +336,17 @@ patch_common () {
|
|||||||
patch="${patch_list[$driver_version]}"
|
patch="${patch_list[$driver_version]}"
|
||||||
object="${object_list[$driver_version]}"
|
object="${object_list[$driver_version]}"
|
||||||
|
|
||||||
|
if [[ $flatpak_flag ]]; then
|
||||||
|
driver_dir=$(get_flatpak_driver_path "$driver_version")
|
||||||
|
if [ -z "$driver_dir" ]; then
|
||||||
|
echo "ERROR: Flatpak package for driver $driver_version does not appear to be installed."
|
||||||
|
echo "Try rebooting your computer and/or running 'flatpak update'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# return early because the code below is out of scope for the Flatpak driver
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
declare -a driver_locations=(
|
declare -a driver_locations=(
|
||||||
'/usr/lib/x86_64-linux-gnu'
|
'/usr/lib/x86_64-linux-gnu'
|
||||||
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
|
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
|
||||||
@ -340,10 +368,10 @@ patch_common () {
|
|||||||
|
|
||||||
rollback () {
|
rollback () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
cp -p "$backup_path/$object.$driver_version" \
|
cp -p "$backup_path/$object.$driver_version$backup_suffix" \
|
||||||
"$driver_dir/$object.$driver_version"
|
"$driver_dir/$object.$driver_version"
|
||||||
echo "Restore from backup $object.$driver_version"
|
echo "Restore from backup $object.$driver_version$backup_suffix"
|
||||||
else
|
else
|
||||||
echo "Backup not found. Try to patch first."
|
echo "Backup not found. Try to patch first."
|
||||||
exit 1
|
exit 1
|
||||||
@ -352,8 +380,8 @@ rollback () {
|
|||||||
|
|
||||||
patch () {
|
patch () {
|
||||||
patch_common
|
patch_common
|
||||||
if [[ -f "$backup_path/$object.$driver_version" ]]; then
|
if [[ -f "$backup_path/$object.$driver_version$backup_suffix" ]]; then
|
||||||
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version" | cut -f1 -d\ )"
|
bkp_hash="$(sha1sum "$backup_path/$object.$driver_version$backup_suffix" | cut -f1 -d\ )"
|
||||||
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
drv_hash="$(sha1sum "$driver_dir/$object.$driver_version" | cut -f1 -d\ )"
|
||||||
if [[ "$bkp_hash" != "$drv_hash" ]] ; then
|
if [[ "$bkp_hash" != "$drv_hash" ]] ; then
|
||||||
echo "Backup exists and driver file differ from backup. Skipping patch."
|
echo "Backup exists and driver file differ from backup. Skipping patch."
|
||||||
@ -363,10 +391,10 @@ patch () {
|
|||||||
echo "Attention! Backup not found. Copying current $object to backup."
|
echo "Attention! Backup not found. Copying current $object to backup."
|
||||||
mkdir -p "$backup_path"
|
mkdir -p "$backup_path"
|
||||||
cp -p "$driver_dir/$object.$driver_version" \
|
cp -p "$driver_dir/$object.$driver_version" \
|
||||||
"$backup_path/$object.$driver_version"
|
"$backup_path/$object.$driver_version$backup_suffix"
|
||||||
fi
|
fi
|
||||||
sha1sum "$backup_path/$object.$driver_version"
|
sha1sum "$backup_path/$object.$driver_version$backup_suffix"
|
||||||
sed "$patch" "$backup_path/$object.$driver_version" > \
|
sed "$patch" "$backup_path/$object.$driver_version$backup_suffix" > \
|
||||||
"${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
"${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
||||||
sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
sha1sum "${PATCH_OUTPUT_DIR-$driver_dir}/$object.$driver_version"
|
||||||
ldconfig
|
ldconfig
|
||||||
|
Loading…
Reference in New Issue
Block a user