diff --git a/trunk/bootrom/build/tests/Makefile b/trunk/bootrom/build/tests/Makefile index ac0db1a..49a0c08 100644 --- a/trunk/bootrom/build/tests/Makefile +++ b/trunk/bootrom/build/tests/Makefile @@ -22,6 +22,7 @@ include $(CTRBROM_ROOT)/build/buildtools/commondefs SUBDIRS = \ thread \ + nand \ #---------------------------------------------------------------------------- diff --git a/trunk/bootrom/build/tests/nand/ARM11/Makefile b/trunk/bootrom/build/tests/nand/ARM11/Makefile new file mode 100644 index 0000000..d6091cb --- /dev/null +++ b/trunk/bootrom/build/tests/nand/ARM11/Makefile @@ -0,0 +1,53 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: CtrBrom - bootrom - nand +# File: Makefile +# +# 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$ +#---------------------------------------------------------------------------- + +#BROM_DEF_LINK_SCATLD = TRUE + +BROM_TARGET = APP + +SUBDIRS = + + +#---------------------------------------------------------------------------- + +TARGET_BIN = nand11.dasm + +SRCS = \ + main.c \ + +#LCFILE = # using default + +include $(CTRBROM_ROOT)/build/buildtools/commondefs + +#ライブラリの追加 +GLIBRARIES += $(addsuffix $(BROM_LIBSUFFIX).a, libnand$(BROM_PROFILE_TYPE)) + +SRCDIR = . + +INSTALL_DIR = .. +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN_BASENAME).axf + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(CTRBROM_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/trunk/bootrom/build/tests/nand/ARM11/main.c b/trunk/bootrom/build/tests/nand/ARM11/main.c new file mode 100644 index 0000000..e53344f --- /dev/null +++ b/trunk/bootrom/build/tests/nand/ARM11/main.c @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + 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 +#include + +//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) + + +NandPageCacheFormat NandPageCache[1]; +u32 BlockBuf [2*1024/4]; + + +void BromMain( void ) +{ + u32 s_ecc, n_ecc; + + osInitException(); + osInitBROM(); + + osPrintf( "ARM11: start\n" ); + + osInitThread(); + + nandInit(); + nandEnable( NandPageCache); + + miCpuFill8( BlockBuf, 0x33, 2*1024); + osTPrintf( "nandWriteSector..."); + nandWriteSector( BlockBuf, 0, 1); + osTPrintf( "done\n"); + + osTPrintf( "nandFlush..."); + nandFlush(); + osTPrintf( "done\n"); + + miCpuFill8( BlockBuf, 0x5A, 2*1024); + osTPrintf( "nandReadSector..."); + nandReadSector( BlockBuf, 0, 1); + osTPrintf( "done\n"); + + osTPrintf( "finished.\n"); + + 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) ); + } +} diff --git a/trunk/bootrom/build/tests/nand/ARM9/Makefile b/trunk/bootrom/build/tests/nand/ARM9/Makefile new file mode 100644 index 0000000..f300122 --- /dev/null +++ b/trunk/bootrom/build/tests/nand/ARM9/Makefile @@ -0,0 +1,52 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: CtrBrom - bootrom - nand +# File: Makefile +# +# 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$ +#---------------------------------------------------------------------------- + + +#BROM_DEF_LINK_SCATLD = TRUE + +BROM_TARGET = APP +BROM_PROC = ARM9 + +SUBDIRS = + + +#---------------------------------------------------------------------------- + +TARGET_BIN = nand9.dasm + +SRCS = \ + main.c \ + +#LCFILE = # using default + +include $(CTRBROM_ROOT)/build/buildtools/commondefs + +SRCDIR = . + +INSTALL_DIR = .. +INSTALL_TARGETS = $(BINDIR)/$(TARGET_BIN_BASENAME).axf + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + + +include $(CTRBROM_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/trunk/bootrom/build/tests/nand/ARM9/main.c b/trunk/bootrom/build/tests/nand/ARM9/main.c new file mode 100644 index 0000000..2de8660 --- /dev/null +++ b/trunk/bootrom/build/tests/nand/ARM9/main.c @@ -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 + +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) ); + } +} + diff --git a/trunk/bootrom/build/tests/nand/Makefile b/trunk/bootrom/build/tests/nand/Makefile new file mode 100644 index 0000000..00acd20 --- /dev/null +++ b/trunk/bootrom/build/tests/nand/Makefile @@ -0,0 +1,33 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: CtrBrom - build +# File: Makefile +# +# Copyright 2009 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 $(CTRBROM_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +SUBDIRS = \ + ARM11 \ + ARM9 \ + +#---------------------------------------------------------------------------- + +include $(CTRBROM_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile ===== diff --git a/trunk/bootrom/include/brom/nand/nand.h b/trunk/bootrom/include/brom/nand/nand.h new file mode 100644 index 0000000..9d7048e --- /dev/null +++ b/trunk/bootrom/include/brom/nand/nand.h @@ -0,0 +1,119 @@ +/*---------------------------------------------------------------------------* + Project: CTR - NAND driver + File: nand.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 __NAND_H__ +#define __NAND_H__ + + +#include "nandif_ip.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/*---------------------------------------------------------------------------* + 定義 + *---------------------------------------------------------------------------*/ +#define NAND_GUARANTEED_BLOCKS (999) +#define NAND_GUARANTEED_SECTORS (NAND_GUARANTEED_BLOCKS*256) //保証されたセクタ数(=使える容量) + +#define NAND_CACHE_PAGES (1) /* 1以外は設定禁止 */ +#define NAND_ANTI_READDISTURB (1) /* TODO */ + +/*---------------------------------------------------------------------------* + 構造体 + *---------------------------------------------------------------------------*/ +typedef struct NandPageCacheFormat { //ブロックキャッシュ + u16 valid; /*有効 or 無効*/ + u16 dirty; /*ダーティ or クリーン*/ + u16 OnTheFlush; /*Flush進行中のNewPhysicalBlk番号*/ + struct NandBlockStatInfo* TargetNandBlockStat; /*Flush進行中のNewPhysicalBlk情報へのポインタ*/ + BOOL BlockDirty; /*ブロック・ダーティ or クリーン*/ +// u16 logical_blk; /*論理ブロック番号*/ + u32 logical_page; /*論理ページ番号*/ + u8 page_flushed_count; /*Flush先の物理ページオフセット(0からカウントアップ)*/ + int page_flushed[64]; /*Flushによって書き込まれた物理ページのオフセット*/ + struct NandPageFormat NandPage[NAND_CACHE_PAGES]; /*1ページ分のキャッシュメモリ*/ + u32 ecc[NAND_CACHE_PAGES][4]; /*読み出し時に自動生成されたECC*/ + struct NandSpareFormat NandSpareWriteForward; /*newブロックにライトするスペア領域*/ + struct NandSpareFormat NandSpareWriteBack; /*oldブロックにライトバックするスペア領域*/ + struct NandSpareFormat NandSpareWriteMerge; /*mergeブロックにライトするスペア領域*/ +} NandPageCacheFormat; + + +typedef struct NandBlockStatInfo { //ブロック状態リンクリスト + u16 physical_blk; + u16 block_stat_bad; + u32 erase_count; + struct NandBlockStatInfo* next; +} NandBlockStatInfo; + + +typedef struct NandStatInfo { + struct NandBlockStatInfo* busy; /*論理blk番号が割り当て済み*/ + struct NandBlockStatInfo* free; /*論理blk番号が未割り当て*/ +} NandStatInfo; + + + +/*RTFS用 FATパラメータ*/ +typedef struct { + u32 device_capacity; //デバイス全体のサイズ(512Byte単位) + u32 adjusted_device_capacity; + + u32 memory_capacity; //data areaのサイズ(512Byte単位) + u32 adjusted_memory_capacity; //memory_capacityをシリンダ(heads*secptrack)の倍数に調整したサイズ(cylinders*heads*secptrackになる) + u16 volume_cylinders; + + u16 heads; + u16 secptrack; + u16 cylinders; + u16 SC; //sectors per cluster + u16 BU; + u16 RDE; //number of root dir entries(512 fix) + u32 SS; //sector size(512 fix) + u32 RSC; //reserved sector count(1 fix) + u16 FATBITS; //16 or 32 + u16 SF; //sectors per FAT + u32 SSA; //sectors in system area + u32 NOM; //sectors in master boot record + + u32 begin_sect; +} NandSpec; + + + +/*---------------------------------------------------------------------------* + API + *---------------------------------------------------------------------------*/ +BOOL nandRtfsAttach( int driveno, int partition); + +void nandInit( void); +void nandEnable( NandPageCacheFormat* NandPageCache); +void nandFormat( void); + +void nandReadSector( u32* dest, u32 logical_sector, u32 sector_count); +void nandWriteSector( u32* src, u32 logical_sector, u32 sector_count); + +BOOL nandFlush( void); +BOOL nandCheckMedia( void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /*__NAND_H__*/ diff --git a/trunk/bootrom/include/brom/nand/nandif_ip.h b/trunk/bootrom/include/brom/nand/nandif_ip.h new file mode 100644 index 0000000..eec85f4 --- /dev/null +++ b/trunk/bootrom/include/brom/nand/nandif_ip.h @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------* + Project: CTR - NAND driver + File: nandif_ip.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 __NAND_IF_IP_H__ +#define __NAND_IF_IP_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +#define NAND_PAGE_DATASIZE (2048) +#define NAND_PAGE_SPARESIZE (64) +#define NAND_PAGE_ALLSIZE (NAND_PAGE_DATASIZE + NAND_PAGE_SPARESIZE) + + +/*---------------------------------------------------------------------------* + 構造体 + *---------------------------------------------------------------------------*/ +typedef struct NandSpareFormat {/*スペア領域 64バイト*/ + u8 block_stat_bad; // 1 ブロックステータス(バッドブロック) + u8 block_stat_warning; // 1 ブロックステータス(注意ブロック) + u8 page_stat; // 1 ページステータス + u8 pad0; // 1 + u32 block_erase_count0; // 4 ブロック消去回数(パリティ付き) + u16 logical_adr0; // 2 論理アドレス(パリティ付き) + u16 pad1; // 2 + u32 ecc[4]; //16 ECC 0〜3 + u32 block_erase_count1; // 4 ブロック消去回数(パリティ付き)予備 + u16 logical_adr1; // 2 論理アドレス(パリティ付き)予備 + u16 pad2; // 2 + char sig0[4]; // 4 Signature"CTR\0" + char sig1[4]; // 4 Signature"CTR\0" + u8 reserve[20]; //28 予約 +} NandSpareFormat; + +typedef struct NandDataFormat { /*データ領域 2048バイト*/ + u32 data[4][512/4]; +/* u32 data0[512/4]; //データ領域1/4(512バイト) + u32 data1[512/4]; //データ領域2/4(512バイト) + u32 data2[512/4]; //データ領域3/4(512バイト) + u32 data3[512/4]; //データ領域4/4(512バイト)*/ +} NandDataFormat; + +typedef struct NandPageFormat { /*ページ全体*/ + struct NandDataFormat data; + struct NandSpareFormat spare; //スペア領域(64バイト) +} NandPageFormat; + + +/* +typedef struct NandSysFormat { + u16 logical_adr; + u16 read_count; + u32 erase_count; +} NandSysFormat;*/ + + + +/*---------------------------------------------------------------------------* + API + *---------------------------------------------------------------------------*/ +BOOL i_nandEraseBlock( u16 physical_blk); +BOOL i_nandReadPage( NandPageFormat* dest, u32 physical_page_addr, BOOL sync); +BOOL i_nandWritePage( NandPageFormat* src, u32 physical_page_addr, BOOL sync); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /*__NAND_IF_IP_H__*/