-fixed possible bug on usb remount if IOS got changed

-proper shutdown of devices on wiiflow end (boot game, exit to, etc)
This commit is contained in:
fix94.1 2012-09-02 11:51:26 +00:00
parent 5ca2c279ba
commit 5b955bbeed
9 changed files with 68 additions and 84 deletions

View File

@ -62,7 +62,7 @@ void DeviceHandler::MountAll()
MountAllUSB();
}
void DeviceHandler::UnMountAll()
void DeviceHandler::UnMountAll(bool ShutdownUSB)
{
for(u32 i = SD; i < MAXDEVICES; i++)
UnMount(i);
@ -77,6 +77,11 @@ void DeviceHandler::UnMountAll()
sd = NULL;
usb0 = NULL;
usb1 = NULL;
USBStorage2_Deinit();
SDHC_Close();
if(ShutdownUSB)
USB_Deinitialize();
}
bool DeviceHandler::Mount(int dev)

View File

@ -72,7 +72,7 @@ class DeviceHandler
void SetModes();
void MountAll();
void UnMountAll();
void UnMountAll(bool ShutdownUSB = false);
bool Mount(int dev);
bool IsInserted(int dev);
void UnMount(int dev);

View File

@ -66,9 +66,9 @@ static char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb2";
static char fs2[] ATTRIBUTE_ALIGN(32) = "/dev/usb123";
static char fs3[] ATTRIBUTE_ALIGN(32) = "/dev/usb/ehc";
static u8 * mem2_ptr = NULL;
static s32 hid = -1, fd = -1;
static u32 usb2_port = -1; //current USB port
u8 *mem2_ptr = NULL;
s32 hid = -1, fd = -1;
s8 usb2_port = -1; //current USB port
bool hddInUse[2] = { false, false };
u32 hdd_sector_size[2] = { 512, 512 };
bool first = false;
@ -84,34 +84,35 @@ inline s32 __USBStorage_isMEM2Buffer(const void *buffer)
s32 USBStorage2_Init(u32 port)
{
/* allocate buf2 */
if(mem2_ptr == NULL)
mem2_ptr = SYS_AllocArena2MemLo(USB_MEM2_SIZE, 32);
if(usb_libogc_mode)
{
__io_usbstorage_ogc.startup();
return (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0) ? IPC_ENOENT : 0;
}
if(hddInUse[port])
return 0;
if(usb_libogc_mode)
__io_usbstorage_ogc.startup();
else
{
/* Create heap */
if(hid < 0)
{
hid = iosCreateHeap(UMS_HEAPSIZE);
if (hid < 0) return IPC_ENOMEM;
}
/* allocate buf2 */
if(mem2_ptr == NULL)
mem2_ptr = SYS_AllocArena2MemLo(USB_MEM2_SIZE, 32);
/* Open USB device */
if (fd < 0) fd = IOS_Open(fs, 0);
if (fd < 0) fd = IOS_Open(fs2, 0);
if (fd < 0) fd = IOS_Open(fs3, 0);
if (fd < 0) return fd;
}
USBStorage2_SetPort(port);
/* Initialize USB storage */
if(!usb_libogc_mode)
IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");
/* Get device capacity */
@ -125,24 +126,25 @@ s32 USBStorage2_Init(u32 port)
void USBStorage2_Deinit()
{
if(usb_libogc_mode)
{
__io_usbstorage_ogc.shutdown();
return;
}
/* Close USB device */
if (fd >= 0)
{
if(usb_libogc_mode)
__io_usbstorage_ogc.shutdown();
else if(fd >= 0)
IOS_Close(fd); // not sure to close the fd is needed
fd = -1;
/* Reset Variables */
if(usb2_port == 0 || usb2_port == 1)
{
hddInUse[usb2_port] = false;
usb2_port = -1;
}
fd = -1;
}
s32 USBStorage2_SetPort(u32 port)
s32 USBStorage2_SetPort(s8 port)
{
//! Port = 2 is handle in the loader, no need to handle it in cIOS
if(port > 1)
if(port > 1 || port < 0)
return -1;
if(port == usb2_port)
@ -160,7 +162,7 @@ s32 USBStorage2_SetPort(u32 port)
return ret;
}
s32 USBStorage2_GetPort()
s8 USBStorage2_GetPort()
{
return usb2_port;
}
@ -178,7 +180,7 @@ s32 USBStorage2_GetCapacity(u32 port, u32 *_sector_size)
else
numSectors = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", &sectorSize);
if(first)
if(first && numSectors && sectorSize)
{
gprintf(" * * * * * * * * * * * *\n");
gprintf(" * HDD Information\n * Sectors: %lu\n", numSectors);
@ -296,7 +298,9 @@ s32 USBStorage2_WriteSectors(u32 port, u32 sector, u32 numSectors, const void *b
s32 USBStorage2_GetSectorSize()
{
if(usb2_port == 0 || usb2_port == 1)
return hdd_sector_size[usb2_port];
return 0;
}
static bool __usbstorage_Startup(void)

View File

@ -21,8 +21,8 @@ s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer);
s32 USBStorage2_WriteSectors(u32 port, u32 sector, u32 numSectors, const void *buffer);
s32 USBStorage2_GetSectorSize();
s32 USBStorage2_SetPort(u32 port);
s32 USBStorage2_GetPort();
s32 USBStorage2_SetPort(s8 port);
s8 USBStorage2_GetPort();
extern int usb_libogc_mode;

View File

@ -85,11 +85,8 @@ bool loadIOS(int ios, bool MountDevices)
bool ret = true;
m_music.Stop();
DeviceHandler::Instance()->UnMountAll();
USBStorage2_Deinit();
SDHC_Close();
#ifndef DOLPHIN
mload_close();
if(ios != IOS_GetVersion())
{
WDVD_Close();

View File

@ -21,8 +21,7 @@
#include "fst.h"
#include "wdvd.h"
#include "channel/nand.hpp"
#include "devicemounter/sdhc.h"
#include "devicemounter/usbstorage.h"
#include "devicemounter/DeviceHandler.hpp"
#include "homebrew/homebrew.h"
/* External WiiFlow Game Booter */
@ -93,14 +92,7 @@ void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 pat
memcpy((void *)0x90000000, &normalCFG, sizeof(the_CFG));
DCFlushRange((void *)(0x90000000), sizeof(the_CFG));
#ifndef DOLPHIN
USBStorage2_Deinit();
USB_Deinitialize();
SDHC_Close();
#endif
Nand::Instance()->DeInit_ISFS(true); //cIOS loves magic :P
WDVD_Close(); //We init that in the booter anyways
ShutdownBeforeExit(true);
memcpy(EXECUTE_ADDR, wii_game_booter_dol, wii_game_booter_dol_size);
DCFlushRange(EXECUTE_ADDR, wii_game_booter_dol_size);
BootHomebrew();
@ -116,3 +108,10 @@ void ExternalBooter_ChannelSetup(void *dolchunkoffset[18], u32 dolchunksize[18],
normalCFG.dolchunkcount = dolchunkcount;
normalCFG.startPoint = StartPoint;
}
void ShutdownBeforeExit(bool KeepPatches)
{
DeviceHandler::Instance()->UnMountAll(true); //Shutdown USB as well
Nand::Instance()->DeInit_ISFS(KeepPatches);
WDVD_Close();
}

View File

@ -31,5 +31,6 @@ extern u32 hooktype;
void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode,
int aspectRatio, u32 returnTo, u8 BootType);
void ExternalBooter_ChannelSetup(void *dolchunkoffset[18], u32 dolchunksize[18], u32 dolchunkcount, u32 StartPoint);
void ShutdownBeforeExit(bool KeepPatches = false);
#endif

View File

@ -12,6 +12,7 @@
#include "gui/video.hpp"
#include "gui/text.hpp"
#include "homebrew/homebrew.h"
#include "loader/external_booter.hpp"
#include "loader/wdvd.h"
#include "loader/alt_ios.h"
#include "loader/sys.h"
@ -134,10 +135,7 @@ int main(int argc, char **argv)
}
//Exit WiiFlow, no game booted...
mainMenu->cleanup();
DeviceHandler::Instance()->UnMountAll();
Nand::Instance()->DeInit_ISFS();
WDVD_Close();
ShutdownBeforeExit();
Sys_Exit();
exit(1);
return 0;

View File

@ -882,7 +882,6 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool disc)
m_cfg.save(true);
cleanup();
DeviceHandler::Instance()->UnMountAll();
GC_SetVideoMode(videoMode, videoSetting);
GC_SetLanguage(GClanguage);
if(loader == 2)
@ -891,20 +890,9 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool disc)
loadIOS(58, false);
else //use cIOS instead to make sure Devolution works anyways
loadIOS(mainIOS, false);
USBStorage2_Deinit();
USB_Deinitialize();
SDHC_Close();
DEVO_SetOptions(path.c_str(), DeviceName[currentPartition], id.c_str(), memcard_emu);
}
#ifndef DOLPHIN
USBStorage2_Deinit();
USB_Deinitialize();
SDHC_Close();
#endif
Nand::Instance()->DeInit_ISFS();
WDVD_Close();
ShutdownBeforeExit();
if(loader == 1 || disc)
{
DML_New_WriteOptions();
@ -928,21 +916,14 @@ void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments)
Playlog_Delete();
cleanup(); // wifi and sd gecko doesnt work anymore after cleanup
LoadHomebrew(filepath);
DeviceHandler::Instance()->UnMountAll(); //homebrew loaded, we can unmount devices now
LoadHomebrew(filepath);
AddBootArgument(filepath);
for(u32 i = 0; i < arguments.size(); ++i)
AddBootArgument(arguments[i].c_str());
loadIOS(58, false);
#ifndef DOLPHIN
USBStorage2_Deinit();
USB_Deinitialize();
SDHC_Close();
#endif
Nand::Instance()->DeInit_ISFS();
WDVD_Close();
loadIOS(58, false);
ShutdownBeforeExit();
writeStub();
BootHomebrew();
}
@ -1100,7 +1081,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
error(_t("errneek1", L"Cannot launch neek2o. Verify your neek2o setup"));
Sys_LoadMenu();
}
DeviceHandler::Instance()->UnMountAll();
ShutdownBeforeExit();
Launch_nk(gameTitle, emuPath.size() > 1 ? emuPath.c_str() : NULL);
}
DeviceHandler::Instance()->UnMountAll();
@ -1152,8 +1133,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
}
if(forwarder)
{
Nand::Instance()->DeInit_ISFS();
WDVD_Close();
ShutdownBeforeExit();
WII_Initialize();
if(WII_LaunchTitle(gameTitle) < 0)
Sys_LoadMenu();