From 92c67ca84ccf45e5d90650e7896e75830d82d7b0 Mon Sep 17 00:00:00 2001 From: sato_masaki Date: Thu, 14 Feb 2008 12:11:49 +0000 Subject: [PATCH] =?UTF-8?q?=E7=84=A1=E7=B7=9A=E3=83=95=E3=82=A1=E3=83=BC?= =?UTF-8?q?=E3=83=A0=E3=82=A6=E3=82=A7=E3=82=A2=E3=83=80=E3=82=A6=E3=83=B3?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E7=94=A8=E3=83=A9=E3=83=83=E3=83=91?= =?UTF-8?q?=E3=83=BC=E9=96=A2=E6=95=B0=E3=81=AE=E9=9B=9B=E5=BD=A2=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@660 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- .../Launcher/ARM9/src/loadWlanFirm.c | 207 ++++++++++++------ .../Launcher/ARM9/src/loadWlanFirm.h | 34 ++- build/systemMenu_RED/Launcher/ARM9/src/main.c | 2 +- 3 files changed, 170 insertions(+), 73 deletions(-) diff --git a/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.c b/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.c index 51bac4fc..97c0884e 100644 --- a/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.c +++ b/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.c @@ -10,26 +10,36 @@ 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. - $Date:: - $Rev: - $Author: + $Date:: $ + $Rev: $ + $Author: $ *---------------------------------------------------------------------------*/ #include #include #include #include +#include + #include "loadWlanFirm.h" /* LCFGの無線ファームバージョンをタイトルIDとしてそのまま使う場合 */ -#define USE_LCFG_STRING 0 +#define USE_LCFG_STRING 0 +#define WLANFIRM_PUBKEY_INDEX 1 static int isNwmActive; static u32 nwmBuf[NWM_SYSTEM_BUF_SIZE/sizeof(u32)] ATTRIBUTE_ALIGN(32); static u32 fwBuffer[256*1024/sizeof(u32)] ATTRIBUTE_ALIGN(32); +static s32 readFirmwareBinary(u8 *buffer, s32 bufSize); +static BOOL verifyWlanfirmSignature(u8* buffer); +/* [TODO:] HotStart/ColdStartを判別するためのもの。ランチャーでの定義ができたら削除? */ +typedef enum { + COLD_START, + HOT_START +} BOOT_POLICY; static void nwmcallback(void* arg) { @@ -55,91 +65,146 @@ static void nwmcallback(void* arg) } - -BOOL WirelessFirmwareDownloadStart(void) +s32 readFirmwareBinary(u8 *buffer, s32 bufSize) { - char path[256]; - FSFile file[1]; - - u8 title[4]; + char path[256]; + FSFile file[1]; + u8 title[4]; + s32 flen; #if( USE_LCFG_STRING == 0 ) - char *title0 = "WFW0"; - char *title1 = "WFW1"; + char *title0 = "WFW0"; + char *title1 = "WFW1"; #endif - u32 titleID_hi; - u32 titleID_lo; - u64 titleID = 0; - s32 flen = 0; - NWMRetCode err; - int i; + u32 titleID_hi; + u32 titleID_lo; + u64 titleID = 0; - - LCFG_THW_GetWirelessFirmTitleID_Lo( title ); + LCFG_THW_GetWirelessFirmTitleID_Lo( title ); #if( USE_LCFG_STRING == 0 ) - if( title[0] == 0 ) { - for( i = 0 ; i < 4 ; i++ ) { - title[i] = (u8)*title0++; + { + int i; + if( title[0] == 0 ) { + for( i = 0 ; i < 4 ; i++ ) { + title[i] = (u8)*title1++; + } + } + else { + for( i = 0 ; i < 4 ; i++ ) { + title[i] = (u8)*title0++; + } + } } - } - else { - for( i = 0 ; i < 4 ; i++ ) { - title[i] = (u8)*title1++; - } - } #endif - titleID_hi = (( 3 /* Nintendo */ << 16) | 4 /* */ | 1 /* */); + titleID_hi = (( 3 /* Nintendo */ << 16) | 4 /* */ | 1 /* */); - titleID_lo = ((u32)( title[0] ) & 0xff) << 24; - titleID_lo |= ((u32)( title[1] )& 0xff) << 16; - titleID_lo |= ((u32)( title[2] )& 0xff) << 8; - titleID_lo |= (u32)( title[3] ) & 0xff; + titleID_lo = ((u32)( title[0] ) & 0xff) << 24; + titleID_lo |= ((u32)( title[1] )& 0xff) << 16; + titleID_lo |= ((u32)( title[2] )& 0xff) << 8; + titleID_lo |= (u32)( title[3] ) & 0xff; - titleID = ((u64)(titleID_hi) << 32) | (u64)titleID_lo; - - // OS_TPrintf( "titleID = 0x%08x%08x\n", titleID_hi, titleID_lo); + titleID = ((u64)(titleID_hi) << 32) | (u64)titleID_lo; - isNwmActive = 0; + // OS_TPrintf( "titleID = 0x%08x%08x\n", titleID_hi, titleID_lo); - if( NAM_OK == NAM_GetTitleBootContentPathFast(path, titleID) ) { - OS_TPrintf( "File = %s\n", path); - } - else { - OS_TPrintf( "Error: NAM_GetTitleBootContentPathFast titleID = 0x%08x0x%08x\n",titleID_hi, titleID_lo); - return FALSE; - } + if( NAM_OK == NAM_GetTitleBootContentPathFast(path, titleID) ) { + OS_TPrintf( "File = %s\n", path); + } + else { + OS_TPrintf( "Error: NAM_GetTitleBootContentPathFast titleID = 0x%08x0x%08x\n",titleID_hi, titleID_lo); + return -1; + } - if (!FS_OpenFileEx(file, path, FS_FILEMODE_R)) { - OS_TWarning("FS_OpenFileEx(%s) failed.\n", path); - return FALSE; - } + if (!FS_OpenFileEx(file, path, FS_FILEMODE_R)) { + OS_TWarning("FS_OpenFileEx(%s) failed.\n", path); + return -1; + } - if( FALSE == FS_SeekFile(file, sizeof(ROM_Header), FS_SEEK_SET) ) { - OS_TWarning("FS_SeekFile failed.\n"); - return FALSE; - } + if( FALSE == FS_SeekFile(file, sizeof(ROM_Header), FS_SEEK_SET) ) { + OS_TWarning("FS_SeekFile failed.\n"); + return -1; + } - flen = FS_ReadFile(file, fwBuffer, sizeof(fwBuffer)); - if( flen == -1 ) { - OS_TWarning("FS_ReadFile failed.\n"); - return FALSE; - } + flen = FS_ReadFile(file, buffer, bufSize); + if( flen == -1 ) { + OS_TWarning("FS_ReadFile failed.\n"); + return -1; + } - (void)FS_CloseFile(file); + (void)FS_CloseFile(file); - - /*************************************************************/ - - NWM_Init(nwmBuf, sizeof(nwmBuf), 3); /* 3 -> DMA no. */ - - (void)NWMi_InstallFirmware(fwBuffer, (u32)flen); - - err = NWM_LoadDevice(nwmcallback); - - /* osRecvMessage */ - - return TRUE; + return flen; +} + +BOOL verifyWlanfirmSignature(u8* buffer) +{ + NWMFirmHeader *hdr = (NWMFirmHeader*)buffer; + u8 *pPubkey; + + pPubkey = OSi_GetFromFirmAddr()->rsa_pubkey[WLANFIRM_PUBKEY_INDEX]; +// OS_TWarning("Pubkey addr %x\n", pPubkey); + + /* calculate SHA-1 digest */ + + /* decrypt according to RSA security */ + + /* verify digest */ + + return TRUE; + +} + +BOOL StartupWireless(void) +{ + s32 flen = 0; + NWMRetCode err; + u8 boot_policy = COLD_START; + + /* [TODO:] HotStart/ColdStartのチェック */ + + + if (boot_policy == COLD_START) + { + flen = readFirmwareBinary((u8*)fwBuffer, sizeof(fwBuffer)); + + if ( 0 > flen ) + { + OS_TWarning("Couldn't read wlan firmware.\n"); + return FALSE; + } + + /* + [TODO:] check signature data + */ + + } + + isNwmActive = 0; + + /*************************************************************/ + + NWM_Init(nwmBuf, sizeof(nwmBuf), 3); /* 3 -> DMA no. */ + + /* In the case of cold start, should register appropriate firmware. */ + if (boot_policy == COLD_START) + { + if ( 0 < flen ) + { + (void)NWMi_InstallFirmware(fwBuffer, (u32)flen); + } + } + + err = NWM_LoadDevice(nwmcallback); + + /* osRecvMessage */ + + return TRUE; +} + +BOOL CleanupWireless(void) +{ + /* [TBD]*/ } diff --git a/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.h b/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.h index 128aee8d..15f8af84 100644 --- a/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.h +++ b/build/systemMenu_RED/Launcher/ARM9/src/loadWlanFirm.h @@ -1,2 +1,34 @@ +/*---------------------------------------------------------------------------* + Project: TWL_RED_IPL - + File: loadWlanFirm.h -BOOL WirelessFirmwareDownloadStart(void); + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + 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. + + $Date:: $ + $Rev: $ + $Author: $ + *---------------------------------------------------------------------------*/ + +#ifndef __LAUNCHER_WIRELESS_H__ +#define __LAUNCHER_WIRELESS_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +BOOL StartupWireless(void); +BOOL CleanupWireless(void); + +#ifdef __cplusplus +} +#endif + +#endif // __LAUNCHER_WIRELESS_H__ diff --git a/build/systemMenu_RED/Launcher/ARM9/src/main.c b/build/systemMenu_RED/Launcher/ARM9/src/main.c index cf37dfc3..8c2a504c 100644 --- a/build/systemMenu_RED/Launcher/ARM9/src/main.c +++ b/build/systemMenu_RED/Launcher/ARM9/src/main.c @@ -188,7 +188,7 @@ void TwlMain( void ) // 無線ファームウェアを無線モジュールにダウンロードする。 #if( WIRELESS_FIRM_LOADING == 1 ) - if( FALSE == WirelessFirmwareDownloadStart() ) { + if( FALSE == StartupWireless() ) { OS_TPrintf( "ERROR: Wireless firmware download failed!\n" ); } #endif