From 73a648801d975efa69d7432675f0ef652283ccea Mon Sep 17 00:00:00 2001 From: aoki_ryoma Date: Wed, 20 Aug 2008 14:04:43 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E3=81=97=E3=81=84ErrorLog=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=E3=80=82=20=E4=B8=80=E3=81=A4=E4=B8=80=E3=81=A4?= =?UTF-8?q?=E3=81=AE=E3=82=A8=E3=83=B3=E3=83=88=E3=83=AA=E3=82=92=E5=85=A8?= =?UTF-8?q?=E6=96=87=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=A8=E3=80=81=E4=B8=80=E8=A1=8C=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=AE=E4=B8=80=E8=A6=A7=E3=83=A2=E3=83=BC=E3=83=89=E3=81=AE?= =?UTF-8?q?=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E3=82=92=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=80=82=20SD=E3=82=AB=E3=83=BC=E3=83=89=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E3=82=B3=E3=83=94=E3=83=BC=E6=A9=9F=E8=83=BD=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=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@2208 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/tests/FatalErrorChecker/ARM9/Makefile | 3 +- build/tests/FatalErrorChecker/ARM9/main.rsf | 4 +- build/tests/FatalErrorChecker/ARM9/src/main.c | 299 ++++++++++++++++-- 3 files changed, 285 insertions(+), 21 deletions(-) diff --git a/build/tests/FatalErrorChecker/ARM9/Makefile b/build/tests/FatalErrorChecker/ARM9/Makefile index ea5408ba..12e304a0 100644 --- a/build/tests/FatalErrorChecker/ARM9/Makefile +++ b/build/tests/FatalErrorChecker/ARM9/Makefile @@ -17,6 +17,7 @@ TARGET_FIRM = SYSTEMMENU TARGET_PLATFORM = TWL TWL_ARCHGEN = LIMITED +TWL_NANDAPP = TRUE SUBDIRS = @@ -34,7 +35,7 @@ TARGET_BIN = menu.srl LLIBRARIES += liberrorlog$(TWL_LIBSUFFIX).a - +MAKETAD_OPTION += -s include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs diff --git a/build/tests/FatalErrorChecker/ARM9/main.rsf b/build/tests/FatalErrorChecker/ARM9/main.rsf index 2b08f05f..eb5a249c 100644 --- a/build/tests/FatalErrorChecker/ARM9/main.rsf +++ b/build/tests/FatalErrorChecker/ARM9/main.rsf @@ -151,7 +151,7 @@ Property # # SDCardAccess: sd card access control [TRUE/FALSE] # - #SDCardAccess FALSE + SDCardAccess TRUE # # NANDAccess: NAND access control [TRUE/FALSE] @@ -201,7 +201,7 @@ AppendProperty # # Boot allowed Media: [GameCard] # - Media NAND + Media gamecard # # Data only title : [TRUE/FALSE] diff --git a/build/tests/FatalErrorChecker/ARM9/src/main.c b/build/tests/FatalErrorChecker/ARM9/src/main.c index 638a2bef..e71902a9 100644 --- a/build/tests/FatalErrorChecker/ARM9/src/main.c +++ b/build/tests/FatalErrorChecker/ARM9/src/main.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------* - Project: TwlSDK - NandInitializer + Project: TwlIPL - Tests - FatalErrorChecker File: main.c Copyright 2008 Nintendo. All rights reserved. @@ -22,15 +22,23 @@ #include "keypad.h" #define FATAL_ERROR_MAX 45 -#define NUM_ENTRY_PER_PAGE 7 -#define NUM_LINE_PER_ENTRY 3 -#define SKIP_SPAN 7 +#define NUM_ENTRY_PER_PAGE 5 +#define NUM_LINE_PER_ENTRY 4 +#define SKIP_SPAN 5 #define FOOTER_Y 22 +#define ASK_LINE_OFFSET 8 +#define RESULT_LINE_OFFSET 10 + +#define DST_LOGFILE_PATH "sdmc:/sysmenu.log" + /*---------------------------------------------------------------------------* 内部変数定義 *---------------------------------------------------------------------------*/ static char *s_strError[ FATAL_ERROR_MAX ]; +static BOOL nowEntryView; +static BOOL nowAsking; +static BOOL resetConsoleFlag; static int drawIndex = 0; static int numEntry; /*---------------------------------------------------------------------------* @@ -40,6 +48,11 @@ static void VBlankIntr(void); static void InitAllocation(void); static void drawErrorLog( void ); static void control(); +static void removeLC( char *dst, const char *src ); +static void drawMessage( void ); +static void kamiFontPrintfWrap( s16 x, s16 y, u8 color, char *fmt, ... ); +static BOOL copyLogToSD( void ); +static void drawMenu( void ); /*---------------------------------------------------------------------------* Name: TwlMain @@ -52,6 +65,8 @@ static void control(); void TwlMain() { + char tst[] = "\n\n\n\n\na"; + OS_Init(); OS_InitArena(); PXI_Init(); @@ -93,13 +108,10 @@ TwlMain() ERRORLOG_Init( OS_AllocFromMain, OS_FreeToMain ); - kamiFontPrintfConsole( CONSOLE_ORANGE, "How to \n"); - kamiFontPrintfConsole( CONSOLE_ORANGE, "+-----------------------------+\n"); - kamiFontPrintfConsole( CONSOLE_ORANGE, "l Up/Down Key : Scroll line l\n"); - kamiFontPrintfConsole( CONSOLE_ORANGE, "l Left/Right Key: Scroll page l\n"); - kamiFontPrintfConsole( CONSOLE_ORANGE, "+-----------------------------+\n"); - numEntry = ERRORLOG_GetNum(); + nowEntryView = FALSE; + nowAsking = FALSE; + resetConsoleFlag = TRUE; while (1) { @@ -111,37 +123,146 @@ TwlMain() // フォントスクリーンデータロード kamiFontLoadScreenData(); + + if( resetConsoleFlag ) + { + drawMenu(); + resetConsoleFlag = FALSE; + } // 操作検出と描画 control(); - drawErrorLog(); + + if( nowEntryView ) + { + drawMessage(); + } + else + { + drawErrorLog(); + } } } +static void drawMessage( void ) +{ + char titlebuf[5]; + const ErrorLogEntry *entry = ERRORLOG_Read( drawIndex ); + kamiFontClear(); + + if( entry->isBroken ) + { + kamiFontPrintf( 0, 0 , FONT_COLOR_BLACK, "%02d: Broken Entry", drawIndex); + + kamiFontPrintfWrap( 0, 2, FONT_COLOR_BLACK, "%s\n" ,entry->errorStr ); + + } + else if( entry->isLauncherError ) + { + STD_CopyLStringZeroFill( titlebuf, (char*)&entry->titleId, 5); + + kamiFontPrintf( 0, 0, FONT_COLOR_BLACK, "%02d: RED %02d/%02d/%02d %02d:%02d:%02d" , + drawIndex , entry->year, entry->month, entry->day, + entry->hour, entry->minute, entry->second ); + + kamiFontPrintf( 0, 1, FONT_COLOR_BLACK, "titleID: %s errorCode: %d", + titlebuf, entry->errorCode ); + + kamiFontPrintf( 0, 3, FONT_COLOR_BLACK, s_strError[entry->errorCode] ); + + } + else{ + STD_CopyLStringZeroFill( titlebuf, (char*)&entry->titleId, 5); + + kamiFontPrintf( 0, 0 , FONT_COLOR_BLACK, "%02d: FFT %02d/%02d/%02d %02d:%02d:%02d" , + drawIndex , entry->year, entry->month, entry->day, + entry->hour, entry->minute, entry->second ); + + kamiFontPrintf( 0, 1, FONT_COLOR_BLACK, "titleID: %s", titlebuf ); + + kamiFontPrintfWrap( 0, 3, FONT_COLOR_BLACK, entry->errorStr ); + + } + +} + static void drawErrorLog( void ) { + char titlebuf[5]; u16 i; kamiFontClear(); for( i = 0; i < NUM_ENTRY_PER_PAGE && i+drawIndex < numEntry ; i++ ) { + u8 color = (i == 0) ? (u8)FONT_COLOR_BLUE : (u8)FONT_COLOR_BLACK; const ErrorLogEntry *entry = ERRORLOG_Read( i + drawIndex ); - kamiFontPrintf( 0, i * NUM_LINE_PER_ENTRY , 0, "%02d: %02d/%02d/%02d %02d:%02d:%02d Err: %d" , - i + drawIndex , entry->year, entry->month, entry->day, - entry->hour, entry->minute, entry->second, entry->errorCode ); - - kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 1, 0, s_strError[entry->errorCode] ); + char drawBuf[257]; + if( entry->isBroken ) + { + kamiFontPrintf( 0, i * NUM_LINE_PER_ENTRY , color, "%02d: Broken Entry", i + drawIndex); + + // 改行を取り除いてから表示 + removeLC( drawBuf, entry->errorStr ); + kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 1, color, drawBuf ); + + } + else if( entry->isLauncherError ) + { + STD_CopyLStringZeroFill( titlebuf, (char*)&entry->titleId, 5); + + kamiFontPrintf( 0, i * NUM_LINE_PER_ENTRY , color, "%02d: RED %02d/%02d/%02d %02d:%02d:%02d" , + i + drawIndex , entry->year, entry->month, entry->day, + entry->hour, entry->minute, entry->second ); + + kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 1, color, "titleID: %s errorCode: %d", + titlebuf, entry->errorCode ); + + kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 2, color, s_strError[entry->errorCode] ); + } + else{ + STD_CopyLStringZeroFill( titlebuf, (char*)&entry->titleId, 5); + + kamiFontPrintf( 0, i * NUM_LINE_PER_ENTRY , color, "%02d: FFT %02d/%02d/%02d %02d:%02d:%02d" , + i + drawIndex , entry->year, entry->month, entry->day, + entry->hour, entry->minute, entry->second ); + + kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 1, color, "titleID: %s", titlebuf ); + + // 改行を取り除いてから表示 + removeLC( drawBuf, entry->errorStr ); + kamiFontPrintf( 0, ( i * NUM_LINE_PER_ENTRY ) + 2, color, drawBuf ); + + } } - kamiFontPrintf( 0, FOOTER_Y , 0, "numEntry : %d", numEntry ); + kamiFontPrintf( 0, FOOTER_Y , FONT_COLOR_BLACK, "numEntry : %d", numEntry ); } static void control() { + if( nowAsking ) + { + // 本当にやるの?って聞いてる最中 + if( kamiPadIsTrigger( PAD_BUTTON_A )) + { + BOOL result = copyLogToSD(); + nowAsking = FALSE; + } + + if( kamiPadIsTrigger( PAD_BUTTON_B )) + { + drawMenu(); + nowAsking = FALSE; + } + + return; + } + + if( kamiPadIsTrigger( PAD_KEY_UP ) ) { drawIndex--; @@ -160,11 +281,152 @@ static void control() drawIndex += SKIP_SPAN; } + if( kamiPadIsTrigger( PAD_BUTTON_A ) ) + { + nowEntryView = !nowEntryView ; + } + else if( kamiPadIsTrigger( PAD_BUTTON_X ) ) + { + drawMenu(); + kamiFontPrintfMain( 0, ASK_LINE_OFFSET, CONSOLE_ORANGE, "Copying Logfile to SD. OK ?"); + kamiFontPrintfMain( 0, ASK_LINE_OFFSET + 1, CONSOLE_ORANGE, "A: Decide B: Cancel"); + + nowAsking = TRUE; + } + // 操作の結果、描画インデクスがはみ出しそうだったら修正 - drawIndex = numEntry - NUM_ENTRY_PER_PAGE < drawIndex ? numEntry - NUM_ENTRY_PER_PAGE: drawIndex ; + drawIndex = numEntry-1 < drawIndex ? numEntry-1 : drawIndex ; drawIndex = drawIndex < 0 ? 0: drawIndex; } +// srcから改行を取り除いてdstに引き渡す +static void removeLC( char *dst, const char *src ) +{ + char *idx; + STD_StrCpy( dst, src ); + + while( ( idx = STD_StrChr( dst, '\n' )) != NULL ) + { + *idx = ' '; + } +} + + +static void kamiFontPrintfWrap( s16 x, s16 y, u8 color, char *fmt, ... ) +{ + va_list vlist; + char temp[256 + 2]; + char *head, *tail; + + va_start(vlist, fmt); + (void)vsnprintf(temp, 256, fmt, vlist); + va_end(vlist); + + head = temp; + + // 終端追加 + temp[256] = '\0'; + + // 自前でctok的な事をして改行を別々に出力する + tail = STD_StrChr( temp, '\n' ); + do + { + *tail = '\0'; + kamiFontPrintf( x, y, color, head ); + head = tail+1; + tail = STD_StrChr( head, '\n' ); + y++; + } while ( tail != NULL ); + + kamiFontPrintf( x, y, color, head ); +} + + +static BOOL copyLogToSD( void ) +{ + FSFile src, dst; + char buf[256 + 1]; + s32 readSize; + + buf[256] = '\0'; + FS_InitFile( &dst ); + + // まずファイルを削除 + FS_DeleteFile( DST_LOGFILE_PATH ); + + if( ! FS_CreateFile( DST_LOGFILE_PATH, FS_PERMIT_R | FS_PERMIT_W ) ) + { + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_CreateFile" ); + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+2, CONSOLE_ORANGE, "errorCode : %d", FS_GetArchiveResultCode( DST_LOGFILE_PATH ) ); + return FALSE; + } + + // ファイル作成に成功 + if( !( FS_OpenFileEx( &dst , DST_LOGFILE_PATH, FS_FILEMODE_RW ) && + ( FS_SetFileLength( &dst, ERRORLOG_SIZE ) == FS_RESULT_SUCCESS ) ) ) + { + // 作成したファイルをopenできなかった場合 + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_OpenFile / FS_SetFileLength" ); + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+2, CONSOLE_ORANGE, "errorCode : %d", FS_GetArchiveResultCode( DST_LOGFILE_PATH ) ); + return FALSE; + } + + // サイズ変更が終わったら、念のためファイルサイズ変更不可なRWLモードで開きなおしておく + FS_CloseFile( &dst ); + + if( !FS_OpenFileEx( &dst, DST_LOGFILE_PATH, FS_FILEMODE_RWL ) ) + { + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_OpenFile" ); + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+2, CONSOLE_ORANGE, "errorCode : %d", FS_GetArchiveResultCode( DST_LOGFILE_PATH ) ); + return FALSE; + } + + src = ERRORLOGi_getLogFilePt(); + + if( !FS_SeekFileToBegin( &src )) + { + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_SeekFileToBegin" ); + return FALSE; + } + + while( ( readSize = FS_ReadFile( &src, buf, 256 )) > 0 ) + { + if( FS_WriteFile( &dst, buf, readSize ) < 0 ) + { + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_WriteFile" ); + return FALSE; + } + } + + if( !FS_CloseFile( &dst )) + { + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Failed!") ; + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET+1, CONSOLE_ORANGE, "func: FS_CloseFile" ); + } + kamiFontPrintfMain( 0, RESULT_LINE_OFFSET, CONSOLE_ORANGE, "Copy Succeeded!") ; + + return TRUE; + +} + +static void drawMenu( void ) +{ + int line = 0; + + kamiFontClearMain(); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "How to"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "+-----------------------------+"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "l U/D Key : Line Scroll l"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "l L/R Key : Page Scroll l"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "l A Button : Switch View Mode l"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "l X Button : Copy to SDCard l"); + kamiFontPrintfMain( 0, line++, CONSOLE_ORANGE, "+-----------------------------+"); +} /*---------------------------------------------------------------------------* Name: VBlankIntr @@ -205,6 +467,7 @@ static void InitAllocation(void) } + static char *s_strError[ FATAL_ERROR_MAX ] = { "FATAL_ERROR_UNDEFINED", "FATAL_ERROR_NAND",