TwlSDKの最新system callに対応

nand_formatterをLIMITEDを一時的にやめる

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@61 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
yutaka 2007-10-24 02:24:12 +00:00
parent bf5462bb6f
commit 625aefddc0
9 changed files with 31 additions and 323 deletions

View File

@ -48,145 +48,7 @@ static ROM_Header* const rh = (ROM_Header*)HW_TWL_ROM_HEADER_BUF;
#define HASH_UNIT 0x800 // TODO: optimizing to maximize cache efficiency
/*
SHA1
MATHライブラリやDGTライブラリと同じだが使
*/
typedef struct SHA1_CTX // 実際には、サイズが同じなら中身は何でも良い
{
u32 h0,h1,h2,h3,h4;
u32 Nl,Nh;
u32 data[16];
int num;
void (*sha_block)(struct SHA1_CTX *c, const u8 *W, int num);
}
SHA1_CTX;
static inline void SHA1_Init(SHA1_CTX *ctx)
{
if (ctx == NULL)
return;
MI_CpuClear8(ctx, sizeof(SHA1_CTX));
SVC_SHA1Init(ctx);
}
static inline void SHA1_Update(SHA1_CTX *ctx, const void* data, u32 len)
{
if (ctx == NULL)
return;
if (len > 0 && data == NULL)
return;
SVC_SHA1Update(ctx, data, len);
}
static inline void SHA1_GetHash(SHA1_CTX *ctx, u8* md)
{
if (ctx == NULL)
return;
if (md == NULL)
return;
SVC_SHA1GetHash(md, ctx);
}
static inline void SHA1_Calc(u8* md, const void* data, u32 len)
{
SVC_CalcSHA1(md, data, len);
}
/*
HMAC (SHA1)
MATHライブラリやDGTライブラリと同じだが使
*/
#define DIGEST_HASH_BLOCK_SIZE_SHA1 (512/8)
typedef struct HMAC_CTX
{
SHA1_CTX sha1_ctx;
u8 key[DIGEST_HASH_BLOCK_SIZE_SHA1];
u32 len;
} HMAC_CTX;
static inline void HMAC_Init( HMAC_CTX *ctx, const void *key, u32 len )
{
u8 ipad[DIGEST_HASH_BLOCK_SIZE_SHA1];
int i;
if ( ctx == NULL )
return;
if ( len > 0 && key == NULL )
return;
/* 鍵がブロック長よりも長い場合、ハッシュ値を鍵とする. */
if ( len > DIGEST_HASH_BLOCK_SIZE_SHA1 )
{
SHA1_Calc( ctx->key, key, len );
ctx->len = DIGEST_SIZE_SHA1;
}
else
{
MI_CpuCopy8( key, ctx->key, len );
ctx->len = len;
}
/* 鍵とipadのXOR */
for ( i = 0; i < ctx->len; i++ )
{
ipad[i] = (u8)(ctx->key[i] ^ 0x36);
}
/* 鍵のパディング部分とipadのXOR */
for ( ; i < DIGEST_HASH_BLOCK_SIZE_SHA1; i++ )
{
ipad[i] = 0x00 ^ 0x36;
}
/* メッセージとの結合とハッシュ値の計算 */
SHA1_Init( &ctx->sha1_ctx );
SHA1_Update( &ctx->sha1_ctx, ipad, DIGEST_HASH_BLOCK_SIZE_SHA1 );
}
static inline void HMAC_Update( HMAC_CTX *ctx, void *data, u32 len )
{
if ( ctx == NULL )
return;
if ( len > 0 && data == NULL )
return;
/* メッセージとの結合とハッシュ値の計算 */
SHA1_Update( &ctx->sha1_ctx, data, len );
}
static inline void HMAC_GetHash( HMAC_CTX *ctx, u8* md )
{
u8 opad[DIGEST_HASH_BLOCK_SIZE_SHA1];
u8 temp[20];
int i;
if ( ctx == NULL )
return;
if ( md == NULL )
return;
/* メッセージとの結合とハッシュ値の計算 */
SHA1_GetHash( &ctx->sha1_ctx, temp );
/* 鍵とopadのXOR */
for ( i = 0; i < ctx->len; i++ )
{
opad[i] = (u8)(ctx->key[i] ^ 0x5c);
}
/* 鍵のパディング部分とopadのXOR */
for ( ; i < DIGEST_HASH_BLOCK_SIZE_SHA1; i++ )
{
opad[i] = 0x00 ^ 0x5c;
}
/* ハッシュ値との結合とハッシュ値の計算 */
SHA1_Init( &ctx->sha1_ctx );
SHA1_Update( &ctx->sha1_ctx, opad, DIGEST_HASH_BLOCK_SIZE_SHA1 );
SHA1_Update( &ctx->sha1_ctx, temp, DIGEST_SIZE_SHA1 );
SHA1_GetHash( &ctx->sha1_ctx, md );
}
static const u8 s_digestDefaultKey[ DIGEST_HASH_BLOCK_SIZE_SHA1 ] = {
static const u8 s_digestDefaultKey[ SVC_SHA1_BLOCK_SIZE ] = {
0x21, 0x06, 0xc0, 0xde,
0xba, 0x98, 0xce, 0x3f,
0xa6, 0x92, 0xe3, 0x9d,
@ -216,14 +78,14 @@ static const u8 s_digestDefaultKey[ DIGEST_HASH_BLOCK_SIZE_SHA1 ] = {
ROMヘッダに付加された証明書のチェックを行います
makerom.TWL内のコードに依存します
Arguments: pool pointer to the pool info for SVC_DecryptoSign
Arguments: pool pointer to the SVCSignHeapContext
pCert pointer to the certification
pCAPubKey pointer to the public key for the certification
gameCode initial code
Returns: TRUE if success
*---------------------------------------------------------------------------*/
static BOOL CheckRomCertificate( int* pool, const RomCertificate *pCert, const void* pCAPubKey, u32 gameCode )
static BOOL CheckRomCertificate( SVCSignHeapContext* pool, const RomCertificate *pCert, const void* pCAPubKey, u32 gameCode )
{
u8 digest[DIGEST_SIZE_SHA1];
u8 md[DIGEST_SIZE_SHA1];
@ -238,10 +100,10 @@ static BOOL CheckRomCertificate( int* pool, const RomCertificate *pCert, const v
result = FALSE;
}
// 証明書署名チェック
SVC_DecryptoSign( pool, &digest, pCert->sign, pCAPubKey );
SVC_DecryptSign( pool, &digest, pCert->sign, pCAPubKey );
// ダイジェストの計算
SHA1_Calc( md, pCert, ROM_CERT_SIGN_OFFSET );
SVC_CalcSHA1( md, pCert, ROM_CERT_SIGN_OFFSET );
// 比較
for (i = 0; i < DIGEST_SIZE_SHA1; i++)
@ -261,8 +123,8 @@ static BOOL CheckRomCertificate( int* pool, const RomCertificate *pCert, const v
Description: receive data from ARM7 and store(move) via WRAM[B]
LoadBufferメカニズムでARM7から受け取ります
SHA1_CTXを指定していた場合SHA1の計算も
SVCSHA1Contextを指定していた場合SHA1の
[LoadBufferメカニズム]
WRAM[B]ARM7,ARM9間のデータ転送を行います
@ -283,11 +145,11 @@ static BOOL CheckRomCertificate( int* pool, const RomCertificate *pCert, const v
Arguments: dest destination address for received data
size size to load
ctx context for SHA1 if execute SHA1_Update
ctx context for SHA1 if execute SVC_SHA1Update
Returns: TRUE if success
*---------------------------------------------------------------------------*/
static BOOL MI_LoadBuffer(u8* dest, u32 size, SHA1_CTX *ctx)
static BOOL MI_LoadBuffer(u8* dest, u32 size, SVCSHA1Context *ctx)
{
u8* base = (u8*)HW_FIRM_LOAD_BUFFER_BASE;
static int count = 0;
@ -295,7 +157,7 @@ static BOOL MI_LoadBuffer(u8* dest, u32 size, SHA1_CTX *ctx)
{
u8* src = base + count * HW_FIRM_LOAD_BUFFER_UNIT_SIZE;
u32 unit = size < HW_FIRM_LOAD_BUFFER_UNIT_SIZE ? size : HW_FIRM_LOAD_BUFFER_UNIT_SIZE;
OS_TPrintf("%s: src=%X, unit=%X\n", __func__, src, unit);
//OS_TPrintf("%s: src=%X, unit=%X\n", __func__, src, unit);
if ( PXI_RecvID() != FIRM_PXI_ID_LOAD_PIRIOD )
{
return FALSE;
@ -314,7 +176,7 @@ OS_TPrintf("%s: src=%X, unit=%X\n", __func__, src, unit);
u8* s = src + done;
u8* d = dest + done;
u32 u = unit < done + HASH_UNIT ? unit - done : HASH_UNIT;
SHA1_Update( ctx, s, u );
SVC_SHA1Update( ctx, s, u );
MI_CpuCopyFast( s, d, u );
}
}
@ -351,17 +213,17 @@ OS_TPrintf("%s: src=%X, unit=%X\n", __func__, src, unit);
*---------------------------------------------------------------------------*/
static /*inline*/ BOOL MI_LoadModule(void* dest, u32 size, const u8 digest[DIGEST_SIZE_SHA1])
{
HMAC_CTX ctx;
SVCHMACSHA1Context ctx;
u8 md[DIGEST_SIZE_SHA1];
int i;
BOOL result = TRUE;
HMAC_Init(&ctx, s_digestDefaultKey, DIGEST_HASH_BLOCK_SIZE_SHA1 );
SVC_HMACSHA1Init(&ctx, s_digestDefaultKey, SVC_SHA1_BLOCK_SIZE );
if ( !MI_LoadBuffer( dest, size, &ctx.sha1_ctx ) ) // UpdateはSHA1と同じ処理
{
return FALSE;
}
HMAC_GetHash(&ctx, md);
SVC_HMACSHA1GetHash(&ctx, md);
#ifdef PROFILE_ENABLE
// xx: after SHA1
profile[pf_cnt++] = (u32)20202020; // checkpoint
@ -391,20 +253,20 @@ static /*inline*/ BOOL MI_LoadModule(void* dest, u32 size, const u8 digest[DIGES
seedデータを16バイト送信します
makerom.TWLまたはIPLの仕様に依存します
Arguments: pool pointer to the pool info for SVC_DecryptoSign
Arguments: pool pointer to the pool info for SVCSignHeapContext
rsa_key key address
Returns: TRUE if success
*---------------------------------------------------------------------------*/
BOOL MI_LoadHeader( int* pool, const void* rsa_key )
BOOL MI_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key )
{
SHA1_CTX ctx;
SVCSHA1Context ctx;
u8 md[DIGEST_SIZE_SHA1];
SignatureData sd;
int i;
BOOL result = TRUE;
SHA1_Init(&ctx);
SVC_SHA1Init(&ctx);
#ifdef PROFILE_ENABLE
pf_cnt = 10;
@ -420,7 +282,7 @@ BOOL MI_LoadHeader( int* pool, const void* rsa_key )
{
return FALSE;
}
SHA1_GetHash(&ctx, md);
SVC_SHA1GetHash(&ctx, md);
#ifdef PROFILE_ENABLE
// 1x: after HMAC
profile[pf_cnt++] = (u32)2020202020; // checkpoint
@ -443,7 +305,7 @@ BOOL MI_LoadHeader( int* pool, const void* rsa_key )
}
// ヘッダ署名チェック
SVC_DecryptoSign( pool, &sd, rh->signature, rsa_key );
SVC_DecryptSign( pool, &sd, rh->signature, rsa_key );
for (i = 0; i < DIGEST_SIZE_SHA1; i++)
{
if ( md[i] != sd.digest[i] )

View File

@ -17,7 +17,7 @@
#----------------------------------------------------------------------------
TARGET_PLATFORM = TWL
TWL_ARCHGEN = LIMITED
#TWL_ARCHGEN = LIMITED
TWL_PROC = ARM7
TWL_NO_STD_PCHDR = TRUE

View File

@ -38,6 +38,7 @@ Autoload WRAM
libpxi_sp.TWL$(CODEGEN).a \
libstd_sp.TWL$(CODEGEN).a \
libexi_sp.TWL$(CODEGEN).a \
libsnd_sp.TWL$(CODEGEN).a \
libspi_sp.TWL$(CODEGEN).a \
libpm_sp.TWL$(CODEGEN).a \
libcdc_sp.TWL$(CODEGEN).a \

View File

@ -19,7 +19,7 @@
TARGET_PLATFORM = TWL
TWL_PROC = ARM9
TWL_ARCHGEN = LIMITED
#TWL_ARCHGEN = LIMITED
TARGET_BIN = formatter.srl
MAKEROM_ARM7_BASE = ../ARM7/bin/$(TWL_BUILDTYPE_ARM7)/formatter_sub

View File

@ -22,7 +22,7 @@
#define RSA_HEAP_SIZE (4*1024) // RSA用ヒープサイズ (サイズ調整必要)
static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32)));
static int acPool[3];
static SVCSignHeapContext acPool;
/*
PROFILE_ENABLE
@ -109,10 +109,10 @@ void TwlMain( void )
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
SVC_InitSignHeap( acPool, acHeap, sizeof(acHeap) );
SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) );
// load menu
if ( MI_LoadHeader( acPool, RSA_KEY_ADDR ) && CheckHeader() && MI_LoadStatic() )
if ( MI_LoadHeader( &acPool, RSA_KEY_ADDR ) && CheckHeader() && MI_LoadStatic() )
{
#ifdef PROFILE_ENABLE
// 127: before Boot

View File

@ -33,7 +33,7 @@ static const u8 rsa_key[128] =
#define RSA_HEAP_SIZE (4*1024) // RSA用ヒープサイズ (サイズ調整必要)
static u8 acHeap[RSA_HEAP_SIZE] __attribute__ ((aligned (32)));
static int acPool[3];
static SVCSignHeapContext acPool;
/*
Profile
@ -111,10 +111,10 @@ void TwlMain( void )
profile[pf_cnt++] = (u32)OS_TicksToMicroSeconds(OS_GetTick());
#endif
SVC_InitSignHeap( acPool, acHeap, sizeof(acHeap) );
SVC_InitSignHeap( &acPool, acHeap, sizeof(acHeap) );
// load menu
if ( MI_LoadHeader( acPool, RSA_KEY_ADDR ) && CheckHeader() && MI_LoadStatic() )
if ( MI_LoadHeader( &acPool, RSA_KEY_ADDR ) && CheckHeader() && MI_LoadStatic() )
{
#ifndef SDK_FINALROM
// 127: before Boot

View File

@ -29,12 +29,12 @@ extern "C" {
Description: load header
Arguments: pool pointer to the pool info for SVC_DecryptoSign
Arguments: pool pointer to the pool info for SVCSignHeapContext
rsa_key key address
Returns: TRUE if success
*---------------------------------------------------------------------------*/
BOOL MI_LoadHeader( int* pool, const void* rsa_key );
BOOL MI_LoadHeader( SVCSignHeapContext* pool, const void* rsa_key );
/*---------------------------------------------------------------------------*
Name: MI_LoadStatic

View File

@ -22,7 +22,6 @@
#include <firm/os/common/init.h>
#include <firm/os/common/tick_brom.h>
#include <firm/os/common/boot.h>
#include <firm/os/common/systemCall.h>
#include <firm/os/common/system.h>
#ifdef __cplusplus

View File

@ -1,154 +0,0 @@
/*---------------------------------------------------------------------------*
Project: TwlFirm - OS - include
File: systemCall.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 FIRM_OS_SYSTEMCALL_H_
#define FIRM_OS_SYSTEMCALL_H_
#ifdef __cplusplus
extern "C" {
#endif
#define SVC_ID_PREMASK 0x3f
#define SVC_ID_SHIFT 1
#define SVC_ID_SEMIHOST_ARM 0x12
#define SVC_ID_SEMIHOST_THUMB 0xab
typedef enum
{
// TWL
SVC_ID_INIT_SIGN_HEAP = 32,
SVC_ID_DEC_RSA = 33,
SVC_ID_DEC_SIGN = 34,
SVC_ID_DEC_SIGN_DER = 35,
SVC_ID_SHA1_INIT = 36,
SVC_ID_SHA1_UPDATE = 37,
SVC_ID_SHA1_FINAL = 38,
SVC_ID_CALC_SHA1 = 39,
SVC_ID_CMP_SHA1 = 40,
SVC_ID_RAND_SHA1 = 41,
SVC_ID_LZ8_DEV = 1,
SVC_ID_LZ16_DEV_IMG = 2,
// reserve 0x2b for semihosting (0xab & 0x3f == 0x2b)
// DS compatible
SVC_ID_SOFT_RESET = 0,
SVC_ID_WAIT_BY_LOOP = 3,
SVC_ID_WAIT_INTR = 4,
SVC_ID_WAIT_VB_INTR = 5,
SVC_ID_HALT = 6,
SVC_ID_SLEEP = 7,
SVC_ID_SND_BIAS = 8,
SVC_ID_DIV = 9,
SVC_ID_CPU_SET = 11,
SVC_ID_CPU_SET_FAST = 12,
SVC_ID_SQRT = 13,
SVC_ID_CRC16 = 14,
SVC_ID_IS_MEMEX = 15,
SVC_ID_UNPACKBITS_DEV = 16,
SVC_ID_LZ8 = 17,
// overlap semihosting ((0x123456>>16) & 0x3f == 0x12)
SVC_ID_LZ16_DEV = 18,
SVC_ID_HUFF_DEV = 19,
SVC_ID_RL8 = 20,
SVC_ID_RL16_DEV = 21,
SVC_ID_DF8 = 22,
SVC_ID_DF16 = 24,
SVC_ID_SND_SIN = 26,
SVC_ID_SND_PITCH = 27,
SVC_ID_SND_VOL = 28,
SVC_ID_DS_IPL2 = 29,
SVC_ID_PAUSE_HI = 31
}
OSSvcID;
int SVC_InitSignHeap(
int acmemory_pool[3],
void* heap,
unsigned int length
);
int SVC_DecryptoRSA(
const void* acmemory_pool,
const void* pData,
unsigned int* len // 出力サイズ
);
int SVC_DecryptoSign(
const void* acmemory_pool,
void* buffer, // 出力領域
const void* sgn_ptr, // データへのポインタ
const void* key_ptr // キーへのポインタ
);
int SVC_DecryptoSignDER(
const void* acmemory_pool,
void* buffer, // 出力領域
const void* sgn_ptr, // データへのポインタ
const void* key_ptr // キーへのポインタ
);
void SVC_SHA1Init( void *c );
void SVC_SHA1Update( void *c, const unsigned char *data, unsigned long len );
void SVC_SHA1GetHash( unsigned char *md, void *c );
int SVC_CalcSHA1(
void* buffer, // 出力領域
const void* buf, // データへのポインタ
unsigned int len // データの長さ
);
int SVC_CompareSHA1(
const void* decedHash, // SVC_Decrypto*の出力
const void* digest // SVC_GetDigestの出力
);
int SVC_RandomSHA1(
void* dest_ptr, // 出力データへのポインタ
unsigned int dest_len, // 出力データの長さ
const void* src_ptr, // 入力データへのポインタ
unsigned int src_len // 入力データの長さ
);
int SVC_UncompressLZ8FromDevice( const void* srcp,
void* destp,
const void* paramp,
const MIReadStreamCallbacks *callbacks
);
int SVC_UncompressLZ16FromDeviceIMG( const void* srcp,
void* destp,
const void* paramp,
const MIReadStreamCallbacks *callbacks
);
#ifdef __cplusplus
} /* extern "C" */
#endif
/* FIRM_OS_SYSTEMCALL_H_ */
#endif