From ef7303caaaf331f8dde05e2f3ee00e30ac402710 Mon Sep 17 00:00:00 2001 From: yutaka Date: Tue, 19 Feb 2008 06:33:37 +0000 Subject: [PATCH] =?UTF-8?q?AES=E9=8D=B5=E3=81=AE=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=80=81=20AES=E9=A0=98=E5=9F=9F=E4=BA=8C?= =?UTF-8?q?=E3=81=A4=E7=9B=AE=E5=AF=BE=E5=BF=9C=E3=80=81=20=E3=83=90?= =?UTF-8?q?=E3=83=83=E3=83=86=E3=83=AA=E5=88=87=E3=82=8C=E6=99=82=E3=81=AB?= =?UTF-8?q?=E9=9B=BB=E6=BA=90OFF=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3(FINALROM=E6=99=82=E3=81=AE=E3=81=BF?= =?UTF-8?q?)=E3=80=81=20=E3=82=BB=E3=82=AD=E3=83=A5=E3=83=AA=E3=83=86?= =?UTF-8?q?=E3=82=A3OFF=E8=A8=AD=E5=AE=9A=E3=81=AE=E8=BF=BD=E5=8A=A0(?= =?UTF-8?q?=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E7=84=A1=E5=8A=B9?= =?UTF-8?q?)=E3=80=81=20SD=E3=83=89=E3=83=A9=E3=82=A4=E3=83=90=E3=81=AEDMA?= =?UTF-8?q?=E3=82=920=E3=80=811=E3=81=AB=E5=A4=89=E6=9B=B4?= 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@696 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/gcdfirm/sdmc-launcher/ARM7/main.c | 22 ++++--- build/gcdfirm/sdmc-launcher/ARM9/main.c | 9 +-- build/libraries/aes/ARM7/aes_init.c | 21 ++++--- build/libraries/fs/ARM7/src/fs_loader.c | 23 ++++++- build/libraries/fs/ARM9/src/fs_loader.c | 74 +++++++++++------------ build/libraries/fs/ARM9/src/fs_loader2.c | 53 ++++++---------- build/libraries/pm/ARM7/pm_init.c | 14 +++++ build/nandfirm/menu-launcher/ARM7/main.c | 22 ++++--- build/nandfirm/menu-launcher/ARM9/main.c | 25 +++----- build/nandfirm/menu-launcher2/ARM7/main.c | 22 ++++--- build/nandfirm/menu-launcher2/ARM9/main.c | 8 +-- build/nandfirm/sdmc-launcher/ARM7/main.c | 22 ++++--- build/nandfirm/sdmc-launcher/ARM9/main.c | 9 +-- include/firm/aes.h | 2 - include/firm/aes/ARM7/aes_init.h | 21 +++++-- include/firm/aes/ARM9/aes_init.h | 50 --------------- include/firm/fs/ARM9/fs_loader.h | 22 ------- include/firm/fs/ARM9/fs_loader2.h | 22 ------- include/firm/os/common/boot.h | 2 +- include/firm/pm/ARM7/pm_init.h | 22 +++---- 20 files changed, 200 insertions(+), 265 deletions(-) delete mode 100644 include/firm/aes/ARM9/aes_init.h diff --git a/build/gcdfirm/sdmc-launcher/ARM7/main.c b/build/gcdfirm/sdmc-launcher/ARM7/main.c index 75e28f2f..96eb76c0 100644 --- a/build/gcdfirm/sdmc-launcher/ARM7/main.c +++ b/build/gcdfirm/sdmc-launcher/ARM7/main.c @@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR; #endif #define THREAD_PRIO_FATFS 8 -#define DMA_FATFS_1 3 -#define DMA_FATFS_2 2 +#define DMA_FATFS_1 0 +#define DMA_FATFS_2 1 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 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } /* FromBrom関連 @@ -134,8 +137,11 @@ static void PostInit(void) */ if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } } @@ -232,8 +238,8 @@ void TwlSpMain( void ) SetDebugLED(++step); // 0x89 AESi_InitKeysFIRM(); - AESi_RecvSeed( rh->s.developer_encrypt ); - // 9: after AESi_RecvSeed + AESi_InitSeed(); + // 9: after AESi_InitSeed PUSH_PROFILE(); SetDebugLED(++step); // 0x8a diff --git a/build/gcdfirm/sdmc-launcher/ARM9/main.c b/build/gcdfirm/sdmc-launcher/ARM9/main.c index b7ef81b7..caa187a9 100644 --- a/build/gcdfirm/sdmc-launcher/ARM9/main.c +++ b/build/gcdfirm/sdmc-launcher/ARM9/main.c @@ -271,21 +271,16 @@ void TwlMain( void ) // 7: after PXI PUSH_PROFILE(); - AESi_SendSeed( FS_GetAesKeySeed() ); - FS_DeleteAesKeySeed(); - // 8: after AESi_SendSeed - PUSH_PROFILE(); - if ( !FS_LoadStatic() ) { OS_TPrintf("Failed to call FS_LoadStatic().\n"); goto end; } - // 9: after FS_LoadStatic + // 8: after FS_LoadStatic PUSH_PROFILE(); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); - // 10: after PXI + // 9: after PXI PUSH_PROFILE(); #ifdef PROFILE_ENABLE diff --git a/build/libraries/aes/ARM7/aes_init.c b/build/libraries/aes/ARM7/aes_init.c index b8e6b3d5..d6339e28 100644 --- a/build/libraries/aes/ARM7/aes_init.c +++ b/build/libraries/aes/ARM7/aes_init.c @@ -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 *---------------------------------------------------------------------------*/ -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_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 { - AES_SetKeySeedA((AESKeySeed*)&seed); // APP + AES_SetKeySeedA( (AESKeySeed*)rom_header->s.main_ltd_static_digest ); } AES_Unlock(); } diff --git a/build/libraries/fs/ARM7/src/fs_loader.c b/build/libraries/fs/ARM7/src/fs_loader.c index 803384c3..88a80224 100644 --- a/build/libraries/fs/ARM7/src/fs_loader.c +++ b/build/libraries/fs/ARM7/src/fs_loader.c @@ -58,6 +58,12 @@ static void EnableAes( u32 offset ) MI_CpuCopy8( rh->s.main_static_digest, &aesCounter, 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 ) { aesFlag = FALSE; @@ -65,11 +71,14 @@ static void DisableAes( void ) 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 ) { + 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 ( end > aes_end ) @@ -78,6 +87,14 @@ static u32 GetTransferSize( u32 offset, u32 size ) } EnableAes( offset ); } + else if ( offset >= aes_offset2 && offset < aes_end2 ) + { + if ( end > aes_end2 ) + { + size = aes_end2 - offset; + } + EnableAes2( offset ); + } else { if ( offset < aes_offset && offset + size > aes_offset ) diff --git a/build/libraries/fs/ARM9/src/fs_loader.c b/build/libraries/fs/ARM9/src/fs_loader.c index f5d623bc..0debdd8a 100644 --- a/build/libraries/fs/ARM9/src/fs_loader.c +++ b/build/libraries/fs/ARM9/src/fs_loader.c @@ -54,35 +54,6 @@ static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] = 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 @@ -197,7 +168,7 @@ BOOL FS_LoadBuffer( u8* dest, u32 size, SVCSHA1Context *ctx ) { MI_CpuCopyFast( src, dest, unit ); } - DC_FlushRange( src, unit ); + DC_InvalidateRange( src, unit ); size -= unit; dest += unit; 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 ) { - 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 ) { + 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 ( end > aes_end ) @@ -237,6 +211,13 @@ static u32 GetTransferSize( u32 offset, u32 size ) size = aes_end - offset; } } + else if ( offset >= aes_offset2 && offset < aes_end2 ) + { + if ( end > aes_end2 ) + { + size = aes_end2 - offset; + } + } else { 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] ) { +#ifndef NO_SECURITY_CHECK SVCHMACSHA1Context ctx; 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); 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 ) { +#ifndef NO_SECURITY_CHECK SVCSHA1Context ctx; u8 md[SVC_SHA1_DIGEST_SIZE]; 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) ); // 残り削除 (他に必要なものはない?) - +#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ヘッダのコピー MI_CpuCopyFast( rh, (void*)HW_ROM_HEADER_BUF, HW_ROM_HEADER_BUF_END-HW_ROM_HEADER_BUF ); return TRUE; diff --git a/build/libraries/fs/ARM9/src/fs_loader2.c b/build/libraries/fs/ARM9/src/fs_loader2.c index 43efe415..b7fba0cf 100644 --- a/build/libraries/fs/ARM9/src/fs_loader2.c +++ b/build/libraries/fs/ARM9/src/fs_loader2.c @@ -56,41 +56,11 @@ static const u8 defaultKey[ SVC_SHA1_BLOCK_SIZE ] = 0x87, 0x46, 0x58, 0x24, }; -static AESKey FSiAesKeySeed; - static BOOL aesFlag; static AESCounter aesCounter; 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 @@ -220,11 +190,13 @@ static void DisableAes( void ) *---------------------------------------------------------------------------*/ 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 ) { + 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 ( end > aes_end ) @@ -237,6 +209,18 @@ static u32 GetTransferSize( u32 offset, u32 size ) } 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 { 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) ); // 残り削除 (他に必要なものはない?) // ROMヘッダのコピー diff --git a/build/libraries/pm/ARM7/pm_init.c b/build/libraries/pm/ARM7/pm_init.c index 363d3add..562156e4 100644 --- a/build/libraries/pm/ARM7/pm_init.c +++ b/build/libraries/pm/ARM7/pm_init.c @@ -89,3 +89,17 @@ void PM_BackLightOn( BOOL force ) 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 ); +} diff --git a/build/nandfirm/menu-launcher/ARM7/main.c b/build/nandfirm/menu-launcher/ARM7/main.c index 62505b31..8cdec9f0 100644 --- a/build/nandfirm/menu-launcher/ARM7/main.c +++ b/build/nandfirm/menu-launcher/ARM7/main.c @@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR; #endif #define THREAD_PRIO_FATFS 8 -#define DMA_FATFS_1 3 -#define DMA_FATFS_2 2 +#define DMA_FATFS_1 0 +#define DMA_FATFS_2 1 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_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } /* FromBrom関連 @@ -136,8 +139,11 @@ static void PostInit(void) 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 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } } @@ -246,8 +252,8 @@ void TwlSpMain( void ) // PM_BackLightOn( FALSE ); AESi_InitKeysFIRM(); - AESi_RecvSeed( rh->s.developer_encrypt ); - // 9: after AESi_RecvSeed + AESi_InitSeed(); + // 9: after AESi_InitSeed PUSH_PROFILE(); SetDebugLED(++step); // 0x8a diff --git a/build/nandfirm/menu-launcher/ARM9/main.c b/build/nandfirm/menu-launcher/ARM9/main.c index 7cf759cd..0e6a7add 100644 --- a/build/nandfirm/menu-launcher/ARM9/main.c +++ b/build/nandfirm/menu-launcher/ARM9/main.c @@ -23,14 +23,14 @@ #define RSA_KEY_ADDR rsa_key static const u8 rsa_key[128] = { - 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, - 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, - 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, - 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, + 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, + 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, + 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, + 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, }; #endif @@ -293,21 +293,16 @@ void TwlMain( void ) // 8: after PXI PUSH_PROFILE(); - AESi_SendSeed( FS_GetAesKeySeed() ); - FS_DeleteAesKeySeed(); - // 9: after AESi_SendSeed - PUSH_PROFILE(); - if ( !FS_LoadStatic() ) { OS_TPrintf("Failed to call FS_LoadStatic().\n"); goto end; } - // 10: after FS_LoadStatic + // 9: after FS_LoadStatic PUSH_PROFILE(); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); - // 11: after PXI + // 10: after PXI PUSH_PROFILE(); #ifdef PROFILE_ENABLE diff --git a/build/nandfirm/menu-launcher2/ARM7/main.c b/build/nandfirm/menu-launcher2/ARM7/main.c index c2b82223..3e1c1b85 100644 --- a/build/nandfirm/menu-launcher2/ARM7/main.c +++ b/build/nandfirm/menu-launcher2/ARM7/main.c @@ -63,8 +63,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR; #endif #define THREAD_PRIO_FATFS 8 -#define DMA_FATFS_1 3 -#define DMA_FATFS_2 2 +#define DMA_FATFS_1 0 +#define DMA_FATFS_2 1 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_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } /* FromBrom関連 @@ -137,8 +140,11 @@ static void PostInit(void) 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 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } } @@ -227,8 +233,8 @@ void TwlSpMain( void ) // PM_BackLightOn( FALSE ); AESi_InitKeysFIRM(); - AESi_RecvSeed( rh->s.developer_encrypt ); - // 9: after AESi_RecvSeed + AESi_InitSeed(); + // 9: after AESi_InitSeed PUSH_PROFILE(); SetDebugLED(++step); // 0x8a diff --git a/build/nandfirm/menu-launcher2/ARM9/main.c b/build/nandfirm/menu-launcher2/ARM9/main.c index 913e8dc1..12b6b601 100644 --- a/build/nandfirm/menu-launcher2/ARM9/main.c +++ b/build/nandfirm/menu-launcher2/ARM9/main.c @@ -303,20 +303,16 @@ void TwlMain( void ) // 8: after PXI PUSH_PROFILE(); - AESi_SendSeed( FS2_GetAesKeySeed() ); - // 9: after AESi_SendSeed - PUSH_PROFILE(); - if ( !FS2_LoadStatic( &file ) ) { OS_TPrintf("Failed to call FS2_LoadStatic().\n"); goto end; } - // 10: after FS2_LoadStatic + // 9: after FS2_LoadStatic PUSH_PROFILE(); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); - // 11: after PXI + // 10: after PXI PUSH_PROFILE(); #ifdef PROFILE_ENABLE diff --git a/build/nandfirm/sdmc-launcher/ARM7/main.c b/build/nandfirm/sdmc-launcher/ARM7/main.c index 5aa3a9ed..a37ca8cd 100644 --- a/build/nandfirm/sdmc-launcher/ARM7/main.c +++ b/build/nandfirm/sdmc-launcher/ARM7/main.c @@ -62,8 +62,8 @@ static char* debugPtr = (char*)PRINT_MEMORY_ADDR; #endif #define THREAD_PRIO_FATFS 8 -#define DMA_FATFS_1 3 -#define DMA_FATFS_2 2 +#define DMA_FATFS_1 0 +#define DMA_FATFS_2 1 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 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } /* FromBrom関連 @@ -134,8 +137,11 @@ static void PostInit(void) */ if ( (MCUi_ReadRegister( MCU_REG_POWER_INFO_ADDR ) & MCU_REG_POWER_INFO_LEVEL_MASK) == 0 ) { - OS_TPrintf("Battery is empty.\n"); - OS_Terminate(); +#ifndef SDK_FINALROM + OS_TPanic("Battery is empty.\n"); +#else + PM_Shutdown(); +#endif } } @@ -232,8 +238,8 @@ void TwlSpMain( void ) SetDebugLED(++step); // 0x89 AESi_InitKeysFIRM(); - AESi_RecvSeed( rh->s.developer_encrypt ); - // 9: after AESi_RecvSeed + AESi_InitSeed(); + // 9: after AESi_InitSeed PUSH_PROFILE(); SetDebugLED(++step); // 0x8a diff --git a/build/nandfirm/sdmc-launcher/ARM9/main.c b/build/nandfirm/sdmc-launcher/ARM9/main.c index fdca66e0..5e6960f8 100644 --- a/build/nandfirm/sdmc-launcher/ARM9/main.c +++ b/build/nandfirm/sdmc-launcher/ARM9/main.c @@ -295,21 +295,16 @@ void TwlMain( void ) // 7: after PXI PUSH_PROFILE(); - AESi_SendSeed( FS_GetAesKeySeed() ); - FS_DeleteAesKeySeed(); - // 8: after AESi_SendSeed - PUSH_PROFILE(); - if ( !FS_LoadStatic() ) { OS_TPrintf("Failed to call FS_LoadStatic().\n"); goto end; } - // 9: after FS_LoadStatic + // 8: after FS_LoadStatic PUSH_PROFILE(); PXI_NotifyID( FIRM_PXI_ID_DONE_STATIC ); - // 10: after PXI + // 9: after PXI PUSH_PROFILE(); #ifdef PROFILE_ENABLE diff --git a/include/firm/aes.h b/include/firm/aes.h index 98e63da4..36462494 100644 --- a/include/firm/aes.h +++ b/include/firm/aes.h @@ -26,8 +26,6 @@ #include #include #include -#else // !SDK_ARM7 -#include #endif // !SDK_ARM7 /* FIRM_AES_H_ */ diff --git a/include/firm/aes/ARM7/aes_init.h b/include/firm/aes/ARM7/aes_init.h index 9804a053..67402a61 100644 --- a/include/firm/aes/ARM7/aes_init.h +++ b/include/firm/aes/ARM7/aes_init.h @@ -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 *---------------------------------------------------------------------------*/ -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 } /* extern "C" */ diff --git a/include/firm/aes/ARM9/aes_init.h b/include/firm/aes/ARM9/aes_init.h deleted file mode 100644 index 8d3cfbe7..00000000 --- a/include/firm/aes/ARM9/aes_init.h +++ /dev/null @@ -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 - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------* - 関数定義 - *---------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------* - 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 diff --git a/include/firm/fs/ARM9/fs_loader.h b/include/firm/fs/ARM9/fs_loader.h index 12c3b6b0..4d2608e8 100644 --- a/include/firm/fs/ARM9/fs_loader.h +++ b/include/firm/fs/ARM9/fs_loader.h @@ -26,28 +26,6 @@ extern "C" { #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 diff --git a/include/firm/fs/ARM9/fs_loader2.h b/include/firm/fs/ARM9/fs_loader2.h index edb22fb0..0d9aefd4 100644 --- a/include/firm/fs/ARM9/fs_loader2.h +++ b/include/firm/fs/ARM9/fs_loader2.h @@ -26,28 +26,6 @@ extern "C" { #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 diff --git a/include/firm/os/common/boot.h b/include/firm/os/common/boot.h index d4ec0318..5a3335ff 100644 --- a/include/firm/os/common/boot.h +++ b/include/firm/os/common/boot.h @@ -38,7 +38,7 @@ extern "C" { 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 diff --git a/include/firm/pm/ARM7/pm_init.h b/include/firm/pm/ARM7/pm_init.h index 055c8d93..765e5fc1 100644 --- a/include/firm/pm/ARM7/pm_init.h +++ b/include/firm/pm/ARM7/pm_init.h @@ -33,17 +33,6 @@ extern "C" { *---------------------------------------------------------------------------*/ 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 @@ -56,6 +45,17 @@ void PM_CheckINIFlag(void); *---------------------------------------------------------------------------*/ void PM_BackLightOn( BOOL force ); +/*---------------------------------------------------------------------------* + Name: PM_Shutdown + + Description: shutdown + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void PM_Shutdown( void ); + #ifdef __cplusplus } /* extern "C" */ #endif