From 50d00541f9fbadab4f98c5833f6ea863b54d219b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 11 Sep 2026 05:42:44 -0600 Subject: [PATCH] headless: run graduated modules for real on a disc, and add --firmware-from-disc Headless force-enabled HLE for everything the caller didn't name, so a run never exercised the graduated modules the way the app does. That is right for pspautotests, which is homebrew PRXes shipping none of the user libraries a retail disc carries - scePsmfPlayer and friends would have nothing real to run. It is wrong for a disc, which brings its own copies. Decide from the resolved boot list: a test batch, or a --vsh run with no file at all, keeps the homebrew treatment; exactly one non-executable target is a disc and is left alone. --firmware-from-disc installs the firmware most discs carry into a scratch NAND beside the memstick and boots against it, which is the version that game shipped with. Kept per disc so a second run reuses it. It goes after the point where the NAND root is settled, since that assignment is unconditional and would otherwise overwrite it - which it silently did until the sceFont check started depending on the answer. Co-Authored-By: Claude Opus 5 (1M context) --- Core/CmdLine.cpp | 1 + Core/CmdLine.h | 4 +++ headless/Headless.cpp | 64 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/Core/CmdLine.cpp b/Core/CmdLine.cpp index 419b0a1858..ff8345744c 100644 --- a/Core/CmdLine.cpp +++ b/Core/CmdLine.cpp @@ -212,6 +212,7 @@ static const CommandLineParam g_autoParams[] = { {POFF(unpackUpdater), CmdParamType::String, "unpack-updater", '\0', "Unpack the firmware in an updater EBOOT.PBP into DIR and exit", CmdLineMode::Headless}, {POFF(unpackUpdaterModel), CmdParamType::String, "unpack-updater-model", '\0', "PSP model to unpack for (01g..12g, default any)", CmdLineMode::Headless}, {POFF(unpackUpdaterFilter), CmdParamType::String, "unpack-updater-filter", '\0', "Only unpack entries under this path, e.g. flash0:/font/", CmdLineMode::Headless}, + {POFF(firmwareFromDisc), CmdParamType::Bool, "firmware-from-disc", '\0', "Install the firmware bundled on the booted disc and use it for this run", CmdLineMode::Headless}, {POFF(installPkg), CmdParamType::String, "install-pkg", '\0', "Install the game update in a .pkg into DIR and exit", CmdLineMode::Headless}, {POFF(reModule), CmdParamType::String, "re-module", '\0', "Load one PRX standalone and write a reverse-engineering report, then exit", CmdLineMode::Headless}, {POFF(reOut), CmdParamType::String, "re-out", '\0', "Directory for --re-module output (default: re-out)", CmdLineMode::Headless}, diff --git a/Core/CmdLine.h b/Core/CmdLine.h index a20df091e7..db58067838 100644 --- a/Core/CmdLine.h +++ b/Core/CmdLine.h @@ -88,6 +88,10 @@ struct CommandLineOptions { // (the default) to take whatever file list names each file first. std::optional unpackUpdaterModel; std::optional unpackUpdaterFilter; + // Headless: install the firmware bundled on the disc being booted into a scratch NAND, and + // boot against that. Lets a run exercise the paths that need real firmware modules without + // having to install one first. + std::optional firmwareFromDisc; // Bitmask of DisableHLEFlags: run the real firmware module instead of our HLE for those // libraries. Needs a firmware dump under the NAND directory. diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 62b518c7f4..bed12ab90a 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -289,6 +289,17 @@ static GraphicsContext *CreateGraphicsContext(GPUCore gpuCore, std::string **dev #endif } +// Whether what we're booting is homebrew rather than a retail disc. The two want opposite +// defaults for the graduated HLE modules - see where this is used. +// +// By extension, not by content: this runs before the loaders are up, and Identify_File can't even +// see the file yet. pspautotests is .prx, with .elf as its fallback, and that is the whole set we +// need to tell apart from a disc. +static bool BootTargetIsHomebrewExecutable(const std::string &filename) { + const std::string ext = Path(filename).GetFileExtension(); + return ext == ".prx" || ext == ".elf"; +} + struct AutoTestOptions { double timeout; double maxScreenshotError; @@ -781,13 +792,23 @@ int main(int argc, const char* argv[]) { // overrides above, so a matching command line flag always wins. cmdLineOptions.ApplyToConfig(); - // Run all modules as HLE - a headless run normally has no firmware to load them from, and the - // homebrew that pspautotests is made of doesn't ship the user libraries a retail disc does, so - // even the graduated modules (scePsmfPlayer and friends) have nothing real to run. An explicit - // --disable-hle means the caller does have what's needed and wants the real thing, so leave - // the modules they asked for alone - including the graduated ones, which is how you get a disc - // game's own libpsmfplayer.prx to run here the way it does in the app. - g_Config.iForceEnableHLE = 0xFFFFFFFF & ~g_Config.iDisableHLE; + // pspautotests is homebrew PRXes that ship none of the user libraries a retail disc carries, so + // the graduated modules (scePsmfPlayer and friends) would have nothing real to run and every + // test that touches them would fail on unresolved imports. Force those back to HLE. + // + // A disc is the opposite case: it brings its own copies and the app runs them for real, so + // headless has to as well or it isn't testing what ships. An explicit --disable-hle always + // wins, in either case, since the caller is saying they have what's needed. + // From the resolved list, not the command line: a test batch arrives as "@-" and is expanded + // above, and that is not a disc however it is spelled. A batch is always homebrew; a game run + // is exactly one disc. A --vsh run has no file at all and keeps the homebrew treatment, since + // the shell's own libraries come from the firmware rather than from a disc. + const bool bootIsDisc = testFilenames.size() == 1 && + !BootTargetIsHomebrewExecutable(testFilenames[0]); + if (!bootIsDisc) { + g_Config.iForceEnableHLE = 0xFFFFFFFF & ~g_Config.iDisableHLE; + } + // This looks contradictory to the above. But, this preserves the old test behavior which apparently ran the JIT for the CPU @@ -878,6 +899,35 @@ int main(int argc, const char* argv[]) { } g_Config.nandRootDirectory = GetSysDirectory(DIRECTORY_NAND); coreParameter.nandRoot = g_Config.nandRootDirectory; + + // Most discs carry the firmware they shipped with, which is the right version to run this game + // against and saves installing one by hand. Unpacked per disc and kept, so a second run of the + // same game reuses it - these are ~25MB each. + if (cmdLineOptions.firmwareFromDisc.value_or(false)) { + if (!bootIsDisc) { + fprintf(stderr, "--firmware-from-disc only applies when booting a disc\n"); + return 1; + } + const Path disc(testFilenames[0]); + const Path nand = g_Config.memStickDirectory / "PSP" / "NAND_FROM_DISC" / disc.GetFilename(); + if (File::Exists(nand / "flash0" / "kd")) { + printf("Reusing the firmware already unpacked from this disc at %s\n", nand.c_str()); + } else { + PSARUnpackOptions unpackOptions; + unpackOptions.verbose = testOptions.verbose; + PSARUnpackStats stats; + std::string unpackError; + if (!UnpackUpdater(disc, nand, unpackOptions, &stats, &unpackError)) { + fprintf(stderr, "Couldn't install the firmware on %s: %s\n", + disc.GetFilename().c_str(), unpackError.c_str()); + return 1; + } + printf("Installed firmware %s from the disc to %s (%d files)\n", + stats.firmwareVersion.c_str(), nand.c_str(), stats.written); + } + g_Config.nandRootDirectory = nand; + coreParameter.nandRoot = nand; + } // Placed here rather than with the other early-exit subcommands above, because resolving a // "flash0:/kd/foo.prx" module path needs nandRootDirectory, which is only settled just above. if (cmdLineOptions.reDecrypt.has_value()) {