ホワイトリストをromアーカイブからNANDアプリ形式に変更

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1162 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-04-16 09:12:23 +00:00
parent 85fa19095e
commit e0ba8d3d76
8 changed files with 190 additions and 46 deletions

View File

@ -18,7 +18,6 @@
#include <twl.h>
#include <sysmenu/dht/dht.h>
#define HASH_PATH "/sign/DSHashTable.bin"
/*
@ -110,7 +109,7 @@ u32 DHT_GetDatabaseLength(const DHTFile* pDHT)
{
if ( pDHT->header.magic_code != DHT_MAGIC_CODE ) // magic codeチェック
{
OS_TPrintf("Invalid " HASH_PATH " magic code (magic=0x%08X).\n", pDHT->header.magic_code);
OS_TPrintf("Invalid magic code (magic=0x%08X).\n", pDHT->header.magic_code);
return 0;
}
return sizeof(DHTHeader) + pDHT->header.nums * sizeof(DHTDatabase);
@ -140,47 +139,68 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT)
return TRUE;
}
BOOL DHT_PrepareDatabase(DHTFile* pDHT)
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath)
{
FSFile file;
u32 length;
s32 result;
s32 length;
u8 title[4] = { 'H','N','G','A' };
PROFILE_INIT();
// ファイルオープン
PROFILE_COUNT();
if (!FS_OpenFileEx(&file, HASH_PATH, FS_FILEMODE_R))
if ( filepath )
{
OS_TPrintf("Cannot open " HASH_PATH ".\n");
return FALSE;
// ファイルオープン
PROFILE_COUNT();
if (!FS_OpenFileEx(&file, filepath, FS_FILEMODE_R))
{
OS_TPrintf("Cannot open %s.\n", filepath);
return FALSE;
}
// ヘッダ読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
if ( result != sizeof(DHTHeader) )
{
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
return FALSE;
}
// magic_codeが HNGA のときはROM_Header分だけシークし直す
if ( pDHT->header.magic_code == *(u32*)title )
{
if ( !FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) )
{
OS_TPrintf("Cannot seek to the header of %s.\n", filepath);
return FALSE;
}
// 再びヘッダ読み込み
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
if ( result != sizeof(DHTHeader) )
{
OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result);
return FALSE;
}
}
// サイズチェック
PROFILE_COUNT();
length = (s32)DHT_GetDatabaseLength(pDHT);
if ( FS_GetFileLength(&file) < length ) // パディングがあり得る
{
OS_TPrintf("Invalid %s size (%d < %d).\n", filepath, FS_GetFileLength(&file), length);
return FALSE;
}
// ヘッダ分を削除
length -= sizeof(DHTHeader);
// データベース読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, pDHT->database, length);
if ( result != length )
{
OS_TPrintf("Cannot read the database of %s (result=%d).\n", filepath, result);
return FALSE;
}
FS_CloseFile(&file);
}
// ヘッダ読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader));
if ( result != sizeof(DHTHeader) )
{
OS_TPrintf("Cannot read the header of " HASH_PATH " (result=%d).\n", result);
return FALSE;
}
// サイズチェック
PROFILE_COUNT();
length = FS_GetFileLength(&file);
if ( length != DHT_GetDatabaseLength(pDHT) )
{
OS_TPrintf("Invalid " HASH_PATH " size (%d != %d).\n", length, DHT_GetDatabaseLength(pDHT));
return FALSE;
}
// databaseサイズの保存
length -= sizeof(DHTHeader);
// データベース読み込み
PROFILE_COUNT();
result = FS_ReadFile(&file, pDHT->database, (s32)length);
if ( result != length )
{
OS_TPrintf("Cannot read the database of " HASH_PATH " (result=%d).\n", result);
return FALSE;
}
FS_CloseFile(&file);
// データベースの検証
PROFILE_COUNT();
@ -199,6 +219,7 @@ BOOL DHT_PrepareDatabase(DHTFile* pDHT)
#endif
return result;
}
/*
ROMヘッダに対応するデータベースを手に入れる
*/

View File

@ -102,10 +102,65 @@ void SYSM_InitPXI( u32 mcu_prio )
#ifdef DHT_TEST
#ifdef SDK_ARM9
static BOOL GetDatabaseFilepath(char *path)
{
u8 title[4] = { 'H','N','G','A' };
#if( USE_LCFG_STRING == 0 )
char *title0 = "HNGA";
#endif
u32 titleID_hi;
u32 titleID_lo;
u64 titleID = 0;
#if( USE_LCFG_STRING == 0 )
{
int i;
if( title[0] == 0 ) {
for( i = 0 ; i < 4 ; i++ ) {
title[i] = (u8)*title0++;
}
}
}
#endif
titleID_hi = (( 3 /* Nintendo */ << 16) | 8 /* CHANNEL_DATA_ONLY */ | 4 /* CHANNEL_CARD */ | 2 /* isLaunch */ | 1 /* isSystem */);
titleID_lo = ((u32)( title[0] ) & 0xff) << 24;
titleID_lo |= ((u32)( title[1] )& 0xff) << 16;
titleID_lo |= ((u32)( title[2] )& 0xff) << 8;
titleID_lo |= (u32)( title[3] ) & 0xff;
titleID = ((u64)(titleID_hi) << 32) | (u64)titleID_lo;
// OS_TPrintf( "[DHT] titleID = 0x%08x%08x\n", titleID_hi, titleID_lo);
if( NAM_OK == NAM_GetTitleBootContentPathFast(path, titleID) ) {
OS_TPrintf( "[DHT] File = %s\n", path);
}
else {
OS_TPrintf( "[DHT] Error: NAM_GetTitleBootContentPathFast titleID = 0x%08x0x%08x\n",titleID_hi, titleID_lo);
return FALSE;
}
return TRUE;
}
void SYSMi_PrepareDatabase(void)
{
DHT_PrepareDatabase(dht);
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
char path[256];
if ( GetDatabaseFilepath( path ) )
{
DHT_PrepareDatabase(dht, path);
DC_FlushRange(dht, DHT_GetDatabaseLength(dht));
}
else
{
MI_CpuClear8(dht, sizeof(DHTHeader));
}
OS_TPrintf("[ARM9] dht address: %08X\n", dht);
SYSMi_SendPXICommand( SYSM_PXI_COMM_DS_HASH_TABLE, (u16)(((u32)dht - 0x2000000) >> 8) );
}

View File

@ -0,0 +1,68 @@
#! make -f
#----------------------------------------------------------------------------
# Project: TwlIPL
# File: Makefile -
#
# Copyright 2007 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:
#----------------------------------------------------------------------------
TARGET_FIRM = SYSTEMMENU
override TARGET_PLATFORM := TWL
override TARGET_CODEGEN := ARM
override TWL_ARCHGEN := LIMITED
# workaround for small srl probrem
WORKAROUND_SMALL_SRL = TRUE
include $(TWL_IPL_RED_ROOT)/build/buildtools/commondefs
MY_TITLE = HNHA
DS_HASH_TABLE = DSHashTable.bin
# workaround for small srl probrem
ifneq ($(WORKAROUND_SMALL_SRL),)
DS_HASH_TABLE2 = DSHashTable2.bin
endif
#----------------------------------------------------------------------------
MY_SRL = $(MY_TITLE).srl
MY_TAD = $(MY_TITLE).tad
ATTACH_HEADER_COMMAND = $(SYSMENU_TOOLSDIR)/bin/attach_dummyromheader.exe
INSTALL_TARGETS = $(MY_TAD)
INSTALL_DIR = $(ROOT)/build/tools/TwlNMenu/data
LDIRT_CLEAN = $(MY_SRL) $(MY_TAD)
#----------------------------------------------------------------------------
include $(TWL_IPL_RED_ROOT)/build/buildtools/modulerules
do-build : $(MY_TAD)
ifneq ($(WORKAROUND_SMALL_SRL),)
$(DS_HASH_TABLE2): $(DS_HASH_TABLE)
cat $< $< > $@
$(MY_SRL): $(DS_HASH_TABLE2)
$(ATTACH_HEADER_COMMAND) -s -l -i $(call empath,$<) -c $(MY_TITLE) -o $@
else
$(MY_SRL): $(DS_HASH_TABLE)
$(ATTACH_HEADER_COMMAND) -s -l -i $(call empath,$<) -c $(MY_TITLE) -o $@
endif
$(MY_TAD): $(MY_SRL)
$(MAKETAD) -s $< $(MAKETAD_FLAGS) -o $@
#===== End of Makefile =====

View File

@ -213,6 +213,4 @@ RomSpec
HostRoot ../../data
Root /data
File NTR_IPL_font_m.NFTR NoCardBanner.bnr EmptyBanner.bnr NoBanner.bnr fanfare.32.wav
Root /sign
File $(DS_HASH_TABLE_FILE)
}
}

View File

@ -234,7 +234,7 @@ RomSpec
{
Offset 0x00000000
Segment ALL
HostRoot ../../systemMenu_RED/data
HostRoot ../../systemMenu_RED/DSHashTable
Root /sign
File DSHashTable.bin
HostRoot $(MAKEROM_SRL_ROOT)

View File

@ -18,6 +18,8 @@
#include <twl.h>
#include <sysmenu/dht/dht.h>
#define HASH_PATH "/sign/DSHashTable.bin"
/*
CARD関数の代わりにFS関数で
DHTライブラリが実装されている前提である
@ -183,7 +185,7 @@ void TwlMain(void)
FS_Init(FS_DMA_NOT_USE);
// 署名ロード
if ( !DHT_PrepareDatabase(dht) )
if ( !DHT_PrepareDatabase(dht, HASH_PATH) )
{
OS_TPanic("Cannot prepare the database.\n");
}

View File

@ -62,14 +62,14 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT);
/*---------------------------------------------------------------------------*
Name: DHT_PrepareDatabase
Description: FS関数を利用して全データベースを読み込み検証まで行う
/sign/DSHashTable.bin固定
Description: FS関数を利用して全データベースを読み込みと検証を行う
Arguments: pDHT
filepath (NULLで格納済みと判定())
Returns: TRUE
*---------------------------------------------------------------------------*/
BOOL DHT_PrepareDatabase(DHTFile* pDHT);
BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath);
/*---------------------------------------------------------------------------*
Name: DHT_GetDatabase