-WIP stuff, dont report bugs please with this rev :P

-if a IOS is found which got the AHBPROT patched out, wiiflow will
run on it (for example if you boot wiiflow via HBC, it will boot
with IOS58 instead of 249)
-on game boot or on entering emu nand, wiiflow automatically reloads
IOS if necessary
-added check to only reload IOS if its really a different one
-removed SD card gecko log buffer allocation, using some 
buffer in dol directly (should allow longer logging, untested)
-set wiiflow optimize level back to -O2
This commit is contained in:
fix94.1 2012-08-23 22:29:15 +00:00
parent 4664af265f
commit 6723f00181
19 changed files with 1211 additions and 128 deletions

View File

@ -55,7 +55,7 @@ ios := 249
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O3 -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H
CFLAGS = -g -O2 -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H
CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -6,6 +6,7 @@
extern "C" {
#endif
enum
{
TYPE_WII_GAME = 0,
@ -15,6 +16,8 @@ enum
TYPE_HOMEBREW,
TYPE_END
};
#define NoGameID(x) (x == TYPE_PLUGIN || x == TYPE_HOMEBREW)
enum
{
@ -22,10 +25,10 @@ enum
IOS_TYPE_WANIN,
IOS_TYPE_HERMES,
IOS_TYPE_KWIIRK,
IOS_TYPE_NO_CIOS,
IOS_TYPE_NORMAL_IOS,
IOS_TYPE_STUB,
};
#define NoGameID(x) (x == TYPE_PLUGIN || x == TYPE_HOMEBREW)
#define CustomIOS(x) (x != IOS_TYPE_NORMAL_IOS && x != IOS_TYPE_STUB)
#ifdef __cplusplus
}

View File

@ -36,9 +36,14 @@
#include <malloc.h>
#include "nand.hpp"
#include "devicemounter/DeviceHandler.hpp"
#include "fileOps/fileOps.h"
#include "gecko/gecko.h"
#include "loader/alt_ios.h"
#include "loader/cios.h"
#include "loader/sys.h"
#include "loader/wbfs.h"
#include "music/musicplayer.h"
#include "memory/memory.h"
u8 *confbuffer ATTRIBUTE_ALIGN(32);
@ -154,6 +159,13 @@ s32 Nand::Enable_Emu()
{
if(emu_enabled)
return 0;
if(CurrentIOS.Type == IOS_TYPE_NORMAL_IOS)
{
m_music.Stop();
loadIOS(mainIOS, false, false);
DeviceHandler::Instance()->MountAll();
m_music.Next();
}
NandDevice *Device = &NandDeviceList[EmuDevice];

View File

@ -56,17 +56,10 @@ void DeviceHandler::DestroyInstance()
instance = NULL;
}
bool DeviceHandler::MountAll()
void DeviceHandler::MountAll()
{
bool result = false;
for(u32 i = SD; i < MAXDEVICES; i++)
{
if(Mount(i))
result = true;
}
return result;
MountSD();
MountAllUSB();
}
void DeviceHandler::UnMountAll()
@ -172,6 +165,11 @@ bool DeviceHandler::MountUSB(int pos)
bool DeviceHandler::MountAllUSB()
{
if(CurrentIOS.Type == IOS_TYPE_NORMAL_IOS)
usb_libogc_mode = 1;
else
usb_libogc_mode = 0;
if(!usb0)
usb0 = new PartitionHandle(GetUSB0Interface());
//if(!usb1 && (Settings.USBPort == 1 || Settings.USBPort == 2))

View File

@ -69,7 +69,7 @@ class DeviceHandler
static DeviceHandler * Instance();
static void DestroyInstance();
bool MountAll();
void MountAll();
void UnMountAll();
bool Mount(int dev);
bool IsInserted(int dev);

View File

@ -33,6 +33,7 @@
#include <string.h>
#include "usbstorage.h"
#include "usbstorage_libogc.h"
#include "gecko/gecko.h"
/* IOCTL commands */
@ -71,6 +72,7 @@ static u32 usb2_port = -1; //current USB port
bool hddInUse[2] = { false, false };
u32 hdd_sector_size[2] = { 512, 512 };
bool first = false;
int usb_libogc_mode = 0;
extern void* SYS_AllocArena2MemLo(u32 size,u32 align);
@ -85,29 +87,35 @@ s32 USBStorage2_Init(u32 port)
if(hddInUse[port])
return 0;
/* Create heap */
if (hid < 0)
if(usb_libogc_mode)
__io_usbstorage_ogc.startup();
else
{
hid = iosCreateHeap(UMS_HEAPSIZE);
if (hid < 0) return IPC_ENOMEM;
}
/* allocate buf2 */
if(mem2_ptr == NULL)
mem2_ptr = SYS_AllocArena2MemLo(USB_MEM2_SIZE, 32);
/* 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;
/* 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 */
IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");
if(!usb_libogc_mode)
IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":");
/* Get device capacity */
if (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0)
if(USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0)
return IPC_ENOENT;
hddInUse[port] = true;
@ -117,6 +125,12 @@ s32 USBStorage2_Init(u32 port)
void USBStorage2_Deinit()
{
if(usb_libogc_mode)
{
__io_usbstorage_ogc.shutdown();
return;
}
/* Close USB device */
if (fd >= 0)
{
@ -140,7 +154,7 @@ s32 USBStorage2_SetPort(u32 port)
gprintf("Changing USB port to port %i....\n", port);
//must be called before USBStorage2_Init (default port 0)
if (fd >= 0)
if(fd >= 0 && !usb_libogc_mode)
ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_SET_PORT, "i:", usb2_port);
return ret;
@ -153,38 +167,44 @@ s32 USBStorage2_GetPort()
s32 USBStorage2_GetCapacity(u32 port, u32 *_sector_size)
{
if (fd >= 0)
{
s32 ret;
u32 sector_size = 0;
USBStorage2_SetPort(port);
if((usb_libogc_mode && !__io_usbstorage_ogc.isInserted()) || (!usb_libogc_mode && fd < 0))
return 0;
s32 ret;
u32 sector_size = 0;
USBStorage2_SetPort(port);
if(usb_libogc_mode)
{
sector_size = USB_OGC_GetSectorSize();
ret = USB_OGC_GetCapacity();
}
else
ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", &sector_size);
if(first)
{
gprintf(" * * * * * * * * * * * *\n");
gprintf(" * HDD Information\n * Sectors: %lu\n", ret);
u32 size = ((((ret / 1024U) * sector_size) / 1024U) / 1024U);
if(size >= 1000U)
gprintf(" * Size [Sector Size]: %lu.%lu TB [%u]\n", size / 1024U, (size * 100U) % 1024U, sector_size);
else
gprintf(" * Size [Sector Size]: %lu GB [%u]\n", size, sector_size);
gprintf(" * * * * * * * * * * * *\n");
first = false;
}
if(ret && _sector_size)
*_sector_size = sector_size;
return ret;
if(first)
{
gprintf(" * * * * * * * * * * * *\n");
gprintf(" * HDD Information\n * Sectors: %lu\n", ret);
u32 size = ((((ret / 1024U) * sector_size) / 1024U) / 1024U);
if(size >= 1000U)
gprintf(" * Size [Sector Size]: %lu.%lu TB [%u]\n", size / 1024U, (size * 100U) % 1024U, sector_size);
else
gprintf(" * Size [Sector Size]: %lu GB [%u]\n", size, sector_size);
gprintf(" * * * * * * * * * * * *\n");
first = false;
}
return IPC_ENOENT;
if(ret && _sector_size)
*_sector_size = sector_size;
return ret;
}
s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer)
{
if(usb_libogc_mode)
return __io_usbstorage_ogc.readSectors(sector, numSectors, buffer);
bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer);
u8 *buf = (u8 *)buffer;
s32 ret = -1;
@ -231,6 +251,9 @@ s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer)
s32 USBStorage2_WriteSectors(u32 port, u32 sector, u32 numSectors, const void *buffer)
{
if(usb_libogc_mode)
return __io_usbstorage_ogc.writeSectors(sector, numSectors, buffer);
bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer);
u8 *buf = (u8 *)buffer;
s32 ret = -1;

View File

@ -8,23 +8,26 @@ extern "C"
{
#endif
/* Prototypes */
s32 USBStorage2_Init(u32 port);
void USBStorage2_Deinit();
s32 USBStorage2_GetCapacity(u32 port, u32 *size);
/* Disc interfaces */
extern const DISC_INTERFACE __io_usbstorage2_port0;
extern const DISC_INTERFACE __io_usbstorage2_port1;
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();
/* Prototypes */
s32 USBStorage2_Init(u32 port);
void USBStorage2_Deinit();
s32 USBStorage2_GetCapacity(u32 port, u32 *size);
s32 USBStorage2_SetPort(u32 port);
s32 USBStorage2_GetPort();
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();
extern int usb_libogc_mode;
#define DEVICE_TYPE_WII_UMS (('W'<<24)|('U'<<16)|('M'<<8)|'S')
extern const DISC_INTERFACE __io_usbstorage2_port0;
extern const DISC_INTERFACE __io_usbstorage2_port1;
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
#ifndef __USBSTORAGE_LIBOGC_H__
#define __USBSTORAGE_LIBOGC_H__
#if defined(HW_RVL)
#include <gctypes.h>
#include <ogc/mutex.h>
#include <ogc/disc_io.h>
#include <ogc/system.h>
#include <ogc/usbstorage.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
s32 USBStorage_OGC_Initialize();
s32 USBStorage_OGC_Open(usbstorage_handle *dev, s32 device_id, u16 vid, u16 pid);
s32 USBStorage_OGC_Close(usbstorage_handle *dev);
s32 USBStorage_OGC_Reset(usbstorage_handle *dev);
s32 USBStorage_OGC_GetMaxLUN(usbstorage_handle *dev);
s32 USBStorage_OGC_MountLUN(usbstorage_handle *dev, u8 lun);
s32 USBStorage_OGC_Suspend(usbstorage_handle *dev);
s32 USBStorage_OGC_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors);
s32 USBStorage_OGC_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer);
s32 USBStorage_OGC_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer);
s32 USBStorage_OGC_StartStop(usbstorage_handle *dev, u8 lun, u8 lo_ej, u8 start, u8 imm);
extern DISC_INTERFACE __io_usbstorage_ogc;
u32 USB_OGC_GetSectorSize();
u32 USB_OGC_GetCapacity();
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* HW_RVL */
#endif /* __USBSTORAGE_H__ */

View File

@ -1,8 +1,6 @@
//Enable the line below to always write SD log
//#define sd_write_log
#define filebuffer 1024
#include <gccore.h>
#include <malloc.h>
#include <stdio.h>
@ -19,9 +17,7 @@ bool geckoinit = false;
bool textVideoInit = false;
bool bufferMessages = true;
bool WriteToSD = false;
char *tmpfilebuffer = NULL;
u32 tmpbuffersize = filebuffer + 1 * sizeof(char);
char tmpfilebuffer[1024];
static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len)
{
@ -69,30 +65,13 @@ static void USBGeckoOutput()
devoptab_list[STD_ERR] = &gecko_out;
}
void ClearLogBuffer()
{
if(tmpfilebuffer == NULL)
return;
free(tmpfilebuffer);
tmpfilebuffer = NULL;
}
void WriteToFile(char* tmp)
{
if(tmpfilebuffer == NULL)
if(!bufferMessages)
return;
if(bufferMessages)
{
if((strlen(tmpfilebuffer) + strlen(tmp)) < filebuffer)
strcat(tmpfilebuffer, tmp);
}
else
{
free(tmpfilebuffer);
tmpfilebuffer = NULL;
return;
}
if((strlen(tmpfilebuffer) + strlen(tmp)) < 1024)
strcat(tmpfilebuffer, tmp);
if(WriteToSD)
{
@ -100,7 +79,7 @@ void WriteToFile(char* tmp)
if(outfile)
{
fwrite(tmpfilebuffer, 1, strlen(tmpfilebuffer), outfile);
memset(tmpfilebuffer, 0, tmpbuffersize);
memset(tmpfilebuffer, 0, 1024);
fclose(outfile);
}
}
@ -168,6 +147,7 @@ bool InitGecko()
return geckoinit;
USBGeckoOutput();
memset(tmpfilebuffer, 0, 1024);
#ifdef sd_write_log
WriteToSD = true;
@ -182,10 +162,3 @@ bool InitGecko()
}
return geckoinit;
}
void AllocSDGeckoBuffer()
{
tmpfilebuffer = (char*)malloc(tmpbuffersize);
if(tmpfilebuffer != NULL)
memset(tmpfilebuffer, 0, tmpbuffersize);
}

View File

@ -15,8 +15,6 @@ extern bool WriteToSD;
void gprintf(const char *format, ...);
void ghexdump(void *d, int len);
bool InitGecko();
void AllocSDGeckoBuffer();
void ClearLogBuffer();
#ifdef __cplusplus
}

View File

@ -86,12 +86,16 @@ bool loadIOS(int ios, bool launch_game, bool emu_channel)
WDVD_Close();
USBStorage2_Deinit();
mload_close();
bool iosOK = true;
gprintf("Reloading into IOS %i from %i...\n", ios, IOS_GetVersion());
Nand::Instance()->DeInit_ISFS();
bool iosOK = IOS_ReloadIOS(ios) == 0;
Nand::Instance()->Init_ISFS();
gprintf("AHBPROT after IOS Reload: %u\n", (*HW_AHBPROT == 0xFFFFFFFF));
if(ios != IOS_GetVersion())
{
gprintf("Reloading into IOS %i from %i...\n", ios, IOS_GetVersion());
Nand::Instance()->DeInit_ISFS();
iosOK = IOS_ReloadIOS(ios) == 0;
Nand::Instance()->Init_ISFS();
gprintf("AHBPROT after IOS Reload: %u\n", (*HW_AHBPROT == 0xFFFFFFFF));
}
IOS_GetCurrentIOSInfo();
if(CurrentIOS.Type == IOS_TYPE_HERMES)

View File

@ -118,13 +118,13 @@ u8 IOS_GetType(u8 slot)
u32 TMD_Length;
signed_blob *TMD_Buffer = GetTMD(slot, &TMD_Length);
if(TMD_Buffer == NULL)
return IOS_TYPE_NO_CIOS;
return IOS_TYPE_STUB;
tmd *iosTMD = (tmd*)SIGNATURE_PAYLOAD(TMD_Buffer);
if(Title_GetSize_FromTMD(iosTMD) < 0x100000 || iosTMD->title_version == 65280)
{
MEM2_free(TMD_Buffer);
return IOS_TYPE_NO_CIOS;
return IOS_TYPE_STUB;
}
u32 title_rev = iosTMD->title_version;
MEM2_free(TMD_Buffer);
@ -156,7 +156,7 @@ u8 IOS_GetType(u8 slot)
if(IOS_D2X(slot, &base))
return IOS_TYPE_D2X;
else
return IOS_TYPE_NO_CIOS;
return IOS_TYPE_NORMAL_IOS;
}
}

View File

@ -36,6 +36,9 @@ void Sys_ExitTo(int);
void Open_Inputs(void);
void Close_Inputs(void);
extern void __exception_setreload(int t);
extern int mainIOS;
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -19,15 +19,10 @@
#include "loader/cios.h"
#include "loader/nk.h"
#include "menu/menu.hpp"
#include "memory/memory.h"
CMenu *mainMenu;
extern "C"
{
extern void __exception_setreload(int t);
extern int mainIOS;
}
int main(int argc, char **argv)
{
__exception_setreload(5);
@ -40,8 +35,6 @@ int main(int argc, char **argv)
Nand::Instance()->Init_ISFS();
MEM2_init(47); //Should be safe to use
vid.waitMessage(0.15f);
AllocSDGeckoBuffer();
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);
char *gameid = NULL;
@ -81,10 +74,15 @@ int main(int argc, char **argv)
CurrentIOS.Revision = 999;
DCFlushRange(&CurrentIOS, sizeof(IOS_Info));
}
else
else if(*HW_AHBPROT != 0xFFFFFFFF)
{
gprintf("Loading cIOS: %d\n", mainIOS);
iosOK = loadIOS(mainIOS, false, false) && CurrentIOS.Type != IOS_TYPE_NO_CIOS;
iosOK = loadIOS(mainIOS, false, false) && CustomIOS(CurrentIOS.Type);
}
else
{
gprintf("Using IOS%d and AHBPROT patched out\n", IOS_GetVersion());
iosOK = loadIOS(IOS_GetVersion(), false, false);
}
#else
iosOK = true;
@ -100,10 +98,10 @@ int main(int argc, char **argv)
{
Open_Inputs(); //(re)init wiimote
#ifndef DOLPHIN
DeviceHandler::Instance()->MountSD();
const DISC_INTERFACE *handle = DeviceHandler::GetUSB0Interface();
bool deviceAvailable = false;
u8 timeout = 0;
DeviceHandler::Instance()->MountSD();
while(!deviceAvailable && timeout++ != 20)
{
deviceAvailable = (handle->startup() && handle->isInserted());

View File

@ -515,13 +515,11 @@ void CMenu::cleanup(bool hb)
wiiLightOff();
_deinitNetwork();
Close_Inputs();
LWP_MutexDestroy(m_mutex);
m_mutex = 0;
ClearLogBuffer();
Close_Inputs();
for(TexSet::iterator texture = theme.texSet.begin(); texture != theme.texSet.end(); texture++)
{
if(texture->second.data.get())
@ -2300,7 +2298,7 @@ void CMenu::_load_installed_cioses()
gprintf("Found d2x base %u in slot %u\n", base, slot);
_installed_cios[slot] = base;
}
else if(IOS_GetType(slot) != IOS_TYPE_NO_CIOS)
else if(CustomIOS(IOS_GetType(slot)))
{
gprintf("Found cIOS in slot %u\n", slot);
_installed_cios[slot] = slot;

View File

@ -938,7 +938,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id, bool emu_channel)
}
}
else if(gameIOS != 57)
gameIOS = CurrentIOS.Version;
gameIOS = mainIOS;
gprintf("Changed requested IOS to %d.\n", gameIOS);
// remap IOS to CIOS

View File

@ -6,6 +6,7 @@
extern "C" {
#endif
enum
{
TYPE_WII_GAME = 0,
@ -15,6 +16,8 @@ enum
TYPE_HOMEBREW,
TYPE_END
};
#define NoGameID(x) (x == TYPE_PLUGIN || x == TYPE_HOMEBREW)
enum
{
@ -22,10 +25,10 @@ enum
IOS_TYPE_WANIN,
IOS_TYPE_HERMES,
IOS_TYPE_KWIIRK,
IOS_TYPE_NO_CIOS,
IOS_TYPE_NORMAL_IOS,
IOS_TYPE_STUB,
};
#define NoGameID(x) (x == TYPE_PLUGIN || x == TYPE_HOMEBREW)
#define CustomIOS(x) (x != IOS_TYPE_NORMAL_IOS && x != IOS_TYPE_STUB)
#ifdef __cplusplus
}