TwlIPL/build/systemMenu_tools/NandInitializerRed/ARM9.TWL/src/process_hw_info.c
kamikawa df75b3245b 書き込むマイコンファームをSDカードのルートから選択できるようにしました。
その他コード整理。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1633 b08762b0-b915-fc4b-9d8c-17b2551a87ff
2008-06-16 07:07:43 +00:00

479 lines
13 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
Project: TwlSDK - NandInitializer
File: process_hw_info.c
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$
*---------------------------------------------------------------------------*/
#include <twl.h>
#include <nitro/snd.h>
#include <twl/fatfs.h>
#include <twl/lcfg.h>
#include <nitro/card.h>
#include <sysmenu/namut.h>
#include "kami_font.h"
#include "kami_pxi.h"
#include "process_topmenu.h"
#include "process_hw_info.h"
#include "process_auto.h"
#include "process_fade.h"
#include "cursor.h"
#include "keypad.h"
#include "hwi.h"
//
#include "TWLHWInfo_api.h"
#include "TWLSettings_api.h"
//
/*---------------------------------------------------------------------------*
Œ^’è‹`
*---------------------------------------------------------------------------*/
enum {
MENU_REGION_JAPAN = 0,
MENU_REGION_AMERICA,
MENU_REGION_EUROPE,
MENU_REGION_AUSTRALIA,
MENU_REGION_CHINA,
MENU_REGION_KOREA,
MENU_RETURN,
NUM_OF_MENU_SELECT
};
/*---------------------------------------------------------------------------*
è<E28099>è`
*---------------------------------------------------------------------------*/
#define DOT_OF_MENU_SPACE 16
#define CHAR_OF_MENU_SPACE 2
#define MENU_TOP_LINE 5
#define CURSOR_ORIGIN_X 32
#define CURSOR_ORIGIN_Y 40
#define NANDINITIALIZER_SETTING_FILE_PATH_IN_SD "sdmc:/nandinitializer.ini"
#define ROUND_UP(value, alignment) \
(((u32)(value) + (alignment-1)) & ~(alignment-1))
/*---------------------------------------------------------------------------*
“à•”•Ï<E280A2>è`
*---------------------------------------------------------------------------*/
static s8 sMenuSelectNo;
static BOOL sWirelessForceOff;
/*---------------------------------------------------------------------------*
“à•”ŠÖ<C5A0><EFBFBD>錾
*---------------------------------------------------------------------------*/
static BOOL WriteHWNormalInfoFile( void );
static BOOL WriteHWSecureInfoFile( u8 region );
//static BOOL DeleteHWInfoFile( void );
static BOOL GetNandInitializerSetting(u8* region, u8* wireless);
/*---------------------------------------------------------------------------*
ƒvƒ<76>ƒZƒXŠÖ<C5A0>è`
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
Name: HWInfo ƒvƒ<76>ƒZƒXO
Description:
Arguments: None.
Returns: next sequence
*---------------------------------------------------------------------------*/
void* HWInfoProcess0(void)
{
int i;
// •¶Žš—ñSƒNƒŠƒA
kamiFontClear();
// ƒo<C692>[ƒWƒ‡ƒ“•\ަ
kamiFontPrintf(2, 1, FONT_COLOR_BLACK, "Write Hardware Information ");
kamiFontPrintf(0, 2, FONT_COLOR_BLACK, "--------------------------------");
// ƒ<>ƒjƒ…<C692>[ˆê——
kamiFontPrintf(3, 4, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 5, FONT_COLOR_BLACK, "l REGION JAPAN l l");
kamiFontPrintf(3, 6, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 7, FONT_COLOR_BLACK, "l REGION AMERICA l l");
kamiFontPrintf(3, 8, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 9, FONT_COLOR_BLACK, "l REGION EUROPE l l");
kamiFontPrintf(3, 10, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 11, FONT_COLOR_BLACK, "l REGION AUSTRALIA l l");
kamiFontPrintf(3, 12, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 13, FONT_COLOR_BLACK, "l REGION CHINA l l");
kamiFontPrintf(3, 14, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 15, FONT_COLOR_BLACK, "l REGION KOREA l l");
kamiFontPrintf(3, 16, FONT_COLOR_BLACK, "+--------------------+----+");
kamiFontPrintf(3, 17, FONT_COLOR_BLACK, "l RETURN l l");
kamiFontPrintf(3, 18, FONT_COLOR_BLACK, "+--------------------+----+");
// Œ»<C592>Ý̃Š<C692>[ƒWƒ‡ƒ“É"now"‚Æ•\ަ
kamiFontPrintf(26, (s16)(MENU_TOP_LINE+LCFG_THW_GetRegion()*CHAR_OF_MENU_SPACE), FONT_COLOR_BLACK, "now");
// ”wŒiSƒNƒŠƒA
for (i=0;i<24;i++)
{
kamiFontFillChar( i, BG_COLOR_TRANS, BG_COLOR_TRANS );
}
// ”wŒi<C592>ã•”
kamiFontFillChar( 0, BG_COLOR_PURPLE, BG_COLOR_PURPLE );
kamiFontFillChar( 1, BG_COLOR_PURPLE, BG_COLOR_PURPLE );
kamiFontFillChar( 2, BG_COLOR_PURPLE, BG_COLOR_TRANS );
// ƒJ<C692>[ƒ\ƒ<C692>œŠO
SetCursorPos((u16)200, (u16)200);
FADE_IN_RETURN( HWInfoProcess1 );
}
/*---------------------------------------------------------------------------*
Name: HWInfo ƒvƒ<76>ƒZƒXP
Description:
Arguments: None.
Returns: next sequence
*---------------------------------------------------------------------------*/
void* HWInfoProcess1(void)
{
#ifndef NAND_INITIALIZER_LIMITED_MODE
// ƒI<C692>[ƒgŽÀ<C5BD>s—p
if (gAutoFlag)
{
return HWInfoProcess2;
}
#endif
// Iðƒ<C3B0>ƒjƒ…<C692>[Ì•Ï<E280A2>X
if ( kamiPadIsRepeatTrigger(PAD_KEY_UP) )
{
if (--sMenuSelectNo < 0) sMenuSelectNo = NUM_OF_MENU_SELECT -1;
}
else if ( kamiPadIsRepeatTrigger(PAD_KEY_DOWN) )
{
if (++sMenuSelectNo >= NUM_OF_MENU_SELECT) sMenuSelectNo = 0;
}
// ƒJ<C692>[ƒ\ƒ”zu
SetCursorPos((u16)CURSOR_ORIGIN_X, (u16)(CURSOR_ORIGIN_Y + sMenuSelectNo * DOT_OF_MENU_SPACE));
// Œˆ’è
if (kamiPadIsTrigger(PAD_BUTTON_A))
{
return HWInfoProcess2;
}
// ƒgƒbƒvƒ<76>ƒjƒ…<C692>[‚Ö–ß‚é
else if (kamiPadIsTrigger(PAD_BUTTON_B))
{
FADE_OUT_RETURN( TopmenuProcess0 );
}
return HWInfoProcess1;
}
/*---------------------------------------------------------------------------*
Name: HWInfo ƒvƒ<76>ƒZƒXQ
Description:
Arguments: None.
Returns: next sequence
*---------------------------------------------------------------------------*/
void* HWInfoProcess2(void)
{
int i;
BOOL result;
#ifndef NAND_INITIALIZER_LIMITED_MODE
// ƒI<C692>[ƒgŽÀ<C5BD>s—p
if (gAutoFlag)
{
// SDƒJ<C692>[ƒhÌnandinitializer.iniæè<E2809A>ÝèðŽæ“¾
if (!GetNandInitializerSetting((u8 *)&sMenuSelectNo, (u8 *)&sWirelessForceOff))
{
// <20>Ýè̎擾Ɏ¸”sµ½<E2809A>ê<EFBFBD>̓fƒtƒHƒƒg<C692>Ýè(REGION_JAPAN/WIRELESS_ENABLE)
sMenuSelectNo = 0;
sWirelessForceOff = FALSE;
}
}
else
#endif
{
sWirelessForceOff = LCFG_THW_IsForceDisableWireless();
}
switch( sMenuSelectNo )
{
case MENU_REGION_JAPAN:
case MENU_REGION_AMERICA:
case MENU_REGION_EUROPE:
case MENU_REGION_AUSTRALIA:
case MENU_REGION_CHINA:
case MENU_REGION_KOREA:
result = WriteHWInfoFile( (u8)sMenuSelectNo, sWirelessForceOff );
// SƒŠ<C692>[ƒWƒ‡ƒ“ÌŒ‰ÊðƒNƒŠƒA
for (i=0;i<NUM_OF_MENU_SELECT;i++)
{
kamiFontPrintf(26, (s16)(MENU_TOP_LINE+i*CHAR_OF_MENU_SPACE), FONT_COLOR_BLACK, " ");
}
// <20>¡‰ñÌŒ‰Êð•\ަ
if ( result == TRUE )
{
kamiFontPrintf(26, (s16)(MENU_TOP_LINE+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_GREEN, "OK ");
}
else
{
kamiFontPrintf(26, (s16)(MENU_TOP_LINE+sMenuSelectNo*CHAR_OF_MENU_SPACE), FONT_COLOR_RED, "NG ");
}
break;
case MENU_RETURN:
FADE_OUT_RETURN( TopmenuProcess0 );
break;
}
#ifndef NAND_INITIALIZER_LIMITED_MODE
// Auto—p
if (gAutoFlag)
{
if (result)
{
gAutoProcessResult[AUTO_PROCESS_MENU_HARDWARE_INFO] = AUTO_PROCESS_RESULT_SUCCESS;
FADE_OUT_RETURN( AutoProcess1 );
}
else
{
gAutoProcessResult[AUTO_PROCESS_MENU_HARDWARE_INFO] = AUTO_PROCESS_RESULT_FAILURE;
FADE_OUT_RETURN( AutoProcess2 );
}
}
#endif
return HWInfoProcess1;
}
/*---------------------------------------------------------------------------*
<20>ˆ<CB86>ŠÖ<C5A0>è`
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
Name: HW<48>î•ñSÌ̃‰ƒCƒg
Description:
Arguments: region :
Returns: None.
*---------------------------------------------------------------------------*/
BOOL WriteHWInfoFile( u8 region, BOOL wirelessForceOff )
{
static const char *pMsgSecureWriting = "Writing Secure File...";
static const char *pMsgNormalWriting = "Writing Normal File...";
static const char *pMsgSignWriting = "Writing Sign File...";
static const char *pMsgSucceeded = "Success!\n";
static const char *pMsgFailed = "Failed!\n";
u32 installedSoftBoxCount = 0;
BOOL result = TRUE;
// ƒZƒLƒ…ƒAƒtƒ@ƒCƒÌƒ‰ƒCƒg
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSecureWriting );
if( HWI_WriteHWSecureInfoFile( region, NULL, wirelessForceOff ) ) {
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
}else {
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
result = FALSE;
}
// ƒm<C692>[ƒ}ƒƒtƒ@ƒCƒÌƒ‰ƒCƒg(ˆÚ<CB86>s‰Â”\ȃ†ƒj<C692>[ƒNID̽ßɃZƒLƒ…ƒAƒtƒ@ƒCƒÌŒãÅ<E2809A>«<E2809A>žÞ<E2809A>j
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgNormalWriting );
if( HWI_WriteHWNormalInfoFile() ) {
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
}else {
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
result = FALSE;
}
// HWID<49><44>¼ƒtƒ@ƒCƒÌƒ‰ƒCƒg
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSignWriting );
if( HWI_WriteHWIDSignFile() ) {
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
}else {
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
result = FALSE;
}
// CFGƒf<C692>[ƒ^Ì<E2809A>C<EFBFBD>³
if (!HWI_ModifyLanguage( region ))
{
kamiFontPrintfConsoleEx(CONSOLE_RED, "Fail! Write TWLSettings\n" );
result = FALSE;
}
return result;
}
/*---------------------------------------------------------------------------*
Name: HWInfoƒtƒ@ƒCƒÌ<E2809A>í<EFBFBD>œ
Description:
Arguments: None.
Returns: None.
*---------------------------------------------------------------------------*/
static BOOL DeleteHWInfoFile( void )
{
static const char *pMsgNormalDeleting = "Deleting Normal File...";
static const char *pMsgSecureDeleting = "Deteting Secure File...";
static const char *pMsgSucceeded = "Success!\n";
static const char *pMsgFailed = "Failed!\n";
BOOL result = TRUE;
// ƒm<C692>[ƒ}ƒƒtƒ@ƒCƒ
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgNormalDeleting );
if( HWI_DeleteHWNormalInfoFile() ) {
OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH );
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
}else {
OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_NORMAL_PATH );
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
result = FALSE;
}
// ƒZƒLƒ…ƒAƒtƒ@ƒCƒ
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSecureDeleting );
if( HWI_DeleteHWSecureInfoFile() ) {
OS_TPrintf( "%s delete succeeded.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH );
kamiFontPrintfConsoleEx(CONSOLE_ORANGE, pMsgSucceeded );
}else {
OS_TPrintf( "%s delete failed.\n", (char *)LCFG_TWL_HWINFO_SECURE_PATH );
kamiFontPrintfConsoleEx(CONSOLE_RED, pMsgFailed );
result = FALSE;
}
return result;
}
/*---------------------------------------------------------------------------*
Name: GetNandInitializerSetting
Description: SDƒJ<C692>[ƒhÌnandinitializer.iniÌ<E2809A>ÝèðŠm”FµÜ·
Arguments: None.
Returns: None.
*---------------------------------------------------------------------------*/
static BOOL GetNandInitializerSetting(u8* region, u8* wireless)
{
FSFile file;
BOOL open_is_ok;
BOOL read_is_ok;
void* pTempBuf;
char* pStr;
u8 temp_region;
u8 temp_wireless;
u32 file_size;
u32 alloc_size;
// ROMƒtƒ@ƒCƒƒI<C692>[ƒvƒ“
FS_InitFile(&file);
open_is_ok = FS_OpenFile(&file, NANDINITIALIZER_SETTING_FILE_PATH_IN_SD);
if (!open_is_ok)
{
OS_Printf("%s is not exist.\n", NANDINITIALIZER_SETTING_FILE_PATH_IN_SD);
return FALSE;
}
// ROMƒtƒ@ƒCƒƒŠ<C692>[ƒh
file_size = FS_GetFileLength(&file) ;
alloc_size = ROUND_UP(file_size, 32) ;
pTempBuf = OS_Alloc( alloc_size );
SDK_NULL_ASSERT(pTempBuf);
DC_InvalidateRange(pTempBuf, alloc_size);
read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size );
if (!read_is_ok)
{
OS_Printf("%s could not be read.\n", NANDINITIALIZER_SETTING_FILE_PATH_IN_SD);
FS_CloseFile(&file);
OS_Free(pTempBuf);
return FALSE;
}
// ROMƒtƒ@ƒCƒƒNƒ<4E><C692>[ƒY
FS_CloseFile(&file);
// REGION: ‚ð“ǂݎæ‚é
pStr = STD_SearchString( pTempBuf, "REGION:");
if (pStr == NULL)
{
OS_Free(pTempBuf);
return FALSE;
}
pStr += STD_GetStringLength("REGION:");
temp_region = (u8)(*pStr - '0');
if (OS_TWL_REGION_JAPAN <= temp_region && temp_region < OS_TWL_REGION_MAX)
{
*region = temp_region;
}
else
{
OS_Free(pTempBuf);
return FALSE;
}
// ­<E280B9>§ƒ<C2A7>ƒCƒ„ƒŒƒXOFF<46>Ýèð“ÇÝŽæé
pStr = STD_SearchString( pTempBuf, "WIRELESS_FORCE_OFF:");
if (pStr == NULL)
{
OS_Free(pTempBuf);
return FALSE;
}
pStr += STD_GetStringLength("WIRELESS_FORCE_OFF:");
temp_wireless = (u8)(*pStr - '0');
if (0 <= temp_wireless && temp_wireless <= 1)
{
*wireless = temp_wireless;
}
else
{
OS_Free(pTempBuf);
return FALSE;
}
OS_Free(pTempBuf);
return TRUE;
}