無線ファームウェアダウンロード用ラッパー関数の雛形を作成。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@660 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
sato_masaki 2008-02-14 12:11:49 +00:00
parent cbc4e4fed9
commit 92c67ca84c
3 changed files with 170 additions and 73 deletions

View File

@ -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 <twl.h>
#include <twl/nam.h>
#include <twl/os/common/format_rom.h>
#include <twl/lcfg.h>
#include <firm.h>
#include "loadWlanFirm.h"
/* LCFGの無線ファームバージョンをタイトルとしてそのまま使う場合 */
#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]*/
}

View File

@ -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__

View File

@ -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