mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
無線ファームウェアダウンロード用ラッパー関数の雛形を作成。
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@660 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
cbc4e4fed9
commit
92c67ca84c
@ -10,26 +10,36 @@
|
|||||||
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:: $
|
||||||
$Rev:
|
$Rev: $
|
||||||
$Author:
|
$Author: $
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
#include <twl.h>
|
#include <twl.h>
|
||||||
#include <twl/nam.h>
|
#include <twl/nam.h>
|
||||||
#include <twl/os/common/format_rom.h>
|
#include <twl/os/common/format_rom.h>
|
||||||
#include <twl/lcfg.h>
|
#include <twl/lcfg.h>
|
||||||
|
|
||||||
|
#include <firm.h>
|
||||||
|
|
||||||
#include "loadWlanFirm.h"
|
#include "loadWlanFirm.h"
|
||||||
|
|
||||||
/* LCFGの無線ファームバージョンをタイトルIDとしてそのまま使う場合 */
|
/* LCFGの無線ファームバージョンをタイトルIDとしてそのまま使う場合 */
|
||||||
#define USE_LCFG_STRING 0
|
#define USE_LCFG_STRING 0
|
||||||
|
|
||||||
|
#define WLANFIRM_PUBKEY_INDEX 1
|
||||||
|
|
||||||
static int isNwmActive;
|
static int isNwmActive;
|
||||||
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 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)
|
static void nwmcallback(void* arg)
|
||||||
{
|
{
|
||||||
@ -55,91 +65,146 @@ static void nwmcallback(void* arg)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 readFirmwareBinary(u8 *buffer, s32 bufSize)
|
||||||
BOOL WirelessFirmwareDownloadStart(void)
|
|
||||||
{
|
{
|
||||||
char path[256];
|
char path[256];
|
||||||
FSFile file[1];
|
FSFile file[1];
|
||||||
|
u8 title[4];
|
||||||
u8 title[4];
|
s32 flen;
|
||||||
|
|
||||||
#if( USE_LCFG_STRING == 0 )
|
#if( USE_LCFG_STRING == 0 )
|
||||||
char *title0 = "WFW0";
|
char *title0 = "WFW0";
|
||||||
char *title1 = "WFW1";
|
char *title1 = "WFW1";
|
||||||
#endif
|
#endif
|
||||||
u32 titleID_hi;
|
u32 titleID_hi;
|
||||||
u32 titleID_lo;
|
u32 titleID_lo;
|
||||||
u64 titleID = 0;
|
u64 titleID = 0;
|
||||||
s32 flen = 0;
|
|
||||||
NWMRetCode err;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
LCFG_THW_GetWirelessFirmTitleID_Lo( title );
|
||||||
LCFG_THW_GetWirelessFirmTitleID_Lo( title );
|
|
||||||
|
|
||||||
#if( USE_LCFG_STRING == 0 )
|
#if( USE_LCFG_STRING == 0 )
|
||||||
if( title[0] == 0 ) {
|
{
|
||||||
for( i = 0 ; i < 4 ; i++ ) {
|
int i;
|
||||||
title[i] = (u8)*title0++;
|
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
|
#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[0] ) & 0xff) << 24;
|
||||||
titleID_lo |= ((u32)( title[1] )& 0xff) << 16;
|
titleID_lo |= ((u32)( title[1] )& 0xff) << 16;
|
||||||
titleID_lo |= ((u32)( title[2] )& 0xff) << 8;
|
titleID_lo |= ((u32)( title[2] )& 0xff) << 8;
|
||||||
titleID_lo |= (u32)( title[3] ) & 0xff;
|
titleID_lo |= (u32)( title[3] ) & 0xff;
|
||||||
|
|
||||||
titleID = ((u64)(titleID_hi) << 32) | (u64)titleID_lo;
|
titleID = ((u64)(titleID_hi) << 32) | (u64)titleID_lo;
|
||||||
|
|
||||||
// OS_TPrintf( "titleID = 0x%08x%08x\n", titleID_hi, titleID_lo);
|
|
||||||
|
|
||||||
isNwmActive = 0;
|
// OS_TPrintf( "titleID = 0x%08x%08x\n", titleID_hi, titleID_lo);
|
||||||
|
|
||||||
if( NAM_OK == NAM_GetTitleBootContentPathFast(path, titleID) ) {
|
if( NAM_OK == NAM_GetTitleBootContentPathFast(path, titleID) ) {
|
||||||
OS_TPrintf( "File = %s\n", path);
|
OS_TPrintf( "File = %s\n", path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OS_TPrintf( "Error: NAM_GetTitleBootContentPathFast titleID = 0x%08x0x%08x\n",titleID_hi, titleID_lo);
|
OS_TPrintf( "Error: NAM_GetTitleBootContentPathFast titleID = 0x%08x0x%08x\n",titleID_hi, titleID_lo);
|
||||||
return FALSE;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FS_OpenFileEx(file, path, FS_FILEMODE_R)) {
|
if (!FS_OpenFileEx(file, path, FS_FILEMODE_R)) {
|
||||||
OS_TWarning("FS_OpenFileEx(%s) failed.\n", path);
|
OS_TWarning("FS_OpenFileEx(%s) failed.\n", path);
|
||||||
return FALSE;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( FALSE == FS_SeekFile(file, sizeof(ROM_Header), FS_SEEK_SET) ) {
|
if( FALSE == FS_SeekFile(file, sizeof(ROM_Header), FS_SEEK_SET) ) {
|
||||||
OS_TWarning("FS_SeekFile failed.\n");
|
OS_TWarning("FS_SeekFile failed.\n");
|
||||||
return FALSE;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flen = FS_ReadFile(file, fwBuffer, sizeof(fwBuffer));
|
flen = FS_ReadFile(file, buffer, bufSize);
|
||||||
if( flen == -1 ) {
|
if( flen == -1 ) {
|
||||||
OS_TWarning("FS_ReadFile failed.\n");
|
OS_TWarning("FS_ReadFile failed.\n");
|
||||||
return FALSE;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)FS_CloseFile(file);
|
(void)FS_CloseFile(file);
|
||||||
|
|
||||||
|
return flen;
|
||||||
/*************************************************************/
|
}
|
||||||
|
|
||||||
NWM_Init(nwmBuf, sizeof(nwmBuf), 3); /* 3 -> DMA no. */
|
BOOL verifyWlanfirmSignature(u8* buffer)
|
||||||
|
{
|
||||||
(void)NWMi_InstallFirmware(fwBuffer, (u32)flen);
|
NWMFirmHeader *hdr = (NWMFirmHeader*)buffer;
|
||||||
|
u8 *pPubkey;
|
||||||
err = NWM_LoadDevice(nwmcallback);
|
|
||||||
|
pPubkey = OSi_GetFromFirmAddr()->rsa_pubkey[WLANFIRM_PUBKEY_INDEX];
|
||||||
/* osRecvMessage */
|
// OS_TWarning("Pubkey addr %x\n", pPubkey);
|
||||||
|
|
||||||
return TRUE;
|
/* 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]*/
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 <twl.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BOOL StartupWireless(void);
|
||||||
|
BOOL CleanupWireless(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // __LAUNCHER_WIRELESS_H__
|
||||||
|
|||||||
@ -188,7 +188,7 @@ void TwlMain( void )
|
|||||||
|
|
||||||
// 無線ファームウェアを無線モジュールにダウンロードする。
|
// 無線ファームウェアを無線モジュールにダウンロードする。
|
||||||
#if( WIRELESS_FIRM_LOADING == 1 )
|
#if( WIRELESS_FIRM_LOADING == 1 )
|
||||||
if( FALSE == WirelessFirmwareDownloadStart() ) {
|
if( FALSE == StartupWireless() ) {
|
||||||
OS_TPrintf( "ERROR: Wireless firmware download failed!\n" );
|
OS_TPrintf( "ERROR: Wireless firmware download failed!\n" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user