-App now exits properly on error, and textures are freed

-Fixed loading bar and cogs not appearing during upload
-More work on rewriting IOS_ReloadIOS() so that cogs pause less
-Cogs disappear if there is an error
-A little more code cleanup
This commit is contained in:
Joostinonline 2013-10-25 19:14:36 +00:00
parent bb7dcdf19d
commit 4a2bbe92ae
6 changed files with 159 additions and 51 deletions

View File

@ -8,4 +8,5 @@ void InitThread(void);
void * DrawCogThread(void *arg); void * DrawCogThread(void *arg);
s32 PauseThread(void); s32 PauseThread(void);
s32 ResumeThread(void); s32 ResumeThread(void);
s32 StopThread(void);
#endif #endif

View File

@ -168,8 +168,7 @@ int initGUI(void) {
} }
void deinitGUI(void) { void deinitGUI(void) {
//StopThread(); StopThread();
done = 1;
GRRLIB_FreeTTF(myFont); GRRLIB_FreeTTF(myFont);
GRRLIB_FreeTexture(tex_background_png); GRRLIB_FreeTexture(tex_background_png);
GRRLIB_FreeTexture(tex_Checkicon_png); GRRLIB_FreeTexture(tex_Checkicon_png);
@ -203,7 +202,7 @@ void DrawDuringSort(void) {
int printError(const char* msg) { int printError(const char* msg) {
int i; int i;
//PauseThread(); PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE);
GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE); GRRLIB_PrintfTTF((640-strlen(msg)*9)/2, 256, myFont, msg, 20, HEX_WHITE);
@ -218,7 +217,7 @@ int printError(const char* msg) {
int printSuccess(const char* msg) { int printSuccess(const char* msg) {
int i; int i;
//PauseThread(); PauseThread();
//GRRLIB_ClearTex(tex_ScreenBuf); //GRRLIB_ClearTex(tex_ScreenBuf);
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE);
@ -334,7 +333,7 @@ inline void DrawCog(void) {
int printEndError(const char* msg) { int printEndError(const char* msg) {
int i; int i;
//PauseThread(); PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE);
@ -398,6 +397,7 @@ int printReport(char report[200][100], int firstLine, bool completeReport) {
int printUploadSuccess(const char* msg) { int printUploadSuccess(const char* msg) {
int i; int i;
PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Checkicon_png, 0, 1, 1, HEX_WHITE);
@ -417,6 +417,7 @@ int printUploadSuccess(const char* msg) {
int printUploadError(const char* msg) { int printUploadError(const char* msg) {
int i; int i;
PauseThread();
GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(0, 0, tex_background_png, 0, 1, 1, HEX_WHITE);
GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE); GRRLIB_DrawImg(256, 112, tex_Deleteicon_png, 0, 1, 1, HEX_WHITE);

View File

@ -32,6 +32,10 @@ distribution.
// This is just stripped down code from ios.c. // This is just stripped down code from ios.c.
// I didn't do any extra work, I'm just making it faster for this one situation // I didn't do any extra work, I'm just making it faster for this one situation
#if defined(HW_RVL)
#include <gctypes.h>
#include <gcutil.h>
#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <malloc.h>
#include <ogc/machine/asm.h> #include <ogc/machine/asm.h>
@ -43,34 +47,83 @@ distribution.
#include <ogc/ios.h> #include <ogc/ios.h>
#include <ogc/irq.h> #include <ogc/irq.h>
#define IOS_HEAP_SIZE 0x1000
#define MAX_IPC_RETRIES 400 #define MAX_IPC_RETRIES 400
extern void udelay(int us); extern void udelay(int us);
void ReloadIOS(int version) { // These two functions deal with the "internal" IOS subsystems that are used by default by libogc
__STM_Close(); // Other stuff should be inited by the user and deinited by the exit callbacks. The user is also responsible
// for deiniting other stuff before an IOS reload and reiniting them after.
/*static s32 __IOS_InitializeSubsystems(void)
{
s32 res;
s32 ret = 0;
res = __ES_Init();
if(res < 0) {
ret = res;
}
res = __STM_Init();
if(res < 0) {
ret = res;
}
return ret;
}
static s32 __IOS_ShutdownSubsystems(void)
{
s32 res;
s32 ret = 0;
res = __STM_Close();
if(res < 0) ret = res;
res = __ES_Close();
if(res < 0) ret = res;
return ret;
}
*/
static s32 LaunchNewIOS(int version)
{
u32 numviews; u32 numviews;
s32 res;
u64 titleID = 0x100000000LL; u64 titleID = 0x100000000LL;
raw_irq_handler_t irq_handler; //raw_irq_handler_t irq_handler;
u32 counter; u32 counter;
STACK_ALIGN(tikview,views,4,32); STACK_ALIGN(tikview,views,4,32);
s32 newversion;
if(version < 3 || version > 0xFF) {
return IOS_EBADVERSION;
}
titleID |= version; titleID |= version;
ES_GetNumTicketViews(titleID, &numviews); res = ES_GetNumTicketViews(titleID, &numviews);
if(res < 0) {
ES_GetTicketViews(titleID, views, numviews); return res;
}
if(numviews > 4) {
printf(" GetNumTicketViews too many views: %u\n",numviews);
return IOS_ETOOMANYVIEWS;
}
res = ES_GetTicketViews(titleID, views, numviews);
if(res < 0) {
return res;
}
write32(0x80003140, 0); write32(0x80003140, 0);
ES_LaunchTitleBackground(titleID, &views[0]); res = ES_LaunchTitleBackground(titleID, &views[0]);
if(res < 0) {
return res;
}
__ES_Reset(); __ES_Reset();
// Mask IPC IRQ while we're busy reloading // Mask IPC IRQ while we're busy reloading
__MaskIrq(IRQ_PI_ACR); //__MaskIrq(IRQ_PI_ACR);
irq_handler = IRQ_Free(IRQ_PI_ACR); //irq_handler = IRQ_Free(IRQ_PI_ACR);
while ((read32(0x80003140) >> 16) == 0) while ((read32(0x80003140) >> 16) == 0)
udelay(1000); udelay(1000);
@ -81,10 +134,48 @@ void ReloadIOS(int version) {
break; break;
} }
IRQ_Request(IRQ_PI_ACR, irq_handler, NULL); //IRQ_Request(IRQ_PI_ACR, irq_handler, NULL);
__UnmaskIrq(IRQ_PI_ACR); //__UnmaskIrq(IRQ_PI_ACR);
__IPC_Reinitialize(); __IPC_Reinitialize();
__ES_Init();
__STM_Init(); newversion = IOS_GetVersion();
if(newversion != version) {
return IOS_EMISMATCH;
}
return version;
} }
s32 ReloadIOS(int version)
{
int ret = 0;
int res = 0;
//res = __IOS_ShutdownSubsystems();
if(res < 0) {
ret = res;
}
res = __ES_Init();
if(res < 0) {
ret = res;
} else {
res = LaunchNewIOS(version);
if(res < 0) {
ret = res;
__ES_Close();
}
}
res = __IOS_InitializeSubsystems();
if(res < 0) {
ret = res;
}
return ret;
}
#endif /* defined(HW_RVL) */

View File

@ -28,6 +28,7 @@
#include "gui.h" #include "gui.h"
#include "languages.h" #include "languages.h"
#include "fatMounter.h" #include "fatMounter.h"
#include "thread.h"
// Constants // Constants
@ -478,7 +479,7 @@ char GetSysMenuRegion(u32 sysVersion) {
case 54449: // mauifrog 4.1U case 54449: // mauifrog 4.1U
case 481: //4.2U case 481: //4.2U
case 513: //4.3U case 513: //4.3U
//case 545: case 545:
SysMenuRegion = 'U'; SysMenuRegion = 'U';
break; break;
case 130: //2.0E case 130: //2.0E
@ -521,7 +522,6 @@ char GetSysMenuRegion(u32 sysVersion) {
SysMenuRegion = 'K'; SysMenuRegion = 'K';
break; break;
default: default:
//SysMenuRegion = 'X';
SysMenuRegion = getSystemMenuRegionFromContent(); SysMenuRegion = getSystemMenuRegionFromContent();
break; break;
} }
@ -536,23 +536,19 @@ void zero_sig(signed_blob *sig)
// Get the boot2 version // Get the boot2 version
u32 GetBoot2Version(void) inline u32 GetBoot2Version(void)
{ {
u32 boot2version = 0; u32 boot2version = 0;
if (ES_GetBoot2Version(&boot2version) < 0) boot2version = 0; if (ES_GetBoot2Version(&boot2version) < 0) boot2version = 0;
return boot2version; return boot2version;
} }
// Get the console ID // Get the console ID
u32 GetDeviceID(void) inline u32 GetDeviceID(void)
{ {
u32 deviceId = 0; u32 deviceId = 0;
if (ES_GetDeviceID(&deviceId) < 0) deviceId = 0; if (ES_GetDeviceID(&deviceId) < 0) deviceId = 0;
return deviceId; return deviceId;
} }
@ -631,7 +627,7 @@ bool CheckVersionPatch(void)
//RemoveBogusTicket(); //RemoveBogusTicket();
/*gpritnf(); /*gprintf();
int ret2 = ES_AddTitleStart((signed_blob *)v1_tmd, v1_tmd_size, (signed_blob *)v1_cert, v1_cert_size, 0, 0); int ret2 = ES_AddTitleStart((signed_blob *)v1_tmd, v1_tmd_size, (signed_blob *)v1_cert, v1_cert_size, 0, 0);
if (ret2 >= 0) ES_AddTitleCancel(); if (ret2 >= 0) ES_AddTitleCancel();
@ -854,7 +850,7 @@ char *url_encode(char *str) {
} }
void transmitSyscheck(char ReportBuffer[200][100], int *lines) { void transmitSyscheck(char ReportBuffer[200][100], int *lines) {
ResumeThread();
printLoadingBar(TXT_Upload, 0); printLoadingBar(TXT_Upload, 0);
gprintf("TempReport bauen\n"); gprintf("TempReport bauen\n");
@ -899,6 +895,7 @@ void transmitSyscheck(char ReportBuffer[200][100], int *lines) {
http_get_result(&http_status, &outbuf, &lenght); http_get_result(&http_status, &outbuf, &lenght);
printLoadingBar(TXT_Upload, 100); printLoadingBar(TXT_Upload, 100);
PauseThread();
(*lines)++; (*lines)++;
memset(ReportBuffer[*lines], 0, 100); memset(ReportBuffer[*lines], 0, 100);

View File

@ -44,13 +44,13 @@ char miosInfo[128] = {0};
extern void __exception_setreload(int t); extern void __exception_setreload(int t);
// Stripped down version of IOS_ReloadIOS, run inline // Stripped down version of IOS_ReloadIOS, run inline
//inline void ReloadIOS(int version) { inline void ReloadIOS2(int version) {
// //__IOS_ShutdownSubsystems(); //__IOS_ShutdownSubsystems();
// __ES_Init(); __ES_Init();
// __IOS_LaunchNewIOS(version); __IOS_LaunchNewIOS(version);
// __IOS_InitializeSubsystems(); __IOS_InitializeSubsystems();
// //WII_LaunchTitle(TITLE_ID(0x00000001,version)); //WII_LaunchTitle(TITLE_ID(0x00000001,version));
//} }
int get_title_ios(u64 title) { int get_title_ios(u64 title) {
s32 ret, fd; s32 ret, fd;
@ -366,9 +366,12 @@ int main(int argc, char **argv)
u32 tempTitles; u32 tempTitles;
if (ES_GetNumTitles(&tempTitles) < 0) { if (ES_GetNumTitles(&tempTitles) < 0) {
PauseThread();
printError(ERR_GetNrOfTitles); printError(ERR_GetNrOfTitles);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
//return false;
} }
s32 nbTitles = tempTitles; s32 nbTitles = tempTitles;
@ -379,7 +382,8 @@ int main(int argc, char **argv)
sprintf(MSG_Buffer, ERR_AllocateMemory, titles); sprintf(MSG_Buffer, ERR_AllocateMemory, titles);
printError(MSG_Buffer); printError(MSG_Buffer);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
// Get list of titles // Get list of titles
@ -388,7 +392,8 @@ int main(int argc, char **argv)
if (ES_GetTitles(titles, nbTitles) < 0) { if (ES_GetTitles(titles, nbTitles) < 0) {
printError(ERR_GetTitleList); printError(ERR_GetTitleList);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
int i; int i;
@ -489,7 +494,8 @@ int main(int argc, char **argv)
sprintf(MSG_Buffer, ERR_GetIosTMDSize, ios[i].titleID); sprintf(MSG_Buffer, ERR_GetIosTMDSize, ios[i].titleID);
printError(MSG_Buffer); printError(MSG_Buffer);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
iosTMDBuffer = (signed_blob*)memalign(32, (tmdSize+31)&(~31)); iosTMDBuffer = (signed_blob*)memalign(32, (tmdSize+31)&(~31));
@ -503,7 +509,8 @@ int main(int argc, char **argv)
sprintf(MSG_Buffer, ERR_GetIosTMD, ios[i].titleID); sprintf(MSG_Buffer, ERR_GetIosTMD, ios[i].titleID);
printError(MSG_Buffer); printError(MSG_Buffer);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
iosTMD = (tmd*)SIGNATURE_PAYLOAD(iosTMDBuffer); iosTMD = (tmd*)SIGNATURE_PAYLOAD(iosTMDBuffer);
@ -578,7 +585,8 @@ int main(int argc, char **argv)
sprintf(MSG_Buffer, ERR_GetIosTMDSize, 2); sprintf(MSG_Buffer, ERR_GetIosTMDSize, 2);
printError(MSG_Buffer); printError(MSG_Buffer);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
iosTMDBuffer = (signed_blob*)memalign(32, (tmdSize+31)&(~31)); iosTMDBuffer = (signed_blob*)memalign(32, (tmdSize+31)&(~31));
@ -590,7 +598,8 @@ int main(int argc, char **argv)
sprintf(MSG_Buffer, ERR_GetIosTMD, 2); sprintf(MSG_Buffer, ERR_GetIosTMD, 2);
printError(MSG_Buffer); printError(MSG_Buffer);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(0x20); char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(0x20);
@ -630,7 +639,8 @@ int main(int argc, char **argv)
if (!GetCertificates()) { if (!GetCertificates()) {
printError(ERR_GetCertificates); printError(ERR_GetCertificates);
sleep(5); sleep(5);
return false; deinitGUI();
exit(1);
} }
//Select an IOS to test //Select an IOS to test
@ -758,8 +768,8 @@ int main(int argc, char **argv)
// Reload IOS // Reload IOS
gprintf("// IOS_ReloadIOS(%d)\n", ios[i].titleID); gprintf("// IOS_ReloadIOS(%d)\n", ios[i].titleID);
logfile("// IOS_ReloadIOS(%d)\r\n", ios[i].titleID); logfile("// IOS_ReloadIOS(%d)\r\n", ios[i].titleID);
IOS_ReloadIOS(ios[i].titleID); //IOS_ReloadIOS(ios[i].titleID);
//ReloadIOS(ios[i].titleID); ReloadIOS(ios[i].titleID);
// Test fake signature // Test fake signature
gprintf("// Test fake signature\n"); gprintf("// Test fake signature\n");
@ -825,7 +835,8 @@ int main(int argc, char **argv)
// Reload the running IOS // Reload the running IOS
IOS_ReloadIOS(runningIOS); //IOS_ReloadIOS(runningIOS);
ReloadIOS(runningIOS);
sprintf(MSG_Buffer, MSG_ReloadIOS, runningIOS, runningIOSRevision); sprintf(MSG_Buffer, MSG_ReloadIOS, runningIOS, runningIOSRevision);
printLoading(MSG_Buffer); printLoading(MSG_Buffer);
//usleep(250000); //usleep(250000);
@ -1179,7 +1190,8 @@ int main(int argc, char **argv)
if (wpressed & WPAD_BUTTON_HOME) { if (wpressed & WPAD_BUTTON_HOME) {
// Unmount the SD Card // Unmount the SD Card
UnmountSD(); UnmountSD();
if(*LOADER_STUB) return true; deinitGUI();
if(*LOADER_STUB) exit(0);;
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
} }
@ -1187,6 +1199,7 @@ int main(int argc, char **argv)
if (wpressed & WPAD_BUTTON_PLUS) { if (wpressed & WPAD_BUTTON_PLUS) {
// Unmount the SD Card // Unmount the SD Card
UnmountSD(); UnmountSD();
deinitGUI();
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
} }
@ -1194,6 +1207,7 @@ int main(int argc, char **argv)
if (wpressed & WPAD_BUTTON_MINUS) { if (wpressed & WPAD_BUTTON_MINUS) {
// Unmount the SD Card // Unmount the SD Card
UnmountSD(); UnmountSD();
deinitGUI();
SYS_ResetSystem(SYS_POWEROFF, 0, 0); SYS_ResetSystem(SYS_POWEROFF, 0, 0);
} }

View File

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include <ogc/lwp.h> #include <ogc/lwp.h>
@ -29,6 +30,7 @@ void * DrawCogThread(void *arg) {
inline void InitThread(void) { inline void InitThread(void) {
memset (&stack, 0, STACKSIZE); memset (&stack, 0, STACKSIZE);
LWP_CreateThread (&Cog_Thread, DrawCogThread, NULL, stack, STACKSIZE, PRIORITY); LWP_CreateThread (&Cog_Thread, DrawCogThread, NULL, stack, STACKSIZE, PRIORITY);
usleep(200);
} }
inline s32 PauseThread(void) { inline s32 PauseThread(void) {
@ -41,6 +43,8 @@ inline s32 ResumeThread(void) {
return LWP_ResumeThread(Cog_Thread); return LWP_ResumeThread(Cog_Thread);
} }
//inline s32 StopThread(void) { inline s32 StopThread(void) {
// return LWP_JoinThread(Cog_Thread, NULL); done = 1;
//} ResumeThread();
return LWP_JoinThread(Cog_Thread, NULL);
}