From ee629a8448d67a7eec22dd33682779ebd8017852 Mon Sep 17 00:00:00 2001 From: kamikawa Date: Fri, 8 Feb 2008 08:54:20 +0000 Subject: [PATCH] =?UTF-8?q?NAMUT=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9?= =?UTF-8?q?=E3=83=AA=E3=82=92=E6=96=B0=E8=A6=8F=E8=BF=BD=E5=8A=A0=E3=80=82?= =?UTF-8?q?=20NAM=20Utility=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA?= =?UTF-8?q?=E3=81=AE=E7=95=A5=E3=81=A7=E3=80=81NAND=E3=81=AE=E6=93=AC?= =?UTF-8?q?=E4=BC=BC=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=A1=8C=E3=81=86=E3=80=82=E5=B0=86=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E3=81=AB=E3=81=AFNAM=E3=81=AB=E5=90=B8=E5=8F=8E=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=82=82=E8=89=AF=E3=81=84=E3=81=A8=E6=80=9D=E3=82=8F?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@625 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/libraries_sysmenu/Makefile | 2 +- build/libraries_sysmenu/namut/ARM9/Makefile | 54 ++ .../libraries_sysmenu/namut/ARM9/src/namut.c | 579 ++++++++++++++++++ build/libraries_sysmenu/namut/Makefile | 31 + include/sysmenu/namut.h | 35 ++ 5 files changed, 700 insertions(+), 1 deletion(-) create mode 100644 build/libraries_sysmenu/namut/ARM9/Makefile create mode 100644 build/libraries_sysmenu/namut/ARM9/src/namut.c create mode 100644 build/libraries_sysmenu/namut/Makefile create mode 100644 include/sysmenu/namut.h diff --git a/build/libraries_sysmenu/Makefile b/build/libraries_sysmenu/Makefile index ecf09b6d..c2fee359 100644 --- a/build/libraries_sysmenu/Makefile +++ b/build/libraries_sysmenu/Makefile @@ -22,7 +22,7 @@ include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS_P = reloc_info sysmenu mb_loader acsign boot hotsw +SUBDIRS_P = reloc_info sysmenu mb_loader acsign boot hotsw namut #---------------------------------------------------------------------------- diff --git a/build/libraries_sysmenu/namut/ARM9/Makefile b/build/libraries_sysmenu/namut/ARM9/Makefile new file mode 100644 index 00000000..e643798a --- /dev/null +++ b/build/libraries_sysmenu/namut/ARM9/Makefile @@ -0,0 +1,54 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlIPL - NAMUT +# File: Makefile +# +# Copyright 2008 Nintendo. All rights reserved. +# +# These coded instructions, statements, and computer programs contain +# proprietary information of Nintendo of America Inc. and/or Nintendo +# Company Ltd., and are protected by Federal copyright law. They may +# not be disclosed to third parties or copied or duplicated in any form, +# in whole or in part, without the prior written consent of Nintendo. +# +# $Date:: $ +# $Rev:$ +# $Author:$ +#---------------------------------------------------------------------------- +#---------------------------------------------------------------------------- + +SUBDIRS = + +#---------------------------------------------------------------------------- +TARGET_FIRM = SYSTEMMENU +TARGET_PLATFORM = TWL +TWL_ARCHGEN = LIMITED +TWL_PROC = ARM9 + +INCDIR = include + +SRCS = namut.c + +TARGET_LIB = libnamut$(TWL_LIBSUFFIX).a + + +include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs + +INSTALL_TARGETS = $(TARGETS) +INSTALL_DIR = $(SYSMENU_INSTALL_LIBDIR) + +CCFLAGS += -DSMALL_CODE_SIZE \ + -DSTANDALONE \ + -DOPT_32_BIT \ + -DNO_SPLIT \ + -DNO_FP_API \ + -DNO_R_DIAG \ + -DNO_STDIO_H \ + -DNO_STDLIB_H + +do-build: $(TARGETS) + +include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/build/libraries_sysmenu/namut/ARM9/src/namut.c b/build/libraries_sysmenu/namut/ARM9/src/namut.c new file mode 100644 index 00000000..503874b0 --- /dev/null +++ b/build/libraries_sysmenu/namut/ARM9/src/namut.c @@ -0,0 +1,579 @@ +/*---------------------------------------------------------------------------* + Project: TwlIPL - NAMUT + File: namut.c + + Copyright 2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev:$ + $Author:$ + *---------------------------------------------------------------------------*/ + +// Nand Application Management UTility ライブラリ、略してNAMUTライブラリです。 +// レイヤー的にはNAMと重なりますのでNAMに吸収しても良いと思います。 + +#include +#include +#include +#include +#include + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +// クリーンアップ実行時に +// 指定ディレクトリ以下は全て消去されます。 +// 指定ディレクトリ自体は残ります +static const char* sDeleteDirectoryList[] = +{ + "nand:/tmp" +}; + +// クリーンアップ実行時に +// 指定ファイルは0xffでFillされます。 +static const char* sFillFileList[] = +{ + "nand:/shared1/TWLCFG0.dat", + "nand:/shared1/TWLCFG1.dat" +}; + +// クリーンアップで消去しないタイトルを +// TitleProperty (TitleID Hiの下位16bit)のビットで指定します。 +// どれか1つでもビットが立っていれば消去の対象から外します。 +#define PROTECT_TITLE_PROPERTY (TITLE_ID_HI_APP_TYPE_MASK) + +#define DIRECTORY_DEPTH_MAX 16 // ディレクトリの深さの最大(NANDの正規構成としては最大6) +#define TITLE_PATH "nand:/title" +#define TICKET_PATH "nand:/ticket" +#define IMPORT_PATH "nand:/import" +#define TITLE_ID_HI_SIZE 8 +#define TITLE_LIST_MAX 256 +#define CLEAR_DATA_SIZE 256 + +static const u8 sClearData[CLEAR_DATA_SIZE] = +{ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; + +/*---------------------------------------------------------------------------* + 内部変数定義 + *---------------------------------------------------------------------------*/ + +static FSDirectoryEntryInfo sEntryInfo; +static NAMTitleId sTitleIdArray[TITLE_LIST_MAX]; + +/*---------------------------------------------------------------------------* + 内部関数宣言 + *---------------------------------------------------------------------------*/ + +static BOOL NAMUTi_DeleteNonprotectedTitle(void); +static BOOL NAMUTi_DeleteNonprotectedTitleEntity(const char* path); +static BOOL NAMUTi_ClearSavedataAll(BOOL fill); +static BOOL NAMUTi_ClearSavedata(const char* path, BOOL fill); +static BOOL NAMUTi_DeleteNandDirectory(const char *path); +static BOOL NAMUTi_FillFile(const char* path); +static void NAMUTi_DrawNandTree(s32 depth, const char *path); +static void PrintDirectory(s32 depth, const char* path); +static void PrintFile(s32 depth, const char* path); + +/*---------------------------------------------------------------------------* + Name: NAMUT_Format + + Description: NANDのクリーンアップ + (システム系の必要なファイルのみを残し他を消去します) + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +BOOL NAMUT_Format(void) +{ + int i; + BOOL ret = TRUE; + + // プロテクトされていないタイトルの削除を行います + ret &= NAMUTi_DeleteNonprotectedTitle(); + + // プロテクトタイトルのセーブデータをフォーマットします + ret &= NAMUTi_ClearSavedataAll(TRUE); + + // 指定ファイルを0xffでクリアします + for (i=0; i 0) + { + ret &= NAMUTi_ClearSavedata(savePublicPath, fill); + } + // privateSaveSizeが0以上なら0xFFクリア&フォーマット + if (namTitleInfo.privateSaveSize > 0) + { + ret &= NAMUTi_ClearSavedata(savePrivatePath, fill); + } + } + else { ret = FALSE; } + } + else { ret = FALSE; } + } + + return ret; +} + +/*---------------------------------------------------------------------------* + Name: NAMUTi_ClearSavedata + + Description: 指定したセーブデータファイルに対して + FFクリア&フォーマットを行います。 + + Arguments: fill : FFクリアを行うならTRUEを指定します + + Returns: None + *---------------------------------------------------------------------------*/ +static BOOL NAMUTi_ClearSavedata(const char* path, BOOL fill) +{ + char drive[2] = { 'Z', '\0' }; + FSFile file; + BOOL ret = FALSE; + + // ファイル構造体初期化 + FS_InitFile(&file); + + // セーブファイルオープン + if (!FS_OpenFileEx(&file, path, (FS_FILEMODE_R|FS_FILEMODE_W))) + { + return FALSE; + } + + // セーブファイルを0xFFでクリア + if (fill) + { + u32 filesize = FS_GetFileLength(&file); + for (; filesize > CLEAR_DATA_SIZE; filesize -= CLEAR_DATA_SIZE) + { + FS_WriteFile(&file, sClearData, CLEAR_DATA_SIZE); + } + FS_WriteFile(&file, sClearData, (s32)filesize); + } + + // セーブファイルに対してマウント + for (drive[0]='Z'; drive[0]>='A'; drive[0]--) + { + if (FATFS_MountDrive(drive, FATFS_MEDIA_TYPE_SUBNAND, (FATFSFileHandle)file.userdata)) + { + break; + } + } + + // マウント成功ならフォーマットする + if (drive[0] >= 'A') + { + char drive_colon[3]; + drive_colon[0] = drive[0]; + drive_colon[1] = ':'; + drive_colon[2] = '\0'; + + // メディアフォーマット + if (FATFSi_FormatMedia(drive_colon)) + { + // ドライブフォーマット + if (FATFS_FormatDrive(drive_colon)) + { + ret = TRUE; + } + } + + // アンマウント + FATFS_UnmountDrive(drive); + } + + // ファイルクローズ + FS_CloseFile(&file); + + return ret; +} + +/*---------------------------------------------------------------------------* + Name: NAMUTi_FillFile + + Description: 指定したファイルを0xFFで埋めます。 + + Arguments: path + + Returns: None + *---------------------------------------------------------------------------*/ +static BOOL NAMUTi_FillFile(const char* path) +{ + FSFile file; + + // ファイル構造体初期化 + FS_InitFile(&file); + + // ファイルオープン + if (FS_OpenFileEx(&file, path, (FS_FILEMODE_R|FS_FILEMODE_W))) + { + // ファイルを0xFFでクリア + u32 filesize = FS_GetFileLength(&file); + for (; filesize > CLEAR_DATA_SIZE; filesize -= CLEAR_DATA_SIZE) + { + FS_WriteFile(&file, sClearData, CLEAR_DATA_SIZE); + } + FS_WriteFile(&file, sClearData, (s32)filesize); + FS_CloseFile(&file); + } + else + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NAMUT_DrawNandTree + + Description: NANDのツリー情報をプリント出力します + + Arguments: ... + + Returns: None. + *---------------------------------------------------------------------------*/ + +void NAMUT_DrawNandTree(void) +{ + NAMUTi_DrawNandTree(0, "nand:/"); +} + +/*---------------------------------------------------------------------------* + Name: NAMUTi_DrawNandTree + + Description: 指定パスのツリー情報をプリント出力します(再帰関数) + + Arguments: ... + + Returns: None. + *---------------------------------------------------------------------------*/ + +static void NAMUTi_DrawNandTree(s32 depth, const char *path) +{ + FSFile dir; + + PrintDirectory(depth, path); + + // 深さ制限 + if (depth > DIRECTORY_DEPTH_MAX) + { + OS_TPrintf("Fail! Depth is too deep.\n"); + return; + } + + FS_InitFile(&dir); + + // 引数で指定されたディレクトリを開く + if (!FS_OpenDirectory(&dir, path, (FS_FILEMODE_R|FS_FILEMODE_W))) + { + OS_TPrintf("%d Fail! FS_OpenDirectory(%s)\n", __LINE__, path); + return; + } + + // カレントディレクトリを設定する + if (!FS_SetCurrentDirectory(path)) + { + OS_TPrintf("Fail! FS_SetCurrentDirectory(%s)\n", path); + FS_CloseDirectory(&dir); + return; + } + + // ディレクトリの中身を読む + while (FS_ReadDirectory(&dir, &sEntryInfo)) + { + if (STD_CompareString(sEntryInfo.longname, ".") == 0 || + STD_CompareString(sEntryInfo.longname, "..") == 0) + { + continue; + } + + // ディレクトリであれば再帰呼び出し + if (!(sEntryInfo.attributes & FS_ATTRIBUTE_IS_DIRECTORY)) + { +// PrintFile(depth, sEntryInfo.longname); + } + else + { + NAMUTi_DrawNandTree(depth + 1, sEntryInfo.longname); + } + } + + // カレントディレクトリを元に戻します + if (!FS_SetCurrentDirectory("..")) + { + OS_TPrintf("Fail! FS_SetCurrentDirectory(..)\n"); + } + + FS_CloseDirectory(&dir); +} + +/*---------------------------------------------------------------------------* + Name: PrintDirectory + + Description: ツリー情報をプリント出力します(ディレクトリ用) + + Arguments: ... + + Returns: None. + *---------------------------------------------------------------------------*/ +static void PrintDirectory(s32 depth, const char* path) +{ + int i; + + for (i=0; i