From d2d48dabc2c03e55438298f518563421fcef8b91 Mon Sep 17 00:00:00 2001 From: Sebastian Musialik Date: Fri, 15 May 2026 16:11:42 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Add=20optional=20=5F=5Fboot=20partition=20a?= =?UTF-8?q?nd=20MWDMA2=20kernel=20patch=20for=20IDE=E2=86=92SD=20adapters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/PSBBN-Installer.sh | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/scripts/PSBBN-Installer.sh b/scripts/PSBBN-Installer.sh index 99633ea..ce7207f 100755 --- a/scripts/PSBBN-Installer.sh +++ b/scripts/PSBBN-Installer.sh @@ -99,6 +99,23 @@ done if [ "$MODE" = "install" ]; then LOG_FILE="${TOOLKIT_PATH}/logs/PSBBN-installer.log" + # Prompt for SCPH-7000x adapter options + echo + echo " ┌─────────────────────────────────────────────────────────┐" + echo " │ SCPH-7000x / IDE→SD adapter options │" + echo " │ Fixes for third-party HDD adapters and SD cards │" + echo " │ Only enable if using IDE→SD, IDE→SATA, or similar │" + echo " └─────────────────────────────────────────────────────────┘" + echo + read -p " Create __boot partition for modchip DEV2 auto-boot? [y/N]: " BOOT_MODE + if [[ "$BOOT_MODE" =~ ^[Yy]$ ]]; then + BOOT_PARTITION=1 + fi + read -p " Enable MWDMA2 kernel patch (fixes UDMA write hangs)? [y/N]: " SD_MODE + if [[ "$SD_MODE" =~ ^[Yy]$ ]]; then + SD_CARD_MWDMA2=1 + fi + [ "$BOOT_PARTITION" = "1" ] || [ "$SD_CARD_MWDMA2" = "1" ] && echo else LOG_FILE="${TOOLKIT_PATH}/logs/update.log" fi @@ -112,6 +129,9 @@ version_le() { # returns 0 (true) if $1 < $2 if [ "$MODE" = "install" ]; then LINUX_PARTITIONS=("__linux.1" "__linux.4" "__linux.5" "__linux.6" "__linux.7" "__linux.8" "__linux.9" ) PFS_PARTITIONS=("__contents" "__system" "__sysconf" "__common" ) + if [ "$BOOT_PARTITION" = "1" ]; then + PFS_PARTITIONS+=("__boot") + fi fi error_msg() { @@ -209,6 +229,62 @@ exit_script() { fi } +# Patch vmlinux kernel to use MWDMA2 instead of UDMA4 for DMA +# Fixes IDE→SD/SATA adapters on SCPH-7000x that fail on UDMA writes +patch_vmlinux_mwdma2() { + local vmlinux="$1" + if [ ! -f "$vmlinux" ]; then + echo " [!] vmlinux not found at $vmlinux" | tee -a "${LOG_FILE}" + return 1 + fi + echo " Patching kernel for MWDMA2 (SD card mode)..." | tee -a "${LOG_FILE}" + python3 -c " +import struct, sys, subprocess +with open('$vmlinux', 'rb+') as f: + data = f.read() + sym_addr = None + # Try nm first, then readelf + for cmd in (['nm', '$vmlinux'], ['readelf', '-s', '$vmlinux']): + try: + out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL).decode() + for line in out.split('\\n'): + if 'ide_config_drive_speed' in line: + parts = line.split() + if parts: + try: sym_addr = int(parts[0], 16); break + except: pass + if sym_addr: break + except: pass + if sym_addr: + jal = (0x0C << 26) | ((sym_addr >> 2) & 0x3FFFFFF) + jal_bytes = struct.pack('= 0: + data = bytearray(data) + data[idx + 4] = 0x22 + f.seek(0); f.write(data); f.truncate() + print(f'Patched at file offset 0x{idx+4:x}') + sys.exit(0) + # Fallback: find JAL + li a1,0x44 + old_li = struct.pack('= 0: + if idx >= 4: + prev = struct.unpack_from('> 26) == 0x03: + data = bytearray(data) + data[idx] = 0x22 + f.seek(0); f.write(data); f.truncate() + print(f'Patched at file offset 0x{idx:x}') + sys.exit(0) + idx = data.find(old_li, idx + 1) + print('Pattern not found') + sys.exit(1) +" 2>> "${LOG_FILE}" && echo " [OK] Kernel patched for MWDMA2" | tee -a "${LOG_FILE}" || echo " [!] Kernel patch failed - may already be patched" | tee -a "${LOG_FILE}" +} + get_latest_file() { local prefix="$1" # e.g., "psbbn-eng" or "psbbn-definitive-patch" local display="$2" # e.g., "English language pack" @@ -939,6 +1015,9 @@ if [ "$MODE" = "install" ]; then COMMANDS="device ${DEVICE}\n" COMMANDS+="initialize yes\n" + if [ "$BOOT_PARTITION" = "1" ]; then + COMMANDS+="mkpart __boot 128M PFS\n" + fi COMMANDS+="mkpart __linux.1 512M EXT2\n" COMMANDS+="mkpart __linux.2 128M EXT2SWAP\n" COMMANDS+="mkpart __linux.4 512M EXT2\n" @@ -1227,6 +1306,12 @@ if [ "$OSD_UPDATE" != "no" ]; then cp -f "${ASSETS_DIR}/osdmenu/"{hosdmenu.elf,version.txt} "${STORAGE_DIR}/__system/osdmenu/" 2>> "${LOG_FILE}" || error_msg "Failed to copy hosdmenu.elf." fi +# Install Dev2 bootloader for auto-boot from __boot partition (if requested) +if [ "$BOOT_PARTITION" = "1" ] && [ -f "${ASSETS_DIR}/modbo_dev2_boot.elf" ]; then + cp -f "${ASSETS_DIR}/modbo_dev2_boot.elf" "${STORAGE_DIR}/__boot/BOOT.ELF" 2>> "${LOG_FILE}" || echo " [!] Failed to copy Dev2 bootloader." | tee -a "${LOG_FILE}" + echo " [OK] Dev2 bootloader installed to __boot partition." | tee -a "${LOG_FILE}" +fi + # Check if OSDMBR.CNF exists if [ ! -f "${STORAGE_DIR}/__sysconf/osdmenu/OSDMBR.CNF" ]; then if sudo "${HDL_DUMP}" toc ${DEVICE} | grep -q "__linux.3"; then @@ -1388,6 +1473,11 @@ if [ "$OS" = "PSBBN" ] && [ "$MODE" = "update" ]; then sudo cp -f "${SYSCONF_XML}" "${STORAGE_DIR}/__linux.4/bn/script/utility/sysconf.xml" || error_msg "Failed to replace sysconf.xml." fi +# Apply SD card MWDMA2 kernel patch if selected +if [ "$SD_CARD_MWDMA2" = "1" ] && [ -f "${STORAGE_DIR}/__system/p2lboot/vmlinux" ]; then + patch_vmlinux_mwdma2 "${STORAGE_DIR}/__system/p2lboot/vmlinux" +fi + UNMOUNT_ALL if [ "$OS" = "PSBBN" ] && [ "$MODE" = "update" ] && version_le "${psbbn_version:-0}" "4.0.0"; then From 3d41e362746594f13678103fc17f3ec372f9bd31 Mon Sep 17 00:00:00 2001 From: sebekkx <6154527+sebekkx@users.noreply.github.com> Date: Sun, 17 May 2026 13:05:16 +0200 Subject: [PATCH 2/3] Address review feedback: always create 8MB __boot, move MWDMA2 patch to Extras menu __boot partition: - Always created (8MB instead of 128MB), no prompt - Bootloader copy step removed; users place their own file - Added to PFS_PARTITIONS unconditionally MWDMA2 kernel patch: - Moved from main installer to Extras menu (option 6) - Added warning that game launching from PSBBN menu may still freeze on 'Wait while loading' screen (under investigation) - Function preserved and moved to Extras.sh Addresses feedback from CosmicScale on PR #575 --- scripts/Extras.sh | 95 ++++++++++++++++++++++++++++++++++++++ scripts/PSBBN-Installer.sh | 95 +++----------------------------------- 2 files changed, 101 insertions(+), 89 deletions(-) diff --git a/scripts/Extras.sh b/scripts/Extras.sh index 64d9851..de89336 100755 --- a/scripts/Extras.sh +++ b/scripts/Extras.sh @@ -589,6 +589,62 @@ cat << "EOF" EOF } +# Patch vmlinux kernel to use MWDMA2 instead of UDMA4 for DMA +# Fixes IDE→SD/SATA adapters on SCPH-7000x that fail on UDMA writes +patch_vmlinux_mwdma2() { + local vmlinux="$1" + if [ ! -f "$vmlinux" ]; then + echo " [!] vmlinux not found at $vmlinux" | tee -a "${LOG_FILE}" + return 1 + fi + echo " Patching kernel for MWDMA2 (SD card mode)..." | tee -a "${LOG_FILE}" + python3 -c " +import struct, sys, subprocess +with open('$vmlinux', 'rb+') as f: + data = f.read() + sym_addr = None + # Try nm first, then readelf + for cmd in (['nm', '$vmlinux'], ['readelf', '-s', '$vmlinux']): + try: + out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL).decode() + for line in out.split('\\n'): + if 'ide_config_drive_speed' in line: + parts = line.split() + if parts: + try: sym_addr = int(parts[0], 16); break + except: pass + if sym_addr: break + except: pass + if sym_addr: + jal = (0x0C << 26) | ((sym_addr >> 2) & 0x3FFFFFF) + jal_bytes = struct.pack('= 0: + data = bytearray(data) + data[idx + 4] = 0x22 + f.seek(0); f.write(data); f.truncate() + print(f'Patched at file offset 0x{idx+4:x}') + sys.exit(0) + # Fallback: find JAL + li a1,0x44 + old_li = struct.pack('= 0: + if idx >= 4: + prev = struct.unpack_from('> 26) == 0x03: + data = bytearray(data) + data[idx] = 0x22 + f.seek(0); f.write(data); f.truncate() + print(f'Patched at file offset 0x{idx:x}') + sys.exit(0) + idx = data.find(old_li, idx + 1) + print('Pattern not found') + sys.exit(1) +" 2>> "${LOG_FILE}" && echo " [OK] Kernel patched for MWDMA2" | tee -a "${LOG_FILE}" || echo " [!] Kernel patch failed - may already be patched" | tee -a "${LOG_FILE}" +} + # Function for Option 1 - Install PS2 Linux option_one() { echo "########################################################################################################" >> "${LOG_FILE}" @@ -1407,6 +1463,40 @@ option_five() { read -n 1 -s -r -p " Press any key to return to the menu..." > "${LOG_FILE}" + echo "MWDMA2 Kernel Patch:" >> "${LOG_FILE}" + + echo + echo " This patches the PS2 Linux kernel to use MWDMA2 instead of UDMA4" + echo " for DMA transfers. Fixes write hangs on SCPH-7000x consoles" + echo " using IDE→SD or IDE→SATA adapters." + echo + echo " NOTE: This fixes the PSBBN boot hang, but game launching from" + echo " the PSBBN menu may still freeze on 'Wait while loading' screen." + echo " This is a separate issue under investigation (see PR #575)." + echo + read -p " Apply MWDMA2 kernel patch? [y/N]: " confirm + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + echo + echo " Patch cancelled." + sleep 2 + return 0 + fi + echo + + if [ ! -f "${STORAGE_DIR}/__system/p2lboot/vmlinux" ]; then + echo " [!] Kernel not found at __system/p2lboot/vmlinux" | tee -a "${LOG_FILE}" + echo " Make sure PSBBN partitions are mounted." + sleep 3 + return 1 + fi + + patch_vmlinux_mwdma2 "${STORAGE_DIR}/__system/p2lboot/vmlinux" + echo + read -n 1 -s -r -p " Press any key to return to the menu..." > 2) & 0x3FFFFFF) - jal_bytes = struct.pack('= 0: - data = bytearray(data) - data[idx + 4] = 0x22 - f.seek(0); f.write(data); f.truncate() - print(f'Patched at file offset 0x{idx+4:x}') - sys.exit(0) - # Fallback: find JAL + li a1,0x44 - old_li = struct.pack('= 0: - if idx >= 4: - prev = struct.unpack_from('> 26) == 0x03: - data = bytearray(data) - data[idx] = 0x22 - f.seek(0); f.write(data); f.truncate() - print(f'Patched at file offset 0x{idx:x}') - sys.exit(0) - idx = data.find(old_li, idx + 1) - print('Pattern not found') - sys.exit(1) -" 2>> "${LOG_FILE}" && echo " [OK] Kernel patched for MWDMA2" | tee -a "${LOG_FILE}" || echo " [!] Kernel patch failed - may already be patched" | tee -a "${LOG_FILE}" -} - get_latest_file() { local prefix="$1" # e.g., "psbbn-eng" or "psbbn-definitive-patch" local display="$2" # e.g., "English language pack" @@ -1015,9 +941,7 @@ if [ "$MODE" = "install" ]; then COMMANDS="device ${DEVICE}\n" COMMANDS+="initialize yes\n" - if [ "$BOOT_PARTITION" = "1" ]; then - COMMANDS+="mkpart __boot 128M PFS\n" - fi + COMMANDS+="mkpart __boot 8M PFS\n" COMMANDS+="mkpart __linux.1 512M EXT2\n" COMMANDS+="mkpart __linux.2 128M EXT2SWAP\n" COMMANDS+="mkpart __linux.4 512M EXT2\n" @@ -1306,11 +1230,7 @@ if [ "$OSD_UPDATE" != "no" ]; then cp -f "${ASSETS_DIR}/osdmenu/"{hosdmenu.elf,version.txt} "${STORAGE_DIR}/__system/osdmenu/" 2>> "${LOG_FILE}" || error_msg "Failed to copy hosdmenu.elf." fi -# Install Dev2 bootloader for auto-boot from __boot partition (if requested) -if [ "$BOOT_PARTITION" = "1" ] && [ -f "${ASSETS_DIR}/modbo_dev2_boot.elf" ]; then - cp -f "${ASSETS_DIR}/modbo_dev2_boot.elf" "${STORAGE_DIR}/__boot/BOOT.ELF" 2>> "${LOG_FILE}" || echo " [!] Failed to copy Dev2 bootloader." | tee -a "${LOG_FILE}" - echo " [OK] Dev2 bootloader installed to __boot partition." | tee -a "${LOG_FILE}" -fi +# __boot partition is created automatically; users copy their own bootloader if needed # Check if OSDMBR.CNF exists if [ ! -f "${STORAGE_DIR}/__sysconf/osdmenu/OSDMBR.CNF" ]; then @@ -1473,10 +1393,7 @@ if [ "$OS" = "PSBBN" ] && [ "$MODE" = "update" ]; then sudo cp -f "${SYSCONF_XML}" "${STORAGE_DIR}/__linux.4/bn/script/utility/sysconf.xml" || error_msg "Failed to replace sysconf.xml." fi -# Apply SD card MWDMA2 kernel patch if selected -if [ "$SD_CARD_MWDMA2" = "1" ] && [ -f "${STORAGE_DIR}/__system/p2lboot/vmlinux" ]; then - patch_vmlinux_mwdma2 "${STORAGE_DIR}/__system/p2lboot/vmlinux" -fi +# MWDMA2 kernel patch is available in the Extras menu for IDE→SD adapter users UNMOUNT_ALL From 787a558732e58cdf30848ea4ae14e180d7c8594e Mon Sep 17 00:00:00 2001 From: CosmicScale <60739760+CosmicScale@users.noreply.github.com> Date: Sun, 17 May 2026 14:21:42 +0100 Subject: [PATCH 3/3] Add mounting and unmounting of __system partition --- scripts/Extras.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Extras.sh b/scripts/Extras.sh index de89336..0b0f1ff 100755 --- a/scripts/Extras.sh +++ b/scripts/Extras.sh @@ -1464,6 +1464,7 @@ option_five() { } option_six() { + clear echo "########################################################################################################" >> "${LOG_FILE}" echo "MWDMA2 Kernel Patch:" >> "${LOG_FILE}" @@ -1483,16 +1484,15 @@ option_six() { sleep 2 return 0 fi - echo - - if [ ! -f "${STORAGE_DIR}/__system/p2lboot/vmlinux" ]; then - echo " [!] Kernel not found at __system/p2lboot/vmlinux" | tee -a "${LOG_FILE}" - echo " Make sure PSBBN partitions are mounted." - sleep 3 - return 1 - fi + + APA_PARTITIONS=("__system" ) + mapper_probe && \ + mount_pfs || return 1 + sleep 2 patch_vmlinux_mwdma2 "${STORAGE_DIR}/__system/p2lboot/vmlinux" + clean_up || return 1 + echo read -n 1 -s -r -p " Press any key to return to the menu..."