<# Lumen PSX - kernel recovery for the PlayStation Classic (Windows PowerShell 5.1 / 7) https://lpsx.dev/recovery Writes a kernel image to the console's BOOTIMG1 through Sony's fastboot mode. Use it when the console no longer starts after its kernel was being written (for example a power cut during "Restore Sony's kernel" in Lumen). powershell -ExecutionPolicy Bypass -File psc-recover.ps1 -Image powershell -ExecutionPolicy Bypass -File psc-recover.ps1 -Check (writes nothing) -Image is one of: - a backup made by Lumen: lumen\backup\kernel\BOOTIMG1-.img or lumen\backup\firmware\BOOTIMG1.img (copy them off the stick first) - Sony's stock kernel: LRECOVERY.EPB from a Project Eris / BleemSync backup, or a boot.img taken from it. The same file works on every PlayStation Classic. Needs fastboot.exe (Android SDK Platform-Tools for Windows, https://developer.android.com/tools/releases/platform-tools): unzip it and either add the folder to PATH, put this script in it, or pass -Fastboot C:\path\fastboot.exe. If the console shows up in Device Manager but fastboot does not see it, install the Google USB Driver, or with Zadig give the device 0BB4:0C01 the WinUSB driver. WSL2 is not needed (and does not see USB devices without usbipd-win). #> param( [string]$Image, [switch]$Check, [string]$Fastboot ) $ErrorActionPreference = 'Stop' $StockMd5 = '28ce5f6de4981764411393310311b517' # Sony's stock kernel partition, every console $Size = 8388608 function Die($msg) { Write-Host ""; Write-Host "ERROR: $msg" -ForegroundColor Red; exit 1 } # fastboot: -Fastboot, next to this script, or on PATH if (-not $Fastboot) { $local = Join-Path $PSScriptRoot 'fastboot.exe' if (Test-Path $local) { $Fastboot = $local } elseif (Get-Command fastboot -ErrorAction SilentlyContinue) { $Fastboot = (Get-Command fastboot).Source } } if (-not $Fastboot -or -not (Test-Path $Fastboot)) { Die "fastboot.exe was not found. Download Android SDK Platform-Tools for Windows from https://developer.android.com/tools/releases/platform-tools, unzip it, and put this script in that folder (or pass -Fastboot C:\path\fastboot.exe)." } function Devices { (& $Fastboot devices 2>$null) | Where-Object { $_ -match 'fastboot' } } function Wait-Console { Write-Host "" Write-Host "Waiting for the console in fastboot mode (up to 3 minutes). Now:" Write-Host " 1. Console unplugged and opened (screws under the rubber feet)." Write-Host " 2. Touch the two round pads on SIDE A of the board, right of the 'LM-11' print," Write-Host " with metal tweezers, and keep them there." Write-Host " 3. Plug the console's micro-USB into this computer (a data cable, not charge-only)." Write-Host " 4. When it is found, you can let go of the tweezers." for ($i = 1; $i -le 180; $i++) { $d = @(Devices) if ($d.Count -eq 1) { Write-Host ""; Write-Host "Console found: $($d[0])"; return } if ($d.Count -gt 1) { Die "more than one fastboot device is connected: leave only the console." } Start-Sleep -Seconds 1 if ($i % 15 -eq 0) { Write-Host " ... still waiting ($i s)" } } Die "no console in fastboot mode. Check the pads, the cable (data, not charge-only) and the driver (Device Manager: Google USB Driver, or WinUSB with Zadig for 0BB4:0C01). See https://lpsx.dev/recovery#troubleshooting" } function Md5Of($path) { (Get-FileHash -Algorithm MD5 -Path $path).Hash.ToLower() } if ($Check) { Wait-Console & $Fastboot getvar product 2>&1 | Select-Object -First 2 Write-Host "OK: the recovery path works on this console. Nothing was written." & $Fastboot reboot 2>$null | Out-Null exit 0 } if (-not $Image) { Get-Help $PSCommandPath; exit 2 } if (-not (Test-Path $Image)) { Die "no such file: $Image" } $Image = (Resolve-Path $Image).Path $work = Join-Path ([IO.Path]::GetTempPath()) ("psc-recover-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $work | Out-Null try { $img = $Image $fs = [IO.File]::OpenRead($Image); $head = New-Object byte[] 4; [void]$fs.Read($head, 0, 4); $fs.Close() if ($head[0] -eq 0x50 -and $head[1] -eq 0x4B) { # a Sony / Eris .EPB: a zip with a 4 KiB "RAWC" trailer, which .NET will not read past Add-Type -AssemblyName System.IO.Compression.FileSystem $bytes = [IO.File]::ReadAllBytes($Image) $zipPath = Join-Path $work 'epb.zip' $n = $bytes.Length if ($n -gt 4096 -and [Text.Encoding]::ASCII.GetString($bytes, $n - 4096, 4) -eq 'RAWC') { $n -= 4096 } $fsz = [IO.File]::Create($zipPath); $fsz.Write($bytes, 0, $n); $fsz.Close() $zip = [IO.Compression.ZipFile]::OpenRead($zipPath) $entry = $zip.Entries | Where-Object { $_.FullName -eq 'boot.img' } | Select-Object -First 1 if (-not $entry) { $zip.Dispose(); Die "$Image has no boot.img inside" } $img = Join-Path $work 'boot.img' [IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $img) $zip.Dispose() Write-Host "Using boot.img from $(Split-Path $Image -Leaf)" } $len = (Get-Item $img).Length if ($len -ne $Size) { Die "not a kernel partition image: $len bytes, expected $Size" } $fs = [IO.File]::OpenRead($img); $magic = New-Object byte[] 4; [void]$fs.Read($magic, 0, 4); $fs.Close() if (($magic | ForEach-Object { $_.ToString('x2') }) -join '' -ne 'd00dfeed') { Die "not a kernel image (no FIT header)" } $m = Md5Of $img $md5file = "$Image.md5"; $manifest = Join-Path (Split-Path $Image) 'MANIFEST' if ($m -eq $StockMd5) { $kind = "Sony's stock kernel (md5 matches)" } elseif ((Test-Path $md5file) -and ((Get-Content $md5file -First 1).Split(' ')[0] -eq $m)) { $kind = "a Lumen backup (md5 matches its .md5)" } elseif ((Test-Path $manifest) -and (Select-String -Path $manifest -Pattern "^$m " -Quiet)) { $kind = "a Lumen firmware backup (md5 matches MANIFEST)" } else { $kind = "an image with no md5 to compare (md5 $m): be sure it is a PlayStation Classic kernel" } Write-Host "" Write-Host "Image: $(Split-Path $Image -Leaf)" Write-Host " $kind" Wait-Console Write-Host "" $a = Read-Host "Write this kernel to BOOTIMG1 and restart the console? Type yes" if ($a -ne 'yes') { Write-Host "Nothing was written."; exit 1 } & $Fastboot flash BOOTIMG1 $img if ($LASTEXITCODE -ne 0) { Die "fastboot could not write BOOTIMG1 (see above)." } Write-Host "" Write-Host "Written. Restarting the console..." & $Fastboot reboot Write-Host "" Write-Host "Done. Unplug the micro-USB from the computer, close the console and start it with its" Write-Host "usual power adapter. If it still does not start: https://lpsx.dev/recovery#troubleshooting" } finally { Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue }