mirror of
https://github.com/rvtr/TwlIPL.git
synced 2025-10-31 06:01:12 -04:00
整理して動作する状況にしました。
makerom.TWLで正しいWRAM設定をするように修正しました。 git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@30 b08762b0-b915-fc4b-9d8c-17b2551a87ff
This commit is contained in:
parent
6f941d89ab
commit
3e42dd4a87
@ -151,6 +151,7 @@ TWL_BUILDARCH ?= $(FIRM_BUILDARCH)
|
||||
ifneq ($(FIRM_TARGET),APP)
|
||||
LCFILE_TEMPLATE ?= $(DEFAULT_FIRM_LCFILE_TEMPLATE)
|
||||
LCFILE_SPEC ?= $(DEFAULT_FIRM_LCFILE_SPEC)
|
||||
ROM_SPEC ?= $(DEFAULT_FIRM_ROM_SPEC)
|
||||
endif # FIRM_TARGET!=APP
|
||||
|
||||
LDEPENDS_LCF += $(FIRM_BUILDTOOLSDIR)/commondefs
|
||||
|
||||
@ -28,18 +28,15 @@ FIRM_CODEGEN_ALL ?= TRUE
|
||||
# Codegen for sub processer
|
||||
FIRM_PROC = ARM7
|
||||
|
||||
INCDIR = rom_sdmc \
|
||||
INCDIR = \
|
||||
$(TWLSDK_ROOT)/build/libraries/fatfs/ARM7.TWL/include \
|
||||
$(TWLSDK_ROOT)/build/libraries/fatfs/ARM7.TWL/include/twl/fatfs/ARM7
|
||||
|
||||
SRCDIR = src rom_sdmc
|
||||
SRCDIR = src
|
||||
|
||||
SRCS = \
|
||||
fatfs_loader.c \
|
||||
fatfs_firm.c \
|
||||
# sdmc.c \
|
||||
# sdmc_nandinit.c \
|
||||
# drsdmc.c \
|
||||
|
||||
|
||||
TARGET_LIB = libfatfs_sp$(FIRM_LIBSUFFIX).a
|
||||
|
||||
@ -1,687 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CTR - rtfs interface for SD Memory Card
|
||||
File: drsdmc.h
|
||||
|
||||
Copyright 2006,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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <rtfs.h>
|
||||
#include <portconf.h>
|
||||
//#if (INCLUDE_SD)
|
||||
|
||||
//#include "sdmc_config.h"
|
||||
//#include "sdmc.h"
|
||||
//#include "sdif_ip.h"
|
||||
//#include "sdif_reg.h"
|
||||
#include <firm/sdmc.h>
|
||||
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define PRINTDEBUG osTPrintf
|
||||
#else
|
||||
#include <ctr/vlink.h>
|
||||
#define PRINTDEBUG vlink_dos_printf
|
||||
#endif
|
||||
#else
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#define NUM_SD_PAGES
|
||||
#define SD_PAGE_SIZE
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
//extern ER_ID sdmc_dtq_id;
|
||||
//extern ER_ID sdmc_result_dtq_id;
|
||||
extern void (*func_SDCARD_In)(void); /* カード挿入イベント用コールバック保存用 */
|
||||
extern void (*func_SDCARD_Out)(void); /* カード排出イベント用コールバック保存用 */
|
||||
extern volatile s16 SDCARD_OutFlag; /* カード排出発生判定フラグ */
|
||||
|
||||
extern int rtfs_first_stat_flag[26];
|
||||
|
||||
/*SDメモリカードのスペック構造体*/
|
||||
extern SdmcSpec sdmc_current_spec;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern SDMC_ERR_CODE sdmcGoIdle(void (*func1)(),void (*func2)());
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
static int sdmc_drive_no;
|
||||
void (*func_usr_sdmc_out)(void) = NULL; /* カード排出イベントのユーザコールバック */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void);
|
||||
static void sdi_get_CHS_params( void);
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval);
|
||||
static void sdi_get_nom( void);
|
||||
static void sdi_get_fatparams( void);
|
||||
static void sdi_build_partition_table( void);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcCheckMedia
|
||||
|
||||
Description: MBRのシグネチャおよび
|
||||
パーティションのフォーマット種別をチェックする
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
(FALSEなら pc_format_media が必要)
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcCheckMedia( void)
|
||||
{
|
||||
u16 i;
|
||||
SdmcResultInfo SdResult;
|
||||
u8* bufp;
|
||||
u32 buffer[512/4];
|
||||
u8 systemid;
|
||||
|
||||
/**/
|
||||
if( sdmcReadFifo( buffer, 1, 0, NULL, &SdResult)) {
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
bufp = (u8*)buffer;
|
||||
|
||||
/* Check the Signature Word. */
|
||||
if( (bufp[510]!=0x55) || (bufp[511]!=0xAA)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of partition. */
|
||||
systemid = bufp[450];
|
||||
if( (systemid!=0x01) && (systemid!=0x04) && (systemid!=0x06) &&
|
||||
(systemid!=0x0B) && (systemid!=0x0C)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of unuse partitions. */
|
||||
for( i=1; i<4; i++) {
|
||||
systemid = bufp[450+(16*i)];
|
||||
if( systemid != 0x00) {
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
/*もっと厳密にチェックするならパーティション0開始位置の
|
||||
正当性も調べる*/
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsIo
|
||||
|
||||
Description: 上位層からのセクタリード/ライト要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
block : 開始ブロック番号
|
||||
buffer :
|
||||
count : ブロック数
|
||||
reading : リード要求時にTRUE
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading)
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
if( reading) {
|
||||
PRINTDEBUG( "DEVCTL_IO_READ ... block:%x, count:%x -> buf:%x\n", block, count, buffer);
|
||||
result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVCTL_IO_WRITE ... block:%x, count:%x <- buf:%x\n", block, count, buffer);
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsCtrl
|
||||
|
||||
Description: 上位層からのコントロール要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
opcode : 要求の種類
|
||||
pargs :
|
||||
|
||||
Returns:
|
||||
Memo : DRIVE_FLAGS_REMOVABLEの場合、ドライバのIO関数を呼ぶ前に
|
||||
CTRL関数のDEVCTL_CHECK_STATUSが呼ばれる。
|
||||
DEVTEST_CHANGED→DEVTEST_NOCHANGEが確認されるとRTFSはセクタ0を
|
||||
読みに行き、FATパラメータを取得した上で目的のセクタを読みに行く。
|
||||
CTRL関数の前にはDEVCTL_CHECK_STATUSが呼ばれないので、DEVCTL_
|
||||
GET_GEOMETRYでは自前で再挿入をチェックする必要がある。
|
||||
*---------------------------------------------------------------------------*/
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
DEV_GEOMETRY gc;
|
||||
int heads, secptrack;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( driveno);
|
||||
|
||||
switch( opcode) {
|
||||
case DEVCTL_GET_GEOMETRY: //formatまたはpartirionするときにRTFSが使うパラメータ
|
||||
PRINTDEBUG( "DEVCTL_GET_GEOMETRY\n");
|
||||
if( (pdr->drive_flags & DRIVE_FLAGS_INSERTED) == 0) { /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == TRUE) { /* 今現在も抜かれているとき */
|
||||
return( -1);
|
||||
}else{ /* 今現在は再挿入されているとき */
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
}
|
||||
}
|
||||
|
||||
rtfs_memset( &gc, (byte)0, sizeof(gc));
|
||||
|
||||
sdi_get_CHS_params(); //最初に呼ぶこと
|
||||
sdi_get_fatparams();
|
||||
sdi_get_nom();
|
||||
|
||||
PRINTDEBUG( "heads : 0x%x\n", sdmc_current_spec.heads);
|
||||
PRINTDEBUG( "secptrack : 0x%x\n", sdmc_current_spec.secptrack);
|
||||
PRINTDEBUG( "cylinders : 0x%x\n", sdmc_current_spec.cylinders);
|
||||
PRINTDEBUG( "SC : 0x%x\n", sdmc_current_spec.SC);
|
||||
PRINTDEBUG( "BU : 0x%x\n", sdmc_current_spec.BU);
|
||||
PRINTDEBUG( "RDE : 0x%x\n", sdmc_current_spec.RDE);
|
||||
PRINTDEBUG( "SS : 0x%x\n", sdmc_current_spec.SS);
|
||||
PRINTDEBUG( "RSC : 0x%x\n", sdmc_current_spec.RSC);
|
||||
PRINTDEBUG( "FATBITS : 0x%x\n", sdmc_current_spec.FATBITS);
|
||||
PRINTDEBUG( "SF : 0x%x\n", sdmc_current_spec.SF);
|
||||
PRINTDEBUG( "SSA : 0x%x\n", sdmc_current_spec.SSA);
|
||||
PRINTDEBUG( "NOM : 0x%x\n", sdmc_current_spec.NOM);
|
||||
|
||||
gc.dev_geometry_lbas = (sdmc_current_spec.adjusted_memory_capacity);// - sdmc_current_spec.NOM);
|
||||
gc.dev_geometry_heads = sdmc_current_spec.heads;
|
||||
gc.dev_geometry_cylinders = sdmc_current_spec.cylinders;
|
||||
gc.dev_geometry_secptrack = sdmc_current_spec.secptrack;
|
||||
/**/
|
||||
gc.fmt_parms_valid = TRUE;
|
||||
gc.fmt.oemname[0] = 'C';
|
||||
gc.fmt.oemname[1] = 'T';
|
||||
gc.fmt.oemname[2] = 'R';
|
||||
gc.fmt.oemname[3] = '\0';
|
||||
gc.fmt.secpalloc = sdmc_current_spec.SC; /*sectors per cluster(FIX by capacity)*/
|
||||
gc.fmt.secreserved = sdmc_current_spec.RSC;//sdmc_current_spec.RSC;/*reserved sectors(FIX 1 at FAT12,16)*/
|
||||
gc.fmt.numfats = 2;
|
||||
gc.fmt.secpfat = sdmc_current_spec.SF;
|
||||
gc.fmt.numhide = sdmc_current_spec.NOM; /**/
|
||||
gc.fmt.numroot = sdmc_current_spec.RDE; /*FIX*/
|
||||
gc.fmt.mediadesc = 0xF8;
|
||||
gc.fmt.secptrk = sdmc_current_spec.secptrack; //CHS Recommendation
|
||||
gc.fmt.numhead = sdmc_current_spec.heads;
|
||||
gc.fmt.numcyl = sdmc_current_spec.cylinders;
|
||||
gc.fmt.physical_drive_no = driveno;
|
||||
gc.fmt.binary_volume_label = BIN_VOL_LABEL;
|
||||
gc.fmt.text_volume_label[0] = '\0';
|
||||
//TODO:dev_geometry_lbasもセットする必要あるか調べること
|
||||
PRINTDEBUG( "heads : 0x%x, secptrack : 0x%x, cylinders : 0x%x\n", gc.dev_geometry_heads, gc.dev_geometry_secptrack, gc.dev_geometry_cylinders);
|
||||
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuCopy8( &gc, pargs, sizeof(gc));
|
||||
// copybuff( pargs, &gc, sizeof(gc));
|
||||
#else
|
||||
MI_CpuCopy8( &gc, pargs, sizeof(gc));
|
||||
#endif
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_FORMAT:
|
||||
PRINTDEBUG( "DEVCTL_FORMAT\n");
|
||||
sdi_build_partition_table(); //MBRセクタ(パーティションテーブル含む)書き込み
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_REPORT_REMOVE: //抜かれたとき
|
||||
PRINTDEBUG( "DEVCTL_REPORT_REMOVE\n");
|
||||
pdr->drive_flags &= ~DRIVE_FLAGS_INSERTED;
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_CHECKSTATUS: //REMOVABLEの場合、毎回R/W前に呼ばれる
|
||||
PRINTDEBUG( "DEVCTL_CHECKSTATUS\n");
|
||||
if (!(pdr->drive_flags & DRIVE_FLAGS_REMOVABLE)) { //リムーバブルでない場合
|
||||
return(DEVTEST_NOCHANGE);
|
||||
}
|
||||
if (pdr->drive_flags & DRIVE_FLAGS_INSERTED) { /* 抜かれてない場合 */
|
||||
if( rtfs_first_stat_flag[driveno]) { //初回のCHECKSTATUS時
|
||||
rtfs_first_stat_flag[driveno] = 0;
|
||||
PRINTDEBUG( "CHANGED!\n");
|
||||
return(DEVTEST_CHANGED);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOCHANGE\n");
|
||||
return( DEVTEST_NOCHANGE);
|
||||
}
|
||||
}else{ /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
PRINTDEBUG( "DEVTEST_CHANGED\n");
|
||||
return( DEVTEST_CHANGED); //挿さっている
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOMEDIA\n");
|
||||
return( DEVTEST_NOMEDIA); //挿さってない
|
||||
}
|
||||
}
|
||||
|
||||
case DEVCTL_WARMSTART: //attachのときしか呼ばれない
|
||||
PRINTDEBUG( "DEVCTL_WARMSTART\n");
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
pdr->drive_flags |= (DRIVE_FLAGS_VALID | DRIVE_FLAGS_REMOVABLE | DRIVE_FLAGS_PARTITIONED);
|
||||
pdr->partition_number = 0;
|
||||
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
}else{ /* カード未挿入のとき */
|
||||
pdr->drive_flags &= (~(DRIVE_FLAGS_INSERTED)); //抜かれているだけではVALIDフラグは落とさないらしい
|
||||
}
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_POWER_RESTORE:
|
||||
PRINTDEBUG( "DEVCTL_POWER_RESTORE\n");
|
||||
break;
|
||||
|
||||
case DEVCTL_POWER_LOSS:
|
||||
PRINTDEBUG( "DEVCTL_POWER_LOSS\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINTDEBUG( "DEVCTL_unknown\n");
|
||||
break;
|
||||
}
|
||||
return( 0);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
抜取コールバック関数
|
||||
|
||||
RTFSが次回"DEVCTL_GET_GEOMETRY"を行うとき、ここでセットしたパラメータを知る
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( sdmc_drive_no);
|
||||
if( pdr) {
|
||||
pdr->dev_table_perform_device_ioctl( pdr->driveno,
|
||||
DEVCTL_REPORT_REMOVE,
|
||||
(void*)0);
|
||||
}
|
||||
|
||||
if( func_usr_sdmc_out) {
|
||||
func_usr_sdmc_out(); //ユーザコールバック
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsAttach
|
||||
|
||||
Description: sdmcドライバをドライブに割り当てる
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsAttach( int driveno)
|
||||
{
|
||||
BOOLEAN result;
|
||||
DDRIVE pdr;
|
||||
|
||||
pdr.dev_table_drive_io = sdmcRtfsIo;
|
||||
pdr.dev_table_perform_device_ioctl = sdmcRtfsCtrl;
|
||||
pdr.register_file_address = (dword) 0; /* Not used */
|
||||
pdr.interrupt_number = 0; /* Not used */
|
||||
pdr.drive_flags = 0;//DRIVE_FLAGS_FAILSAFE;
|
||||
pdr.partition_number = 0; /* Not used */
|
||||
pdr.pcmcia_slot_number = 0; /* Not used */
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
result = rtfs_attach( driveno, &pdr, "SD"); //構造体がFSライブラリ側にコピーされる
|
||||
|
||||
/*drivenoをグローバル変数に記憶*/
|
||||
sdmc_drive_no = driveno;
|
||||
|
||||
return( result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*SD File System Specification(仕様書)に基づいた値を出す*/
|
||||
static void sdi_get_CHS_params( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
while( 1) {
|
||||
if( mbytes <= 2) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 16;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 16) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32) {
|
||||
sdmc_current_spec.heads = 4;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 128) {
|
||||
sdmc_current_spec.heads = 8;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 504) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 1008) {
|
||||
sdmc_current_spec.heads = 32;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2016) {
|
||||
sdmc_current_spec.heads = 64;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 4032) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.heads = 255;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*シリンダ数を計算*/
|
||||
sdmc_current_spec.cylinders = (sdmc_current_spec.memory_capacity /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack));
|
||||
|
||||
/*memory_capacityを再計算してadjusted_memory_capacityに格納*/
|
||||
sdmc_current_spec.adjusted_memory_capacity = sdmc_current_spec.cylinders *
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
}
|
||||
|
||||
|
||||
/*引数を超える最も小さい整数を算出する*/
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval)
|
||||
{
|
||||
return( (cval / mval) + (1 * (cval % mval != 0)));
|
||||
}
|
||||
|
||||
|
||||
/*マスターブートセクタのセクタ数を返す*/
|
||||
static void sdi_get_nom( void)
|
||||
{
|
||||
u32 RSC = 1; //FAT12,16では1
|
||||
u32 RDE = 512; //ルートディレクトリエントリ。FIX
|
||||
u32 SS = 512; //セクタサイズ。FIX
|
||||
u32 TS, SC, n;
|
||||
u32 MAX, SFdash;
|
||||
|
||||
TS = sdmc_current_spec.adjusted_memory_capacity;
|
||||
SC = sdmc_current_spec.SC;
|
||||
|
||||
sdmc_current_spec.SF = sdi_get_ceil( TS/SC * sdmc_current_spec.FATBITS, SS*8);
|
||||
|
||||
/*-----------------------SDHCのとき----------------------------*/
|
||||
if( sdmc_current_spec.csd_ver2_flag) {
|
||||
sdmc_current_spec.NOM = sdmc_current_spec.BU;
|
||||
do {
|
||||
n = sdi_get_ceil( 2*sdmc_current_spec.SF, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.RSC = (sdmc_current_spec.BU * n) - ( 2 * sdmc_current_spec.SF);
|
||||
if( sdmc_current_spec.RSC < 9) {
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}
|
||||
sdmc_current_spec.SSA = sdmc_current_spec.RSC + (2 * sdmc_current_spec.SF);
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SSA += sdmc_current_spec.BU;
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF -= 1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
}else{ /*-------------------------SDのとき-------------------------------*/
|
||||
do {
|
||||
sdmc_current_spec.SSA = RSC + ( 2 * sdmc_current_spec.SF) + sdi_get_ceil( 32*RDE, SS);
|
||||
n = sdi_get_ceil( sdmc_current_spec.SSA, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.NOM = (sdmc_current_spec.BU * n) - sdmc_current_spec.SSA;
|
||||
if( sdmc_current_spec.NOM != sdmc_current_spec.BU) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF = SFdash;
|
||||
}else{
|
||||
break; //complete
|
||||
}
|
||||
}while( 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*FATのビット数を返す*/
|
||||
static void sdi_get_fatparams( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.FATBITS = 12;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.FATBITS = 16;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
sdmc_current_spec.FATBITS = 32;
|
||||
sdmc_current_spec.RDE = 0; //FAT32のときは未使用。0にしておかないとRTFSが BAD FORMAT を返す。
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( mbytes <= 8) {
|
||||
sdmc_current_spec.SC = 16;
|
||||
sdmc_current_spec.BU = 16;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 32;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 64;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 1024) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 8192;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションセクタ含む)を生成して書き込む*/
|
||||
static void sdi_build_partition_table( void)
|
||||
{
|
||||
u16 MbrSectDat[512/2];
|
||||
u32 starting_head, starting_sect, starting_cyl;
|
||||
u32 ending_head, ending_sect, ending_cyl;
|
||||
u32 total_sect;
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
u32 starting_data, ending_data;
|
||||
#endif
|
||||
u32 systemid;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
/**/
|
||||
starting_head = sdmc_current_spec.NOM % (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
starting_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
starting_sect = (sdmc_current_spec.NOM % sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
starting_cyl = sdmc_current_spec.NOM / (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
total_sect = (sdmc_current_spec.adjusted_memory_capacity - sdmc_current_spec.NOM);
|
||||
ending_head = (sdmc_current_spec.NOM + total_sect - 1) %
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
ending_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
ending_sect = ((sdmc_current_spec.NOM + total_sect - 1) %
|
||||
sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
ending_cyl = (sdmc_current_spec.NOM + total_sect - 1) /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
if( sdmc_current_spec.FATBITS == 32) { //FAT32のとき
|
||||
if( total_sect < 0xFB0400) { //8032.5MBが閾値(SD FileSystemSpec2.00参照)
|
||||
systemid = 0x0B; /* FAT32 */
|
||||
}else{
|
||||
systemid = 0x0C; /* FAT32(拡張INT13対応) */
|
||||
}
|
||||
}else{ //FAT12,FAT16のとき
|
||||
if( total_sect < 32680) {
|
||||
systemid = 0x01; /* FAT12 */
|
||||
}else if( total_sect < 65536) {
|
||||
systemid = 0x04; /* FAT16(16MB~32MB未満) */
|
||||
}else{
|
||||
systemid = 0x06; /* FAT16(32MB~4GB) */
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションテーブル含む)作成*/
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuFill8( MbrSectDat, 0, 512);
|
||||
#else
|
||||
MI_CpuFill8( MbrSectDat, 0, 512);
|
||||
#endif
|
||||
MbrSectDat[446/2] = (starting_head<<8);
|
||||
//上位8bit:starting_cylの下位8bit, 下位8bit:starting_cylの上位2bit + starting_sect 6bit.
|
||||
MbrSectDat[448/2] = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
MbrSectDat[450/2] = (ending_head<<8) + systemid;
|
||||
//上位8bit:ending_cylの下位8bit, 下位8bit:ending_cylの上位2bit + ending_sect 6bit.
|
||||
MbrSectDat[452/2] = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
MbrSectDat[454/2] = sdmc_current_spec.NOM;
|
||||
MbrSectDat[456/2] = (sdmc_current_spec.NOM>>16);
|
||||
MbrSectDat[458/2] = total_sect;
|
||||
MbrSectDat[460/2] = (total_sect>>16);
|
||||
MbrSectDat[510/2] = 0xAA55;
|
||||
/*セクタ0に書き込み*/
|
||||
sdmcWriteFifo( MbrSectDat, 1, 0, NULL, &SdResult);
|
||||
|
||||
/**/
|
||||
PRINTDEBUG( "total sect : 0x%x\n", total_sect);
|
||||
PRINTDEBUG( "starting head : 0x%x\n", starting_head);
|
||||
PRINTDEBUG( "starting sect : 0x%x\n", starting_sect);
|
||||
PRINTDEBUG( "starting cyl : 0x%x\n", starting_cyl);
|
||||
PRINTDEBUG( "ending head : 0x%x\n", ending_head);
|
||||
PRINTDEBUG( "ending sect : 0x%x\n", ending_sect);
|
||||
PRINTDEBUG( "ending cyl : 0x%x\n", ending_cyl);
|
||||
PRINTDEBUG( "\n");
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
starting_data = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
PRINTDEBUG( "starting data : 0x%x\n", starting_data);
|
||||
ending_data = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
PRINTDEBUG( "endign data : 0x%x\n", ending_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//#endif /*(INCLUDE_SD)*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,246 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project:
|
||||
File: sdmc_port.c
|
||||
|
||||
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.
|
||||
|
||||
$Log: sdmc_port.c,v $
|
||||
$NoKeywords: $
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <firm.h>
|
||||
#include "sdmc_config.h"
|
||||
#include "sdif_reg.h"
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc.h>
|
||||
#include "sdif_ip.h"
|
||||
|
||||
|
||||
// #define PRINTDEBUG OS_TPrintf
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
|
||||
|
||||
|
||||
/*extern変数(sdmc.c)*/
|
||||
extern u32 SDCARD_SectorSize; /* セクタサイズ デフォルト 512bytes */
|
||||
extern SDMC_ERR_CODE SDCARD_ErrStatus; /* エラーステータス */
|
||||
extern volatile s16 SDCARD_OutFlag; /* カード排出発生判定フラグ */
|
||||
|
||||
|
||||
extern SDPortContext SDPort0Context;
|
||||
extern SDPortContext SDPort1Context;
|
||||
|
||||
|
||||
/*extern関数(sdmc.c)*/
|
||||
extern void i_sdmcCalcSize( void);
|
||||
extern void SDCARD_Backup_port1(void);
|
||||
extern void SDCARD_Restore_port1(void);
|
||||
extern SDMC_ERR_CODE SDCARD_Layer_Init(void);
|
||||
extern void SDCARD_TimerStop(void); /* タイムアウト計測停止 */
|
||||
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no);
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no);
|
||||
|
||||
static void sdmcPrintContext( SDPortContext* targ);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcClearPortContext
|
||||
|
||||
Description:
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void sdmcClearPortContext( SDPortContext* buf_adr)
|
||||
{
|
||||
MI_CpuFill8( buf_adr, 0x00, sizeof(SDPortContext));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcCheckPortContext
|
||||
|
||||
Description:
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcCheckPortContext( SDPortContext* buf_adr)
|
||||
{
|
||||
if( (buf_adr->SD_CID[0] != 0)&&(buf_adr->port_no < 2)) {
|
||||
return( SDMC_NORMAL);
|
||||
}else{
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcSavePortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファに退避する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( &SDPort0Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( &SDPort1Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcLoadPortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファから復帰する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( buf_adr->port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( buf_adr, &SDPort0Context, sizeof(SDPortContext));
|
||||
*port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( buf_adr, &SDPort1Context, sizeof(SDPortContext));
|
||||
*port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_sdmcMPInitFirm
|
||||
|
||||
Description: initialize SD card in multi ports.
|
||||
マルチポートのSDカード初期化
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE i_sdmcMPInitFirm( void)
|
||||
{
|
||||
u16 load_port_no;
|
||||
SDPortContext* SDNandContext;
|
||||
|
||||
//予約領域のポートコンテキスト参照
|
||||
SDNandContext = (SDPortContext*)&(((OSFromBromBuf*)OSi_GetFromBromAddr())->SDNandContext);
|
||||
|
||||
#if 0
|
||||
sdmcPrintContext( SDNandContext);
|
||||
#endif
|
||||
|
||||
//NANDスロットの初期化
|
||||
SD_SetFPGA( SD_PORTSEL, SDMC_PORT_NAND); /* NANDポート選択 */
|
||||
|
||||
PRINTDEBUG( "SDNandContext : 0x%x\n", SDNandContext);
|
||||
//初期化済みでないときだけ初期化
|
||||
if( sdmcCheckPortContext( SDNandContext) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "sdmcCheckPortContext : ERR!\n");
|
||||
SDCARD_ErrStatus = SDCARD_Layer_Init();
|
||||
|
||||
SDCARD_Backup_port1(); //TODO:ポート番号
|
||||
//ポートコンテキストの保存
|
||||
if( i_sdmcSavePortContext( SDNandContext, 1) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "i_sdmcSavePortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}else{ //ポートコンテキストの復帰
|
||||
PRINTDEBUG( "sdmcCheckPortContext : NORMAL\n");
|
||||
|
||||
/*SDCARD_Layer_Init()の代わり*/
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
// SD_SetFPGA(SD_CLK_CTRL,(SD_CLK_CTRL_128)); /* SDクロックの周波数 261KHz(初期化時は100~400khz) */
|
||||
|
||||
if( i_sdmcLoadPortContext( SDNandContext, &load_port_no) != SDMC_NORMAL) {
|
||||
PRINTDEBUG( "i_sdmcLoadPortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
SDCARD_Restore_port1(); //TODO:load_port_no値判定
|
||||
}
|
||||
|
||||
SDCARD_OutFlag = FALSE; /* 排出フラグをリセット */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
SD_DisableClock(); /* SD-CLK Disable */
|
||||
SD_EnableInfo(); /* SD Card 挿抜 割り込み許可 */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
|
||||
/*デバッグ用*/
|
||||
static void sdmcPrintContext( SDPortContext* targ)
|
||||
{
|
||||
OS_TPrintf( "CID[0]:0x%x\n", targ->SD_CID[0]);
|
||||
OS_TPrintf( "CID[1]:0x%x\n", targ->SD_CID[1]);
|
||||
OS_TPrintf( "CID[2]:0x%x\n", targ->SD_CID[2]);
|
||||
OS_TPrintf( "CID[3]:0x%x\n", targ->SD_CID[3]);
|
||||
OS_TPrintf( "CID[4]:0x%x\n", targ->SD_CID[4]);
|
||||
OS_TPrintf( "CID[5]:0x%x\n", targ->SD_CID[5]);
|
||||
OS_TPrintf( "CID[6]:0x%x\n", targ->SD_CID[6]);
|
||||
OS_TPrintf( "CID[7]:0x%x\n\n", targ->SD_CID[7]);
|
||||
|
||||
OS_TPrintf( "CSD[0]:0x%x\n", targ->SD_CSD[0]);
|
||||
OS_TPrintf( "CSD[1]:0x%x\n", targ->SD_CSD[1]);
|
||||
OS_TPrintf( "CSD[2]:0x%x\n", targ->SD_CSD[2]);
|
||||
OS_TPrintf( "CSD[3]:0x%x\n", targ->SD_CSD[3]);
|
||||
OS_TPrintf( "CSD[4]:0x%x\n", targ->SD_CSD[4]);
|
||||
OS_TPrintf( "CSD[5]:0x%x\n", targ->SD_CSD[5]);
|
||||
OS_TPrintf( "CSD[6]:0x%x\n", targ->SD_CSD[6]);
|
||||
OS_TPrintf( "CSD[7]:0x%x\n\n", targ->SD_CSD[7]);
|
||||
|
||||
OS_TPrintf( "OCR[0]:0x%x\n", targ->SD_OCR[0]);
|
||||
OS_TPrintf( "OCR[1]:0x%x\n\n", targ->SD_OCR[1]);
|
||||
|
||||
OS_TPrintf( "SCR[0]:0x%x\n", targ->SD_SCR[0]);
|
||||
OS_TPrintf( "SCR[1]:0x%x\n\n", targ->SD_SCR[1]);
|
||||
|
||||
OS_TPrintf( "RCA:0x%x\n\n", targ->SD_RCA);
|
||||
|
||||
OS_TPrintf( "MMCFlag :0x%x\n", targ->MMCFlag);
|
||||
OS_TPrintf( "SDHCFlag:0x%x\n", targ->SDHCFlag);
|
||||
OS_TPrintf( "SDFlag :0x%x\n\n", targ->SDFlag);
|
||||
|
||||
OS_TPrintf( "ErrStatus:0x%x\n", targ->ErrStatus);
|
||||
OS_TPrintf( "Status:0x%x\n\n", targ->Status);
|
||||
|
||||
OS_TPrintf( "SD_CLK_CTRL_VALUE:0x%x\n", targ->SD_CLK_CTRL_VALUE);
|
||||
OS_TPrintf( "SD_OPTION_VALUE :0x%x\n\n", targ->SD_OPTION_VALUE);
|
||||
|
||||
OS_TPrintf( "OutFlag:0x%x\n\n", targ->OutFlag);
|
||||
|
||||
OS_TPrintf( "port_no:0x%x\n", targ->port_no);
|
||||
}
|
||||
@ -1,686 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlBrom - rtfs interface for SD Memory Card
|
||||
File: drsdmc.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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <rtfs.h>
|
||||
#include <portconf.h>
|
||||
//#if (INCLUDE_SD)
|
||||
|
||||
#include "sdmc_config.h"
|
||||
//#include "sdmc.h"
|
||||
#include "sdif_ip.h"
|
||||
#include "sdif_reg.h"
|
||||
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define PRINTDEBUG osTPrintf
|
||||
#else
|
||||
#include <ctr/vlink.h>
|
||||
#define PRINTDEBUG vlink_dos_printf
|
||||
#endif
|
||||
#else
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#define NUM_SD_PAGES
|
||||
#define SD_PAGE_SIZE
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
//extern ER_ID sdmc_dtq_id;
|
||||
//extern ER_ID sdmc_result_dtq_id;
|
||||
extern void (*func_SDCARD_In)(void); /* カード挿入イベント用コールバック保存用 */
|
||||
extern void (*func_SDCARD_Out)(void); /* カード排出イベント用コールバック保存用 */
|
||||
extern volatile s16 SDCARD_OutFlag; /* カード排出発生判定フラグ */
|
||||
|
||||
extern int rtfs_first_stat_flag[26];
|
||||
|
||||
/*SDメモリカードのスペック構造体*/
|
||||
extern SdmcSpec sdmc_current_spec;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
extern関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
extern SDMC_ERR_CODE sdmcGoIdle(void (*func1)(),void (*func2)());
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
static int sdmc_drive_no;
|
||||
void (*func_usr_sdmc_out)(void) = NULL; /* カード排出イベントのユーザコールバック */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void);
|
||||
static void sdi_get_CHS_params( void);
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval);
|
||||
static void sdi_get_nom( void);
|
||||
static void sdi_get_fatparams( void);
|
||||
static void sdi_build_partition_table( void);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcCheckMedia
|
||||
|
||||
Description: MBRのシグネチャおよび
|
||||
パーティションのフォーマット種別をチェックする
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
(FALSEなら pc_format_media が必要)
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcCheckMedia( void)
|
||||
{
|
||||
u16 i;
|
||||
SdmcResultInfo SdResult;
|
||||
u8* bufp;
|
||||
u32 buffer[512/4];
|
||||
u8 systemid;
|
||||
|
||||
/**/
|
||||
if( sdmcReadFifo( buffer, 1, 0, NULL, &SdResult)) {
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
bufp = (u8*)buffer;
|
||||
|
||||
/* Check the Signature Word. */
|
||||
if( (bufp[510]!=0x55) || (bufp[511]!=0xAA)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of partition. */
|
||||
systemid = bufp[450];
|
||||
if( (systemid!=0x01) && (systemid!=0x04) && (systemid!=0x06) &&
|
||||
(systemid!=0x0B) && (systemid!=0x0C)) {
|
||||
return( FALSE);
|
||||
}
|
||||
/* Check the System ID of unuse partitions. */
|
||||
for( i=1; i<4; i++) {
|
||||
systemid = bufp[450+(16*i)];
|
||||
if( systemid != 0x00) {
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
/*もっと厳密にチェックするならパーティション0開始位置の
|
||||
正当性も調べる*/
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsIo
|
||||
|
||||
Description: 上位層からのセクタリード/ライト要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
block : 開始ブロック番号
|
||||
buffer :
|
||||
count : ブロック数
|
||||
reading : リード要求時にTRUE
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading)
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
if( reading) {
|
||||
PRINTDEBUG( "DEVCTL_IO_READ ... block:%x, count:%x -> buf:%x\n", block, count, buffer);
|
||||
result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVCTL_IO_WRITE ... block:%x, count:%x <- buf:%x\n", block, count, buffer);
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsCtrl
|
||||
|
||||
Description: 上位層からのコントロール要求を受ける
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
opcode : 要求の種類
|
||||
pargs :
|
||||
|
||||
Returns:
|
||||
Memo : DRIVE_FLAGS_REMOVABLEの場合、ドライバのIO関数を呼ぶ前に
|
||||
CTRL関数のDEVCTL_CHECK_STATUSが呼ばれる。
|
||||
DEVTEST_CHANGED→DEVTEST_NOCHANGEが確認されるとRTFSはセクタ0を
|
||||
読みに行き、FATパラメータを取得した上で目的のセクタを読みに行く。
|
||||
CTRL関数の前にはDEVCTL_CHECK_STATUSが呼ばれないので、DEVCTL_
|
||||
GET_GEOMETRYでは自前で再挿入をチェックする必要がある。
|
||||
*---------------------------------------------------------------------------*/
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
DEV_GEOMETRY gc;
|
||||
int heads, secptrack;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( driveno);
|
||||
|
||||
switch( opcode) {
|
||||
case DEVCTL_GET_GEOMETRY: //formatまたはpartirionするときにRTFSが使うパラメータ
|
||||
PRINTDEBUG( "DEVCTL_GET_GEOMETRY\n");
|
||||
if( (pdr->drive_flags & DRIVE_FLAGS_INSERTED) == 0) { /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == TRUE) { /* 今現在も抜かれているとき */
|
||||
return( -1);
|
||||
}else{ /* 今現在は再挿入されているとき */
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
}
|
||||
}
|
||||
|
||||
rtfs_memset( &gc, (byte)0, sizeof(gc));
|
||||
|
||||
sdi_get_CHS_params(); //最初に呼ぶこと
|
||||
sdi_get_fatparams();
|
||||
sdi_get_nom();
|
||||
|
||||
PRINTDEBUG( "heads : 0x%x\n", sdmc_current_spec.heads);
|
||||
PRINTDEBUG( "secptrack : 0x%x\n", sdmc_current_spec.secptrack);
|
||||
PRINTDEBUG( "cylinders : 0x%x\n", sdmc_current_spec.cylinders);
|
||||
PRINTDEBUG( "SC : 0x%x\n", sdmc_current_spec.SC);
|
||||
PRINTDEBUG( "BU : 0x%x\n", sdmc_current_spec.BU);
|
||||
PRINTDEBUG( "RDE : 0x%x\n", sdmc_current_spec.RDE);
|
||||
PRINTDEBUG( "SS : 0x%x\n", sdmc_current_spec.SS);
|
||||
PRINTDEBUG( "RSC : 0x%x\n", sdmc_current_spec.RSC);
|
||||
PRINTDEBUG( "FATBITS : 0x%x\n", sdmc_current_spec.FATBITS);
|
||||
PRINTDEBUG( "SF : 0x%x\n", sdmc_current_spec.SF);
|
||||
PRINTDEBUG( "SSA : 0x%x\n", sdmc_current_spec.SSA);
|
||||
PRINTDEBUG( "NOM : 0x%x\n", sdmc_current_spec.NOM);
|
||||
|
||||
gc.dev_geometry_lbas = (sdmc_current_spec.adjusted_memory_capacity);// - sdmc_current_spec.NOM);
|
||||
gc.dev_geometry_heads = sdmc_current_spec.heads;
|
||||
gc.dev_geometry_cylinders = sdmc_current_spec.cylinders;
|
||||
gc.dev_geometry_secptrack = sdmc_current_spec.secptrack;
|
||||
/**/
|
||||
gc.fmt_parms_valid = TRUE;
|
||||
gc.fmt.oemname[0] = 'C';
|
||||
gc.fmt.oemname[1] = 'T';
|
||||
gc.fmt.oemname[2] = 'R';
|
||||
gc.fmt.oemname[3] = '\0';
|
||||
gc.fmt.secpalloc = sdmc_current_spec.SC; /*sectors per cluster(FIX by capacity)*/
|
||||
gc.fmt.secreserved = sdmc_current_spec.RSC;//sdmc_current_spec.RSC;/*reserved sectors(FIX 1 at FAT12,16)*/
|
||||
gc.fmt.numfats = 2;
|
||||
gc.fmt.secpfat = sdmc_current_spec.SF;
|
||||
gc.fmt.numhide = sdmc_current_spec.NOM; /**/
|
||||
gc.fmt.numroot = sdmc_current_spec.RDE; /*FIX*/
|
||||
gc.fmt.mediadesc = 0xF8;
|
||||
gc.fmt.secptrk = sdmc_current_spec.secptrack; //CHS Recommendation
|
||||
gc.fmt.numhead = sdmc_current_spec.heads;
|
||||
gc.fmt.numcyl = sdmc_current_spec.cylinders;
|
||||
gc.fmt.physical_drive_no = driveno;
|
||||
gc.fmt.binary_volume_label = BIN_VOL_LABEL;
|
||||
gc.fmt.text_volume_label[0] = '\0';
|
||||
//TODO:dev_geometry_lbasもセットする必要あるか調べること
|
||||
PRINTDEBUG( "heads : 0x%x, secptrack : 0x%x, cylinders : 0x%x\n", gc.dev_geometry_heads, gc.dev_geometry_secptrack, gc.dev_geometry_cylinders);
|
||||
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuCopy8( &gc, pargs, sizeof(gc));
|
||||
// copybuff( pargs, &gc, sizeof(gc));
|
||||
#else
|
||||
MI_CpuCopy8( &gc, pargs, sizeof(gc));
|
||||
#endif
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_FORMAT:
|
||||
PRINTDEBUG( "DEVCTL_FORMAT\n");
|
||||
sdi_build_partition_table(); //MBRセクタ(パーティションテーブル含む)書き込み
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_REPORT_REMOVE: //抜かれたとき
|
||||
PRINTDEBUG( "DEVCTL_REPORT_REMOVE\n");
|
||||
pdr->drive_flags &= ~DRIVE_FLAGS_INSERTED;
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_CHECKSTATUS: //REMOVABLEの場合、毎回R/W前に呼ばれる
|
||||
PRINTDEBUG( "DEVCTL_CHECKSTATUS\n");
|
||||
if (!(pdr->drive_flags & DRIVE_FLAGS_REMOVABLE)) { //リムーバブルでない場合
|
||||
return(DEVTEST_NOCHANGE);
|
||||
}
|
||||
if (pdr->drive_flags & DRIVE_FLAGS_INSERTED) { /* 抜かれてない場合 */
|
||||
if( rtfs_first_stat_flag[driveno]) { //初回のCHECKSTATUS時
|
||||
rtfs_first_stat_flag[driveno] = 0;
|
||||
PRINTDEBUG( "CHANGED!\n");
|
||||
return(DEVTEST_CHANGED);
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOCHANGE\n");
|
||||
return( DEVTEST_NOCHANGE);
|
||||
}
|
||||
}else{ /* 抜かれていた場合 */
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
PRINTDEBUG( "DEVTEST_CHANGED\n");
|
||||
return( DEVTEST_CHANGED); //挿さっている
|
||||
}else{
|
||||
PRINTDEBUG( "DEVTEST_NOMEDIA\n");
|
||||
return( DEVTEST_NOMEDIA); //挿さってない
|
||||
}
|
||||
}
|
||||
|
||||
case DEVCTL_WARMSTART: //attachのときしか呼ばれない
|
||||
PRINTDEBUG( "DEVCTL_WARMSTART\n");
|
||||
/*-- GoIdleセット --*/
|
||||
if( func_SDCARD_Out != i_sdmcRemovedIntr) {
|
||||
func_usr_sdmc_out = func_SDCARD_Out; //ユーザコールバック取得
|
||||
}
|
||||
sdmcGoIdle( func_SDCARD_In, i_sdmcRemovedIntr); //カード初期化シーケンス
|
||||
/*------------------*/
|
||||
pdr->drive_flags |= (DRIVE_FLAGS_VALID | DRIVE_FLAGS_REMOVABLE | DRIVE_FLAGS_PARTITIONED);
|
||||
pdr->partition_number = 0;
|
||||
|
||||
if( SDCARD_OutFlag == FALSE) { /* 排出フラグ参照 */
|
||||
pdr->drive_flags |= DRIVE_FLAGS_INSERTED;
|
||||
}else{ /* カード未挿入のとき */
|
||||
pdr->drive_flags &= (~(DRIVE_FLAGS_INSERTED)); //抜かれているだけではVALIDフラグは落とさないらしい
|
||||
}
|
||||
return( 0);
|
||||
|
||||
case DEVCTL_POWER_RESTORE:
|
||||
PRINTDEBUG( "DEVCTL_POWER_RESTORE\n");
|
||||
break;
|
||||
|
||||
case DEVCTL_POWER_LOSS:
|
||||
PRINTDEBUG( "DEVCTL_POWER_LOSS\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINTDEBUG( "DEVCTL_unknown\n");
|
||||
break;
|
||||
}
|
||||
return( 0);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
抜取コールバック関数
|
||||
|
||||
RTFSが次回"DEVCTL_GET_GEOMETRY"を行うとき、ここでセットしたパラメータを知る
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_sdmcRemovedIntr( void)
|
||||
{
|
||||
DDRIVE *pdr;
|
||||
|
||||
pdr = pc_drno_to_drive_struct( sdmc_drive_no);
|
||||
if( pdr) {
|
||||
pdr->dev_table_perform_device_ioctl( pdr->driveno,
|
||||
DEVCTL_REPORT_REMOVE,
|
||||
(void*)0);
|
||||
}
|
||||
|
||||
if( func_usr_sdmc_out) {
|
||||
func_usr_sdmc_out(); //ユーザコールバック
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcRtfsAttach
|
||||
|
||||
Description: sdmcドライバをドライブに割り当てる
|
||||
|
||||
Arguments: driveno : ドライブ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL sdmcRtfsAttach( int driveno)
|
||||
{
|
||||
BOOLEAN result;
|
||||
DDRIVE pdr;
|
||||
|
||||
pdr.dev_table_drive_io = sdmcRtfsIo;
|
||||
pdr.dev_table_perform_device_ioctl = sdmcRtfsCtrl;
|
||||
pdr.register_file_address = (dword) 0; /* Not used */
|
||||
pdr.interrupt_number = 0; /* Not used */
|
||||
pdr.drive_flags = 0;//DRIVE_FLAGS_FAILSAFE;
|
||||
pdr.partition_number = 0; /* Not used */
|
||||
pdr.pcmcia_slot_number = 0; /* Not used */
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
result = rtfs_attach( driveno, &pdr, "SD"); //構造体がFSライブラリ側にコピーされる
|
||||
|
||||
/*drivenoをグローバル変数に記憶*/
|
||||
sdmc_drive_no = driveno;
|
||||
|
||||
return( result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*SD File System Specification(仕様書)に基づいた値を出す*/
|
||||
static void sdi_get_CHS_params( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
while( 1) {
|
||||
if( mbytes <= 2) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 16;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 16) {
|
||||
sdmc_current_spec.heads = 2;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32) {
|
||||
sdmc_current_spec.heads = 4;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 128) {
|
||||
sdmc_current_spec.heads = 8;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 32;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 504) {
|
||||
sdmc_current_spec.heads = 16;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 1008) {
|
||||
sdmc_current_spec.heads = 32;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2016) {
|
||||
sdmc_current_spec.heads = 64;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 4032) {
|
||||
sdmc_current_spec.heads = 128;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.heads = 255;
|
||||
sdmc_current_spec.secptrack = 63;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*シリンダ数を計算*/
|
||||
sdmc_current_spec.cylinders = (sdmc_current_spec.memory_capacity /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack));
|
||||
|
||||
/*memory_capacityを再計算してadjusted_memory_capacityに格納*/
|
||||
sdmc_current_spec.adjusted_memory_capacity = sdmc_current_spec.cylinders *
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
}
|
||||
|
||||
|
||||
/*引数を超える最も小さい整数を算出する*/
|
||||
static u32 sdi_get_ceil( u32 cval, u32 mval)
|
||||
{
|
||||
return( (cval / mval) + (1 * (cval % mval != 0)));
|
||||
}
|
||||
|
||||
|
||||
/*マスターブートセクタのセクタ数を返す*/
|
||||
static void sdi_get_nom( void)
|
||||
{
|
||||
u32 RSC = 1; //FAT12,16では1
|
||||
u32 RDE = 512; //ルートディレクトリエントリ。FIX
|
||||
u32 SS = 512; //セクタサイズ。FIX
|
||||
u32 TS, SC, n;
|
||||
u32 MAX, SFdash;
|
||||
|
||||
TS = sdmc_current_spec.adjusted_memory_capacity;
|
||||
SC = sdmc_current_spec.SC;
|
||||
|
||||
sdmc_current_spec.SF = sdi_get_ceil( TS/SC * sdmc_current_spec.FATBITS, SS*8);
|
||||
|
||||
/*-----------------------SDHCのとき----------------------------*/
|
||||
if( sdmc_current_spec.csd_ver2_flag) {
|
||||
sdmc_current_spec.NOM = sdmc_current_spec.BU;
|
||||
do {
|
||||
n = sdi_get_ceil( 2*sdmc_current_spec.SF, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.RSC = (sdmc_current_spec.BU * n) - ( 2 * sdmc_current_spec.SF);
|
||||
if( sdmc_current_spec.RSC < 9) {
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}
|
||||
sdmc_current_spec.SSA = sdmc_current_spec.RSC + (2 * sdmc_current_spec.SF);
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SSA += sdmc_current_spec.BU;
|
||||
sdmc_current_spec.RSC += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF -= 1;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
}else{ /*-------------------------SDのとき-------------------------------*/
|
||||
do {
|
||||
sdmc_current_spec.SSA = RSC + ( 2 * sdmc_current_spec.SF) + sdi_get_ceil( 32*RDE, SS);
|
||||
n = sdi_get_ceil( sdmc_current_spec.SSA, sdmc_current_spec.BU);
|
||||
sdmc_current_spec.NOM = (sdmc_current_spec.BU * n) - sdmc_current_spec.SSA;
|
||||
if( sdmc_current_spec.NOM != sdmc_current_spec.BU) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}
|
||||
do {
|
||||
MAX = ((TS - sdmc_current_spec.NOM - sdmc_current_spec.SSA) / SC) + 1;
|
||||
SFdash = sdi_get_ceil( (2+(MAX-1)) * sdmc_current_spec.FATBITS, SS*8);
|
||||
if( SFdash > sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.NOM += sdmc_current_spec.BU;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}while( 1);
|
||||
if( SFdash != sdmc_current_spec.SF) {
|
||||
sdmc_current_spec.SF = SFdash;
|
||||
}else{
|
||||
break; //complete
|
||||
}
|
||||
}while( 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*FATのビット数を返す*/
|
||||
static void sdi_get_fatparams( void)
|
||||
{
|
||||
int mbytes;
|
||||
|
||||
// mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512;
|
||||
mbytes = (sdmc_current_spec.card_capacity >> 11);
|
||||
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.FATBITS = 12;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.FATBITS = 16;
|
||||
sdmc_current_spec.RDE = 512;
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}else{
|
||||
sdmc_current_spec.FATBITS = 32;
|
||||
sdmc_current_spec.RDE = 0; //FAT32のときは未使用。0にしておかないとRTFSが BAD FORMAT を返す。
|
||||
sdmc_current_spec.RSC = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( mbytes <= 8) {
|
||||
sdmc_current_spec.SC = 16;
|
||||
sdmc_current_spec.BU = 16;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 64) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 32;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 256) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 64;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 1024) {
|
||||
sdmc_current_spec.SC = 32;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 2048) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 128;
|
||||
return;
|
||||
}
|
||||
if( mbytes <= 32768) {
|
||||
sdmc_current_spec.SC = 64;
|
||||
sdmc_current_spec.BU = 8192;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションセクタ含む)を生成して書き込む*/
|
||||
static void sdi_build_partition_table( void)
|
||||
{
|
||||
u16 MbrSectDat[512/2];
|
||||
u32 starting_head, starting_sect, starting_cyl;
|
||||
u32 ending_head, ending_sect, ending_cyl;
|
||||
u32 total_sect;
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
u32 starting_data, ending_data;
|
||||
#endif
|
||||
u32 systemid;
|
||||
SdmcResultInfo SdResult;
|
||||
|
||||
/**/
|
||||
starting_head = sdmc_current_spec.NOM % (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
starting_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
starting_sect = (sdmc_current_spec.NOM % sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
starting_cyl = sdmc_current_spec.NOM / (sdmc_current_spec.heads *
|
||||
sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
total_sect = (sdmc_current_spec.adjusted_memory_capacity - sdmc_current_spec.NOM);
|
||||
ending_head = (sdmc_current_spec.NOM + total_sect - 1) %
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
ending_head /= sdmc_current_spec.secptrack;
|
||||
|
||||
/**/
|
||||
ending_sect = ((sdmc_current_spec.NOM + total_sect - 1) %
|
||||
sdmc_current_spec.secptrack) + 1;
|
||||
|
||||
/**/
|
||||
ending_cyl = (sdmc_current_spec.NOM + total_sect - 1) /
|
||||
(sdmc_current_spec.heads * sdmc_current_spec.secptrack);
|
||||
|
||||
/**/
|
||||
if( sdmc_current_spec.FATBITS == 32) { //FAT32のとき
|
||||
if( total_sect < 0xFB0400) { //8032.5MBが閾値(SD FileSystemSpec2.00参照)
|
||||
systemid = 0x0B; /* FAT32 */
|
||||
}else{
|
||||
systemid = 0x0C; /* FAT32(拡張INT13対応) */
|
||||
}
|
||||
}else{ //FAT12,FAT16のとき
|
||||
if( total_sect < 32680) {
|
||||
systemid = 0x01; /* FAT12 */
|
||||
}else if( total_sect < 65536) {
|
||||
systemid = 0x04; /* FAT16(16MB~32MB未満) */
|
||||
}else{
|
||||
systemid = 0x06; /* FAT16(32MB~4GB) */
|
||||
}
|
||||
}
|
||||
|
||||
/*MBRセクタ(パーティションテーブル含む)作成*/
|
||||
#if (TARGET_OS_CTR == 1)
|
||||
miCpuFill8( MbrSectDat, 0, 512);
|
||||
#else
|
||||
MI_CpuFill8( MbrSectDat, 0, 512);
|
||||
#endif
|
||||
MbrSectDat[446/2] = (starting_head<<8);
|
||||
//上位8bit:starting_cylの下位8bit, 下位8bit:starting_cylの上位2bit + starting_sect 6bit.
|
||||
MbrSectDat[448/2] = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
MbrSectDat[450/2] = (ending_head<<8) + systemid;
|
||||
//上位8bit:ending_cylの下位8bit, 下位8bit:ending_cylの上位2bit + ending_sect 6bit.
|
||||
MbrSectDat[452/2] = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
MbrSectDat[454/2] = sdmc_current_spec.NOM;
|
||||
MbrSectDat[456/2] = (sdmc_current_spec.NOM>>16);
|
||||
MbrSectDat[458/2] = total_sect;
|
||||
MbrSectDat[460/2] = (total_sect>>16);
|
||||
MbrSectDat[510/2] = 0xAA55;
|
||||
/*セクタ0に書き込み*/
|
||||
sdmcWriteFifo( MbrSectDat, 1, 0, NULL, &SdResult);
|
||||
|
||||
/**/
|
||||
PRINTDEBUG( "total sect : 0x%x\n", total_sect);
|
||||
PRINTDEBUG( "starting head : 0x%x\n", starting_head);
|
||||
PRINTDEBUG( "starting sect : 0x%x\n", starting_sect);
|
||||
PRINTDEBUG( "starting cyl : 0x%x\n", starting_cyl);
|
||||
PRINTDEBUG( "ending head : 0x%x\n", ending_head);
|
||||
PRINTDEBUG( "ending sect : 0x%x\n", ending_sect);
|
||||
PRINTDEBUG( "ending cyl : 0x%x\n", ending_cyl);
|
||||
PRINTDEBUG( "\n");
|
||||
#if (SD_DEBUG_PRINT_ON == 1)
|
||||
starting_data = (starting_cyl<<8) + ((starting_cyl>>2) & 0xC0) + starting_sect;
|
||||
PRINTDEBUG( "starting data : 0x%x\n", starting_data);
|
||||
ending_data = (ending_cyl<<8) + ((ending_cyl>>2) & 0xC0) + ending_sect;
|
||||
PRINTDEBUG( "endign data : 0x%x\n", ending_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
//#endif /*(INCLUDE_SD)*/
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,349 +0,0 @@
|
||||
/*
|
||||
** Copyright (c) 2000-2001 Matsushita Electric Industrial Co., Ltd.
|
||||
** All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** $Module SDカードアクセスモジュール・インクルード
|
||||
** $Filename SD_CARD_IP.H
|
||||
** $Version 1.0 版
|
||||
** $Date 01/02/16
|
||||
** $Log 01/02/16 rev1.0作成
|
||||
** 松下電器産業(株)半導体開発本部
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SD_CARD_IP_H__
|
||||
#define __SD_CARD_IP_H__
|
||||
|
||||
//#define IO3 0 /* Insert Remove SW = FALSE IO3 = TRUE */
|
||||
|
||||
//#define MAX_SD_CLOCK_4M 0 /* MAX SD Clock 4.608MHz */
|
||||
//#define MAX_SD_CLOCK_9M 1 /* MAX SD Clock 9.216MHz */
|
||||
|
||||
|
||||
/*---------------------------------------------
|
||||
ラッパーレジスタのビット制御(フラグ定義)
|
||||
---------------------------------------------*/
|
||||
/* SD_CNTレジスタ */
|
||||
#define SDIF_CNT_USEDTC (0x0001) /* DTC使用フラグ (R/W) */
|
||||
#define SDIF_CNT_USEFIFO (0x0002) /* FIFO使用フラグ (R/W) */
|
||||
#define SDIF_CNT_FULL (0x0100) /* FIFO FULLフラグ (RO) */
|
||||
#define SDIF_CNT_NEMP (0x0200) /* FIFO NOT EMPTYフラグ (RO) */
|
||||
#define SDIF_CNT_FCLR (0x0400) /* FIFO クリアフラグ (WO) */
|
||||
#define SDIF_CNT_FFIE (0x0800) /* FIFO FULLで割り込み (R/W) */
|
||||
#define SDIF_CNT_FEIE (0x1000) /* FIFO EMPTYで割り込み (R/W) */
|
||||
|
||||
#define SDCARD_UseFifoFlag ((*SDIF_CNT) & SDIF_CNT_USEFIFO)
|
||||
|
||||
/*-------------------------------------
|
||||
レジスタのビット制御(フラグ定義)
|
||||
-------------------------------------*/
|
||||
/* SD_CMDレジスタ*/
|
||||
#define SD_CMD_CMD 0x0000 /* SDカードへの通常アクセス(CMD) */
|
||||
#define SD_CMD_ACMD 0x0040 /* SDカードへのセキュリティアクセス(ACMD) */
|
||||
|
||||
/* SD_STOPレジスタ */
|
||||
#define SD_STOP_STP 0x0001 /* データ転送終了を知らせる */
|
||||
#define SD_STOP_SEC_ENABLE 0x0100 /* SD_SECCNTレジスタ有効(セクタカウントレジスタ) */
|
||||
|
||||
/* SD_SECCNTレジスタ */
|
||||
#define SD_SECCNT_END 0x0000 /* SD_SECCNTレジスタ カウントチェック */
|
||||
|
||||
/* SD_SIZEレジスタ */
|
||||
#define SD_SIZE_DATA_LENGTH_1B 0x0001 /* SDカード転送データサイズ 1Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_2B 0x0002 /* SDカード転送データサイズ 2Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_4B 0x0004 /* SDカード転送データサイズ 4Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_8B 0x0008 /* SDカード転送データサイズ 8Bytes (SCR) */
|
||||
#define SD_SIZE_DATA_LENGTH_16B 0x0010 /* SDカード転送データサイズ 16Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_32B 0x0020 /* SDカード転送データサイズ 32Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_64B 0x0040 /* SDカード転送データサイズ 64Bytes (SD_Status) */
|
||||
#define SD_SIZE_DATA_LENGTH_128B 0x0080 /* SDカード転送データサイズ 128Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_256B 0x0100 /* SDカード転送データサイズ 256Bytes */
|
||||
#define SD_SIZE_DATA_LENGTH_512B 0x0200 /* SDカード転送データサイズ 512Bytes (データ) */
|
||||
|
||||
/* SD_OPTIONレジスタ */
|
||||
#define SD_OPTION_WIDTH_1BIT 0x8000 /* ビット幅の選択 1bit幅 */
|
||||
#define SD_OPTION_MSEL_C2NOUSE 0x4000 /* C2モジュール未使用 */
|
||||
#define SD_CD_DETECT_TIME 0xFFF0 /* CD 検出タイムだけをクリアするためのマスク */
|
||||
|
||||
/* SD_INFO2レジスタ */
|
||||
#define SD_INFO2_ERR_ILA 0x8000 /* イリーガルアクセスエラー */
|
||||
#define SD_INFO2_BWE 0x0200 /* SDカードから512byteのデータ書込み要求 */
|
||||
#define SD_INFO2_BRE 0x0100 /* SDカードから512byteのデータ読込み要求 */
|
||||
#define SD_INFO2_ERR_ALLCLR 0x807F /* SD Card エラーレジスタクリア */
|
||||
#define SD_INFO2_ERR_SDDAT0 0x0080 /* SD Card Busy bit */
|
||||
#define SD_INFO2_ERR_RESTIMEOUT 0x0040 /* レスポンスタイムアウトエラー */
|
||||
#define SD_INFO2_ERR_UNDERFLOW 0x0020 /* FIFO アンダーフローエラー */
|
||||
#define SD_INFO2_ERR_OVERFLOW 0x0010 /* FIFO オーバーフローエラー */
|
||||
#define SD_INFO2_ERR_TIMEOUT 0x0008 /* レスポンス以外のタイムアウトエラー */
|
||||
#define SD_INFO2_ERR_END 0x0004 /* フレーム終了認識できないときの(END)エラー */
|
||||
#define SD_INFO2_ERR_CRC 0x0002 /* CRC エラー */
|
||||
#define SD_INFO2_ERR_CMD 0x0001 /* CMDエラー */
|
||||
|
||||
#define SD_INFO2_RW_SET 0x0300 /* SDカード Read/Write 要求割込み要因チェック */
|
||||
#define SD_INFO2_ERROR_SET 0x807F /* SDカード エラー割込み要因チェック */
|
||||
|
||||
/* SD_INFO2_MASKレジスタ */
|
||||
#define SD_INFO2_MASK_ILA 0x8000 /* イリーガルアクセスエラー割込みマスク */
|
||||
#define SD_INFO2_MASK_BWE 0x0200 /* SDカードからのデータ書込み要求割込み禁止 */
|
||||
#define SD_INFO2_MASK_BRE 0x0100 /* SDカードからのデータ読込み要求割込み禁止 */
|
||||
#define SD_INFO2_MASK_ALLERRMASK 0x807F /* 全エラー割り込み禁止 */
|
||||
#define SD_INFO2_MASK_EXCEPT_OVERFLOW 0x802F /* 全エラー割り込み禁止 FIFO Overflow Errorを除く */
|
||||
#define SD_INFO2_MASK_RESTIMEOUT 0x0040 /* Time out 割込みEnable */
|
||||
#define SD_INFO2_MASK_UNDERFLOW 0x0020 /* FIFO アンダーフロー 割込みEnable */
|
||||
#define SD_INFO2_MASK_OVERFLOW 0x0010 /* FIFO オーバーフロー 割込みEnable */
|
||||
#define SD_INFO2_MASK_TIMEOUT 0x0008 /* Time out 割込みEnable */
|
||||
#define SD_INFO2_MASK_END 0x0004 /* END エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_CRC 0x0002 /* CRC エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_CMD 0x0001 /* CMD エラー 割込みEnable */
|
||||
#define SD_INFO2_MASK_ERRSET 0x807F /* SDカード エラー割込み要因チェック */
|
||||
|
||||
/* SD_INFO1レジスタ */
|
||||
#define SD_INFO1_DAT3DETECT 0x0400 /* (IO3検出) card detect(検出=1) : CTRでは使用できない*/
|
||||
#define SD_INFO1_DAT3INSERT 0x0200 /* (IO3検出) card inserted(挿入=1) : CTRでは使用できない */
|
||||
#define SD_INFO1_DAT3REMOVE 0x0100 /* (IO3検出) card removed(抜け=1) : CTRでは使用できない */
|
||||
#define SD_INFO1_DAT3INIT 0x0300 /* (IO3検出) の初期化 */
|
||||
#define SD_INFO1_WRITEPROTECT 0x0080 /* write protect(書き込み禁止=1) */
|
||||
#define SD_INFO1_DETECT 0x0020 /* card detect(検出=1) */
|
||||
|
||||
#define SD_INFO1_INSERT 0x0010 /* card inserted(挿入=1) */
|
||||
#define SD_INFO1_REMOVE 0x0008 /* card removed(抜け=1) */
|
||||
|
||||
#define SD_INFO1_ALL_END 0x0004 /* R/W access all end */
|
||||
#define SD_INFO1_RES_END 0x0001 /* Response end */
|
||||
#define SD_INFO1_INIT 0x0005 /* SD Cardの状態を初期化 */
|
||||
|
||||
#define SD_INFO1_SET 0x031D /* SDカード 挿抜 and RWアクセス終了 and レスポンス終了 要求割込み要因チェック */
|
||||
|
||||
/* SD_INFO1_MASKレジスタ (0:割り込み許可、1:割り込み禁止)*/
|
||||
#define SD_INFO1_MASK_DAT3INSERT 0x0200 /* (IO3検出) card inserted(挿入) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_DAT3REMOVE 0x0100 /* (IO3検出) card removed(抜け) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_INSERT 0x0010 /* card inserted(挿入) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_REMOVE 0x0008 /* card removed(抜け) 割込み禁止 */
|
||||
#define SD_INFO1_MASK_ALL_END 0x0004 /* R/W access all end 割込み禁止 */
|
||||
#define SD_INFO1_MASK_RES_END 0x0001 /* Response end 割込み禁止 */
|
||||
|
||||
/* CC_EXT_MODEレジスタ */
|
||||
#define CC_EXT_MODE_PIO 0x0000 /* PIOモード */
|
||||
#define CC_EXT_MODE_DMA 0x0002 /* DMAモード */
|
||||
|
||||
/* SOFT_RSTレジスタ */
|
||||
#define SOFT_RST_SDIF_RST 0x0001 /* SD I/Fモジュールをリセット */
|
||||
|
||||
/* SD_CLK_CTRLレジスタ */
|
||||
#define SD_CLK_CTRL_SDCLKEN 0x0100 /* SDカードクロック出力イネーブル */
|
||||
#define SD_CLK_CTRL_512 0x0180 /* SDクロックの周波数(分周比512)*/
|
||||
#define SD_CLK_CTRL_256 0x0140 /* SDクロックの周波数(分周比256)*/
|
||||
#define SD_CLK_CTRL_128 0x0120 /* SDクロックの周波数(分周比128)*/
|
||||
#define SD_CLK_CTRL_64 0x0110 /* SDクロックの周波数(分周比 64)*/
|
||||
#define SD_CLK_CTRL_32 0x0108 /* SDクロックの周波数(分周比 32)*/
|
||||
#define SD_CLK_CTRL_16 0x0104 /* SDクロックの周波数(分周比 16)*/
|
||||
#define SD_CLK_CTRL_8 0x0102 /* SDクロックの周波数(分周比 8)*/
|
||||
#define SD_CLK_CTRL_4 0x0101 /* SDクロックの周波数(分周比 4)*/
|
||||
#define SD_CLK_CTRL_2 0x0100 /* SDクロックの周波数(分周比 2)*/
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
マルチポート対応ビット制御(フラグ定義)
|
||||
-------------------------------------*/
|
||||
#define SDCARD_PORT_NO 0x0300 /* カードポート選択数 */
|
||||
#define SDCARD_PORT_NO_MAX 0x04//0x02 /* カードポート最大選択数 */
|
||||
#define SDCARD_PORT_NO_MIN 0x01 /* カードポート最小選択数 */
|
||||
#define SDCARD_PORT_SELECT_NO 0x0001 /* カードポート番号ビット */
|
||||
#define SDCARD_PORT0 0x0000 /* カードポート番号ビット */
|
||||
#define SDCARD_PORT1 0x0001 /* カードポート番号ビット */
|
||||
|
||||
/* EXT_WPレジスタ(ポート1以降のライトプロテクト) */
|
||||
#define EXT_WP_PORT1 0x0001 /* ポート1write protect(書き込み禁止=1)*/
|
||||
|
||||
/* EXT_CDレジスタ */
|
||||
#define EXT_CD_PORT1_REMOVE 0x0001 /* ポート1 card detect(検出=1) */
|
||||
#define EXT_CD_PORT1_INSERT 0x0002 /* ポート1 card inserted(挿入=1) */
|
||||
#define EXT_CD_PORT1_DETECT 0x0004 /* ポート1 card removed(抜け=1) */
|
||||
|
||||
/* EXT_CD_DAT3レジスタ */
|
||||
//#define EXT_CD_PORT1_DAT3INIT 0x0003 /* ポート1 card の状態 (IO3検出) の初期化 */
|
||||
#define EXT_CD_PORT1_DAT3REMOVE 0x0001 /* ポート1 dat3 card detect(検出=1) */
|
||||
#define EXT_CD_PORT1_DAT3INSERT 0x0002 /* ポート1 dat3 card inserted(挿入=1) */
|
||||
#define EXT_CD_PORT1_DAT3DETECT 0x0004 /* ポート1 dat3 card removed(抜け=1) */
|
||||
|
||||
/* EXT_CD_DAT3_MASKレジスタ */
|
||||
#define EXT_CD_MASK_PORT1INSERT 0x0002 /* port1 card inserted(挿入) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1REMOVE 0x0001 /* port1 card removed(抜け) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1DAT3INSERT 0x0002 /* port1 (IO3検出) card inserted(挿入) 割込み禁止 */
|
||||
#define EXT_CD_MASK_PORT1DAT3REMOVE 0x0001 /* port1 (IO3検出) card removed(抜け) 割込み禁止 */
|
||||
|
||||
/*-------------------------------------
|
||||
カードの選択
|
||||
--------------------------------------*/
|
||||
#define SDCARD_DETECT_VISUAL_BIT 0x0400 /*** upper layer card detected visual bit ***/
|
||||
|
||||
/*-------------------------------------
|
||||
ライトプロテクト
|
||||
-------------------------------------*/
|
||||
#define SDCARD_WP_PERMANENT_BIT 0x0020 /*** permanent write protection ***/
|
||||
#define SDCARD_WP_TEMPORARY_BIT 0x0010 /*** temporary write protection ***/
|
||||
|
||||
/*-------------------------------------
|
||||
SD or MMCカードコマンド
|
||||
-------------------------------------*/
|
||||
#define GO_IDLE_STATE (0) /* resets all cards to idle state */
|
||||
#define SEND_OP_COND (1) /* Asks all cards in idle state to send their operation conditions */
|
||||
#define ALL_SEND_CID (2) /* send CID numbers */
|
||||
#define SEND_RELATIVE_ADDR (3) /* ask the card to publish a new relative address(RCA) */
|
||||
#define SET_BUS_WIDTH (6) /* ビット幅の選択 */
|
||||
#define SELECT_CARD (7) /* Command toggles acard between thr Stand-by and Transfer states */
|
||||
#define SEND_CSD (9) /* addressed card sends its card-specific data(CSD) */
|
||||
#define STOP_TRANSMISSION (12) /* forces the card to stop transmission */
|
||||
#define SD_SEND_STATUS (13) /* addressed card sends its status register */
|
||||
#define SET_BLOCKLEN (16) /* sets the block length */
|
||||
#define READ_MULTIPLE_BLOCK (18) /* マルチブロックリード */
|
||||
#define WRITE_MULTIPLE_BLOCK (25) /* マルチブロックライト */
|
||||
#define APP_CMD (55) /* CMD55 */
|
||||
#define SD_STATUS (13) /* ACMD13 Send the SD_CARD status */
|
||||
#define SEND_NUM_WR_SECTORS (22) /* ACMD22 書きこみ完了セクタ数取得 */
|
||||
#define SD_APP_OP_COND (41) /* ACMD41 */
|
||||
#define SEND_SCR (51) /* SD configuration register (SCR) */
|
||||
|
||||
/* MMCplus, eMMCの定義 */
|
||||
#define EXT_CSD_ACCESS (6)
|
||||
|
||||
/* Extended Commandの定義 */
|
||||
#define EXT_NORMAL (0)
|
||||
#define EXT_SDIO (0x4000)
|
||||
|
||||
#define EXT_COM_R3 (0x0700)
|
||||
|
||||
#define EXT_CMD (0x00C0)
|
||||
|
||||
#define SEND_IF_COND (8) /* Physical Layer 2.0 で追加されたコマンド */
|
||||
#define SEND_IF_COND_EXT (EXT_SDIO | EXT_COM_R3 | EXT_CMD | SEND_IF_COND)
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
IP レジスタアクセス マクロ関数
|
||||
-------------------------------------*/
|
||||
#define SD_OrFPGA(reg,value) ((reg) |= (value));
|
||||
#define SD_AndFPGA(reg,value) ((reg) &= (value));
|
||||
#define SD_SetFPGA(reg,value) ((reg) = (value));
|
||||
#define SD_GetFPGA(dest,reg) ((dest) = (reg));
|
||||
|
||||
/***********************************************************************
|
||||
構造体定数
|
||||
***********************************************************************/
|
||||
typedef union{
|
||||
u32 dat;
|
||||
struct {
|
||||
u16 low;
|
||||
u16 high;
|
||||
} dt2word;
|
||||
} LELONG;
|
||||
|
||||
/*-------------------------------------
|
||||
その他(ビット制御)
|
||||
-------------------------------------*/
|
||||
#define RSP_R3_OCR31 0x8000 /* Use OCR Busy bit Check */
|
||||
#define RSP_R3_OCR_VDD 0x0030 /* Use OCR VDD bit Check (3.2-3.3v,3.3-3.4v is OK)*/
|
||||
|
||||
/*--- SCR[0]に対する4bitバス幅対応フラグのマスク ---*/
|
||||
//SCRのbit50に相当するが、SCRとSD_STATUSはMSBから送られてくることを考慮してある
|
||||
#define SCR_DAT_BUS_WIDTH_4BIT 0x0400 /* SCR DAT Bus width supported 4bit */
|
||||
|
||||
/*--- 127bitCSD (CSD[0]~CSD[7])関連 ---*/
|
||||
#define CSD_VDD_R_CURR_MIN 0x0038 /* "VDD_R_CURR_MIN" (for CSD[3]) */
|
||||
#define CSD_VDD_R_CURR_MAX 0x0007 /* "VDD_R_CURR_MAX" (for CSD[3]) */
|
||||
#define CSD_VDD_W_CURR_MIN 0xE000 /* "VDD_W_CURR_MIN" (for CSD[2]) */
|
||||
#define CSD_VDD_W_CURR_MAX 0x1C00 /* "VDD_W_CURR_MAX" (for CSD[2]) */
|
||||
|
||||
#define CSD_READ_BL_LEN 0x0F00 /* "READ_BL_LEN" (for CSD[4])*/
|
||||
#define CSD_WRITE_BL_LEN_BIT_25_24 0x0003 /* "WRITE_BL_LEN" (for CSD[1])*/
|
||||
#define CSD_WRITE_BL_LEN_BIT_23_22 0xC000 /* "WRITE_BL_LEN" (for CSD[0]*/
|
||||
#define CSD_READ_BL_PARTIAL 0x0080 /* "READ_BL_PARTIAL" (for CSD[4]) */
|
||||
#define CSD_TRANSFER_RATE 0x0700 /* "Transfer rate unit" of "TRAN_SPEED" (for CSD[5]) */
|
||||
#define CSD_TRAN_SPEED_100K 0x0000 /* 100Kbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_1M 0x0001 /* 1Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_10M 0x0002 /* 10Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_100M 0x0003 /* 100Mbit/s (for CSD Transfer rate) */
|
||||
#define CSD_TRAN_SPEED_OTHER 0x0004 /* Reserve (for CSD Transfer rate) */
|
||||
|
||||
#define CSD_C_SIZE_MULT 0x0380 /* RSP2 の bit[49:47] */
|
||||
#define CSD_C_SIZE_BIT_73_72 0x0003 /* RSP3 の bit[73:72](C_SIZE) */
|
||||
#define CSD_C_SIZE_BIT_71_62 0xFFC0 /* RSP3 の bit[71:62](C_SIZE) */
|
||||
//SDHC(CSD format version2)の場合
|
||||
#define CSD_C_SIZE_BIT_69_56 0x3FFF /* SD_CSD[3] */
|
||||
#define CSD_C_SIZE_BIT_55_48 0xFF00 /* SD_CSD[2] */
|
||||
|
||||
#define CSD_STRUCT_BIT_127_126 0x00C0 /* SD_CSD[7] */
|
||||
|
||||
//#define VDD_R_CURR_MIN 0x0000 /* CSD max read current@VDD min */
|
||||
//#define VDD_R_CURR_MAX 0x0007 /* CSD max read current@VDD max */
|
||||
//#define VDD_W_CURR_MIN 0x0000 /* CSD max write current@VDD min */
|
||||
//#define VDD_W_CURR_MAX 0x0007 /* CSD max write current@VDD max */
|
||||
|
||||
/*--- R1レスポンスの card status(32bit)に対するマスク ---*/
|
||||
#define RSP_R1_STATUS_ERR 0xF9FF0008 /* R1(レスポンス)のカードステータスのチェック */
|
||||
#define SDCARD_STATUS_OUT_OF_RANGE 0x80000000 /* Card Status OUT_OF_RANGE のチェック */
|
||||
#define RSP_R1_CURRENT_STATE 0x1E00 /* CARD current state */
|
||||
/*-------------------------------------------------------*/
|
||||
|
||||
/* レスポンスのRSP0 & RSP_R1_CURRENT_STATEを1ビット右シフトした値に対するフラグ */
|
||||
#define CURRENT_STATE_DATA 0x0500 /* CARD current state data */
|
||||
#define CURRENT_STATE_RCV 0x0600 /* CARD current state rcv */
|
||||
|
||||
/* カードステータス */
|
||||
#define SD_MEMORY_CARD 0x00FF /* SD_CARD_TYPE SD memory card */
|
||||
|
||||
|
||||
/*-------------------------------------
|
||||
プロトタイプ宣言
|
||||
-------------------------------------*/
|
||||
void SD_Init(void); /* SD Cardインターフェース部をリセット&初期設定 */
|
||||
void SD_EnableInfo(void); /* SD Card 挿抜 割り込みイネーブル・ディスエーブル */
|
||||
u16 SD_Command(u16 ucCommand); /* SDカードコマンド送出 */
|
||||
u16 SD_AppCommand(void); /* SDカード RCA = 1をセット後 CMD55 発行 */
|
||||
u16 SD_AppOpCond(void); /* ACMD41 発行 busyでなくなるまで繰り返し */
|
||||
u16 SD_SendOpCond(void); /* CMD1 発行 busyでなくなるまで繰り返し */
|
||||
u16 SD_SendIfCond(void); /* CMD8 発行 (SDHCのみ反応してくる) */
|
||||
u16 SD_SendRelativeAddr(void); /* CMD3 発行 正常終了時 RCA<-ResのRCA */
|
||||
u16 SD_SelectCard(void); /* CMD7 発行 Command toggles acard between the Stand-by and Transfer states */
|
||||
u16 SD_SetBlockLength(u32 ulBlockLength); /* ブロックレングス(1セクタの転送量)の設定 */
|
||||
u16 SD_SendCID(void); /* card identification data の取得コマンド発行 */
|
||||
u16 SD_SendCSD(void); /* card-specific data の取得コマンド発行 */
|
||||
u16 SD_SendSCR(void); /* SD register の取得コマンド発行 */
|
||||
u16 SD_SDStatus(void); /* SD STATUS の取得コマンド発行 */
|
||||
u16 SD_SendStatus(void); /* SD status register の取得コマンド発行 */
|
||||
u16 SD_MultiReadBlock(u32 ulOffset); /* マルチセクタリードコマンド発行 */
|
||||
u16 SD_ClockDivSet(u16 usTranSpeed); /* カードの動作クロック設定 */
|
||||
|
||||
void SD_EnableClock( void); /* SDカードのクロック有効 */
|
||||
void SD_DisableClock( void); /* SDカードのクロック無効(省電力) */
|
||||
|
||||
u16 SD_SelectBitWidth(s16 b4bit); /* ビット幅の選択 */
|
||||
|
||||
u16 MMCP_WriteBusWidth(s16 b4bit);
|
||||
u16 MMCP_BusTest( BOOL readflag);
|
||||
|
||||
|
||||
BOOL SD_FPGA_irq(void); /* カード転送要求時のFPGAの制御 */
|
||||
void SD_StopTransmission(void); /* カード転送終了をFPGAに通知する。 */
|
||||
void SD_TransEndFPGA(void); /* カード転送の終了処理(割り込みマスクを戻す) */
|
||||
u16 SD_CheckStatus(BOOL bRead); /* Normal response command カードステータスのチェック */
|
||||
u16 SD_SwapByte(u16 *data); /* 上位byte、下位byteを入れ替える関数 */
|
||||
|
||||
void SD_EnableSeccnt( u32 ulSDCARD_SectorCount); /* SD_SECCNTレジスタ有効化&値設定 */
|
||||
void SD_DisableSeccnt( void); /* SD_SECCNTレジスタ無効化 */
|
||||
|
||||
void SD_SetErr(u16 Error); /* エラーステータスを設定する */
|
||||
void SD_ClrErr(u16 Error); /* エラーステータスをクリアする */
|
||||
|
||||
BOOL SD_CheckFPGAReg(u16 reg,u16 value); /* IPレジスタにフラグが立っているか判定 */
|
||||
|
||||
void SD_TransReadyFPGA(void); /* 転送処理準備FPGA設定 */
|
||||
u16 SD_TransCommand(u16 ucCommand); /* 命令発行処理 */
|
||||
|
||||
u16 SD_MultiWriteBlock(u32 ulOffset); /* マルチセクタライトコマンド発行 */
|
||||
u16 SD_SendNumWRSectors(void); /* ACMD22 書きこみ完了セクタ数取得コマンド発行 */
|
||||
|
||||
|
||||
#endif /* __SD_CARD_IP_H__ */
|
||||
@ -1,118 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: TwlBrom - SD driver
|
||||
File: sd_ip_reg.h
|
||||
|
||||
Copyright 2006 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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __SD_IP_REG_H__
|
||||
#define __SD_IP_REG_H__
|
||||
|
||||
/*********************************************
|
||||
SD IPレジスタ
|
||||
|
||||
(R/W) : readable and writable
|
||||
(RO) : read only
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IP_BASE (0x08030000) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IP_BASE (0x400B0000) // IOP実機設定
|
||||
#endif*/
|
||||
#define SD_IP_BASE (0x04004800) // TWL ARM7設定
|
||||
|
||||
|
||||
#define SD_CMD (*(vu16 *)(SD_IP_BASE + 0x00)) /* CMD発行レジスタ(R/W) */
|
||||
#define SD_PORTSEL (*(vu16 *)(SD_IP_BASE + 0x02)) /* ポート選択レジスタ(R/W) */
|
||||
#define SD_ARG0 (*(vu16 *)(SD_IP_BASE + 0x04)) /* Argument[15:0] (R/W) */
|
||||
#define SD_ARG1 (*(vu16 *)(SD_IP_BASE + 0x06)) /* Argument[31:16] (R/W) */
|
||||
#define SD_STOP (*(vu16 *)(SD_IP_BASE + 0x08)) /* 転送終了後STOP、SD_SECCNT有効 (R/W) */
|
||||
#define SD_SECCNT (*(vu16 *)(SD_IP_BASE + 0x0A)) /* 転送セクタ数制御 (R/W) */
|
||||
#define SD_RSP0 (*(vu16 *)(SD_IP_BASE + 0x0C)) /* Response [23:8] (RO) */
|
||||
#define SD_RSP1 (*(vu16 *)(SD_IP_BASE + 0x0E)) /* Response [39:24] (RO) */
|
||||
#define SD_RSP2 (*(vu16 *)(SD_IP_BASE + 0x10)) /* Response [55:40] (RO) */
|
||||
#define SD_RSP3 (*(vu16 *)(SD_IP_BASE + 0x12)) /* Response [71:56] (RO) */
|
||||
#define SD_RSP4 (*(vu16 *)(SD_IP_BASE + 0x14)) /* Response [87:72] (RO) */
|
||||
#define SD_RSP5 (*(vu16 *)(SD_IP_BASE + 0x16)) /* Response [103:88] (RO) */
|
||||
#define SD_RSP6 (*(vu16 *)(SD_IP_BASE + 0x18)) /* Response [119:104] (RO) */
|
||||
#define SD_RSP7 (*(vu16 *)(SD_IP_BASE + 0x1A)) /* Response [127:120] (RO) */
|
||||
#define SD_INFO1 (*(vu16 *)(SD_IP_BASE + 0x1C)) /* SDメモリーカードの状態 (R/W) */
|
||||
#define SD_INFO2 (*(vu16 *)(SD_IP_BASE + 0x1E)) /* バッファ制御とエラー情報 (R/W) */
|
||||
#define SD_INFO1_MASK (*(vu16 *)(SD_IP_BASE + 0x20)) /* SD_INFO1割込みマスク (R/W) */
|
||||
#define SD_INFO2_MASK (*(vu16 *)(SD_IP_BASE + 0x22)) /* SD_INFO2割込みマスク (R/W) */
|
||||
#define SD_CLK_CTRL (*(vu16 *)(SD_IP_BASE + 0x24)) /* SDクロック設定 (R/W) */
|
||||
#define SD_SIZE (*(vu16 *)(SD_IP_BASE + 0x26)) /* ビット幅と転送データ長の設定 (R/W) */
|
||||
#define SD_OPTION (*(vu16 *)(SD_IP_BASE + 0x28)) /* タイムアウト、width、CD検出タイム (R/W) */
|
||||
#define SD_ERR_STS1 (*(vu16 *)(SD_IP_BASE + 0x2C)) /* CMD, CRC, ENDエラー割込み原因 (RO) */
|
||||
#define SD_ERR_STS2 (*(vu16 *)(SD_IP_BASE + 0x2E)) /* タイムアウトエラー割込み原因 (RO) */
|
||||
#define SD_BUF0 (vu16 *)(SD_IP_BASE + 0x30) /* SDバッファ読込/書込データポート (R/W) */
|
||||
#define CC_EXT_MODE (*(vu16 *)(SD_IP_BASE + 0xD8)) /* DMAモード/PIOモード切り替え */
|
||||
#define SOFT_RST (*(vu16 *)(SD_IP_BASE + 0xE0)) /* ソフトウェアリセット (R/W) */
|
||||
#define VERSION (*(vu16 *)(SD_IP_BASE + 0xE2)) /* Version レジスタ (RO) */
|
||||
#define EXT_WP (*(vu16 *)(SD_IP_BASE + 0xF6)) /* 拡張SD Card ライトプロテクト (RO) */
|
||||
#define EXT_CD (*(vu16 *)(SD_IP_BASE + 0xF8)) /* 拡張SD Card 検出、挿入、抜け フラグ (R/W) */
|
||||
#define EXT_CD_DAT3 (*(vu16 *)(SD_IP_BASE + 0xFA)) /* 拡張SD Card 検出、挿入、抜け フラグ (R/W) */
|
||||
#define EXT_CD_MASK (*(vu16 *)(SD_IP_BASE + 0xFC)) /* 拡張SD Card 検出、挿入、抜け 割込みマスク (R/W) */
|
||||
#define EXT_CD_DAT3_MASK (*(vu16 *)(SD_IP_BASE + 0xFE)) /* 拡張SD Card 検出、挿入、抜け 割込みマスク (R/W) */
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
SD I/F(ラッパー)レジスタ
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define SD_IF_BASE (0x08030100) // NTR用ブレッドボード設定
|
||||
#else
|
||||
#define SD_IF_BASE (0x400B0100) // IOP実機設定
|
||||
#endif*/
|
||||
#define SD_IF_BASE (0x04004900) // IOP実機設定
|
||||
|
||||
|
||||
#define SDIF_CNT ((vu32 *)(SD_IF_BASE+0x00)) /* コントロール */
|
||||
#define SDIF_FDS ((vu32 *)(SD_IF_BASE+0x04)) /* FIFOサイズ */
|
||||
#define SDIF_FSC ((vu32 *)(SD_IF_BASE+0x08)) /* セクタカウント */
|
||||
#define SDIF_FI ((vu32 *)(SD_IF_BASE+0x0c)) /* FIFOウィンドウ */
|
||||
|
||||
#define SDIF_CNT_L ((vu16 *)(SD_IF_BASE+0x00))
|
||||
#define SDIF_CNT_H ((vu16 *)(SD_IF_BASE+0x02))
|
||||
#define SDIF_FDS_L ((vu16 *)(SD_IF_BASE+0x04))
|
||||
#define SDIF_FDS_H ((vu16 *)(SD_IF_BASE+0x06))
|
||||
#define SDIF_FSC_L ((vu16 *)(SD_IF_BASE+0x08))
|
||||
#define SDIF_FSC_H ((vu16 *)(SD_IF_BASE+0x0a))
|
||||
#define SDIF_FI_L ((vu16 *)(SD_IF_BASE+0x0c))
|
||||
#define SDIF_FI_H ((vu16 *)(SD_IF_BASE+0x0e))
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
INTCレジスタ
|
||||
*********************************************/
|
||||
/*#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define CTR_INT_BASE (0x08000000)
|
||||
#else
|
||||
#define CTR_INT_BASE (0x40010000)
|
||||
#endif
|
||||
|
||||
|
||||
#define CTR_INT_SE (CTR_INT_BASE + 0x00) //割り込み要求選択レジスタ
|
||||
#define CTR_INT_IE (CTR_INT_BASE + 0x04) //IE
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x08) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<13) //SD割り込みフラグ
|
||||
*/
|
||||
#define CTR_INT_BASE (0x04000000)
|
||||
|
||||
#define CTR_INT_SE (CTR_INT_BASE + 0x208) //割り込み要求選択レジスタ
|
||||
#define CTR_INT_IE (CTR_INT_BASE + 0x218) //IE
|
||||
#define CTR_INT_IF (CTR_INT_BASE + 0x21C) //IF
|
||||
|
||||
#define CTR_IE_SD_MASK (1<<8) //SD割り込みフラグ
|
||||
|
||||
|
||||
#endif /* __SD_IP_REG_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,77 +0,0 @@
|
||||
|
||||
#ifndef __SDMC_H__
|
||||
#define __SDMC_H__
|
||||
|
||||
//#include <brom.h>
|
||||
//#include <rtfs.h>
|
||||
|
||||
#include <firm/devices/firm_sdmc/ARM7/sdmc_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************
|
||||
RTFS用ドライバインタフェース
|
||||
*********************************************/
|
||||
#if 0
|
||||
BOOL sdmcRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading);
|
||||
int sdmcRtfsCtrl( int driveno, int opcode, void* pargs);
|
||||
BOOL sdmcRtfsAttach( int driveno);
|
||||
#endif
|
||||
|
||||
BOOL sdmcCheckMedia( void);
|
||||
|
||||
|
||||
/*********************************************
|
||||
データ転送関数の登録関連
|
||||
*********************************************/
|
||||
typedef void (*sdmcTransferFunction)( void* sd_adr, u32 size, BOOL read_flag);
|
||||
|
||||
//void sdmcSetTransferFunction( sdmcTransferFunction usr_func);
|
||||
|
||||
|
||||
/*********************************************
|
||||
基本API
|
||||
*********************************************/
|
||||
void sdmcClearPortContext( SDPortContext* buf_adr);
|
||||
SDMC_ERR_CODE sdmcCheckPortContext( SDPortContext* buf_adr);
|
||||
|
||||
|
||||
SDMC_ERR_CODE sdmcInit( SDMC_DMA_NO dma_no, void (*func1)(),void (*func2)());/* カードドライバ初期化 */
|
||||
SDMC_ERR_CODE sdmcReset( void); /* カードリセット */
|
||||
|
||||
SDMC_ERR_CODE sdmcGetStatus(u16 *status); /* カードドライバの現在の状態を取得する */
|
||||
u32 sdmcGetCardSize(void); /* カード全サイズの取得 */
|
||||
|
||||
/*SD I/FのFIFOを使ってリードする(高速)*/
|
||||
SDMC_ERR_CODE sdmcReadFifo(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcReadFifoDirect( sdmcTransferFunction usr_func,
|
||||
u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
SDMC_ERR_CODE sdmcReadStreamBegin( u32 offset, SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcReadStreamEnd( SdmcResultInfo *info);
|
||||
|
||||
|
||||
/*リードする*/
|
||||
//SDMC_ERR_CODE sdmcRead(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
/*SD I/FのFIFOを使ってライトする(高速)*/
|
||||
SDMC_ERR_CODE sdmcWriteFifo(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
SDMC_ERR_CODE sdmcWriteFifoDirect(sdmcTransferFunction usr_func,
|
||||
u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
/*ライトする*/
|
||||
//SDMC_ERR_CODE sdmcWrite(void* buf,u32 bufsize,u32 offset,void(*func)(void),SdmcResultInfo *info);
|
||||
|
||||
/*ポート選択*/
|
||||
u16 sdmcSelectedNo(void);
|
||||
SDMC_ERR_CODE sdmcSelect(u16 select);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*__SDMC_H__*/
|
||||
@ -1,87 +0,0 @@
|
||||
/*
|
||||
** Copyright (c) 2000-2001 Matsushita Electric Industrial Co., Ltd.
|
||||
** All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** $System IP1.1 without C2 サンプルソフト
|
||||
** $Subsystem カードドライバ
|
||||
** $Filename CARDDRV.H
|
||||
** $Version 1.0 版
|
||||
** $Date 01/02/16
|
||||
** $Log 01/02/16 rev1.0作成
|
||||
** 松下電器産業(株)半導体開発本部
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SDMC_CONFIG_H__
|
||||
#define __SDMC_CONFIG_H__
|
||||
|
||||
|
||||
#include <firm.h>
|
||||
|
||||
#ifdef USE_OS
|
||||
#include <sd_ip_reg.h> /* IP 対応レジスタ定義 */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*********************************************
|
||||
ターゲットOS
|
||||
*********************************************/
|
||||
#define TARGET_OS_CTR (0)
|
||||
#define TARGET_OS_NITRO (TARGET_OS_CTR ^ 1)
|
||||
|
||||
|
||||
/*********************************************
|
||||
SDドライバ コンフィグレーション
|
||||
*********************************************/
|
||||
#define SD_DEBUG_PRINT_ON 0 /* デバッグ表示 */
|
||||
|
||||
#define WP_ena 1 /* ライトプロテクトのチェック有効 */
|
||||
#define TIMEOUT 1 /* FPGA Timeout none = FALSE */
|
||||
#define SCR 1 /* Send SCR Command = TRUE */
|
||||
#define RESID 1 /* Write Error Resid enable = TRUE */
|
||||
#define ATC_ON 0 /* ATC転送 使用/未使用 */
|
||||
|
||||
#define SecEnable 1 /* SD_SECCNTレジスタ Enable */
|
||||
#define SecDisenable 0 /* SD_SECCNTレジスタ Disable */
|
||||
//#define STANDBYMODE 0x04 /*** 5772 standby control bit ***/
|
||||
|
||||
#define SDCARD_TIMER_ID (OS_TIMER_3)
|
||||
|
||||
|
||||
/*********************************************
|
||||
タイムアウト設定値(ms単位)
|
||||
*********************************************/
|
||||
#define SDCARD_RW_TIMEOUT (2000)
|
||||
#define SDCARD_STDBY_TIMEOUT (50)
|
||||
#define SDCARD_CLOCK_WAIT (500)
|
||||
#define SDCARD_SDCLK_WAIT (10)
|
||||
#define SDCARD_INITIAL_TIMEOUT (800)
|
||||
#define SDCARD_RESET_TIMEOUT (1500)
|
||||
#define SDCARD_ERASE_TIMEOUT (1)
|
||||
#define SDCARD_ERRPROC_TIMEOUT (2000)
|
||||
|
||||
|
||||
/*********************************************
|
||||
リトライ回数(Multiple Block R/W のとき)
|
||||
*********************************************/
|
||||
#define SDCARD_RETRY_COUNT (3)
|
||||
|
||||
/*********************************************
|
||||
その他
|
||||
*********************************************/
|
||||
#define SECTOR_SIZE (512) /* 1セクタのバイト数 */
|
||||
#define SECTOR_MAX (255) /* SYSFPGA アクセス最大セクタ数 */
|
||||
|
||||
/*--- 上位レイヤに返すステータス値(SDCARD_Getstatus参照)用 ---*/
|
||||
#define SDCARD_FLAG_CLR (0x3FFF) /* カード判定部分クリア用 */
|
||||
#define SDCARD_FLAG_SD (0x8000) /* カード判定部分SDカード */
|
||||
#define SDCARD_FLAG_MMC (0x4000) /* カード判定部分MMCカード */
|
||||
#define SDCARD_PORT1_CLR (0x0007) /* カードポート1判定部分クリア用 */
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /*__SDMC_CONFIG_H__*/
|
||||
@ -1,637 +0,0 @@
|
||||
/*
|
||||
Project: TwlBrom SD port driver
|
||||
File: Carddrv.c
|
||||
|
||||
2006, Research and Development Department, Nintendo.
|
||||
*/
|
||||
|
||||
#include "sdmc_config.h"
|
||||
#include "sdmc.h"
|
||||
#include "sdif_reg.h"
|
||||
#include "sdif_ip.h"
|
||||
#include <firm.h>
|
||||
//#include <twl/hw/ARM7/ioreg_MI.h>
|
||||
//#include "sdmc_config.h"
|
||||
//#include "sdif_reg.h" /* IP 対応レジスタ定義 */
|
||||
//#include <brom/rom_sdmc.h>
|
||||
//#include "sdif_ip.h" /* IP 対応フラグ定義 */
|
||||
|
||||
// #define PRINTDEBUG OS_TPrintf
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
定数
|
||||
***********************************************************************/
|
||||
static BOOL sdmcGetErrStat( void);
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
static関数の宣言
|
||||
***********************************************************************/
|
||||
static void SDCARD_Backup_port1(void);
|
||||
static void SDCARD_Restore_port1(void);
|
||||
|
||||
static int MMCP_SetBusWidth( BOOL b4bit); /* ビット幅の選択(MMCplus, eMMC, moviNAND) */
|
||||
|
||||
static SDMC_ERR_CODE SDCARD_Layer_Init(void);
|
||||
static SDMC_ERR_CODE i_sdmcMPInit( void); /* カードドライバ初期化(マルチポート対応) */
|
||||
|
||||
/***********************************************************************
|
||||
外部参照変数
|
||||
***********************************************************************/
|
||||
extern void SDCARD_Timer_irq(void* arg); /* タイムアウト割り込みハンドラ */
|
||||
extern void SDCARD_TimerCheck( void);
|
||||
extern void SDCARD_TimerStart(u32 tim); /* タイムアウト計測スタート */
|
||||
extern void SDCARD_TimerStop(void); /* タイムアウト計測停止 */
|
||||
|
||||
|
||||
extern u16 SD_CID[8]; /* CID値保存用 */
|
||||
extern u16 SD_CSD[8]; /* CSD値保存用 */
|
||||
extern u16 SD_OCR[2]; /* OCR値保存用 */
|
||||
extern u16 SD_SCR[4]; /* SCR値保存用 */
|
||||
extern u16 SD_RCA; /* RCA値保存用 */
|
||||
|
||||
extern s16 SDCARD_MMCFlag; /* MMCカードフラグ */
|
||||
extern s16 SDCARD_SDHCFlag; /* SDHCカードフラグ */
|
||||
extern u16 SD_port_number; /* 現在ポート番号 */
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
グローバル
|
||||
***********************************************************************/
|
||||
static u16 SD_SDSTATUS[32]; /* SD_STATUSレジスタ保存用 */
|
||||
static u16 SDCARD_WP_FLAG0; /* カードライトプロテクトフラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_FLAG1; /* カードライトプロテクトフラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_PERMANENT; /* カードライトプロテクト永久フラグ。0=なし、1=有り */
|
||||
static u16 SDCARD_WP_TEMPORARY; /* カードライトプロテクト一時フラグ。0=なし、1=有り */
|
||||
|
||||
static u32 SDCARD_SectorSize; /* セクタサイズ デフォルト 512bytes */
|
||||
|
||||
static u16 SD_INFO1_VALUE; /* SD_INFO1レジスタ取得用変数 */
|
||||
static u16 SD_INFO1_MASK_VALUE; /* SD_INFO1割込みマスク用変数(0で許可, 1で禁止) */
|
||||
static u16 SD_INFO2_VALUE; /* SD_INFO2レジスタ取得用変数 */
|
||||
static u16 SD_INFO2_MASK_VALUE; /* SD_INFO2割り込みマスク用変数(0で許可, 1で禁止) */
|
||||
static u16 SD_INFO_ERROR_VALUE; /* SD_INFO2, SD_INFO1のエラービット確認用変数 */
|
||||
|
||||
|
||||
/*ポート状態保存*/
|
||||
static SDPortContext SDPort0Context;
|
||||
static SDPortContext SDPort1Context;
|
||||
//SDPortContext *SDPortCurrentContext = &SDPort0Context; /*TODO*/
|
||||
|
||||
|
||||
|
||||
extern volatile SDMC_ERR_CODE SDCARD_ErrStatus; /* エラーステータス */
|
||||
extern volatile u32 SDCARD_Status; /* カードステータス */
|
||||
|
||||
static s16 SDCARD_SDFlag; /* SDカードフラグ */
|
||||
|
||||
static volatile s16 SDCARD_OutFlag = 0; /* カード排出発生判定フラグ */
|
||||
static SdmcResultInfo *pSDCARD_info = NULL; /* 保存用実行結果構造体ポインタ */
|
||||
|
||||
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no);
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcSavePortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファに退避する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcSavePortContext( SDPortContext* buf_adr, u16 port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( &SDPort0Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( &SDPort1Context, buf_adr, sizeof(SDPortContext));
|
||||
buf_adr->port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcLoadPortContext
|
||||
|
||||
Description: ポート0のレジスタや変数をユーザバッファから復帰する
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcLoadPortContext( SDPortContext* buf_adr, u16* port_no)
|
||||
{
|
||||
if( buf_adr == NULL) {
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
switch( buf_adr->port_no) {
|
||||
case 0:
|
||||
MI_CpuCopy8( buf_adr, &SDPort0Context, sizeof(SDPortContext));
|
||||
*port_no = 0;
|
||||
break;
|
||||
case 1:
|
||||
MI_CpuCopy8( buf_adr, &SDPort1Context, sizeof(SDPortContext));
|
||||
*port_no = 1;
|
||||
break;
|
||||
default: return( SDMC_ERR_PARAM);
|
||||
}
|
||||
return( SDMC_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Backup_port1
|
||||
|
||||
Description: backup registers and variables of port1.
|
||||
ポート1のレジスタや変数をバックアップする
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SDCARD_Backup_port1(void)
|
||||
{
|
||||
/* registers */
|
||||
SD_GetFPGA(SDPort1Context.SD_CLK_CTRL_VALUE,SD_CLK_CTRL);
|
||||
SD_GetFPGA(SDPort1Context.SD_OPTION_VALUE, SD_OPTION);
|
||||
|
||||
/* variables */
|
||||
SDPort1Context.SD_RCA = SD_RCA;
|
||||
SDPort1Context.ErrStatus = SDCARD_ErrStatus;
|
||||
SDPort1Context.Status = SDCARD_Status;
|
||||
SDPort1Context.MMCFlag = SDCARD_MMCFlag;
|
||||
SDPort1Context.SDHCFlag = SDCARD_SDHCFlag;
|
||||
SDPort1Context.SDFlag = SDCARD_SDFlag;
|
||||
|
||||
SDPort1Context.OutFlag = SDCARD_OutFlag;
|
||||
|
||||
/*media registers*/
|
||||
MI_CpuCopy8( SD_CID, SDPort1Context.SD_CID, 16);
|
||||
MI_CpuCopy8( SD_CSD, SDPort1Context.SD_CSD, 16);
|
||||
MI_CpuCopy8( SD_OCR, SDPort1Context.SD_OCR, 4);
|
||||
MI_CpuCopy8( SD_SCR, SDPort1Context.SD_SCR, 8);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Restore_port1
|
||||
|
||||
Description: restore registers and variables of port0.
|
||||
ポート1のレジスタや変数を復帰する。
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void SDCARD_Restore_port1(void)
|
||||
{
|
||||
/* registers */
|
||||
SD_SetFPGA( SD_CLK_CTRL, SDPort1Context.SD_CLK_CTRL_VALUE);
|
||||
SD_SetFPGA( SD_OPTION, SDPort1Context.SD_OPTION_VALUE);
|
||||
|
||||
/* variables */
|
||||
SD_RCA = SDPort1Context.SD_RCA;
|
||||
SDCARD_ErrStatus = SDPort1Context.ErrStatus;
|
||||
SDCARD_Status = SDPort1Context.Status;
|
||||
SDCARD_MMCFlag = SDPort1Context.MMCFlag;
|
||||
SDCARD_SDHCFlag = SDPort1Context.SDHCFlag;
|
||||
SDCARD_SDFlag = SDPort1Context.SDFlag;
|
||||
|
||||
SDCARD_OutFlag = SDPort1Context.OutFlag;
|
||||
pSDCARD_info = NULL;
|
||||
|
||||
/*media registers*/
|
||||
MI_CpuCopy8( SDPort1Context.SD_CID, SD_CID, 16);
|
||||
MI_CpuCopy8( SDPort1Context.SD_CSD, SD_CSD, 16);
|
||||
MI_CpuCopy8( SDPort1Context.SD_OCR, SD_OCR, 4);
|
||||
MI_CpuCopy8( SDPort1Context.SD_SCR, SD_SCR, 8);
|
||||
|
||||
/*recalc*/
|
||||
SDCARD_WP_PERMANENT = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_PERMANENT_BIT));
|
||||
SDCARD_WP_TEMPORARY = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_TEMPORARY_BIT));
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcNandInit
|
||||
|
||||
Description: Initialize SD interface and SD card.
|
||||
初期化
|
||||
|
||||
Arguments: dma_no : 使用するDMA番号
|
||||
func1 : カード挿入時コールバック関数
|
||||
func2 : カード排出時コールバック関数
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcNandInit( void)
|
||||
{
|
||||
/* SD初期化 */
|
||||
SDCARD_ErrStatus = sdmcReset();
|
||||
|
||||
if(!SDCARD_ErrStatus) {
|
||||
SDCARD_ErrStatus = i_sdmcMPInit();
|
||||
}
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcReset
|
||||
|
||||
Description: reset SD card.
|
||||
リセット
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE sdmcReset( void)
|
||||
{
|
||||
OSIntrMode irq_core_flag;
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカード判定フラグクリア */
|
||||
SDCARD_SDHCFlag = FALSE;
|
||||
SDCARD_SDFlag = FALSE; /* SDカード判定フラグクリア */
|
||||
|
||||
/*** カードステータスをクリア ***/
|
||||
SDCARD_ErrStatus = SDMC_NORMAL;
|
||||
SDCARD_Status = SDMC_NORMAL;
|
||||
|
||||
/*** カードCSD WPビットをクリア ***/
|
||||
SDCARD_WP_FLAG0 = 0;
|
||||
SDCARD_WP_FLAG1 = 0;
|
||||
SDCARD_WP_PERMANENT = 0;
|
||||
SDCARD_WP_TEMPORARY = 0;
|
||||
|
||||
irq_core_flag = OS_DisableInterrupts(); /* 割込み禁止 */
|
||||
|
||||
*SDIF_CNT_L = 0x0402; //ラッパーレジスタ
|
||||
*SDIF_CNT_L = 0x0000; //ラッパーレジスタ
|
||||
*SDIF_FDS_L = 0;
|
||||
*SDIF_FSC_L = 1;
|
||||
SD_Init(); /* SD Card I/F 初期化処理 */
|
||||
SD_AndFPGA( SD_OPTION, SD_CD_DETECT_TIME); /* CD 検出タイムをゼロクリア */
|
||||
|
||||
SD_port_number = SDCARD_PORT1; /*** 現在のポート番号をデフォルトに設定 ***/
|
||||
|
||||
// SDCARD_Backup_port1(); /* port1 backup */
|
||||
|
||||
OS_RestoreInterrupts( irq_core_flag); /* 割り込み設定を元に戻す */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: SDCARD_Layer_Init
|
||||
|
||||
Description: initialize sequence for SD card.
|
||||
SDカード規定の初期化手順
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE SDCARD_Layer_Init(void)
|
||||
{
|
||||
u32 ulCSize;
|
||||
u16 read_block_len_val, mult_val;
|
||||
|
||||
// u16 memory_exist, function_number;
|
||||
SDCARD_Status = SDMC_NORMAL; /* カードステータスをクリア */
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカード判定フラグクリア */
|
||||
SDCARD_SDHCFlag = FALSE;
|
||||
SDCARD_SDFlag = FALSE; /* SDカード判定フラグクリア */
|
||||
|
||||
SD_SetFPGA(SD_CLK_CTRL,(SD_CLK_CTRL_128)); /* SDクロックの周波数 261KHz(初期化時は100~400khz) */
|
||||
SD_EnableClock(); /* SDカードのクロックをイネーブルにする */
|
||||
|
||||
/* SD I/F部ダミー80クロック(1mSec)転送待ち(タイマーで待ちを実装しても良い) */
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
|
||||
SDCARD_ErrStatus = SDMC_NORMAL; /* エラーステータスをクリア */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
|
||||
#if TIMEOUT
|
||||
SDCARD_TimerStart(SDCARD_RESET_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
|
||||
PRINTDEBUG( " CMD0(GO_IDLE_STATE)\n");
|
||||
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT)); /* タイムアウト以外のエラーをクリア */
|
||||
SD_Command(SD_CMD_CMD | GO_IDLE_STATE); /* CMD0発行、レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*------- idle state -------*/
|
||||
SVC_WaitByLoop( 17900); //179*4サイクル=716サイクル=10024ns=10us
|
||||
|
||||
while(!(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT)){ /* タイムアウトになったら抜ける */
|
||||
/******************/
|
||||
SDCARD_TimerCheck();
|
||||
/******************/
|
||||
SD_ClrErr((u16)(~SDMC_ERR_FPGA_TIMEOUT));
|
||||
|
||||
SD_RCA = 0; /* RCA = 0をセット */
|
||||
|
||||
if(!SDCARD_MMCFlag){ /* MMCカードフラグが 0(OFF) か? */
|
||||
|
||||
if( SD_AppCommand() == SDMC_NORMAL) { /* CMD55 発行処理が正常か? */
|
||||
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカードフラグクリア */
|
||||
if(!SD_AppOpCond()){ /* ACMD41発行処理が正常か?(OCR31bit = L の時 No Response) */
|
||||
|
||||
SDCARD_SDFlag = TRUE; /* SDカードフラグセット */
|
||||
break;
|
||||
}
|
||||
}else{ /* CMD55 が正常終了しない */
|
||||
if(SDCARD_ErrStatus == SDMC_ERR_TIMEOUT){ /* タイムアウト(==No Response)か? */
|
||||
SDCARD_MMCFlag = TRUE; /* MMCカードフラグセット */
|
||||
}else{
|
||||
// break; //コメントアウトしないとSDカードの初期化に失敗する
|
||||
}
|
||||
}
|
||||
}
|
||||
if(SDCARD_MMCFlag){ /* MMCカードフラグが 1(ON) のとき */
|
||||
SD_RCA = 1; /* RCA = 1をセット */
|
||||
if(!SD_SendOpCond()){ /* CMD1発行処理が正常か? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?)*/
|
||||
if(SDCARD_ErrStatus & SDMC_ERR_FPGA_TIMEOUT){ /* タイムアウトエラーかチェック */
|
||||
SD_ClrErr(SDMC_ERR_FPGA_TIMEOUT); /* タイムアウトエラーの設定クリア */
|
||||
SD_SetErr(SDMC_ERR_RESET); /* 初期化カードリセットコマンド時1.5秒タイムアウトエラーの設定 */
|
||||
}
|
||||
SDCARD_MMCFlag = FALSE; /* MMCカードフラグクリア */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
#if TIMEOUT
|
||||
SDCARD_TimerStart(SDCARD_INITIAL_TIMEOUT); /* タイムアウト判定用タイマスタート */
|
||||
#endif
|
||||
|
||||
SD_SendCID(); /* CMD2発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
while(1){
|
||||
/******************/
|
||||
SDCARD_TimerCheck();
|
||||
/******************/
|
||||
SD_SendRelativeAddr(); /* CMD3発行 レスポンス確認 正常終了時 RCA<-ResのRCA */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
if(SD_RCA != 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*------- standby state -------*/
|
||||
SD_SendCSD(); /* CMD9発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
SDCARD_WP_PERMANENT = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_PERMANENT_BIT));
|
||||
SDCARD_WP_TEMPORARY = (u16)(SD_CSD[0] & (u16)(SDCARD_WP_TEMPORARY_BIT));
|
||||
|
||||
/* 転送速度設定 */
|
||||
SD_ClockDivSet(SD_RSP5); /* SDカードの動作クロック設定 (CSD[5]) */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/* Command toggles acard between the Stand-by and Transfer states */
|
||||
SD_SelectCard(); /* CMD7発行 レスポンス確認 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*------- translate state -------*/
|
||||
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
SD_SetBlockLength(SDCARD_SectorSize); /* CMD16 ブロックサイズの設定 */
|
||||
if(SDCARD_ErrStatus){ /* エラーステータスの確認(エラー有り?) */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
SD_SCR[0] |= SCR_DAT_BUS_WIDTH_4BIT; //SCRの必要な部分のみ
|
||||
|
||||
SD_EnableClock(); /* SD-CLK Enable */
|
||||
|
||||
if(SDCARD_MMCFlag){ /* MMCカード ON かチェック */
|
||||
if( ((SD_CSD[7] & 0x3C)>>2) >= 4) {
|
||||
MMCP_SetBusWidth( TRUE);
|
||||
}
|
||||
// SD_SelectBitWidth(FALSE); /* CMD55->ACMD6 ビット幅の選択 1bit */
|
||||
}else{
|
||||
SD_SelectBitWidth(TRUE); /* CMD55->ACMD6 ビット幅の選択 4bit */
|
||||
}
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_sdmcMPInit
|
||||
|
||||
Description: initialize SD card in multi ports.
|
||||
マルチポートのSDカード初期化
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
static SDMC_ERR_CODE i_sdmcMPInit( void)
|
||||
{
|
||||
u16 load_port_no;
|
||||
SDPortContext* SDNandContext;
|
||||
|
||||
//予約領域のポートコンテキスト参照
|
||||
SDNandContext = (SDPortContext*)&(((OSFromBromBuf*)OSi_GetFromBromAddr())->SDNandContext);
|
||||
|
||||
//NANDスロットの初期化
|
||||
SD_SetFPGA( SD_PORTSEL, SDMC_PORT_NAND); /* NANDポート選択 */
|
||||
|
||||
// OS_TPrintf( "SDNandContext : 0x%x\n", SDNandContext);
|
||||
//初期化済みでないときだけ初期化
|
||||
if( sdmcCheckPortContext( SDNandContext) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "sdmcCheckPortContext : ERR!\n");
|
||||
SDCARD_ErrStatus = SDCARD_Layer_Init();
|
||||
|
||||
SDCARD_Backup_port1();
|
||||
//ポートコンテキストの保存
|
||||
if( i_sdmcSavePortContext( SDNandContext, 1) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "i_sdmcSavePortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
}else{ //ポートコンテキストの復帰
|
||||
// OS_TPrintf( "sdmcCheckPortContext : NORMAL\n");
|
||||
|
||||
/*SDCARD_Layer_Init()の代わり*/
|
||||
SDCARD_SectorSize = SECTOR_SIZE; /* セクタサイズ デフォルト 512bytes */
|
||||
|
||||
if( i_sdmcLoadPortContext( SDNandContext, &load_port_no) != SDMC_NORMAL) {
|
||||
// OS_TPrintf( "i_sdmcLoadPortContext failed\n");
|
||||
return( SDMC_ERR_PARAM);
|
||||
}
|
||||
SDCARD_Restore_port1(); //TODO:load_port_no値判定
|
||||
}
|
||||
|
||||
SDCARD_OutFlag = FALSE; /* 排出フラグをリセット */
|
||||
|
||||
SDCARD_TimerStop(); /* タイムアウト判定用タイマストップ */
|
||||
SD_DisableClock(); /* SD-CLK Disable */
|
||||
SD_EnableInfo(); /* SD Card 挿抜 割り込み許可 */
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcGetStatus
|
||||
|
||||
Description: get card status
|
||||
カードの状態を取得する
|
||||
bit15 SDカード判別ビット(検出したら1)
|
||||
bit14 MMCカード判別ビット(検出したら1)
|
||||
bit10 IO3 card detect(検出したら1) ※CTRではプルアップのため使えない
|
||||
bit9 IO3 card inserted(挿入動作で1) ※CTRではプルアップのため使えない
|
||||
bit8 IO3 card removed(脱動作で1) ※CTRではプルアップのため使えない
|
||||
bit7 write protect(書き込み禁止の場合1)
|
||||
bit5 card detect(検出したら1)
|
||||
bit4 card inserted(挿入動作で1)
|
||||
bit3 card removed(脱動作で1)
|
||||
bit2 R/W access all end
|
||||
bit0 Response end
|
||||
|
||||
Arguments: *status : カードの状態を格納する変数へのポインタ
|
||||
|
||||
Returns: 0 : success
|
||||
> 0 : error code
|
||||
*---------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------
|
||||
SD_INFO1レジスタ
|
||||
bit[10,9,8,7] = DAT3CD, DAT3IN, DAT3OUT, WP
|
||||
bit[5, 4, 3, 2] = CD, INS, REM, ALLEND
|
||||
bit0 = RESEND
|
||||
-------------------------------------------------
|
||||
EXT_CDレジスタ
|
||||
bit[2,1,0] = P1CD, P1INS, P1REM
|
||||
-------------------------------------------------
|
||||
EXT_CD_DAT3レジスタ
|
||||
bit[2, 1, 0] = P1DCD, P1DINS, P1DREM
|
||||
-------------------------------------------------
|
||||
EXT_WPレジスタ
|
||||
bit0 = P1WP
|
||||
-----------------------------------------------*/
|
||||
SDMC_ERR_CODE sdmcGetStatus(u16 *status)
|
||||
{
|
||||
u16 SD_INFO1_STATUS;
|
||||
|
||||
SD_INFO1_STATUS = SD_INFO1; /* SD_INFO1レジスタ読み出し */
|
||||
*status = SD_INFO1_STATUS; /* 論理反転 */
|
||||
|
||||
/*--- ポート0のとき ---*/
|
||||
if(SD_port_number == SDCARD_PORT0)
|
||||
{
|
||||
*status &= SDCARD_FLAG_CLR; /* SD/MMCフラグクリア */
|
||||
}
|
||||
/*--- ポート1のとき ---*/
|
||||
else if (SD_port_number == SDCARD_PORT1)
|
||||
{
|
||||
*status &= SDCARD_PORT1_CLR; /* port1に関係ない部分をクリア */
|
||||
SD_INFO1_STATUS = (u16)((EXT_CD & 0x0007) << 3);
|
||||
SD_INFO1_STATUS |= ((EXT_CD_DAT3 & 0x0007) << 8);
|
||||
SD_INFO1_STATUS |= ((EXT_WP & 0x0001) << 7);
|
||||
*status |= SD_INFO1_STATUS; /* カードport1フラグ設定 */
|
||||
}
|
||||
/*--- SD/MMCフラグをセット ---*/
|
||||
if( SDCARD_MMCFlag) { /* 検出したカードがMMCカードの時 */
|
||||
*status |= SDCARD_FLAG_MMC; /* カード判定部分MMCカード */
|
||||
}
|
||||
if( SDCARD_SDFlag) { /* 検出したカードがSDカードの時 */
|
||||
*status |= SDCARD_FLAG_SD; /* カード判定部分SDカード */
|
||||
}
|
||||
|
||||
return SDMC_NORMAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
static int MMCP_SetBusWidth( BOOL b4bit)
|
||||
{
|
||||
SD_EnableClock(); /* SD-CLK Enable */
|
||||
|
||||
/*コマンド6発行*/
|
||||
MMCP_WriteBusWidth( b4bit);
|
||||
SD_AndFPGA(SD_OPTION,(~SD_OPTION_WIDTH_1BIT)); /* IPにビット幅の設定(4bit幅) */
|
||||
|
||||
return( 0);
|
||||
}
|
||||
/*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: sdmcGetErrStat
|
||||
|
||||
Description: エラー取得
|
||||
|
||||
Arguments:
|
||||
|
||||
Returns: TRUE : success
|
||||
FALSE : error
|
||||
*---------------------------------------------------------------------------*/
|
||||
static BOOL sdmcGetErrStat( void)
|
||||
{
|
||||
PRINTDEBUG( "SD_INFO2:0x%x\n", SD_INFO2);
|
||||
|
||||
/*--- 取得 ---*/
|
||||
SD_GetFPGA( SD_INFO2_VALUE, SD_INFO2);
|
||||
/*------------------------------------------*/
|
||||
|
||||
/*--- SD_INFO2のエラーフラグ作成 ---*/
|
||||
SD_INFO_ERROR_VALUE = (u16)(SD_INFO2_VALUE & 0x807F);//
|
||||
/*--- エラーステータス作成 (RESTIMEOUTとILAエラーのフラグは反映しない) ---*/
|
||||
SDCARD_ErrStatus |= SD_INFO_ERROR_VALUE & (~(SD_INFO2_ERR_RESTIMEOUT)) &
|
||||
(~(SD_INFO2_ERR_ILA)) & SD_INFO2_MASK_ERRSET;
|
||||
|
||||
/*--- RESTIMEOUTとILAエラーはフラグの位置をずらして反映する ---*/
|
||||
if( SD_INFO_ERROR_VALUE & SD_INFO2_ERR_ILA) {
|
||||
SDCARD_ErrStatus |= SDMC_ERR_ILA; /* イリーガルアクセスエラー発生 */
|
||||
}
|
||||
if( SD_INFO_ERROR_VALUE & SD_INFO2_ERR_RESTIMEOUT) {
|
||||
SDCARD_ErrStatus |= SDMC_ERR_TIMEOUT; /* Response Time out エラー発生 */
|
||||
}/*------------------------------------------------------------*/
|
||||
|
||||
SD_AndFPGA( SD_INFO2,(~(SD_INFO2_ERROR_SET))); /* SD_INFO2のエラーフラグを全て落とす */
|
||||
|
||||
if( (SD_INFO_ERROR_VALUE) != 0) {
|
||||
return( FALSE);
|
||||
}else{
|
||||
return( TRUE);
|
||||
}
|
||||
}
|
||||
@ -24,12 +24,6 @@
|
||||
#include <twl/aes/ARM7/lo.h>
|
||||
#include <rtfs.h>
|
||||
|
||||
//#include <twl/os/ARM7/debugLED.h>
|
||||
|
||||
#define OS_InitDebugLED() (TRUE)
|
||||
#define OS_SetDebugLED(pattern) (TRUE)
|
||||
#define OS_GetDebugLED() (TRUE)
|
||||
|
||||
extern u32 NAND_FAT_PARTITION_COUNT;
|
||||
|
||||
#define DMA_PIPE 2
|
||||
@ -93,6 +87,15 @@ static inline void MIi_NDmaRecv(u32 ndmaNo, const void *src, void *dest, u32 siz
|
||||
MIi_SetWordCount( ndmaNo, size/4 );
|
||||
MIi_SetControl( ndmaNo, MI_NDMA_BWORD_16 | MI_NDMA_SRC_FIX | MIi_DEST_INC | MIi_IMM | MI_NDMA_ENABLE );
|
||||
}
|
||||
static inline void MIi_Sd1_NDmaRecv(u32 ndmaNo, void *dest, u32 size)
|
||||
{
|
||||
MIi_SetSrc( ndmaNo, (u32)SDIF_FI );
|
||||
MIi_SetDest( ndmaNo, (u32)dest );
|
||||
MIi_SetInterval( ndmaNo, MI_NDMA_NO_INTERVAL, MI_NDMA_INTERVAL_PS_1 );
|
||||
MIi_SetTotalWordCount( ndmaNo, size/4 );
|
||||
MIi_SetWordCount( ndmaNo, SECTOR_SIZE/4 );
|
||||
MIi_SetControl( ndmaNo, MI_NDMA_BWORD_128 | MI_NDMA_SRC_FIX | MIi_DEST_INC | MI_NDMA_TIMING_SD_1 | MI_NDMA_ENABLE );
|
||||
}
|
||||
|
||||
static inline void MIi_NDmaPipeSetup(u32 ndmaNo, const void *src, void *dest, u32 size)
|
||||
{
|
||||
@ -113,13 +116,12 @@ static inline void MIi_NDmaRestart(u32 ndmaNo)
|
||||
/*
|
||||
専用NAND関数
|
||||
*/
|
||||
//extern void SDCARD_TimerStart(u32 tim); /* タイムアウト計測スタート */
|
||||
extern volatile SDMC_ERR_CODE SDCARD_ErrStatus;
|
||||
extern s16 SDCARD_SDHCFlag; /* SDHCカードフラグ */
|
||||
extern SDPortContext* SDNandContext; /* NAND初期化パラメータ */
|
||||
|
||||
static inline void WaitFifoFull( void )
|
||||
{
|
||||
// SDCARD_TimerStart(SDCARD_RW_TIMEOUT); /* タイムアウト判定用タイマスタート(2000msec) */
|
||||
while( (*SDIF_CNT & SDIF_CNT_FULL) == 0 )
|
||||
{
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL ) // an error was occurred
|
||||
@ -133,11 +135,10 @@ static void StartToRead(u32 block, u32 count)
|
||||
{
|
||||
*SDIF_FSC = count;
|
||||
*SDIF_FDS = SECTOR_SIZE;
|
||||
*SDIF_CNT = (*SDIF_CNT & ~SDIF_CNT_FEIE) | SDIF_CNT_FFIE | SDIF_CNT_FCLR | SDIF_CNT_USEFIFO;
|
||||
*SDIF_CNT = (*SDIF_CNT & ~(SDIF_CNT_FEIE | SDIF_CNT_FFIE)) | SDIF_CNT_FCLR | SDIF_CNT_USEFIFO;
|
||||
CC_EXT_MODE = CC_EXT_MODE_DMA;
|
||||
|
||||
SDCARD_ErrStatus = SDMC_NORMAL;
|
||||
// SDCARD_TimerStart(SDCARD_RW_TIMEOUT); /* タイムアウト判定用タイマスタート(2000msec) */
|
||||
SD_EnableClock();
|
||||
SD_EnableSeccnt(count);
|
||||
if ( SDCARD_SDHCFlag )
|
||||
@ -146,13 +147,13 @@ static void StartToRead(u32 block, u32 count)
|
||||
}
|
||||
else
|
||||
{
|
||||
SD_MultiReadBlock(block * SECTOR_SIZE);
|
||||
SD_MultiReadBlock( block * SECTOR_SIZE );
|
||||
}
|
||||
}
|
||||
|
||||
static void StopToRead( void )
|
||||
{
|
||||
if( !SD_CheckFPGAReg(SD_STOP,SD_STOP_SEC_ENABLE) ){
|
||||
if( !SD_CheckFPGAReg( SD_STOP,SD_STOP_SEC_ENABLE ) ){
|
||||
SD_StopTransmission(); /* カード転送終了をFPGAに通知(CMD12発行) */
|
||||
}
|
||||
SD_TransEndFPGA(); /* 転送終了処理(割り込みマスクを禁止に戻す) */
|
||||
@ -208,29 +209,18 @@ void FATFS_DisableAES( void )
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
Returns: 0 if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void ReadNormal(u32 block, void *dest, u16 count)
|
||||
static u16 ReadNormal(u32 block, void *dest, u16 count)
|
||||
{
|
||||
OS_SetDebugLED((u8)(0x80 | block));
|
||||
//MI_StopNDma( DMA_PIPE ); // already stopped
|
||||
//MI_StopNDma( DMA_RECV ); // already stopped
|
||||
OS_TPrintf("ReadNormal(%d, 0x%08X, %d) is calling.\n", block, dest, count);
|
||||
|
||||
MIi_Sd1_NDmaRecv( DMA_PIPE, dest, (u32)(count * SECTOR_SIZE) );
|
||||
StartToRead( block, count );
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while ( count-- ) // TODO: 自動起動DMA1つで十分なはず
|
||||
{
|
||||
WaitFifoFull();
|
||||
MIi_NDmaRecv( DMA_PIPE, (void*)SDIF_FI, dest, SECTOR_SIZE );
|
||||
MI_WaitNDma( DMA_PIPE );
|
||||
dest = (void*)((u32)dest + SECTOR_SIZE);
|
||||
}
|
||||
MI_WaitNDma( DMA_PIPE );
|
||||
StopToRead();
|
||||
OS_SetDebugLED((u8)(0x90 | block));
|
||||
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -242,15 +232,14 @@ OS_SetDebugLED((u8)(0x90 | block));
|
||||
dest: dest address (4 bytes alignment)
|
||||
count: sectors to transfer
|
||||
|
||||
Returns: None
|
||||
Returns: 0 if success
|
||||
*---------------------------------------------------------------------------*/
|
||||
#define PIPE_SIZE 64
|
||||
static void ReadAES(u32 block, void *dest, u16 count)
|
||||
static u16 ReadAES(u32 block, void *dest, u16 count)
|
||||
{
|
||||
u32 offset = 0; // in bytes
|
||||
OS_SetDebugLED((u8)(0xC0 | block));
|
||||
//MI_StopNDma( DMA_PIPE ); // already stopped
|
||||
//MI_StopNDma( DMA_RECV ); // already stopped
|
||||
|
||||
OS_TPrintf("ReadAES(%d, 0x%08X, %d) is calling.\n", block, dest, count);
|
||||
|
||||
MIi_NDmaPipeSetup( DMA_PIPE, (void*)SDIF_FI, (void*)REG_AES_IFIFO_ADDR, PIPE_SIZE );
|
||||
|
||||
@ -267,7 +256,7 @@ OS_SetDebugLED((u8)(0xC0 | block));
|
||||
StartToRead( block, count );
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL )
|
||||
{
|
||||
return;
|
||||
goto err;
|
||||
}
|
||||
|
||||
while ( block * SECTOR_SIZE > offset )
|
||||
@ -278,6 +267,10 @@ OS_SetDebugLED((u8)(0xC0 | block));
|
||||
if ( (offset & SECTOR_SIZE) == 0 )
|
||||
{
|
||||
WaitFifoFull();
|
||||
if ( SDCARD_ErrStatus != SDMC_NORMAL )
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
MIi_NDmaRestart( DMA_PIPE );
|
||||
offset += PIPE_SIZE;
|
||||
@ -285,7 +278,14 @@ OS_SetDebugLED((u8)(0xC0 | block));
|
||||
MI_WaitNDma( DMA_PIPE );
|
||||
StopToRead();
|
||||
MI_WaitNDma( DMA_RECV );
|
||||
OS_SetDebugLED((u8)(0xD0 | block));
|
||||
return SDCARD_ErrStatus;
|
||||
|
||||
err:
|
||||
MI_StopNDma( DMA_RECV );
|
||||
MI_StopNDma( DMA_PIPE );
|
||||
StopToRead();
|
||||
AESi_Reset();
|
||||
return SDCARD_ErrStatus;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -301,36 +301,26 @@ OS_SetDebugLED((u8)(0xD0 | block));
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
static BOOL nandRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOOL reading)
|
||||
static BOOL nandRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOOL reading )
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
u16 result;
|
||||
#pragma unused( driveno)
|
||||
|
||||
/**/
|
||||
sdmcSelect( (u16)SDMC_PORT_NAND);
|
||||
|
||||
if( reading) {
|
||||
if (useAES)
|
||||
{
|
||||
ReadAES(block, buffer, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadNormal(block, buffer, count);
|
||||
}
|
||||
result = 0; // always success
|
||||
// result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
if( reading )
|
||||
{
|
||||
result = useAES ?
|
||||
ReadAES( block, buffer, count ) :
|
||||
ReadNormal( block, buffer, count );
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
SdmcResultInfo SdResult;
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return result ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -346,36 +336,26 @@ static BOOL nandRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOO
|
||||
|
||||
Returns: TRUE/FALSE
|
||||
*---------------------------------------------------------------------------*/
|
||||
static BOOL sdmcRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOOL reading)
|
||||
static BOOL sdmcRtfsIoFirm( int driveno, u32 block, void* buffer, u16 count, BOOL reading )
|
||||
{
|
||||
u16 result;
|
||||
SdmcResultInfo SdResult;
|
||||
u16 result;
|
||||
#pragma unused( driveno)
|
||||
|
||||
/**/
|
||||
sdmcSelect( (u16)SDMC_PORT_CARD);
|
||||
sdmcSelect( (u16)SDMC_PORT_CARD );
|
||||
|
||||
if( reading) {
|
||||
if (useAES)
|
||||
{
|
||||
ReadAES(block, buffer, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadNormal(block, buffer, count);
|
||||
}
|
||||
result = 0; // always success
|
||||
// result = sdmcReadFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcRead( buffer, count, block, NULL, &SdResult);
|
||||
}else{
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult);
|
||||
// result = sdmcWrite( buffer, count, block, NULL, &SdResult);
|
||||
if( reading )
|
||||
{
|
||||
result = useAES ?
|
||||
ReadAES( block, buffer, count ) :
|
||||
ReadNormal( block, buffer, count );
|
||||
}
|
||||
if( result) {
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
SdmcResultInfo SdResult;
|
||||
result = sdmcWriteFifo( buffer, count, block, NULL, &SdResult );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return result ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -394,8 +374,9 @@ static BOOL nandRtfsAttachFirm( int driveno, int partition_no)
|
||||
BOOLEAN result;
|
||||
DDRIVE pdr;
|
||||
|
||||
if( partition_no >= NAND_FAT_PARTITION_COUNT) {
|
||||
return( FALSE);
|
||||
if( partition_no >= NAND_FAT_PARTITION_COUNT )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pdr.dev_table_drive_io = nandRtfsIoFirm;
|
||||
@ -408,25 +389,26 @@ static BOOL nandRtfsAttachFirm( int driveno, int partition_no)
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
switch( partition_no) {
|
||||
case 0:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p0"); //構造体がFSライブラリ側にコピーされる
|
||||
switch( partition_no )
|
||||
{
|
||||
case 0:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p0" ); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 1:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p1"); //構造体がFSライブラリ側にコピーされる
|
||||
case 1:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p1" ); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 2:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p2"); //構造体がFSライブラリ側にコピーされる
|
||||
case 2:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p2" ); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
case 3:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p3"); //構造体がFSライブラリ側にコピーされる
|
||||
case 3:
|
||||
result = rtfs_attach( driveno, &pdr, "SD1p3" ); //構造体がFSライブラリ側にコピーされる
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
result = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
return( result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -455,9 +437,9 @@ static BOOL sdmcRtfsAttachFirm( int driveno)
|
||||
pdr.controller_number = 0;
|
||||
pdr.logical_unit_number = 0;
|
||||
|
||||
result = rtfs_attach( driveno, &pdr, "SD0"); //構造体がFSライブラリ側にコピーされる
|
||||
result = rtfs_attach( driveno, &pdr, "SD0" ); //構造体がFSライブラリ側にコピーされる
|
||||
|
||||
return( result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
@ -469,16 +451,19 @@ static BOOL sdmcRtfsAttachFirm( int driveno)
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_InitFIRM( void )
|
||||
BOOL FATFS_InitFIRM( void* nandContext )
|
||||
{
|
||||
/* RTFSライブラリを初期化 */
|
||||
if(!FATFSi_rtfs_init())
|
||||
if( !FATFSi_rtfs_init() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* NAND初期化パラメータの設定 */
|
||||
SDNandContext = (SDPortContext*)nandContext;
|
||||
|
||||
/* SDドライバ初期化 */
|
||||
if (FATFSi_sdmcInit(SDMC_NOUSE_DMA, NULL, NULL) != SDMC_NORMAL)
|
||||
if ( FATFSi_sdmcInit( SDMC_NOUSE_DMA, NULL, NULL ) != SDMC_NORMAL )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@ -496,22 +481,22 @@ BOOL FATFS_InitFIRM( void )
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_MountDriveFirm( int driveno, FATFSMediaType media, int partition_no )
|
||||
{
|
||||
if (media == FATFS_MEDIA_TYPE_NAND)
|
||||
if ( media == FATFS_MEDIA_TYPE_NAND )
|
||||
{
|
||||
// CAUTION!: 同じ関数を2回呼び出す理由について要確認。
|
||||
if ( !nandRtfsAttachFirm(driveno, partition_no) || nandRtfsAttachFirm(driveno, partition_no))
|
||||
if ( !nandRtfsAttachFirm( driveno, partition_no ) || nandRtfsAttachFirm( driveno, partition_no ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (partition_no) // support only 0
|
||||
if ( partition_no ) // support only 0
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
// CAUTION!: 同じ関数を2回呼び出す理由について要確認。
|
||||
if ( !sdmcRtfsAttachFirm(driveno) || sdmcRtfsAttachFirm(driveno))
|
||||
if ( !sdmcRtfsAttachFirm( driveno ) || sdmcRtfsAttachFirm( driveno ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ static int menu_fd = -1;
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_OpenRecentMenu( int driveno )
|
||||
{
|
||||
char menufile[] = "A:\\ipl\\menu.srl";
|
||||
char *menufile = (char*)L"A:\\ipl\\menu.srl";
|
||||
if (driveno < 0 || driveno >= 26)
|
||||
{
|
||||
return FALSE;
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
#include <nitro/code32.h>
|
||||
#include <firm.h>
|
||||
|
||||
#define FIRM_ENABLE_JTAG
|
||||
|
||||
extern void TwlMain(void);
|
||||
extern void OS_IrqHandler(void);
|
||||
extern void *const _start_ModuleParams[];
|
||||
@ -54,10 +56,12 @@ extern void SDK_AUTOLOAD_LIST_END(void); // end pointer to autoload infor
|
||||
*---------------------------------------------------------------------------*/
|
||||
SDK_WEAK_SYMBOL asm void _start( void )
|
||||
{
|
||||
#ifdef FIRM_ENABLE_JTAG
|
||||
ldr r1, =REG_JTAG_ADDR
|
||||
ldrh r2, [r1]
|
||||
orr r2, r2, #REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK
|
||||
strh r2, [r1]
|
||||
#endif
|
||||
|
||||
//---- set IME = 0
|
||||
// ( use that LSB of HW_REG_BASE equal to 0 )
|
||||
@ -234,13 +238,19 @@ SDK_WEAK_SYMBOL asm void _start_AutoloadDoneCallback( void* argv[] )
|
||||
|
||||
Description: detect main memory size.
|
||||
result is written into (u32*)HW_MMEMCHECKER_SUB.
|
||||
value is [OS_CONSOLE_SIZE_4MB|OS_CONSOLE_SIZE_8MB]
|
||||
value is [OS_CONSOLE_SIZE_4MB|OS_CONSOLE_SIZE_8MB|
|
||||
OS_CONSOLE_SIZE_16MB|OS_CONSOLE_SIZE_32MB]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Arguments: None.
|
||||
|
||||
Returns: None.
|
||||
*---------------------------------------------------------------------------*/
|
||||
#define OSi_IMAGE_DIFFERENCE 0x400000
|
||||
#define OSi_IMAGE_DIFFERENCE 0x400000
|
||||
#define OSi_IMAGE_DIFFERENCE2 0xb00000
|
||||
|
||||
static asm void detect_main_memory_size( void )
|
||||
{
|
||||
@ -254,13 +264,39 @@ static asm void detect_main_memory_size( void )
|
||||
ldrh r12, [r3]
|
||||
cmp r1, r12
|
||||
|
||||
movne r0, #OS_CONSOLE_SIZE_8MB
|
||||
|
||||
bne @2
|
||||
|
||||
add r1, r1, #1
|
||||
cmp r1, #2 // check 2 loop
|
||||
bne @1
|
||||
b @4
|
||||
|
||||
//---- 8MB or 16MB or 32MB
|
||||
@2:
|
||||
// check if running on twl/nitro
|
||||
ldr r1, =REG_CLK_ADDR
|
||||
ldrh r12, [r1]
|
||||
tst r12, #REG_SCFG_CLK_WRAMHCLK_MASK
|
||||
moveq r0, #OS_CONSOLE_SIZE_8MB
|
||||
beq @4
|
||||
|
||||
//---- 16MB or 32MB
|
||||
mov r1, #0
|
||||
add r3, r2, #OSi_IMAGE_DIFFERENCE2
|
||||
@3:
|
||||
strh r1, [r2]
|
||||
ldrh r12, [r3]
|
||||
cmp r1, r12
|
||||
|
||||
movne r0, #OS_CONSOLE_SIZE_32MB
|
||||
bne @4
|
||||
|
||||
add r1, r1, #1
|
||||
cmp r1, #2 // check 2 loop
|
||||
bne @3
|
||||
mov r0, #OS_CONSOLE_SIZE_16MB
|
||||
@4:
|
||||
strh r0, [r2]
|
||||
bx lr
|
||||
}
|
||||
|
||||
@ -149,7 +149,6 @@ BOOL MI_LoadHeader( int* pool, const void* rsa_key )
|
||||
#endif
|
||||
{
|
||||
SignatureData sd;
|
||||
#if 0
|
||||
int i;
|
||||
BOOL result = TRUE;
|
||||
SVC_DecryptoSign(pool, &sd, rh->signature, rsa_key);
|
||||
@ -160,13 +159,12 @@ BOOL MI_LoadHeader( int* pool, const void* rsa_key )
|
||||
result = FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
if ( !result )
|
||||
{
|
||||
#if 0
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PXI_NotifyID( FIRM_PXI_ID_AUTH_HEADER );
|
||||
// PXI_SendDataByFifo( PXI_FIFO_TAG_DATA, sd.aes_key_seed, AES_BLOCK_SIZE );
|
||||
MI_CpuClear8(&sd, sizeof(sd));
|
||||
@ -188,16 +186,16 @@ static inline BOOL MIi_LoadModule(void* dest, u32 size, const u8 digest[DIGEST_S
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#if 0
|
||||
SHA1_GetHash(&ctx, md);
|
||||
for ( i = 0; i < DIGEST_SIZE_SHA1; i++ )
|
||||
{
|
||||
if ( md[i] != digest[i] )
|
||||
{
|
||||
#if 0
|
||||
result = FALSE;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -199,7 +199,7 @@ asm void OSi_BootCore( OSEntryPoint p, MIHeader_WramRegs* w )
|
||||
|
||||
// clear stack with r4-r9
|
||||
mov r0, #0
|
||||
#if 1
|
||||
#if 0
|
||||
ldr r1, =HW_FIRM_STACK
|
||||
ldr r2, =HW_FIRM_STACK_SIZE
|
||||
bl MIi_CpuClearFast
|
||||
@ -208,7 +208,7 @@ asm void OSi_BootCore( OSEntryPoint p, MIHeader_WramRegs* w )
|
||||
mov lr, r11
|
||||
|
||||
// clear registers
|
||||
#if 1
|
||||
#if 0
|
||||
ldr sp, =HW_FIRM_STACK
|
||||
ldmia sp, {r0-r12,sp}
|
||||
#endif
|
||||
|
||||
@ -32,7 +32,7 @@ void OS_InitFIRM(void)
|
||||
{
|
||||
#ifdef SDK_ARM9
|
||||
//---- system shared area check
|
||||
SDK_ASSERT((u32)&(OS_GetSystemWork()->command_area) == HW_CMD_AREA);
|
||||
// SDK_ASSERT((u32)&(OS_GetSystemWork()->command_area) == HW_CMD_AREA);
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// for ARM9
|
||||
@ -64,7 +64,7 @@ void OS_InitFIRM(void)
|
||||
OS_SetIrqStackChecker();
|
||||
|
||||
//---- Init Exception System
|
||||
OS_InitException();
|
||||
// OS_InitException();
|
||||
|
||||
//---- Init MI (Wram bank and DMA0 arranged)
|
||||
MI_Init();
|
||||
|
||||
@ -20,7 +20,6 @@
|
||||
#include <twl/os/ARM7/debugLED.h>
|
||||
|
||||
//#define BOOT_SECURE_SRL // 本番SRLをブートするときにだけ定義する
|
||||
//#define FIRM_ENABLE_JTAG
|
||||
|
||||
#define FATFS_HEAP_SIZE (64*1024)
|
||||
|
||||
@ -46,52 +45,79 @@ static u64 fatfs_arena[FATFS_HEAP_SIZE/sizeof(u64)];
|
||||
static u8 step = 0x80;
|
||||
#endif
|
||||
|
||||
static SDPortContext nandContext;
|
||||
|
||||
void TwlSpMain( void )
|
||||
{
|
||||
// OS_TPrintf( "\nNAND Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick()));
|
||||
|
||||
#ifndef BOOT_SECURE_SRL
|
||||
MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) );
|
||||
/* FromBromで必要なものはここで待避 */
|
||||
nandContext = OSi_GetFromBromAddr()->SDNandContext;
|
||||
#ifdef BOOT_SECURE_SRL
|
||||
/* 鍵はどこへ? */
|
||||
#endif
|
||||
|
||||
// I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x03, 0x00);
|
||||
// I2Ci_WriteRegister(I2C_SLAVE_DEBUG_LED, 0x01, (0xff));
|
||||
|
||||
MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) );
|
||||
|
||||
#ifdef FIRM_ENABLE_JTAG
|
||||
reg_SCFG_JTAG = REG_SCFG_JTAG_CPUJE_MASK | REG_SCFG_JTAG_ARM7SEL_MASK;
|
||||
#endif // FIRM_ENABLE_JTAG
|
||||
|
||||
OS_InitFIRM();
|
||||
OS_TPrintf("OS_InitFIRM() was called\n");
|
||||
|
||||
OS_InitDebugLED();
|
||||
OS_SetDebugLED(++step);
|
||||
|
||||
PM_InitFIRM();
|
||||
OS_TPrintf("PM_InitFIRM() was called\n");
|
||||
|
||||
OS_SetDebugLED(++step);
|
||||
|
||||
OS_TPrintf("OS_GetMainArenaHi() = 0x%08X\n", OS_GetMainArenaHi());
|
||||
OS_TPrintf("OS_GetMainArenaLo() = 0x%08X\n", OS_GetMainArenaLo());
|
||||
OS_TPrintf("OS_GetSubPrivArenaHi() = 0x%08X\n", OS_GetSubPrivArenaHi());
|
||||
OS_TPrintf("OS_GetSubPrivArenaLo() = 0x%08X\n", OS_GetSubPrivArenaLo());
|
||||
OS_TPrintf("OS_GetMainExArenaHi() = 0x%08X\n", OS_GetMainExArenaHi());
|
||||
OS_TPrintf("OS_GetMainExArenaLo() = 0x%08X\n", OS_GetMainExArenaLo());
|
||||
OS_TPrintf("OS_GetITCMArenaHi() = 0x%08X\n", OS_GetITCMArenaHi());
|
||||
OS_TPrintf("OS_GetITCMArenaLo() = 0x%08X\n", OS_GetITCMArenaLo());
|
||||
OS_TPrintf("OS_GetDTCMArenaHi() = 0x%08X\n", OS_GetDTCMArenaHi());
|
||||
OS_TPrintf("OS_GetDTCMArenaLo() = 0x%08X\n", OS_GetDTCMArenaLo());
|
||||
OS_TPrintf("OS_GetSharedArenaHi() = 0x%08X\n", OS_GetSharedArenaHi());
|
||||
OS_TPrintf("OS_GetSharedArenaLo() = 0x%08X\n", OS_GetSharedArenaLo());
|
||||
OS_TPrintf("OS_GetWramMainArenaHi() = 0x%08X\n", OS_GetWramMainArenaHi());
|
||||
OS_TPrintf("OS_GetWramMainArenaLo() = 0x%08X\n", OS_GetWramMainArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubArenaHi() = 0x%08X\n", OS_GetWramSubArenaHi());
|
||||
OS_TPrintf("OS_GetWramSubArenaLo() = 0x%08X\n", OS_GetWramSubArenaLo());
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaHi() = 0x%08X\n", OS_GetWramSubPrivArenaHi());
|
||||
OS_TPrintf("OS_GetWramSubPrivArenaLo() = 0x%08X\n", OS_GetWramSubPrivArenaLo());
|
||||
|
||||
|
||||
/* FATFSライブラリ用にカレントヒープに設定 */
|
||||
{
|
||||
OSHeapHandle hh;
|
||||
u8 *lo = (u8*)fatfs_arena;
|
||||
u8 *hi = (u8*)fatfs_arena + FATFS_HEAP_SIZE;
|
||||
#if 0
|
||||
OS_SetSubPrivArenaLo(lo);
|
||||
OS_SetSubPrivArenaHi(hi);
|
||||
OS_SetSubPrivArenaLo(lo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, lo, hi, 1));
|
||||
#else
|
||||
lo = OS_InitAlloc(OS_ARENA_MAIN_SUBPRIV, lo, hi, 1);
|
||||
#endif
|
||||
hh = OS_CreateHeap(OS_ARENA_MAIN_SUBPRIV, lo + 32, hi - 32);
|
||||
OS_SetCurrentHeap(OS_ARENA_MAIN_SUBPRIV, hh);
|
||||
}
|
||||
|
||||
OS_SetDebugLED(++step);
|
||||
|
||||
if ( FATFS_InitFIRM() )
|
||||
if ( FATFS_InitFIRM( &nandContext ) )
|
||||
{
|
||||
OS_TPrintf("FATFS_InitFIRM() was called\n");
|
||||
OS_SetDebugLED(++step);
|
||||
|
||||
if ( FATFS_MountDriveFirm( DRIVE_NO, BOOT_DEVICE, PARTITION_NO ) )
|
||||
{
|
||||
BOOL result;
|
||||
OS_TPrintf("FATFS_MountDriveFirm() was called\n");
|
||||
OS_SetDebugLED(++step);
|
||||
|
||||
#ifdef BOOT_SECURE_SRL
|
||||
@ -119,6 +145,7 @@ void TwlSpMain( void )
|
||||
OS_Terminate();
|
||||
break;
|
||||
}
|
||||
OS_TPrintf("FATFS_OpenSpecifiedMenu() was called\n");
|
||||
#endif
|
||||
if ( result )
|
||||
{
|
||||
|
||||
@ -34,16 +34,25 @@ int acPool[3];
|
||||
|
||||
void TwlMain( void )
|
||||
{
|
||||
// OS_TPrintf( "\nNAND Boot time is %d msec.\n", OS_TicksToMilliSecondsBROM32(OS_GetTick()));
|
||||
/* FromBromで必要なものはここで待避 */
|
||||
|
||||
#ifndef BOOT_SECURE_SRL
|
||||
#define FIRM_SHARD HW_TWL_SECONDARY_ROM_HEADER_BUF
|
||||
#define FIRM_SHARD_END HW_TWL_MAIN_MEM_END
|
||||
#define FIRM_SHARD_SIZE (FIRM_SHARD_END-FIRM_SHARD)
|
||||
MIi_CpuClearFast( 0, (void*)FIRM_SHARD, FIRM_SHARD_SIZE );
|
||||
DC_FlushRange( (void*)FIRM_SHARD, FIRM_SHARD_SIZE );
|
||||
// MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) );
|
||||
#ifdef BOOT_SECURE_SRL
|
||||
/* 鍵はどこへ? */
|
||||
#endif
|
||||
MIi_CpuClearFast( 0, (void*)OSi_GetFromBromAddr(), sizeof(OSFromBromBuf) );
|
||||
|
||||
/* メインメモリのクリア領域 (TODO: Reset時に残す領域がある(ここでは無条件で残すようにする)) */
|
||||
#define FIRM_CLEAR_A (FIRM_CLEAR_A_END-FIRM_CLEAR_A_SIZE)
|
||||
#define FIRM_CLEAR_A_END HW_TWL_MAIN_MEM_END
|
||||
#define FIRM_CLEAR_A_SIZE 0x8000
|
||||
#define FIRM_CLEAR_B HW_TWL_MAIN_MEM
|
||||
#define FIRM_CLEAR_B_END (FIRM_CLEAR_B + FIRM_CLEAR_B_SIZE)
|
||||
#define FIRM_CLEAR_B_SIZE 0x10000
|
||||
// MIi_CpuClearFast( 0, (void*)FIRM_CLEAR_A, FIRM_CLEAR_A_SIZE );
|
||||
MIi_CpuClearFast( 0, (void*)FIRM_CLEAR_B, FIRM_CLEAR_B_SIZE );
|
||||
DC_FlushRange( (void*)FIRM_CLEAR_A, FIRM_CLEAR_A_SIZE );
|
||||
DC_FlushRange( (void*)FIRM_CLEAR_B, FIRM_CLEAR_B_SIZE );
|
||||
|
||||
reg_GX_VRAMCNT_C = REG_GX_VRAMCNT_C_FIELD( TRUE, 0, 0x2);
|
||||
|
||||
OS_InitFIRM();
|
||||
|
||||
@ -54,11 +54,11 @@ void FATFS_DisableAES( void );
|
||||
|
||||
Description: init file system
|
||||
|
||||
Arguments: None
|
||||
Arguments: nandContext : nand context to omit initialization (if any)
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL FATFS_InitFIRM( void );
|
||||
BOOL FATFS_InitFIRM( void* nandContext );
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: FATFS_MountDriveFirm
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
#---------------------------------------------------------------------------
|
||||
MEMORY
|
||||
{
|
||||
<STATIC.NAME> (RWX) : ORIGIN = <STATIC.ADDRESS>, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<STATIC.NAME> (RWX) : ORIGIN = <STATIC.ADDRESS>, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
|
||||
<FOREACH.AUTOLOADS>
|
||||
<AUTOLOAD.NAME> (RWX) : ORIGIN = <AUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<AUTOLOAD.NAME> (RWX) : ORIGIN = <AUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
<END.AUTOLOADS>
|
||||
binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
|
||||
<PROPERTY.OVERLAYDEFS>F (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.OVERLAYDEFS><PROPERTY.FLXSUFFIX>
|
||||
<PROPERTY.OVERLAYTABLE>F (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.OVERLAYTABLE><PROPERTY.FLXSUFFIX>
|
||||
@ -33,11 +33,11 @@ MEMORY
|
||||
check.WORKRAM (RWX) : ORIGIN = 0x037f8000, LENGTH = 0x18000 > workram.check
|
||||
check.MAINMEM (RWX) : ORIGIN = 0x02fe0000, LENGTH = 0x1c000 > mainmem.check
|
||||
|
||||
binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
<FOREACH.LTDAUTOLOADS>
|
||||
<LTDAUTOLOAD.NAME> (RWX) : ORIGIN = <LTDAUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<LTDAUTOLOAD.NAME> (RWX) : ORIGIN = <LTDAUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
<END.LTDAUTOLOADS>
|
||||
binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
|
||||
<PROPERTY.LTDOVERLAYDEFS>L (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.LTDOVERLAYDEFS><PROPERTY.LTDSUFFIX>
|
||||
<PROPERTY.LTDOVERLAYTABLE>L (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.LTDOVERLAYTABLE><PROPERTY.LTDSUFFIX>
|
||||
|
||||
@ -16,13 +16,13 @@
|
||||
#---------------------------------------------------------------------------
|
||||
MEMORY
|
||||
{
|
||||
<STATIC.NAME> (RWX) : ORIGIN = <STATIC.ADDRESS>, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<STATIC.NAME> (RWX) : ORIGIN = <STATIC.ADDRESS>, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
|
||||
<FOREACH.AUTOLOADS>
|
||||
<AUTOLOAD.NAME> (RWX) : ORIGIN = <AUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<AUTOLOAD.NAME> (RWX) : ORIGIN = <AUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
<END.AUTOLOADS>
|
||||
binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.AUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.FLXSUFFIX>
|
||||
|
||||
<PROPERTY.OVERLAYDEFS>F (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.OVERLAYDEFS><PROPERTY.FLXSUFFIX>
|
||||
<PROPERTY.OVERLAYTABLE>F (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.OVERLAYTABLE><PROPERTY.FLXSUFFIX>
|
||||
@ -39,11 +39,11 @@ MEMORY
|
||||
check.ITCM (RW) : ORIGIN = 0x0, LENGTH = 0x08000 > itcm.check
|
||||
check.DTCM (RW) : ORIGIN = 0x0, LENGTH = 0x04000 > dtcm.check
|
||||
|
||||
binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
<FOREACH.LTDAUTOLOADS>
|
||||
<LTDAUTOLOAD.NAME> (RWX) : ORIGIN = <LTDAUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
<LTDAUTOLOAD.NAME> (RWX) : ORIGIN = <LTDAUTOLOAD.ADDRESS>, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
<END.LTDAUTOLOADS>
|
||||
binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.SUFFIX>
|
||||
binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> <STATIC.NAME><PROPERTY.LTDSUFFIX>
|
||||
|
||||
<PROPERTY.LTDOVERLAYDEFS>L (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.LTDOVERLAYDEFS><PROPERTY.LTDSUFFIX>
|
||||
<PROPERTY.LTDOVERLAYTABLE>L (RW) : ORIGIN = 0, LENGTH = 0x0 > <PROPERTY.LTDOVERLAYTABLE><PROPERTY.LTDSUFFIX>
|
||||
@ -89,10 +89,10 @@ SECTIONS
|
||||
SDK_STATIC_START =.;
|
||||
SDK_STATIC_TEXT_START =.;
|
||||
#:::::::::: text/rodata
|
||||
crt0_firm.o (.text)
|
||||
libsyscall.a (.text)
|
||||
OBJECT(_start,*)
|
||||
crt0_firm.o (.text)
|
||||
crt0_firm.o (.rodata)
|
||||
libsyscall.a (.text)
|
||||
#
|
||||
# .version セクションを追加しています。
|
||||
# このセクションに含まれる情報はロットチェックの際に
|
||||
@ -393,13 +393,13 @@ SECTIONS
|
||||
SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_START + SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO);
|
||||
SDK_AUTOLOAD_SIZE = SDK_AUTOLOAD_SIZE + SIZEOF(.binary.AUTOLOAD_INFO);
|
||||
|
||||
# ############################ STATIC_FOOTER ##########################
|
||||
# .binary.STATIC_FOOTER:
|
||||
# {
|
||||
# WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE
|
||||
# WRITEW _start_ModuleParams - ADDR(.<STATIC.NAME>);
|
||||
# WRITEW 0; # NO DIGEST
|
||||
# } > binary.STATIC_FOOTER
|
||||
############################ STATIC_FOOTER ##########################
|
||||
.binary.STATIC_FOOTER:
|
||||
{
|
||||
WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE
|
||||
WRITEW _start_ModuleParams - ADDR(.<STATIC.NAME>);
|
||||
WRITEW 0; # NO DIGEST
|
||||
} > binary.STATIC_FOOTER
|
||||
|
||||
############################ OVERLAYS ###############################
|
||||
SDK_OVERLAY_NUMBER = <NUMBER.OVERLAYS>;
|
||||
@ -966,10 +966,10 @@ SECTIONS
|
||||
# Module filelist
|
||||
.binary.MODULE_FILES:
|
||||
{
|
||||
WRITES ("<STATIC.NAME><PROPERTY.SUFFIX>");
|
||||
WRITES ("<STATIC.NAME><PROPERTY.FLXSUFFIX>");
|
||||
WRITES ("<PROPERTY.OVERLAYDEFS><PROPERTY.FLXSUFFIX>");
|
||||
WRITES ("<PROPERTY.OVERLAYTABLE><PROPERTY.FLXSUFFIX>");
|
||||
WRITES ("<STATIC.NAME><PROPERTY.SUFFIX>");
|
||||
WRITES ("<STATIC.NAME><PROPERTY.LTDSUFFIX>");
|
||||
WRITES ("<PROPERTY.LTDOVERLAYDEFS><PROPERTY.LTDSUFFIX>");
|
||||
WRITES ("<PROPERTY.LTDOVERLAYTABLE><PROPERTY.LTDSUFFIX>");
|
||||
|
||||
|
||||
148
include/firm/specfiles/ROM-TS.rsf
Normal file
148
include/firm/specfiles/ROM-TS.rsf
Normal file
@ -0,0 +1,148 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: TwlSDK - include
|
||||
# File: ROM-BB.rsf
|
||||
#
|
||||
# Copyright 2007 Nintendo. All rights reserved.
|
||||
#
|
||||
# These coded insructions, 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:: $
|
||||
# $Rev$
|
||||
# $Author$
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# TWL ROM SPEC FILE
|
||||
#
|
||||
|
||||
Arm9
|
||||
{
|
||||
Static "$(MAKEROM_ARM9:r).FLX.TWL.sbin$(COMPSUFFIX9)"
|
||||
OverlayDefs "$(MAKEROM_ARM9:r)_defs.FLX.TWL.sbin$(COMPSUFFIX9)"
|
||||
OverlayTable "$(MAKEROM_ARM9:r)_table.FLX.TWL.sbin$(COMPSUFFIX9)"
|
||||
Elf "$(MAKEROM_ARM9:r).tef"
|
||||
}
|
||||
|
||||
Arm7
|
||||
{
|
||||
Static "$(MAKEROM_ARM7_BASE:r).FLX.TWL.sbin$(COMPSUFFIX7)"
|
||||
OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.FLX.TWL.sbin$(COMPSUFFIX7)"
|
||||
OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.FLX.TWL.sbin$(COMPSUFFIX7)"
|
||||
Elf "$(MAKEROM_ARM7_BASE:r).tef"
|
||||
}
|
||||
|
||||
Arm9.Ltd
|
||||
{
|
||||
Static "$(MAKEROM_ARM9:r).LTD.TWL.sbin$(COMPSUFFIX9)"
|
||||
OverlayDefs "$(MAKEROM_ARM9:r)_defs.LTD.TWL.sbin$(COMPSUFFIX9)"
|
||||
OverlayTable "$(MAKEROM_ARM9:r)_table.LTD.TWL.sbin$(COMPSUFFIX9)"
|
||||
}
|
||||
|
||||
Arm7.Ltd
|
||||
{
|
||||
Static "$(MAKEROM_ARM7_BASE:r).LTD.TWL.sbin$(COMPSUFFIX7)"
|
||||
OverlayDefs "$(MAKEROM_ARM7_BASE:r)_defs.LTD.TWL.sbin$(COMPSUFFIX7)"
|
||||
OverlayTable "$(MAKEROM_ARM7_BASE:r)_table.LTD.TWL.sbin$(COMPSUFFIX7)"
|
||||
}
|
||||
|
||||
Property
|
||||
{
|
||||
###
|
||||
### Settings for FinalROM
|
||||
###
|
||||
#### BEGIN
|
||||
#
|
||||
# TITLE NAME: Your product name within 12bytes
|
||||
#
|
||||
TitleName "FIRM"
|
||||
|
||||
#
|
||||
# MAKER CODE: Your company ID# in 2 ascii words
|
||||
# issued by NINTENDO
|
||||
#
|
||||
MakerCode "01"
|
||||
|
||||
#
|
||||
# REMASTER VERSION: Mastering version
|
||||
#
|
||||
#RomVersion 0
|
||||
|
||||
#
|
||||
# ROM SPEED TYPE: [MROM/1TROM/UNDEFINED]
|
||||
#
|
||||
RomSpeedType $(MAKEROM_ROMSPEED)
|
||||
|
||||
#
|
||||
# ROM SIZE: in bit [64M/128M/256M/512M/1G/2G]
|
||||
#
|
||||
#RomSize 128M
|
||||
#RomSize 256M
|
||||
|
||||
#
|
||||
# ROM PADDING: TRUE if finalrom
|
||||
#
|
||||
#RomFootPadding TRUE
|
||||
|
||||
#
|
||||
# ROM HEADER TEMPLATE: Provided to every product by NINTENDO
|
||||
#
|
||||
#RomHeaderTemplate ./etc/rom_header.template.sbin
|
||||
|
||||
#
|
||||
# BANNER FILE: generated from Banner Spec File
|
||||
#
|
||||
#BannerFile ./etc/myGameBanner.bnr
|
||||
BannerFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr
|
||||
|
||||
###
|
||||
### Setting for TWL
|
||||
###
|
||||
#
|
||||
# BANNER FILE:
|
||||
#
|
||||
BannerTWLFile $(TWLSDK_ROOT)/include/twl/specfiles/default.bnr
|
||||
|
||||
#
|
||||
# Boot allowed Media: [GameCard/NAND/SDCard/DownloadPlay]
|
||||
# possible to choose one or more.
|
||||
#
|
||||
BootMedia GameCard NAND SDCard DownloadPlay
|
||||
|
||||
#
|
||||
# Certification FILE:
|
||||
#
|
||||
Certificate $(TWLSDK_ROOT)/include/twl/specfiles/default_sgn.sbin
|
||||
|
||||
#
|
||||
# Digest parameters:
|
||||
#
|
||||
DigestParam 1024 32
|
||||
|
||||
#
|
||||
# WRAM mapping: [MAP_BB_HYB/MAP_BB_LTD/MAP_TS_HYB/MAP_TS_LTD]
|
||||
# don't have to edit
|
||||
#
|
||||
#WramMapping $(MAKEROM_WRAM_MAPPING)
|
||||
WramMappingDirect wram_regs/wram_regs.rbin
|
||||
|
||||
#
|
||||
# Codec mode:
|
||||
# don't have to edit
|
||||
#
|
||||
CodecMode $(MAKEROM_CODEC_MODE)
|
||||
|
||||
###
|
||||
#### END
|
||||
}
|
||||
|
||||
RomSpec
|
||||
{
|
||||
Offset 0x00000000
|
||||
Segment ALL
|
||||
HostRoot $(MAKEROM_ROMROOT)
|
||||
Root /
|
||||
File $(MAKEROM_ROMFILES)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user