(shirait) fatfsサンプルのコミット漏れ

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@286 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
(no author) 2009-02-13 00:41:55 +00:00
parent 3cb3abc8ee
commit 592f917801
2 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,184 @@
/*---------------------------------------------------------------------------*
Project: TwlBrom - thread
File: main.c
Copyright 2008 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#include <brom.h>
#include <brom/nand/nand.h>
#include <firm/fatfs/rtfs.h>
//REG_NAND_COMMAND
#define NAND_START (0x0100)
#define NAND_BUSY NAND_START
#define NAND_RESET 6
#define NAND_READ_STATUS 5
#define NAND_ERASE_BLOCK 4
#define NAND_PROGRAM_PAGE 3
#define NAND_READ_PAGE 1
//REG_NAND_ECC
#define NAND_ENABLE_ECC 1
#define REG_NAND_ADR_LO (0x18019840)
#define REG_NAND_ADR_HI (0x18019842)
#define REG_NAND_COMMAND (0x1801984E)
#define REG_NAND_ECC (0x18019850)
#define REG_NAND_DATA (0x18019000)
#define REG_NAND_SPARE (0x18019800)
void NandReset( void);
void NandErase( u16 adr_hi, u16 adr_lo);
void NandWrite( u16 adr_hi, u16 adr_lo, u32* buf);
void NandRead( u16 adr_hi, u16 adr_lo);
u32 CalcECC( u32* buf);
u32 CalcCP( u32* buf, u32 st, u32 cmp, u32 logic);
u32 CalcLP( u32* buf, u32 st, u32 cmp, u32 logic);
BOOL i_nandCheckECC( u32* data, u32* stored_ecc, u32 new_ecc);
void nandSetFormatRequest( u16 partition_num, u32* partition_sectors);
NandPageCacheFormat NandPageCache[1];
u32 BlockBuf[2*1024/4];
void BromMain( void )
{
u32 partition_sectors[5];
DEV_GEOMETRY dgeometry;
PCFD fd;
int result;
u32 s_ecc, n_ecc;
osInitException();
osInitBROM();
osPrintf( "ARM11: start\n" );
osInitThread();
/*nandレイアウト*/
partition_sectors[0] = (( 1*1024*1024)/512); // 1MB
partition_sectors[1] = ((96*1024*1024)/512); // 96MB
partition_sectors[2] = ((24*1024*1024)/512); // 24MB
partition_sectors[3] = (( 1*1024*1024)/512); // rest
partition_sectors[4] = (0);
/*nandドライバ初期化*/
nandInit();
nandEnable( NandPageCache);
/*fatfsライブラリ初期化*/
rtfs_init();
/*マウント*/
nandRtfsAttach( /*drive*/0, /*partition*/0); // "A:"...partition0
nandRtfsAttach( /*drive*/1, /*partition*/1); // "B:"...partition1
nandRtfsAttach( /*drive*/2, /*partition*/2); // "C:"...partition2
#if 0
/*メディアフォーマット*/
nandSetFormatRequest( 3, partition_sectors);
if( pc_get_media_parms( (u8*)L"A:", &dgeometry) == FALSE) {
osTPrintf( "pc_get_media_parms : FAILURE\n");
}else{
osTPrintf( "pc_get_media_parms : SUCCESS\n");
}
if( pc_format_media( (u8*)L"A:", &dgeometry) == FALSE) {
osTPrintf( "pc_format_media : FAILURE\n");
}else{
osTPrintf( "pc_format_media : SUCCESS\n");
}
/*パーティション0フォーマット*/
if( pc_format_volume( (u8*)L"A:", &dgeometry) == FALSE) {
osTPrintf( "pc_format_volume for FAT-PARTITION(0) : FAILURE\n");
}else{
osTPrintf( "pc_format_volume for FAT-PARTITION(0) : SUCCESS\n");
}
/*パーティション1フォーマット*/
if( pc_get_media_parms( (u8*)L"B:", &dgeometry) == FALSE) {
osTPrintf( "pc_get_media_parms : FAILURE\n");
}else{
osTPrintf( "pc_get_media_parms : SUCCESS\n");
}
if( pc_format_volume( (u8*)L"B:", &dgeometry) == FALSE) {
osTPrintf( "pc_format_volume for FAT-PARTITION(1) : FAILURE\n");
}else{
osTPrintf( "pc_format_volume for FAT-PARTITION(1) : SUCCESS\n");
}
/*パーティション2フォーマット*/
if( pc_get_media_parms( (u8*)L"C:", &dgeometry) == FALSE) {
osTPrintf( "pc_get_media_parms : FAILURE\n");
}else{
osTPrintf( "pc_get_media_parms : SUCCESS\n");
}
if( pc_format_volume( (u8*)L"C:", &dgeometry) == FALSE) {
osTPrintf( "pc_format_volume for FAT-PARTITION(2) : FAILURE\n");
}else{
osTPrintf( "pc_format_volume for FAT-PARTITION(2) : SUCCESS\n");
}
nandFlush();
osTPrintf( "fat format finished.\n");
osTPrintf( "\n");
{
u32 total_blocks, free_blocks;
osTPrintf( "pc_free for FAT-PARTITION(0) results follow.\n");
osTPrintf( "free bytes : 0x%x\n", pc_free( (u8*)L"A:", &total_blocks, &free_blocks));
osTPrintf( "total_blocks : 0x%x, free_blocks : 0x%x\n", total_blocks, free_blocks);
osTPrintf( "\n");
osTPrintf( "pc_free for FAT-PARTITION(1) results follow.\n");
osTPrintf( "free bytes : 0x%x\n", pc_free( (u8*)L"B:", &total_blocks, &free_blocks));
osTPrintf( "total_blocks : 0x%x, free_blocks : 0x%x\n", total_blocks, free_blocks);
osTPrintf( "\n");
osTPrintf( "pc_free for FAT-PARTITION(2) results follow.\n");
osTPrintf( "free bytes : 0x%x\n", pc_free( (u8*)L"C:", &total_blocks, &free_blocks));
osTPrintf( "total_blocks : 0x%x, free_blocks : 0x%x\n", total_blocks, free_blocks);
osTPrintf( "\n");
}
osTPrintf( "finished.\n");
#else
{
u32 total_blocks, free_blocks;
osTPrintf( "pc_free\n");
osTPrintf( "free bytes : 0x%x\n", pc_free( (u8*)L"A:", &total_blocks, &free_blocks));
osTPrintf( "total_blocks : 0x%x, free_blocks : 0x%x\n", total_blocks, free_blocks);
}
osTPrintf( "po_open\n");
fd = po_open( "A:\\test2.bin", (PO_BINARY | PO_RDWR | PO_CREAT), PS_IWRITE);
osTPrintf( "fd : 0x%x\n", fd);
result = po_close( fd);
osTPrintf( "po_close : %d\n", result);
#endif
while (1)
{
u32 pmon = osGetPerfMonitor(OS_MONITOR_1);
OSTick tick = osGetTick();
osSleep(1000);
tick = osGetTick() - tick;
pmon = osGetPerfMonitor(OS_MONITOR_1) - pmon;
osTPrintf( "sleep tick = %llu msec\n", OS_TICK_TO_MSEC(tick) );
osTPrintf( "sleep mon = %llu msec\n", OS_PMON_TO_MSEC(pmon) );
}
}

View File

@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------*
Project: TwlBrom - thread
File: main.c
Copyright 2008 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#include <brom.h>
void BromSpMain( void )
{
osInitException();
osInitBROM();
osPrintf( "ARM9: start\n" );
osInitThread();
while (1)
{
OSTick tick = osGetTick();
osSleep(1000);
tick = osGetTick() - tick;
osTPrintf( "sleep tick = %llu msec\n", OS_TICK_TO_MSEC(tick) );
}
}