diff --git a/build/libraries/devices/sdmc/ARM7/drnand.c b/build/libraries/devices/sdmc/ARM7/drnand.c index 3b1c1a4..753274d 100644 --- a/build/libraries/devices/sdmc/ARM7/drnand.c +++ b/build/libraries/devices/sdmc/ARM7/drnand.c @@ -27,6 +27,9 @@ #endif +/*---------------------------------------------------------------------------* + 定数 + *---------------------------------------------------------------------------*/ #define NUM_SD_PAGES #define SD_PAGE_SIZE @@ -50,7 +53,9 @@ extern void i_sdmcCalcSize( void); //TODO:sdmc_current_spec /*---------------------------------------------------------------------------* static変数 *---------------------------------------------------------------------------*/ -static int nand_drive_no; +static int nand_drive_no; +static FATSpec NandFatSpec[4]; //FATパラメータ(パーティション0〜3個別) +static int nand_calculated_fat_params = 0; /*---------------------------------------------------------------------------* @@ -63,6 +68,36 @@ static void sdi_get_fatparams( void); static void sdi_build_partition_table( void); +#if 1 //アプリケーションでパーティション構成を決めたいとき + +u32 NAND_FAT_PARTITION_COUNT; +u32 NAND_RAW_SECTORS; +u32 NAND_FAT0_SECTORS; +u32 NAND_FAT1_SECTORS; +u32 NAND_FAT2_SECTORS; +u32 NAND_FAT3_SECTORS; + +void nandSetFormatRequest( u16 partition_num, u16* partition_mbytes) +{ + NAND_RAW_SECTORS = (partition_mbytes[0] * 1024 * 1024) / 512; + NAND_FAT0_SECTORS = ((partition_mbytes[1] * 1024 * 1024) / 512) + NAND_RAW_SECTORS; + NAND_FAT1_SECTORS = (partition_mbytes[2] * 1024 * 1024) / 512; + NAND_FAT2_SECTORS = (partition_mbytes[3] * 1024 * 1024) / 512; + NAND_FAT3_SECTORS = (partition_mbytes[4] * 1024 * 1024) / 512; + NAND_FAT_PARTITION_COUNT = partition_num; +} + +#else //パーティション構成を決め打ちするとき + +#define NAND_FAT_PARTITION_COUNT (3) +#define NAND_RAW_SECTORS (( 8*1024*1024)/512); +#define NAND_FAT0_SECTORS (((16*1024*1024)/512) + NAND_RAW_SECTORS); //計算上RAWを含めておく +#define NAND_FAT1_SECTORS ((16*1024*1024)/512); +#define NAND_FAT2_SECTORS (( 8*1024*1024)/512); +#define NAND_FAT3_SECTORS (0); + +#endif + /*---------------------------------------------------------------------------* Name: nandCheckMedia @@ -75,7 +110,7 @@ static void sdi_build_partition_table( void); Returns: TRUE/FALSE (FALSEなら pc_format_media が必要) *---------------------------------------------------------------------------*/ -BOOL nandCheckMedia( void) +BOOL nandCheckMedia( void) //TODO:nand partition仕様に対応させること { u16 i; SdmcResultInfo SdResult; @@ -188,56 +223,64 @@ int nandRtfsCtrl( int driveno, int opcode, void* pargs) rtfs_memset( &gc, (byte)0, sizeof(gc)); - i_sdmcCalcSize(); //TODO:sdmc_current_specを構造体に入れること - sdi_get_CHS_params(); //最初に呼ぶこと - sdi_get_fatparams(); - sdi_get_nom( (8*1024*1024)/512); //8MBytes <= NOM + if( nand_calculated_fat_params == 0) { + i_sdmcCalcSize(); //TODO:sdmc_current_specを構造体に入れること + sdi_get_CHS_params(); //最初に呼ぶこと + sdi_get_fatparams(); + sdi_get_nom( NAND_RAW_SECTORS); + nand_calculated_fat_params = 1; + } - 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); + PRINTDEBUG( "memory capacity : 0x%x\n", NandFatSpec[pdr->partition_number].memory_capacity); + PRINTDEBUG( "device capacity : 0x%x\n", NandFatSpec[pdr->partition_number].device_capacity); + PRINTDEBUG( "adjusted capacity : 0x%x\n", NandFatSpec[pdr->partition_number].adjusted_memory_capacity); + PRINTDEBUG( "volume cylinders : 0x%x\n", NandFatSpec[pdr->partition_number].volume_cylinders); + PRINTDEBUG( "\n"); + PRINTDEBUG( "heads : 0x%x\n", NandFatSpec[pdr->partition_number].heads); + PRINTDEBUG( "secptrack : 0x%x\n", NandFatSpec[pdr->partition_number].secptrack); + PRINTDEBUG( "cylinders : 0x%x\n", NandFatSpec[pdr->partition_number].cylinders); + PRINTDEBUG( "SC : 0x%x\n", NandFatSpec[pdr->partition_number].SC); + PRINTDEBUG( "BU : 0x%x\n", NandFatSpec[pdr->partition_number].BU); + PRINTDEBUG( "RDE : 0x%x\n", NandFatSpec[pdr->partition_number].RDE); + PRINTDEBUG( "SS : 0x%x\n", NandFatSpec[pdr->partition_number].SS); + PRINTDEBUG( "RSC : 0x%x\n", NandFatSpec[pdr->partition_number].RSC); + PRINTDEBUG( "FATBITS : 0x%x\n", NandFatSpec[pdr->partition_number].FATBITS); + PRINTDEBUG( "SF : 0x%x\n", NandFatSpec[pdr->partition_number].SF); + PRINTDEBUG( "SSA : 0x%x\n", NandFatSpec[pdr->partition_number].SSA); + PRINTDEBUG( "NOM : 0x%x\n", NandFatSpec[pdr->partition_number].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.dev_geometry_lbas = (NandFatSpec[pdr->partition_number].begin_sect + + NandFatSpec[pdr->partition_number].memory_capacity); + gc.dev_geometry_heads = NandFatSpec[pdr->partition_number].heads; + gc.dev_geometry_secptrack = NandFatSpec[pdr->partition_number].secptrack; + + /*デバイスの先頭から現在のパーティションの領域までを含む容量分をセットする*/ + gc.dev_geometry_cylinders = gc.dev_geometry_lbas / + (gc.dev_geometry_heads * gc.dev_geometry_secptrack); /**/ - gc.fmt_parms_valid = TRUE; - gc.fmt.oemname[0] = 'T'; - gc.fmt.oemname[1] = 'W'; - gc.fmt.oemname[2] = 'L'; - 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_parms_valid = TRUE; + gc.fmt.oemname[0] = 'T'; + gc.fmt.oemname[1] = 'W'; + gc.fmt.oemname[2] = 'L'; + gc.fmt.oemname[3] = '\0'; + gc.fmt.secpalloc = NandFatSpec[pdr->partition_number].SC; /*sectors per cluster(FIX by capacity)*/ + gc.fmt.secreserved = NandFatSpec[pdr->partition_number].RSC;//sdmc_current_spec.RSC;/*reserved sectors(FIX 1 at FAT12,16)*/ + gc.fmt.numfats = 2; + gc.fmt.secpfat = NandFatSpec[pdr->partition_number].SF; + gc.fmt.numhide = NandFatSpec[pdr->partition_number].NOM; /**/ + gc.fmt.numroot = NandFatSpec[pdr->partition_number].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.secptrk = NandFatSpec[pdr->partition_number].secptrack; //CHS Recommendation + gc.fmt.numhead = NandFatSpec[pdr->partition_number].heads; + gc.fmt.numcyl = gc.dev_geometry_cylinders;//NandFatSpec[pdr->partition_number].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: @@ -261,6 +304,7 @@ int nandRtfsCtrl( int driveno, int opcode, void* pargs) return(DEVTEST_CHANGED); }else{ PRINTDEBUG( "DEVTEST_NOCHANGE\n"); + pdr->drive_flags |= DRIVE_FLAGS_INSERTED; // return( DEVTEST_NOCHANGE); } @@ -270,8 +314,6 @@ int nandRtfsCtrl( int driveno, int opcode, void* pargs) sdmcGoIdle( NULL, NULL); //カード初期化シーケンス TODO:1ポートだけにする /*------------------*/ pdr->drive_flags |= (DRIVE_FLAGS_VALID | DRIVE_FLAGS_REMOVABLE | DRIVE_FLAGS_PARTITIONED); - pdr->partition_number = 0; - pdr->drive_flags |= DRIVE_FLAGS_INSERTED; return( 0); @@ -299,22 +341,42 @@ int nandRtfsCtrl( int driveno, int opcode, void* pargs) Returns: *---------------------------------------------------------------------------*/ -BOOL nandRtfsAttach( int driveno) +BOOL nandRtfsAttach( int driveno, int partition_no) { BOOLEAN result; DDRIVE pdr; + if( partition_no >= NAND_FAT_PARTITION_COUNT) { + return( FALSE); + } + pdr.dev_table_drive_io = nandRtfsIo; pdr.dev_table_perform_device_ioctl = nandRtfsCtrl; - pdr.register_file_address = (dword) 0; /* Not used */ + 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.drive_flags = (DRIVE_FLAGS_VALID | DRIVE_FLAGS_PARTITIONED);//DRIVE_FLAGS_FAILSAFE; + pdr.partition_number = partition_no; /* Not used */ pdr.pcmcia_slot_number = 0; /* Not used */ pdr.controller_number = 0; pdr.logical_unit_number = 0; - result = rtfs_attach( driveno, &pdr, "SD1"); //構造体がFSライブラリ側にコピーされる + switch( partition_no) { + case 0: + result = rtfs_attach( driveno, &pdr, "SD1p0"); //構造体がFSライブラリ側にコピーされる + break; + case 1: + result = rtfs_attach( driveno, &pdr, "SD1p1"); //構造体がFSライブラリ側にコピーされる + break; + case 2: + result = rtfs_attach( driveno, &pdr, "SD1p2"); //構造体がFSライブラリ側にコピーされる + break; + case 3: + result = rtfs_attach( driveno, &pdr, "SD1p3"); //構造体がFSライブラリ側にコピーされる + break; + default: + result = FALSE; + break; + } /*drivenoをグローバル変数に記憶*/ nand_drive_no = driveno; @@ -323,80 +385,137 @@ BOOL nandRtfsAttach( int driveno) } - /*SD File System Specification(仕様書)に基づいた値を出す*/ static void sdi_get_CHS_params( void) { + u16 i; int mbytes; + u32 cumulative_capacity; //累計 + + /**/ + NandFatSpec[0].memory_capacity = NAND_FAT0_SECTORS; + NandFatSpec[1].memory_capacity = NAND_FAT1_SECTORS; + NandFatSpec[2].memory_capacity = NAND_FAT2_SECTORS; + NandFatSpec[3].memory_capacity = NAND_FAT3_SECTORS; + + + cumulative_capacity = 0; + for( i=0; i<(NAND_FAT_PARTITION_COUNT - 1); i++) { + cumulative_capacity += NandFatSpec[i].memory_capacity; + } + /*容量破綻チェック*/ + if( cumulative_capacity >= sdmc_current_spec.memory_capacity) { + OS_TPrintf( "INVALID PARAMETER ERROR!\n"); + while( 1) {}; + } + + /*最終パーティションは残りのセクタ全部*/ + NandFatSpec[NAND_FAT_PARTITION_COUNT -1].memory_capacity = + sdmc_current_spec.memory_capacity - cumulative_capacity; + + /*無効なパーティションにサイズ0を設定*/ + for( i=NAND_FAT_PARTITION_COUNT; i<4; i++) { + NandFatSpec[i].memory_capacity = 0; + } + // mbytes = (sdmc_current_spec.card_capacity / (1024 * 1024)) * 512; - mbytes = (sdmc_current_spec.card_capacity >> 11); + mbytes = (sdmc_current_spec.card_capacity >> 11); //TODO:forの中に入れてパーティション毎の値にするテストをすること + for( i=0; i 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); + /*-----------------------SDHCのとき----------------------------*/ + if( sdmc_current_spec.csd_ver2_flag) { + PRINTDEBUG( "ERR! enter SDHC branch\n"); /*nandの場合、NOMは少なくともMIN_NOM以上*/ - n+= sdi_get_ceil( MIN_NOM, 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; + if( i==0) { + NandFatSpec[i].NOM = sdi_get_ceil( MIN_NOM, NandFatSpec[i].BU) * + NandFatSpec[i].BU; + }else{ + 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; + n = sdi_get_ceil( 2*NandFatSpec[i].SF, NandFatSpec[i].BU); + NandFatSpec[i].RSC = (NandFatSpec[i].BU * n) - ( 2 * NandFatSpec[i].SF); + if( NandFatSpec[i].RSC < 9) { + NandFatSpec[i].RSC += NandFatSpec[i].BU; + } + NandFatSpec[i].SSA = NandFatSpec[i].RSC + (2 * NandFatSpec[i].SF); + do { + MAX = ((TS[i] - NandFatSpec[i].NOM - NandFatSpec[i].SSA) / SC) + 1; + SFdash = sdi_get_ceil( (2+(MAX-1)) * NandFatSpec[i].FATBITS, SS*8); + if( SFdash > NandFatSpec[i].SF) { + NandFatSpec[i].SSA += NandFatSpec[i].BU; + NandFatSpec[i].RSC += NandFatSpec[i].BU; + }else{ + break; + } + }while( 1); + if( SFdash != NandFatSpec[i].SF) { + NandFatSpec[i].SF -= 1; }else{ break; } }while( 1); - if( SFdash != sdmc_current_spec.SF) { - sdmc_current_spec.SF = SFdash; - }else{ - break; //complete - } - }while( 1); + }else{ /*-------------------------SDのとき-------------------------------*/ + do { + NandFatSpec[i].SSA = RSC[i] + ( 2 * NandFatSpec[i].SF) + sdi_get_ceil( 32*RDE, SS); + n = sdi_get_ceil( NandFatSpec[i].SSA, NandFatSpec[i].BU); + + /*nand パーティション0の場合、NOMは少なくともMIN_NOM以上*/ + if( i==0) { + n+= sdi_get_ceil( MIN_NOM, NandFatSpec[i].BU); + } + + NandFatSpec[i].NOM = (NandFatSpec[i].BU * n) - NandFatSpec[i].SSA; + if( NandFatSpec[i].NOM != NandFatSpec[i].BU) { + NandFatSpec[i].NOM += NandFatSpec[i].BU; + } + do { + MAX = ((TS[i] - NandFatSpec[i].NOM - NandFatSpec[i].SSA) / SC) + 1; + SFdash = sdi_get_ceil( (2+(MAX-1)) * NandFatSpec[i].FATBITS, SS*8); + if( SFdash > NandFatSpec[i].SF) { + NandFatSpec[i].NOM += NandFatSpec[i].BU; + }else{ + break; + } + }while( 1); + if( SFdash != NandFatSpec[i].SF) { + NandFatSpec[i].SF = SFdash; + }else{ + break; //complete + } + }while( 1); + } + } + + for( i=0; i> 11); + for( i=0; i> 11); if( mbytes <= 64) { - sdmc_current_spec.FATBITS = 12; - sdmc_current_spec.RDE = 512; - sdmc_current_spec.RSC = 1; + NandFatSpec[i].FATBITS = 12; + NandFatSpec[i].RDE = 512; + NandFatSpec[i].RSC = 1; }else{ if( mbytes <= 2048) { - sdmc_current_spec.FATBITS = 16; - sdmc_current_spec.RDE = 512; - sdmc_current_spec.RSC = 1; + NandFatSpec[i].FATBITS = 16; + NandFatSpec[i].RDE = 512; + NandFatSpec[i].RSC = 1; }else{ - sdmc_current_spec.FATBITS = 32; - sdmc_current_spec.RDE = 0; //FAT32のときは未使用。0にしておかないとRTFSが BAD FORMAT を返す。 - sdmc_current_spec.RSC = 1; + NandFatSpec[i].FATBITS = 32; + NandFatSpec[i].RDE = 0; //FAT32のときは未使用。0にしておかないとRTFSが BAD FORMAT を返す。 + NandFatSpec[i].RSC = 1; } } - - if( mbytes <= 8) { - sdmc_current_spec.SC = 16; - sdmc_current_spec.BU = 16; - return; + + while( 1) { + if( mbytes <= 8) { + NandFatSpec[i].SC = 16; + NandFatSpec[i].BU = 16; + break; + } + if( mbytes <= 64) { + NandFatSpec[i].SC = 32; + NandFatSpec[i].BU = 32; + break; + } + if( mbytes <= 256) { + NandFatSpec[i].SC = 32; + NandFatSpec[i].BU = 64; + break; + } + if( mbytes <= 1024) { + NandFatSpec[i].SC = 32; + NandFatSpec[i].BU = 128; + break; + } + if( mbytes <= 2048) { + NandFatSpec[i].SC = 64; + NandFatSpec[i].BU = 128; + break; + } + if( mbytes <= 32768) { + NandFatSpec[i].SC = 64; + NandFatSpec[i].BU = 8192; + break; + } + break; } - 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; + SdmcResultInfo SdResult; + u16 MbrSectDat[512/2]; + u32 starting_head[4], starting_sect[4], starting_cyl[4]; + u32 ending_head[4], ending_sect[4], ending_cyl[4]; + u32 total_sect[4]; + u32 starting_data[4], ending_data[4]; + u32 systemid[4]; + u16 i; - /**/ - starting_head = sdmc_current_spec.NOM % (sdmc_current_spec.heads * - sdmc_current_spec.secptrack); - starting_head /= sdmc_current_spec.secptrack; + for( i=0; i<4; i++) { + if( i < NAND_FAT_PARTITION_COUNT) { + /**/ + starting_head[i] = NandFatSpec[i].NOM % (NandFatSpec[i].heads * + NandFatSpec[i].secptrack); + starting_head[i] /= NandFatSpec[i].secptrack; - /**/ - starting_sect = (sdmc_current_spec.NOM % sdmc_current_spec.secptrack) + 1; + /**/ + starting_sect[i] = (NandFatSpec[i].NOM % NandFatSpec[i].secptrack) + 1; - /**/ - starting_cyl = sdmc_current_spec.NOM / (sdmc_current_spec.heads * - sdmc_current_spec.secptrack); + /**/ + starting_cyl[i] = NandFatSpec[i].NOM / (NandFatSpec[i].heads * + NandFatSpec[i].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; + /**/ +// total_sect[i] = (NandFatSpec[i].adjusted_memory_capacity - NandFatSpec[i].NOM); + total_sect[i] = (NandFatSpec[i].begin_sect + + NandFatSpec[i].adjusted_memory_capacity - NandFatSpec[i].NOM); + + ending_head[i] = (NandFatSpec[i].NOM + total_sect[i] - 1) % + (NandFatSpec[i].heads * NandFatSpec[i].secptrack); + ending_head[i] /= NandFatSpec[i].secptrack; - /**/ - ending_sect = ((sdmc_current_spec.NOM + total_sect - 1) % - sdmc_current_spec.secptrack) + 1; + /**/ + ending_sect[i] = ((NandFatSpec[i].NOM + total_sect[i] - 1) % + NandFatSpec[i].secptrack) + 1; - /**/ - ending_cyl = (sdmc_current_spec.NOM + total_sect - 1) / - (sdmc_current_spec.heads * sdmc_current_spec.secptrack); + /**/ + ending_cyl[i] = (NandFatSpec[i].NOM + total_sect[i] - 1) / + (NandFatSpec[i].heads * NandFatSpec[i].secptrack); - /**/ - if( sdmc_current_spec.FATBITS == 32) { //FAT32のとき - if( total_sect < 0xFB0400) { //8032.5MBが閾値(SD FileSystemSpec2.00参照) - systemid = 0x0B; /* FAT32 */ + /**/ + if( NandFatSpec[i].FATBITS == 32) { //FAT32のとき + if( total_sect[i] < 0xFB0400) { //8032.5MBが閾値(SD FileSystemSpec2.00参照) + systemid[i] = 0x0B; /* FAT32 */ + }else{ + systemid[i] = 0x0C; /* FAT32(拡張INT13対応) */ + } + }else{ //FAT12,FAT16のとき + if( total_sect[i] < 32680) { + systemid[i] = 0x01; /* FAT12 */ + }else if( total_sect[i] < 65536) { + systemid[i] = 0x04; /* FAT16(16MB〜32MB未満) */ + }else{ + systemid[i] = 0x06; /* FAT16(32MB〜4GB) */ + } + } }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) */ + starting_head[i] = 0; + starting_sect[i] = 0; + starting_cyl[i] = 0; + total_sect[i] = 0; + ending_head[i] = 0; + ending_sect[i] = 0; + ending_cyl[i] = 0; + systemid[i] = 0; } } /*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); + + for( i=0; i<4; i++) { + MbrSectDat[(446+(i*16))/2] = (starting_head[i]<<8); + //上位8bit:starting_cylの下位8bit, 下位8bit:starting_cylの上位2bit + starting_sect 6bit. + MbrSectDat[(448+(i*16))/2] = (starting_cyl[i]<<8) + + ((starting_cyl[i]>>2) & 0xC0) + starting_sect[i]; + MbrSectDat[(450+(i*16))/2] = (ending_head[i]<<8) + systemid[i]; + //上位8bit:ending_cylの下位8bit, 下位8bit:ending_cylの上位2bit + ending_sect 6bit. + MbrSectDat[(452+(i*16))/2] = (ending_cyl[i]<<8) + + ((ending_cyl[i]>>2) & 0xC0) + ending_sect[i]; + MbrSectDat[(454+(i*16))/2] = NandFatSpec[i].NOM; + MbrSectDat[(456+(i*16))/2] = (NandFatSpec[i].NOM>>16); + MbrSectDat[(458+(i*16))/2] = total_sect[i]; + MbrSectDat[(460+(i*16))/2] = (total_sect[i]>>16); + } MbrSectDat[510/2] = 0xAA55; /*セクタ0に書き込み*/ - sdmcWriteFifo( MbrSectDat, 1, 0, NULL, &SdResult); + sdmcWriteFifo( MbrSectDat, 1, 0, NULL, &SdResult);//MbrSectDatは2Byte alignかも知れないので危険 /**/ - 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 + for( i=0; i<4; i++) { + PRINTDEBUG( "---partition %d---\n", i); + PRINTDEBUG( "total sect : 0x%x\n", total_sect[i]); + PRINTDEBUG( "starting head : 0x%x\n", starting_head[i]); + PRINTDEBUG( "starting sect : 0x%x\n", starting_sect[i]); + PRINTDEBUG( "starting cyl : 0x%x\n", starting_cyl[i]); + PRINTDEBUG( "ending head : 0x%x\n", ending_head[i]); + PRINTDEBUG( "ending sect : 0x%x\n", ending_sect[i]); + PRINTDEBUG( "ending cyl : 0x%x\n", ending_cyl[i]); + PRINTDEBUG( "\n"); + } } //#endif /*(INCLUDE_SD)*/ diff --git a/build/tests/fatfs/Makefile b/build/tests/fatfs/Makefile index 013c8ff..c52370e 100644 --- a/build/tests/fatfs/Makefile +++ b/build/tests/fatfs/Makefile @@ -20,7 +20,8 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -SUBDIRS = fatfs_sd +SUBDIRS = fatfs_sd \ + nand_formatter_kmc \ #---------------------------------------------------------------------------- diff --git a/build/tests/fatfs/fatfs_sd/ARM7/src/main.c b/build/tests/fatfs/fatfs_sd/ARM7/src/main.c index 7f01cee..364189a 100644 --- a/build/tests/fatfs/fatfs_sd/ARM7/src/main.c +++ b/build/tests/fatfs/fatfs_sd/ARM7/src/main.c @@ -187,10 +187,10 @@ void TwlSpMain(void) PRINTDEBUG( "sdmcRtfsAttach error!.\n"); } } - if( nandRtfsAttach( 5) == FALSE) { //nandをFドライブにする + if( nandRtfsAttach( 5, 0) == FALSE) { //nandをFドライブにする PRINTDEBUG( "nandRtfsAttach failed.\n"); }else{ - if( nandRtfsAttach( 5) == FALSE) { + if( nandRtfsAttach( 5, 0) == FALSE) { PRINTDEBUG( "nandRtfsAttach success.\n"); }else{ PRINTDEBUG( "nandRtfsAttach error!.\n"); diff --git a/build/tests/fatfs/nand_formatter_kmc/ARM7/src/main.c b/build/tests/fatfs/nand_formatter_kmc/ARM7/src/main.c index f3bb26b..f8ab818 100644 --- a/build/tests/fatfs/nand_formatter_kmc/ARM7/src/main.c +++ b/build/tests/fatfs/nand_formatter_kmc/ARM7/src/main.c @@ -24,11 +24,26 @@ #define kmc_getchar() ((char)vlink_dos_get_console()) #define kmc_putchar(x) vlink_dos_put_console((char)(x)) + + + + +extern void nandSetFormatRequest( u16 partition_num, u16* partition_mbytes); + + /*---------------------------------------------------------------------------* 定数定義 *---------------------------------------------------------------------------*/ #define PRINTDEBUG OS_TPrintf +//配列partition_MB_sizeのインデックス +#define INDEX_RAW_PARTITION 0 +#define INDEX_FAT0_PARTITION 1 +#define INDEX_FAT1_PARTITION 2 +#define INDEX_FAT2_PARTITION 3 +#define INDEX_FAT3_PARTITION 4 + + /*---------------------------------------------------------------------------* 内部関数定義 *---------------------------------------------------------------------------*/ @@ -64,6 +79,46 @@ static BOOL getchar_yes_no_prompt(void) } } +static int pow10( int count) +{ + int i, result; + + result = 1; + for( i=0; i= '0')&&(c <= '9')) { + kmc_putchar( c); + size_num[i++] = ((int)c) % ((int)'0'); + if( i==3) { break;} + } + if( c == '\b') { + if( i != 0) { i--;} + kmc_putchar( c); + } + } + keta = i; + + result_num = 0; + for( j=0; j "); + if( FALSE == getchar_yes_no_prompt()) { + PRINTDEBUG( "o\n"); + DBG_CHAR( '\n'); + goto NAND_FLASH_FORMAT_END; + } + DBG_PRINTF( "es\n"); + DBG_CHAR( '\n'); + + +#if 1 + nand_fat_partition_num = 1; + while( 1) { + DBG_PRINTF( "RAW PARTITION SIZE?(MBytes) -> "); + partition_MB_size[INDEX_RAW_PARTITION] = get_number_prompt(); + DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_RAW_PARTITION]); + + DBG_PRINTF( "FAT PARTITION 0 SIZE?(MBytes) -> "); + partition_MB_size[INDEX_FAT0_PARTITION] = get_number_prompt(); + DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_FAT0_PARTITION]); + if( partition_MB_size[INDEX_FAT0_PARTITION] == 0) { + DBG_PRINTF( "invalid parameter.\n"); + goto NAND_FLASH_FORMAT_END; + } + nand_fat_partition_num++; + + DBG_PRINTF( "FAT PARTITION 1 SIZE?(MBytes) -> "); + partition_MB_size[INDEX_FAT1_PARTITION] = get_number_prompt(); + DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_FAT1_PARTITION]); + if( partition_MB_size[INDEX_FAT1_PARTITION] == 0) { + break; + } + nand_fat_partition_num++; + + DBG_PRINTF( "FAT PARTITION 2 SIZE?(MBytes) -> "); + partition_MB_size[INDEX_FAT2_PARTITION] = get_number_prompt(); + DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_FAT2_PARTITION]); + if( partition_MB_size[INDEX_FAT2_PARTITION] == 0) { + break; + } + nand_fat_partition_num++; + + DBG_PRINTF( "FAT PARTITION 3 SIZE?(MBytes) -> "); + partition_MB_size[INDEX_FAT3_PARTITION] = get_number_prompt(); + DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_FAT3_PARTITION]); + break; + } +#endif + DBG_PRINTF( "%d FAT Partitions.\n", nand_fat_partition_num); + /*パーティション構成をライブラリに要求*/ + nandSetFormatRequest( nand_fat_partition_num, partition_MB_size); + + + + /*マウント*/ + if( nandRtfsAttach( 5, 0) == FALSE) { //nandパーティション0をFドライブにする PRINTDEBUG( "nandRtfsAttach failed.\n"); + goto NAND_FLASH_FORMAT_END; }else{ - if( nandRtfsAttach( 5) == FALSE) { - PRINTDEBUG( "nandRtfsAttach success.\n"); + if( nandRtfsAttach( 5, 0) == FALSE) { }else{ PRINTDEBUG( "nandRtfsAttach error!.\n"); + goto NAND_FLASH_FORMAT_END; } } if( !rtfs_pc_set_default_drive( (unsigned char*)"F:")) { PRINTDEBUG( "pc_set_default_drive failed\n"); - while( 1){}; + goto NAND_FLASH_FORMAT_END; } - PRINTDEBUG( "pc_set_default_drive success\n"); + /**/ - PRINTDEBUG( "pc_check_disk start. please wait.\n"); - pc_check_disk( (byte*)"F:", &dstat, 0, 1, 1); - PRINTDEBUG( "pc_check_disk end.\n"); +// PRINTDEBUG( "pc_check_disk start. please wait.\n"); +// pc_check_disk( (byte*)"F:", &dstat, 0, 1, 1); +// PRINTDEBUG( "pc_check_disk end.\n"); + /*--- MBR書き込み、パーティション0フォーマット ---*/ if( !rtfs_pc_get_media_parms( (byte*)"F:", &geometry)) { PRINTDEBUG( "pc_get_media_parms failed\n"); + goto NAND_FLASH_FORMAT_END; } + /**/ if( !pc_format_media( (byte*)"F:", &geometry)) { PRINTDEBUG( "pc_format_media failed\n"); + goto NAND_FLASH_FORMAT_END; } - + PRINTDEBUG( "build MBR success.\n"); + + /*ボリュームフォーマット*/ if( !pc_format_volume( (byte*)"F:", &geometry)) { - PRINTDEBUG( "pc_format_volume failed\n"); + PRINTDEBUG( "pc_format_volume (p0) failed\n"); + goto NAND_FLASH_FORMAT_END; } + PRINTDEBUG( "format FAT partition 0 success.\n"); + /*-------------------------------------------------*/ + - PRINTDEBUG( "Sample program ends.\n"); - - - while (TRUE) - { - OS_Halt(); - - //---- check reset - if (OS_IsResetOccurred()) - { - OS_ResetSystem(); + /*マウント(F:p0, G:p1, H:p2, I:p3)*/ + for( i=1; i