メモリリークしていた部分を修正。

TitleIDの表示が抜けていた点について修正。
FS_CreateDirectoryをCreateDirectoryAutoに変更。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@2203 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
aoki_ryoma 2008-08-20 09:15:30 +00:00
parent 2d267d30ee
commit b50d63af47
2 changed files with 78 additions and 15 deletions

View File

@ -16,7 +16,6 @@
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
// Fatal error発生時に"nand:/sys/log/sysmenu.log"にログを吐くためのライブラリ // Fatal error発生時に"nand:/sys/log/sysmenu.log"にログを吐くためのライブラリ
//
#include <twl.h> #include <twl.h>
@ -31,15 +30,25 @@
#define ERRORLOG_BAR "====================" #define ERRORLOG_BAR "===================="
#define ERRORLOG_BAR_LENGTH 20 #define ERRORLOG_BAR_LENGTH 20
#define ERRORLOG_WRITE_FORMAT_RED ERRORLOG_BAR"\n#RED %02u-%02u-%02u[%3s] %02u:%02u:%02u ErrorCode: %u\n%s \n\0" #define ERRORLOG_WRITE_FORMAT_RED1 ERRORLOG_BAR"\n#RED %02u-%02u-%02u[%3s] %02u:%02u:%02u\n"
#define ERRORLOG_WRITE_FORMAT ERRORLOG_BAR"\n#FFT %02u-%02u-%02u[%3s] %02u:%02u:%02u \n%s \n\0" #define ERRORLOG_WRITE_FORMAT_RED2 "title: %04s ErrorCode: %u\n%s"
#define ERRORLOG_READ_FORMAT_RED ERRORLOG_BAR"\n#RED %d-%d-%d[%3s] %d:%d:%d ErrorCode: %u\n%*s \n\0" #define ERRORLOG_WRITE_FORMAT1 ERRORLOG_BAR"\n#FFT %02u-%02u-%02u[%3s] %02u:%02u:%02u\n"
#define ERRORLOG_READ_FORMAT ERRORLOG_BAR"\n#FFT %d-%d-%d[%3s] %d:%d:%d \n%s \n\0" #define ERRORLOG_WRITE_FORMAT2 "title: %04s\n%s"
#define ERRORLOG_NUM_ARGS 8 #define ERRORLOG_READ_FORMAT_RED1 ERRORLOG_BAR"\n#RED %d-%d-%d[%3s] %d:%d:%d\n"
#define ERRORLOG_READ_FORMAT_RED2 "title: %4s ErrorCode: %u\n%*s"
#define ERRORLOG_READ_FORMAT1 ERRORLOG_BAR"\n#FFT %d-%d-%d[%3s] %d:%d:%d\n"
#define ERRORLOG_READ_FORMAT2 "title: %4s\n%s"
#define ERRORLOG_WRITE_FORMAT ERRORLOG_WRITE_FORMAT1 ERRORLOG_WRITE_FORMAT2
#define ERRORLOG_WRITE_FORMAT_RED ERRORLOG_WRITE_FORMAT_RED1 ERRORLOG_WRITE_FORMAT_RED2
#define ERRORLOG_READ_FORMAT ERRORLOG_READ_FORMAT1 ERRORLOG_READ_FORMAT2
#define ERRORLOG_READ_FORMAT_RED ERRORLOG_READ_FORMAT_RED1 ERRORLOG_READ_FORMAT_RED2
#define ERRORLOG_NUM_ARGS 9
#define ERRORLOG_SIZE ( 16 * 1024 ) // ファイルは16KBサイズ固定 #define ERRORLOG_SIZE ( 16 * 1024 ) // ファイルは16KBサイズ固定
#define ERRORLOG_BUFSIZE 256 // 1エントリあたりのサイズ #define ERRORLOG_BUFSIZE 256 // 1エントリあたりのサイズ
#define ERRORLOG_STR_OFFSET 51 #define ERRORLOG_STR_OFFSET 61
#define ERRORLOG_NUM_ENTRY ( ERRORLOG_SIZE / ERRORLOG_BUFSIZE ) // ログに書き込まれるエントリの最大数 #define ERRORLOG_NUM_ENTRY ( ERRORLOG_SIZE / ERRORLOG_BUFSIZE ) // ログに書き込まれるエントリの最大数
@ -66,6 +75,7 @@ void ERRORLOGi_WriteLogToBuf( char *buf );
BOOL ERRORLOGi_WriteLogToFile( char *buf ); BOOL ERRORLOGi_WriteLogToFile( char *buf );
void ERRORLOGi_fillSpace( char *buf, int bufsize ); void ERRORLOGi_fillSpace( char *buf, int bufsize );
BOOL ERRORLOGi_WriteCommon( BOOL isLauncherError, u64 errorCode, const char *fmt, va_list arglist ); BOOL ERRORLOGi_WriteCommon( BOOL isLauncherError, u64 errorCode, const char *fmt, va_list arglist );
u32 ERRORLOGi_getTitleId( void );
static char *s_strWeek[7]; static char *s_strWeek[7];
static char *s_strError[FATAL_ERROR_MAX]; static char *s_strError[FATAL_ERROR_MAX];
@ -139,6 +149,16 @@ BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) )
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void ERRORLOG_End( void ) void ERRORLOG_End( void )
{ {
int idx;
for( idx = 0; idx < ERRORLOG_NUM_ENTRY ; idx++ )
{
if( elWork.entry[idx].errorStr != NULL )
{
elWork.Free( elWork.entry[idx].errorStr );
}
}
elWork.Free( elWork.entry ); elWork.Free( elWork.entry );
if( !FS_CloseFile( &elWork.file ) ) if( !FS_CloseFile( &elWork.file ) )
@ -207,10 +227,12 @@ BOOL ERRORLOGi_WriteCommon( BOOL isLauncherError, u64 errorCode, const char *fmt
char *writeBuf; char *writeBuf;
writeBuf = (char*) elWork.Alloc( ERRORLOG_SIZE ); writeBuf = (char*) elWork.Alloc( ERRORLOG_SIZE );
SDK_ASSERT( writeBuf );
// 新しいログエントリを書き込むためのRTC // 新しいログエントリを書き込むためのRTC
if( ( rtcRes = RTC_GetDateTime( &date, &time )) != RTC_RESULT_SUCCESS ) if( ( rtcRes = RTC_GetDateTime( &date, &time )) != RTC_RESULT_SUCCESS )
{ {
elWork.Free( writeBuf );
OS_TPrintf("EL Error: RTC getDateTime() Failed! Status:%d\n", rtcRes); OS_TPrintf("EL Error: RTC getDateTime() Failed! Status:%d\n", rtcRes);
return FALSE; return FALSE;
} }
@ -239,11 +261,11 @@ BOOL ERRORLOGi_WriteCommon( BOOL isLauncherError, u64 errorCode, const char *fmt
// 最終的にファイルを書き込む // 最終的にファイルを書き込む
if( !ERRORLOGi_WriteLogToFile( writeBuf ) ) if( !ERRORLOGi_WriteLogToFile( writeBuf ) )
{ {
elWork.Free( writeBuf );
return FALSE; return FALSE;
} }
elWork.Free( writeBuf ); elWork.Free( writeBuf );
return TRUE; return TRUE;
} }
@ -320,6 +342,7 @@ BOOL ERRORLOGi_addNewEntryRED( int idx, RTCDate *date, RTCTime *time, int errorC
elWork.entry[idx].minute = (int)time->minute; elWork.entry[idx].minute = (int)time->minute;
elWork.entry[idx].second = (int)time->second; elWork.entry[idx].second = (int)time->second;
elWork.entry[idx].errorCode = (int)errorCode; elWork.entry[idx].errorCode = (int)errorCode;
elWork.entry[idx].titleId = ERRORLOGi_getTitleId();
if( elWork.entry[idx].errorStr != NULL ) if( elWork.entry[idx].errorStr != NULL )
{ {
@ -358,6 +381,7 @@ void ERRORLOGi_addNewEntry( int idx, RTCDate *date, RTCTime *time, const char *f
elWork.entry[idx].hour = (int)time->hour; elWork.entry[idx].hour = (int)time->hour;
elWork.entry[idx].minute = (int)time->minute; elWork.entry[idx].minute = (int)time->minute;
elWork.entry[idx].second = (int)time->second; elWork.entry[idx].second = (int)time->second;
elWork.entry[idx].titleId = ERRORLOGi_getTitleId();
if( elWork.entry[idx].errorStr == NULL ) if( elWork.entry[idx].errorStr == NULL )
{ {
@ -397,7 +421,7 @@ CheckStatus ERRORLOGi_CheckAndCreateDirectory( const char *path )
} }
// ディレクトリが存在しないのでディレクトリを作成 // ディレクトリが存在しないのでディレクトリを作成
if( ! FS_CreateDirectory( path, FS_PERMIT_R | FS_PERMIT_W ) ) if( ! FS_CreateDirectoryAuto( path, FS_PERMIT_R | FS_PERMIT_W ) )
{ {
OS_TPrintf("EL Error: FS_CreateDirectory() failed. FSResult: %d\n", FS_GetArchiveResultCode(path) ); OS_TPrintf("EL Error: FS_CreateDirectory() failed. FSResult: %d\n", FS_GetArchiveResultCode(path) );
// ディレクトリ作成に失敗 // ディレクトリ作成に失敗
@ -495,6 +519,7 @@ CheckStatus ERRORLOGi_CheckAndCreateFile( const char *path )
int ERRORLOGi_ReadEntry( void ) int ERRORLOGi_ReadEntry( void )
{ {
char buf[ERRORLOG_BUFSIZE+1]; char buf[ERRORLOG_BUFSIZE+1];
char titlebuf[5];
int numEntry = 0; int numEntry = 0;
int readSize = 0; int readSize = 0;
@ -524,8 +549,12 @@ int ERRORLOGi_ReadEntry( void )
&(elWork.entry[numEntry].hour) , &(elWork.entry[numEntry].hour) ,
&(elWork.entry[numEntry].minute) , &(elWork.entry[numEntry].minute) ,
&(elWork.entry[numEntry].second) , &(elWork.entry[numEntry].second) ,
titlebuf ,
&(elWork.entry[numEntry].errorCode) ); &(elWork.entry[numEntry].errorCode) );
elWork.entry[numEntry].titleId = MI_LoadLE32( titlebuf );
OS_TPrintf("reading titleid: %4x\n", elWork.entry[numEntry].titleId);
} }
else if( !STD_StrNCmp( "#FFT", &buf[ERRORLOG_BAR_LENGTH + 1], 4 ) ) else if( !STD_StrNCmp( "#FFT", &buf[ERRORLOG_BAR_LENGTH + 1], 4 ) )
{ {
@ -545,8 +574,10 @@ int ERRORLOGi_ReadEntry( void )
&(elWork.entry[numEntry].hour) , &(elWork.entry[numEntry].hour) ,
&(elWork.entry[numEntry].minute) , &(elWork.entry[numEntry].minute) ,
&(elWork.entry[numEntry].second) , &(elWork.entry[numEntry].second) ,
titlebuf ,
elWork.entry[numEntry].errorStr ); // 最後の一つは引数数のつじつまを合わせるため elWork.entry[numEntry].errorStr ); // 最後の一つは引数数のつじつまを合わせるため
elWork.entry[numEntry].titleId = MI_LoadLE32( titlebuf );
STD_CopyLStringZeroFill( elWork.entry[numEntry].errorStr, &buf[ERRORLOG_STR_OFFSET], ERRORLOG_STR_LENGTH + 1); STD_CopyLStringZeroFill( elWork.entry[numEntry].errorStr, &buf[ERRORLOG_STR_OFFSET], ERRORLOG_STR_LENGTH + 1);
} }
@ -586,22 +617,31 @@ int ERRORLOGi_ReadEntry( void )
BOOL ERRORLOGi_SetString( char *buf, ErrorLogEntry *entry ) BOOL ERRORLOGi_SetString( char *buf, ErrorLogEntry *entry )
{ {
char titlebuf[5];
if( entry->isBroken ) if( entry->isBroken )
{ {
STD_CopyLString( buf, entry->errorStr, ERRORLOG_BUFSIZE ); STD_CopyLString( buf, entry->errorStr, ERRORLOG_BUFSIZE );
return TRUE;
} }
else if ( entry->isLauncherError )
// 壊れてない場合はtitleIDを書き込む必要があるので、u32を文字列化する
STD_CopyLStringZeroFill( titlebuf, (char*)&entry->titleId, 5);
if ( entry->isLauncherError )
{ {
STD_TSNPrintf(buf, ERRORLOG_BUFSIZE, ERRORLOG_WRITE_FORMAT_RED, STD_TSNPrintf(buf, ERRORLOG_BUFSIZE, ERRORLOG_WRITE_FORMAT_RED,
entry->year, entry->month, entry->day, entry->week, entry->year, entry->month, entry->day, entry->week,
entry->hour, entry->minute, entry->second, entry->errorCode, entry->hour, entry->minute, entry->second,
titlebuf, entry->errorCode,
s_strError[entry->errorCode] ? s_strError[entry->errorCode] : "" ); s_strError[entry->errorCode] ? s_strError[entry->errorCode] : "" );
} }
else else
{ {
STD_TSNPrintf(buf, ERRORLOG_BUFSIZE, ERRORLOG_WRITE_FORMAT, STD_TSNPrintf(buf, ERRORLOG_BUFSIZE, ERRORLOG_WRITE_FORMAT,
entry->year, entry->month, entry->day, entry->week, entry->year, entry->month, entry->day, entry->week,
entry->hour, entry->minute, entry->second, entry->errorStr ); entry->hour, entry->minute, entry->second,
titlebuf, entry->errorStr );
} }
// 余りをスペースで埋めて、改行で終端する // 余りをスペースで埋めて、改行で終端する
@ -692,6 +732,22 @@ void ERRORLOGi_fillSpace( char *buf, int bufsize )
MI_CpuFill8( &buf[length], ' ', bufsize - length ); MI_CpuFill8( &buf[length], ' ', bufsize - length );
} }
/*---------------------------------------------------------------------------*
Name: ERRORLOGi_getTitleId
Description: titleIdを取得
Arguments:
Returns: titleID_Lo
*---------------------------------------------------------------------------*/
u32 ERRORLOGi_getTitleId( void )
{
return MI_LoadBE32( (void*)(HW_TWL_ROM_HEADER_BUF + 0x230) );
}
static char *s_strWeek[] = { static char *s_strWeek[] = {
"SUN", "SUN",
"MON", "MON",

View File

@ -29,7 +29,8 @@ extern "C" {
/*-- type definition ----------------------------*/ /*-- type definition ----------------------------*/
// 日付データとかを除いた、自由フォーマットで書き込めるサイズ // 日付データとかを除いた、自由フォーマットで書き込めるサイズ
// このサイズを超えた文字列は切り捨てられます // このサイズを超えた文字列は切り捨てられます
#define ERRORLOG_STR_LENGTH 204 // ERRORLOG_STR_LENGTH = ERRORLOG_BUFSIZE - ERRORLOG_STR_OFFSET - 1
#define ERRORLOG_STR_LENGTH 194
// 既に書き込まれたエラーログを表現するためのエントリ // 既に書き込まれたエラーログを表現するためのエントリ
typedef struct ErrorLogEntry{ typedef struct ErrorLogEntry{
@ -46,6 +47,9 @@ typedef struct ErrorLogEntry{
int minute; int minute;
int second; int second;
// u32だけど実態は4byteの文字列
u32 titleId;
// ---- isLauncherError = TRUEの時のデータ ---- // ---- isLauncherError = TRUEの時のデータ ----
// エラーコード // エラーコード
int errorCode; int errorCode;
@ -68,13 +72,16 @@ typedef struct ErrorLogWork{
/*-- function prototype -------------------------*/ /*-- function prototype -------------------------*/
extern BOOL ERRORLOG_Write( u64 errorCode );
extern BOOL ERRORLOG_Printf( const char *fmt, ... ); extern BOOL ERRORLOG_Printf( const char *fmt, ... );
extern BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) ); extern BOOL ERRORLOG_Init( void* (*AllocFunc) (u32) , void (*FreeFunc) (void*) );
extern void ERRORLOG_End( void ); extern void ERRORLOG_End( void );
extern int ERRORLOG_GetNum() ; extern int ERRORLOG_GetNum() ;
extern const ErrorLogEntry* ERRORLOG_Read( int idx ); extern const ErrorLogEntry* ERRORLOG_Read( int idx );
// for RED Launcher
extern BOOL ERRORLOG_Write( u64 errorCode );
#endif // SDK_ARM9 #endif // SDK_ARM9
#ifdef __cplusplus #ifdef __cplusplus