Created
August 29, 2010 13:41
-
-
Save lukegb/556296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- libogc/ios.c 2009-10-05 12:32:06.000000000 +0100 | |
+++ /home/lukegb/libogc_tt_source/libogc/ios.new.c 2010-08-29 02:37:21.265624866 +0100 | |
@@ -31,6 +31,7 @@ | |
#if defined(HW_RVL) | |
#include <stdio.h> | |
+#include <malloc.h> | |
#include "asm.h" | |
#include "processor.h" | |
#include "cache.h" | |
@@ -41,13 +42,12 @@ | |
#include "irq.h" | |
#define IOS_HEAP_SIZE 0x1000 | |
-#define MAX_IOS_RETRIES 2000 | |
-#define MAX_IPC_RETRIES 2000 | |
+#define MAX_IPC_RETRIES 200 | |
//#define DEBUG_IOS | |
-#define IOS_MAX_VERSION 36 | |
-#define IOS_MIN_VERSION 3 | |
+#define IOS_MAX_VERSION 61 | |
+#define IOS_MIN_VERSION 28 | |
static s32 __ios_hid = -1; | |
extern void udelay(int us); | |
@@ -114,6 +114,7 @@ | |
s32 res; | |
u32 count; | |
u64 *titles; | |
+ u32 tmd_size; | |
u32 i; | |
u32 a,b; | |
@@ -143,6 +144,14 @@ | |
iosFree(__ios_hid, titles); | |
return res; | |
} | |
+ | |
+ u32 *tmdbuffer = memalign(32, MAX_SIGNED_TMD_SIZE); | |
+ | |
+ if(!tmdbuffer) | |
+ { | |
+ iosFree(__ios_hid, titles); | |
+ return -1; | |
+ } | |
for(i=0; i<count; i++) { | |
a = titles[i]>>32; | |
@@ -150,12 +159,26 @@ | |
if(a != 1) continue; | |
if(b < IOS_MIN_VERSION) continue; | |
if(b > IOS_MAX_VERSION) continue; | |
- if(((s32)b) > ((s32)ver)) ver = b; | |
+ | |
+ if (ES_GetStoredTMDSize(titles[i], &tmd_size) < 0) | |
+ continue; | |
+ | |
+ if (tmd_size < 0 || tmd_size > 4096) | |
+ continue; | |
+ | |
+ if(ES_GetStoredTMD(titles[i], (signed_blob *)tmdbuffer, tmd_size) < 0) | |
+ continue; | |
+ | |
+ if (!tmdbuffer[1] && !tmdbuffer[2]) | |
+ continue; | |
+ | |
+ if((((s32)b) > ((s32)ver) && ver != 58) || b == 58) ver = b; | |
} | |
#ifdef DEBUG_IOS | |
printf(" Preferred verson: %d\n",ver); | |
#endif | |
iosFree(__ios_hid, titles); | |
+ free(tmdbuffer); | |
return ver; | |
} | |
@@ -201,9 +224,10 @@ | |
s32 __IOS_LaunchNewIOS(int version) | |
{ | |
u32 numviews; | |
- s32 res, retries; | |
+ s32 res; | |
u64 titleID = 0x100000000LL; | |
raw_irq_handler_t irq_handler; | |
+ u32 counter; | |
STACK_ALIGN(tikview,views,4,32); | |
#ifdef DEBUG_IOS | |
@@ -244,6 +268,8 @@ | |
return res; | |
} | |
+ write32(0x80003140, 0); | |
+ | |
res = ES_LaunchTitleBackground(titleID, &views[0]); | |
if(res < 0) { | |
#ifdef DEBUG_IOS | |
@@ -251,42 +277,52 @@ | |
#endif | |
return res; | |
} | |
- __ES_Reset(); | |
+ | |
+ __ES_Reset(); | |
// Mask IPC IRQ while we're busy reloading | |
__MaskIrq(IRQ_PI_ACR); | |
irq_handler = IRQ_Free(IRQ_PI_ACR); | |
- // Wait for old IOS to change version number before reloading | |
- for (retries = 0; retries < MAX_IOS_RETRIES; retries++) | |
- { | |
- newversion = IOS_GetVersion(); | |
#ifdef DEBUG_IOS | |
- printf(" IOS Version: IOS%d %d.%d\n",newversion,IOS_GetRevisionMajor(),IOS_GetRevisionMinor()); | |
+ printf("Waiting for IOS ...\n"); | |
#endif | |
- if (newversion != version) udelay(1000); | |
- } | |
+ while ((read32(0x80003140) >> 16) == 0) | |
+ udelay(1000); | |
- if(newversion != version) | |
- { | |
#ifdef DEBUG_IOS | |
- printf(" Version mismatch!\n"); | |
+ u32 v = read32(0x80003140); | |
+ printf("IOS loaded: IOS%d v%d.%d\n", v >> 16, (v >> 8) & 0xff, v & 0xff); | |
#endif | |
- return IOS_EMISMATCH; | |
- } | |
- // Wait for new IOS to signal IPC is ready | |
- for (retries = 0; retries < MAX_IPC_RETRIES; retries++) | |
- { | |
- if(IPC_ReadReg(1) & 2) break; | |
+#ifdef DEBUG_IOS | |
+ printf("Waiting for IPC ...\n"); | |
+#endif | |
+ for (counter = 0; !(read32(0x0d000004) & 2); counter++) { | |
udelay(1000); | |
+ | |
+ if (counter >= MAX_IPC_RETRIES) | |
+ break; | |
} | |
+#ifdef DEBUG_IOS | |
+ printf("IPC started (%u)\n", counter); | |
+#endif | |
+ | |
IRQ_Request(IRQ_PI_ACR, irq_handler, NULL); | |
__UnmaskIrq(IRQ_PI_ACR); | |
__IPC_Reinitialize(); | |
+ newversion = IOS_GetVersion(); | |
+ | |
+ if(newversion != version) { | |
+#ifdef DEBUG_IOS | |
+ printf(" Version mismatch!\n"); | |
+#endif | |
+ return IOS_EMISMATCH; | |
+ } | |
+ | |
return version; | |
} | |
@@ -312,6 +348,7 @@ | |
res = __IOS_LaunchNewIOS(version); | |
if(res < 0) return res; | |
#endif | |
+ | |
return 0; | |
} | |
@@ -319,22 +356,44 @@ | |
{ | |
int ret = 0; | |
int res; | |
+ | |
#ifdef DEBUG_IOS | |
printf("Reloading to IOS%d\n",version); | |
#endif | |
+ | |
res = __IOS_ShutdownSubsystems(); | |
- if(res < 0) ret = res; | |
+ if(res < 0) { | |
+#ifdef DEBUG_IOS | |
+ printf("__IOS_ShutdownSubsystems failed: %d\n", res); | |
+#endif | |
+ ret = res; | |
+ } | |
+ | |
res = __ES_Init(); | |
- if(res < 0) ret = res; | |
- else { | |
+ if(res < 0) { | |
+#ifdef DEBUG_IOS | |
+ printf("__ES_Init failed: %d\n", res); | |
+#endif | |
+ ret = res; | |
+ } else { | |
res = __IOS_LaunchNewIOS(version); | |
if(res < 0) { | |
+#ifdef DEBUG_IOS | |
+ printf("__IOS_LaunchNewIOS failed: %d\n", res); | |
+#endif | |
ret = res; | |
__ES_Close(); | |
} | |
} | |
+ | |
res = __IOS_InitializeSubsystems(); | |
- if(res < 0) ret = res; | |
+ if(res < 0) { | |
+#ifdef DEBUG_IOS | |
+ printf("__IOS_InitializeSubsystems failed: %d\n", res); | |
+#endif | |
+ ret = res; | |
+ } | |
+ | |
return ret; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment