mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Portable resolver for the reference NVIDIA 580.178.04 `nv-kernel.o_binary`."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import os
|
|
from pathlib import Path
|
|
|
|
REFERENCE_580_SHA256 = "5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b"
|
|
LEGACY_580_BINARY = Path(
|
|
"/home/geodd/nvidia-driver/analysis-580.178.04/extracted/kernel/nvidia/nv-kernel.o_binary"
|
|
)
|
|
SYSTEM_580_CANDIDATES = (
|
|
Path("/usr/src/nvidia-580.178.04/nvidia/nv-kernel.o_binary"),
|
|
Path("/usr/src/nvidia-srv-580.178.04/nvidia/nv-kernel.o_binary"),
|
|
)
|
|
|
|
|
|
def verify_580_binary(path: Path, expected_sha256: str = REFERENCE_580_SHA256) -> str:
|
|
"""Verify `path` exists and matches the reference 580.178.04 SHA-256 digest."""
|
|
if not path.is_file():
|
|
raise SystemExit(f"reference 580.178.04 binary not found: {path}")
|
|
actual = hashlib.sha256(path.read_bytes()).hexdigest()
|
|
if actual != expected_sha256:
|
|
raise SystemExit(
|
|
f"reference 580.178.04 binary digest mismatch for {path}: "
|
|
f"got {actual}, expected {expected_sha256}"
|
|
)
|
|
return actual
|
|
|
|
|
|
def resolve_580_binary(*, verify: bool = False) -> Path:
|
|
"""Resolve `nv-kernel.o_binary` via env overrides, system `/usr/src`, or legacy path."""
|
|
path: Path | None = None
|
|
explicit = os.environ.get("NV_RS_580_BINARY")
|
|
if explicit:
|
|
path = Path(explicit)
|
|
else:
|
|
analysis_root = os.environ.get("NV_RS_ANALYSIS_ROOT")
|
|
if analysis_root:
|
|
cand = Path(analysis_root) / "extracted/kernel/nvidia/nv-kernel.o_binary"
|
|
if cand.is_file():
|
|
path = cand
|
|
if path is None:
|
|
for cand in SYSTEM_580_CANDIDATES:
|
|
if cand.is_file():
|
|
path = cand
|
|
break
|
|
if path is None:
|
|
path = LEGACY_580_BINARY
|
|
if verify:
|
|
verify_580_binary(path)
|
|
return path
|
|
|
|
|
|
if __name__ == "__main__":
|
|
p = resolve_580_binary()
|
|
print(f"resolved 580 binary: {p} (exists={p.is_file()})")
|