diff --git a/build/tools/sctools/common/src/error_report.c b/build/tools/sctools/common/src/error_report.c new file mode 100644 index 0000000..556b66c --- /dev/null +++ b/build/tools/sctools/common/src/error_report.c @@ -0,0 +1,112 @@ +#include +#include "text.h" +#include "mprintf.h" +#include "logprintf.h" + +#include "error_report.h" + + +typedef struct _ERROR_REPORT { + struct _ERROR_REPORT *next; + char *report_str; +} ERROR_REPORT; + +static ERROR_REPORT *er_head; +static BOOL er_active = FALSE; + +void Error_Report_Init(void) +{ + er_active = TRUE; + er_head = NULL; +} + +void Error_Report_End(void) +{ + ERROR_REPORT *er_temp; + ERROR_REPORT *er_next; + er_temp = er_head; + while( er_temp != NULL ) { + if( er_temp->report_str ) { + OS_Free( (void *)(er_temp->report_str) ); + } + er_next = er_temp->next; + OS_Free( er_temp ); + er_temp = er_next; + } + er_head = NULL; + er_active = FALSE; +} + +BOOL Error_Report_Display(TEXT_CTRL *tc) +{ + ERROR_REPORT *er_temp; + if( er_active == FALSE ) { + return FALSE; + } + if( er_head == NULL ) { + return FALSE; + } + + er_temp = er_head; + while( er_temp != NULL ) { + if( er_temp->report_str ) { + mfprintf(tc, "%s", er_temp->report_str ); + } + er_temp = er_temp->next; + } + return TRUE; +} + + +BOOL Error_Report_Add(char *str) +{ + ERROR_REPORT *er_temp; + ERROR_REPORT **er_next; + char *str_buf; + u32 str_len; + if( er_active == FALSE ) { + return FALSE; + } + if( str == NULL ) { + return FALSE; + } + er_temp = (ERROR_REPORT *)OS_Alloc( sizeof(ERROR_REPORT) ); + if( er_temp == NULL ) { + return FALSE; + } + str_len = (u32)STD_StrLen(str); + str_buf = (char *)OS_Alloc( str_len + 1 ); + if( str_buf == NULL ) { + return FALSE; + } + STD_StrCpy(str_buf , str); + er_temp->report_str = str_buf; + str_buf += str_len; + *str_buf = '\0'; + er_temp->next = NULL; + + er_next = &er_head; + + while( 1 ) { + if( *er_next == NULL ) { + *er_next = er_temp; + return TRUE; + } + er_next = &((*er_next)->next); + } + return FALSE; +} + +BOOL Error_Report_Printf(const char *fmt, ...) +{ +#define STR_BUF_LEN 200 + char str_buf[STR_BUF_LEN]; + int ret; + va_list vlist; + va_start(vlist, fmt); + ret = STD_TVSNPrintf(str_buf, STR_BUF_LEN, fmt, vlist); + va_end(vlist); + OS_TPrintf( "%s len = %d\n",__FUNCTION__,ret); + // return ret; + return Error_Report_Add(str_buf); +} diff --git a/build/tools/sctools/common/src/error_report.h b/build/tools/sctools/common/src/error_report.h new file mode 100644 index 0000000..f4cd059 --- /dev/null +++ b/build/tools/sctools/common/src/error_report.h @@ -0,0 +1,22 @@ +#ifndef _ERROR_REPORT_H_ +#define _ERROR_REPORT_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +void Error_Report_Init(void); +void Error_Report_End(void); + +BOOL Error_Report_Add(char *str); +BOOL Error_Report_Printf(const char *fmt, ...); + +BOOL Error_Report_Display(TEXT_CTRL *tc); + +#ifdef __cplusplus +} +#endif + + +#endif /* _ERROR_REPORT_H_ */ diff --git a/build/tools/sctools/common/src/hwi.c b/build/tools/sctools/common/src/hwi.c index 015d1b8..95ae521 100644 --- a/build/tools/sctools/common/src/hwi.c +++ b/build/tools/sctools/common/src/hwi.c @@ -142,6 +142,7 @@ BOOL MiyaRestoreTWLSettings(const char *path) s32 readSize; LCFGTWLSettingsData cfg_data; LCFGReadResult retval; + LCFGTWLTPCalibData tp_cal_data; retval = LCFGi_THW_ReadSecureInfo(); if( retval != LCFG_TSF_READ_RESULT_SUCCEEDED ) { @@ -151,9 +152,13 @@ BOOL MiyaRestoreTWLSettings(const char *path) } if( FALSE == ReadTWLSettings( &cfg_data ) ) { - mprintf("Failed read cfg file 2.\n" ); + mprintf("Failed read TWLSettings 2.\n" ); + return FALSE; } + /* とりあえず別でTPキャリブレーションデータだけ置いとく */ + LCFG_TSD_GetTPCalibration( &tp_cal_data ); + FS_InitFile(&f); bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); @@ -162,11 +167,9 @@ BOOL MiyaRestoreTWLSettings(const char *path) mprintf("Failed open file 2 - HWNormal Info.:%d\n", fsResult ); return FALSE; } -#if 0 - readSize = FS_ReadFile(&f, (void *)&cfg_data, (s32)sizeof(LCFGTWLSettingsData) ); -#else + readSize = my_fs_crypto_read(&f, (void *)&cfg_data, (s32)sizeof(LCFGTWLSettingsData) ); -#endif + if( readSize != sizeof(LCFGTWLSettingsData) ) { fsResult = FS_GetArchiveResultCode(path); @@ -181,6 +184,9 @@ BOOL MiyaRestoreTWLSettings(const char *path) return FALSE; } + /* さっき置いといたTPキャリブレーションデータを上書き */ + STD_CopyMemory( (void *)&cfg_data.tp, (void *)&tp_cal_data ,sizeof(LCFGTWLTPCalibData) ); + /* 実際に書き出し */ if( FALSE == WriteTWLSettings( &cfg_data ) ) { return FALSE; @@ -205,11 +211,6 @@ BOOL MiyaReadHWSecureInfo( LCFGTWLHWSecureInfo *Info ) return FALSE; } - /* - c:/twlsdk/include/twl/lcfg/common/TWLHWInfo.h - #define LCFGi_GetHWN() ( &s_hwInfoN ) - */ - STD_CopyMemory( (void *)Info, (void *)LCFGi_GetHWS() , sizeof(LCFGTWLHWSecureInfo) ); OS_TPrintf( "HW Secure Info read succeeded.\n" ); diff --git a/build/tools/sctools/common/src/hwi.h b/build/tools/sctools/common/src/hwi.h index 7960c74..e7baa95 100644 --- a/build/tools/sctools/common/src/hwi.h +++ b/build/tools/sctools/common/src/hwi.h @@ -43,6 +43,88 @@ BOOL MiyaReadHWSecureInfo( LCFGTWLHWSecureInfo *Info ); BOOL MiyaReadHWNormalInfo_From_SD(const char *path, LCFGTWLHWNormalInfo *info); +#if 0 +typedef struct LCFGTWLHWNormalInfo +{ + u8 rtcAdjust; // RTC調整値 + u8 rsv[ 3 ]; + u8 movableUniqueID[ LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ]; // 移行可能なユニークID +} LCFGTWLHWNormalInfo; // 20byte + + + +typedef struct LCFGTWLHWSecureInfo +{ + u32 validLanguageBitmap; // 本体で有効な言語コードをビット列で表現 + struct { + u8 forceDisableWireless :1; + u8 :7; + }flags; + u8 pad[ 3 ]; + u8 region; // リージョン + u8 serialNo[ LCFG_TWL_HWINFO_SERIALNO_LEN_MAX ]; // シリアルNo.(終端付きASCII文字列) +//------------------------------------------------------------- +// [TODO:]ランチャーでここまでの24bytesをSystemSharedにコピー。 +//------------------------------------------------------------- + u8 launcherTitleID_Lo[ 4 ]; // NANDファームがリージョンによって異なる可能性のあるランチャーのTitleIDを識別するために使用 +} LCFGTWLHWSecureInfo; // 28bytes + + +static inline void LCFG_TSD_GetTPCalibration( LCFGTWLTPCalibData *pDst ) +{ + MI_CpuCopy8( &LCFGi_GetTSD()->tp, pDst, sizeof(LCFGTWLTPCalibData) ); +} + + // タッチパネルキャリブレーションデータのセット。 +static inline void LCFG_TSD_SetTPCalibration( const LCFGTWLTPCalibData *pTPCalib ) +{ + MI_CpuCopy16( pTPCalib, &LCFGi_GetTSD()->tp, sizeof(LCFGTWLTPCalibData) ); +// MI_CpuCopy16( pTPCalib, &LCFGi_GetTSD_OS()->tp, sizeof(LCFGTWLTPCalibData) ); +} + +typedef struct LCFGTWLSettingsData +{ + union { + struct { + u32 isFinishedInitialSetting : 1; // 初回設定終了? + u32 isFinishedInitialSetting_Launcher : 1; // ランチャーの初回設定終了? + u32 isSetLanguage : 1; // 言語コード設定済み? + u32 isAvailableWireless : 1; // 無線モジュールのRFユニットの有効化/無効化 + u32 isBrokenTWLSettings : 1; // フラッシュ壊れシーケンス中? + u32 rsv : 19; // 予約 + u32 isAgreeEULAFlagList : 8; // EULA同意フラグリスト(最下位ビットしか使用していない) + // WiFi設定は別データなので、ここに設定済みフラグは用意しない。 + }; + u32 raw; + } flags; + u8 rsv[ 1 ]; // 予約 + u8 country; // 国コード + u8 language; // 言語(NTRとの違いは、データサイズ8bit) + u8 rtcLastSetYear; // RTCの前回設定年 + s64 rtcOffset; // RTC設定時のオフセット値(ユーザーがRTC設定を変更する度にその値に応じて増減します。) + // 16bytes ここまでのパラメータサイズ + u8 agreeEulaVersion[ EULA_VERSION_LIST_NUM ]; // 8bytes 同意したEULAのバージョン + u8 pad[2]; + LCFGTWLAlarm alarm; // 6bytes アラーム + LCFGTWLLauncherStatus launcherStatus; // 16bytes ランチャーステータス情報 + LCFGTWLTPCalibData tp; // 20bytes タッチパネルキャリブレーションデータ + LCFGTWLOwnerInfo owner; // 80bytes オーナー情報 + LCFGTWLParentalControl parental; // 148bytes ペアレンタルコントロール情報 +} LCFGTWLSettingsData; // 296bytes + + +#define LCFG_TWL_FLAG_SET_LANGUAGE ( 1 << LCFG_TWL_FLAG_SET_LANGUAGE_SHIFT ) +#define LCFG_TWL_FLAG_SET_DATE_TIME ( 1 << LCFG_TWL_FLAG_SET_DATE_TIME_SHIFT ) +#define LCFG_TWL_FLAG_SET_COUNTRY ( 1 << LCFG_TWL_FLAG_SET_COUNTRY_SHIFT ) +#define LCFG_TWL_FLAG_SET_FACE_PHOTO ( 1 << LCFG_TWL_FLAG_SET_FACE_PHOTO_SHIFT ) +#define LCFG_TWL_FLAG_SET_NICKNAME ( 1 << LCFG_TWL_FLAG_SET_NICKNAME_SHIFT ) +#define LCFG_TWL_FLAG_SET_COMMENT ( 1 << LCFG_TWL_FLAG_SET_COMMENT_SHIFT ) +#define LCFG_TWL_FLAG_SET_BIRTHDAY ( 1 << LCFG_TWL_FLAG_SET_BIRTHDAY_SHIFT ) +#define LCFG_TWL_FLAG_SET_USER_COLOR ( 1 << LCFG_TWL_FLAG_SET_USER_COLOR_SHIFT ) +#define LCFG_TWL_FLAG_SET_TP + +#endif + #ifdef __cplusplus } diff --git a/build/tools/sctools/common/src/logprintf.h b/build/tools/sctools/common/src/logprintf.h index 84983ee..4821c3c 100644 --- a/build/tools/sctools/common/src/logprintf.h +++ b/build/tools/sctools/common/src/logprintf.h @@ -1,7 +1,15 @@ #ifndef _LOGPRINT_ #define _LOGPRINT_ +#ifdef __cplusplus +extern "C" { +#endif + void miya_log_fprintf(FSFile *fd, const char *fmt, ...); +#ifdef __cplusplus +} +#endif + #endif /* _LOGPRINT_ */ diff --git a/build/tools/sctools/common/src/miya_mcu.c b/build/tools/sctools/common/src/miya_mcu.c index becde34..34f59fa 100644 --- a/build/tools/sctools/common/src/miya_mcu.c +++ b/build/tools/sctools/common/src/miya_mcu.c @@ -19,6 +19,8 @@ static void miya_mcu_free_reg_pxi_callback(PXIFifoTag tag, u32 data, BOOL err) #pragma unused(err) switch( my_mcu_command ) { + case MIYA_MCU_COMMAND_SET_FREE_REG: + break; case MIYA_MCU_COMMAND_GET_FREE_REG: miya_mcu_free_register = (u8)(0xff & data); break; @@ -63,6 +65,17 @@ static void miya_mcu_get_free_reg(void) miya_mcu_send_pxi_data(MIYA_MCU_COMMAND_GET_FREE_REG); } +// miya_mcu_set_free_reg( u8 number, u8 value ); + +static void miya_mcu_set_free_reg( u8 value ) +{ + u32 data; + data = MIYA_MCU_COMMAND_SET_FREE_REG; + data |= ((u32)value << 4); + miya_mcu_send_pxi_data(data); +} + + static void miya_mcu_get_volume(void) { miya_mcu_send_pxi_data(MIYA_MCU_COMMAND_GET_VOLUME); @@ -91,6 +104,25 @@ static void miya_mcu_set_brightness(u8 brightness) +u8 MCU_GetFreeRegister( void ) +{ + OSMessage message; + miya_mcu_get_free_reg(); + if( TRUE == OS_ReceiveMessage(&MyMesgQueue, &message, OS_MESSAGE_BLOCK) ) { + } + return miya_mcu_free_register; +} + +BOOL MCU_SetFreeRegister( u8 value ) +{ + OSMessage message; + miya_mcu_set_free_reg( value ); + if( TRUE == OS_ReceiveMessage(&MyMesgQueue, &message, OS_MESSAGE_BLOCK) ) { + } + return TRUE; +} + + u8 MCU_GetFreeReg( void ) { OSMessage message; diff --git a/build/tools/sctools/common/src/miya_mcu.h b/build/tools/sctools/common/src/miya_mcu.h index 44ee635..4335e73 100644 --- a/build/tools/sctools/common/src/miya_mcu.h +++ b/build/tools/sctools/common/src/miya_mcu.h @@ -6,7 +6,7 @@ #define MIYA_MCU_COMMAND_GET_BRIGHTNESS 3 #define MIYA_MCU_COMMAND_SET_VOLUME 4 #define MIYA_MCU_COMMAND_SET_BRIGHTNESS 5 - +#define MIYA_MCU_COMMAND_SET_FREE_REG 6 #ifdef __cplusplus @@ -15,6 +15,8 @@ extern "C" { void MIYA_MCU_Init(void); u8 MCU_GetFreeReg( void ); +u8 MCU_GetFreeRegister( void ); +BOOL MCU_SetFreeRegister( u8 value ); BOOL MCU_SetBackLightBrightness( u8 brightness ); BOOL MCU_SetVolume( u8 vol ); u8 MCU_GetBackLightBrightness( void ); diff --git a/build/tools/sctools/common/src/my_fs_util.c b/build/tools/sctools/common/src/my_fs_util.c index 2748a44..18981f3 100644 --- a/build/tools/sctools/common/src/my_fs_util.c +++ b/build/tools/sctools/common/src/my_fs_util.c @@ -4,6 +4,28 @@ #include "mprintf.h" #include "my_fs_util.h" #include "logprintf.h" +#include "error_report.h" + + +#define ATTRIBUTE_BACK 1 + +/* このフラグどこかまずい!!!*/ +#define COPY_FILE_ENCRYPTION 1 + + +static BOOL miya_debug_flag = FALSE; +static int miya_debug_counter = 0; + +void Miya_debug_ON(void) +{ + miya_debug_flag = TRUE; +} + +void Miya_debug_OFF(void) +{ + miya_debug_flag = FALSE; +} + /* NAND -> SDコピーの時、アトリビュートと時間とパーミッションを合わせる必要あり? @@ -95,40 +117,41 @@ typedef struct { /* c:/twlsdk/include/nitro/fs/types.h */ -static FS_RESUTL_WORD my_word[] = { - { FS_RESULT_SUCCESS, "FS_RESULT_SUCCESS" }, - { FS_RESULT_FAILURE, "FS_RESULT_FAILURE" }, - { FS_RESULT_BUSY, "FS_RESULT_BUSY" }, - { FS_RESULT_CANCELED, "FS_RESULT_CANCELED" }, - { FS_RESULT_CANCELLED, "FS_RESULT_CANCELLED" }, - { FS_RESULT_UNSUPPORTED, "FS_RESULT_UNSUPPORTED" }, - { FS_RESULT_ERROR, "FS_RESULT_ERROR" }, - { FS_RESULT_INVALID_PARAMETER, "FS_RESULT_INVALID_PARAMETER" }, - { FS_RESULT_NO_MORE_RESOUCE, "FS_RESULT_NO_MORE_RESOUCE" }, - { FS_RESULT_ALREADY_DONE, "FS_RESULT_ALREADY_DONE" }, - { FS_RESULT_PERMISSION_DENIED, "FS_RESULT_PERMISSION_DENIED" }, - { FS_RESULT_MEDIA_FATAL, "FS_RESULT_MEDIA_FATAL" }, - { FS_RESULT_NO_ENTRY, "FS_RESULT_NO_ENTRY" }, - { FS_RESULT_MEDIA_NOTHING, "FS_RESULT_MEDIA_NOTHING" }, - { FS_RESULT_MEDIA_UNKNOWN, "FS_RESULT_MEDIA_UNKNOWN" }, - { FS_RESULT_BAD_FORMAT, "FS_RESULT_BAD_FORMAT" }, - { FS_RESULT_MAX, "FS_RESULT_MAX" }, - // プロシージャ内で使用する一時的な結果値 - { FS_RESULT_PROC_ASYNC, "FS_RESULT_PROC_ASYNC" }, - { FS_RESULT_PROC_DEFAULT, "FS_RESULT_PROC_DEFAULT" }, - { FS_RESULT_PROC_UNKNOWN, "FS_RESULT_PROC_UNKNOW" }, -}; char *my_fs_util_get_fs_result_word( FSResult res ) { int i; + static FS_RESUTL_WORD my_fs_result_word[] = { + { FS_RESULT_SUCCESS, "FS_RESULT_SUCCESS" }, + { FS_RESULT_FAILURE, "FS_RESULT_FAILURE" }, + { FS_RESULT_BUSY, "FS_RESULT_BUSY" }, + { FS_RESULT_CANCELED, "FS_RESULT_CANCELED" }, + { FS_RESULT_CANCELLED, "FS_RESULT_CANCELLED" }, + { FS_RESULT_UNSUPPORTED, "FS_RESULT_UNSUPPORTED" }, + { FS_RESULT_ERROR, "FS_RESULT_ERROR" }, + { FS_RESULT_INVALID_PARAMETER, "FS_RESULT_INVALID_PARAMETER" }, + { FS_RESULT_NO_MORE_RESOUCE, "FS_RESULT_NO_MORE_RESOUCE" }, + { FS_RESULT_ALREADY_DONE, "FS_RESULT_ALREADY_DONE" }, + { FS_RESULT_PERMISSION_DENIED, "FS_RESULT_PERMISSION_DENIED" }, + { FS_RESULT_MEDIA_FATAL, "FS_RESULT_MEDIA_FATAL" }, + { FS_RESULT_NO_ENTRY, "FS_RESULT_NO_ENTRY" }, + { FS_RESULT_MEDIA_NOTHING, "FS_RESULT_MEDIA_NOTHING" }, + { FS_RESULT_MEDIA_UNKNOWN, "FS_RESULT_MEDIA_UNKNOWN" }, + { FS_RESULT_BAD_FORMAT, "FS_RESULT_BAD_FORMAT" }, + { FS_RESULT_MAX, "FS_RESULT_MAX" }, + // プロシージャ内で使用する一時的な結果値 + { FS_RESULT_PROC_ASYNC, "FS_RESULT_PROC_ASYNC" }, + { FS_RESULT_PROC_DEFAULT, "FS_RESULT_PROC_DEFAULT" }, + { FS_RESULT_PROC_UNKNOWN, "FS_RESULT_PROC_UNKNOW" }, + }; + for( i = 0 ; i < 19 ; i++ ) { - if( my_word[i].result == res ) { - return my_word[i].string; + if( my_fs_result_word[i].result == res ) { + return my_fs_result_word[i].string; } } - return my_word[0].string; + return my_fs_result_word[0].string; } @@ -146,20 +169,23 @@ static void PrintAttributes(u32 attributes, FSFile *log_fd) } - -static BOOL Log_File_Open(FSFile *log_fd, const char *log_file_name) +BOOL Log_File_Open(FSFile *log_fd, const char *log_file_name) { BOOL bSuccess; FSResult res; + if( log_fd == NULL ) { + return FALSE; + } + if( log_file_name == NULL ) { + miya_log_fprintf(NULL, "%s %d: No log file name\n",__FUNCTION__,__LINE__); return FALSE; } FS_InitFile(log_fd); bSuccess = FS_OpenFileEx(log_fd, log_file_name, (FS_FILEMODE_W)); - if( ! bSuccess ) { FS_CreateFileAuto( log_file_name, FS_PERMIT_W); bSuccess = FS_OpenFileEx(log_fd, log_file_name, (FS_FILEMODE_W)); @@ -173,23 +199,90 @@ static BOOL Log_File_Open(FSFile *log_fd, const char *log_file_name) return TRUE; } -static void Log_File_Close(FSFile *log_fd) +void Log_File_Close(FSFile *log_fd) { - FS_FlushFile(log_fd); - FS_CloseFile(log_fd); + if( log_fd ) { + FS_FlushFile(log_fd); + FS_CloseFile(log_fd); + } } -/*---------------------------------------------------------------------------* - Name: LoadFile - Description: 内部でメモリを確保しファイルを読み込みます。 - Arguments: path: 読み込むファイルのパス。 +/* + void CRYPTO_RC4Encrypt(CRYPTORC4Context* context, const void* in, u32 length, void* out); + + context - CRYPTO_RC4Init() で予め鍵を設定した CRYPTORC4Context 型の構造体を指定します。 + in - RC4 アルゴリズムによる暗号化/復号を行う対象のデータへのポインタを指定します。 + length - in で指定したデータの長さを指定します。 + out - 暗号化/復号を行った結果を格納する先のポインタを指定します。 + +*/ +static u32 my_fs_GetStringLength(char* str) +{ + u32 i; + for (i = 0; ; i++) { + if (*(str++) == '\0') { + return i; + } + } +} + +static char *my_fs_key = "twl-repair-tool"; + + +s32 my_fs_crypto_read(FSFile *f, void *ptr, s32 size) +{ + s32 readSize; + CRYPTORC4FastContext context; + u8 *crypt_buf; + + crypt_buf = (u8 *)OS_Alloc( (u32)size ); + if(crypt_buf == NULL ) { + return -1; + } + + readSize = FS_ReadFile(f, (void *)crypt_buf, size); + if( readSize != size ) { + /* error! */ + goto end; + } + CRYPTO_RC4FastInit(&context, my_fs_key, my_fs_GetStringLength(my_fs_key)); + CRYPTO_RC4FastEncrypt(&context, (char *)crypt_buf, (u32)size, ptr); + + end: + if( crypt_buf != NULL ) { + OS_Free(crypt_buf); + } + return readSize; +} + +s32 my_fs_crypto_write(FSFile *f, void *ptr, s32 size) +{ + s32 writtenSize; + CRYPTORC4FastContext context; + u8 *crypt_buf; + + crypt_buf = (u8 *)OS_Alloc( (u32)size ); + if(crypt_buf == NULL ) { + return -1; + } + + CRYPTO_RC4FastInit(&context, my_fs_key, my_fs_GetStringLength(my_fs_key)); + CRYPTO_RC4FastEncrypt(&context, (char *)ptr, (u32)size, crypt_buf); + + writtenSize = FS_WriteFile(f, crypt_buf, size); + if( writtenSize != size ) { + /* error */ + } + + if( crypt_buf != NULL ) { + OS_Free(crypt_buf); + } + return writtenSize; +} + - Returns: ファイルが存在するならファイルの内容が読み込まれた - 内部で確保したバッファへのポインタを返します。 - このポインタは FS_Free で解放する必要があります。 - *---------------------------------------------------------------------------*/ static BOOL LoadFile(const char* path, char **alloc_ptr, int *alloc_size, FSFile *log_fd) { FSFile f; @@ -199,7 +292,7 @@ static BOOL LoadFile(const char* path, char **alloc_ptr, int *alloc_size, FSFile s32 readSize = 0; if( alloc_ptr == 0 || alloc_size == NULL ) { - miya_log_fprintf(log_fd, "Failed LoadFile argument error\n"); + miya_log_fprintf(log_fd, "Failed LoadFile argument error ptr=0x%08p, size=%d\n", alloc_ptr , alloc_size); return FALSE; } @@ -207,33 +300,45 @@ static BOOL LoadFile(const char* path, char **alloc_ptr, int *alloc_size, FSFile bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); if( ! bSuccess ) { - miya_log_fprintf(log_fd, "Failed Open File %s\n",__FUNCTION__); + miya_log_fprintf(log_fd, "%s Failed Open File\n",__FUNCTION__); miya_log_fprintf(log_fd, " path=%s\n", path ); miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) )); return FALSE; } fileSize = FS_GetFileLength(&f); - pBuffer = (char*)OS_Alloc(fileSize + 1); + + // pBuffer = (char*)OS_Alloc(fileSize + 1); + pBuffer = (char*)OS_Alloc( fileSize ); if( pBuffer == NULL ) { - miya_log_fprintf(log_fd, "Mem alloc error: %s\n", __FUNCTION__); + miya_log_fprintf(log_fd, "%s Mem alloc error: %d\n", __FUNCTION__, fileSize); + *alloc_size = 0; + *alloc_ptr = NULL; return FALSE; } readSize = FS_ReadFile(&f, pBuffer, (s32)fileSize); if( readSize != fileSize ) { - miya_log_fprintf(log_fd, "Failed Read File: %s\n",path); + miya_log_fprintf(log_fd, "%s Failed Read File:%s\n",__FUNCTION__ , path ); + miya_log_fprintf(log_fd, " request size=%d read size=%d\n", fileSize, readSize); + if( pBuffer != NULL ) { + OS_Free(pBuffer); + } + *alloc_size = 0; + *alloc_ptr = NULL; + return FALSE; } *alloc_size = (int)readSize; bSuccess = FS_CloseFile(&f); if( ! bSuccess ) { - miya_log_fprintf(log_fd, "Failed Close File\n"); + miya_log_fprintf(log_fd, "%s Failed Close File\n", __FUNCTION__ ); miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path))); } - pBuffer[fileSize] = '\0'; + // pBuffer[fileSize] = '\0'; + *alloc_ptr = pBuffer; return TRUE; } @@ -254,8 +359,9 @@ static BOOL SaveFile(const char* path, void* pData, u32 size, FSFile *log_fd) /* 本来ここで問題なし */ } else { - miya_log_fprintf(log_fd, "Failed open file:%s %d %s %s\n", - __FUNCTION__,__LINE__, path, my_fs_util_get_fs_result_word(res) ); + miya_log_fprintf(log_fd, "%s Failed open file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(res) ); } } else { @@ -268,8 +374,9 @@ static BOOL SaveFile(const char* path, void* pData, u32 size, FSFile *log_fd) bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); if (bSuccess == FALSE) { FSResult res = FS_GetArchiveResultCode(path); - miya_log_fprintf(log_fd,"Failed open file:%s %d %s %s\n", - __FUNCTION__,__LINE__, path, my_fs_util_get_fs_result_word(res) ); + miya_log_fprintf(log_fd, "%s Failed open file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(res) ); return FALSE; } @@ -279,13 +386,17 @@ static BOOL SaveFile(const char* path, void* pData, u32 size, FSFile *log_fd) writtenSize = FS_WriteFile(&f, pData, (s32)size); if( writtenSize != size ) { + FSResult res = FS_GetArchiveResultCode(path); + miya_log_fprintf(log_fd, "%s Failed write file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(res) ); + (void)FS_CloseFile(&f); + return FALSE; } FS_FlushFile(&f); - bSuccess = FS_CloseFile(&f); - if( bSuccess ) { - - } + (void)FS_CloseFile(&f); + return TRUE; } @@ -309,6 +420,134 @@ BOOL CopyFile(const char *dst_path, const char *src_path, FSFile *log_fd ) return FALSE; } + +#ifdef COPY_FILE_ENCRYPTION +static BOOL CopyFileCrypto(const char *dst_path, const char *src_path, FSFile *log_fd ) +{ + FSFile f_src; + FSFile f_dst; + char* pBuffer; + u32 fileSize; + s32 readSize = 0; + FSResult fsResult; + s32 writtenSize; + CRYPTORC4FastContext context; + char* pBuffer_crypto; + BOOL ret_flag = FALSE; + + if( miya_debug_flag ) { + miya_debug_counter++; + if( miya_debug_counter > 2 ) { + miya_debug_counter = 0; + return FALSE; + } + } + + FS_InitFile(&f_src); + + if( FALSE == FS_OpenFileEx(&f_src, src_path, FS_FILEMODE_R) ) { + miya_log_fprintf(log_fd, "%s Failed Open File\n",__FUNCTION__); + miya_log_fprintf(log_fd, " path=%s\n", src_path ); + miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(src_path) )); + return FALSE; + } + + fileSize = FS_GetFileLength(&f_src); + + pBuffer = (char*)OS_Alloc( fileSize ); + if( pBuffer == NULL ) { + miya_log_fprintf(log_fd, "%s Mem alloc error: %d\n", __FUNCTION__, fileSize); + } + else { + readSize = FS_ReadFile(&f_src, pBuffer, (s32)fileSize); + if( readSize != fileSize ) { + miya_log_fprintf(log_fd, "%s Failed Read File:%s\n",__FUNCTION__ , src_path ); + miya_log_fprintf(log_fd, " request size=%d read size=%d\n", fileSize, readSize); + } + else { + /* crypto start */ + pBuffer_crypto = (char*)OS_Alloc( fileSize ); + if( pBuffer_crypto == NULL ) { + miya_log_fprintf(log_fd, "%s Mem(cryto) alloc error: %d\n", __FUNCTION__, fileSize); + } + else { + /* ここからWrite */ + + CRYPTO_RC4FastInit(&context, my_fs_key, my_fs_GetStringLength(my_fs_key)); + CRYPTO_RC4FastEncrypt(&context, pBuffer, (u32)fileSize, pBuffer_crypto); + + + FS_InitFile(&f_dst); + if( FALSE == FS_OpenFileEx(&f_dst, dst_path, FS_FILEMODE_W) ) { + FSResult res = FS_GetArchiveResultCode(dst_path); + if( res == FS_RESULT_NO_ENTRY ) { + /* 本来ここで問題なし */ + } + else { + miya_log_fprintf(log_fd, "%s Failed open file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", dst_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(res) ); + } + } + else { + FS_CloseFile(&f_dst); + /* backup バックアップを取っておくべき?? */ + FS_DeleteFile(dst_path); + } + + + FS_CreateFile(dst_path, (FS_PERMIT_R|FS_PERMIT_W)); + if( FALSE == FS_OpenFileEx(&f_dst, dst_path, FS_FILEMODE_W) ) { + miya_log_fprintf(log_fd, "%s Failed open file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", dst_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(FS_GetArchiveResultCode(dst_path)) ); + } + else { + fsResult = FS_SetFileLength(&f_dst, 0); + if( fsResult != FS_RESULT_SUCCESS ) { + miya_log_fprintf(log_fd, "%s Error: Set file len\n", __FUNCTION__); + miya_log_fprintf(log_fd, " %s\n", dst_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(fsResult) ); + } + else { + writtenSize = FS_WriteFile(&f_dst, pBuffer_crypto, readSize); + if( writtenSize != readSize ) { + miya_log_fprintf(log_fd, "%s Failed write file %d:\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", dst_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word(FS_GetArchiveResultCode(dst_path)) ); + } + else { + FS_FlushFile(&f_dst); + ret_flag = TRUE; + } + } + } + /* Write終了 */ + } + /* crypto end */ + } + } + + if( pBuffer != NULL ) { + OS_Free(pBuffer); + } + if( pBuffer_crypto != NULL ) { + OS_Free(pBuffer_crypto); + } + + if( FALSE == FS_CloseFile(&f_src) ) { + miya_log_fprintf(log_fd, "%s Failed Close File\n", __FUNCTION__ ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(src_path))); + } + if( FALSE == FS_CloseFile(&f_dst) ) { + miya_log_fprintf(log_fd, "%s Failed Close File\n", __FUNCTION__ ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(dst_path))); + } + + return ret_flag; +} +#endif + static BOOL CompareFsDateTime( FSDateTime *dt1, FSDateTime *dt2) { if( dt1->year != dt2->year ) { @@ -371,20 +610,27 @@ static BOOL restore_entry_list(MY_DIR_ENTRY_LIST **headp, FSFile *log_fd) } -static BOOL add_entry_list( MY_DIR_ENTRY_LIST **headp, MY_DIR_ENTRY_LIST *entry_list ) +static BOOL add_entry_list( MY_DIR_ENTRY_LIST **headp, MY_DIR_ENTRY_LIST *entry_list, FSFile *log_fd) { MY_DIR_ENTRY_LIST *list_temp; MY_DIR_ENTRY_LIST *list_prev_temp; if( entry_list == NULL ) { + miya_log_fprintf(log_fd, "%s ERROR:entry_list ptr -> NULL\n", __FUNCTION__); return FALSE; } if( headp == NULL ) { + miya_log_fprintf(log_fd, "%s ERROR:headp ptr -> NULL\n", __FUNCTION__); return FALSE; } if( *headp == NULL ) { *headp = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + if( *headp == NULL ) { + miya_log_fprintf(log_fd, "%s memory alloc error: *headp size=%d\n", + __FUNCTION__, sizeof(MY_DIR_ENTRY_LIST) ); + return FALSE; + } STD_CopyMemory( (void *)(*headp), (void *)entry_list , sizeof(MY_DIR_ENTRY_LIST) ); (*headp)->prev = NULL; (*headp)->next = NULL; @@ -394,6 +640,11 @@ static BOOL add_entry_list( MY_DIR_ENTRY_LIST **headp, MY_DIR_ENTRY_LIST *entry_ ; } list_temp->next = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + if( list_temp->next == NULL ) { + miya_log_fprintf(log_fd, "%s memory alloc error: list_temp->next size=%d\n", + __FUNCTION__, sizeof(MY_DIR_ENTRY_LIST) ); + return FALSE; + } list_prev_temp = list_temp; list_temp = list_temp->next; @@ -404,26 +655,35 @@ static BOOL add_entry_list( MY_DIR_ENTRY_LIST **headp, MY_DIR_ENTRY_LIST *entry_ return TRUE; } + + static BOOL my_fs_add_list( MY_DIR_ENTRY_LIST **headp, FSDirectoryEntryInfo *entry, const char *src_path, const char *dst_path, FSFile *log_fd) { + MY_DIR_ENTRY_LIST *list_temp; MY_DIR_ENTRY_LIST *list_prev_temp; FSPathInfo path_info; - if( entry == NULL ) { + + + if( (entry == NULL) || (src_path == NULL) ) { + miya_log_fprintf(log_fd, "%s %d: invalid arg.\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " entry=0x%08p src_path=0x%-8p\n",entry, src_path); return FALSE; } /* ファイルの場合 srcがNAND, dstがSD */ if( !STD_StrCmp( src_path, "nand:" ) ) { /* nandのルートディレクトリはスルーする。 */ + miya_log_fprintf(log_fd, "detect nand: root dir\n"); return TRUE; } - if( FALSE == FS_GetPathInfo(src_path,&path_info) ) { - miya_log_fprintf(log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); + FSResult fsResult = FS_GetArchiveResultCode( src_path ); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); miya_log_fprintf(log_fd, " %s\n", src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); } else { if( FALSE == CompareFsDateTime( &(entry->atime), &(path_info.atime)) ) { @@ -432,9 +692,7 @@ static BOOL my_fs_add_list( MY_DIR_ENTRY_LIST **headp, FSDirectoryEntryInfo *ent miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", entry->atime.hour,entry->atime.minute,entry->atime.second); miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.atime.year,path_info.atime.month,path_info.atime.day); miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.atime.hour,path_info.atime.minute,path_info.atime.second); - entry->atime = path_info.atime; - } if( FALSE == CompareFsDateTime( &(entry->mtime), &(path_info.mtime)) ) { @@ -443,13 +701,11 @@ static BOOL my_fs_add_list( MY_DIR_ENTRY_LIST **headp, FSDirectoryEntryInfo *ent miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", entry->mtime.hour,entry->mtime.minute,entry->mtime.second); miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.mtime.year,path_info.mtime.month,path_info.mtime.day); miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.mtime.hour,path_info.mtime.minute,path_info.mtime.second); - entry->mtime = path_info.mtime; } #if 0 /* なぜがWarningが出る */ -OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); if( FALSE == CompareFsDateTime( &(entry->ctime), &(path_info.ctime)) ) { miya_log_fprintf(log_fd, "warning ctime\n"); miya_log_fprintf(log_fd," entry %d/%02d/%02d ", entry->ctime.year,entry->ctime.month,entry->ctime.day); @@ -457,7 +713,6 @@ OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); miya_log_fprintf(log_fd," path_info %d/%02d/%02d ", path_info.ctime.year,path_info.ctime.month,path_info.ctime.day); miya_log_fprintf(log_fd,"%02d:%02d:%02d\n", path_info.ctime.hour,path_info.ctime.minute,path_info.ctime.second); } -OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); #endif // OS_TPrintf("path info att=0x%08x\n",path_info.attributes); if( entry->attributes != path_info.attributes ) { @@ -467,11 +722,14 @@ OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); entry->attributes = path_info.attributes; } - if( *headp == NULL ) { *headp = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + if( *headp == NULL ) { + miya_log_fprintf(log_fd, "%s memory alloc error: *headp size=%d\n", + __FUNCTION__, sizeof(MY_DIR_ENTRY_LIST) ); + return FALSE; + } STD_MemSet((void *)*headp, 0, sizeof(MY_DIR_ENTRY_LIST) ); - (*headp)->prev = NULL; (*headp)->next = NULL; STD_CopyMemory( (void *)&((*headp)->content), (void *)entry ,sizeof(FSDirectoryEntryInfo) ); @@ -485,8 +743,12 @@ OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); ; } list_temp->next = (MY_DIR_ENTRY_LIST *)OS_Alloc( sizeof(MY_DIR_ENTRY_LIST) ); + if( list_temp->next == NULL ) { + miya_log_fprintf(log_fd, "%s memory alloc error:list_temp->next size=%d\n", + __FUNCTION__, sizeof(MY_DIR_ENTRY_LIST) ); + return FALSE; + } STD_MemSet((void *)list_temp->next, 0, sizeof(MY_DIR_ENTRY_LIST) ); - list_prev_temp = list_temp; list_temp = list_temp->next; list_temp->prev = list_prev_temp; @@ -497,15 +759,20 @@ OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); STD_StrCpy(list_temp->dst_path, dst_path); } } +#if 1 + PrintAttributes(entry->attributes, log_fd); + miya_log_fprintf(log_fd, " %s len=%d\n",src_path,entry->filesize); +#endif return TRUE; } BOOL ClearDirEntryList( MY_DIR_ENTRY_LIST **headp ) { - MY_DIR_ENTRY_LIST *list_temp1 = *headp; + MY_DIR_ENTRY_LIST *list_temp1; MY_DIR_ENTRY_LIST *list_temp2; + list_temp1 = *headp; *headp = NULL; while( list_temp1 ) { @@ -559,6 +826,81 @@ void PrintDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) miya_log_fprintf(log_fd, "PrintDirEntryListBackward-----End\n"); } +static int a_to_int(char c) +{ + if( ('a' <= c) && (c <= 'f') ) { + return (int)( c - 'a' + 10 ); + } + else if( ('A' <= c) && (c <= 'F') ) { + return (int)( c - 'A' + 10 ); + } + else if( ('0' <= c) && (c <= '9') ) { + return (int)( c - '0' ); + } + return -1; +} + + +static BOOL GetAppGameCode(const char path[], char *code_buf , FSFile *log_fd) +{ + /* + 012345678901234567890123456789 + nand:/title/00030017/484e4141 は ランチャー + */ + int c_hi; + int c_lo; + int i; + char *str; + str = code_buf; + + if( (path == NULL ) || (code_buf == NULL) ) { + miya_log_fprintf(log_fd, "%s Error:invalid argument\n", __FUNCTION__); + miya_log_fprintf(log_fd, " path=0x%08x code_buf=0x%08x\n", path, code_buf); + return FALSE; + } + + if( STD_StrLen(path) < 28 ) { + return FALSE; + } + + for( i = 0 ; i < 8 ; i++ ) { + if( i % 2 ) { + c_lo = a_to_int( path[21+i] ); + if( c_lo == -1 ) { + return FALSE; + } + *str = (char)( c_hi << 4 | c_lo ); + str++; + } + else { + c_hi = a_to_int( path[21+i] ); + if( c_hi == -1 ) { + return FALSE; + } + } + } + *str = '\0'; + return TRUE; +} + +static void AppErrorReport(const char *path, char *msg) +{ + char game_code[5]; + char *dir_name1 = "nand:/shared2"; + char *dir_name2 = "nand2:/photo"; + if( !STD_StrNCmp( path, dir_name1 , STD_StrLen(dir_name1) ) ) { + (void)Error_Report_Printf(" Shared:%s\n", msg); + } + else if( !STD_StrNCmp( path, dir_name2 , STD_StrLen(dir_name2) ) ) { + (void)Error_Report_Printf(" Photo :%s\n", msg); + } + else if( TRUE == GetAppGameCode(path, game_code, NULL ) ) { + (void)Error_Report_Printf(" %s :%s\n", game_code, msg); + } + else { + (void)Error_Report_Printf(" ???? :%s\n path=%s\n",msg, path); + } +} static BOOL CheckSystemApp(char path[]) { @@ -581,31 +923,22 @@ static BOOL CheckSystemApp(char path[]) */ c = path[19]; - if( ('a' <= c) && (c <= 'f') ) { - num = (int)( c - 'a' + 10 ); - } - else if( ('A' <= c) && (c <= 'F') ) { - num = (int)( c - 'A' + 10 ); - } - else if( ('0' <= c) && (c <= '9') ) { - num = (int)( c - '0' ); - } - else { + num = a_to_int( c ); + + if( num == -1 ) { + /* Panicぐらいでええかも */ + miya_log_fprintf(NULL, "%s error: not ascii code-> %c\n",__FUNCTION__, c); num = 0; } - - if( num & 1 ) { - /* System App. */ + if( num & 1 ) { /* System App. */ return TRUE; } - else { - /* User App. */ + else { /* User App. */ return FALSE; } } - -void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size) +BOOL GetUserAppTitleList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size, char *log_file_name ) { int i; int count = 0; @@ -613,7 +946,20 @@ void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size) u64 *buf = NULL; char c; u8 hex; - + BOOL log_active = FALSE; + FSFile *log_fd; + FSFile log_fd_real; + BOOL ret_flag = TRUE; + + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + else { + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + } + if( head == NULL ) { *pBuffer = NULL; *size = 0; @@ -626,12 +972,18 @@ void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size) } } } - OS_TPrintf("User App. count1 = %d\n", count); - // mprintf("\nUser App. count1 = %d\n", count); + miya_log_fprintf(log_fd, "User App. count = %d\n", count); if( count ) { buf = (u64 *)OS_Alloc( (u32)(count * sizeof(u64)) ); - STD_MemSet((void *)buf, 0, count * sizeof(u64)); + if( buf ) { + STD_MemSet((void *)buf, 0, count * sizeof(u64)); + } + else { + miya_log_fprintf(log_fd, "%s memory allocate error\n",__FUNCTION__); + ret_flag = FALSE; + goto function_end; + } } else { @@ -655,52 +1007,39 @@ void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size) システムアプリはダウンロード対象外 */ if( FALSE == CheckSystemApp( list_temp->src_path ) ) { - /* koko-made */ - count++; - /* User App. */ for( i = 0 ; i < 8 ; i++ ) { c = list_temp->src_path[12 + i]; - hex = 0; - if( ('a' <= c) && (c <= 'f') ) { - hex = (u8)( c - 'a' + 10 ); - } - else if( ('A' <= c) && (c <= 'F') ) { - hex = (u8)( c - 'A' + 10 ); - } - else if( ('0' <= c) && (c <= '9') ) { - hex = (u8)(c - '0'); + hex = (u8)a_to_int(c); + if( hex > -1 ) { } else { /* error! */ - // count--; - return; + miya_log_fprintf(log_fd, "%s 1 invalid path name %s\n",__FUNCTION__,list_temp->src_path); + if( *size > 0 ) { + *size = *size - 1; + } + goto next_loop; } *buf |= (((u64)hex) << ((7-i)*4 + 32 )); } - for( i = 0 ; i < 8 ; i++ ) { c = list_temp->src_path[21 + i]; - hex = 0; - if( ('a' <= c) && (c <= 'f') ) { - hex = (u8)( c - 'a' + 10 ); - } - else if( ('A' <= c) && (c <= 'F') ) { - hex = (u8)( c - 'A' + 10 ); - } - else if( ('0' <= c) && (c <= '9') ) { - hex = (u8)(c - '0'); + hex = (u8)a_to_int(c); + if( hex > -1 ) { } else { /* error! */ - // count--; - return; + miya_log_fprintf(log_fd, "%s 2 invalid path name %s\n",__FUNCTION__,list_temp->src_path); + if( *size > 0 ) { + *size = *size - 1; + } + goto next_loop; } *buf |= (((u64)hex) << ((7-i)*4 )); } buf++; - // OS_TPrintf("User App. count2 = %d\n", count); - + count++; } /* 012345678901234567890123456789 @@ -708,16 +1047,23 @@ void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size) nand:/title/00030015/484e4641 は shop nand:/title/00030015/484e4241 は 本体設定 */ + next_loop: + ; } } } +function_end: + if( log_active ) { + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); + } + return ret_flag; } void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) { MY_DIR_ENTRY_LIST *list_temp; - // MY_DIR_ENTRY_LIST *list_prev; miya_log_fprintf(log_fd, "PrintSrcDirEntryListBackword-----Start\n"); if( head == NULL ) { } @@ -728,11 +1074,6 @@ void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) for( ; list_temp != NULL ; list_temp = list_temp->prev ) { if( list_temp->src_path ) { miya_log_fprintf(log_fd, "%s\n", list_temp->src_path ); - /* - nand:/title/00030017/484e4141 は ランチャー - nand:/title/00030015/484e4641 は shop - nand:/title/00030015/484e4241 は 本体設定 - */ } } } @@ -740,53 +1081,69 @@ void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd) } - - - -int SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ) +BOOL SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path, int *list_count, int *error_count, char *log_file_name) { FSFile f; FSFile f_src; FSFile f_dst; - BOOL bSuccess; FSResult fsResult; s32 writtenSize; MY_DIR_ENTRY_LIST *list_temp; - int list_count = 0; FSFile log_fd_real; FSFile *log_fd; BOOL log_active = FALSE; - // char *log_file_name = "sdmc:/miya/save_dir_entry_log.txt"; - char *log_file_name = NULL; - + BOOL copy_error_flag; + log_fd = &log_fd_real; - /* ここでSDカードがあるかどうか調べる */ log_active = Log_File_Open( log_fd, log_file_name ); if( !log_active ) { log_fd = NULL; } + else { + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + } + + if( (list_count == NULL) || (error_count == NULL) ) { + miya_log_fprintf(log_fd, "%s Error:invalid argument\n", __FUNCTION__); + miya_log_fprintf(log_fd, " list ptr=0x%08x error ptr=0x%08x\n", list_count, error_count); + return FALSE; + } + + *list_count = 0; + *error_count = 0; + /* 最初にSD側のルートディレクトリのデータを消しとくべきか? せっかくファイルリストに記録してるのでもったいない→必要ない */ FS_InitFile(&f); FS_InitFile(&f_src); FS_InitFile(&f_dst); + if( path == NULL ) { - miya_log_fprintf(log_fd, "%s %d not specify entry save file\n",__FUNCTION__,__LINE__ ); - return -1; + miya_log_fprintf(log_fd, "%s %d not specify entry save file name\n",__FUNCTION__,__LINE__ ); + return FALSE; /* error */ } + FS_CreateFileAuto(path, (FS_PERMIT_R|FS_PERMIT_W)); - bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); - if (bSuccess == FALSE) { + if( FALSE == FS_OpenFileEx(&f, path, FS_FILEMODE_W) ) { fsResult = FS_GetArchiveResultCode(path); - miya_log_fprintf(log_fd, "Failed create file - dir entry list file:%d\n", fsResult ); - return -1; + miya_log_fprintf(log_fd, "%s %d Failed open-file\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " - dir entry list file:\n"); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult )); + + (void)Error_Report_Printf(" ???? :Open file failed.\n path=%s\n", path); + return FALSE; /* error */ } fsResult = FS_SetFileLength(&f, 0); if( fsResult != FS_RESULT_SUCCESS ) { - miya_log_fprintf(log_fd, "Failed set file len - dir entry list file:%d\n", fsResult ); + miya_log_fprintf(log_fd, "%s %d Failed set file-len 0\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " - dir entry list file:\n"); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult )); + + (void)Error_Report_Printf(" ???? :Open file failed.\n path=%s\n", path); + return FALSE; /* error */ } /* バックワードでファイルに保存 */ @@ -797,31 +1154,27 @@ int SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ) ; } for( ; list_temp != NULL ; list_temp = list_temp->prev ) { - // OS_TPrintf( "name = %s\n", list_temp->src_path ); - /* SDにログを残す場合 */ - if( log_active ) { - miya_log_fprintf(log_fd, "%s\n", list_temp->src_path); - } + copy_error_flag = FALSE; + + miya_log_fprintf(log_fd, "%s\n", list_temp->src_path); - writtenSize = FS_WriteFile(&f, (void *)list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); - if( writtenSize != sizeof(MY_DIR_ENTRY_LIST) ) { - miya_log_fprintf(log_fd, "%s %d: Failed write file\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(log_fd, " %s\n", path); - miya_log_fprintf(log_fd, " entry count %d\n", list_count ); - } - /* SD側にディレクトリの作成とファイルのコピー */ if( (list_temp->content.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { /* ディレクトリの場合 */ - bSuccess = FS_CreateDirectoryAuto(list_temp->dst_path, FS_PERMIT_RW); - // bSuccess = FS_CreateDirectory(list_temp->dst_path, FS_PERMIT_RW); - if(!bSuccess) { + // copy_error_flag = FS_CreateDirectoryAuto(list_temp->dst_path, FS_PERMIT_RW); + // Createオートを使ったらまずい。 + copy_error_flag = FS_CreateDirectory(list_temp->dst_path, FS_PERMIT_RW); + + if(!copy_error_flag ) { fsResult = FS_GetArchiveResultCode(list_temp->dst_path); if( fsResult != FS_RESULT_ALREADY_DONE ) { miya_log_fprintf(log_fd, "%s %d: Failed Create DST Directory\n", __FUNCTION__ , __LINE__ ); miya_log_fprintf(log_fd, " %s\n", list_temp->dst_path); miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); - return -1; + // return -1; + } + else { + copy_error_flag = TRUE; /* カッコ悪・・ */ } } } @@ -833,10 +1186,41 @@ int SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ) else { /* NANDからSDにコピーする */ // CopyFile( dst <= src ); - CopyFile(list_temp->dst_path, list_temp->src_path, log_fd ); + // Createオートを使ったらまずい。 +#ifdef COPY_FILE_ENCRYPTION + copy_error_flag = CopyFileCrypto(list_temp->dst_path, list_temp->src_path, log_fd ); +#else + copy_error_flag = CopyFile(list_temp->dst_path, list_temp->src_path, log_fd ); +#endif } } - list_count++; + + if( copy_error_flag == TRUE ) { + writtenSize = FS_WriteFile(&f, (void *)list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); + if( writtenSize != sizeof(MY_DIR_ENTRY_LIST) ) { + miya_log_fprintf(log_fd, "%s %d: Failed write file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n\n", path); + if( writtenSize > 0 ) { + if(FALSE == FS_SeekFile( &f, -writtenSize, FS_SEEK_CUR) ) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(log_fd, "%s %d: Failed seek-file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + /* panic.. */ + } + } + (*error_count)++; + AppErrorReport(list_temp->src_path, "copy file failed"); + } + else { + (*list_count)++; + } + } + else { + (*error_count)++; + AppErrorReport(list_temp->src_path, "copy file failed"); + } + } } @@ -847,20 +1231,22 @@ int SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ) miya_log_fprintf(log_fd, " %s\n", path); miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) ) ); } - if( log_active ) { - miya_log_fprintf(log_fd, "write entry list count %d\n", list_count); - } - if( log_active ) { - Log_File_Close(log_fd); + miya_log_fprintf(log_fd, "write entry list count %d\n", *list_count); + miya_log_fprintf(log_fd, " error count %d\n", *error_count ); + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); + + if( *error_count > 0 ) { + return FALSE; } - return list_count; + return TRUE; } /******************************************** * NANDにディレクトリエントリとファイルを復活させる。 *********************************************/ -BOOL RestoreDirEntryList( char *path , char *log_file_name) +BOOL RestoreDirEntryList( char *path , char *log_file_name, int *list_count, int *error_count) { FSFile f; FSFile f_dir; @@ -869,152 +1255,394 @@ BOOL RestoreDirEntryList( char *path , char *log_file_name) s32 readSize; MY_DIR_ENTRY_LIST list_temp; FSPathInfo path_info; - int list_count = 0; MY_DIR_ENTRY_LIST *readonly_list_head = NULL; - - FSFile log_fd; + BOOL copy_error_flag; + FSFile log_fd_real; + FSFile *log_fd; BOOL log_active = FALSE; - /* ここでSDカードがあるかどうか調べる */ - log_active = Log_File_Open( &log_fd, log_file_name ); + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + + + if( (list_count == NULL) || (error_count == NULL) ) { + miya_log_fprintf(log_fd, "%s Error:invalid argument\n", __FUNCTION__); + miya_log_fprintf(log_fd, " list ptr=0x%08x error ptr=0x%08x\n", list_count, error_count); + return FALSE; + } + + *list_count = 0; + *error_count = 0; FS_InitFile(&f); FS_InitFile(&f_dir); if( FS_OpenFileEx(&f, path, FS_FILEMODE_R) == FALSE) { fsResult = FS_GetArchiveResultCode(path); - miya_log_fprintf(&log_fd, "%s %d: Failed Open file\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); - return FALSE; + miya_log_fprintf(log_fd, "%s %d: Failed Open file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + + (void)Error_Report_Printf(" ???? :Open file failed.\n path=%s\n", path); + return FALSE; /* error */ } while( 1 ) { + /* リストはルートディレクトリに近い順から入っている */ readSize = FS_ReadFile(&f, (void *)&list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); if( readSize == 0 ) { - miya_log_fprintf(&log_fd, "Read entry count %d\n", list_count ); + /* 終わり */ break; } else if( readSize != (s32)sizeof(MY_DIR_ENTRY_LIST) ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Read file\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path); - miya_log_fprintf(&log_fd, " read entry count %d\n", list_count ); + miya_log_fprintf(log_fd, "%s %d: Failed Read file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); break; } - list_count++; + copy_error_flag = TRUE; + + + /* もうちょっとよく考えて順番とか作り直し FS_GetPathInfoとか減らせそう・・ */ /* NAND側にディレクトリの作成とファイルのコピー */ if( (list_temp.content.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { /* ディレクトリの場合 */ if( TRUE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { - /* 復元される側にすでにディレクトリエントリがある場合 */ + /* 復元される側(NAND)にすでに何かファイルかディレクトリがある場合 */ if( (path_info.attributes & FS_ATTRIBUTE_IS_DIRECTORY) == 0 ) { /* ディレクトリでない場合 エラー */ /* SDにログを残す場合 */ - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: NOT a directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); - } + miya_log_fprintf(log_fd, "%s %d: NOT a directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); /* require backup file */ /* パニック?? */ /* それとも一度デリートする?? */ + FS_DeleteFile( list_temp.src_path ); /* ちょっと無理やりか? */ + goto label1; } + /* read onlyディレクトリだった場合の処理は下のほうでやる。 */ } else { - /* 復元される側にディレクトリエントリがない場合 */ + label1: + /* 復元される側(NAND)にディレクトリエントリがない場合 */ bSuccess = FS_CreateDirectory(list_temp.src_path, FS_PERMIT_RW); if(!bSuccess) { fsResult = FS_GetArchiveResultCode(list_temp.src_path); if( fsResult != FS_RESULT_ALREADY_DONE ) { - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Create NAND Directory\n", __FUNCTION__,__LINE__); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path); - } + miya_log_fprintf(log_fd, "%s %d: Failed Create NAND Directory\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path); + copy_error_flag = FALSE; + } } if( FALSE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); - } + miya_log_fprintf(log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); // return FALSE; } } + +#ifdef ATTRIBUTE_BACK /* このディレクトリを記憶しておき、あとで属性をまとめて戻す */ - if( FALSE == add_entry_list( &readonly_list_head, &list_temp ) ) { - miya_log_fprintf(&log_fd, "%s %d: ERROR: add_entry_list\n", __FUNCTION__,__LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); + if( FALSE == add_entry_list( &readonly_list_head, &list_temp, log_fd ) ) { + miya_log_fprintf(log_fd, "%s %d: ERROR: add_entry_list\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); } +#endif if( (path_info.attributes & FS_ATTRIBUTE_DOS_READONLY) != 0 ) { /* リードオンリーの場合,一度リードライト可能にする */ path_info.attributes &= ~FS_ATTRIBUTE_DOS_READONLY; if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { fsResult = FS_GetArchiveResultCode(list_temp.src_path); - miya_log_fprintf(&log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); } } } else { - /* ファイルの場合 srcがSD, dstがNAND */ + /* ファイルの場合 */ if( !STD_StrCmp( list_temp.src_path, "nand:" ) ) { /* nandのルートディレクトリはスルーする。 */ + OS_TPrintf("nand: root detect \n"); } else { /* とりあえずデスティネーションファイルがあるかどうか確認して あればSDにバックアップする */ // CopyFile( dst <= src ); - CopyFile( list_temp.src_path, list_temp.dst_path, &log_fd ); +#ifdef COPY_FILE_ENCRYPTION + copy_error_flag = CopyFileCrypto( list_temp.src_path, list_temp.dst_path, log_fd ); +#else + copy_error_flag = CopyFile( list_temp.src_path, list_temp.dst_path, log_fd ); +#endif - path_info.attributes = list_temp.content.attributes; - path_info.ctime = list_temp.content.ctime; - path_info.mtime = list_temp.content.mtime; - path_info.atime = list_temp.content.atime; - path_info.id = list_temp.content.id; - path_info.filesize = list_temp.content.filesize; - if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { - fsResult = FS_GetArchiveResultCode(list_temp.src_path); - miya_log_fprintf(&log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", list_temp.src_path ); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + if( TRUE == copy_error_flag ) { + path_info.attributes = list_temp.content.attributes; + path_info.ctime = list_temp.content.ctime; + path_info.mtime = list_temp.content.mtime; + path_info.atime = list_temp.content.atime; + path_info.id = list_temp.content.id; + path_info.filesize = list_temp.content.filesize; + if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } } } } + + /* ファイルでもディレクトリでもどっちでもここを通る */ + if( copy_error_flag == FALSE ) { + (*error_count)++; + AppErrorReport(list_temp.src_path, "copy file failed"); + } + else { + (*list_count)++; + } } + miya_log_fprintf(log_fd, "%s Read entry count %d error count %d\n",__FUNCTION__ , *list_count, *error_count ); + +#ifdef ATTRIBUTE_BACK /* add_entry_list( &readonly_list_head, &list_temp ); でリストにしたエントリーのアトリビュートを逆順で元に戻す。*/ - if( FALSE == restore_entry_list(&readonly_list_head, &log_fd) ) { - miya_log_fprintf(&log_fd, "%s %d: ERROR: restore_entry_list\n", __FUNCTION__,__LINE__ ); + if( FALSE == restore_entry_list(&readonly_list_head, log_fd) ) { + miya_log_fprintf(log_fd, "%s %d: ERROR: restore_entry_list\n", __FUNCTION__,__LINE__ ); } +#endif exit_label: // FS_FlushFile(&f); //リードだからいらない if( FS_CloseFile(&f) == FALSE) { fsResult = FS_GetArchiveResultCode(path); - miya_log_fprintf(&log_fd, "%s %d: Failed Close file\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + miya_log_fprintf(log_fd, "%s %d: Failed Close file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); } + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); if( log_active ) { - Log_File_Close(&log_fd); + Log_File_Close(log_fd); + } + if( *error_count > 0 ) { + return FALSE; } - return TRUE; } -// = "nand:/title"; + + +BOOL RestoreDirEntryListSystemBackupOnly( char *path , char *log_file_name, int *list_count, int *error_count) +{ + FSFile f; + FSFile f_dir; + BOOL bSuccess; + FSResult fsResult; + s32 readSize; + MY_DIR_ENTRY_LIST list_temp; + FSPathInfo path_info; + MY_DIR_ENTRY_LIST *readonly_list_head = NULL; + BOOL copy_error_flag; + FSFile log_fd_real; + FSFile *log_fd; + BOOL log_active = FALSE; + + + + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + + + if( (list_count == NULL) || (error_count == NULL) ) { + miya_log_fprintf(log_fd, "%s Error:invalid argument\n", __FUNCTION__); + miya_log_fprintf(log_fd, " list ptr=0x%08x error ptr=0x%08x\n", list_count, error_count); + return FALSE; + } + + *list_count = 0; + *error_count = 0; + + FS_InitFile(&f); + FS_InitFile(&f_dir); + + if( FS_OpenFileEx(&f, path, FS_FILEMODE_R) == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(log_fd, "%s %d: Failed Open file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + return FALSE; /* error */ + } + + while( 1 ) { + /* リストはルートディレクトリに近い順から入っている */ + readSize = FS_ReadFile(&f, (void *)&list_temp, (s32)sizeof(MY_DIR_ENTRY_LIST) ); + if( readSize == 0 ) { + /* 終わり */ + break; + } + else if( readSize != (s32)sizeof(MY_DIR_ENTRY_LIST) ) { + miya_log_fprintf(log_fd, "%s %d: Failed Read file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + break; + } + + copy_error_flag = TRUE; + + /* NAND側にディレクトリの作成とファイルのコピー */ + if( (list_temp.content.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { + /* ディレクトリの場合 */ + if( TRUE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { + /* 復元される側(NAND)にすでに何かファイルかディレクトリがある場合 */ + if( (path_info.attributes & FS_ATTRIBUTE_IS_DIRECTORY) == 0 ) { + /* ディレクトリでない場合 エラー */ + /* SDにログを残す場合 */ + miya_log_fprintf(log_fd, "%s %d: NOT a directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + /* require backup file */ + /* パニック?? */ + /* それとも一度デリートする?? */ + FS_DeleteFile( list_temp.src_path ); /* ちょっと無理やりか? */ + goto label1; + } + /* read onlyディレクトリだった場合の処理は下のほうでやる。 */ + } + else { + label1: + /* 復元される側(NAND)にディレクトリエントリがない場合 */ + bSuccess = FS_CreateDirectory(list_temp.src_path, FS_PERMIT_RW); + if(!bSuccess) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + if( fsResult != FS_RESULT_ALREADY_DONE ) { + miya_log_fprintf(log_fd, "%s %d: Failed Create NAND Directory\n", __FUNCTION__,__LINE__); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path); + copy_error_flag = FALSE; + } + } + if( FALSE == FS_GetPathInfo(list_temp.src_path, &path_info) ) { + miya_log_fprintf(log_fd, "%s %d: Failed GetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + // return FALSE; + } + } + + +#ifdef ATTRIBUTE_BACK + /* このディレクトリを記憶しておき、あとで属性をまとめて戻す */ + if( FALSE == add_entry_list( &readonly_list_head, &list_temp, log_fd ) ) { + miya_log_fprintf(log_fd, "%s %d: ERROR: add_entry_list\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + } +#endif + + if( (path_info.attributes & FS_ATTRIBUTE_DOS_READONLY) != 0 ) { + /* リードオンリーの場合,一度リードライト可能にする */ + path_info.attributes &= ~FS_ATTRIBUTE_DOS_READONLY; + if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + } + } + else { + /* ファイルの場合 */ + if( !STD_StrCmp( list_temp.src_path, "nand:" ) ) { + /* nandのルートディレクトリはスルーする。 */ + OS_TPrintf("nand: root detect \n"); + } + else { + + // CopyFile( dst <= src ); + if( TRUE == CheckSystemApp( list_temp.src_path ) ) { + /* 一応拡張子(*.sav)もチェックしといたほうがいいか? */ + OS_TPrintf("sys backup %s\n",list_temp.src_path); +#ifdef COPY_FILE_ENCRYPTION + copy_error_flag = CopyFileCrypto( list_temp.src_path, list_temp.dst_path, log_fd ); +#else + copy_error_flag = CopyFile( list_temp.src_path, list_temp.dst_path, log_fd ); +#endif + + if( TRUE == copy_error_flag ) { + path_info.attributes = list_temp.content.attributes; + path_info.ctime = list_temp.content.ctime; + path_info.mtime = list_temp.content.mtime; + path_info.atime = list_temp.content.atime; + path_info.id = list_temp.content.id; + path_info.filesize = list_temp.content.filesize; + if( FALSE == FS_SetPathInfo( list_temp.src_path, &path_info) ) { + fsResult = FS_GetArchiveResultCode(list_temp.src_path); + miya_log_fprintf(log_fd, "%s %d: Failed SetPathInfo\n", __FUNCTION__,__LINE__ ); + miya_log_fprintf(log_fd, " %s\n", list_temp.src_path ); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + (*list_count)++; + } + } + else { + /* ユーザーアプリだった場合。 */ + + } + } + } + + if( copy_error_flag == FALSE ) { + (*error_count)++; + AppErrorReport(list_temp.src_path, "copy file failed"); + } + } + + miya_log_fprintf(log_fd, "%s Read entry count %d error count %d\n",__FUNCTION__ , *list_count, *error_count ); + +#ifdef ATTRIBUTE_BACK + /* add_entry_list( &readonly_list_head, &list_temp ); + でリストにしたエントリーのアトリビュートを逆順で元に戻す。*/ + if( FALSE == restore_entry_list(&readonly_list_head, log_fd) ) { + miya_log_fprintf(log_fd, "%s %d: ERROR: restore_entry_list\n", __FUNCTION__,__LINE__ ); + } +#endif + + exit_label: + + // FS_FlushFile(&f); //リードだからいらない + if( FS_CloseFile(&f) == FALSE) { + fsResult = FS_GetArchiveResultCode(path); + miya_log_fprintf(log_fd, "%s %d: Failed Close file\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( fsResult ) ); + } + + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + if( log_active ) { + Log_File_Close(log_fd); + } + if( *error_count > 0 ) { + return FALSE; + } + return TRUE; +} + + static BOOL my_fs_is_Title_Hi_dir_name(const char *name) { @@ -1038,6 +1666,12 @@ static BOOL my_fs_is_Title_Hi_dir_name(const char *name) return TRUE; } +/* + nand:/title/00030017/484e4141 は ランチャー + nand:/title/00030015/484e4641 は shop + nand:/title/00030015/484e4241 は 本体設定 +*/ + static BOOL my_fs_is_Title_Lo_dir_name(const char *name) { char *str; @@ -1119,80 +1753,6 @@ static void Path_Buffers_Clean( char *path_src_dir, char *path_src_full, - -/* - void CRYPTO_RC4Encrypt(CRYPTORC4Context* context, const void* in, u32 length, void* out); - - context - CRYPTO_RC4Init() で予め鍵を設定した CRYPTORC4Context 型の構造体を指定します。 - in - RC4 アルゴリズムによる暗号化/復号を行う対象のデータへのポインタを指定します。 - length - in で指定したデータの長さを指定します。 - out - 暗号化/復号を行った結果を格納する先のポインタを指定します。 - -*/ -static u32 my_fs_GetStringLength(char* str) -{ - u32 i; - for (i = 0; ; i++) { - if (*(str++) == '\0') { - return i; - } - } -} - -static char *my_fs_key = "twl-repair-tool"; - - -s32 my_fs_crypto_read(FSFile *f, void *ptr, s32 size) -{ - s32 readSize; - CRYPTORC4FastContext context; - u8 *crypt_buf; - - crypt_buf = (u8 *)OS_Alloc( (u32)size ); - if(crypt_buf == NULL ) { - return -1; - } - - readSize = FS_ReadFile(f, (void *)crypt_buf, size); - if( readSize != size ) { - /* error! */ - goto end; - } - CRYPTO_RC4FastInit(&context, my_fs_key, my_fs_GetStringLength(my_fs_key)); - CRYPTO_RC4FastEncrypt(&context, (char *)crypt_buf, (u32)size, ptr); - - end: - if( crypt_buf != NULL ) { - OS_Free(crypt_buf); - } - return readSize; -} - -s32 my_fs_crypto_write(FSFile *f, void *ptr, s32 size) -{ - s32 writtenSize; - CRYPTORC4FastContext context; - u8 *crypt_buf; - - crypt_buf = (u8 *)OS_Alloc( (u32)size ); - if(crypt_buf == NULL ) { - return -1; - } - - CRYPTO_RC4FastInit(&context, my_fs_key, my_fs_GetStringLength(my_fs_key)); - CRYPTO_RC4FastEncrypt(&context, (char *)ptr, (u32)size, crypt_buf); - - writtenSize = FS_WriteFile(f, crypt_buf, size); - if( writtenSize != size ) { - /* error */ - } - - if( crypt_buf != NULL ) { - OS_Free(crypt_buf); - } - return writtenSize; -} - BOOL MydataLoadDecrypt(const char *path, void *pBuffer, int size, FSFile *log_fd) { FSFile f; @@ -1264,7 +1824,7 @@ BOOL MydataSaveEncrypt(const char *path, void *pData, int size, FSFile *log_fd) } - +#if 0 BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd) { FSFile f; @@ -1293,8 +1853,9 @@ BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd) return TRUE; } +#endif - +#if 0 BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd) { #pragma unused(log_fd) @@ -1336,9 +1897,9 @@ BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd) } return TRUE; } +#endif - -BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, FSFile *log_fd) +BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, char *log_file_name) { FSFile f; BOOL bSuccess; @@ -1346,22 +1907,38 @@ BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, FSFile *log_fd) s32 readSize = 0; int id_count= 0; int size; + BOOL log_active = FALSE; + FSFile *log_fd; + FSFile log_fd_real; + BOOL ret_flag = TRUE; + + log_fd = &log_fd_real; FS_InitFile(&f); + + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + else { + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + } bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_R); if( ! bSuccess ) { miya_log_fprintf(log_fd, "Failed Open File %s\n",__FUNCTION__); miya_log_fprintf(log_fd, " path=%s\n", path ); miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) )); - return FALSE; + ret_flag = FALSE; + goto function_end; } if( sizeof(int) != FS_ReadFile(&f, &id_count, (s32)sizeof(int)) ) { miya_log_fprintf(log_fd, "Failed Read File %s\n",__FUNCTION__); miya_log_fprintf(log_fd, " path=%s\n", path ); miya_log_fprintf(log_fd, " res=%s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path) )); - return FALSE; + ret_flag = FALSE; + goto function_end; } @@ -1370,60 +1947,93 @@ BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, FSFile *log_fd) *pBuffer = (u64 *)OS_Alloc( (u32)size ); if( *pBuffer == NULL ) { - return FALSE; + ret_flag = FALSE; + miya_log_fprintf(log_fd, "%s Failed memory alloc size %d\n",__FUNCTION__, size); + goto function_end; } readSize = FS_ReadFile(&f, *pBuffer, (s32)size ); if( readSize != size ) { - miya_log_fprintf(log_fd, "Failed Read File: %s\n",path); + miya_log_fprintf(log_fd, "Failed Read File: %s request size %d read size %d\n",path, size, readSize); + if( readSize != size ) { + ret_flag = FALSE; + goto function_end; + } } + + + function_end: + bSuccess = FS_CloseFile(&f); if( ! bSuccess ) { miya_log_fprintf(log_fd, "Failed Close File\n"); miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path))); } - return TRUE; - + if( log_active ) { + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); + } + return ret_flag; } -BOOL TitleIDSave(const char *path, u64 *pData, int count, FSFile *log_fd) +BOOL TitleIDSave(const char *path, u64 *pData, int count, char *log_file_name ) { -#pragma unused(log_fd) FSFile f; BOOL bSuccess; FSResult res; FSResult fsResult; // s32 writtenSize; + BOOL log_active = FALSE; + FSFile *log_fd; + FSFile log_fd_real; + BOOL ret_flag = TRUE; + + log_fd = &log_fd_real; FS_InitFile(&f); + + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + else { + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + } + bSuccess = FS_OpenFileEx(&f, path, FS_FILEMODE_W); if( ! bSuccess ) { FS_CreateFileAuto( path, FS_PERMIT_W|FS_PERMIT_R); bSuccess = FS_OpenFileEx(&f, path , FS_FILEMODE_W ); if( ! bSuccess ) { res = FS_GetArchiveResultCode( path ); - miya_log_fprintf(NULL, "%s file open error %s\n", __FUNCTION__,path ); - miya_log_fprintf(NULL, " Failed open file:%s\n", my_fs_util_get_fs_result_word( res )); - return FALSE; + miya_log_fprintf(log_fd, "%s file open error %s\n", __FUNCTION__,path ); + miya_log_fprintf(log_fd, " Failed open file:%s\n", my_fs_util_get_fs_result_word( res )); + ret_flag = FALSE; + goto function_end; } } fsResult = FS_SetFileLength(&f, 0); if( fsResult != FS_RESULT_SUCCESS ) { res = FS_GetArchiveResultCode( path ); - miya_log_fprintf(NULL, "%s file length error %s\n", __FUNCTION__,path ); - miya_log_fprintf(NULL, " Failed file lenght :%s\n", my_fs_util_get_fs_result_word( res )); - return FALSE; + miya_log_fprintf(log_fd, "%s file length error %s\n", __FUNCTION__,path ); + miya_log_fprintf(log_fd, " Failed file lenght :%s\n", my_fs_util_get_fs_result_word( res )); + ret_flag = FALSE; + goto function_end; } if( sizeof(int) != FS_WriteFile(&f, &count, (s32)sizeof(int)) ) { res = FS_GetArchiveResultCode( path ); - miya_log_fprintf(NULL, "%s file write error %s\n", __FUNCTION__,path ); - miya_log_fprintf(NULL, " Failed write file:%s\n", my_fs_util_get_fs_result_word( res )); - return FALSE; + miya_log_fprintf(log_fd, "%s file write error %s\n", __FUNCTION__,path ); + miya_log_fprintf(log_fd, " Failed write file:%s\n", my_fs_util_get_fs_result_word( res )); + ret_flag = FALSE; + goto function_end; + } + else { + miya_log_fprintf(log_fd, "num of title id = %d\n", count); } /* @@ -1440,18 +2050,40 @@ BOOL TitleIDSave(const char *path, u64 *pData, int count, FSFile *log_fd) /* 16文字だから */ if( (count*sizeof(u64)) != FS_WriteFile(&f, pData, (s32)(count*sizeof(u64)) )) { res = FS_GetArchiveResultCode( path ); - miya_log_fprintf(NULL, "%s file write error %s\n", __FUNCTION__,path ); - miya_log_fprintf(NULL, " Failed write file:%s\n", my_fs_util_get_fs_result_word( res )); - return FALSE; + miya_log_fprintf(log_fd, "%s file write error %s\n", __FUNCTION__,path ); + miya_log_fprintf(log_fd, " Failed write file:%s\n", my_fs_util_get_fs_result_word( res )); + ret_flag = FALSE; + goto function_end; + } + else { + int j; + u64 *ptr = pData; + if( ptr != NULL && count > 0 ) { + for( j = 0 ; j < count ; j++ ) { + miya_log_fprintf(log_fd,"No. %d 0x%016llx\n",j,*ptr); + ptr++; + } + } } } FS_FlushFile(&f); + + function_end: + bSuccess = FS_CloseFile(&f); if( bSuccess ) { } - return TRUE; + + if( log_active ) { + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); + } + + + return ret_flag; + } @@ -1464,52 +2096,17 @@ BOOL TWLCardValidation(void) if( TRUE == OS_IsRunOnDebugger() ) { if( flag_TWLCardValidation == FALSE ) { flag_TWLCardValidation = TRUE; - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + // OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); } return FALSE; /* カードは抜けていることにする。 */ } - - /* - CARD_IsPulledOut(); - カード抜けを検出した場合 TRUE を、そうでない場合は FALSE を返します。 - 一度でもカード抜けを検出した後は常に TRUE を返します。 - */ -#if 1 /* CARD_IsPulledOutをつかうにはアルマジロの改造がいる。 - - c:/twlsdk/build/components/armadillo.TWL/src/main.c - - //---- check pull out card - CARD_CheckPullOut_Polling(); - */ + */ if( TRUE == CARD_IsPulledOut() ) { return FALSE; } -#else - { - s32 lock_ret; - u16 id; - lock_ret = OS_GetLockID(); - if( lock_ret != OS_LOCK_ID_ERROR ) { - id = (u16)lock_ret; - CARD_LockRom(id); - - CARD_CheckPulledOut(); - if( TRUE == CARD_IsPulledOut() ) { - return FALSE; - } - - CARD_UnlockRom(id); - OS_ReleaseLockID( id ); - } - else { - mprintf("CARD Lock error\n"); - } - } -#endif - return TRUE; } @@ -1530,9 +2127,6 @@ BOOL SDCardValidation(void) } - - - /* 過去にショップに接続したかどうか リージョンコードは以下のファイルで定義 @@ -1555,70 +2149,30 @@ BOOL CheckShopRecord(u8 region, FSFile *log_fd) #pragma unused(log_fd) FSFile f; + FSResult res; + + BOOL ret_flag = TRUE; BOOL bSuccess; char path[256]; s32 readSize = 0; -#if 0 - u32 fileSize; - void *pBuffer; - char *str; - int i; -#endif - FS_InitFile(&f); -#if 0 + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + + FS_InitFile(&f); STD_StrCpy(path, "nand:/sys/dev.kp"); bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); if( ! bSuccess ) { if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { + /* キーペアファイルがない */ + ret_flag = FALSE; + miya_log_fprintf(log_fd, "No key pair file\n"); } - /* キーペアファイルがない */ - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); - return FALSE; - } - (void)FS_CloseFile(&f); -#endif - -#if 0 - // CopyFile( dst <= src ); - CopyFile("sdmc:/shop.log", "nand:/sys/log/shop.log",NULL); - - STD_StrCpy(path, "nand:/sys/log/shop.log"); - bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); - if( !bSuccess ) { - if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { - } - return FALSE; - } - - fileSize = FS_GetFileLength(&f); - if( fileSize ) { - pBuffer = (char*)OS_Alloc(fileSize + 1); - if( pBuffer == NULL ) { - OS_TPrintf("Mem alloc error: %s %d\n", __FUNCTION__,__LINE__); - return FALSE; - } - - readSize = FS_ReadFile(&f, pBuffer, (s32)fileSize); - if( readSize != fileSize ) { - OS_TPrintf("Failed Read File: %s %s %d\n",path,__FUNCTION__,__LINE__); - return FALSE; - } - - str = (char *)pBuffer; - - mprintf("\n\n"); - for( i = 0 ; i < readSize ; i++ ) { - OS_PutChar( *str++ ); - m_putchar(tc[0],*str++ ); - } - mprintf("\n\n"); } else { + (void)FS_CloseFile(&f); } - (void)FS_CloseFile(&f); -#endif + // STD_StrCpy(path, "nand:/title/00030015/484e464a/data/ec.cfg"); /* ショップアカウント情報 */ /* 海外だと変わってくる・・ */ /* リージョンコードと合わせる-> リージョンコードは変えられないから。 */ @@ -1626,74 +2180,89 @@ BOOL CheckShopRecord(u8 region, FSFile *log_fd) J(0x4a) - Japan E(0x45) - America P(0x50) - Europe - U(0x41) - Australia + U(0x55) - Australia C(0x43) - China K(0x4b) - Korea */ + + miya_log_fprintf(log_fd, "device region "); - // STD_StrCpy(path, "nand:/title/00030015/484e4641/data/ec.cfg"); + /* STD_StrCpy(path, "nand:/title/00030015/484e4641/data/ec.cfg"); ALL Region */ switch( region ) { case OS_TWL_REGION_JAPAN: /* J(0x4a) - Japan */ + miya_log_fprintf(log_fd, "Japan"); STD_StrCpy(path, "nand:/title/00030015/484e464a/data/ec.cfg"); break; case OS_TWL_REGION_AMERICA: /* E(0x45) - America */ + miya_log_fprintf(log_fd, "US"); STD_StrCpy(path, "nand:/title/00030015/484e4645/data/ec.cfg"); break; case OS_TWL_REGION_EUROPE: /* P(0x50) - Europe */ + miya_log_fprintf(log_fd, "EUROPE"); STD_StrCpy(path, "nand:/title/00030015/484e4650/data/ec.cfg"); break; case OS_TWL_REGION_AUSTRALIA: - /* U(0x41) - Australia */ - STD_StrCpy(path, "nand:/title/00030015/484e4641/data/ec.cfg"); + /* U(0x55) - Australia */ + miya_log_fprintf(log_fd, "Australie"); + STD_StrCpy(path, "nand:/title/00030015/484e4655/data/ec.cfg"); break; case OS_TWL_REGION_CHINA: /* C(0x43) - China */ + miya_log_fprintf(log_fd, "China"); STD_StrCpy(path, "nand:/title/00030015/484e4643/data/ec.cfg"); break; case OS_TWL_REGION_KOREA: /* K(0x4b) - Korea */ + miya_log_fprintf(log_fd, "Korea"); STD_StrCpy(path, "nand:/title/00030015/484e464b/data/ec.cfg"); break; default: - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); - return FALSE; + miya_log_fprintf(log_fd, "Unknown region"); + ret_flag = FALSE; } + miya_log_fprintf(log_fd, "\n"); - bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); - if( ! bSuccess ) { - if( FS_RESULT_NO_ENTRY == FS_GetArchiveResultCode(path) ) { - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); + + if( ret_flag == TRUE ) { + bSuccess = FS_OpenFileEx(&f, path, (FS_FILEMODE_R)); + if( ! bSuccess ) { + res = FS_GetArchiveResultCode(path); + if( FS_RESULT_NO_ENTRY == res ) { + /* ショップアカウント情報ファイルがない */ + ret_flag = FALSE; + miya_log_fprintf(log_fd, "No ec.cfg file %s\n",path); + } } - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); - /* ショップアカウント情報ファイルがない */ - return FALSE; + (void)FS_CloseFile(&f); } - (void)FS_CloseFile(&f); - return TRUE; + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + + return ret_flag; } int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_parent_dir_info_flag, char *log_file_name, int level ) { - static FSFile log_fd; + static FSFile *log_fd; + static FSFile log_fd_real; static BOOL log_active = FALSE; FSFile f_src; FSDirectoryEntryInfo entry_src; FSDirectoryEntryInfo entry_current_dir; int ret_value = 0; - // FSResult fs_ret_value; int save_parent_dir_info_flag_temp = 0; char *path_src_dir = NULL; char *path_src_full = NULL; - /* ここでSDカードがあるかどうか調べる */ if( level == 0 ) { - log_active = Log_File_Open( &log_fd, log_file_name ); + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); } level++; @@ -1710,27 +2279,29 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare FS_InitFile(&f_src); if(FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); - } - ret_value = -1; + miya_log_fprintf(log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + + ret_value |= 1; + AppErrorReport(path_src, "Open directory failed."); goto end_process; } /* ファイル名バッファ初期化 */ path_src_dir = (char *)OS_Alloc( FILE_PATH_LEN ); if( path_src_dir == NULL ) { - miya_log_fprintf(&log_fd, "Error: alloc error src_dir\n"); - ret_value = -1; + miya_log_fprintf(log_fd, "Error: alloc error src_dir\n"); + ret_value |= 1; + AppErrorReport(path_src, "Open directory failed."); goto end_process; } path_src_full = (char *)OS_Alloc( FILE_PATH_LEN ); if( path_src_full == NULL ) { - miya_log_fprintf(&log_fd, "Error: alloc error src_full\n"); - ret_value = -1; + miya_log_fprintf(log_fd, "Error: alloc error src_full\n"); + ret_value |= 1; + AppErrorReport(path_src, "Open directory failed."); goto end_process; } @@ -1750,13 +2321,6 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare STD_StrCpy( path_src_full , path_src_dir ); STD_StrCat( path_src_full , entry_src.longname ); - /* SDにログを残す場合 */ - if( log_active ) { - // OS_TPrintf("path = %s len=%d att=0x%08x\n",path_src_full,entry_src.filesize, entry_src.attributes); - PrintAttributes(entry_src.attributes, &log_fd); - miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); - } - if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { /* ディレクトリの場合 */ // level 1 2 3 4 @@ -1764,17 +2328,17 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare // nand:/title/00000000/00000000/data/*.sav if( level == 1 ) { if( my_fs_is_Title_Hi_dir_name( entry_src.longname ) == TRUE ) { - get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); + ret_value |= get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); } } if( level == 2 ) { if( my_fs_is_Title_Lo_dir_name( entry_src.longname ) == TRUE ) { - get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); + ret_value |= get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); } } else if( (level == 3) ) { if( !STD_StrCmp( entry_src.longname, "content" ) ) { - get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); + ret_value |= get_title_id( headp, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); } } } @@ -1785,9 +2349,6 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare if( (level == 4) ) { if( !STD_StrCmp( entry_src.longname, "title.tmd" ) ) { /* 目的のファイルを見つけた。 */ -#if 0 - my_fs_add_list(headp, &entry_src, path_src_full, NULL, &log_fd); -#endif save_parent_dir_info_flag_temp = 1; } } @@ -1796,23 +2357,24 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare } if( save_parent_dir_info_flag_temp == 1 ) { - // OS_TPrintf("save dir info = %s\n\n",path_src); if( level == 3 ) { - my_fs_add_list( headp, &entry_current_dir, path_src, NULL, &log_fd); + if( FALSE == my_fs_add_list( headp, &entry_current_dir, path_src, NULL, log_fd) ) { + ret_value |= 1; + AppErrorReport(path_src, "Save directory failed."); + } } else { /* contentディレクトリなど */ - } *save_parent_dir_info_flag = 1; } /* ソースディレクトリクローズ */ if( FS_CloseDirectory(&f_src) == FALSE) { - miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); - ret_value = -1; + miya_log_fprintf(log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + // ret_value |= 1; /* いらないかも?あとで考える */ } end_process: @@ -1826,9 +2388,8 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare level--; if( level == 0 ) { - if( log_active ) { - Log_File_Close(&log_fd); - } + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); } return ret_value; @@ -1838,9 +2399,10 @@ int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_pare int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, int *save_parent_dir_info_flag, char *log_file_name, int level ) { - static FSFile log_fd; + // static FSFile log_fd; + static FSFile *log_fd; + static FSFile log_fd_real; static BOOL log_active = FALSE; - // static char *log_file_name = "sdmc:/miya/nandinfo_find_title_save_data.txt"; FSFile f_src; FSDirectoryEntryInfo entry_src; @@ -1857,7 +2419,9 @@ int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const /* ここでSDカードがあるかどうか調べる */ if( level == 0 ) { - log_active = Log_File_Open( &log_fd, log_file_name ); + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); } level++; @@ -1874,22 +2438,21 @@ int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const FS_InitFile(&f_src); if(FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); - } - ret_value = -1; + miya_log_fprintf(log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + AppErrorReport(path_src, "Open directory failed."); + ret_value |= 1; goto end_process; } /* ファイル名バッファ初期化 */ - if( FALSE == Path_Buffers_Init(path_src, path_dst, - &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) - { - ret_value = -1; - goto end_process; - } + if( FALSE == Path_Buffers_Init(path_src, path_dst, &path_src_dir, + &path_src_full, &path_dst_dir, &path_dst_full, log_fd ) ) { + AppErrorReport(path_src, "Open directory failed."); + ret_value |= 1; + goto end_process; + } while( FS_ReadDirectory(&f_src, &entry_src) ) { @@ -1905,13 +2468,6 @@ int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const STD_StrCpy( path_dst_full , path_dst_dir ); STD_StrCat( path_dst_full , entry_src.longname ); - /* SDにログを残す場合 */ - if( log_active ) { - // OS_TPrintf("path = %s len=%d att=0x%08x\n",path_src_full,entry_src.filesize, entry_src.attributes); - PrintAttributes(entry_src.attributes, &log_fd); - miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); - } - if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { /* ディレクトリの場合 */ // level 1 2 3 4 @@ -1919,17 +2475,20 @@ int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const // nand:/title/00000000/00000000/data/*.sav if( level == 1 ) { if( my_fs_is_Title_Hi_dir_name( entry_src.longname ) == TRUE ) { - find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name , level ); + ret_value |= find_title_save_data( headp, path_dst_full, path_src_full , + &save_parent_dir_info_flag_temp, log_file_name , level ); } } if( level == 2 ) { if( my_fs_is_Title_Lo_dir_name( entry_src.longname ) == TRUE ) { - find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); + ret_value |= find_title_save_data( headp, path_dst_full, path_src_full , + &save_parent_dir_info_flag_temp, log_file_name, level ); } } else if( (level == 3) ) { if( !STD_StrCmp( entry_src.longname, "data" ) ) { - find_title_save_data( headp, path_dst_full, path_src_full , &save_parent_dir_info_flag_temp, log_file_name, level ); + ret_value |= find_title_save_data( headp, path_dst_full, path_src_full , + &save_parent_dir_info_flag_temp, log_file_name, level ); } } } @@ -1938,150 +2497,15 @@ int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const // nand:/title // nand:/title/00000000/00000000/data/*.sav if( (level == 4) ) { - if( !STD_StrCmp( entry_src.longname, "public.sav" ) ) { + if( !STD_StrCmp( entry_src.longname, "public.sav" ) + || !STD_StrCmp( entry_src.longname, "private.sav" ) + || !STD_StrCmp( entry_src.longname, "banner.sav" ) ) { /* 目的のファイルを見つけた。 */ - my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); - save_parent_dir_info_flag_temp = 1; - } - else if( !STD_StrCmp( entry_src.longname, "private.sav" ) ) { - my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); - save_parent_dir_info_flag_temp = 1; - } -#if 1 - /* いるのか? */ - else if( !STD_StrCmp( entry_src.longname, "banner.sav" ) ) { - my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); - save_parent_dir_info_flag_temp = 1; - } -#endif - } - } - } - } - - if( save_parent_dir_info_flag_temp == 1 ) { - // OS_TPrintf("save dir info = %s\n\n",path_src); - my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd); - *save_parent_dir_info_flag = 1; - } - - /* ソースディレクトリクローズ */ - if( FS_CloseDirectory(&f_src) == FALSE) { - miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); - ret_value = -1; - } - - end_process: - - Path_Buffers_Clean( path_src_dir, path_src_full, path_dst_dir, path_dst_full ); - - level--; - - if( level == 0 ) { - if( log_active ) { - Log_File_Close(&log_fd); - } - } - - return ret_value; -} - - -int find_copy(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, - char *extension, int max_level, int *save_parent_dir_info_flag, char *log_file_name, int level ) -{ - static FSFile log_fd; - static BOOL log_active = FALSE; - // static char *log_file_name = "sdmc:/miya/nandinfo_find_copy.txt"; - - FSFile f_src; - FSDirectoryEntryInfo entry_src; - FSDirectoryEntryInfo entry_current_dir; - int ret_value = 0; - // FSResult fs_ret_value; - int save_parent_dir_info_flag_temp = 0; - - char *path_src_dir = NULL; - char *path_src_full = NULL; - char *path_dst_dir = NULL; - char *path_dst_full = NULL; - - /* ここでSDカードがあるかどうか調べる */ - - if( level == 0 ) { - log_active = Log_File_Open( &log_fd, log_file_name ); - } - - if( level > max_level ) { - ret_value = 0; - goto end_process; - } - - level++; - - /* ソースディレクトリオープン */ - FS_InitFile(&f_src); - - if( FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); - ret_value = -1; - goto end_process; - } - - /* ファイル名バッファ初期化 */ - if( FALSE == Path_Buffers_Init(path_src, path_dst, - &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) - { - ret_value = -1; - goto end_process; - } - - while( FS_ReadDirectory(&f_src, &entry_src) ) { - - if( STD_StrCmp(entry_src.longname, ".") == 0 ) { - /* とりあえずカレントディレクトリエントリを残しておく */ - STD_CopyMemory( (void *)&entry_current_dir, (void *)&entry_src ,sizeof(FSDirectoryEntryInfo) ); - } - else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { - } - else { - STD_StrCpy( path_src_full , path_src_dir ); - STD_StrCat( path_src_full , entry_src.longname ); - STD_StrCpy( path_dst_full , path_dst_dir ); - STD_StrCat( path_dst_full , entry_src.longname ); - - /* SDにログを残す場合 */ - if( log_active ) { - PrintAttributes(entry_src.attributes, &log_fd); - miya_log_fprintf(&log_fd, " %8d %s\n", entry_src.filesize, path_src_full ); - } - - if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { - find_copy( headp, path_dst_full, path_src_full , extension, max_level, &save_parent_dir_info_flag_temp , log_file_name, level); - } - else { - /* ここで拡張子比較 */ - { - int len; - int extension_len = STD_StrLen( extension ); - len = STD_StrLen( path_src_full ); - - if( len > (extension_len - 1) ) { - // 123456789012345678901234567890123456789012345678901234567890123 - // ../backup_sample/ARM7.TWL/bin/ARM7-TS.HYB/Release/ltdmain.c.cpp - if( !STD_StrNCmp( &(path_src_full[len - (extension_len )]), extension , extension_len+1 ) ) { - /* 目的のファイルを見つけた。 */ - // OS_TPrintf("%s len=%d att=0x%08x\n", path_src_full, entry_src.filesize, entry_src.attributes); - // OS_TPrintf("%s\n", path_dst_full ); - - my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); - - save_parent_dir_info_flag_temp = 1; + if( FALSE == my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, log_fd) ) { + ret_value |= 1; + AppErrorReport(path_src_full, "Save file failed."); } + save_parent_dir_info_flag_temp = 1; } } } @@ -2090,16 +2514,19 @@ int find_copy(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_ if( save_parent_dir_info_flag_temp == 1 ) { // OS_TPrintf("save dir info = %s\n\n",path_src); - my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd ); + if( FALSE == my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, log_fd) ) { + ret_value |= 1; + AppErrorReport(path_src, "Save Directory failed."); + } *save_parent_dir_info_flag = 1; } /* ソースディレクトリクローズ */ if( FS_CloseDirectory(&f_src) == FALSE) { - miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); - ret_value = -1; + miya_log_fprintf(log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + // ret_value |= 1; /* いらないかも?あとで考える */ } end_process: @@ -2107,21 +2534,21 @@ int find_copy(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_ Path_Buffers_Clean( path_src_dir, path_src_full, path_dst_dir, path_dst_full ); level--; + if( level == 0 ) { - if( log_active ) { - Log_File_Close(&log_fd); - } + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); } return ret_value; } - int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, char *log_file_name, int level ) { - static FSFile log_fd; + // static FSFile log_fd; static BOOL log_active = FALSE; - // static char *log_file_name = "sdmc:/nandinfo_copy_r.txt"; + static FSFile *log_fd; + static FSFile log_fd_real; FSFile f_src; FSDirectoryEntryInfo entry_src; @@ -2135,7 +2562,11 @@ int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_sr /* ここでSDカードがあるかどうか調べる */ if( level == 0 ) { - log_active = Log_File_Open( &log_fd, log_file_name ); + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( log_active ) { + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + } } level++; @@ -2145,20 +2576,24 @@ int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_sr if( FS_OpenDirectory(&f_src, path_src, FS_PERMIT_R) == FALSE ) { if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); + miya_log_fprintf(log_fd, "%s %d: Failed Open Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src) ) ); } - ret_value = -1; + ret_value |= 1; + AppErrorReport(path_src, "Open directory failed."); + goto end_process; } /* ファイル名バッファ初期化 */ if( FALSE == Path_Buffers_Init(path_src, path_dst, - &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, &log_fd ) ) + &path_src_dir, &path_src_full, &path_dst_dir, &path_dst_full, log_fd ) ) { - ret_value = -1; + ret_value |= 1; + AppErrorReport(path_src, "Open directory failed."); + goto end_process; } @@ -2176,32 +2611,32 @@ int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_sr STD_StrCat( path_src_full , entry_src.longname ); STD_StrCpy( path_dst_full , path_dst_dir ); STD_StrCat( path_dst_full , entry_src.longname ); - /* SDにログを残す場合 */ - if( log_active ) { - miya_log_fprintf(&log_fd, "path = %s len=%d\n",path_src_full,entry_src.filesize); - } if( (entry_src.attributes & FS_ATTRIBUTE_IS_DIRECTORY) != 0 ) { - copy_r( headp, path_dst_full, path_src_full, log_file_name, level ); + ret_value |= copy_r( headp, path_dst_full, path_src_full, log_file_name, level ); } else { - my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, &log_fd); + if( FALSE == my_fs_add_list(headp, &entry_src, path_src_full, path_dst_full, log_fd) ) { + ret_value |= 1; + AppErrorReport(path_src_full, "Save file failed."); + } } } } /* ディレクトリエントリをセーブ */ - my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, &log_fd ); + if( FALSE == my_fs_add_list( headp, &entry_current_dir, path_src, path_dst, log_fd ) ) { + AppErrorReport(path_src, "Save directory failed."); + ret_value |= 1; + } /* ディレクトリクローズ */ if( FS_CloseDirectory(&f_src) == FALSE) { - if( log_active ) { - miya_log_fprintf(&log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); - miya_log_fprintf(&log_fd, " %s\n", path_src); - miya_log_fprintf(&log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); - } - ret_value = -1; + miya_log_fprintf(log_fd, "%s %d: Failed Close Directory\n", __FUNCTION__ , __LINE__ ); + miya_log_fprintf(log_fd, " %s\n", path_src); + miya_log_fprintf(log_fd, " %s\n", my_fs_util_get_fs_result_word( FS_GetArchiveResultCode(path_src))); + // ret_value |= 1; /* いらないかも?あとで考える */ } end_process: @@ -2210,11 +2645,9 @@ int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_sr level--; if( level == 0 ) { - if( log_active ) { - Log_File_Close(&log_fd); - } + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + Log_File_Close(log_fd); } - return ret_value; } diff --git a/build/tools/sctools/common/src/my_fs_util.h b/build/tools/sctools/common/src/my_fs_util.h index 4ff129e..76391cf 100644 --- a/build/tools/sctools/common/src/my_fs_util.h +++ b/build/tools/sctools/common/src/my_fs_util.h @@ -22,8 +22,6 @@ s32 my_fs_crypto_read(FSFile *f, void *ptr, s32 size); int find_title_save_data(MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, int *save_dir_info, char *log_file_name , int level); -int find_copy( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, - char *extension, int max_level, int *save_info, char *log_file_name , int level); int copy_r( MY_DIR_ENTRY_LIST **headp, const char *path_dst, const char *path_src, char *log_file_name, int level ); int get_title_id(MY_DIR_ENTRY_LIST **headp, const char *path_src, int *save_parent_dir_info_flag, char *log_file_name, int level ); @@ -32,25 +30,38 @@ void PrintDirEntryListForward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd ); void PrintDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd ); void PrintSrcDirEntryListBackward( MY_DIR_ENTRY_LIST *head, FSFile *log_fd); -int SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path ); -BOOL RestoreDirEntryList( char *path, char *log_file_name); +BOOL SaveDirEntryList( MY_DIR_ENTRY_LIST *head , char *path, int *list_count, int *error_count, char *log_file_name); +BOOL RestoreDirEntryList( char *path , char *log_file_name, int *list_count, int *error_count); +BOOL RestoreDirEntryListSystemBackupOnly( char *path , char *log_file_name, int *list_count, int *error_count); + +BOOL GetUserAppTitleList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size, char *log_file_name); BOOL ClearDirEntryList( MY_DIR_ENTRY_LIST **headp ); + void write_debug_data(void); + BOOL SDCardValidation(void); BOOL TWLCardValidation(void); BOOL CheckShopRecord(u8 region, FSFile *log_fd); -BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd); -BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd); + //BOOL MydataSave(const char *path, void *pData, int size, FSFile *log_fd); + //BOOL MydataLoad(const char *path, void *pBuffer, int size, FSFile *log_fd); BOOL MydataLoadDecrypt(const char *path, void *pBuffer, int size, FSFile *log_fd); BOOL MydataSaveEncrypt(const char *path, void *pData, int size, FSFile *log_fd); -void GetDirEntryList( MY_DIR_ENTRY_LIST *head, u64 **pBuffer, int *size); -BOOL TitleIDSave(const char *path, u64 *pData, int count, FSFile *log_fd); -BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, FSFile *log_fd); + +BOOL TitleIDSave(const char *path, u64 *pData, int count, char *log_file_name); +BOOL TitleIDLoad(const char *path, u64 **pBuffer, int *count, char *log_file_name); BOOL CopyFile(const char *dst_path, const char *src_path, FSFile *log_fd ); +void Log_File_Close(FSFile *log_fd); +BOOL Log_File_Open(FSFile *log_fd, const char *log_file_name); + + +void Miya_debug_OFF(void); +void Miya_debug_ON(void); + + #ifdef __cplusplus } #endif diff --git a/build/tools/sctools/common/src/mydata.h b/build/tools/sctools/common/src/mydata.h index 1814fea..42027e8 100644 --- a/build/tools/sctools/common/src/mydata.h +++ b/build/tools/sctools/common/src/mydata.h @@ -3,7 +3,7 @@ #define MY_DATA_VERSION_MAJOR 0 -#define MY_DATA_VERSION_MINOR 2 +#define MY_DATA_VERSION_MINOR 5 typedef struct { u8 version_major; @@ -12,11 +12,19 @@ typedef struct { BOOL rtc_time_flag; RTCDate rtc_date; RTCTime rtc_time; + BOOL wireless_lan_param_flag; + BOOL user_settings_flag; BOOL shop_record_flag; int num_of_user_download_app; int num_of_app_save_data; int num_of_photo_files; int num_of_shared2_files; + + int num_of_error_user_download_app; /* unused */ + int num_of_error_app_save_data; + int num_of_error_photo_files; + int num_of_error_shared2_files; + BOOL uniqueid_flag; u8 movableUniqueID[ LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ]; // 移行可能なユニークID 16byte u32 deviceId; diff --git a/build/tools/sctools/common/src/myfilename.c b/build/tools/sctools/common/src/myfilename.c index cdab3df..b0293de 100644 --- a/build/tools/sctools/common/src/myfilename.c +++ b/build/tools/sctools/common/src/myfilename.c @@ -58,6 +58,30 @@ char *MyFile_GetUserSettingsFileName(void) return path; } + +char *MyFile_GetUserAppTitleListLogFileName(void) +{ + STD_StrCpy( path , path_base ); + STD_StrCat( path , MY_FILE_NAME_USER_APP_TITLE_LIST_LOG ); + return path; +} + +char *MyFile_GetNupLogFileName(void) +{ + STD_StrCpy( path , "sdmc:/" ); + STD_StrCat( path , MY_FILE_NAME_NUP_LOG); + return path; +} + +char *MyFile_GetEcDownloadLogFileName(void) +{ + STD_StrCpy( path , path_base ); + STD_StrCat( path , MY_FILE_NAME_EC_DOWNLOAD_LOG ); + return path; +} + + + char *MyFile_GetAppSharedSaveDirName(void) { STD_StrCpy( path , path_base ); @@ -79,6 +103,14 @@ char *MyFile_GetAppSharedRestoreLogFileName(void) return path_log; } +char *MyFile_GetAppSharedSaveLogFileName(void) +{ + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , MY_FILE_NAME_APP_SHARED_SAVE_LOG ); + return path_log; +} + + char *MyFile_GetAppSharedListFileName(void) { STD_StrCpy( path , path_base ); @@ -107,6 +139,13 @@ char *MyFile_GetPhotoRestoreLogFileName(void) return path_log; } +char *MyFile_GetPhotoSaveLogFileName(void) +{ + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , MY_FILE_NAME_PHOTO_SAVE_LOG ); + return path_log; +} + char *MyFile_GetPhotoListFileName(void) { STD_StrCpy( path , path_base ); @@ -114,31 +153,46 @@ char *MyFile_GetPhotoListFileName(void) return path; } -char *MyFile_GetAppDataSaveDirName(void) +char *MyFile_GetSaveDataSaveDirName(void) { STD_StrCpy( path , path_base ); - STD_StrCat( path , MY_DIR_NAME_TITLE ); + STD_StrCat( path , MY_DIR_NAME_SAVE_DATA ); return path; } -char *MyFile_GetAppDataLogFileName(void) +char *MyFile_GetSaveDataLogFileName(void) { STD_StrCpy( path_log , path_base ); - STD_StrCat( path_log , MY_FILE_NAME_TITLE_LOG ); + STD_StrCat( path_log , MY_FILE_NAME_SAVE_DATA_LOG ); return path_log; } -char *MyFile_GetAppDataRestoreLogFileName(void) +char *MyFile_GetSaveDataRestoreLogFileName(void) { STD_StrCpy( path_log , path_base ); - STD_StrCat( path_log , MY_FILE_NAME_TITLE_RESTORE_LOG ); + STD_StrCat( path_log , MY_FILE_NAME_SAVE_DATA_RESTORE_LOG ); return path_log; } -char *MyFile_GetAppDataListFileName(void) +char *MyFile_GetSaveDataSaveLogFileName(void) +{ + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , MY_FILE_NAME_SAVE_DATA_SAVE_LOG ); + return path_log; +} + +char *MyFile_GetSaveDataListFileName(void) { STD_StrCpy( path , path_base ); - STD_StrCat( path , MY_FILE_NAME_TITLE_LIST ); + STD_StrCat( path , MY_FILE_NAME_SAVE_DATA_LIST ); + return path; +} + + +char *MyFile_GetSaveDataListLogFileName(void) +{ + STD_StrCpy( path , path_base ); + STD_StrCat( path , MY_FILE_NAME_SAVE_DATA_LIST_LOG ); return path; } @@ -156,6 +210,13 @@ char *MyFile_GetDownloadTitleIDRestoreLogFileName(void) return path_log; } +char *MyFile_GetDownloadTitleIDSaveLogFileName(void) +{ + STD_StrCpy( path_log , path_base ); + STD_StrCat( path_log , MY_FILE_NAME_DOWNLOAD_TITLE_ID_RESTORE_LOG ); + return path_log; +} + char *MyFile_GetDownloadTitleIDFileName(void) { STD_StrCpy( path , path_base ); @@ -184,4 +245,9 @@ char *MyFile_GetGlobalInformationRestoreFileName(void) return path; } - +char *MyFile_GetGlobalInformationSaveFileName(void) +{ + STD_StrCpy( path , path_base ); + STD_StrCat( path , MY_FILE_NAME_ORG_SAVE_LOG ); + return path; +} diff --git a/build/tools/sctools/common/src/myfilename.h b/build/tools/sctools/common/src/myfilename.h index bfb52b0..1bf9dd5 100644 --- a/build/tools/sctools/common/src/myfilename.h +++ b/build/tools/sctools/common/src/myfilename.h @@ -2,34 +2,47 @@ #define _MY_FILE_NAME_H_ + #define MY_FILE_NAME_UNIQUE_ID ("twl_unique.dat") #define MY_FILE_NAME_WIFI_PARAM ("twl_wifi.bin") #define MY_FILE_NAME_USER_SETTINGS ("twl_user.dat") +#define MY_FILE_NAME_USER_APP_TITLE_LIST_LOG ("user_app_lst.txt") +#define MY_FILE_NAME_NUP_LOG ("nup_log.txt") +#define MY_FILE_NAME_EC_DOWNLOAD_LOG ("ecdown.txt") + #define MY_DIR_NAME_APP_SHARED ("shared2") #define MY_FILE_NAME_APP_SHARED_LOG ("shared2.txt") #define MY_FILE_NAME_APP_SHARED_LIST ("shared2.lst") #define MY_FILE_NAME_APP_SHARED_RESTORE_LOG ("shared2_rst.txt") +#define MY_FILE_NAME_APP_SHARED_SAVE_LOG ("shared2_sv.txt") #define MY_DIR_NAME_PHOTO ("photo") #define MY_FILE_NAME_PHOTO_LOG ("photo.txt") #define MY_FILE_NAME_PHOTO_LIST ("photo.lst") #define MY_FILE_NAME_PHOTO_RESTORE_LOG ("photo_rst.txt") +#define MY_FILE_NAME_PHOTO_SAVE_LOG ("photo_sv.txt") -#define MY_DIR_NAME_TITLE ("title") -#define MY_FILE_NAME_TITLE_LOG ("title.txt") -#define MY_FILE_NAME_TITLE_LIST ("title.lst") -#define MY_FILE_NAME_TITLE_RESTORE_LOG ("title_rst.txt") +#define MY_DIR_NAME_SAVE_DATA ("save") -#define MY_DIR_NAME_DOWNLOAD_TITLE_ID ("title") +#define MY_FILE_NAME_SAVE_DATA_LIST ("save.lst") +#define MY_FILE_NAME_SAVE_DATA_LOG ("save.txt") +#define MY_FILE_NAME_SAVE_DATA_LIST_LOG ("save_lst.txt") +#define MY_FILE_NAME_SAVE_DATA_RESTORE_LOG ("save_rst.txt") +#define MY_FILE_NAME_SAVE_DATA_SAVE_LOG ("save_sv.txt") + + +#define MY_DIR_NAME_DOWNLOAD_TITLE_ID ("title_id") #define MY_FILE_NAME_DOWNLOAD_TITLE_ID_DATA ("title_id.dat") #define MY_FILE_NAME_DOWNLOAD_TITLE_ID_LOG ("title_id.txt" ) #define MY_FILE_NAME_DOWNLOAD_TITLE_ID_RESTORE_LOG ("title_id_rst.txt" ) +#define MY_FILE_NAME_DOWNLOAD_TITLE_ID_SAVE_LOG ("title_id_sv.txt" ) #define MY_FILE_NAME_ORG_DATA ("personal.dat") #define MY_FILE_NAME_ORG_LOG ("personal.txt") #define MY_FILE_NAME_ORG_RESTORE_LOG ("personal_rst.txt") +#define MY_FILE_NAME_ORG_SAVE_LOG ("personal_sv.txt") #define MY_FILE_NAME_PRODUCT_LOG "product.log" @@ -53,29 +66,38 @@ char *MyFile_GetUniqueIDFileName(void); char *MyFile_GetWifiParamFileName(void); char *MyFile_GetUserSettingsFileName(void); +char *MyFile_GetUserAppTitleListLogFileName(void); +char *MyFile_GetEcDownloadLogFileName(void); +char *MyFile_GetNupLogFileName(void); + char *MyFile_GetAppSharedSaveDirName(void); char *MyFile_GetAppSharedLogFileName(void); char *MyFile_GetAppSharedListFileName(void); char *MyFile_GetAppSharedRestoreLogFileName(void); +char *MyFile_GetAppSharedSaveLogFileName(void); char *MyFile_GetPhotoListFileName(void); char *MyFile_GetPhotoSaveDirName(void); char *MyFile_GetPhotoLogFileName(void); char *MyFile_GetPhotoRestoreLogFileName(void); +char *MyFile_GetPhotoSaveLogFileName(void); -char *MyFile_GetAppDataSaveDirName(void); -char *MyFile_GetAppDataLogFileName(void); -char *MyFile_GetAppDataListFileName(void); -char *MyFile_GetAppDataRestoreLogFileName(void); +char *MyFile_GetSaveDataSaveDirName(void); +char *MyFile_GetSaveDataLogFileName(void); +char *MyFile_GetSaveDataListFileName(void); +char *MyFile_GetSaveDataListLogFileName(void); +char *MyFile_GetSaveDataRestoreLogFileName(void); +char *MyFile_GetSaveDataSaveLogFileName(void); char *MyFile_GetDownloadTitleIDLogFileName(void); char *MyFile_GetDownloadTitleIDFileName(void); char *MyFile_GetDownloadTitleIDRestoreLogFileName(void); +char *MyFile_GetDownloadTitleIDSaveLogFileName(void); char *MyFile_GetGlobalInformationFileName(void); char *MyFile_GetGlobalInformationRestoreFileName(void); char *MyFile_GetGlobalInformationLogFileName(void); - +char *MyFile_GetGlobalInformationSaveFileName(void); #ifdef __cplusplus } diff --git a/build/tools/sctools/common/src/netconnect.c b/build/tools/sctools/common/src/netconnect.c index 86ce9d2..e503129 100644 --- a/build/tools/sctools/common/src/netconnect.c +++ b/build/tools/sctools/common/src/netconnect.c @@ -37,16 +37,18 @@ static void* myAlloc_SOCL(u32 size); static void myFree_SOCL(void* ptr); #endif // SDK_TWL -static void ncStartWiFi(void); +static int ncStartWiFi(void); static void ncFinishWiFi(void); -static void ncStartInet(void); -static void ncFinishInet(void); static WcmControlApInfo apInfo; static s32 previousAddr = 0; static u8 g_deviceId = WCM_DEVICEID_DEFAULT; static BOOL g_started = FALSE; + +static int nc_error_code = 0; + + /*---------------------------------------------------------------------------* Name : NcGlobalInit Description : @@ -93,9 +95,11 @@ typedef struct #endif -static void ncStartWiFi(void) +static int ncStartWiFi(void) { int result; + int timeout_counter; + if (previousAddr != 0) { /* @@ -152,14 +156,32 @@ static void ncStartWiFi(void) { OS_TPrintf("SOC_Startup failed (%d)", result); mprintf("SOC_Startup failed (%d)", result); - return; + return -2; } g_started = TRUE; OS_TPrintf("DHCP....\n"); + timeout_counter = 0; + while (SOC_GetHostID() == 0) { - OS_Sleep(100); + s32 err_code = SOC_GetConfigError(NULL); + if( err_code == SOC_IP_ERR_DHCP_TIMEOUT ) { + mprintf("%s -dhcp timeout\n",__FUNCTION__); + return NC_ERROR_TIMEOUT; + } + else if(err_code == SOC_IP_ERR_LINK_DOWN ) { + mprintf("%s -link down\n",__FUNCTION__); + return NC_ERROR_LINKDOWN; + } + else { + OS_Sleep(100); + timeout_counter++; + if( timeout_counter > (60 * 1000 / 100) ) { + mprintf("%s -timeout\n",__FUNCTION__); + return NC_ERROR_TIMEOUT; + } + } } OS_TPrintf("IP addr = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSMyIp)); @@ -167,6 +189,7 @@ static void ncStartWiFi(void) OS_TPrintf("GW addr = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSGatewayIp)); OS_TPrintf("DNS[0] = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSDnsIp[0])); OS_TPrintf("DNS[1] = %3d.%3d.%3d.%3d\n", CPS_CV_IPv4(CPSDnsIp[1])); + return 0; } static void ncFinishWiFi(void) @@ -187,62 +210,73 @@ static void ncFinishWiFi(void) Arguments : apClass - SitDefsに定義されているアクセスポイントのクラス名 Returns : *---------------------------------------------------------------------------*/ -void NcStart(const char* apClass) +int NcStart(const char* apClass) { int counter = 0; s32 wcm_phase; int len; u8 key_bin_buf[MAX_KEY_BIN_BUF]; - + int timeout_counter; + SiteDefs_Init(); - if( TRUE == GetKeyModeStr() ) { - if( FALSE == ENV_SetBinary("WiFi.LAN.1.AP.1.WEP.KEY", (void *)GetWlanKEYSTR()) ) { - OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); - } - } - else { - STD_MemSet((void *)key_bin_buf, 0, MAX_KEY_BIN_BUF ); - len = GetWlanKEYBIN(key_bin_buf); - if( len ) { - if( FALSE == ENV_SetBinary2("WiFi.LAN.1.AP.1.WEP.KEY", (void *)key_bin_buf, (u32)len) ) { - OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); - } - } - } - - if( FALSE == ENV_SetString("WiFi.LAN.1.AP.1.ESSID", GetWlanSSID()) ) { - OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); - } - - if( FALSE == ENV_SetU8("WiFi.LAN.1.AP.1.WEP.MODE", (u8)GetWlanMode() ) ) { - OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); - } - - if (!InitWcmApInfo(&apInfo, apClass)) - { - mprintf("Invalid AP Class...."); - OS_TPrintf("Invalid AP Class...."); + if( TRUE == GetKeyModeStr() ) { + if( FALSE == ENV_SetBinary("WiFi.LAN.1.AP.1.WEP.KEY", (void *)GetWlanKEYSTR()) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); } - - while (1) { - wcm_phase = WCM_GetPhase(); - if( wcm_phase == WCM_PHASE_NULL) { - break; + } + else { + STD_MemSet((void *)key_bin_buf, 0, MAX_KEY_BIN_BUF ); + len = GetWlanKEYBIN(key_bin_buf); + if( len ) { + if( FALSE == ENV_SetBinary2("WiFi.LAN.1.AP.1.WEP.KEY", (void *)key_bin_buf, (u32)len) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); } - // OS_TPrintf("%s %d phase = %d\n", __FUNCTION__,__LINE__,wcm_phase); - OS_Sleep(100); } + } - InitWcmControlByApInfoEx(&apInfo, g_deviceId); + if( FALSE == ENV_SetString("WiFi.LAN.1.AP.1.ESSID", GetWlanSSID()) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); + } + + if( FALSE == ENV_SetU8("WiFi.LAN.1.AP.1.WEP.MODE", (u8)GetWlanMode() ) ) { + OS_TPrintf("Error %s %d\n", __FUNCTION__,__LINE__); + } + + if (!InitWcmApInfo(&apInfo, apClass)) { + mprintf("Invalid AP Class...."); + OS_TPrintf("Invalid AP Class...."); + return NC_ERROR_INVALID_AP_CLASS; + } - OS_TPrintf("LINK UP....\n"); - mprintf("-LINK UP"); - while ( 1 ) { - wcm_phase = WCM_GetPhase(); - if( wcm_phase == WCM_PHASE_DCF ) { - break; - } + timeout_counter = 0; + while (1) { + wcm_phase = WCM_GetPhase(); + if( wcm_phase == WCM_PHASE_NULL) { + break; + } + timeout_counter++; + if( timeout_counter > (60 * 1000 / 100) ) { + mprintf("%s -timeout\n",__FUNCTION__); + return NC_ERROR_TIMEOUT; + } + OS_Sleep(100); + + } + + InitWcmControlByApInfoEx(&apInfo, g_deviceId); + + OS_TPrintf("LINK UP....\n"); + mprintf("-LINK UP"); + + timeout_counter = 0; + + + while ( 1 ) { + wcm_phase = WCM_GetPhase(); + if( wcm_phase == WCM_PHASE_DCF ) { + break; + } #if 0 #define WCM_PHASE_NULL 0 // 初期化前 #define WCM_PHASE_WAIT 1 // 初期化直後の状態( 要求待ち ) @@ -260,47 +294,42 @@ void NcStart(const char* apClass) #define WCM_PHASE_TERMINATING 13 // WCM ライブラリの強制停止シーケンス中 #endif -#if 0 + switch( counter ) { + case 0: mprintf("\r-LINK UP. "); - for( i = 0 ; i < counter ; i++ ) { - m_putchar(tc[0], '.'); - } - for( ; i < 6 ; i++ ) { - m_putchar(tc[0], ' '); - } - i %= 6; -#else - switch( counter ) { - case 0: - mprintf("\r-LINK UP. "); - break; - case 1: - mprintf("\r-LINK UP.. "); - break; - case 2: - mprintf("\r-LINK UP... "); - break; - case 3: - mprintf("\r-LINK UP.... "); - break; - case 5: - mprintf("\r-LINK UP..... "); - break; - case 6: - mprintf("\r-LINK UP......"); - counter = -1; - break; - } -#endif - OS_Sleep(200); - counter++; + break; + case 1: + mprintf("\r-LINK UP.. "); + break; + case 2: + mprintf("\r-LINK UP... "); + break; + case 3: + mprintf("\r-LINK UP.... "); + break; + case 5: + mprintf("\r-LINK UP..... "); + break; + case 6: + mprintf("\r-LINK UP......"); + counter = -1; + break; } - OS_TPrintf("connected\n"); - mprintf(" connected\n"); - - ncStartWiFi(); + timeout_counter++; + if( timeout_counter > (60 * 1000 / 200) ) { + mprintf("%s -timeout\n",__FUNCTION__); + return NC_ERROR_TIMEOUT; + } + OS_Sleep(200); + counter++; + } + OS_TPrintf("connected\n"); + mprintf(" connected\n"); + + return ncStartWiFi(); + // return 0; /* 0 means success */ } void NcFinish() diff --git a/build/tools/sctools/common/src/netconnect.h b/build/tools/sctools/common/src/netconnect.h index 1b495fb..a44924a 100644 --- a/build/tools/sctools/common/src/netconnect.h +++ b/build/tools/sctools/common/src/netconnect.h @@ -18,6 +18,11 @@ #ifndef NITROWIFI_DEMOS_NETCONNECT_H_ #define NITROWIFI_DEMOS_NETCONNECT_H_ + +#define NC_ERROR_TIMEOUT 1 +#define NC_ERROR_INVALID_AP_CLASS 2 +#define NC_ERROR_LINKDOWN 3 + #ifdef __cplusplus extern "C" @@ -25,7 +30,7 @@ extern "C" #endif void NcGlobalInit(void); -void NcStart(const char* apClass); +int NcStart(const char* apClass); void NcFinish(void); void NcSetDevice(u8 deviceId); void* NcAlloc(u32 name, s32 size); diff --git a/build/tools/sctools/common/src/text.c b/build/tools/sctools/common/src/text.c index 992cfe3..2342214 100644 --- a/build/tools/sctools/common/src/text.c +++ b/build/tools/sctools/common/src/text.c @@ -3,6 +3,7 @@ #include "text.h" #define TAB_SIZE 8 +#define Y_LINE_VIRTUAL_MAX (Y_LINE_MAX*10) /*****************************************************/ static LINE_BUF *lb_free_ptr; @@ -125,7 +126,8 @@ static void init_text_buf(TEXT_BUF *tb) tb->num_y = &y_size; tb->num_x = &x_size; tb->virtual_x = LINE_BUF_X_SIZE - X_LINE_MAX - 1; - tb->virtual_y = Y_LINE_MAX * 4; + // tb->virtual_y = Y_LINE_MAX * 4; + tb->virtual_y = Y_LINE_VIRTUAL_MAX; tb->start = tb->cur = alloc_line_buf(); tb->display_offset_y = 0; tb->display_offset_x = 0; diff --git a/build/tools/sctools/copy_dst/Makefile b/build/tools/sctools/copy_dst/Makefile index 988b1ee..bb12076 100644 --- a/build/tools/sctools/copy_dst/Makefile +++ b/build/tools/sctools/copy_dst/Makefile @@ -24,7 +24,7 @@ SRCDIR = ../common/src ./src SRCS = main.c mfiler.c key.c font.c text.c mprintf.c logprintf.c \ gfx.c hwi.c mynvram.c my_fs_util.c \ - hatamotolib.cpp miya_mcu.c \ + hatamotolib.cpp miya_mcu.c error_report.c \ sitedefs.c wcm_control.c netconnect.c mywlan.c \ mynuc.c nuc_error_msg.c stream.c myfilename.c menu_version.c diff --git a/build/tools/sctools/copy_dst/src/hatamotolib.cpp b/build/tools/sctools/copy_dst/src/hatamotolib.cpp index 063a573..47f0308 100644 --- a/build/tools/sctools/copy_dst/src/hatamotolib.cpp +++ b/build/tools/sctools/copy_dst/src/hatamotolib.cpp @@ -19,7 +19,7 @@ #include "mprintf.h" #include "logprintf.h" - +#include "my_fs_util.h" #ifdef SDK_DEBUG #define ECDL_LOG(msg) OS_TPrintf("----\nECDL-LOG: %s\n----\n", msg); @@ -32,6 +32,11 @@ #endif +static BOOL log_active = FALSE; +static FSFile *log_fd; +static FSFile log_fd_real; + + static void *Alloc(size_t size) { @@ -39,6 +44,7 @@ static void *Alloc(size_t size) void* p = OS_Alloc(size); if( p == NULL ) { OS_TPrintf("Alloc error %s %d\n",__FUNCTION__,__LINE__); + mprintf("Alloc error %s %d\n",__FUNCTION__,__LINE__); } OS_RestoreInterrupts(old); return p; @@ -55,8 +61,21 @@ static void Free(void* ptr) } -static void* AllocForNHTTP(u32 size, int align) { SDK_ASSERT(align <= 32);(void)align; return Alloc(size); } -static void* AllocForEC (u32 size, int align) { SDK_ASSERT(align <= 32);(void)align; return Alloc(size); } +static void* AllocForNHTTP(u32 size, int align) +{ + if(align <= 32) { + return Alloc(size); + } + return Alloc(size); +} + +static void* AllocForEC(u32 size, int align) +{ + if(align <= 32) { + return Alloc(size); + } + return NULL; +} static void* AllocForNSSL (u32 size) { return Alloc(size); } static void* AllocForNAM (u32 size) { return Alloc(size); } @@ -80,17 +99,6 @@ static void* ReallocForNSSL(void* p, u32 size) } -static void PrintBytes(const void* pv, u32 size) -{ - const u8* p = reinterpret_cast(pv); - - for( u32 i = 0; i < size; i++ ) - { - OS_TPrintf("%02X", p[i]); - } -} - - struct StringMap { int value; @@ -169,129 +177,27 @@ GetOSTWLRegionString(u8 x) } -void SetupUserInfo(void) +BOOL SetupVerData(void) { BOOL bSuccess; - BOOL bModified = FALSE; - void* pWork; - - // LCFG_ReadTWLSettings を行う前に LCFG_ReadHWSecureInfo が必要 - { - bSuccess = LCFG_ReadHWSecureInfo(); - SDK_ASSERT(bSuccess); - } - - // 設定の読み込み - { - pWork = Alloc(LCFG_READ_TEMP); - SDK_POINTER_ASSERT(pWork); - - bSuccess = LCFG_ReadTWLSettings(reinterpret_cast(pWork)); - SDK_ASSERT(bSuccess); - - Free(pWork); - } - - { - // ニックネームが空なら適当に設定 - if( *LCFG_TSD_GetNicknamePtr() == L'\0' ) - { - LCFG_TSD_SetNickname(reinterpret_cast(L"ecdl")); - bModified = TRUE; - } - - // 国が選択されていないなら適当に設定 - if( LCFG_TSD_GetCountry() == LCFG_TWL_COUNTRY_UNDEFINED ) - { - LCFG_TSD_SetCountry(LCFG_TWL_COUNTRY_JAPAN); - bModified = TRUE; - } - } - - // 設定が変更されているなら書き出す - if( bModified ) - { - pWork = Alloc(LCFG_WRITE_TEMP); - SDK_POINTER_ASSERT(pWork); - - bSuccess = LCFG_WriteTWLSettings(reinterpret_cast(pWork)); - SDK_ASSERT(bSuccess); - - Free(pWork); - } -} - -void SetupVerData(void) -{ - BOOL bSuccess; - void* pWork = Alloc(NA_VERSION_DATA_WORK_SIZE); - SDK_POINTER_ASSERT(pWork); - + if( pWork == NULL ) { + miya_log_fprintf(log_fd, "%s Error memory alloc\n", __FUNCTION__); + return FALSE; + } bSuccess = NA_LoadVersionDataArchive(pWork, NA_VERSION_DATA_WORK_SIZE); - - SDK_ASSERT(bSuccess); + return bSuccess; } -void PrintDeviceInfo(void) -{ - ESId deviceId; - u8 region; - u32 launcherInitialCode; - const u8* pSerial; - const u8* pMovable; - u32 movableLen1; - u32 movableLen2; - u64 fuseId; - char bmsDeviceId[32]; - - LCFG_ReadHWNormalInfo(); - LCFG_ReadHWSecureInfo(); - - // region - region = LCFG_THW_GetRegion(); - - // launcher initial code - LCFG_THW_GetLauncherTitleID_Lo(reinterpret_cast(&launcherInitialCode)); - - // ES Device ID - ES_GetDeviceId(&deviceId); - snprintf(bmsDeviceId, sizeof(bmsDeviceId), "%lld", ((0x3ull << 32) | deviceId)); - - // serial - pSerial = LCFG_THW_GetSerialNoPtr(); - - // movable id - pMovable = LCFG_THW_GetMovableUniqueIDPtr(); - movableLen1 = LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN / 2; - movableLen2 = LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN - movableLen1; - - // fuse id - fuseId = SCFG_ReadFuseData(); - - OS_TPrintf("Region: %-10s %08X\n", GetOSTWLRegionString(region), launcherInitialCode); - OS_TPrintf("DeviceID: %08X %u\n", deviceId, deviceId); - OS_TPrintf(" %s\n", bmsDeviceId); - OS_TPrintf("Serial: %s\n", pSerial); - OS_TPrintf("MovableID: "); PrintBytes(pMovable, movableLen1); OS_TPrintf("\n"); - OS_TPrintf(" "); PrintBytes(pMovable + movableLen1, movableLen2); OS_TPrintf("\n"); - OS_TPrintf("FuseID: %08X%08X\n", static_cast(fuseId >> 32), static_cast(fuseId)); -} - void SetupTitlesDataFile(const NAMTitleId* pTitleIds, u32 numTitleIds) { NAMTitleId tid; - - // OS_TPrintf("%s %d num=%d\n",__FUNCTION__,__LINE__,numTitleIds); - for( u32 i = 0; i < numTitleIds; i++ ) { tid = pTitleIds[i]; - // OS_TPrintf("%s %d 0x%016X\n",__FUNCTION__,__LINE__,(u64)tid); NAM_SetupTitleDataFile(tid); - //OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); } } @@ -308,6 +214,8 @@ void DeleteECDirectory(void) void SetupShopTitleId(void) { + // はたもとくんに確認->ショップのオールリージョンでOK + // *(u64 *)(HW_TWL_ROM_HEADER_BUF + 0x230) = 0x00030015 48-4E-46-41-ull; *(u64 *)(HW_TWL_ROM_HEADER_BUF + 0x230) = 0x00030015484E4641ull; } @@ -334,7 +242,8 @@ BOOL SetupNHTTP(void) if (rv != NHTTP_ERROR_NONE) { - OS_TPrintf("Failed to start NHTTP, rv=%d\n", rv); + miya_log_fprintf(log_fd, "Failed to start NHTTP, rv=%d\n", rv); + mprintf("Failed to start NHTTP, rv=%d\n", rv); return FALSE; } return TRUE; @@ -386,7 +295,8 @@ LoadCert(void** ppCert, u32* pSize, const char* name) bSuccess = FS_OpenFile(&f, path); if( ! bSuccess ) { - OS_TPrintf("Cannot open %s\n", path); + miya_log_fprintf(log_fd, "Cannot open %s\n", path); + mprintf("Cannot open %s\n", path); return FALSE; } @@ -394,14 +304,16 @@ LoadCert(void** ppCert, u32* pSize, const char* name) pCert = OS_Alloc(certSize); if ( pCert == NULL ) { - OS_TPrintf("Cannot allocate work memroy\n"); + miya_log_fprintf(log_fd, "Cannot allocate work memroy\n"); + mprintf("Cannot allocate work memroy\n"); return FALSE; } readSize = FS_ReadFile(&f, pCert, static_cast(certSize)); if( readSize != certSize ) { - OS_TPrintf("fail to read file\n"); + miya_log_fprintf(log_fd, "%s fail to read file\n", __FUNCTION__); + mprintf("fail to read file\n"); return FALSE; } @@ -410,7 +322,8 @@ LoadCert(void** ppCert, u32* pSize, const char* name) result = NA_DecodeVersionData(pCert, certSize, pCert, certSize); if( result <= 0 ) { - OS_TPrintf("fail to decode version info %d\n", result); + miya_log_fprintf(log_fd, "%s fail to decode version info %d\n",__FUNCTION__,result); + mprintf("fail to decode version info %d\n", result); return FALSE; } @@ -442,8 +355,8 @@ BOOL SetupEC(void) //#define EC_LOG_FINEST 6 // logLevel = EC_LOG_FINEST; - logLevel = EC_LOG_FINE; - // logLevel = EC_LOG_NONE; + // logLevel = EC_LOG_FINE; + logLevel = EC_LOG_WARN; LoadCert(&pClientCert, &clientCertSize, ".twl-nup-cert.der"); LoadCert(&pClientKey, &clientKeySize, ".twl-nup-prvkey.der"); @@ -466,7 +379,8 @@ BOOL SetupEC(void) rv = EC_Init(initArgs, nInitArgs); // SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to initialize EC, rv=%d\n", rv); if( rv != EC_ERROR_OK ) { - OS_TPrintf("Failed to initialize EC, rv=%d\n", rv); + miya_log_fprintf(log_fd, "%s Failed to initialize EC, rv=%d\n",__FUNCTION__, rv); + mprintf("Failed to initialize EC, rv=%d\n", rv); return FALSE; } @@ -475,7 +389,8 @@ BOOL SetupEC(void) "https://cas.t.shop.nintendowifi.net/cas/services/CatalogingSOAP" ); // SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to EC_SetWebSvcUrls, rv=%d\n", rv); if( rv != EC_ERROR_OK ) { - OS_TPrintf("Failed to EC_SetWebSvcUrls, rv=%d\n", rv); + miya_log_fprintf(log_fd, "%s Failed to EC_SetWebSvcUrls, rv=%d\n", __FUNCTION__, rv); + mprintf("Failed to EC_SetWebSvcUrls, rv=%d\n", rv); return FALSE; } @@ -483,7 +398,8 @@ BOOL SetupEC(void) "http://ccs.t.shop.nintendowifi.net/ccs/download" ); // SDK_ASSERTMSG(rv == EC_ERROR_OK, "Failed to EC_SetContentUrls, rv=%d\n", rv); if( rv != EC_ERROR_OK ) { - OS_TPrintf("Failed to EC_SetContentUrls, rv=%d\n", rv); + miya_log_fprintf(log_fd, "%s Failed to EC_SetContentUrls, rv=%d\n",__FUNCTION__, rv); + mprintf("Failed to EC_SetContentUrls, rv=%d\n", rv); return FALSE; } @@ -499,7 +415,8 @@ BOOL WaitEC(ECOpId opId) if( opId < 0 ) { - OS_TPrintf("error %d %s\n", opId, GetECErrorString(opId)); + miya_log_fprintf(log_fd, "%s WaitEC error %d %s\n", __FUNCTION__,opId, GetECErrorString(opId)); + mprintf("WaitEC error %d %s\n", opId, GetECErrorString(opId)); return FALSE; } @@ -512,9 +429,10 @@ BOOL WaitEC(ECOpId opId) { if( result == EC_ERROR_NOT_ACTIVE ) { - OS_TPrintf("opId=%d\n", opId); + miya_log_fprintf(log_fd, "%s opId=%d\n", __FUNCTION__, opId); } - OS_TPrintf("Failed to EC_GetProgress, result=%d %s\n", result, GetECErrorString(result)); + miya_log_fprintf(log_fd, "%s Failed to EC_GetProgress, result=%d %s\n", + __FUNCTION__, result, GetECErrorString(result)); mprintf("EC_GetProgress failed %d\n %s\n", result, GetECErrorString(result)); return FALSE; } @@ -556,14 +474,17 @@ static char CheckRegistration() ECError ecError; ECDeviceInfo di; - ECDL_LOG("check registeration"); + //ECDL_LOG("check registeration"); progress = EC_CheckRegistration(); if( FALSE == WaitEC(progress) ) { return '\0'; // 微妙・・ } ecError = EC_GetDeviceInfo(&di); - SDK_ASSERT( ecError == EC_ERROR_OK ); + // SDK_ASSERT( ecError == EC_ERROR_OK ); + if( ecError != EC_ERROR_OK ) { + return '\0'; // 微妙・・ + } #ifdef SDK_DEBUG #define ECDL_DI_FMT "%-30s" @@ -607,22 +528,24 @@ static BOOL GetChallenge(char* challenge) s32 progress; ECError ecError; - ECDL_LOG("get challenge"); + //ECDL_LOG("get challenge"); progress = EC_SendChallengeReq(); if( FALSE == WaitEC(progress) ) { return FALSE; } ecError = EC_GetChallengeResp(challenge); - SDK_ASSERT( ecError == EC_ERROR_OK ); - return TRUE; + if( ecError == EC_ERROR_OK ) { + return TRUE; + } + return FALSE; } static BOOL SyncRegistration(const char* challenge) { s32 progress; - ECDL_LOG("sync registration"); + // ECDL_LOG("sync registration"); progress = EC_SyncRegistration(challenge); if( FALSE == WaitEC(progress) ) { return FALSE; @@ -634,7 +557,7 @@ static BOOL Register(const char* challenge) { s32 progress; - ECDL_LOG("register"); + // ECDL_LOG("register"); progress = EC_Register(challenge, NULL, NULL); if( FALSE == WaitEC(progress) ) { return FALSE; @@ -646,7 +569,7 @@ static BOOL Transfer(const char* challenge) { s32 progress; - ECDL_LOG("transfer"); + // ECDL_LOG("transfer"); progress = EC_Transfer(challenge); if( FALSE == WaitEC(progress) ) { return FALSE; @@ -658,7 +581,7 @@ static BOOL SyncTickets() { s32 progress; - ECDL_LOG("sync tickets"); + // ECDL_LOG("sync tickets"); progress = EC_SyncTickets(EC_SYNC_TYPE_IMPORT_ALL); if( FALSE == WaitEC(progress) ) { return FALSE; @@ -666,133 +589,211 @@ static BOOL SyncTickets() return TRUE; } +static int a_to_int(char c) +{ + if( ('a' <= c) && (c <= 'f') ) { + return (int)( c - 'a' + 10 ); + } + else if( ('A' <= c) && (c <= 'F') ) { + return (int)( c - 'A' + 10 ); + } + else if( ('0' <= c) && (c <= '9') ) { + return (int)( c - '0' ); + } + return -1; +} + +static BOOL Tid_To_GameCode(u64 tid, char *gcode) +{ + u32 code; + char *str; + OS_TPrintf("tid = %016X\n",tid); + str = gcode; + code = (u32)(tid & 0xffffffff); + *str++ = (char)((code >> 24) & 0xff); + *str++ = (char)((code >> 16) & 0xff); + *str++ = (char)((code >> 8) & 0xff); + *str++ = (char)(code & 0xff); + return TRUE; +} + + static BOOL DownloadTitles(const NAMTitleId* pTitleIds, u32 numTitleIds) { s32 progress; + NAMTitleId tid; + BOOL ret_flag = TRUE; + // ECDL_LOG("download"); + char game_code_buf[5]; - ECDL_LOG("download"); - for( u32 i = 0; i < numTitleIds; i++ ) - { - NAMTitleId tid = pTitleIds[i]; + for( u32 i = 0; i < numTitleIds; i++ ) { + tid = pTitleIds[i]; progress = EC_DownloadTitle(tid, EC_DT_UPDATE_REQUIRED_CONTENTS); + // mprintf("-check registration.. "); + (void)Tid_To_GameCode((u64)tid, game_code_buf); + game_code_buf[4] = '\0'; + mprintf(" downloading.. [%s] ", game_code_buf); if( FALSE == WaitEC(progress) ) { - return FALSE; + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + miya_log_fprintf(log_fd, " %s download NG.\n",game_code_buf); + ret_flag = FALSE; + } + else { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + miya_log_fprintf(log_fd, " %s download OK.\n",game_code_buf); } } - return TRUE; + return ret_flag; } BOOL ECDownload(const NAMTitleId* pTitleIds, u32 numTitleIds) { char challenge[EC_CHALLENGE_BUF_SIZE]; char status; + BOOL ret_flag; - // mprintf("-CheckRegistration..\n"); + mprintf("-check registration.. "); + miya_log_fprintf(log_fd, "-check registration..."); status = CheckRegistration(); // U unregistered // R registered // P pending // T transfered -#if 0 - SDK_ASSERTMSG(status != 'U', "acount not transfered yet."); - SDK_ASSERTMSG(status != 'R', "already registered. please delete acount."); - SDK_ASSERTMSG( (status == 'P') || (status == 'T'), "invalid registration status '%c'", status ); -#else - if( status == 'U') { + if( status == '\0' ) { + miya_log_fprintf(log_fd, "NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + mprintf(" my error.\n"); + miya_log_fprintf(log_fd, " my error.\n"); + return FALSE; + } + else if( status == 'U') { + miya_log_fprintf(log_fd, "NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); mprintf(" acount not transfered yet.\n"); + miya_log_fprintf(log_fd, " acount not transfered yet.\n"); return FALSE; } - if( status == 'R') { + else if( status == 'R') { + miya_log_fprintf(log_fd, "NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); mprintf(" already registered. please delete acount.\n"); + miya_log_fprintf(log_fd, " already registered. please delete acount.\n"); return FALSE; } - if( (status != 'P') && (status != 'T') ) { + else if( (status != 'P') && (status != 'T') ) { + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); mprintf(" invalid registration status '%c'\n", status ); + miya_log_fprintf(log_fd, " invalid registration status '%c'\n", status ); return FALSE; } - // mprintf(" succeeded."); -#endif + else { + miya_log_fprintf(log_fd, "OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + miya_log_fprintf(log_fd, "-get challenge1.."); mprintf("-get challenge1 "); if( FALSE == GetChallenge(challenge) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } + miya_log_fprintf(log_fd, "-transfer.. "); mprintf("-transfer "); if( FALSE == Transfer(challenge) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } + + miya_log_fprintf(log_fd, "-get challenge.. "); mprintf("-get challenge2 "); if( FALSE == GetChallenge(challenge) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } + miya_log_fprintf(log_fd, "-sync registration.."); mprintf("-sync registration "); if( FALSE == SyncRegistration(challenge) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } + miya_log_fprintf(log_fd, "-sync tickets.."); mprintf("-sync tickets "); if( FALSE == SyncTickets() ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } - mprintf("-download titles "); - if( FALSE == DownloadTitles(pTitleIds, numTitleIds) ) { - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; - } - else { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - } + // ここでアプリをダウンロードしている + miya_log_fprintf(log_fd, "-download titles\n"); + mprintf("-download titles\n"); - return TRUE; + ret_flag = DownloadTitles(pTitleIds, numTitleIds); + + return ret_flag; } @@ -800,32 +801,36 @@ BOOL KPSClient() { s32 progress; - OS_TPrintf("generate key pair\n"); + miya_log_fprintf(log_fd, "-generate key pair .."); mprintf("-generate key pair "); progress = EC_GenerateKeyPair(); if( FALSE == WaitEC(progress) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } - OS_TPrintf("confirm key pair\n"); + miya_log_fprintf(log_fd, "-confirm key pair .. "); mprintf("-confirm key pair "); progress = EC_ConfirmKeyPair(); if( FALSE == WaitEC(progress) ) { + miya_log_fprintf(log_fd, "NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); return FALSE; } else { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); @@ -836,3 +841,22 @@ BOOL KPSClient() +FSFile *hatamotolib_log_start(char *log_file_name ) +{ + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + return log_fd; +} + +void hatamotolib_log_end(void) +{ + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + if( log_active ) { + Log_File_Close(log_fd); + } +} + diff --git a/build/tools/sctools/copy_dst/src/hatamotolib.h b/build/tools/sctools/copy_dst/src/hatamotolib.h index 77ba41e..814ab03 100644 --- a/build/tools/sctools/copy_dst/src/hatamotolib.h +++ b/build/tools/sctools/copy_dst/src/hatamotolib.h @@ -8,14 +8,15 @@ extern "C" { void PrintDeviceInfo(void); void SetupShopTitleId(void); void SetupUserInfo(void); -void SetupVerData(void); +BOOL SetupVerData(void); void SetupNSSL(void); BOOL SetupNHTTP(void); BOOL SetupEC(void); void DeleteECDirectory(void); void SetupTitlesDataFile(const NAMTitleId* pTitleIds, u32 numTitleIds); +FSFile *hatamotolib_log_start(char *log_file_name ); +void hatamotolib_log_end(void); -BOOL hatamotolib_main(u64 *title_id_buf, u32 num_title); #ifdef __cplusplus } diff --git a/build/tools/sctools/copy_dst/src/main.c b/build/tools/sctools/copy_dst/src/main.c index 7f0e728..67d03d4 100644 --- a/build/tools/sctools/copy_dst/src/main.c +++ b/build/tools/sctools/copy_dst/src/main.c @@ -24,6 +24,8 @@ #include "font.h" #include "text.h" #include "mprintf.h" +#include "logprintf.h" + #include "gfx.h" #include "key.h" #include "my_fs_util.h" @@ -40,6 +42,7 @@ #include "nuc.h" #include "mynuc.h" #include "miya_mcu.h" +#include "error_report.h" #include "myfilename.h" #include "mfiler.h" @@ -53,15 +56,36 @@ static BOOL no_reboot_flag = FALSE; static BOOL only_wifi_config_data_trans_flag = FALSE; static BOOL user_and_wifi_config_data_trans_flag = FALSE; +static BOOL no_network_flag = FALSE; static BOOL completed_flag = FALSE; static FSEventHook sSDHook; static BOOL sd_card_flag = FALSE; //static BOOL reboot_flag = FALSE; + +static u8 org_region = 0; +static u64 org_fuseId = 0; +static int select_mode = 0; static volatile BOOL reboot_flag; +static int miya_debug_level = 0; + + + static u8 WorkForNA[NA_VERSION_DATA_WORK_SIZE]; + +static BOOL pushed_power_button = FALSE; + +static PMExitCallbackInfo pmexitcallbackinfo; + +static void pmexitcallback(void *arg) +{ +#pragma unused(arg) + pushed_power_button = TRUE; +} + + static void SDEvents(void *userdata, FSEvent event, void *arg) { (void)userdata; @@ -162,7 +186,6 @@ static BOOL RestoreFromSDCard1(void) ちなみにすでにMydataLoad関数は成功しているものとする。 したがって MyData mydata にはデータが入っている。 */ - // static BOOL SDBackupToSDCard8(void) if( (mydata.rtc_date_flag == TRUE) && (mydata.rtc_time_flag == TRUE) ) { mprintf("RTC data restore "); if( RTC_RESULT_SUCCESS != RTC_SetDate( &(mydata.rtc_date) ) ) { @@ -186,6 +209,7 @@ static BOOL RestoreFromSDCard1(void) mprintf("No original RTC data\n"); flag = TRUE; } + return flag; } @@ -220,18 +244,23 @@ static BOOL RestoreFromSDCard2(void) static BOOL RestoreFromSDCard3(void) { // static BOOL SDBackupToSDCard2(void) - mprintf("WirelessLAN param. restore "); - if( TRUE == nvram_restore( MyFile_GetWifiParamFileName() ) ) { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + if( mydata.wireless_lan_param_flag == TRUE ) { + mprintf("WirelessLAN param. restore "); + if( TRUE == nvram_restore( MyFile_GetWifiParamFileName() ) ) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + return FALSE; + } } else { - // error - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + mprintf("no original WirelessLAN param.\n"); } return TRUE; @@ -240,79 +269,158 @@ static BOOL RestoreFromSDCard3(void) static BOOL RestoreFromSDCard4(void) { // static BOOL SDBackupToSDCard3(void) - mprintf("User setting param. restore "); - if( TRUE == MiyaRestoreTWLSettings( MyFile_GetUserSettingsFileName() ) ) { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + if( mydata.user_settings_flag == TRUE ) { + mprintf("User setting param. restore "); + if( TRUE == MiyaRestoreTWLSettings( MyFile_GetUserSettingsFileName() ) ) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + return FALSE; + } } else { - // error - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + mprintf("no original user setting param.\n"); } - return TRUE; } static BOOL RestoreFromSDCard5(void) { // static BOOL SDBackupToSDCard4(void) - mprintf("App. shared files restore "); - if( TRUE == RestoreDirEntryList( MyFile_GetAppSharedListFileName(), MyFile_GetAppSharedRestoreLogFileName() )) { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + int list_count; + int error_count; + + Error_Report_Init(); + + if( mydata.num_of_shared2_files > 0 ) { + mprintf("App. shared files restore "); + if( TRUE == RestoreDirEntryList( MyFile_GetAppSharedListFileName(), + MyFile_GetAppSharedRestoreLogFileName(), &list_count, &error_count )) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + } + else if( mydata.num_of_shared2_files == 0 ) { + mprintf("Original device has no shared file\n"); } else { - // error - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + mprintf("Original shared files saving failed\n"); } + + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + return TRUE; } static BOOL RestoreFromSDCard6(void) { - // static BOOL SDBackupToSDCard5(void) - mprintf("Photo files restore "); - if( TRUE == RestoreDirEntryList( MyFile_GetPhotoListFileName() , MyFile_GetPhotoRestoreLogFileName() )) { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + int list_count; + int error_count; + + + Error_Report_Init(); + + if( mydata.num_of_photo_files > 0 ) { + mprintf("Photo files restore "); + if( TRUE == RestoreDirEntryList( MyFile_GetPhotoListFileName() , + MyFile_GetPhotoRestoreLogFileName(), + &list_count, &error_count )) { + + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + } + else if( mydata.num_of_photo_files == 0 ) { + mprintf("Original device has no photo file\n"); } else { - // error - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + mprintf("Original photo files saving failed\n"); } + + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + return TRUE; } static BOOL RestoreFromSDCard8(void) { + int list_count; + int error_count; - // static BOOL SDBackupToSDCard6(void) - mprintf("App. save data restore "); - if( TRUE == RestoreDirEntryList( MyFile_GetAppDataListFileName() , MyFile_GetAppDataRestoreLogFileName() )) { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + Error_Report_Init(); + + if( mydata.num_of_app_save_data > 0 ) { + mprintf("App. save data restore "); + if( no_network_flag == TRUE ) { + if( TRUE == RestoreDirEntryListSystemBackupOnly( MyFile_GetSaveDataListFileName() , + MyFile_GetSaveDataRestoreLogFileName(), + &list_count, &error_count )) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + } + else { + if( TRUE == RestoreDirEntryList( MyFile_GetSaveDataListFileName() , + MyFile_GetSaveDataRestoreLogFileName(), + &list_count, &error_count )) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + // error + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + } + } + else if( mydata.num_of_app_save_data == 0 ) { + mprintf("Original device has no app. save data\n"); } else { - // error - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + mprintf("Original app. save data saving failed\n"); } + + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + return TRUE; } @@ -418,6 +526,7 @@ static BOOL LoadWlanConfig(void) else { OS_TPrintf("Invalid wlan cfg file\n"); mfprintf(tc[3],"Invalid wlan cfg file\n"); + mprintf("Invalid wlan cfg file\n"); return FALSE; } return TRUE; @@ -430,113 +539,134 @@ static BOOL RestoreFromSDCard7(void) int title_id_count; int i; ECError rv; + BOOL ret_flag = TRUE; + FSFile *log_fd; title_id_buf_ptr = NULL; title_id_count = 0; rv = EC_ERROR_OK; /* hws_info.serialNoは戻せない */ - /* */ - // static BOOL SDBackupToSDCard7(void) - // for DEBUG - // mydata.shop_record_flag = TRUE; + if( no_network_flag == TRUE ) { + return TRUE; + } + + log_fd = hatamotolib_log_start( MyFile_GetEcDownloadLogFileName() ); if( mydata.shop_record_flag == FALSE ) { /* ネットワークにつながなくていいか? */ - OS_TPrintf("no shop record\n"); + miya_log_fprintf(log_fd,"no shop record\n"); mprintf(" (--no shop record--)\n"); } else { - mprintf("Connect to the internet\n"); - - mprintf("-user title list loading.. "); - OS_TPrintf("user title list loading\n"); - if( TRUE == TitleIDLoad( MyFile_GetDownloadTitleIDFileName(), &title_id_buf_ptr, - &title_id_count, NULL) ) { - - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - for( i = 0; i < title_id_count ; i++ ) { - u64 tid = *(title_id_buf_ptr + i ); - mprintf(" id %02d %08X %08X\n", i,(u32)(tid >> 32), (u32)tid); + miya_log_fprintf(log_fd,"EC download\n"); + mprintf("EC download\n"); + + if( mydata.num_of_user_download_app > 0 ) { + miya_log_fprintf(log_fd,"-user title list loading\n"); + mprintf("-user title list load "); + if( TRUE == TitleIDLoad( MyFile_GetDownloadTitleIDFileName(), &title_id_buf_ptr, + &title_id_count, MyFile_GetDownloadTitleIDRestoreLogFileName()) ) { + + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + for( i = 0; i < title_id_count ; i++ ) { + u64 tid = *(title_id_buf_ptr + i ); + mprintf(" id %02d %08X %08X\n", i,(u32)(tid >> 32), (u32)tid); + miya_log_fprintf(log_fd," id %02d %08X %08X\n", i,(u32)(tid >> 32), (u32)tid); + } + } + else { + ret_flag = FALSE; + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } } + else if( mydata.num_of_user_download_app == 0 ) { + miya_log_fprintf(log_fd,"Original device has no user download app.\n"); + mprintf("Original device has no user download app.\n"); + } else { - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + miya_log_fprintf(log_fd,"Original user download app. list saving failed\n"); + mprintf("Original user download app. list saving failed\n"); } // mprintf(" "); - mprintf("-wireless AP conf. loading.. "); + miya_log_fprintf(log_fd,"-wireless AP conf. load.. "); + mprintf("-wireless AP conf. load "); if( TRUE == LoadWlanConfig() ) { + miya_log_fprintf(log_fd, "OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + /* nand:/ticketはチケット同期でダウンロード */ // 不要:デバイス情報の表示 // PrintDeviceInfo(); - // OS_TPrintf("--------------------------------\n"); - // setup // 必須:タイトル ID の偽装 - SetupShopTitleId(); - + SetupShopTitleId(); /* エラーはない */ + miya_log_fprintf(log_fd,"SetupShopTitleId\n"); + + // ?:ユーザ設定がされていないと接続できないので適当に設定 - SetupUserInfo(); + // SetupUserInfo(); // 必須:バージョンデータのマウント - SetupVerData(); + if( FALSE == SetupVerData() ) { + miya_log_fprintf(log_fd, "%s failed SetupVerData\n", __FUNCTION__); + ret_flag = FALSE; + goto end_log_e; + } + + // 必須:ネットワークへの接続 - NcStart(SITEDEFS_DEFAULTCLASS); + if( 0 != NcStart(SITEDEFS_DEFAULTCLASS) ) { + miya_log_fprintf(log_fd, "%s failed NcStart\n", __FUNCTION__); + ret_flag = FALSE; + goto end_log_e; + } /******** ネットワークにつないだ *************/ // 必須:HTTP と SSL の初期化 - OS_TPrintf("start NHTTP\n"); - mprintf("-start NHTTP "); + miya_log_fprintf(log_fd,"-setup NSSL & NHTTP\n"); SetupNSSL(); if( FALSE == SetupNHTTP() ) { - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + ret_flag = FALSE; + miya_log_fprintf(log_fd, "%s failed SetupNHTTP\n", __FUNCTION__); + mprintf(" %s failed SetupNHTTP\n", __FUNCTION__); goto end_nhttp; } - else { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - } /******** NHTTP & NSSLにつないだ *************/ // 必須:EC の初期化 - OS_TPrintf("start EC\n"); - mprintf("-start EC "); + miya_log_fprintf(log_fd,"-setup EC\n"); if( FALSE == SetupEC() ) { - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + ret_flag = FALSE; + miya_log_fprintf(log_fd, "%s failed SetupEC\n", __FUNCTION__); + mprintf(" %s failed SetupEC\n", __FUNCTION__); goto end_ec; } - else { - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - } // 必須:デバイス証明書の発行 if( FALSE == KPSClient() ) { + ret_flag = FALSE; + miya_log_fprintf(log_fd, "%s failed KPSClient\n", __FUNCTION__); goto end_ec_f; } if( FALSE == ECDownload((NAMTitleId *)title_id_buf_ptr , (u32)title_id_count) ) { + ret_flag = FALSE; + miya_log_fprintf(log_fd, "%s failed ECDownload\n", __FUNCTION__); goto end_ec_f; } @@ -547,13 +677,15 @@ static BOOL RestoreFromSDCard7(void) end_ec_f: // cleanup // EC の終了処理 - mprintf("-EC_Shutdown.. "); + mprintf("-ec shutdown.. "); rv = EC_Shutdown(); // SDK_WARNING(rv == EC_ERROR_OK, "Failed to shutdown EC, rv=%d\n", rv); if( rv != EC_ERROR_OK ) { + ret_flag = FALSE; m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + miya_log_fprintf(log_fd, "%s failed EC_Shutdown\n", __FUNCTION__); } else { m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); @@ -561,11 +693,10 @@ static BOOL RestoreFromSDCard7(void) } m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); end_ec: - // ネットワークからの切断 - OS_TPrintf("disconnecting ..\n"); - mprintf("-disconnecting... "); + miya_log_fprintf(log_fd,"-LINK DOWN...."); + mprintf("-LINK DOWN...."); NHTTP_Cleanup(); end_nhttp: @@ -573,11 +704,11 @@ static BOOL RestoreFromSDCard7(void) end_nssl: NcFinish(); end_nc: - //OS_TPrintf("NSSL_Finish() return = %d\n", NSSL_Finish()); + //miya_log_fprintf(log_fd,"NSSL_Finish() return = %d\n", NSSL_Finish()); TerminateWcmControl(); - OS_TPrintf("done.\n"); + miya_log_fprintf(log_fd,"done.\n"); mprintf("done.\n"); if( title_id_buf_ptr != NULL && title_id_count != 0 ) { @@ -585,17 +716,22 @@ static BOOL RestoreFromSDCard7(void) } // EC が自分の Title ID のディレクトリを作成してしまうため、削除する DeleteECDirectory(); - + end_log_e: + ; } else { /* mprintf("-Wireless AP conf. loading.. "); */ + miya_log_fprintf(log_fd, "NG.\n"); + ret_flag = FALSE; m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); } m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); } - return TRUE; + hatamotolib_log_end(); + + return ret_flag; } @@ -662,13 +798,14 @@ static void MyThreadProc(void *arg) stream_play1(); /* ok.aiff */ } Gfx_Set_BG1_Color((u16)M_TEXT_COLOR_DARKGREEN); +#ifdef MIYA_SET_VOL_AND_BRIGHT OS_Sleep(2000); (void)MCU_SetVolume((u8)(mydata.volume)); (void)MCU_SetBackLightBrightness((u8)(mydata.backlight_brightness)); OS_TPrintf("vol = %d\n",mydata.volume ); OS_TPrintf("bright = %d\n", mydata.backlight_brightness); - OS_Sleep(200000); +#endif break; } OS_Sleep(200); @@ -695,17 +832,39 @@ static void MyThreadProcNuc(void *arg) #pragma unused(arg) OSMessage message; u16 keyData; + FSFile *log_fd; + BOOL ret_flag; + + + + while( 1 ) { (void)OS_SendMessage(&MyMesgQueue_response, (OSMessage)0, OS_MESSAGE_NOBLOCK); (void)OS_ReceiveMessage(&MyMesgQueue_request, &message, OS_MESSAGE_BLOCK); - mprintf("-Wireless AP conf. loading.. "); + mprintf("-Wireless AP conf. load "); if( TRUE == LoadWlanConfig() ) { m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - NcStart(SITEDEFS_DEFAULTCLASS); + + if( 0 != NcStart(SITEDEFS_DEFAULTCLASS) ) { + mprintf("connection failed!\n\n"); + while( 1 ) { + keyData = m_get_key_code(); + if ( keyData & (PAD_BUTTON_A | PAD_BUTTON_START) ) { + OS_RebootSystem(); + } + OS_Sleep(20); + } + } + + /* NSSL_Init()呼んではダメ! */ - if( TRUE == my_numc_proc() ) { + log_fd = my_nuc_log_start( MyFile_GetNupLogFileName() ); + ret_flag = my_numc_proc(); + my_nuc_log_end(); + + if( TRUE == ret_flag ) { m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); OS_TPrintf("Network Update Completed!\n"); mprintf("Network Update Completed!\n"); @@ -722,9 +881,10 @@ static void MyThreadProcNuc(void *arg) mprintf("\n"); text_blink_current_line(tc[0]); mprintf("press A button to start RESTORE\n\n"); + MCU_SetFreeRegister( 0x55 ); while( 1 ) { keyData = m_get_key_code(); - if ( keyData & PAD_BUTTON_A ) { + if ( keyData & (PAD_BUTTON_A | PAD_BUTTON_START) ) { OS_RebootSystem(); } OS_Sleep(20); @@ -735,7 +895,7 @@ static void MyThreadProcNuc(void *arg) // text_blink_current_line(tc[0]); while( 1 ) { keyData = m_get_key_code(); - if ( keyData & PAD_BUTTON_A ) { + if ( keyData & (PAD_BUTTON_A | PAD_BUTTON_START) ) { } OS_Sleep(20); } @@ -794,7 +954,7 @@ void TwlMain(void) RTCDate rtc_date; RTCTime rtc_time; int i; - // int n; + int n; u8 macAddress[6]; MY_ENTRY_LIST *mfiler_list_head = NULL; u16 s_major, s_minor; @@ -803,7 +963,9 @@ void TwlMain(void) BOOL MydataLoadDecrypt_message_flag = TRUE; BOOL MydataLoadDecrypt_dir_flag = TRUE; BOOL MydataLoadDecrypt_success_flag = TRUE; - + BOOL dir_select_mode = FALSE; + u8 free_reg; + u8 mode; OS_Init(); OS_InitThread(); @@ -824,7 +986,7 @@ void TwlMain(void) // ファイルシステム初期化 FS_Init( FS_DMA_NOT_USE ); - + PM_Init(); // メインアリーナのアロケートシステムを初期化 newArenaLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1); OS_SetMainArenaLo(newArenaLo); @@ -856,8 +1018,27 @@ void TwlMain(void) MIYA_MCU_Init(); OS_TPrintf("MCU Free Reg. 0x%02x\n", MCU_GetFreeReg()); - if( MCU_GetFreeReg() == 0x55 ) { + free_reg = MCU_GetFreeReg(); + if( free_reg == 0x55 ) { reboot_flag = TRUE; + } + else if( free_reg == 0x66 ) { + reboot_flag = TRUE; + no_network_flag = TRUE; + } + else if( free_reg == 0x77 ) { + no_reboot_flag = TRUE; + mprintf("no_reboot_flag ON\n"); + } + else if( free_reg == 0x88 ) { + reboot_flag = TRUE; + only_wifi_config_data_trans_flag = TRUE; + mprintf("only_wifi_config_data_trans ON\n"); + } + else if( free_reg == 0x99 ) { + reboot_flag = TRUE; + user_and_wifi_config_data_trans_flag = TRUE; + mprintf("user_and_wifi_config_data ON\n"); } else { reboot_flag = FALSE; @@ -867,18 +1048,18 @@ void TwlMain(void) /* miya */ // reboot_flag = TRUE; -#if 0 - /* - static inline u8 MCU_GetVolume( void ) - static inline BOOL MCU_SetVolume( u8 volume ) - static inline u8 MCU_GetBackLightBrightness( void ) - static inline BOOL MCU_SetBackLightBrightness( u8 brightness ) - */ -#endif + + + PM_SetAutoExit( FALSE ); + PM_SetExitCallbackInfo( &pmexitcallbackinfo,pmexitcallback, NULL); + PM_PrependPreExitCallback( &pmexitcallbackinfo ); + + +#ifdef MIYA_SET_VOL_AND_BRIGHT MCU_SetVolume( (u8)31 ); MCU_SetBackLightBrightness( (u8)4 ); - +#endif if( FALSE == SDCardValidation() ) { sd_card_flag = FALSE; @@ -918,22 +1099,41 @@ void TwlMain(void) m_set_palette(tc[0], 0xF); /* white */ } +#if 1 + // ニックネームが空なら適当に設定 + if( *LCFG_TSD_GetNicknamePtr() == L'\0' ) { + LCFG_TSD_SetNickname((const u16*)(L"repair-tool")); + // mprintf("Set dummy Nickname\n"); + } +#endif + + // 国が選択されていないなら適当に設定 + if( LCFG_TSD_GetCountry() == LCFG_TWL_COUNTRY_UNDEFINED ) { + LCFG_TSD_SetCountry(LCFG_TWL_COUNTRY_JAPAN); + // mprintf("Set dummy Country code\n"); + } + // region - mydata.region = LCFG_THW_GetRegion(); + org_region = LCFG_THW_GetRegion(); // ES Device ID - mydata.fuseId = SCFG_ReadFuseData(); - OS_TPrintf("eFuseID: %08X%08X\n", (u32)(mydata.fuseId >> 32), (u32)(mydata.fuseId)); + org_fuseId = SCFG_ReadFuseData(); + OS_TPrintf("eFuseID: %08X%08X\n", (u32)(org_fuseId >> 32), (u32)(org_fuseId)); OS_GetMacAddress( macAddress ); + mydata.shop_record_flag = FALSE; es_error_code = ES_GetDeviceId(&mydata.deviceId); if( es_error_code == ES_ERR_OK ) { - mydata.shop_record_flag = TRUE; + if( TRUE == CheckShopRecord( hws_info.region, NULL ) ) { + mydata.shop_record_flag = TRUE; + } + else { + mprintf("no ec.cfg file\n"); + } } else { OS_TPrintf("es_error_code = %d\n", es_error_code ); - mydata.shop_record_flag = FALSE; } // (void)CheckShopRecord( hws_info.region, NULL ); @@ -944,38 +1144,6 @@ void TwlMain(void) OS_TPrintf("DeviceID: %s\n", mydata.bmsDeviceId); } - // mprintf("mcu reg 0x%02X\n", miya_mcu_free_register ); -#if 0 - OS_TPrintf("MCU Free Reg. 0x%02x\n",MCU_GetFreeReg()); - if( MCU_GetFreeReg() == 0x55 ) { - reboot_flag = TRUE; - } - else { - reboot_flag = FALSE; - } -#endif - -#if 1 - (void)m_get_key_trigger(); - keyData = m_get_key_code(); - if ( keyData & PAD_BUTTON_X ) { - reboot_flag = TRUE; - } - else if( keyData & PAD_BUTTON_Y ) { - no_reboot_flag = TRUE; - mprintf("no_reboot_flag ON\n"); - } - else if( keyData & PAD_BUTTON_B ) { - reboot_flag = TRUE; - only_wifi_config_data_trans_flag = TRUE; - mprintf("only_wifi_config_data_trans ON\n"); - } - else if( keyData & (PAD_BUTTON_START | PAD_BUTTON_SELECT) ) { - reboot_flag = TRUE; - user_and_wifi_config_data_trans_flag = TRUE; - mprintf("user_and_wifi_config_data ON\n"); - } -#endif if( FALSE == reboot_flag ) { mprintf("Network update mode\n"); @@ -1016,6 +1184,8 @@ void TwlMain(void) } else { + dir_select_mode = TRUE; + mprintf("user data restore mode\n"); // NAM の初期化 NAM_Init(&AllocForNAM, &FreeForNAM); @@ -1071,7 +1241,8 @@ void TwlMain(void) vram_num_main = (MAX_VRAM_NUM-1); } } - else if ( keyData & PAD_BUTTON_A ) { + else if ( keyData & (PAD_BUTTON_A | PAD_BUTTON_START) ) { + if( sd_card_flag == TRUE ) { if( FALSE == reboot_flag ) { /* ネットワークアップデート */ @@ -1091,6 +1262,7 @@ void TwlMain(void) if( only_wifi_config_data_trans_flag == TRUE ) { /* 無線設定のみリストアする */ + mydata.wireless_lan_param_flag = TRUE; vram_num_sub = 0; MydataLoadDecrypt_message_flag = TRUE; MydataLoadDecrypt_dir_flag = TRUE; @@ -1098,6 +1270,8 @@ void TwlMain(void) (void)RestoreFromSDCard3(); } else if( user_and_wifi_config_data_trans_flag == TRUE ) { + mydata.user_settings_flag = TRUE; + mydata.wireless_lan_param_flag = TRUE; vram_num_sub = 0; MydataLoadDecrypt_message_flag = TRUE; MydataLoadDecrypt_dir_flag = TRUE; @@ -1110,7 +1284,17 @@ void TwlMain(void) MydataLoadDecrypt_success_flag = MydataLoadDecrypt( MyFile_GetGlobalInformationFileName(), &mydata, sizeof(MyData), NULL); if(TRUE == MydataLoadDecrypt_success_flag ) { - if( mydata.version_major != MY_DATA_VERSION_MAJOR ) { + if( org_region != mydata.region ) { + m_set_palette(tc[0], M_TEXT_COLOR_RED ); + mprintf("NG.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_YELLOW ); + mprintf(" invalid region code.\n"); + mprintf(" \n"); + mprintf(" \n"); + m_set_palette(tc[0], 0xF); /* white */ + MydataLoadDecrypt_message_flag = FALSE; + } + else if( mydata.version_major != MY_DATA_VERSION_MAJOR ) { m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_YELLOW ); @@ -1139,6 +1323,7 @@ void TwlMain(void) MydataLoadDecrypt_message_flag = TRUE; MydataLoadDecrypt_dir_flag = TRUE; MydataLoadDecrypt_success_flag = TRUE; + dir_select_mode = FALSE; start_my_thread(); } } @@ -1167,30 +1352,102 @@ void TwlMain(void) } } else if ( keyData & PAD_BUTTON_B ) { + miya_debug_level++; + miya_debug_level &= 1; + if( miya_debug_level ) { + Miya_debug_ON(); + mprintf("debug ON\n"); + } + else { + Miya_debug_OFF(); + mprintf("debug OFF\n"); + } } +#if 0 + /* スタートボタンはAボタンと同じ扱い */ else if ( keyData & PAD_BUTTON_START ) { } +#endif else if ( keyData & PAD_BUTTON_SELECT ) { } else if ( keyData & PAD_BUTTON_X ) { + select_mode++; + switch( select_mode ) { + case 1: + free_reg = mode = 0x55; + break; + case 2: + free_reg = mode = 0x66; + no_network_flag = TRUE; + break; + case 3: + free_reg = mode = 0x77; + no_reboot_flag = TRUE; + break; + case 4: + free_reg = mode = 0x88; + only_wifi_config_data_trans_flag = TRUE; + break; + case 5: + free_reg = mode = 0x99; + user_and_wifi_config_data_trans_flag = TRUE; + break; + default: + free_reg = mode = 0; + select_mode = 0; + break; + } + } else if ( keyData & PAD_BUTTON_Y ) { + MCU_SetFreeRegister( mode); + OS_RebootSystem(); + } + else if ( keyData & PAD_KEY_RIGHT ) { + n = m_get_display_offset_x(tc[0]); + n++; + m_set_display_offset_x(tc[0], n); + } + else if ( keyData & PAD_KEY_LEFT ) { + n = m_get_display_offset_x(tc[0]); + n--; + m_set_display_offset_x(tc[0], n); } else if ( keyData & PAD_KEY_UP ) { if( FALSE == reboot_flag ) { + n = m_get_display_offset_y(tc[0]); + n++; + m_set_display_offset_y(tc[0], n); } else { - if( vram_num_sub == 2 ) { - MFILER_CursorY_Up(); + if( dir_select_mode == TRUE ) { + if( vram_num_sub == 2 ) { + MFILER_CursorY_Up(); + } + } + else { + n = m_get_display_offset_y(tc[0]); + n++; + m_set_display_offset_y(tc[0], n); } } } else if ( keyData & PAD_KEY_DOWN ) { if( FALSE == reboot_flag ) { + n = m_get_display_offset_y(tc[0]); + n--; + m_set_display_offset_y(tc[0], n); } else { - if( vram_num_sub == 2 ) { - MFILER_CursorY_Down(); + if( dir_select_mode == TRUE ) { + if( vram_num_sub == 2 ) { + MFILER_CursorY_Down(); + } + } + else { + n = m_get_display_offset_y(tc[0]); + n--; + m_set_display_offset_y(tc[0], n); } } } @@ -1234,7 +1491,7 @@ void TwlMain(void) m_set_palette(tc[1], M_TEXT_COLOR_LIGHTBLUE ); mfprintf(tc[1], "eFuse ID: "); m_set_palette(tc[1], M_TEXT_COLOR_WHITE ); - mfprintf(tc[1],"%08X%08X\n\n", (u32)(mydata.fuseId >> 32), (u32)(mydata.fuseId)); + mfprintf(tc[1],"%08X%08X\n\n", (u32)(org_fuseId >> 32), (u32)(org_fuseId)); m_set_palette(tc[1], M_TEXT_COLOR_LIGHTBLUE ); @@ -1262,13 +1519,45 @@ void TwlMain(void) rtc_time.hour , rtc_time.minute , rtc_time.second ); - // mfprintf(tc[1], "cwd = %s\n\n", MFILER_Get_CurrentDir()); - if( FALSE == reboot_flag ) { + if( free_reg == 0x55 ) { + mfprintf(tc[1],"restart to RESTORE mode\n"); + } + else if( free_reg == 0x66 ) { + mfprintf(tc[1],"network-connection OFF mode\n"); + } + else if( free_reg == 0x77 ) { + mfprintf(tc[1],"no_reboot_flag ON\n"); + } + else if( free_reg == 0x88 ) { + mfprintf(tc[1],"only wifi config data\n"); + } + else if( free_reg == 0x99 ) { + mfprintf(tc[1],"only user settings data\n"); + } + else { + mfprintf(tc[1],"just reboot\n"); + } + mfprintf(tc[1], "press Y button to restart.\n"); + } else { mfprintf(tc[1], "function no.%d/%d\n\n", function_counter, function_table_max); + if( free_reg == 0x66 ) { + mfprintf(tc[1],"network-connection OFF mode\n"); + } + else if( free_reg == 0x77 ) { + mfprintf(tc[1],"no_reboot_flag ON\n"); + } + else if( free_reg == 0x88 ) { + mfprintf(tc[1],"only wifi config data\n"); + } + else if( free_reg == 0x99 ) { + mfprintf(tc[1],"only user settings data\n"); + } + + mfprintf(tc[2],"\f"); if( MydataLoadDecrypt_dir_flag == FALSE ) { @@ -1303,42 +1592,17 @@ void TwlMain(void) MFILER_ReadDir(&mfiler_list_head, MFILER_Get_CurrentDir()); MFILER_DisplayDir(tc[2], &mfiler_list_head, 0 ); } + + if( pushed_power_button == TRUE ) { + MCU_SetFreeRegister( 0x00 ); + // OS_TPrintf("ahondara\n"); + PM_ReadyToExit(); + } + loop_counter++; } -#if 0 - else if ( keyData & PAD_KEY_UP ) { - if( vram_num_main != 1 ) { - n = m_get_display_offset_y(tc[0]); - n++; - m_set_display_offset_y(tc[0], n); - } - else if( vram_num_sub == 2 ) { - MFILER_CursorY_Up(); - } - } - else if ( keyData & PAD_KEY_DOWN ) { - if( vram_num_main != 1 ) { - n = m_get_display_offset_y(tc[0]); - n--; - m_set_display_offset_y(tc[0], n); - } - else if( vram_num_sub == 2 ) { - MFILER_CursorY_Down(); - } - } - else if ( keyData & PAD_KEY_RIGHT ) { - n = m_get_display_offset_x(tc[0]); - n++; - m_set_display_offset_x(tc[0], n); - } - else if ( keyData & PAD_KEY_LEFT ) { - n = m_get_display_offset_x(tc[0]); - n--; - m_set_display_offset_x(tc[0], n); - } -#endif OS_Terminate(); } diff --git a/build/tools/sctools/copy_dst/src/mfiler.c b/build/tools/sctools/copy_dst/src/mfiler.c index f1b4e9e..dc71088 100644 --- a/build/tools/sctools/copy_dst/src/mfiler.c +++ b/build/tools/sctools/copy_dst/src/mfiler.c @@ -173,6 +173,10 @@ int MFILER_ReadDir(MY_ENTRY_LIST **headp, const char *path_src) } else if( STD_StrCmp(entry_src.longname, "..") == 0 ) { } + else if( STD_StrCmp(entry_src.longname, "wlan_cfg.txt") == 0 ) { + } + else if( STD_StrCmp(entry_src.longname, "nup_log.txt") == 0 ) { + } else if( entry_src.attributes & FS_ATTRIBUTE_DOS_VOLUME ) { } else { diff --git a/build/tools/sctools/copy_dst/src/mynuc.c b/build/tools/sctools/copy_dst/src/mynuc.c index 2f432ac..07a22e8 100644 --- a/build/tools/sctools/copy_dst/src/mynuc.c +++ b/build/tools/sctools/copy_dst/src/mynuc.c @@ -11,9 +11,17 @@ #include "text.h" #include "mprintf.h" +#include "logprintf.h" +#include "my_fs_util.h" #define STRING_ANIM_CNT 20 + +static BOOL log_active = FALSE; +static FSFile *log_fd; +static FSFile log_fd_real; + + static volatile NetConnectState NetConnect = NET_CONNECT_NONE; // state管理 @@ -59,7 +67,10 @@ static void *alloc(u32 size, int align) (void)OS_RestoreInterrupts( old ); end: - SDK_ASSERT(((u32)ptr & (align - 1)) == 0); + // SDK_ASSERT(((u32)ptr & (align - 1)) == 0); + if( ((u32)ptr & (align - 1)) != 0 ) { + return NULL; + } return (void *) ptr; } @@ -73,6 +84,7 @@ static void free(void *p) Name: InitNupLib Description: NUCライブラリを開始します。 *---------------------------------------------------------------------------*/ + BOOL InitNupLib() { BOOL ret; @@ -88,8 +100,10 @@ BOOL InitNupLib() if (ret == FALSE) { // NUC_Init() failed, error code=34416 - OS_TPrintf("NUC_Init() failed, error code=%d\n", NUC_GetLastError()); - OS_TPrintf(" error type:%s\n", error_msg[ NUC_GetErrorType(NUC_GetLastError())] ); + miya_log_fprintf(log_fd, "NUC_Init() failed, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, " error type:%s\n", error_msg[ NUC_GetErrorType(NUC_GetLastError())] ); + mprintf("NUC_Init() failed, error code=%d\n", NUC_GetLastError()); + mprintf(" error type:%s\n", error_msg[ NUC_GetErrorType(NUC_GetLastError())] ); } return ret; } @@ -106,7 +120,8 @@ BOOL StartNupCheck(void) ret = NUC_CheckAsync(TitleIds, &TitleIdNum); if (ret == FALSE) { - OS_TPrintf("NUC_CheckAsync() failed, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, "NUC_CheckAsync() failed, error code=%d\n", NUC_GetLastError()); + mprintf("NUC_CheckAsync() failed, error code=%d\n", NUC_GetLastError()); } return ret; @@ -126,7 +141,7 @@ NucStatus ProgressNupCheck(void) if (status == NUC_STATUS_ERROR) { // NUC_GetProgress() failed in checking, error code=34303 - OS_TPrintf("NUC_GetProgress() failed in checking, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, "NUC_GetProgress() failed in checking, error code=%d\n", NUC_GetLastError()); mprintf("NUC_GetProgress() failed in checking\n error code=%d\n", NUC_GetLastError()); } if (TestState.count++ % STRING_ANIM_CNT == 0) @@ -154,7 +169,8 @@ BOOL StartNupDownload(void) if (ret == FALSE) { - OS_TPrintf("NUP_DownloadAsync() failed, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, "NUP_DownloadAsync() failed, error code=%d\n", NUC_GetLastError()); + mprintf("NUP_DownloadAsync() failed, error code=%d\n", NUC_GetLastError()); } return ret; @@ -173,7 +189,7 @@ NucStatus ProgressNupDownload(void) if (status == NUC_STATUS_ERROR) { // エラー発生 // NUC_GetProgress() failed in checking, error code=34303 - OS_TPrintf("NUC_GetProgress() failed in download, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, "NUC_GetProgress() failed in download, error code=%d\n", NUC_GetLastError()); mprintf("\nNUC_GetProgress() failed\n in download\n error code=%d\n", NUC_GetLastError()); } @@ -199,7 +215,8 @@ BOOL CleanNupLib(void) BOOL ret = NUC_Cleanup(TitleIds, TitleIdNum); if (ret == FALSE) { - OS_TPrintf("NUP_CleanUp() failed, error code=%d\n", NUC_GetLastError()); + miya_log_fprintf(log_fd, "NUP_CleanUp() failed, error code=%d\n", NUC_GetLastError()); + mprintf( "NUP_CleanUp() failed, error code=%d\n", NUC_GetLastError()); } return ret; } @@ -225,23 +242,20 @@ void ProgressNetConnect(void) void ShowErrorMsg(int error_code) { - - mprintf("Error Occurred "); - if (error_code > 0) { mprintf("Error Code:%d", error_code); - mprintf("%s", GetPublicMsg(error_code)); - mprintf("%s", GetPrivateMsg(error_code)); + mprintf(" %s\n", GetPublicMsg(error_code)); + mprintf(" %s\n", GetPrivateMsg(error_code)); - OS_TPrintf( "Error Code:%d\n", error_code); - OS_TPrintf( "%s\n", GetPublicMsg(error_code)); - OS_TPrintf( "%s\n", GetPrivateMsg(error_code)); + miya_log_fprintf(log_fd, "Error Code:%d\n", error_code); + miya_log_fprintf(log_fd, "%s\n", GetPublicMsg(error_code)); + miya_log_fprintf(log_fd, "%s\n", GetPrivateMsg(error_code)); } else { - OS_TPrintf( "%s\n", "Network Error occurred.\nTry again later."); + miya_log_fprintf(log_fd, "%s\n", "Network Error occurred.\nTry again later."); // ネットワークエラー時の表示メッセージ(暫定) - mprintf( "%s", "Network Error occurred.\nTry again later."); + mprintf( "%s", "Network Error occurred.\nTry again later.\n"); } } @@ -259,6 +273,7 @@ BOOL my_numc_proc(void) switch ( TestState.state ) { case PHASE_NUP_BREAK: mprintf("NUP Initialize\n"); + miya_log_fprintf(log_fd, "NUP Initialize\n"); ret = InitNupLib(); if (ret == FALSE) { // エラー発生 @@ -273,6 +288,7 @@ BOOL my_numc_proc(void) case PHASE_NUP_READY: // 更新情報の取得を開始します。 mprintf("NUP Check\n"); + miya_log_fprintf(log_fd, "NUP Check\n"); ret = StartNupCheck(); if (ret == FALSE) { // エラー発生 @@ -290,17 +306,19 @@ BOOL my_numc_proc(void) if (status == NUC_STATUS_ERROR) { // エラー発生 mprintf("\n"); + miya_log_fprintf(log_fd, "\n"); ChangeState(PHASE_NUP_CLEANUP); error_code = NUC_GetLastError(); } else if (status == NUC_STATUS_COMPLETED) { // 更新リスト 取得終了 mprintf("\n"); + miya_log_fprintf(log_fd, "\n"); if (TitleIdNum > 0 ) { // ダウンロードへ int i; for (i = 0; i < TitleIdNum; i++) { - OS_TPrintf("DL list:%3d:0x%llx\n", i, TitleIds[i]); + miya_log_fprintf(log_fd, "DL list:%3d:0x%llx\n", i, TitleIds[i]); mprintf("DL list:%3d:0x%llx\n", i, TitleIds[i]); } ChangeState(PHASE_NUP_DOWNLOAD); @@ -308,6 +326,7 @@ BOOL my_numc_proc(void) else { // 更新すべきものがない mprintf("No title to update\n"); + miya_log_fprintf(log_fd, "No title to update\n"); ChangeState(PHASE_NUP_CLEANUP); } } @@ -315,6 +334,7 @@ BOOL my_numc_proc(void) case PHASE_NUP_DOWNLOAD: // ダウンロードを開始します。 mprintf("NUP Download\n"); + miya_log_fprintf(log_fd, "NUP Download\n"); ret = StartNupDownload(); if (ret == FALSE) { // エラー発生 @@ -332,21 +352,22 @@ BOOL my_numc_proc(void) if (status == NUC_STATUS_ERROR) { // エラー発生 mprintf("\n"); + miya_log_fprintf(log_fd, "\n"); ChangeState(PHASE_NUP_CLEANUP); error_code = NUC_GetLastError(); } else if (status == NUC_STATUS_COMPLETED) { // ダウンロード完了 mprintf("\n"); + miya_log_fprintf(log_fd, "\n"); ChangeState(PHASE_NUP_CLEANUP); } break; case PHASE_NUP_CLEANUP: // NUPライブラリのクリーンアップ mprintf("NUP Cleanup\n"); + miya_log_fprintf(log_fd, "NUP Cleanup\n"); ret = CleanNupLib(); - OS_TPrintf("%s %d\n",__FUNCTION__,__LINE__); - if (ret == FALSE && error_code == 0) { // 他でエラーが起こっていない場合のみ上書きします。 error_code = NUC_GetLastError(); @@ -358,11 +379,11 @@ BOOL my_numc_proc(void) case PHASE_FINISHED: // ネットワークアップデートが正常終了しました。 if( error_code == 0 ) { if (TitleIdNum > 0) { - OS_TPrintf("%d file is updated\n", TitleIdNum); + miya_log_fprintf(log_fd, "%d file is updated\n", TitleIdNum); mprintf("%d file is updated\n", TitleIdNum); } else { - OS_TPrintf("Nothing is updated\n"); + miya_log_fprintf(log_fd, "Nothing is updated\n"); mprintf("Nothing is updated\n"); } } @@ -388,3 +409,21 @@ BOOL my_numc_proc(void) } +FSFile *my_nuc_log_start(char *log_file_name ) +{ + log_fd = &log_fd_real; + log_active = Log_File_Open( log_fd, log_file_name ); + if( !log_active ) { + log_fd = NULL; + } + miya_log_fprintf(log_fd, "%s START\n", __FUNCTION__); + return log_fd; +} + +void my_nuc_log_end(void) +{ + miya_log_fprintf(log_fd, "%s END\n\n", __FUNCTION__); + if( log_active ) { + Log_File_Close(log_fd); + } +} diff --git a/build/tools/sctools/copy_dst/src/mynuc.h b/build/tools/sctools/copy_dst/src/mynuc.h index e800940..abbecf6 100644 --- a/build/tools/sctools/copy_dst/src/mynuc.h +++ b/build/tools/sctools/copy_dst/src/mynuc.h @@ -47,6 +47,9 @@ BOOL CleanNupLib(void); void ProgressNetConnect(void); void ShowErrorMsg(int error_code); BOOL my_numc_proc(void); +FSFile *my_nuc_log_start(char *log_file_name ); +void my_nuc_log_end(void); + #ifdef __cplusplus } diff --git a/build/tools/sctools/copy_org/Makefile b/build/tools/sctools/copy_org/Makefile index 491ef49..f50a7a0 100644 --- a/build/tools/sctools/copy_org/Makefile +++ b/build/tools/sctools/copy_org/Makefile @@ -23,7 +23,7 @@ TWL_ARCHGEN := LIMITED SRCDIR = ../common/src ./src SRCS = main.c key.c font.c text.c mprintf.c logprintf.c \ - gfx.c hwi.c mynvram.c my_fs_util.c miya_mcu.c \ + gfx.c hwi.c mynvram.c my_fs_util.c miya_mcu.c error_report.c \ sitedefs.c wcm_control.c netconnect.c mywlan.c \ stream.c myfilename.c menu_version.c diff --git a/build/tools/sctools/copy_org/src/main.c b/build/tools/sctools/copy_org/src/main.c index cb25f51..a2efc2e 100644 --- a/build/tools/sctools/copy_org/src/main.c +++ b/build/tools/sctools/copy_org/src/main.c @@ -33,6 +33,7 @@ #include "mydata.h" #include "nuc.h" #include "miya_mcu.h" +#include "error_report.h" #include "myfilename.h" #include "menu_version.h" @@ -43,6 +44,7 @@ static BOOL completed_flag = FALSE; static FSEventHook sSDHook; static BOOL sd_card_flag = FALSE; +static int miya_debug_level = 0; static void SDEvents(void *userdata, FSEvent event, void *arg) @@ -130,11 +132,13 @@ static BOOL SDBackupToSDCard2(void) m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + mydata.wireless_lan_param_flag = TRUE; } else { m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + mydata.wireless_lan_param_flag = FALSE; return FALSE; } return TRUE; @@ -149,11 +153,13 @@ static BOOL SDBackupToSDCard3(void) m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + mydata.user_settings_flag = TRUE; } else { m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + mydata.user_settings_flag = FALSE; return FALSE; } return TRUE; @@ -163,66 +169,137 @@ static BOOL SDBackupToSDCard4(void) { MY_DIR_ENTRY_LIST *dir_entry_list_head = NULL; int save_dir_info = 0; + BOOL ret_flag = TRUE; + int list_count; + int error_count; /* nand:/shared2ディレクトリまわりの保存 内容はアプリケーション共有ファイル nand:/shared2/* */ + + Error_Report_Init(); + + mprintf("App. shared files backup "); if( 0 == copy_r( &dir_entry_list_head, MyFile_GetAppSharedSaveDirName() , "nand:/shared2" , MyFile_GetAppSharedLogFileName(), 0) ) { - // PrintDirEntryListBackward( dir_entry_list_head, NULL ); - mydata.num_of_shared2_files = SaveDirEntryList( dir_entry_list_head, MyFile_GetAppSharedListFileName() ); - m_set_palette(tc[0], 0x2); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], 0xF); /* white */ + if( TRUE == SaveDirEntryList( dir_entry_list_head, MyFile_GetAppSharedListFileName(), + &list_count, &error_count, MyFile_GetAppSharedSaveLogFileName()) ) { + mydata.num_of_shared2_files = list_count; + mydata.num_of_error_shared2_files = error_count; + + if( error_count == 0 ) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } + else { + ret_flag = FALSE; + } + } + else { + mydata.num_of_shared2_files = -1; /* failed */ + mydata.num_of_error_shared2_files = -1; + ret_flag = FALSE; + } } else { + mydata.num_of_shared2_files = -1; /* failed */ + mydata.num_of_error_shared2_files = -1; + ret_flag = FALSE; + } + + if( ret_flag == FALSE ) { m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; } + (void)ClearDirEntryList( &dir_entry_list_head ); - return TRUE; + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + + return ret_flag; } + static BOOL SDBackupToSDCard5(void) { MY_DIR_ENTRY_LIST *dir_entry_list_head = NULL; int save_dir_info = 0; + BOOL ret_flag = TRUE; + int list_count; + int error_count; + /* nand2:/photoディレクトリまわりの保存 内容は写真長のJPEGファイル nand2:/photo/*.* */ + Error_Report_Init(); + mprintf("Photo files backup "); if( 0 == copy_r( &dir_entry_list_head, MyFile_GetPhotoSaveDirName() , "nand2:/photo" , MyFile_GetPhotoLogFileName(),0 ) ) { // PrintDirEntryListBackward( dir_entry_list_head, NULL ); - mydata.num_of_photo_files = SaveDirEntryList( dir_entry_list_head, MyFile_GetPhotoListFileName() ); - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + if( TRUE == SaveDirEntryList( dir_entry_list_head, MyFile_GetPhotoListFileName(), + &list_count, &error_count, MyFile_GetPhotoSaveLogFileName() ) ) { + mydata.num_of_photo_files = list_count; + mydata.num_of_error_photo_files = error_count; + if( error_count > 0 ) { + ret_flag = FALSE; + } + } + else { + mydata.num_of_photo_files = -1; /* failed */ + mydata.num_of_error_photo_files = -1; /* failed */ + ret_flag = FALSE; + } } else { + mydata.num_of_photo_files = -1; /* failed */ + mydata.num_of_error_photo_files = -1; /* failed */ + ret_flag = FALSE; + } + + if( ret_flag == FALSE ) { m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; + } + else { + m_set_palette(tc[0], 0x2); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], 0xF); /* white */ + } (void)ClearDirEntryList( &dir_entry_list_head ); + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); - return TRUE; + + return ret_flag; } static BOOL SDBackupToSDCard6(void) { MY_DIR_ENTRY_LIST *dir_entry_list_head = NULL; int save_dir_info = 0; + BOOL ret_flag = TRUE; + + int list_count; + int error_count; + + + Error_Report_Init(); /* nand:/ticketはチケット同期?でうまいこと合わせてくれるんでバックアップ不要 */ @@ -232,10 +309,34 @@ static BOOL SDBackupToSDCard6(void) */ mprintf("App. save data backup "); - if( 0 == find_title_save_data( &dir_entry_list_head, MyFile_GetAppDataSaveDirName(), "nand:/title", - &save_dir_info, MyFile_GetAppDataLogFileName(),0 ) ) { + if( 0 == find_title_save_data( &dir_entry_list_head, MyFile_GetSaveDataSaveDirName(), "nand:/title", + &save_dir_info, MyFile_GetSaveDataLogFileName(),0 ) ) { // PrintDirEntryListBackward( dir_entry_list_head, NULL ); - mydata.num_of_app_save_data = SaveDirEntryList( dir_entry_list_head , MyFile_GetAppDataListFileName() ); + // mydata.num_of_app_save_data = SaveDirEntryList( dir_entry_list_head , + // mydata.num_of_app_save_data = + + + if( TRUE == SaveDirEntryList( dir_entry_list_head , MyFile_GetSaveDataListFileName(), + &list_count, &error_count, MyFile_GetSaveDataSaveLogFileName() ) ) { + mydata.num_of_app_save_data = list_count; + mydata.num_of_error_app_save_data = error_count; + if( error_count > 0 ) { + ret_flag = FALSE; + } + } + else { + mydata.num_of_app_save_data = -1; + mydata.num_of_error_app_save_data = -1; + ret_flag = FALSE; + } + } + else { + mydata.num_of_app_save_data = -1; + mydata.num_of_error_app_save_data = -1; + ret_flag = FALSE; + } + + if( ret_flag == TRUE ) { m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); @@ -244,12 +345,17 @@ static BOOL SDBackupToSDCard6(void) m_set_palette(tc[0], M_TEXT_COLOR_RED ); mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - return FALSE; } + (void)ClearDirEntryList( &dir_entry_list_head ); - return TRUE; + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + + return ret_flag; } static BOOL SDBackupToSDCard7(void) @@ -285,51 +391,58 @@ static BOOL SDBackupToSDCard7(void) | システムアプリはダウンロード対象外 */ + + Error_Report_Init(); + OS_TPrintf("User title list backup \n"); mprintf("User title list backup "); if( 0 == get_title_id( &dir_entry_list_head, "nand:/title", &save_dir_info, MyFile_GetDownloadTitleIDLogFileName(), 0 ) ) { - GetDirEntryList( dir_entry_list_head, &pBuffer, &count); + flag = GetUserAppTitleList( dir_entry_list_head, &pBuffer, &count, + MyFile_GetUserAppTitleListLogFileName()) ; - ptr = pBuffer; - mydata.num_of_user_download_app = count; - - if( ptr != NULL && count != 0 ) { - for( j = 0 ; j < count ; j++ ) { - OS_TPrintf("No. %d 0x%016llx\n",j,*ptr); - mfprintf(tc[2],"No. %d 0x%016llx\n",j,*ptr); - ptr++; + if( TRUE == flag ) { + ptr = pBuffer; + mydata.num_of_user_download_app = count; + mydata.num_of_error_user_download_app = 0; + + if( ptr != NULL && count != 0 ) { + for( j = 0 ; j < count ; j++ ) { + OS_TPrintf("No. %d 0x%016llx\n",j,*ptr); + mfprintf(tc[2],"No. %d 0x%016llx\n",j,*ptr); + ptr++; + } } - } - PrintSrcDirEntryListBackward( dir_entry_list_head, NULL ); - - if( TRUE == TitleIDSave( MyFile_GetDownloadTitleIDFileName(), pBuffer, count, NULL) ) { - //MyFile_GetDownloadTitleIDLogFileName() - m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ - mprintf("OK.\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - } - else { - m_set_palette(tc[0], M_TEXT_COLOR_RED ); - mprintf("NG.(save ids)\n"); - m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - flag = FALSE; - // return FALSE; + + // PrintSrcDirEntryListBackward( dir_entry_list_head, NULL ); + flag = TitleIDSave( MyFile_GetDownloadTitleIDFileName(), + pBuffer, count, MyFile_GetDownloadTitleIDSaveLogFileName()); } if( pBuffer ) { OS_Free(pBuffer); } } + + if( flag == TRUE ) { + m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ + mprintf("OK.\n"); + m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); + } else { m_set_palette(tc[0], 0x1); /* red */ - mprintf("NG.(get ids)\n"); + mprintf("NG.\n"); m_set_palette(tc[0], M_TEXT_COLOR_WHITE ); - flag = FALSE; - // return FALSE; + mydata.num_of_user_download_app = -1; /* failed */ + mydata.num_of_error_user_download_app = -1; } (void)ClearDirEntryList( &dir_entry_list_head ); + if( TRUE == Error_Report_Display(tc[0]) ) { + mprintf("\n"); + } + Error_Report_End(); + return flag; } @@ -338,7 +451,6 @@ static BOOL SDBackupToSDCard8(void) RTCDate rtc_date; RTCTime rtc_time; - /* オリジナルのデータのバックアップ */ if( RTC_RESULT_SUCCESS != RTC_GetDate( &rtc_date ) ) { mprintf("rtc read date error.\n"); @@ -361,6 +473,7 @@ static BOOL SDBackupToSDCard8(void) LCFG_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN ); mprintf("Personal data backup "); + /* こいつはフラグを立てられない、セーブできない。あたりまえ */ if( TRUE == MydataSaveEncrypt( MyFile_GetGlobalInformationFileName(), (void *)&mydata, sizeof(MyData), NULL) ) { m_set_palette(tc[0], M_TEXT_COLOR_GREEN ); /* green */ mprintf("OK.\n"); @@ -659,12 +772,14 @@ void TwlMain(void) mydata.volume = (s32)MCU_GetVolume(); mydata.backlight_brightness = (s32)MCU_GetBackLightBrightness(); + +#if 0 /* いらないらしい */ OS_TPrintf("vol = %d\n",mydata.volume ); OS_TPrintf("bright = %d\n", mydata.backlight_brightness); MCU_SetVolume( (u8)31 ); MCU_SetBackLightBrightness( (u8)4 ); - +#endif // static inline BOOL MCU_SetVolume( u8 volume ) // static inline BOOL MCU_SetBackLightBrightness( u8 brightness ) @@ -740,7 +855,7 @@ void TwlMain(void) } #endif } - else if ( keyData & PAD_BUTTON_A ) { + else if ( keyData & (PAD_BUTTON_A | PAD_BUTTON_START) ) { /* ユーザーデータ吸出しモード */ if(completed_flag == FALSE ) { if( sd_card_flag == TRUE ) { @@ -757,9 +872,22 @@ void TwlMain(void) } } else if ( keyData & PAD_BUTTON_B ) { + miya_debug_level++; + miya_debug_level &= 1; + if( miya_debug_level ) { + Miya_debug_ON(); + mprintf("debug ON\n"); + } + else { + Miya_debug_OFF(); + mprintf("debug OFF\n"); + } } +#if 0 + /* スタートボタンはAボタンと同じ扱い */ else if ( keyData & PAD_BUTTON_START ) { } +#endif else if ( keyData & PAD_BUTTON_SELECT ) { } else if ( keyData & PAD_BUTTON_X ) { diff --git a/build/tools/sctools/my_armadillo.TWL/src/main.c b/build/tools/sctools/my_armadillo.TWL/src/main.c index 33ad945..0784d07 100644 --- a/build/tools/sctools/my_armadillo.TWL/src/main.c +++ b/build/tools/sctools/my_armadillo.TWL/src/main.c @@ -81,10 +81,13 @@ static s32 CheckCorrectNCD(NVRAMConfig* ncdsp); static void VBlankIntr(void); + #define MIYA_MCU_FREE_REG_NO 1 + +#if 0 #define MIYA_MCU_FREE_REG_CODE 0x55 static u8 miya_mcu_free_register = 0x66; - +#endif static void miya_mcu_free_reg_send_pxi_data(u32 data) { @@ -98,6 +101,7 @@ static void miya_mcu_free_reg_send_pxi_data(u32 data) #define MIYA_MCU_COMMAND_GET_BRIGHTNESS 3 #define MIYA_MCU_COMMAND_SET_VOLUME 4 #define MIYA_MCU_COMMAND_SET_BRIGHTNESS 5 +#define MIYA_MCU_COMMAND_SET_FREE_REG 6 static void miya_mcu_free_reg_pxi_callback(PXIFifoTag tag, u32 data, BOOL err) { @@ -106,8 +110,12 @@ static void miya_mcu_free_reg_pxi_callback(PXIFifoTag tag, u32 data, BOOL err) switch( (data & 0xf) ) { case MIYA_MCU_COMMAND_GET_FREE_REG: - miya_mcu_free_reg_send_pxi_data( (u32)miya_mcu_free_register ); + miya_mcu_free_reg_send_pxi_data((u32)MCU_GetFreeRegister((u8)MIYA_MCU_FREE_REG_NO )); break; + case MIYA_MCU_COMMAND_SET_FREE_REG: + miya_mcu_free_reg_send_pxi_data( (u32)MCU_SetFreeRegister((u8)MIYA_MCU_FREE_REG_NO , (u8)((data >> 4) & 0xff)) ); + break; + case MIYA_MCU_COMMAND_GET_VOLUME: miya_mcu_free_reg_send_pxi_data( (u32)MCU_GetVolume() ); break; @@ -117,15 +125,15 @@ static void miya_mcu_free_reg_pxi_callback(PXIFifoTag tag, u32 data, BOOL err) break; case MIYA_MCU_COMMAND_SET_VOLUME: - miya_mcu_free_reg_send_pxi_data( (u32)MCU_SetVolume( (u8)((data >> 4) & 0xf)) ); + miya_mcu_free_reg_send_pxi_data( (u32)MCU_SetVolume( (u8)((data >> 4) & 0xff)) ); break; case MIYA_MCU_COMMAND_SET_BRIGHTNESS: - miya_mcu_free_reg_send_pxi_data( (u32)MCU_SetBackLightBrightness( (u8)((data >> 4) & 0xf) )); + miya_mcu_free_reg_send_pxi_data( (u32)MCU_SetBackLightBrightness( (u8)((data >> 4) & 0xff) )); break; - + default: - miya_mcu_free_reg_send_pxi_data( (u32)miya_mcu_free_register ); + miya_mcu_free_reg_send_pxi_data( (u32)0xffffffff ); break; } @@ -183,10 +191,6 @@ TwlSpMain(void) SPI_Init(THREAD_PRIO_SPI); - miya_mcu_free_register = MCU_GetFreeRegister( (u8)MIYA_MCU_FREE_REG_NO ); - - (void)MCU_SetFreeRegister( (u8)MIYA_MCU_FREE_REG_NO , (u8)MIYA_MCU_FREE_REG_CODE ); - PXI_SetFifoRecvCallback(PXI_FIFO_TAG_USER_0, miya_mcu_free_reg_pxi_callback);