#!/bin/sh # Lumen PSX — kernel recovery for the PlayStation Classic (macOS / Linux) # 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). # # sh psc-recover.sh check the image, wait for the console, write, restart # sh psc-recover.sh --check only look for a console in fastboot mode (writes nothing) # # 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 (Android platform-tools): # macOS: brew install --cask android-platform-tools # Linux: sudo apt install fastboot (or android-sdk-platform-tools; Fedora: android-tools) # Linux: if the console is not seen, run this with sudo (or add a udev rule for 0bb4:0c01). set -e STOCK_MD5=28ce5f6de4981764411393310311b517 # Sony's stock kernel partition, every console SIZE=8388608 say() { printf '%s\n' "$*"; } die() { printf '\nERROR: %s\n' "$*" >&2; exit 1; } md5_of() { if command -v md5 >/dev/null 2>&1; then md5 -q "$1"; else md5sum "$1" | cut -d' ' -f1; fi; } size_of() { wc -c < "$1" | tr -d ' '; } FB=${FASTBOOT:-fastboot} command -v "$FB" >/dev/null 2>&1 || die "fastboot was not found. macOS: brew install --cask android-platform-tools Linux: sudo apt install fastboot then run this again (or set FASTBOOT=/path/to/fastboot)." wait_console() { say "" say "Waiting for the console in fastboot mode (up to 3 minutes). Now:" say " 1. Console unplugged and opened (screws under the rubber feet)." say " 2. Touch the two round pads on SIDE A of the board, right of the 'LM-11' print," say " with metal tweezers, and keep them there." say " 3. Plug the console's micro-USB into this computer (a data cable, not charge-only)." say " 4. When it is found, you can let go of the tweezers." i=0 while [ $i -lt 180 ]; do n=$("$FB" devices 2>/dev/null | grep -c fastboot || true) [ "$n" = 1 ] && { say ""; say "Console found: $("$FB" devices 2>/dev/null | head -1)"; return 0; } [ "$n" -gt 1 ] 2>/dev/null && die "more than one fastboot device is connected: leave only the console." sleep 1; i=$((i + 1)); [ $((i % 15)) = 0 ] && say " ... still waiting ($i s)" done die "no console in fastboot mode. Check the pads, the cable (data, not charge-only) and, on Linux, run with sudo. See https://lpsx.dev/recovery#troubleshooting" } if [ "$1" = --check ]; then wait_console "$FB" getvar product 2>&1 | head -2 || true say "OK: the recovery path works on this console. Nothing was written." "$FB" reboot >/dev/null 2>&1 || true exit 0 fi [ -n "$1" ] || { sed -n '2,21p' "$0" | sed 's/^# \{0,1\}//'; exit 2; } SRC=$1 [ -f "$SRC" ] || die "no such file: $SRC" WORK=$(mktemp -d); trap 'rm -rf "$WORK"' EXIT IMG=$SRC # a Sony / Eris .EPB (zip + a 4 KiB trailer): take its boot.img if [ "$(head -c 2 "$SRC")" = PK ]; then command -v unzip >/dev/null 2>&1 || die "unzip is needed to read $SRC" unzip -p "$SRC" boot.img > "$WORK/boot.img" 2>/dev/null || true [ -s "$WORK/boot.img" ] || die "$SRC has no boot.img inside" IMG="$WORK/boot.img"; say "Using boot.img from $(basename "$SRC")" fi # checks: a whole kernel partition (8 MiB), a FIT image, and a known md5 when there is one [ "$(size_of "$IMG")" = $SIZE ] || die "not a kernel partition image: $(size_of "$IMG") bytes, expected $SIZE" [ "$(head -c 4 "$IMG" | od -An -tx1 | tr -d ' \n')" = d00dfeed ] || die "not a kernel image (no FIT header)" M=$(md5_of "$IMG") if [ "$M" = "$STOCK_MD5" ]; then KIND="Sony's stock kernel (md5 matches)" elif [ -f "$SRC.md5" ] && [ "$(cut -d' ' -f1 "$SRC.md5")" = "$M" ]; then KIND="a Lumen backup (md5 matches its .md5)" elif [ -f "$(dirname "$SRC")/MANIFEST" ] && grep -q "^$M " "$(dirname "$SRC")/MANIFEST"; then 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"; fi say "" say "Image: $(basename "$SRC")" say " $KIND" wait_console say "" printf 'Write this kernel to BOOTIMG1 and restart the console? Type yes: ' read -r a [ "$a" = yes ] || { say "Nothing was written."; exit 1; } "$FB" flash BOOTIMG1 "$IMG" say "" say "Written. Restarting the console..." "$FB" reboot || true say "" say "Done. Unplug the micro-USB from the computer, close the console and start it with its" say "usual power adapter. If it still does not start: https://lpsx.dev/recovery#troubleshooting"