Fix some hangs during boot & Wiimote sync issues

This commit is contained in:
wiidev 2021-08-01 18:00:42 +01:00
parent 4b2372e150
commit e25c4e7bd8
11 changed files with 161 additions and 149 deletions

View File

@ -96,18 +96,20 @@ int StartUpProcess::ParseArguments(int argc, char *argv[])
//! The arguments override //! The arguments override
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
{ {
if(!argv[i]) continue; if (!argv[i])
continue;
gprintf("Boot argument %i: %s\n", i + 1, argv[i]); gprintf("Boot argument %i: %s\n", i + 1, argv[i]);
char *ptr = strcasestr(argv[i], "-ios="); char *ptr = strcasestr(argv[i], "-bootios=");
if (ptr) if (ptr)
{ {
if(atoi(ptr+strlen("-ios=")) == 58) if (atoi(ptr + strlen("-bootios=")) == 58)
Settings.LoaderIOS = 58; Settings.LoaderIOS = 58;
else else
Settings.LoaderIOS = LIMIT(atoi(ptr+strlen("-ios=")), 200, 255); Settings.LoaderIOS = LIMIT(atoi(ptr + strlen("-bootios=")), 200, 255);
Settings.UseArgumentIOS = ON; Settings.UseArgumentIOS = ON;
Settings.BootIOS = Settings.LoaderIOS;
} }
ptr = strcasestr(argv[i], "-usbport="); ptr = strcasestr(argv[i], "-usbport=");
@ -194,11 +196,8 @@ bool StartUpProcess::USBSpinUp()
if (handle1) if (handle1)
started1 = (handle1->startup() && handle1->isInserted()); started1 = (handle1->startup() && handle1->isInserted());
if( (!handle0 || started0) if ((!handle0 || started0) && (!handle1 || started1))
&& (!handle1 || started1)) {
break; break;
}
UpdatePads(); UpdatePads();
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
@ -210,8 +209,7 @@ bool StartUpProcess::USBSpinUp()
messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20 - (int)countDown.elapsed()); messageTxt->SetTextf("Waiting for HDD: %i sec left\n", 20 - (int)countDown.elapsed());
Draw(); Draw();
usleep(50000); usleep(50000);
} } while (countDown.elapsed() < 20.f);
while(countDown.elapsed() < 20.f);
drawCancel = false; drawCancel = false;
@ -224,7 +222,7 @@ int StartUpProcess::Run(int argc, char *argv[])
StartUpProcess Process; StartUpProcess Process;
int ret = Process.Execute(); int ret = Process.Execute(quickGameBoot != -1);
if (quickGameBoot != -1) if (quickGameBoot != -1)
return QuickGameBoot(argv[quickGameBoot]); return QuickGameBoot(argv[quickGameBoot]);
@ -232,46 +230,38 @@ int StartUpProcess::Run(int argc, char *argv[])
return ret; return ret;
} }
int StartUpProcess::Execute() int StartUpProcess::Execute(bool quickGameBoot)
{ {
Settings.EntryIOS = IOS_GetVersion(); Settings.EntryIOS = IOS_GetVersion();
gprintf("Current IOS: %i - have AHB access: %s\n", Settings.EntryIOS, AHBPROT_DISABLED ? "yes" : "no"); // Disable AHBPROT
IosLoader::PatchAHB();
// Only reload the IOS if the XML requests it, we don't have full HW access or the entry IOS isn't 58 gprintf("Current IOS: %d - have AHB access: %s\n", Settings.EntryIOS, AHBPROT_DISABLED ? "yes" : "no");
if(Settings.UseArgumentIOS || !AHBPROT_DISABLED || IOS_GetVersion() != 58) // Reload to a cIOS if required (old forwarder?) or requested
if (!AHBPROT_DISABLED || (Settings.EntryIOS != Settings.BootIOS))
{ {
if (Settings.UseArgumentIOS) SetTextf("Reloading to cIOS %d%s\n", Settings.LoaderIOS, Settings.UseArgumentIOS ? "requested in meta.xml" : "");
SetTextf("Reloading to %sIOS %i requested in meta.xml\n", Settings.LoaderIOS >= 200 ? "c" : "", Settings.LoaderIOS);
else
SetTextf("Reloading to %sIOS %i\n", Settings.LoaderIOS >= 200 ? "c" : "", Settings.LoaderIOS);
// Reload to the default loader IOS or the IOS set in meta.xml
// And on failure try cIOS 249, 250, 222, 223, 245, 246, 247 and 248
if (IosLoader::LoadAppCios(Settings.LoaderIOS) < 0) if (IosLoader::LoadAppCios(Settings.LoaderIOS) < 0)
{ {
SetTextf("Failed to load an IOS. USB Loader GX requires a cIOS or IOS58 with AHB access. Exiting...\n"); SetTextf("Failed to load an IOS. USB Loader GX requires a cIOS or IOS58 with AHB access. Exiting...\n");
sleep(5); sleep(5);
Sys_BackToLoader(); Sys_BackToLoader();
} }
if(!AHBPROT_DISABLED && IOS_GetVersion() < 200) SetTextf("Reloaded to cIOS %d\n", Settings.LoaderIOS);
{ gprintf("Current IOS: %d - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no");
SetTextf("Failed to load into IOS %i. USB Loader GX requires a cIOS or IOS58 with AHB access. Exiting...\n", IOS_GetVersion());
sleep(5);
Sys_BackToLoader();
}
} }
SetupPads(); SetupPads();
gprintf("Current IOS: %i - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no");
SetTextf("Initializing sd card\n"); SetTextf("Initializing SD card\n");
DeviceHandler::Instance()->MountSD(); DeviceHandler::Instance()->MountSD();
// Do not mount USB if not needed. USB is not available with WiiU WiiVC injected channel. // Do not mount USB if not needed. USB is not available with WiiU WiiVC injected channel
if (Settings.USBAutoMount == ON && !isWiiVC) if (Settings.USBAutoMount == ON && !isWiiVC)
{ {
SetTextf("Initializing usb devices\n"); SetTextf("Initializing USB devices\n");
USBSpinUp(); USBSpinUp();
DeviceHandler::Instance()->MountAllUSB(false); DeviceHandler::Instance()->MountAllUSB(false);
gprintf("Completed initialization of USB devices\n");
} }
SetTextf("Loading config files\n"); SetTextf("Loading config files\n");
@ -283,28 +273,38 @@ int StartUpProcess::Execute()
if (Settings.CacheTitles) if (Settings.CacheTitles)
gprintf("\tLoading cached titles...%s\n", GameTitles.ReadCachedTitles(Settings.titlestxt_path) ? "done" : "failed (using default)"); gprintf("\tLoading cached titles...%s\n", GameTitles.ReadCachedTitles(Settings.titlestxt_path) ? "done" : "failed (using default)");
// Reload to users settings if different than current IOS, and if not using an injected WiiU WiiVC IOS255 (fw.img) // Some settings need to be enabled to boot directly into games
if(Settings.LoaderIOS != IOS_GetVersion() && !isWiiVC && !Settings.UseArgumentIOS) gprintf("Quick game boot: %s\n", quickGameBoot ? "yes" : "no");
if (quickGameBoot)
{ {
Settings.USBAutoMount = ON;
Settings.LoaderMode = MODE_ALL;
Settings.skipSaving = true;
}
// Reload to users settings if different than current IOS, and if not using an injected WiiU WiiVC IOS255 (fw.img)
if (Settings.LoaderIOS != IOS_GetVersion() && !isWiiVC)
{
// Shutdown pads
sleep(1); // Some Wiimotes won't reconnect as player 1 without this
Wpad_Disconnect();
// Unmount devices // Unmount devices
DeviceHandler::DestroyInstance(); DeviceHandler::DestroyInstance();
if (Settings.USBAutoMount == ON) if (Settings.USBAutoMount == ON)
USBStorage2_Deinit(); USBStorage2_Deinit();
// Shutdown pads
Wpad_Disconnect();
// Now load the cIOS that was set in the settings menu // Now load the cIOS that was set in the settings menu
if (IosLoader::LoadAppCios(Settings.LoaderIOS) > -1) if (IosLoader::LoadAppCios(Settings.LoaderIOS) > -1)
{ {
SetTextf("Reloaded into cIOS %i R%i\n", IOS_GetVersion(), IOS_GetRevision()); SetTextf("Reloaded to %s%d r%d\n", IOS_GetVersion() >= 200 ? "cIOS " : "IOS", Settings.LoaderIOS, IOS_GetRevision());
// Re-Mount devices // Re-Mount devices
SetTextf("Reinitializing devices\n"); SetTextf("Reinitializing devices\n");
} }
gprintf("Current IOS: %d - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no");
// Start pads again // Start pads again
SetupPads(); SetupPads();
gprintf("Current IOS: %i - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no");
DeviceHandler::Instance()->MountSD(); DeviceHandler::Instance()->MountSD();
if (Settings.USBAutoMount == ON) if (Settings.USBAutoMount == ON)
@ -322,7 +322,7 @@ int StartUpProcess::Execute()
{ {
if (Settings.USBAutoMount == ON && !isWiiVC) if (Settings.USBAutoMount == ON && !isWiiVC)
{ {
SetTextf("Changing USB Port to %i\n", Settings.USBPort); SetTextf("Changing USB port to %i\n", Settings.USBPort);
DeviceHandler::Instance()->UnMountAllUSB(); DeviceHandler::Instance()->UnMountAllUSB();
DeviceHandler::Instance()->MountAllUSB(); DeviceHandler::Instance()->MountAllUSB();
} }
@ -331,7 +331,7 @@ int StartUpProcess::Execute()
{ {
if (Settings.USBAutoMount == ON && !isWiiVC) if (Settings.USBAutoMount == ON && !isWiiVC)
{ {
SetTextf("Mounting USB Port to 1\n"); SetTextf("Mounting USB port to 1\n");
DeviceHandler::Instance()->MountUSBPort1(); DeviceHandler::Instance()->MountUSBPort1();
} }
} }
@ -339,14 +339,14 @@ int StartUpProcess::Execute()
// Enable isfs permission if using Hermes v4 without AHB, or WiiU WiiVC (IOS255 fw.img) // Enable isfs permission if using Hermes v4 without AHB, or WiiU WiiVC (IOS255 fw.img)
if (IOS_GetVersion() < 200 || (IosLoader::IsHermesIOS() && IOS_GetRevision() == 4) || isWiiVC) if (IOS_GetVersion() < 200 || (IosLoader::IsHermesIOS() && IOS_GetRevision() == 4) || isWiiVC)
{ {
SetTextf("Patching %sIOS%i\n", IOS_GetVersion() >= 200 ? "c" : "", IOS_GetVersion()); SetTextf("Patching %s%d\n", IOS_GetVersion() >= 200 ? "cIOS " : "IOS", IOS_GetVersion());
if (IosPatch_RUNTIME(!isWiiVC, false, false, isWiiVC, false) == ERROR_PATCH) if (IosPatch_RUNTIME(!isWiiVC, false, false, isWiiVC, false) == ERROR_PATCH)
gprintf("Patching %sIOS%i failed!\n", IOS_GetVersion() >= 200 ? "c" : "", IOS_GetVersion()); gprintf("Patching %sIOS%d failed!\n", IOS_GetVersion() >= 200 ? "c" : "", IOS_GetVersion());
else else
NandTitles.Get(); // get NAND channel's titles NandTitles.Get(); // get NAND channel's titles
}
gprintf("Current IOS: %i - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no"); gprintf("Current IOS: %d - have AHB access: %s\n", IOS_GetVersion(), AHBPROT_DISABLED ? "yes" : "no");
}
// We only initialize once for the whole session // We only initialize once for the whole session
ISFS_Initialize(); ISFS_Initialize();
@ -368,7 +368,7 @@ int StartUpProcess::Execute()
gprintf("\tLoading font...%s\n", Theme::LoadFont(Settings.ConfigPath) ? "done" : "failed (using default)"); gprintf("\tLoading font...%s\n", Theme::LoadFont(Settings.ConfigPath) ? "done" : "failed (using default)");
gprintf("\tLoading theme...%s\n", Theme::Load(Settings.theme) ? "done" : "failed (using default)"); gprintf("\tLoading theme...%s\n", Theme::Load(Settings.theme) ? "done" : "failed (using default)");
//! Init the rest of the System //! Init the rest of the system
Sys_Init(); Sys_Init();
InitAudio(); InitAudio();
setlocale(LC_CTYPE, "en_US.UTF-8"); setlocale(LC_CTYPE, "en_US.UTF-8");

View File

@ -7,10 +7,11 @@ class StartUpProcess
{ {
public: public:
static int Run(int argc, char *argv[]); static int Run(int argc, char *argv[]);
private: private:
StartUpProcess(); StartUpProcess();
~StartUpProcess(); ~StartUpProcess();
int Execute(); int Execute(bool quickGameBoot);
bool USBSpinUp(); bool USBSpinUp();
void TextFade(int direction); void TextFade(int direction);
void SetTextf(const char *format, ...); void SetTextf(const char *format, ...);

View File

@ -121,6 +121,7 @@ void CSettings::SetDefault()
tooltips = ON; tooltips = ON;
gamesound = ON; gamesound = ON;
parentalcontrol = PARENTAL_LVL_ADULT; parentalcontrol = PARENTAL_LVL_ADULT;
BootIOS = 58;
LoaderIOS = 249; LoaderIOS = 249;
cios = 249; cios = 249;
gridRows = 3; gridRows = 3;
@ -306,6 +307,8 @@ bool CSettings::Reset()
bool CSettings::Save() bool CSettings::Save()
{ {
// Quick game booting doesn't need to save
if (skipSaving) return false;
if (!FindConfig()) return false; if (!FindConfig()) return false;
char filedest[300]; char filedest[300];

View File

@ -121,6 +121,7 @@ class CSettings
short gamesoundvolume; short gamesoundvolume;
short tooltips; short tooltips;
short parentalcontrol; short parentalcontrol;
u8 BootIOS;
u8 LoaderIOS; u8 LoaderIOS;
u8 cios; u8 cios;
short quickboot; short quickboot;
@ -240,8 +241,9 @@ class CSettings
short GCInstallAligned; short GCInstallAligned;
short PrivateServer; short PrivateServer;
// This variable is not saved to the settings file // These variables are not saved to the settings file
bool FirstTimeRun; bool FirstTimeRun;
bool skipSaving;
protected: protected:
bool ValidVersion(FILE * file); bool ValidVersion(FILE * file);
bool ValidateURL(char *value, int type = 0); bool ValidateURL(char *value, int type = 0);

View File

@ -212,7 +212,6 @@ LoaderSettings::LoaderSettings()
oldLoaderMode = Settings.LoaderMode; oldLoaderMode = Settings.LoaderMode;
oldGameCubeSource = Settings.GameCubeSource; oldGameCubeSource = Settings.GameCubeSource;
oldLoaderIOS = Settings.LoaderIOS;
} }
LoaderSettings::~LoaderSettings() LoaderSettings::~LoaderSettings()
@ -233,12 +232,6 @@ LoaderSettings::~LoaderSettings()
{ {
GCGames::Instance()->LoadAllGames(); GCGames::Instance()->LoadAllGames();
} }
if(oldLoaderIOS != Settings.LoaderIOS)
{
// edit meta.xml arguments
editMetaArguments();
}
} }
void LoaderSettings::SetOptionNames() void LoaderSettings::SetOptionNames()

View File

@ -38,7 +38,6 @@ class LoaderSettings : public SettingsMenu
short oldLoaderMode; short oldLoaderMode;
short oldGameCubeSource; short oldGameCubeSource;
short oldLoaderIOS;
OptionList GuiOptions; OptionList GuiOptions;
}; };

View File

@ -34,7 +34,7 @@ int updateMetaXML (void)
return 0; return 0;
char line[50]; char line[50];
snprintf(line, sizeof(line), "--ios=%d", Settings.LoaderIOS); snprintf(line, sizeof(line), "--bootios=%d", Settings.BootIOS);
MetaXML.SetArgument(line); MetaXML.SetArgument(line);
snprintf(line, sizeof(line), "--usbport=%d", Settings.USBPort); snprintf(line, sizeof(line), "--usbport=%d", Settings.USBPort);
MetaXML.SetArgument(line); MetaXML.SetArgument(line);
@ -73,17 +73,23 @@ int editMetaArguments (void)
while (fgets(line, max_line_size, source) != NULL) while (fgets(line, max_line_size, source) != NULL)
{ {
// delete commented lines // delete commented lines
if( strstr(line, " <!-- remove this line to enable arguments") != NULL ||
strstr(line, " remove this line to enable arguments -->") != NULL)
{
strcpy(line, "");
}
// delete commented lines (old version)
if( strstr(line, "<!-- // remove this line to enable arguments") != NULL || if( strstr(line, "<!-- // remove this line to enable arguments") != NULL ||
strstr(line, "// remove this line to enable arguments -->") != NULL) strstr(line, "// remove this line to enable arguments -->") != NULL)
{ {
strcpy(line, " \n"); strcpy(line, "");
} }
// generate argurments // generate argurments
if(strstr(line, "<arguments>") != NULL) if(strstr(line, "<arguments>") != NULL)
{ {
fputs(line, destination); fputs(line, destination);
snprintf(line, max_line_size, " <arg>--ios=%d</arg>\n", Settings.LoaderIOS); snprintf(line, max_line_size, " <arg>--bootios=%d</arg>\n", Settings.BootIOS);
fputs(line, destination); fputs(line, destination);
snprintf(line, max_line_size, " <arg>--usbport=%d</arg>\n", Settings.USBPort); snprintf(line, max_line_size, " <arg>--usbport=%d</arg>\n", Settings.USBPort);
fputs(line, destination); fputs(line, destination);

View File

@ -175,6 +175,13 @@ s32 IosLoader::ReloadIosSafe(s32 ios)
* Reloads a certain IOS and keeps the AHBPROT flag enabled if available. * Reloads a certain IOS and keeps the AHBPROT flag enabled if available.
*/ */
s32 IosLoader::ReloadIosKeepingRights(s32 ios) s32 IosLoader::ReloadIosKeepingRights(s32 ios)
{
PatchAHB();
// Reload IOS. MEM2 protection is implicitly re-enabled
return IOS_ReloadIOS(ios);
}
void IosLoader::PatchAHB()
{ {
if (CheckAHBPROT()) if (CheckAHBPROT())
{ {
@ -186,15 +193,14 @@ s32 IosLoader::ReloadIosKeepingRights(s32 ios)
0x4698, // mov r8, r3 ; Store it for the DVD video bitcheck later 0x4698, // mov r8, r3 ; Store it for the DVD video bitcheck later
0x07DB // lsls r3, r3, 0x1F ; check AHBPROT bit 0x07DB // lsls r3, r3, 0x1F ; check AHBPROT bit
}; };
// Disable memory protection
/* Disable MEM 2 protection */ write16(MEM2_PROT, 0);
write16(MEM2_PROT, 2);
for (u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_END; patchme++) for (u16 *patchme = ES_MODULE_START; patchme < ES_MODULE_END; patchme++)
{ {
if (!memcmp(patchme, ticket_check, sizeof(ticket_check))) if (!memcmp(patchme, ticket_check, sizeof(ticket_check)))
{ {
gprintf("ReloadIos: Found TMD access rights check at %p\n", patchme); gprintf("PatchAHB: Found TMD access rights check at %p\n", patchme);
/* Apply patch */ /* Apply patch */
patchme[ES_HACK_OFFSET] = 0x23FF; // li r3, 0xFF ; Set full access rights patchme[ES_HACK_OFFSET] = 0x23FF; // li r3, 0xFF ; Set full access rights
@ -204,9 +210,9 @@ s32 IosLoader::ReloadIosKeepingRights(s32 ios)
break; break;
} }
} }
// Enable memory protection
write16(MEM2_PROT, 1);
} }
// Reload IOS. MEM2 protection is implicitly re-enabled
return IOS_ReloadIOS(ios);
} }
/* /*

View File

@ -88,6 +88,7 @@ class IosLoader
static s32 LoadGameCios(s32 ios); static s32 LoadGameCios(s32 ios);
static s32 ReloadIosSafe(s32 ios); static s32 ReloadIosSafe(s32 ios);
static s32 ReloadIosKeepingRights(s32 ios); static s32 ReloadIosKeepingRights(s32 ios);
static void PatchAHB();
static bool IsHermesIOS(s32 ios = IOS_GetVersion()); static bool IsHermesIOS(s32 ios = IOS_GetVersion());
static bool IsWaninkokoIOS(s32 ios = IOS_GetVersion()); static bool IsWaninkokoIOS(s32 ios = IOS_GetVersion());
static bool IsD2X(s32 ios = IOS_GetVersion()); static bool IsD2X(s32 ios = IOS_GetVersion());

View File

@ -5,9 +5,6 @@
#include "sys.h" #include "sys.h"
#include "wpad.h" #include "wpad.h"
/* Constants */
#define MAX_WIIMOTES 4
extern u8 shutdown; extern u8 shutdown;
void __Wpad_PowerCallback(s32 chan) void __Wpad_PowerCallback(s32 chan)
@ -35,8 +32,12 @@ void Wpad_Disconnect(void)
u32 cnt; u32 cnt;
/* Disconnect Wiimotes */ /* Disconnect Wiimotes */
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) for (cnt = 0; cnt < WPAD_MAX_WIIMOTES; cnt++)
{
if (WPAD_Probe(cnt, 0) < 0)
continue;
WPAD_Disconnect(cnt); WPAD_Disconnect(cnt);
}
/* Shutdown Wiimote subsystem */ /* Shutdown Wiimote subsystem */
WPAD_Shutdown(); WPAD_Shutdown();

View File

@ -49,7 +49,7 @@ cat <<EOF > ./HBC/meta.xml
<release_date>$rev_date</release_date> <release_date>$rev_date</release_date>
<!-- remove this line to enable arguments <!-- remove this line to enable arguments
<arguments> <arguments>
<arg>--ios=250</arg> <arg>--bootios=58</arg>
<arg>--usbport=0</arg> <arg>--usbport=0</arg>
<arg>--mountusb=1</arg> <arg>--mountusb=1</arg>
</arguments> </arguments>