Files
chimera-gfx-Public/tools/build_phase10dm_observer.py
Chimera GFX release export a6037502d7
phase0-ci / build-and-audit (push) Successful in 2m14s
Publish Chimera GFX source
2026-09-03 03:27:14 +02:00

23 lines
1.6 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Derive the W^X linker script and build the offline Phase-1.0DM ELF."""
from __future__ import annotations
import argparse,hashlib,subprocess
from pathlib import Path
SDK_SCRIPT_SHA256="3bacf56a21602a1298752023a4c5b0c305954ddf6cdbce1464476fc9da9d9093"
def main():
p=argparse.ArgumentParser();p.add_argument("--root",type=Path,required=True);a=p.parse_args();root=a.root.resolve();sdk=root/"work/toolchains/ps5-payload-sdk-v0.41";source=sdk/"target/lib/main.script";raw=source.read_bytes()
if hashlib.sha256(raw).hexdigest()!=SDK_SCRIPT_SHA256:raise SystemExit("SDK linker script identity mismatch")
text=raw.decode();needle="ph_text PT_LOAD FLAGS (0x7);"
if text.count(needle)!=1:raise SystemExit("SDK text PHDR differs")
derived=text.replace(needle,"ph_text PT_LOAD FLAGS (0x5);")
out=root/"build/phase10dm";out.mkdir(parents=True,exist_ok=True);script=out/"observer-wx.script";script.write_text(derived,newline="\n")
source=root.parent/"chimera-retroarch/pkg/ps5/chimera_ps5_title_snapshot_observer.c";artifact=out/"chimera_title_snapshot_observer.elf";linkmap=out/"chimera_title_snapshot_observer.map"
if not source.is_file():raise SystemExit("target source missing")
def wsl(path):return "/mnt/c/"+path.as_posix().split(":/",1)[1]
command=f"set -euo pipefail; '{wsl(sdk)}/bin/prospero-clang' -std=c11 -Wall -Wextra -Werror -O2 -fno-common -Wl,-T,'{wsl(script)}' -Wl,-Map,'{wsl(linkmap)}' -o '{wsl(artifact)}' '{wsl(source)}'"
subprocess.run(["wsl.exe","bash","-lc",command],check=True)
return 0
if __name__=="__main__":raise SystemExit(main())