mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 14:38:47 +00:00
58 lines
2.6 KiB
Bash
Executable File
58 lines
2.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Fetches the 580.178.04 nv-kernel.o_binary that tools/extract_gv100_firmware.py needs, for hosts
|
|
# whose installed stock driver is a different version (for example 580.196.07).
|
|
#
|
|
# sh tools/fetch_580_kernel_object.sh [OUT_DIR] # default target/stock-580.178.04
|
|
# python3 tools/extract_gv100_firmware.py --rm-object OUT_DIR/nv-kernel.o_binary --family all
|
|
#
|
|
# It downloads NVIDIA's installer, or uses RUN_FILE=/path/to/NVIDIA-Linux-x86_64-580.178.04.run,
|
|
# and unpacks that one file from it. The installer is never executed: its header is only read for
|
|
# the line count that precedes the zstd archive. Nothing is installed and no module is touched.
|
|
# The result is checked against the digest the extractor requires. Needs curl, zstd, tar, sha256sum.
|
|
set -eu
|
|
VERSION=580.178.04
|
|
DIGEST=5269a23ffba19a17fe16f076463e7ad4151254659441d1711bee6c6221ff6f4b
|
|
RUN_NAME=NVIDIA-Linux-x86_64-$VERSION.run
|
|
URL=${URL:-https://us.download.nvidia.com/XFree86/Linux-x86_64/$VERSION/$RUN_NAME}
|
|
MEMBER=kernel/nvidia/nv-kernel.o_binary
|
|
cd "$(dirname "$0")/.."
|
|
OUT=${1:-target/stock-$VERSION}
|
|
mkdir -p "$OUT"
|
|
|
|
check() { [ "$(sha256sum "$1" | cut -d' ' -f1)" = "$DIGEST" ]; }
|
|
|
|
if [ -f "$OUT/nv-kernel.o_binary" ] && check "$OUT/nv-kernel.o_binary"; then
|
|
echo "$OUT/nv-kernel.o_binary already present and verified"
|
|
exit 0
|
|
fi
|
|
for tool in zstd tar sha256sum; do
|
|
command -v "$tool" >/dev/null 2>&1 || { echo "missing tool: $tool" >&2; exit 2; }
|
|
done
|
|
|
|
if [ -n "${RUN_FILE:-}" ]; then
|
|
RUN=$RUN_FILE
|
|
[ -f "$RUN" ] || { echo "RUN_FILE not found: $RUN" >&2; exit 2; }
|
|
else
|
|
RUN=$OUT/$RUN_NAME
|
|
if [ ! -f "$RUN" ]; then
|
|
command -v curl >/dev/null 2>&1 || { echo "missing tool: curl (or set RUN_FILE)" >&2; exit 2; }
|
|
echo "downloading $URL"
|
|
curl -fL --retry 3 -o "$RUN.part" "$URL"
|
|
mv "$RUN.part" "$RUN"
|
|
fi
|
|
fi
|
|
|
|
# The makeself header states how many lines precede the archive ("skip=<n>": archive starts at line n).
|
|
skip=$(head -n 40 "$RUN" | sed -n 's/^skip=\([0-9][0-9]*\)$/\1/p' | head -n 1)
|
|
[ -n "$skip" ] || { echo "$RUN: no skip=<n> line in the header; not a makeself installer?" >&2; exit 3; }
|
|
|
|
tmp=$(mktemp -d "$OUT/unpack.XXXXXX")
|
|
trap 'rm -rf "$tmp"' EXIT
|
|
tail -n +"$skip" "$RUN" | zstd -dc | tar -x -C "$tmp" --no-same-owner "$MEMBER" ||
|
|
{ echo "$RUN: could not unpack $MEMBER" >&2; exit 3; }
|
|
check "$tmp/$MEMBER" ||
|
|
{ echo "$RUN: $MEMBER is not the $VERSION object the firmware extractor expects" >&2; exit 4; }
|
|
mv "$tmp/$MEMBER" "$OUT/nv-kernel.o_binary"
|
|
echo "$OUT/nv-kernel.o_binary verified (sha256 $DIGEST)"
|
|
echo "next: python3 tools/extract_gv100_firmware.py --rm-object $OUT/nv-kernel.o_binary --family all"
|