change FW buffer and signheap to allocate from heap.

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@678 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
sato_masaki 2008-02-15 07:48:16 +00:00
parent 7dabde21d3
commit 1681310385
2 changed files with 25 additions and 12 deletions

View File

@ -10,9 +10,9 @@
not be disclosed to third parties or copied or duplicated in any form, not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo. in whole or in part, without the prior written consent of Nintendo.
$Date:: $ $Date:: 2008-02-15#$
$Rev: $ $Rev: 677 $
$Author: $ $Author: sato_masaki $
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#include <twl.h> #include <twl.h>
#include <twl/nam.h> #include <twl/nam.h>
@ -33,9 +33,11 @@
#define USE_ACSIGN 0 /* for experimental purpose */ #define USE_ACSIGN 0 /* for experimental purpose */
#define SIGN_LENGTH 128 #define SIGN_LENGTH 128
#define FWBUFFER_SIZE 0x40000
#define SIGNHEAP_SIZE 0x01000
static u32 nwmBuf[NWM_SYSTEM_BUF_SIZE/sizeof(u32)] ATTRIBUTE_ALIGN(32); static u32 nwmBuf[NWM_SYSTEM_BUF_SIZE/sizeof(u32)] ATTRIBUTE_ALIGN(32);
static u32 fwBuffer[256*1024/sizeof(u32)] ATTRIBUTE_ALIGN(32); static u8* fwBuffer = 0;
static u8 signHeap[0x1000];
#if (MEASURE_WIRELESS_INITTIME == 1) #if (MEASURE_WIRELESS_INITTIME == 1)
static OSTick startTick; static OSTick startTick;
#endif #endif
@ -56,6 +58,7 @@ static void nwmcallback(void* arg)
err = NWM_UnloadDevice(nwmcallback); err = NWM_UnloadDevice(nwmcallback);
} else { } else {
OS_TPrintf("Wlan firm:Load Device Timeout Error!\n"); OS_TPrintf("Wlan firm:Load Device Timeout Error!\n");
SYSM_Free( fwBuffer );
} }
break; break;
case NWM_APIID_UNLOAD_DEVICE: case NWM_APIID_UNLOAD_DEVICE:
@ -64,10 +67,12 @@ static void nwmcallback(void* arg)
OS_TPrintf("Wlan firm:LoadTime=%dmsec\n", OS_TicksToMilliSeconds(OS_GetTick() - startTick)); OS_TPrintf("Wlan firm:LoadTime=%dmsec\n", OS_TicksToMilliSeconds(OS_GetTick() - startTick));
#endif #endif
OS_TPrintf("Wlan firm:Wlan firmware has been installed successfully!\n"); OS_TPrintf("Wlan firm:Wlan firmware has been installed successfully!\n");
SYSM_Free( fwBuffer );
/* [TODO:] osSendMessage */ /* [TODO:] osSendMessage */
break; break;
default: default:
OS_TWarning("Wlan firm:Error(invalid apiid=0x%04X)!\n", cb->apiid); OS_TWarning("Wlan firm:Error(invalid apiid=0x%04X)!\n", cb->apiid);
SYSM_Free( fwBuffer );
break; break;
} }
@ -159,6 +164,7 @@ BOOL verifyWlanfirmSignature(u8* buffer, u32 length)
SVCSHA1Context sctx; SVCSHA1Context sctx;
SVCSignHeapContext rctx; SVCSignHeapContext rctx;
int i; int i;
u8* signHeap;
#if (MEASURE_VERIFY_SIGN_TIME == 1) #if (MEASURE_VERIFY_SIGN_TIME == 1)
OSTick vstart = OS_GetTick(); OSTick vstart = OS_GetTick();
#endif #endif
@ -190,7 +196,8 @@ BOOL verifyWlanfirmSignature(u8* buffer, u32 length)
#if ( USE_ACSIGN == 1) #if ( USE_ACSIGN == 1)
ACSign_SetAllocFunc( SYSM_Alloc, SYSM_Free ); ACSign_SetAllocFunc( SYSM_Alloc, SYSM_Free );
#else #else
SVC_InitSignHeap( &rctx, signHeap, sizeof(signHeap)); signHeap = SYSM_Alloc( SIGNHEAP_SIZE );
SVC_InitSignHeap( &rctx, signHeap, SIGNHEAP_SIZE);
#endif #endif
MI_CpuClear8( signDigest, 0x80 ); MI_CpuClear8( signDigest, 0x80 );
@ -200,10 +207,13 @@ BOOL verifyWlanfirmSignature(u8* buffer, u32 length)
#else #else
if (FALSE == SVC_DecryptSign( &rctx, signDigest, (const void*)pSign, (const void*)pPubkey )) if (FALSE == SVC_DecryptSign( &rctx, signDigest, (const void*)pSign, (const void*)pPubkey ))
{ {
SYSM_Free(signHeap);
return FALSE; return FALSE;
} }
#endif #endif
SYSM_Free(signHeap);
OS_TPrintf("Decrypted digest: "); OS_TPrintf("Decrypted digest: ");
for (i = 0; i < SVC_SHA1_DIGEST_SIZE; i++ ) for (i = 0; i < SVC_SHA1_DIGEST_SIZE; i++ )
{ {
@ -237,22 +247,25 @@ BOOL InstallWirelessFirmware(void)
return FALSE; return FALSE;
} }
/* [TODO:] fwBuffer should be allocated from heap. */ /* fwBuffer should be allocated from heap. */
fwBuffer = SYSM_Alloc( FWBUFFER_SIZE );
flen = readFirmwareBinary((u8*)fwBuffer, sizeof(fwBuffer)); flen = readFirmwareBinary(fwBuffer, FWBUFFER_SIZE);
if ( 0 > flen ) if ( 0 > flen )
{ {
OS_TWarning("Couldn't read wlan firmware.\n"); OS_TWarning("Couldn't read wlan firmware.\n");
SYSM_Free( fwBuffer );
return FALSE; return FALSE;
} }
/* /*
[TODO:] check signature data [TODO:] check signature data
*/ */
if (FALSE == verifyWlanfirmSignature((u8*)fwBuffer, (u32)flen)) if (FALSE == verifyWlanfirmSignature(fwBuffer, (u32)flen))
{ {
OS_TWarning("Illegal Wlan Firmware has been loaded!\n"); OS_TWarning("Illegal Wlan Firmware has been loaded!\n");
SYSM_Free( fwBuffer );
return FALSE; return FALSE;
} }

View File

@ -10,9 +10,9 @@
not be disclosed to third parties or copied or duplicated in any form, not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo. in whole or in part, without the prior written consent of Nintendo.
$Date:: $ $Date:: 2008-02-15#$
$Rev: $ $Rev: 677 $
$Author: $ $Author: sato_masaki $
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
#ifndef __LAUNCHER_WIRELESS_H__ #ifndef __LAUNCHER_WIRELESS_H__