mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
内部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:
parent
ce82cbc906
commit
53786510bb
@ -52,9 +52,10 @@ static const u8 g_pubkey_DER[ 0xa2 ] = {
|
||||
|
||||
static const u8 hmac_key[] = DHT_HMAC_KEY;
|
||||
|
||||
static DHTReadFunc ReadFunc;
|
||||
static void* readArg;
|
||||
#define PAGE_SIZE 512
|
||||
static DHTReadFunc ReadFunc;
|
||||
static void* readArg;
|
||||
static DHTPhase2Work* p2work;
|
||||
static int fatPage;
|
||||
|
||||
/*
|
||||
自家製bsearch
|
||||
@ -303,42 +304,48 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
|
||||
対象領域の読み込みとチェックを行う
|
||||
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;
|
||||
}
|
||||
SVC_HMACSHA1Update(ctx, buffer, (u32)length);
|
||||
if ( !ReadFunc(p2work->buffer, offset, length, readArg) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
SVC_HMACSHA1Update(ctx, p2work->buffer, (u32)length);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
||||
{
|
||||
ROM_FAT *fat;
|
||||
static u8 fat_cache[PAGE_SIZE*2];
|
||||
static int last_page = 0;
|
||||
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / PAGE_SIZE;
|
||||
if ( last_page != page )
|
||||
int page = (fat_offset + no * (s32)sizeof(ROM_FAT)) / DHT_FAT_PAGE_SIZE;
|
||||
if ( !p2work )
|
||||
{
|
||||
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 );
|
||||
if ( !ReadFunc(&fat_cache[PAGE_SIZE], (page+1) * PAGE_SIZE, PAGE_SIZE, readArg) )
|
||||
MI_CpuCopy8( &p2work->fatCache[DHT_FAT_PAGE_SIZE], &p2work->fatCache[0], DHT_FAT_PAGE_SIZE );
|
||||
if ( !ReadFunc(&p2work->fatCache[DHT_FAT_PAGE_SIZE], (page+1) * DHT_FAT_PAGE_SIZE, DHT_FAT_PAGE_SIZE, readArg) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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 )
|
||||
{
|
||||
*pOffset = (s32)fat->top.offset;
|
||||
@ -350,7 +357,7 @@ static BOOL GetOverlayInfo(int no, int fat_offset, int* pOffset, int* pLength)
|
||||
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));
|
||||
u8 md[20];
|
||||
@ -362,26 +369,28 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
|
||||
int total_sectors;
|
||||
int i;
|
||||
|
||||
if ( !func )
|
||||
if ( !func || !work )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
ReadFunc = func;
|
||||
readArg = arg;
|
||||
ReadFunc = func;
|
||||
readArg = arg;
|
||||
p2work = work;
|
||||
fatPage = -2; // default value = out of range
|
||||
|
||||
// 準備
|
||||
PROFILE_COUNT();
|
||||
SVC_HMACSHA1Init(&ctx, hmac_key, sizeof(hmac_key));
|
||||
// OVT
|
||||
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");
|
||||
return FALSE;
|
||||
}
|
||||
// FAT
|
||||
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);
|
||||
return FALSE;
|
||||
@ -404,7 +413,7 @@ BOOL DHT_CheckHashPhase2(const u8* hash, const ROM_Header_Short* pROMHeader, voi
|
||||
{
|
||||
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);
|
||||
return FALSE;
|
||||
|
||||
@ -168,7 +168,7 @@ static CardSecureModeFunction s_funcTable[] = {
|
||||
#ifdef DHT_TEST
|
||||
#include <sysmenu/dht/dht.h>
|
||||
DHTFile* dht;
|
||||
static void* ov_buffer = (void*)0x02e80000;
|
||||
static DHTPhase2Work* p2work = (void*)0x02e80000;
|
||||
static BOOL ReadImage(void* dest, s32 offset, s32 length, void* arg)
|
||||
{
|
||||
HotSwState retval = ReadPageGame((CardBootData*)arg, (u32)offset, dest, (u32)length);
|
||||
@ -971,7 +971,7 @@ static HotSwState LoadStaticModule(void)
|
||||
OS_TPrintf(" Done.\n");
|
||||
|
||||
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");
|
||||
return HOTSW_HASH_CHECK_ERROR;
|
||||
@ -1456,8 +1456,8 @@ static void HotSwThread(void *arg)
|
||||
{
|
||||
#pragma unused( arg )
|
||||
|
||||
static BOOL isReadError = FALSE;
|
||||
|
||||
static BOOL isReadError = FALSE;
|
||||
|
||||
HotSwState retval;
|
||||
HotSwMessage *msg;
|
||||
|
||||
@ -1506,22 +1506,22 @@ static void HotSwThread(void *arg)
|
||||
}
|
||||
|
||||
if(!isReadError){
|
||||
retval = LoadCardData();
|
||||
retval = LoadCardData();
|
||||
|
||||
DebugPrintErrorMessage(retval);
|
||||
DebugPrintErrorMessage(retval);
|
||||
|
||||
if(retval != HOTSW_SUCCESS){
|
||||
McPowerOff();
|
||||
if(retval != HOTSW_SUCCESS){
|
||||
McPowerOff();
|
||||
|
||||
ClearCaradFlgs();
|
||||
ClearCaradFlgs();
|
||||
|
||||
isReadError = TRUE;
|
||||
}
|
||||
isReadError = TRUE;
|
||||
}
|
||||
|
||||
s_IsPulledOut = FALSE;
|
||||
s_IsPulledOut = FALSE;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1536,8 +1536,8 @@ static void HotSwThread(void *arg)
|
||||
MI_CpuClearFast((u32 *)SYSM_CARD_BANNER_BUF, sizeof(TWLBannerFile));
|
||||
|
||||
s_IsPulledOut = TRUE;
|
||||
isReadError = FALSE;
|
||||
|
||||
isReadError = FALSE;
|
||||
|
||||
// ワンセグのスリープ時シャットダウン対策を戻す
|
||||
MCU_EnableDeepSleepToPowerLine( MCU_PWR_LINE_33, TRUE );
|
||||
|
||||
@ -1556,7 +1556,7 @@ static void HotSwThread(void *arg)
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void ClearCaradFlgs(void)
|
||||
{
|
||||
// ƒtƒ‰ƒO<C692>ˆ—<CB86>
|
||||
// ƒtƒ‰ƒO<C692>ˆ—<CB86>
|
||||
LockHotSwRsc(&SYSMi_GetWork()->lockHotSW);
|
||||
SYSMi_GetWork()->flags.hotsw.isExistCard = FALSE;
|
||||
SYSMi_GetWork()->flags.hotsw.isValidCardBanner = FALSE;
|
||||
|
||||
@ -36,7 +36,7 @@ static DHTFile *const dht = (DHTFile*)dht_buffer;
|
||||
/*
|
||||
Phase2用バッファ
|
||||
*/
|
||||
static u8 ov_buffer[DHT_OVERLAY_MAX];
|
||||
static DHTPhase2Work p2work;
|
||||
|
||||
/*
|
||||
実際にはアドレス固定
|
||||
@ -159,7 +159,7 @@ static BOOL CheckValidation(FSFile* fp)
|
||||
return FALSE;
|
||||
}
|
||||
// ハッシュ計算 (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;
|
||||
}
|
||||
|
||||
@ -21,6 +21,16 @@
|
||||
#include <twl/os/common/format_rom.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
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -137,11 +147,11 @@ BOOL DHT_CheckHashPhase1(const u8* hash, const ROM_Header_Short* pROMHeader, con
|
||||
fctx (FS版) FSFile構造体へのポインタ
|
||||
(CARD版) dma番号をvoid*にキャストしたもの
|
||||
(HOTSW版) CardBootData構造体へのポインタ
|
||||
buffer 本APIで使用するワーク (DHT_OVERLAY_MAXだけ必要)
|
||||
work 本APIで使用するワーク (DHT_OVERLAY_MAXだけ必要)
|
||||
|
||||
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
|
||||
} /* extern "C" */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user