implement generation of JSONs for older drivers

This commit is contained in:
Mikhail Novosyolov 2021-10-04 02:59:43 +03:00
parent aba5c74734
commit 08b388ef30
3 changed files with 82 additions and 2 deletions

View file

@ -3,8 +3,8 @@ Name: auto-krokodil
Group: System/Kernel and hardware
License: GPLv3
Url: https://abf.io/import/auto-krokodil
Version: 0.1
Release: 2
Version: 0.2
Release: 1
BuildArch: noarch
# for php -l (syntax check)
BuildRequires: /usr/bin/php
@ -24,6 +24,8 @@ Source21: test.nvidia470.json
Source22: LICENSE.nvidia-json
Source23: test.spec.in
Source31: krokodil-legacy-converter.php
%description
Scripts to automate packaging and installation of proprietary drivers for Nvidia GPUs
@ -59,6 +61,21 @@ Generators of RPM provides for proprietary Nvidia drivers
#----------------------------------------
%package legacy-converter
Summary: Convert JSON from newer Nvidia driver to an older one
Requires: /usr/bin/php
%description legacy-converter
Old Nvidia drivers do not have a JSON with supported models,
but JSONs of newer drivers specify GPUs supported by older drivers.
This scripts takes a JSON from a newer driver and converts it
into a JSON for an older driver which does not ship a native JSON.
%files legacy-converter
%{_bindir}/krokodil-legacy-converter
#----------------------------------------
%prep
%build
@ -73,9 +90,12 @@ install -m0755 %{SOURCE10} %{buildroot}%{_bindir}/krokodil-rpm-provides
mkdir -p %{buildroot}%{_fileattrsdir}
install -m0644 %{SOURCE11} %{buildroot}%{_fileattrsdir}/krokodilnvidia.attr
install -m0755 %{SOURCE31} %{buildroot}%{_bindir}/krokodil-legacy-converter
%check
# check syntax
/usr/bin/php -l %{buildroot}%{_bindir}/krokodil-rpm-provides
/usr/bin/php -l %{buildroot}%{_bindir}/krokodil-legacy-converter
# very basic check of the generator
FILE="%{SOURCE21}" EVR=888-777 %{buildroot}%{_bindir}/krokodil-rpm-provides | grep -q '^nvidia-blob-devid(1f9d) = 888-777$'

View file

@ -0,0 +1,57 @@
#!/usr/bin/php
<?php
/* Old Nvidia drivers do not have a JSON with supported models,
* but JSONs of newer drivers specify GPUs supported by older drivers.
* This scripts takes a JSON from a newer driver and converts it
* into a JSON for an older driver which does not ship a native JSON. */
define("EXIT_CODE_EINPUT", 10);
define("EXIT_CODE_PARSEERROR", 20);
$FILE = getenv("FILE");
if (empty($FILE)) {
fwrite(STDERR, "Env FILE is not set! Set FILE=supported-gpus.json" . PHP_EOL);
exit(EXIT_CODE_EINPUT);
}
$BRANCH = getenv("BRANCH");
if (empty($BRANCH)) {
fwrite(STDERR, "Env BRANCH is not set! Set e.g. ENV=390 to generate JSON for branch 390.xx" . PHP_EOL);
exit(EXIT_CODE_EINPUT);
}
$data = file_get_contents($FILE);
$array = json_decode($data);
if (empty($array)) {
fwrite(STDERR, "Error decoding JSON from file " . $FILE . " !" . PHP_EOL);
exit(EXIT_CODE_EINPUT);
}
$chips_arr = array();
foreach($array->chips as $chip) {
if (empty($chip->legacybranch))
continue;
// php 8+ has str_starts_with()
if (!(strpos($chip->legacybranch, $BRANCH . ".", 0) === 0))
continue;
// devid (Device ID) cannot be empty, other params can be empty
if (empty($chip->devid)) {
fwrite(STDERR, "Device ID cannot be empty!" . PHP_EOL);
exit(EXIT_CODE_PARSEERROR);
}
$arr = array("devid" => $chip->devid,
"subdevid" => $chip->subdevid,
"subvendorid" => $chip->subvendorid,
"name" => $chip->name,
"features" => $chip->features);
array_push($chips_arr, $arr);
}
$chips_arr = array("chips" => $chips_arr);
echo json_encode($chips_arr);
?>

View file

@ -2,6 +2,9 @@
<?php
/* Proprietary Nvidia drivers ship JSONs which specify which GPUs
* are supported by the driver. This script creates RPM provides from it. */
define("EXIT_CODE_EINPUT", 10);
define("EXIT_CODE_PARSEERROR", 20);