-made homebrew booting more safe, shouldnt blackscreen

or codedump anymore
This commit is contained in:
fix94.1 2012-05-19 16:06:06 +00:00
parent b0e0b005b3
commit 8643cdfa5a
6 changed files with 44 additions and 68 deletions

View File

@ -24,8 +24,6 @@ static u8 *homebrewbuffer = EXECUTE_ADDR;
static u32 homebrewsize = 0; static u32 homebrewsize = 0;
static vector<string> Arguments; static vector<string> Arguments;
bool bootHB;
bool IsDollZ (u8 *buff) bool IsDollZ (u8 *buff)
{ {
u8 dollz_stamp[] = {0x3C}; u8 dollz_stamp[] = {0x3C};
@ -40,27 +38,11 @@ bool IsDollZ (u8 *buff)
void AddBootArgument(const char * argv) void AddBootArgument(const char * argv)
{ {
std::string arg(argv); string arg(argv);
Arguments.push_back(arg); Arguments.push_back(arg);
} }
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len) int LoadHomebrew(const char *filepath)
{
homebrewsize += len;
memcpy(homebrewbuffer+pos, temp, len);
DCFlushRange(homebrewbuffer+pos, len);
return 1;
}
void FreeHomebrewBuffer()
{
homebrewbuffer = EXECUTE_ADDR;
homebrewsize = 0;
Arguments.clear();
}
int LoadHomebrew(const char * filepath)
{ {
if(!filepath) if(!filepath)
return -1; return -1;
@ -73,15 +55,7 @@ int LoadHomebrew(const char * filepath)
u32 filesize = ftell(file); u32 filesize = ftell(file);
rewind(file); rewind(file);
if(filesize > 33554431) fread(homebrewbuffer, 1, filesize, file);
return -3;
bool good_read = fread(homebrewbuffer, 1, filesize, file) == filesize;
if (!good_read)
{
fclose(file);
return -4;
}
fclose(file); fclose(file);
homebrewsize += filesize; homebrewsize += filesize;
@ -129,9 +103,6 @@ static int SetupARGV(struct __argv * args)
int BootHomebrew() int BootHomebrew()
{ {
if(homebrewsize == 0)
return -1;
struct __argv args; struct __argv args;
if (!IsDollZ(homebrewbuffer)) if (!IsDollZ(homebrewbuffer))
SetupARGV(&args); SetupARGV(&args);
@ -139,13 +110,16 @@ int BootHomebrew()
memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size); memcpy(BOOTER_ADDR, app_booter_bin, app_booter_bin_size);
DCFlushRange(BOOTER_ADDR, app_booter_bin_size); DCFlushRange(BOOTER_ADDR, app_booter_bin_size);
entrypoint entry = (entrypoint) BOOTER_ADDR; entrypoint entry = (entrypoint)BOOTER_ADDR;
memmove(ARGS_ADDR, &args, sizeof(args)); memmove(ARGS_ADDR, &args, sizeof(args));
DCFlushRange(ARGS_ADDR, sizeof(args) + args.length); DCFlushRange(ARGS_ADDR, sizeof(args) + args.length);
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); /* Shutdown IOS subsystems */
u32 level = IRQ_Disable();
__IOS_ShutdownSubsystems();
__exception_closeall();
entry(); entry();
IRQ_Restore(level);
return 0; return 0;
} }

View File

@ -1,10 +1,8 @@
#ifndef _BOOTHOMEBREW_H_ #ifndef _BOOTHOMEBREW_H_
#define _BOOTHOMEBREW_H_ #define _BOOTHOMEBREW_H_
extern bool bootHB;
int BootHomebrew(); int BootHomebrew();
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len); void AddBootArgument(const char * arg);
void AddBootArgument(const char * arg); int LoadHomebrew(const char * filepath);
void FreeHomebrewBuffer();
int LoadHomebrew(const char * filepath);
#endif #endif

View File

@ -136,11 +136,6 @@ int main(int argc, char **argv)
ret = menu.main(); ret = menu.main();
} }
} }
if (bootHB)
{
//IOS_ReloadIOS(58);
BootHomebrew();
}
Open_Inputs(); //reinit wiimote Open_Inputs(); //reinit wiimote
} while (ret == 1); } while (ret == 1);

View File

@ -134,7 +134,6 @@ CMenu::CMenu(CVideo &vid) :
m_exit = false; m_exit = false;
m_initialCoverStatusComplete = false; m_initialCoverStatusComplete = false;
m_reload = false; m_reload = false;
bootHB = false;
m_gamesound_changed = false; m_gamesound_changed = false;
m_base_font_size = 0; m_base_font_size = 0;
m_current_view = COVERFLOW_USB; m_current_view = COVERFLOW_USB;

View File

@ -32,8 +32,10 @@
using namespace std; using namespace std;
extern "C" {extern u8 currentPartition;} extern "C"
extern bool bootHB; {
extern u8 currentPartition;
}
class CMenu class CMenu
{ {

View File

@ -515,7 +515,8 @@ void CMenu::_game(bool launch)
gprintf("Launching game %s\n", id.c_str()); gprintf("Launching game %s\n", id.c_str());
_launch(hdr); _launch(hdr);
if(m_exit || bootHB) break; if(m_exit)
break;
_hideWaitMessage(); _hideWaitMessage();
launch = false; launch = false;
@ -768,29 +769,36 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool DML)
void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments) void CMenu::_launchHomebrew(const char *filepath, vector<string> arguments)
{ {
Nand::Instance()->Disable_Emu();
m_reload = true;
gprintf("Filepath of homebrew: %s\n",filepath); gprintf("Filepath of homebrew: %s\n",filepath);
if(LoadHomebrew(filepath))
{
m_gcfg1.save(true);
m_gcfg2.save(true);
m_cat.save(true);
m_cfg.save(true);
AddBootArgument(filepath); m_gcfg1.save(true);
for(u32 i = 0; i < arguments.size(); ++i) m_gcfg2.save(true);
AddBootArgument(arguments[i].c_str()); m_cat.save(true);
m_cfg.save(true);
Playlog_Delete(); while(net_get_status() == -EBUSY)
usleep(100);
cleanup(); m_vid.CheckWaitThread(true);
Close_Inputs(); Playlog_Delete();
USBStorage_Deinit(); cleanup();
// wifi and sd gecko doesnt work anymore after cleanup
Close_Inputs();
m_vid.cleanup();
wiiLightOff();
__dsp_shutdown();
Nand::Instance()->Disable_Emu(); LoadHomebrew(filepath);
DeviceHandler::DestroyInstance();
bootHB = true; USBStorage_Deinit();
} AddBootArgument(filepath);
m_exit = true; for(u32 i = 0; i < arguments.size(); ++i)
AddBootArgument(arguments[i].c_str());
gprintf("Booting Homebrew application...\n");
BootHomebrew();
} }
int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id) int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id)