内部static領域をworkに含めた (合計513KB必要)

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1160 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-04-16 07:10:16 +00:00
parent ce82cbc906
commit 53786510bb
4 changed files with 62 additions and 43 deletions

View File

@ -52,9 +52,10 @@ static const u8 g_pubkey_DER[ 0xa2 ] = {
static const u8 hmac_key[] = DHT_HMAC_KEY; static const u8 hmac_key[] = DHT_HMAC_KEY;
static DHTReadFunc ReadFunc; static DHTReadFunc ReadFunc;
static void* readArg; static void* readArg;
#define PAGE_SIZE 512 static DHTPhase2Work* p2work;
static int fatPage;
/* /*
bsearch bsearch
@ -303,42 +304,48 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
FSを用いたテストの場合とCARDアプリの場合で異なる FSを用いたテストの場合とCARDアプリの場合で異なる
*/ */
static BOOL ImageHMACSHA1Update(SVCHMACSHA1Context* ctx, s32 offset, s32 length, void* buffer) static BOOL ImageHMACSHA1Update(SVCHMACSHA1Context* ctx, s32 offset, s32 length)
{ {
if ( !ReadFunc(buffer, offset, length, readArg) ) if ( !p2work )
{ {
return FALSE; return FALSE;
} }
SVC_HMACSHA1Update(ctx, buffer, (u32)length); if ( !ReadFunc(p2work->buffer, offset, length, readArg) )
{
return FALSE;
}
SVC_HMACSHA1Update(ctx, p2work->buffer, (u32)length);
return TRUE; return TRUE;
} }
static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength) static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
{ {
ROM_FAT *fat; ROM_FAT *fat;
static u8 fat_cache[PAGE_SIZE*2]; int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / DHT_FAT_PAGE_SIZE;
static int last_page = 0; if ( !p2work )
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / PAGE_SIZE;
if ( last_page != page )
{ {
if ( last_page + 1 == page ) // 1ページはキャッシュ済み return FALSE;
}
if ( fatPage != page )
{
if ( fatPage + 1 == page ) // 1ページはキャッシュ済み
{ {
MI_CpuCopy8( &fat_cache[PAGE_SIZE], &fat_cache[0], PAGE_SIZE ); MI_CpuCopy8( &p2work->fatCache[DHT_FAT_PAGE_SIZE], &p2work->fatCache[0], DHT_FAT_PAGE_SIZE );
if ( !ReadFunc(&fat_cache[PAGE_SIZE], (page+1) * PAGE_SIZE, PAGE_SIZE, readArg) ) if ( !ReadFunc(&p2work->fatCache[DHT_FAT_PAGE_SIZE], (page+1) * DHT_FAT_PAGE_SIZE, DHT_FAT_PAGE_SIZE, readArg) )
{ {
return FALSE; return FALSE;
} }
} }
else // 通常は2ページ読み else // 通常は2ページ読み
{ {
if ( !ReadFunc(fat_cache, page * PAGE_SIZE, PAGE_SIZE*2, readArg) ) if ( !ReadFunc(p2work->fatCache, page * DHT_FAT_PAGE_SIZE, DHT_FAT_CACHE_SIZE, readArg) )
{ {
return FALSE; return FALSE;
} }
} }
last_page = page; fatPage = page;
} }
fat = (ROM_FAT*)(fat_cache + fat_offset + no * sizeof(ROM_FAT) - page * PAGE_SIZE); fat = (ROM_FAT*)(p2work->fatCache + fat_offset + no * sizeof(ROM_FAT) - page * DHT_FAT_PAGE_SIZE);
if ( pOffset ) if ( pOffset )
{ {
*pOffset = (s32)fat->top.offset; *pOffset = (s32)fat->top.offset;
@ -350,7 +357,7 @@ static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
return TRUE; return TRUE;
} }
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg) BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, DHTPhase2Work* work, DHTReadFunc func, void* arg)
{ {
int overlay_nums = (int)(pROMHeader->main_ovt_size / sizeof(ROM_OVT)); int overlay_nums = (int)(pROMHeader->main_ovt_size / sizeof(ROM_OVT));
u8 md[20]; u8 md[20];
@ -362,26 +369,28 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
int total_sectors; int total_sectors;
int i; int i;
if ( !func ) if ( !func || !work )
{ {
return FALSE; return FALSE;
} }
ReadFunc = func; ReadFunc = func;
readArg = arg; readArg = arg;
p2work = work;
fatPage = -2; // default value = out of range
// 準備 // 準備
PROFILE_COUNT(); PROFILE_COUNT();
SVC_HMACSHA1Init(&ctx, hmac_key, sizeof(hmac_key)); SVC_HMACSHA1Init(&ctx, hmac_key, sizeof(hmac_key));
// OVT // OVT
PROFILE_COUNT(); PROFILE_COUNT();
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->main_ovt_offset, (s32)pROMHeader->main_ovt_size, buffer) ) if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->main_ovt_offset, (s32)pROMHeader->main_ovt_size) )
{ {
OS_TPrintf("Cannot calc HMAC-SHA1 for OVT.\n"); OS_TPrintf("Cannot calc HMAC-SHA1 for OVT.\n");
return FALSE; return FALSE;
} }
// FAT // FAT
PROFILE_COUNT(); PROFILE_COUNT();
if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->fat_offset, overlay_nums * (s32)sizeof(ROM_FAT), buffer) ) if ( !ImageHMACSHA1Update(&ctx, (s32)pROMHeader->fat_offset, overlay_nums * (s32)sizeof(ROM_FAT)) )
{ {
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of FAT.\n", overlay_nums); OS_TPrintf("Cannot calc HMAC-SHA1 for %d of FAT.\n", overlay_nums);
return FALSE; return FALSE;
@ -404,7 +413,7 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
{ {
length = max_sectors; length = max_sectors;
} }
if ( !ImageHMACSHA1Update(&ctx, offset, length * 512, buffer) ) if ( !ImageHMACSHA1Update(&ctx, offset, length * 512) )
{ {
OS_TPrintf("Cannot calc HMAC-SHA1 for %d of overlay.\n", i); OS_TPrintf("Cannot calc HMAC-SHA1 for %d of overlay.\n", i);
return FALSE; return FALSE;

View File

@ -168,7 +168,7 @@ static CardSecureModeFunction s_funcTable[] = {
#ifdef DHT_TEST #ifdef DHT_TEST
#include <sysmenu/dht/dht.h> #include <sysmenu/dht/dht.h>
DHTFile* dht; DHTFile* dht;
static void* ov_buffer = (void*)0x02e80000; static DHTPhase2Work* p2work = (void*)0x02e80000;
static BOOL ReadImage(void* dest, s32 offset, s32 length, void* arg) static BOOL ReadImage(void* dest, s32 offset, s32 length, void* arg)
{ {
HotSwState retval = ReadPageGame((CardBootData*)arg, (u32)offset, dest, (u32)length); HotSwState retval = ReadPageGame((CardBootData*)arg, (u32)offset, dest, (u32)length);
@ -971,7 +971,7 @@ static HotSwState LoadStaticModule(void)
OS_TPrintf(" Done.\n"); OS_TPrintf(" Done.\n");
OS_TPrintf("DHT Pahse2..."); OS_TPrintf("DHT Pahse2...");
if ( !DHT_CheckHashPhase2(hash1, &s_cbData.pBootSegBuf->rh.s, ov_buffer, ReadImage, &s_cbData) ) if ( !DHT_CheckHashPhase2(hash1, &s_cbData.pBootSegBuf->rh.s, p2work, ReadImage, &s_cbData) )
{ {
OS_TPrintf(" Failed.\n"); OS_TPrintf(" Failed.\n");
return HOTSW_HASH_CHECK_ERROR; return HOTSW_HASH_CHECK_ERROR;
@ -1456,7 +1456,7 @@ static void HotSwThread(void *arg)
{ {
#pragma unused( arg ) #pragma unused( arg )
static BOOL isReadError = FALSE; static BOOL isReadError = FALSE;
HotSwState retval; HotSwState retval;
HotSwMessage *msg; HotSwMessage *msg;
@ -1506,22 +1506,22 @@ static void HotSwThread(void *arg)
} }
if(!isReadError){ if(!isReadError){
retval = LoadCardData(); retval = LoadCardData();
DebugPrintErrorMessage(retval); DebugPrintErrorMessage(retval);
if(retval != HOTSW_SUCCESS){ if(retval != HOTSW_SUCCESS){
McPowerOff(); McPowerOff();
ClearCaradFlgs(); ClearCaradFlgs();
isReadError = TRUE; isReadError = TRUE;
} }
s_IsPulledOut = FALSE; s_IsPulledOut = FALSE;
} }
else{ else{
break; break;
} }
} }
@ -1536,7 +1536,7 @@ static void HotSwThread(void *arg)
MI_CpuClearFast((u32 *)SYSM_CARD_BANNER_BUF, sizeof(TWLBannerFile)); MI_CpuClearFast((u32 *)SYSM_CARD_BANNER_BUF, sizeof(TWLBannerFile));
s_IsPulledOut = TRUE; s_IsPulledOut = TRUE;
isReadError = FALSE; isReadError = FALSE;
// ワンセグのスリープ時シャットダウン対策を戻す // ワンセグのスリープ時シャットダウン対策を戻す
MCU_EnableDeepSleepToPowerLine( MCU_PWR_LINE_33, TRUE ); MCU_EnableDeepSleepToPowerLine( MCU_PWR_LINE_33, TRUE );
@ -1556,7 +1556,7 @@ static void HotSwThread(void *arg)
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
static void ClearCaradFlgs(void) static void ClearCaradFlgs(void)
{ {
// ƒtƒ‰ƒO<C692>ˆ<CB86> // ƒtƒ‰ƒO<C692>ˆ<CB86>
LockHotSwRsc(&SYSMi_GetWork()->lockHotSW); LockHotSwRsc(&SYSMi_GetWork()->lockHotSW);
SYSMi_GetWork()->flags.hotsw.isExistCard = FALSE; SYSMi_GetWork()->flags.hotsw.isExistCard = FALSE;
SYSMi_GetWork()->flags.hotsw.isValidCardBanner = FALSE; SYSMi_GetWork()->flags.hotsw.isValidCardBanner = FALSE;

View File

@ -36,7 +36,7 @@ static DHTFile *const dht = (DHTFile*)dht_buffer;
/* /*
Phase2用バッファ Phase2用バッファ
*/ */
static u8 ov_buffer[DHT_OVERLAY_MAX]; static DHTPhase2Work p2work;
/* /*
@ -159,7 +159,7 @@ static BOOL CheckValidation(FSFile* fp)
return FALSE; return FALSE;
} }
// ハッシュ計算 (2) - 隠蔽は難しいか // ハッシュ計算 (2) - 隠蔽は難しいか
if ( !DHT_CheckHashPhase2(db->hash[1], &rom_header, ov_buffer, ReadImage, fp) ) if ( !DHT_CheckHashPhase2(db->hash[1], &rom_header, &p2work, ReadImage, fp) )
{ {
return FALSE; return FALSE;
} }

View File

@ -21,6 +21,16 @@
#include <twl/os/common/format_rom.h> #include <twl/os/common/format_rom.h>
#include <sysmenu/dht/dht_format.h> #include <sysmenu/dht/dht_format.h>
#define DHT_FAT_PAGE_SIZE 512
#define DHT_FAT_CACHE_SIZE (DHT_FAT_PAGE_SIZE * 2)
typedef struct DHTPhase2Work
{
u32 buffer[DHT_OVERLAY_MAX/sizeof(u32)]; // multiple usage
u8 fatCache[DHT_FAT_CACHE_SIZE]; // for fat cache only
}
DHTPhase2Work;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -137,11 +147,11 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
fctx (FS版) FSFile構造体へのポインタ fctx (FS版) FSFile構造体へのポインタ
(CARD版) dma番号をvoid* (CARD版) dma番号をvoid*
(HOTSW版) CardBootData構造体へのポインタ (HOTSW版) CardBootData構造体へのポインタ
buffer APIで使用するワーク (DHT_OVERLAY_MAXだけ必要) work APIで使用するワーク (DHT_OVERLAY_MAXだけ必要)
Returns: TRUE Returns: TRUE
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, void* buffer, DHTReadFunc func, void* arg); BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, DHTPhase2Work* work, DHTReadFunc func, void* arg);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */