AES鍵の位置変更、

AES領域二つ目対応、
バッテリ切れ時に電源OFFするように修正(FINALROM時のみ)、
セキュリティOFF設定の追加(デフォルト無効)、
SDドライバのDMAを0、1に変更


git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@696 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2008-02-19 06:33:37 +00:00
parent 45ec74a6c4
commit ef7303caaa
20 changed files with 200 additions and 265 deletions

View File

@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR;
#endif #endif
#define THREAD_PRIO_FATFS 8 #define THREAD_PRIO_FATFS 8
#define DMA_FATFS_1 3 #define DMA_FATFS_1 0
#define DMA_FATFS_2 2 #define DMA_FATFS_2 1
extern void* SDNandContext; /* NAND初期化パラメータ */ extern void* SDNandContext; /* NAND初期化パラメータ */
@ -99,8 +99,11 @@ static void PreInit(void)
*/ */
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
/* /*
FromBrom関連 FromBrom関連
@ -134,8 +137,11 @@ static void PostInit(void)
*/ */
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
} }
@ -232,8 +238,8 @@ void TwlSpMain( void )
SetDebugLED(++step); // 0x89 SetDebugLED(++step); // 0x89
AESi_InitKeysFIRM(); AESi_InitKeysFIRM();
AESi_RecvSeed( rh->s.developer_encrypt ); AESi_InitSeed();
// 9: after AESi_RecvSeed // 9: after AESi_InitSeed
PUSH_PROFILE(); PUSH_PROFILE();
SetDebugLED(++step); // 0x8a SetDebugLED(++step); // 0x8a

View File

@ -271,21 +271,16 @@ void TwlMain( void )
// 7: after PXI // 7: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
AESi_SendSeed( FS_GetAesKeySeed() );
FS_DeleteAesKeySeed();
// 8: after AESi_SendSeed
PUSH_PROFILE();
if ( !FS_LoadStatic() ) if ( !FS_LoadStatic() )
{ {
OS_TPrintf("Failed to call FS_LoadStatic().\n"); OS_TPrintf("Failed to call FS_LoadStatic().\n");
goto end; goto end;
} }
// 9: after FS_LoadStatic // 8: after FS_LoadStatic
PUSH_PROFILE(); PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC );
// 10: after PXI // 9: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE

View File

@ -110,28 +110,29 @@ void AESi_ResetAesKey( void )
} }
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: AESi_RecvSeed Name: AESi_InitSeedWithRomHeader
Description: set SEED/KEY from ARM9 via PXI. Description: set SEED/KEY from ROM header
Arguments: None Arguments: rom_header ROM header
Returns: None Returns: None
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void AESi_RecvSeed( BOOL developer_encrypt ) void AESi_InitSeedWithRomHeader( ROM_Header* rom_header )
{ {
AESKey seed;
// PXI_RecvDataByFifo( PXI_FIFO_TAG_DATA, &seed, AES_BLOCK_SIZE );
PXI_RecvStream( &seed, AES_BLOCK_SIZE );
AES_Lock(); AES_Lock();
AES_WaitKey(); AES_WaitKey();
if ( developer_encrypt ) if ( !rom_header )
{ {
AES_SetKeyA(&seed); // Direct return;
}
if ( rom_header->s.developer_encrypt )
{
AES_SetKeyA( (AESKey*)rom_header->s.title_name );
} }
else else
{ {
AES_SetKeySeedA((AESKeySeed*)&seed); // APP AES_SetKeySeedA( (AESKeySeed*)rom_header->s.main_ltd_static_digest );
} }
AES_Unlock(); AES_Unlock();
} }

View File

@ -58,6 +58,12 @@ static void EnableAes( u32 offset )
MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, AES_BLOCK_SIZE ); MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, AES_BLOCK_SIZE );
AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE ); AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target_rom_offset) / AES_BLOCK_SIZE );
} }
static void EnableAes2( u32 offset )
{
aesFlag = TRUE;
MI_CpuCopy8( rh->s.sub_static_digest, &aesCounter, AES_BLOCK_SIZE );
AES_AddToCounter( &aesCounter, (offset - rh->s.aes_target2_rom_offset) / AES_BLOCK_SIZE );
}
static void DisableAes( void ) static void DisableAes( void )
{ {
aesFlag = FALSE; aesFlag = FALSE;
@ -65,11 +71,14 @@ static void DisableAes( void )
static u32 GetTransferSize( u32 offset, u32 size ) static u32 GetTransferSize( u32 offset, u32 size )
{ {
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size);
u32 end = offset + RoundUpModuleSize(size);
if ( rh->s.enable_aes ) if ( rh->s.enable_aes )
{ {
u32 end = offset + RoundUpModuleSize(size);
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size);
u32 aes_offset2 = rh->s.aes_target2_rom_offset;
u32 aes_end2 = aes_offset2 + RoundUpModuleSize(rh->s.aes_target2_size);
if ( offset >= aes_offset && offset < aes_end ) if ( offset >= aes_offset && offset < aes_end )
{ {
if ( end > aes_end ) if ( end > aes_end )
@ -78,6 +87,14 @@ static u32 GetTransferSize( u32 offset, u32 size )
} }
EnableAes( offset ); EnableAes( offset );
} }
else if ( offset >= aes_offset2 && offset < aes_end2 )
{
if ( end > aes_end2 )
{
size = aes_end2 - offset;
}
EnableAes2( offset );
}
else else
{ {
if ( offset < aes_offset && offset + size > aes_offset ) if ( offset < aes_offset && offset + size > aes_offset )

View File

@ -54,35 +54,6 @@ static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] =
0x87, 0x46, 0x58, 0x24, 0x87, 0x46, 0x58, 0x24,
}; };
static AESKey FSiAesKeySeed;
/*---------------------------------------------------------------------------*
Name: FS_GetAesKeySeed
Description: retreive aes key seed in the signature
Arguments: None
Returns: pointer to seed
*---------------------------------------------------------------------------*/
AESKey* const FS_GetAesKeySeed( void )
{
return &FSiAesKeySeed;
}
/*---------------------------------------------------------------------------*
Name: FS_DeleteAesKeySeed
Description: delete aes key seed in the signature
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void FS_DeleteAesKeySeed( void )
{
MI_CpuClear8( &FSiAesKeySeed, sizeof(FSiAesKeySeed) );
}
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: FS_SetDigestKey Name: FS_SetDigestKey
@ -197,7 +168,7 @@ BOOL FS_LoadBuffer( u8* dest, u32 size, SVCSHA1Context *ctx )
{ {
MI_CpuCopyFast( src, dest, unit ); MI_CpuCopyFast( src, dest, unit );
} }
DC_FlushRange( src, unit ); DC_InvalidateRange( src, unit );
size -= unit; size -= unit;
dest += unit; dest += unit;
MIi_SetWramBankMaster_B( count, MI_WRAM_ARM7 ); MIi_SetWramBankMaster_B( count, MI_WRAM_ARM7 );
@ -225,11 +196,14 @@ BOOL FS_LoadBuffer( u8* dest, u32 size, SVCSHA1Context *ctx )
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
static u32 GetTransferSize( u32 offset, u32 size ) static u32 GetTransferSize( u32 offset, u32 size )
{ {
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + rh->s.aes_target_size;
u32 end = offset + size;
if ( rh->s.enable_aes ) if ( rh->s.enable_aes )
{ {
u32 end = offset + RoundUpModuleSize(size);
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size);
u32 aes_offset2 = rh->s.aes_target2_rom_offset;
u32 aes_end2 = aes_offset2 + RoundUpModuleSize(rh->s.aes_target2_size);
if ( offset >= aes_offset && offset < aes_end ) if ( offset >= aes_offset && offset < aes_end )
{ {
if ( end > aes_end ) if ( end > aes_end )
@ -237,6 +211,13 @@ static u32 GetTransferSize( u32 offset, u32 size )
size = aes_end - offset; size = aes_end - offset;
} }
} }
else if ( offset >= aes_offset2 && offset < aes_end2 )
{
if ( end > aes_end2 )
{
size = aes_end2 - offset;
}
}
else else
{ {
if ( offset < aes_offset && offset + size > aes_offset ) if ( offset < aes_offset && offset + size > aes_offset )
@ -264,6 +245,7 @@ static u32 GetTransferSize( u32 offset, u32 size )
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIGEST_SIZE] ) BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIGEST_SIZE] )
{ {
#ifndef NO_SECURITY_CHECK
SVCHMACSHA1Context ctx; SVCHMACSHA1Context ctx;
u8 md[SVC_SHA1_DIGEST_SIZE]; u8 md[SVC_SHA1_DIGEST_SIZE];
@ -281,6 +263,21 @@ BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIG
} }
SVC_HMACSHA1GetHash(&ctx, md); SVC_HMACSHA1GetHash(&ctx, md);
return CheckDigest(md, (u8*)digest, TRUE, FALSE); return CheckDigest(md, (u8*)digest, TRUE, FALSE);
#else
(void)digest;
while ( size > 0 )
{
u32 unit = GetTransferSize( offset, size );
if ( !FS_LoadBuffer( dest, unit, NULL ) )
{
return FALSE;
}
dest += unit;
offset += unit;
size -= unit;
}
return TRUE;
#endif
} }
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
@ -296,6 +293,7 @@ BOOL FS_LoadModule( u8* dest, u32 offset, u32 size, const u8 digest[SVC_SHA1_DIG
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
BOOL FS_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key ) BOOL FS_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key )
{ {
#ifndef NO_SECURITY_CHECK
SVCSHA1Context ctx; SVCSHA1Context ctx;
u8 md[SVC_SHA1_DIGEST_SIZE]; u8 md[SVC_SHA1_DIGEST_SIZE];
SignatureData sd; SignatureData sd;
@ -332,11 +330,13 @@ BOOL FS_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key )
// ダイジェスト以外のデータのチェックが必要!! // ダイジェスト以外のデータのチェックが必要!!
// Œ®‚̕ۑ¶
MI_CpuCopy8( (AESKey*)sd.aes_key_seed, &FSiAesKeySeed, sizeof(FSiAesKeySeed) );
MI_CpuClear8( &sd, sizeof(sd) ); // 残り削除 (他に必要なものはない?) MI_CpuClear8( &sd, sizeof(sd) ); // 残り削除 (他に必要なものはない?)
#else
(void)pool;
(void)rsa_key;
FS_LoadBuffer( (u8*)rh, FS_HEADER_AUTH_SIZE, NULL );
FS_LoadBuffer( (u8*)rh + FS_HEADER_AUTH_SIZE, HW_TWL_ROM_HEADER_BUF_SIZE - FS_HEADER_AUTH_SIZE, NULL );
#endif
// ROMヘッダのコピー // ROMヘッダのコピー
MI_CpuCopyFast( rh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); MI_CpuCopyFast( rh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF );
return TRUE; return TRUE;

View File

@ -56,41 +56,11 @@ static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] =
0x87, 0x46, 0x58, 0x24, 0x87, 0x46, 0x58, 0x24,
}; };
static AESKey FSiAesKeySeed;
static BOOL aesFlag; static BOOL aesFlag;
static AESCounter aesCounter; static AESCounter aesCounter;
static u8* const aesBuffer = (u8*)HW_FIRM_FS_AES_BUFFER; // 0x2ff3800 static u8* const aesBuffer = (u8*)HW_FIRM_FS_AES_BUFFER; // 0x2ff3800
/*---------------------------------------------------------------------------*
Name: FS2_GetAesKeySeed
Description: retreive aes key seed in the signature
Arguments: None
Returns: pointer to seed
*---------------------------------------------------------------------------*/
AESKey* const FS2_GetAesKeySeed( void )
{
return &FSiAesKeySeed;
}
/*---------------------------------------------------------------------------*
Name: FS2_DeleteAesKeySeed
Description: delete aes key seed in the signature
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void FS2_DeleteAesKeySeed( void )
{
MI_CpuClear8( &FSiAesKeySeed, sizeof(FSiAesKeySeed) );
}
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: FS2_SetDigestKey Name: FS2_SetDigestKey
@ -220,11 +190,13 @@ static void DisableAes( void )
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
static u32 GetTransferSize( u32 offset, u32 size ) static u32 GetTransferSize( u32 offset, u32 size )
{ {
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size);
u32 end = offset + RoundUpModuleSize(size);
if ( rh->s.enable_aes ) if ( rh->s.enable_aes )
{ {
u32 end = offset + RoundUpModuleSize(size);
u32 aes_offset = rh->s.aes_target_rom_offset;
u32 aes_end = aes_offset + RoundUpModuleSize(rh->s.aes_target_size);
u32 aes_offset2 = rh->s.aes_target2_rom_offset;
u32 aes_end2 = aes_offset2 + RoundUpModuleSize(rh->s.aes_target2_size);
if ( offset >= aes_offset && offset < aes_end ) if ( offset >= aes_offset && offset < aes_end )
{ {
if ( end > aes_end ) if ( end > aes_end )
@ -237,6 +209,18 @@ static u32 GetTransferSize( u32 offset, u32 size )
} }
EnableAes( offset ); EnableAes( offset );
} }
else if ( offset >= aes_offset2 && offset < aes_end2 )
{
if ( end > aes_end2 )
{
size = aes_end2 - offset;
}
if ( size > HW_FIRM_FS_AES_BUFFER_SIZE )
{
size = HW_FIRM_FS_AES_BUFFER_SIZE;
}
EnableAes( offset );
}
else else
{ {
if ( offset < aes_offset && offset + size > aes_offset ) if ( offset < aes_offset && offset + size > aes_offset )
@ -368,9 +352,6 @@ BOOL FS2_LoadHeader( FSFile *pFile, SVCSignHeapContext* pool, const void* rsa_ke
// ダイジェスト以外のデータのチェックが必要!! // ダイジェスト以外のデータのチェックが必要!!
// Œ®‚̕ۑ¶
MI_CpuCopy8( (AESKey*)sd.aes_key_seed, &FSiAesKeySeed, sizeof(FSiAesKeySeed) );
MI_CpuClear8( &sd, sizeof(sd) ); // 残り削除 (他に必要なものはない?) MI_CpuClear8( &sd, sizeof(sd) ); // 残り削除 (他に必要なものはない?)
// ROMヘッダのコピー // ROMヘッダのコピー

View File

@ -89,3 +89,17 @@ void PM_BackLightOn( BOOL force )
doneBackLight = TRUE; doneBackLight = TRUE;
} }
} }
/*---------------------------------------------------------------------------*
Name: PM_Shutdown
Description: shutdown
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void PM_Shutdown( void )
{
PMi_SetFlags( REG_PMIC_CTL_ADDR, PMIC_CTL_PWR_OFF );
}

View File

@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR;
#endif #endif
#define THREAD_PRIO_FATFS 8 #define THREAD_PRIO_FATFS 8
#define DMA_FATFS_1 3 #define DMA_FATFS_1 0
#define DMA_FATFS_2 2 #define DMA_FATFS_2 1
extern void* SDNandContext; /* NAND初期化パラメータ */ extern void* SDNandContext; /* NAND初期化パラメータ */
@ -100,8 +100,11 @@ static void PreInit(void)
if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策 if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
/* /*
FromBrom関連 FromBrom関連
@ -136,8 +139,11 @@ static void PostInit(void)
if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策 if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
} }
@ -246,8 +252,8 @@ void TwlSpMain( void )
// PM_BackLightOn( FALSE ); // PM_BackLightOn( FALSE );
AESi_InitKeysFIRM(); AESi_InitKeysFIRM();
AESi_RecvSeed( rh->s.developer_encrypt ); AESi_InitSeed();
// 9: after AESi_RecvSeed // 9: after AESi_InitSeed
PUSH_PROFILE(); PUSH_PROFILE();
SetDebugLED(++step); // 0x8a SetDebugLED(++step); // 0x8a

View File

@ -23,14 +23,14 @@
#define RSA_KEY_ADDR rsa_key #define RSA_KEY_ADDR rsa_key
static const u8 rsa_key[128] = static const u8 rsa_key[128] =
{ {
0xe9, 0x9e, 0xa7, 0x9f, 0x59, 0x4d, 0xf4, 0xa7, 0x60, 0x04, 0xbd, 0x47, 0xf2, 0xb3, 0x64, 0xcd, 0xe9, 0x9e, 0xa7, 0x9f, 0x59, 0x4d, 0xf4, 0xa7, 0x60, 0x04, 0xbd, 0x47, 0xf2, 0xb3, 0x64, 0xcd,
0x16, 0x79, 0xc1, 0x47, 0x39, 0xf6, 0xa9, 0xf8, 0xee, 0x1a, 0xd0, 0x72, 0xcf, 0x43, 0x97, 0x0c, 0x16, 0x79, 0xc1, 0x47, 0x39, 0xf6, 0xa9, 0xf8, 0xee, 0x1a, 0xd0, 0x72, 0xcf, 0x43, 0x97, 0x0c,
0x93, 0xa1, 0x38, 0x4e, 0x13, 0x40, 0x6c, 0x10, 0x59, 0x43, 0xe2, 0x71, 0x29, 0x54, 0x14, 0x2c, 0x93, 0xa1, 0x38, 0x4e, 0x13, 0x40, 0x6c, 0x10, 0x59, 0x43, 0xe2, 0x71, 0x29, 0x54, 0x14, 0x2c,
0xc5, 0xda, 0x59, 0x4d, 0xb4, 0x6a, 0xef, 0x85, 0x61, 0x6f, 0x7f, 0x1c, 0x59, 0x34, 0x2c, 0xc6, 0xc5, 0xda, 0x59, 0x4d, 0xb4, 0x6a, 0xef, 0x85, 0x61, 0x6f, 0x7f, 0x1c, 0x59, 0x34, 0x2c, 0xc6,
0x24, 0xf3, 0x7b, 0xc3, 0xb7, 0x40, 0xd1, 0x46, 0xf8, 0x90, 0xb7, 0xc2, 0x98, 0x50, 0xaf, 0x95, 0x24, 0xf3, 0x7b, 0xc3, 0xb7, 0x40, 0xd1, 0x46, 0xf8, 0x90, 0xb7, 0xc2, 0x98, 0x50, 0xaf, 0x95,
0x52, 0x42, 0xdb, 0xac, 0xd6, 0x7e, 0xa9, 0xc3, 0x3d, 0x1b, 0x51, 0x56, 0x07, 0x06, 0xd0, 0x0b, 0x52, 0x42, 0xdb, 0xac, 0xd6, 0x7e, 0xa9, 0xc3, 0x3d, 0x1b, 0x51, 0x56, 0x07, 0x06, 0xd0, 0x0b,
0x01, 0xbb, 0x58, 0x93, 0xea, 0xa0, 0x2c, 0xc7, 0x7d, 0x6a, 0x31, 0x7e, 0xc9, 0xe2, 0xda, 0xfe, 0x01, 0xbb, 0x58, 0x93, 0xea, 0xa0, 0x2c, 0xc7, 0x7d, 0x6a, 0x31, 0x7e, 0xc9, 0xe2, 0xda, 0xfe,
0x1f, 0x2e, 0x9d, 0xa7, 0x54, 0x84, 0xdc, 0x28, 0xb9, 0x18, 0xea, 0x16, 0xf2, 0x95, 0x55, 0x6d, 0x1f, 0x2e, 0x9d, 0xa7, 0x54, 0x84, 0xdc, 0x28, 0xb9, 0x18, 0xea, 0x16, 0xf2, 0x95, 0x55, 0x6d,
}; };
#endif #endif
@ -293,21 +293,16 @@ void TwlMain( void )
// 8: after PXI // 8: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
AESi_SendSeed( FS_GetAesKeySeed() );
FS_DeleteAesKeySeed();
// 9: after AESi_SendSeed
PUSH_PROFILE();
if ( !FS_LoadStatic() ) if ( !FS_LoadStatic() )
{ {
OS_TPrintf("Failed to call FS_LoadStatic().\n"); OS_TPrintf("Failed to call FS_LoadStatic().\n");
goto end; goto end;
} }
// 10: after FS_LoadStatic // 9: after FS_LoadStatic
PUSH_PROFILE(); PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC );
// 11: after PXI // 10: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE

View File

@ -63,8 +63,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR;
#endif #endif
#define THREAD_PRIO_FATFS 8 #define THREAD_PRIO_FATFS 8
#define DMA_FATFS_1 3 #define DMA_FATFS_1 0
#define DMA_FATFS_2 2 #define DMA_FATFS_2 1
extern void* SDNandContext; /* NAND初期化パラメータ */ extern void* SDNandContext; /* NAND初期化パラメータ */
@ -101,8 +101,11 @@ static void PreInit(void)
if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策 if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
/* /*
FromBrom関連 FromBrom関連
@ -137,8 +140,11 @@ static void PostInit(void)
if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策 if ( MCUi_ReadRegister( MCU_REG_VER_INFO_ADDR ) >= 0x20 ) // MCU旧バージョン対策
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
} }
@ -227,8 +233,8 @@ void TwlSpMain( void )
// PM_BackLightOn( FALSE ); // PM_BackLightOn( FALSE );
AESi_InitKeysFIRM(); AESi_InitKeysFIRM();
AESi_RecvSeed( rh->s.developer_encrypt ); AESi_InitSeed();
// 9: after AESi_RecvSeed // 9: after AESi_InitSeed
PUSH_PROFILE(); PUSH_PROFILE();
SetDebugLED(++step); // 0x8a SetDebugLED(++step); // 0x8a

View File

@ -303,20 +303,16 @@ void TwlMain( void )
// 8: after PXI // 8: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
AESi_SendSeed( FS2_GetAesKeySeed() );
// 9: after AESi_SendSeed
PUSH_PROFILE();
if ( !FS2_LoadStatic( &file ) ) if ( !FS2_LoadStatic( &file ) )
{ {
OS_TPrintf("Failed to call FS2_LoadStatic().\n"); OS_TPrintf("Failed to call FS2_LoadStatic().\n");
goto end; goto end;
} }
// 10: after FS2_LoadStatic // 9: after FS2_LoadStatic
PUSH_PROFILE(); PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC );
// 11: after PXI // 10: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE

View File

@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR;
#endif #endif
#define THREAD_PRIO_FATFS 8 #define THREAD_PRIO_FATFS 8
#define DMA_FATFS_1 3 #define DMA_FATFS_1 0
#define DMA_FATFS_2 2 #define DMA_FATFS_2 1
extern void* SDNandContext; /* NAND初期化パラメータ */ extern void* SDNandContext; /* NAND初期化パラメータ */
@ -99,8 +99,11 @@ static void PreInit(void)
*/ */
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
/* /*
FromBrom関連 FromBrom関連
@ -134,8 +137,11 @@ static void PostInit(void)
*/ */
if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 )
{ {
OS_TPrintf("Battery is empty.\n"); #ifndef SDK_FINALROM
OS_Terminate(); OS_TPanic("Battery is empty.\n");
#else
PM_Shutdown();
#endif
} }
} }
@ -232,8 +238,8 @@ void TwlSpMain( void )
SetDebugLED(++step); // 0x89 SetDebugLED(++step); // 0x89
AESi_InitKeysFIRM(); AESi_InitKeysFIRM();
AESi_RecvSeed( rh->s.developer_encrypt ); AESi_InitSeed();
// 9: after AESi_RecvSeed // 9: after AESi_InitSeed
PUSH_PROFILE(); PUSH_PROFILE();
SetDebugLED(++step); // 0x8a SetDebugLED(++step); // 0x8a

View File

@ -295,21 +295,16 @@ void TwlMain( void )
// 7: after PXI // 7: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
AESi_SendSeed( FS_GetAesKeySeed() );
FS_DeleteAesKeySeed();
// 8: after AESi_SendSeed
PUSH_PROFILE();
if ( !FS_LoadStatic() ) if ( !FS_LoadStatic() )
{ {
OS_TPrintf("Failed to call FS_LoadStatic().\n"); OS_TPrintf("Failed to call FS_LoadStatic().\n");
goto end; goto end;
} }
// 9: after FS_LoadStatic // 8: after FS_LoadStatic
PUSH_PROFILE(); PUSH_PROFILE();
PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC );
// 10: after PXI // 9: after PXI
PUSH_PROFILE(); PUSH_PROFILE();
#ifdef PROFILE_ENABLE #ifdef PROFILE_ENABLE

View File

@ -26,8 +26,6 @@
#include <twl/aes/ARM7/lo.h> #include <twl/aes/ARM7/lo.h>
#include <firm/aes/ARM7/aes_init.h> #include <firm/aes/ARM7/aes_init.h>
#include <firm/aes/ARM7/aes_ids.h> #include <firm/aes/ARM7/aes_ids.h>
#else // !SDK_ARM7
#include <firm/aes/ARM9/aes_init.h>
#endif // !SDK_ARM7 #endif // !SDK_ARM7
/* FIRM_AES_H_ */ /* FIRM_AES_H_ */

View File

@ -79,15 +79,28 @@ static inline void AESi_InitKeysFIRM( void )
} }
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: AESi_RecvSeed Name: AESi_InitSeedWithRomHeader
Description: set SEED/KEY from ARM9 via PXI. Description: set SEED/KEY from ROM header
Arguments: developer_encrypt set TRUE if received key is using as direct key Arguments: rom_header ROM header
Returns: None Returns: None
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void AESi_RecvSeed( BOOL developer_encrypt ); void AESi_InitSeedWithRomHeader( ROM_Header* rom_header );
/*---------------------------------------------------------------------------*
Name: AESi_InitSeedWithRomHeader
Description: set SEED/KEY from ROM header in HW_TWL_ROM_HEADER_BUF
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
static inline void AESi_InitSeed( void )
{
}
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@ -1,50 +0,0 @@
/*---------------------------------------------------------------------------*
Project: TwlIPL - AES - include
File: aes_init.h
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:: 2007-09-06$
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#ifndef TWL_AES_AES_INIT_H_
#define TWL_AES_AES_INIT_H_
#include <firm/pxi.h>
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------*
ŠÖ<EFBFBD>è`
*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*
Name: AESi_SendSeed
Description: send SEED/KEY to ARM7 via PXI.
Arguments: pSeed pointer to seed
Returns: None
*---------------------------------------------------------------------------*/
static inline void AESi_SendSeed( const AESKey *pSeed )
{
PXI_SendStream( pSeed, AES_BLOCK_SIZE );
}
#ifdef __cplusplus
} /* extern "C" */
#endif
/* TWL_AES_AES_INIT_H_ */
#endif

View File

@ -26,28 +26,6 @@
extern "C" { extern "C" {
#endif #endif
/*---------------------------------------------------------------------------*
Name: FS_GetAesKeySeed
Description: retreive aes key seed in the signature
Arguments: None
Returns: pointer to seed
*---------------------------------------------------------------------------*/
AESKey* const FS_GetAesKeySeed( void );
/*---------------------------------------------------------------------------*
Name: FS_DeleteAesKeySeed
Description: delete aes key seed in the signature
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void FS_DeleteAesKeySeed( void );
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: FS_SetDigestKey Name: FS_SetDigestKey

View File

@ -26,28 +26,6 @@
extern "C" { extern "C" {
#endif #endif
/*---------------------------------------------------------------------------*
Name: FS2_GetAesKeySeed
Description: retreive aes key seed in the signature
Arguments: None
Returns: pointer to seed
*---------------------------------------------------------------------------*/
AESKey* const FS2_GetAesKeySeed( void );
/*---------------------------------------------------------------------------*
Name: FS2_DeleteAesKeySeed
Description: delete aes key seed in the signature
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void FS2_DeleteAesKeySeed( void );
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: FS2_SetDigestKey Name: FS2_SetDigestKey

View File

@ -38,7 +38,7 @@ extern "C" {
void OS_BootWithRomHeaderFromFIRM( ROM_Header* rom_header ); void OS_BootWithRomHeaderFromFIRM( ROM_Header* rom_header );
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: OS_BootDefault Name: OS_BootFromFIRM
Description: boot system menu using ROM_Header in HW_TWL_ROM_HEADER_BUF Description: boot system menu using ROM_Header in HW_TWL_ROM_HEADER_BUF

View File

@ -33,17 +33,6 @@ extern "C" {
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void PM_InitFIRM( void ); void PM_InitFIRM( void );
/*---------------------------------------------------------------------------*
Name: PM_CheckINIFlag
Description: Check INI in GX_DISPSTAT (able to call before PM_InitFIRM)
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void PM_CheckINIFlag(void);
/*---------------------------------------------------------------------------* /*---------------------------------------------------------------------------*
Name: PM_BackLightOn Name: PM_BackLightOn
@ -56,6 +45,17 @@ void PM_CheckINIFlag(void);
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
void PM_BackLightOn( BOOL force ); void PM_BackLightOn( BOOL force );
/*---------------------------------------------------------------------------*
Name: PM_Shutdown
Description: shutdown
Arguments: None
Returns: None
*---------------------------------------------------------------------------*/
void PM_Shutdown( void );
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif