Fix an issue with IOS reloading

This commit is contained in:
wiidev 2020-12-20 20:30:02 +00:00
parent e25c4e25f0
commit 69de883610
4 changed files with 23 additions and 55 deletions

View File

@ -237,7 +237,7 @@ int StartUpProcess::Execute()
Settings.EntryIOS = IOS_GetVersion();
// Reloading to cIOS 249 fixes compatibility issues with old forwarders
IosLoader::ReloadIosSafe(249);
s32 ret = IosLoader::ReloadIosSafe(249);
// Reload to the IOS set in meta.xml
if(Settings.UseArgumentIOS)
@ -250,15 +250,13 @@ int StartUpProcess::Execute()
Sys_BackToLoader();
}
}
else if(BUILD_IOS != 249)
// This prevents an unnecessary IOS reload
else if(BUILD_IOS != 249 || ret < 0)
{
// Reload to the default IOS (58) if nothing is set in meta.xml
IosLoader::ReloadIosSafe(BUILD_IOS);
if(!AHBPROT_DISABLED || (AHBPROT_DISABLED && IOS_GetVersion() != BUILD_IOS))
// Reload to the default IOS (58) or a cIOS if nothing is set in meta.xml
if(IosLoader::LoadAppCios(BUILD_IOS) < 0)
{
SetTextf("Failed loading %sIOS %i. USB Loader GX requires a cIOS or IOS58 with AHB access. Exiting...\n", BUILD_IOS >= 200 ? "c" : "", BUILD_IOS);
SetTextf("Failed to load a cIOS or IOS58 with AHB access. Exiting...\n");
sleep(5);
Sys_BackToLoader();
}
@ -305,12 +303,12 @@ int StartUpProcess::Execute()
Wpad_Disconnect();
// Loading now the cIOS setup in the settings
IosLoader::LoadAppCios();
SetTextf("Reloaded into cIOS %i R%i\n", IOS_GetVersion(), IOS_GetRevision());
// Re-Mount devices
SetTextf("Reinitializing devices\n");
if(IosLoader::LoadAppCios(Settings.LoaderIOS) > -1)
{
SetTextf("Reloaded into cIOS %i R%i\n", IOS_GetVersion(), IOS_GetRevision());
// Re-Mount devices
SetTextf("Reinitializing devices\n");
}
DeviceHandler::Instance()->MountSD();
if(Settings.USBAutoMount == ON)
{

View File

@ -16,6 +16,7 @@
#include "mload/modules/ehcmodule_5.h"
#include "mload/modules/dip_plugin_249.h"
#include "mload/modules/odip_frag.h"
#include "libs/libruntimeiospatch/runtimeiospatch.h"
#include "utils/tools.h"
#include "gecko.h"
@ -74,16 +75,16 @@ bool IosLoader::IsD2X(s32 ios)
* Loads CIOS (If possible the one from the settings file).
* @return 0 if a cios has been successfully loaded. Else a value below 0 is returned.
*/
s32 IosLoader::LoadAppCios()
s32 IosLoader::LoadAppCios(u8 ios)
{
u32 activeCios = IOS_GetVersion();
s32 ret = -1;
// We have what we need
if((int) activeCios == Settings.LoaderIOS)
if((int) activeCios == ios)
return 0;
u8 ciosLoadPriority[] = { Settings.LoaderIOS, 249, 250, 222, 223, 245, 246, 247, 248 }; // Ascending.
u8 ciosLoadPriority[] = { ios, 249, 250, 222, 223, 245, 246, 247, 248 }; // Ascending
for (u32 i = 0; i < (sizeof(ciosLoadPriority)/sizeof(ciosLoadPriority[0])); ++i)
@ -98,7 +99,7 @@ s32 IosLoader::LoadAppCios()
if ((ret = ReloadIosSafe(cios)) > -1)
{
// Remember working cios.
// Remember working cios
Settings.LoaderIOS = cios;
break;
}
@ -165,7 +166,7 @@ s32 IosLoader::ReloadIosSafe(s32 ios)
}
s32 r = ReloadIosKeepingRights(ios);
if (r >= 0) WII_Initialize();
if(r >= 0) WII_Initialize();
IosLoader::LoadIOSModules(IOS_GetVersion(), IOS_GetRevision());
@ -177,37 +178,8 @@ s32 IosLoader::ReloadIosSafe(s32 ios)
*/
s32 IosLoader::ReloadIosKeepingRights(s32 ios)
{
if (CheckAHBPROT())
{
static const u16 ticket_check[] = {
0x685B, // ldr r3, [r3, #4] ; Get TMD pointer
0x22EC, 0x0052, // movs r2, 0x1D8 ; Set offset of access rights field in TMD
0x189B, // adds r3, r3, r2 ; Add offset to TMD pointer
0x681B, // ldr r3, [r3] ; Load access rights. We'll hack it with full access rights!!!
0x4698, // mov r8, r3 ; Store it for the DVD video bitcheck later
0x07DB // lsls r3, r3, 0x1F ; check AHBPROT bit
};
/* Disable MEM 2 protection */
write16(MEM2_PROT, 2);
for (u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_END; patchme++)
{
if (!memcmp(patchme, ticket_check, sizeof(ticket_check)))
{
gprintf("ReloadIos: Found TMD access rights check at %p\n", patchme);
/* Apply patch */
patchme[ES_HACK_OFFSET] = 0x23FF; // li r3, 0xFF ; Set full access rights
/* Flush cache */
DCFlushRange(patchme+ES_HACK_OFFSET, 2);
break;
}
}
}
/* Reload IOS. MEM2 protection is implicitly re-enabled */
IosPatch_AHBPROT(false);
// Reload IOS. MEM2 protection is implicitly re-enabled
return IOS_ReloadIOS(ios);
}

View File

@ -4,8 +4,6 @@
#include <gccore.h>
#include <ogc/machine/processor.h>
#define CheckAHBPROT() (read32(0x0D800064) == 0xFFFFFFFF)
enum MiosInfo
{
DEFAULT_MIOS,
@ -84,7 +82,7 @@ typedef struct _iosinfo_t
class IosLoader
{
public:
static s32 LoadAppCios();
static s32 LoadAppCios(u8 ios);
static s32 LoadGameCios(s32 ios);
static s32 ReloadIosSafe(s32 ios);
static s32 ReloadIosKeepingRights(s32 ios);

View File

@ -810,7 +810,7 @@ int GameBooter::BootDevolution(struct discHdr *gameHdr)
return -1;
}
if(!CheckAHBPROT())
if(!AHBPROT_DISABLED)
{
WindowPrompt(tr("Error:"), fmt(tr("%s requires AHB access! Please launch USBLoaderGX from HBC or from an updated channel or forwarder."),LoaderName), tr("OK"));
return -1;
@ -1053,7 +1053,7 @@ int GameBooter::BootNintendont(struct discHdr *gameHdr)
const char *ninLoaderPath = game_cfg->NINLoaderPath.size() == 0 ? Settings.NINLoaderPath : game_cfg->NINLoaderPath.c_str();
if(!CheckAHBPROT())
if(!AHBPROT_DISABLED)
{
WindowPrompt(tr("Error:"), fmt(tr("%s requires AHB access! Please launch USBLoaderGX from HBC or from an updated channel or forwarder."),LoaderName), tr("OK"));
return -1;