#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Which GameCube firmware images do we have? SHA-1s only; nothing is copied or kept. Firmware is Nintendo's (and the drive's maker's) and is never committed, copied, traced or disassembled in this repository (docs/ipl.md). This script hashes candidates in place (zip members are read in memory, never extracted) and matches them against the SHA-1 list below: - the IPL (boot ROM, 2 MiB, read through EXI) of each console revision; - the DVD drive's firmware (128 KiB, the drive controller's program); - the DSP's instruction ROM (8 KiB) and coefficient ROM (4 KiB), which are inside Flipper. Where it looks: - ``$REDUMP_DIR/Nintendo - GameCube - BIOS Images``: Redump's dumps (zips and loose .bin); - ``$MAME_ROMPATH``: MAME's ``gcjp``, ``gcus``, ``gceu``, ``gcbr`` and ``triforce`` sets. REDUMP_DIR=... MAME_ROMPATH=... python -I scripts/census_bios.py The SHA-1 list is fact data, not firmware. Sources: Redump's "Nintendo - GameCube - BIOS Images (16) (2021-09-18)" datfile (authors ElBarto, Jackal, Extrems) for the IPLs, NPDP and development boot ROMs and drive firmware; ``mame -listxml gcjp gcus gceu gcbr triforce`` (MAME 0.285) for the DSP ROMs and the Triforce boot ROM. Both are OBSERVED (a dumping group's and an emulator's records), not hardware documents. """ from __future__ import annotations import hashlib import os import sys import zipfile from pathlib import Path # SHA-1 -> (kind, name, description, source) KNOWN = { "a1837968288253ed541f2b11440b68f5a9b33875": ("ipl", "gc-ntsc-10", "DOL-001(USA/JPN), DOT-001, SL-GC10 (NTSC 1.0)", "redump; mame gcjp v10"), "239eacd86527ff9a75aeb7282da65797baeef010": ("ipl", "gc-ntsc-11", "DOL-001(USA/JPN), DOT-001 (NTSC 1.1)", "redump; mame gcjp v11"), "96f69a21645de73a5ba61e57951ef303d55788c5": ("ipl", "gc-ntsc-12-001", "DOL-001(USA/JPN) (NTSC 1.2)", "redump"), "ef9194ab4804aa0aa8540d846caf291b28331165": ("ipl", "gc-ntsc-12-101", "DOL-101(USA/JPN) (NTSC 1.2)", "redump; mame gcjp v12"), "f27c63e5394e2fd1606f70df004c4fc2d6027700": ("ipl", "gc-pal-10", "DOL-001(EUR), DOT-001P (PAL 1.0)", "redump; mame gceu v10"), "f3cd0c7c61cbcefa85e7de3aff4cfa50bc508714": ("ipl", "gc-pal-11", "DOL-002(BRA) (MPAL 1.1)", "redump; mame gcbr"), "80b8744ff5e43585392f55546bd03a673d11ef5f": ("ipl", "gc-pal-12", "DOL-101(EUR) (PAL 1.2)", "redump; mame gceu v12"), "338b11ee65e868d0e1b37dcf93de4ecad62a16b4": ("ipl-dev", "gc-npdp-ntsc", "DOT-002 (NPDP, NTSC 1.0)", "redump"), "7eaf7922ae96bc40910f4401f6e501be2ad3b3f1": ("ipl-dev", "gc-npdp-pal", "DOT-002P (NPDP, PAL 1.0)", "redump"), "588c251dd3a7555509f36f729dedd1aa2f4f1613": ("ipl-dev", "gc-tdev", "DOT-006 (devkit boot ROM 1.0, 48 MB)", "redump"), "318b532bc149657a0ba3b6c65909ca231f347aaa": ("ipl-dev", "gc-npdp-gdev", "GCT-0100 (devkit boot ROM 0.93a)", "redump"), "27872c201e87b06a19bf85d36c796ef383f8d52d": ("drive", "gc-dvd-20010608", "GC-D2 B (2001-06-08)", "redump; mame gcjp 20010608.bin"), "ed00b63e9f56b295ebe08b4fa0e5ca83814cb31e": ("drive", "gc-nr-dvd-20010608", "GC-RD2 A (NR reader, 2001-06-08)", "redump"), "ae7233cae8f94749796e0b740d6021e3b00a8926": ("drive", "gc-dvd-20010831", "GC-D3 (2001-08-31)", "redump"), "691e46213d8428befdf568157e670b971ab94e1d": ("drive", "gc-dvd-20020402", "GC-D2 C (2002-04-02)", "redump"), "2faaf92bcaffe675f54f7249d30f3791507e22ab": ("drive", "gc-dvd-20020823", "GC-D2 D (2002-08-23)", "redump"), "3c6cc6e04fdd0b2a392d7a6ed769455444846be7": ("dsp-irom", "dsp_rom.bin", "DSP instruction ROM, 8 KiB", "mame gcjp"), "c116d867ba001dcd6bf6d399ff4bf38d340f556c": ("dsp-coef", "dsp_coef.bin", "DSP coefficient ROM, 4 KiB", "mame gcjp"), "c3cb7227e4dbc2af861e76d00cb59726105a2e4c": ("triforce", "triforce_bootrom.bin", "Triforce boot ROM (not a GameCube IPL)", "mame triforce"), } MAME_SETS = ("gcjp", "gcus", "gceu", "gcbr", "triforce") REDUMP_BIOS = "Nintendo - GameCube - BIOS Images" def sha1(data: bytes) -> str: return hashlib.sha1(data).hexdigest() def candidates(redump: Path | None, mame: Path | None): """Yield (label, size, sha1) for every candidate image, hashed in memory.""" if redump and redump.is_dir(): for path in sorted(redump.iterdir()): if path.suffix.lower() == ".zip": with zipfile.ZipFile(path) as archive: for info in archive.infolist(): if not info.is_dir(): yield f"redump/{path.name}:{info.filename}", info.file_size, sha1(archive.read(info)) elif path.suffix.lower() == ".bin": yield f"redump/{path.name}", path.stat().st_size, sha1(path.read_bytes()) if mame and mame.is_dir(): for name in MAME_SETS: path = mame / f"{name}.zip" if path.exists(): with zipfile.ZipFile(path) as archive: for info in archive.infolist(): if not info.is_dir(): yield f"mame/{name}.zip:{info.filename}", info.file_size, sha1(archive.read(info)) def main() -> int: redump_root = os.environ.get("REDUMP_DIR") mame_root = os.environ.get("MAME_ROMPATH") if not redump_root and not mame_root: print("set REDUMP_DIR and/or MAME_ROMPATH", file=sys.stderr) return 2 redump = Path(redump_root) / REDUMP_BIOS if redump_root else None mame = Path(mame_root.split(";")[0]) if mame_root else None found: dict[str, list[str]] = {} unknown = [] count = 0 for label, size, digest in candidates(redump, mame): count += 1 if digest in KNOWN: found.setdefault(digest, []).append(label) else: unknown.append((label, size, digest)) print(f"candidate images hashed: {count}") print(f"known SHA-1s: {len(KNOWN)}; present: {len(found)}; missing: {len(KNOWN) - len(found)}\n") for digest, (kind, name, description, source) in KNOWN.items(): where = found.get(digest) state = "HAVE" if where else "missing" print(f"{state:7} {kind:8} {name:20} {digest} {description} [{source}]") for label in where or []: print(f" at {label}") if unknown: print("\nimages whose SHA-1 is not in the list (not firmware we know, or a bad dump):") for label, size, digest in unknown: print(f" {label} {size} bytes {digest}") return 0 if __name__ == "__main__": sys.exit(main())