Files
nvdriver/tools/extract_gsp_bindata.py
Eric Hartford ee935e18c4 gsp/turing: boot Turing (TU10x/TU11x) GSP-RM + 580.196.07 + CE class DB (#267, #268, #184)
Combines #267 (Turing FWSEC-FRTS, SEC2 Booter Load/Unload, bundled MIT
Booters, LibOS2 libos_init, debug/display-fuse guards, dynamic VRAM
reserve), #268 (GSP-RM 580.196.07 support + bundled Booters), and
selective ports from #184 (Turing 0x100c10-only sysmem flush + 40-bit
DMA check, Turing CE class DB 0x20802a06 / gsp_split_turing.rs, and
TU116 multi-gen RMAPI placeholder tests).

Fixes applied during integration:
- Keep #204's fw::bar1_identity_extent() in ga10x_mem.rs.
- Fix latent dmem_pa != 0 slice in fwsec2_build().
- Add #[repr(u8)] with V580_178_04 = 0 on GspFwRelease so
  Heap::<Ga10xGsp>::zeroed() is sound.

Verified with 32/32 offline/build/QEMU/gate checks (1,060 unit tests).

Co-authored-by: SpyrosPsarras <SpyrosPsarras@users.noreply.github.com>
Co-authored-by: Cavemanmining <Cavemanmining@users.noreply.github.com>
2026-12-02 18:10:46 +00:00

89 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Rebuild the SEC2 Booter and generic falcon bootloader images in src/nvidia/src/gpu/ucode/ from NVIDIA's
MIT-licensed open-gpu-kernel-modules checkout at tag 580.178.04 (src/nvidia/generated/g_bindata_*.c).
Booters are written as nvfw_bin_hdr + nvfw_hs_header_v2 + nvfw_hs_load_header_v2 with the production image and
signatures (the layout nouveau and linux-firmware use, and ga10x_gsp::parse_booter reads). --check compares
instead of writing; the GA102 images already in the tree reproduce byte for byte.
The images in ucode/ come from tag 580.178.04. --release 580.196.07 writes the Booters of a checkout of that tag
into ucode/580.196.07/ (its bootloaders are byte-identical to 580.178.04's, so they are not duplicated).
python3 tools/extract_gsp_bindata.py --ogkm ~/open-gpu-kernel-modules [--release 580.196.07] [--check]
"""
import argparse
import pathlib
import re
import struct
import sys
import zlib
UCODE = pathlib.Path(__file__).resolve().parent.parent / "src/nvidia/src/gpu/ucode"
BOOTERS = {
"booter_load_ga102.bin": "BooterLoadUcode_GA102",
"booter_unload_ga102.bin": "BooterUnloadUcode_GA102",
"booter_load_tu102.bin": "BooterLoadUcode_TU102",
"booter_unload_tu102.bin": "BooterUnloadUcode_TU102",
"booter_load_tu116.bin": "BooterLoadUcode_TU116",
"booter_unload_tu116.bin": "BooterUnloadUcode_TU116",
}
ENTRY = re.compile(
r'// FUNCTION: \w+\("(\w+)"\)\n(?://.*\n)*?// COMPRESSION: (\w+)\n(?://.*\n)*?'
r'static BINDATA_CONST NvU8 \w+\[\] = \s*\{([^}]*)\}'
)
def labels(path):
out = {}
for m in ENTRY.finditer(path.read_text()):
raw = bytes(int(x, 16) for x in re.findall(r"0x([0-9a-fA-F]{2})", m.group(3)))
out[m.group(1)] = zlib.decompress(raw, -15) if m.group(2) == "YES" else raw
return out
def booter(path):
b = labels(path)
sig = b["BINDATA_LABEL_SIG_PROD"]
tail = [b[k] for k in ("BINDATA_LABEL_PATCH_LOC", "BINDATA_LABEL_PATCH_SIG", "BINDATA_LABEL_PATCH_META",
"BINDATA_LABEL_NUM_SIGS", "BINDATA_LABEL_HEADER_PROD")]
offs, o = [], 0x18 + 0x24 + len(sig)
for t in tail:
offs.append(o)
o += len(t)
image = b["BINDATA_LABEL_IMAGE_PROD"]
hs = struct.pack("<9I", 0x3c, len(sig), offs[0], offs[1], offs[2], len(tail[2]), offs[3], offs[4], len(tail[4]))
size = o + len(image)
hdr = struct.pack("<6I", 0x10DE, 1, (size + 0xFF) & ~0xFF, 0x18, o, len(image))
return hdr + hs + sig + b"".join(tail) + image
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--ogkm", required=True, type=pathlib.Path)
ap.add_argument("--release", help="write the Booters into ucode/<release>/")
ap.add_argument("--check", action="store_true")
a = ap.parse_args()
gen = a.ogkm / "src/nvidia/generated"
images = {name: booter(gen / f"g_bindata_kgspGetBinArchive{src}.c") for name, src in BOOTERS.items()}
out = UCODE / a.release if a.release else UCODE
if not a.release:
bl = labels(gen / "g_bindata_ksec2GetBinArchiveBlUcode_TU102.c")
images["falcon_bl_tu102.bin"] = bl["BINDATA_LABEL_UCODE_IMAGE"]
if not a.check:
out.mkdir(exist_ok=True)
bad = 0
for name, data in images.items():
path = out / name
if a.check:
same = path.exists() and path.read_bytes() == data
print(("ok " if same else "DIFF ") + name)
bad += not same
else:
path.write_bytes(data)
print(f"wrote {name} ({len(data)} bytes)")
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main())