mirror of
https://github.com/rvtr/ctr_firmware.git
synced 2025-10-31 07:51:08 -04:00
NANDドライバ追加、
NANDデバイスレベルフォーマッタ追加 git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@245 b871894f-2f95-9b40-918c-086798483c85
This commit is contained in:
parent
6a5f4a9f39
commit
a447e861fb
51
trunk/bootrom/build/libraries/nand/ARM11/Makefile
Normal file
51
trunk/bootrom/build/libraries/nand/ARM11/Makefile
Normal file
@ -0,0 +1,51 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: CtrBrom - libraries - mi
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2008-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$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
SUBMAKES =
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
BROM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
#(NE1)-------------------------------------------
|
||||
ifeq ($(BROM_PLATFORM),NE1EMU)
|
||||
SRCDIR = . ./src/ne1 ../common/ne1
|
||||
SRCS = \
|
||||
nandif.c \
|
||||
nand.c \
|
||||
crc.c
|
||||
endif
|
||||
#------------------------------------------------
|
||||
|
||||
TARGET_LIB = libnand$(BROM_LIBSUFFIX).a
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(BROM_INSTALL_LIBDIR)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
#===== End of Makefile =====
|
||||
47
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/crc.c
Normal file
47
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/crc.c
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
#include <brom.h>
|
||||
#include "crc.h"
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
global変数
|
||||
*---------------------------------------------------------------------------*/
|
||||
static const u16 cr16_table[16] = {
|
||||
0x0000, 0xCC01, 0xD801, 0x1400,
|
||||
0xF001, 0x3C00, 0x2800, 0xE401,
|
||||
0xA001, 0x6C00, 0x7800, 0xB401,
|
||||
0x5000, 0x9C01, 0x8801, 0x4400,
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: crcCalc
|
||||
|
||||
Description: CRC(CRC-ANSI, 別名CRC16)を算出する
|
||||
|
||||
Arguments: data :
|
||||
len :
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
u16 crcCalc( vu8* data, vu16 len)
|
||||
{
|
||||
vu16 r1, total;
|
||||
|
||||
total = 0;
|
||||
while( len-- > 0) {
|
||||
/*下位4bit*/
|
||||
r1 = cr16_table[ total & 0xf];
|
||||
total = (total >> 4) & 0x0FFF;
|
||||
total = total ^ r1 ^ cr16_table[ *data & 0xf];
|
||||
|
||||
/*上位4bit*/
|
||||
r1 = cr16_table[ total & 0xf];
|
||||
total = (total >> 4) & 0x0fff;
|
||||
total = total ^ r1 ^ cr16_table[ (*data >> 4) & 0xf];
|
||||
|
||||
/*次のバイトへ*/
|
||||
data++;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
26
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/crc.h
Normal file
26
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/crc.h
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef __CRC_H__
|
||||
#define __CRC_H__
|
||||
|
||||
|
||||
#include <brom.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
API
|
||||
*---------------------------------------------------------------------------*/
|
||||
u16 crcCalc( vu8* data, vu16 len);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*__CRC_H__*/
|
||||
1611
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nand.c
Normal file
1611
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nand.c
Normal file
File diff suppressed because it is too large
Load Diff
121
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nand.h
Normal file
121
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nand.h
Normal file
@ -0,0 +1,121 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
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番号*/
|
||||
u16 reserve0;
|
||||
struct NandBlockStatInfo* TargetNandBlockStat; /*Flush進行中のNewPhysicalBlk情報へのポインタ*/
|
||||
BOOL BlockDirty; /*ブロック・ダーティ or クリーン*/
|
||||
// u16 logical_blk; /*論理ブロック番号*/
|
||||
u32 logical_page; /*論理ページ番号*/
|
||||
u8 page_flushed_count; /*Flush先の物理ページオフセット(0からカウントアップ)*/
|
||||
u8 reserve1[3];
|
||||
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__*/
|
||||
398
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif.c
Normal file
398
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif.c
Normal file
@ -0,0 +1,398 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CTR - NAND driver
|
||||
File: nandif.c
|
||||
|
||||
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.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <brom.h>
|
||||
#include "nandif_ip.h"
|
||||
#include "nandif_reg.h"
|
||||
|
||||
#if 0
|
||||
#define PRINTDEBUG osTPrintf
|
||||
#else
|
||||
#define PRINTDEBUG( ...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
static関数
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void i_nandWait( void);
|
||||
static void i_nandStart( u16 mode);
|
||||
static void i_nandSetEccDirection( u32 direction);
|
||||
static void i_nandChangeBuffer( void);
|
||||
|
||||
static u32 CalcECC( u32* buf);
|
||||
static u32 CalcCP( u32* buf, u32 st, u32 cmp, u32 logic);
|
||||
static u32 CalcLP( u32* buf, u32 st, u32 cmp, u32 logic);
|
||||
|
||||
u32 nand_ecc[4];
|
||||
|
||||
|
||||
/*NAND低レベル層制御*/
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandWait
|
||||
|
||||
Description: オペレーションが終了するまで待つ
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void i_nandWait( void)
|
||||
{
|
||||
u32 stat;
|
||||
|
||||
while( 1) {
|
||||
stat = *(vu16*)REG_NAND_COMMAND;
|
||||
if( (stat & NAND_BUSY) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandStart
|
||||
|
||||
Description: 指定したモードをスタートする
|
||||
|
||||
Arguments: mode :
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void i_nandStart( u16 mode)
|
||||
{
|
||||
i_nandWait();
|
||||
*(vu32*)REG_NAND_COMMAND = (mode | NAND_START);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandSetEccDirection
|
||||
|
||||
Description: ECCが算出される条件を指定する
|
||||
|
||||
Arguments: direction : NAND_CTRL_ECC_WRITE or NAND_CTRL_ECC_READ
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void i_nandSetEccDirection( u32 direction)
|
||||
{
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandChangeBuffer
|
||||
|
||||
Description: バッファの裏表を切り替える
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
static void i_nandChangeBuffer( void)
|
||||
{
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandReset
|
||||
|
||||
Description: HW-IPを初期状態にする
|
||||
|
||||
Arguments: None
|
||||
|
||||
Returns: None
|
||||
*---------------------------------------------------------------------------*/
|
||||
void i_nandReset( void)
|
||||
{
|
||||
/*--- HW ECC OFF ---*/
|
||||
*(vu16*)REG_NAND_ECC &= ~NAND_ENABLE_ECC;
|
||||
|
||||
i_nandWait();
|
||||
*(u16*)REG_NAND_COMMAND = (NAND_RESET | NAND_START);
|
||||
i_nandWait();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandEraseBlock
|
||||
|
||||
Description: 物理ブロックを消去する
|
||||
|
||||
Arguments: physical_blk : 物理ブロック番号
|
||||
|
||||
Returns: FALSE : 失敗
|
||||
TRUE : 成功
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL i_nandEraseBlock( u16 physical_blk)
|
||||
{
|
||||
// PRINTDEBUG( ">>>@ erase physical blk : 0x%x\n", physical_blk);
|
||||
|
||||
i_nandWait(); /*デバイス待ち*/
|
||||
|
||||
/*イレースするためのレジスタ設定*/
|
||||
*(u16*)REG_NAND_ADR_LO = 0;
|
||||
*(u16*)REG_NAND_ADR_HI = (physical_blk << 1);
|
||||
|
||||
/*書き込み開始*/
|
||||
*(u16*)REG_NAND_COMMAND = (NAND_ERASE_BLOCK | NAND_START);
|
||||
|
||||
// osSleep( 1); /* 90nm(typ:2ms, max:3ms),60nm実測1.2ms */
|
||||
|
||||
i_nandWait(); /*デバイス内部消去動作中*/
|
||||
#if 0
|
||||
/*READY状態になったらPASSかFAILかを判定する*/
|
||||
while( 1) {
|
||||
/*ステータスリード*/
|
||||
*(vu32*)NAND_IP_CTRL = NAND_CTRL_READSTAT | NAND_CTRL_ECC_WRITE |
|
||||
(*(vu32*)NAND_IP_CTRL & NAND_CTRL_PAGE_MASK) | NAND_CTRL_SPEED_HI;
|
||||
*(u32*)NAND_IP_CTRL |= NAND_CTRL_START;
|
||||
/*ステータスリード*/
|
||||
i_nandWait();
|
||||
/*ステータスレジスタチェック*/
|
||||
if( *(vu16*)NAND_IP_STAT & NAND_STAT_READY) {
|
||||
if( *(vu16*)NAND_IP_STAT & NAND_STAT_FAIL) {
|
||||
return FALSE;
|
||||
}else{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandReadPage
|
||||
|
||||
Description: 物理ページをリードする
|
||||
|
||||
Arguments: physical_page_addr : 物理ページ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL i_nandReadPage( NandPageFormat* dest, u32 physical_page_addr, BOOL sync)
|
||||
{
|
||||
u32 byte_addr;
|
||||
PRINTDEBUG( ">>>@ read physical page : 0x%x\n", physical_page_addr);
|
||||
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
|
||||
/*リードするためのレジスタ設定*/
|
||||
byte_addr = (physical_page_addr * NAND_PAGE_DATASIZE);
|
||||
*(u16*)REG_NAND_ADR_LO = (u16)(byte_addr);
|
||||
*(u16*)REG_NAND_ADR_HI = (u16)(((u32)byte_addr >> 16));
|
||||
|
||||
/*最初の1ページをリードする*/
|
||||
*(u16*)REG_NAND_COMMAND = (NAND_READ_PAGE | NAND_START);
|
||||
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
|
||||
if( sync) {
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
//ここでページバッファにデータが入った
|
||||
}
|
||||
|
||||
miCpuCopy16( (u16*)REG_NAND_DATA, &(dest->data.data[0][0]), NAND_PAGE_DATASIZE);
|
||||
miCpuCopy16( (u16*)REG_NAND_SPARE, (u32*)&(dest->spare), NAND_PAGE_SPARESIZE);
|
||||
|
||||
/*---------- ソフトウェアECC ----------*/
|
||||
{
|
||||
u32 q_addr = (u32)(&(dest->data.data[0][0]));
|
||||
nand_ecc[0] = CalcECC( (u32*)q_addr);
|
||||
nand_ecc[1] = CalcECC( (u32*)(q_addr + 512));
|
||||
nand_ecc[2] = CalcECC( (u32*)(q_addr + 1024));
|
||||
nand_ecc[3] = CalcECC( (u32*)(q_addr + 1536));
|
||||
}
|
||||
/*-------------------------------------*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*
|
||||
Name: i_nandWritePage
|
||||
|
||||
Description: 物理ページに書き込む
|
||||
予め該当ページをイレースしておくこと。
|
||||
|
||||
Arguments: physical_page_addr : 物理ページ番号
|
||||
|
||||
Returns:
|
||||
*---------------------------------------------------------------------------*/
|
||||
BOOL i_nandWritePage( NandPageFormat* src, u32 physical_page_addr, BOOL sync)
|
||||
{
|
||||
u32 byte_addr;
|
||||
PRINTDEBUG( ">>>@ write physical page : 0x%x\n", physical_page_addr);
|
||||
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
|
||||
/*DataとSpare*/
|
||||
miCpuCopy16( &(src->data.data[0][0]), (u16*)REG_NAND_DATA, NAND_PAGE_DATASIZE); //2KB
|
||||
/*---------- ソフトウェアECC ----------*/
|
||||
{
|
||||
u32 q_addr = (u32)(&(src->data.data[0][0]));
|
||||
nand_ecc[0] = CalcECC( (u32*)(q_addr));
|
||||
nand_ecc[1] = CalcECC( (u32*)(q_addr + 512));
|
||||
nand_ecc[2] = CalcECC( (u32*)(q_addr + 1024));
|
||||
nand_ecc[3] = CalcECC( (u32*)(q_addr + 1536));
|
||||
}
|
||||
/*-------------------------------------*/
|
||||
miCpuCopy16( &(nand_ecc[0]), &(src->spare.ecc[0]), 4);
|
||||
miCpuCopy16( &(nand_ecc[1]), &(src->spare.ecc[1]), 4);
|
||||
miCpuCopy16( &(nand_ecc[2]), &(src->spare.ecc[2]), 4);
|
||||
miCpuCopy16( &(nand_ecc[3]), &(src->spare.ecc[3]), 4);
|
||||
miCpuCopy16( &(src->spare), (u16*)REG_NAND_SPARE, NAND_PAGE_SPARESIZE);
|
||||
|
||||
/*ライトするためのレジスタ設定*/
|
||||
byte_addr = (physical_page_addr * NAND_PAGE_DATASIZE);
|
||||
*(u16*)REG_NAND_ADR_LO = (u16)(byte_addr);
|
||||
*(u16*)REG_NAND_ADR_HI = (u16)(((u32)byte_addr >> 16));
|
||||
|
||||
*(u16*)REG_NAND_COMMAND = (NAND_PROGRAM_PAGE | NAND_START);
|
||||
|
||||
if( sync) {
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
#if 0
|
||||
/*READY状態になったらPASSかFAILかを判定する*/
|
||||
while( 1) {
|
||||
/*ステータスリード*/
|
||||
*(vu32*)NAND_IP_CTRL = NAND_CTRL_READSTAT | NAND_CTRL_ECC_WRITE |
|
||||
(*(vu32*)NAND_IP_CTRL & NAND_CTRL_PAGE_MASK) | NAND_CTRL_SPEED_HI;
|
||||
*(u32*)NAND_IP_CTRL |= NAND_CTRL_START;
|
||||
|
||||
/*IP動作中*/
|
||||
i_nandWait();
|
||||
/*ステータスレジスタチェック*/
|
||||
if( *(vu16*)NAND_IP_STAT & NAND_STAT_READY) {
|
||||
if( *(vu16*)NAND_IP_STAT & NAND_STAT_FAIL) {
|
||||
return FALSE;
|
||||
}else{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
return TRUE;
|
||||
#endif
|
||||
}else{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static u32 CalcECC( u32* buf)
|
||||
{
|
||||
u32 cp[10];
|
||||
u32 lp[14];
|
||||
u32 cym;
|
||||
|
||||
cp[0] = CalcCP( buf, 0, 0x1, 0);
|
||||
cp[1] = CalcCP( buf, 1, 0x1, 1);
|
||||
cp[2] = CalcCP( buf, 0, 0x2, 0);
|
||||
cp[3] = CalcCP( buf, 2, 0x2, 1);
|
||||
cp[4] = CalcCP( buf, 0, 0x4, 0);
|
||||
cp[5] = CalcCP( buf, 4, 0x4, 1);
|
||||
cp[6] = CalcCP( buf, 0, 0x8, 0);
|
||||
cp[7] = CalcCP( buf, 8, 0x8, 1);
|
||||
cp[8] = CalcCP( buf, 0x00, 0x10, 0);
|
||||
cp[9] = CalcCP( buf, 0x10, 0x10, 1);
|
||||
|
||||
lp[0] = CalcLP( buf, 0, 0x1, 0);
|
||||
lp[1] = CalcLP( buf, 1, 0x1, 1);
|
||||
lp[2] = CalcLP( buf, 0, 0x2, 0);
|
||||
lp[3] = CalcLP( buf, 2, 0x2, 1);
|
||||
lp[4] = CalcLP( buf, 0, 0x4, 0);
|
||||
lp[5] = CalcLP( buf, 4, 0x4, 1);
|
||||
lp[6] = CalcLP( buf, 0, 0x8, 0);
|
||||
lp[7] = CalcLP( buf, 8, 0x8, 1);
|
||||
lp[8] = CalcLP( buf, 0x00, 0x10, 0);
|
||||
lp[9] = CalcLP( buf, 0x10, 0x10, 1);
|
||||
lp[10] = CalcLP( buf, 0x00, 0x20, 0);
|
||||
lp[11] = CalcLP( buf, 0x20, 0x20, 1);
|
||||
lp[12] = CalcLP( buf, 0x00, 0x40, 0);
|
||||
lp[13] = CalcLP( buf, 0x40, 0x40, 1);
|
||||
|
||||
cym = ((lp[13] & 0x1) << 23) +
|
||||
((lp[12] & 0x1) << 22) +
|
||||
((lp[11] & 0x1) << 21) +
|
||||
((lp[10] & 0x1) << 20) +
|
||||
((lp[ 9] & 0x1) << 19) +
|
||||
((lp[ 8] & 0x1) << 18) +
|
||||
((lp[ 7] & 0x1) << 17) +
|
||||
((lp[ 6] & 0x1) << 16) +
|
||||
((lp[ 5] & 0x1) << 15) +
|
||||
((lp[ 4] & 0x1) << 14) +
|
||||
((lp[ 3] & 0x1) << 13) +
|
||||
((lp[ 2] & 0x1) << 12) +
|
||||
((lp[ 1] & 0x1) << 11) +
|
||||
((lp[ 0] & 0x1) << 10) +
|
||||
((cp[ 9] & 0x1) << 9) +
|
||||
((cp[ 8] & 0x1) << 8) +
|
||||
((cp[ 7] & 0x1) << 7) +
|
||||
((cp[ 6] & 0x1) << 6) +
|
||||
((cp[ 5] & 0x1) << 5) +
|
||||
((cp[ 4] & 0x1) << 4) +
|
||||
((cp[ 3] & 0x1) << 3) +
|
||||
((cp[ 2] & 0x1) << 2) +
|
||||
((cp[ 1] & 0x1) << 1) +
|
||||
((cp[ 0] & 0x1) << 0);
|
||||
// osTPrintf( "cym:0x%x\n", cym);
|
||||
return( cym);
|
||||
}
|
||||
|
||||
static u32 CalcCP( u32* buf, u32 st, u32 cmp, u32 logic)
|
||||
{
|
||||
u32 cp;
|
||||
u32 cmp0;
|
||||
u32 i, j;
|
||||
|
||||
cp = 0;
|
||||
for( j=st; j<32; j++) {
|
||||
if( (j & cmp) == 0) {
|
||||
cmp0 = 0;
|
||||
}else{
|
||||
cmp0 = 1;
|
||||
}
|
||||
if( cmp0 == logic) {
|
||||
for( i=0; i<128; i++) {
|
||||
cp ^= ((buf[i] >> j) & 0x1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
static u32 CalcLP( u32* buf, u32 st, u32 cmp, u32 logic)
|
||||
{
|
||||
u32 lp;
|
||||
u32 cmp0;
|
||||
u32 i, j;
|
||||
|
||||
lp = 0;
|
||||
for( i=st; i<128; i++) {
|
||||
if( (i & cmp) == 0) {
|
||||
cmp0 = 0;
|
||||
}else{
|
||||
cmp0 = 1;
|
||||
}
|
||||
if( cmp0 == logic) {
|
||||
for( j=0; j<32; j++) {
|
||||
lp ^= ((buf[i] >> j) & 0x1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lp;
|
||||
}
|
||||
|
||||
86
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif_ip.h
Normal file
86
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif_ip.h
Normal file
@ -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__*/
|
||||
125
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif_reg.h
Normal file
125
trunk/bootrom/build/libraries/nand/ARM11/src/ne1/nandif_reg.h
Normal file
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*
|
||||
Project: CTR - NAND driver
|
||||
File: nandif_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 __NAND_IP_REG_H__
|
||||
#define __NAND_IP_REG_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)
|
||||
|
||||
|
||||
#define NAND_IP_ECC_0 (0x0100) //ダミー
|
||||
|
||||
#if 0
|
||||
/*********************************************
|
||||
NAND IPレジスタ
|
||||
|
||||
(R/W) : readable and writable
|
||||
(RO) : read only
|
||||
*********************************************/
|
||||
#if (CTR_DEF_ENVIRONMENT_DSEMU == 1)
|
||||
#define NAND_IP_BASE (0x08020000)
|
||||
#else
|
||||
#define NAND_IP_BASE (0x400D0000) // IOP実機設定
|
||||
#endif
|
||||
|
||||
|
||||
#define NAND_IP_CADDR (NAND_IP_BASE + 0x0000) //16bit
|
||||
#define NAND_IP_PADDR (NAND_IP_BASE + 0x0004) //24bit + dummy8bit
|
||||
#define NAND_IP_COMMAND (NAND_IP_BASE + 0x0008) //0,1,2,3
|
||||
#define NAND_IP_CTRL (NAND_IP_BASE + 0x000C) //32bit
|
||||
#define NAND_IP_ID (NAND_IP_BASE + 0x0010) //48bit
|
||||
#define NAND_IP_ID_H (NAND_IP_BASE + 0x0014)
|
||||
#define NAND_IP_STAT (NAND_IP_BASE + 0x0018) //16bit
|
||||
#define NAND_IP_ECC_0 (NAND_IP_BASE + 0x0100)
|
||||
#define NAND_IP_ECC_1 (NAND_IP_BASE + 0x0104)
|
||||
#define NAND_IP_ECC_2 (NAND_IP_BASE + 0x0108)
|
||||
#define NAND_IP_ECC_3 (NAND_IP_BASE + 0x010C)
|
||||
#define NAND_IP_SPARE (NAND_IP_BASE + 0x0400) // 64BYTE
|
||||
#define NAND_IP_DATA (NAND_IP_BASE + 0x0800) //2048BYTE
|
||||
|
||||
|
||||
|
||||
/*コマンドレジスタに入れる値の詳細値*/
|
||||
#define NAND_COM_WRITE (0x00701080) //0x70:StatRead, 0x10:AutoProgram, 0x80:DataInput
|
||||
#define NAND_COM_READ (0x00003000) //0x30:ReadStart, 0x00:ReadAdrInput
|
||||
#define NAND_COM_ERASE (0x0070D060) //0x70:StatRead, 0xD0:EraseStart, 0x60:EraseSetup
|
||||
#define NAND_COM_READID (0x00000090)
|
||||
|
||||
/*コントロールレジスタに入れる値の詳細値*/
|
||||
#define NAND_CTRL_READSTAT (0x0010) //10000b
|
||||
#define NAND_CTRL_READID (0x0011)
|
||||
#define NAND_CTRL_WRITE (0x0012)
|
||||
#define NAND_CTRL_ERASE (0x0013)
|
||||
#define NAND_CTRL_READ_SETUP (0x0014)
|
||||
#define NAND_CTRL_READ_2112 (0x000d)
|
||||
|
||||
#define NAND_CTRL_RDY_MASK ((u32)0x1<<15)
|
||||
|
||||
#define NAND_CTRL_ECC_WRITE (0)
|
||||
#define NAND_CTRL_ECC_READ ((u32)0x1<<24)
|
||||
|
||||
#define NAND_CTRL_PAGE_0 (0)
|
||||
#define NAND_CTRL_PAGE_1 ((u32)1<<25)
|
||||
#define NAND_CTRL_PAGE_MASK ((u32)1<<25)
|
||||
#define NAND_CTRL_PAGE_SHIFT (25)
|
||||
|
||||
#define NAND_CTRL_W8MHZ (0)
|
||||
#define NAND_CTRL_W11MHZ ((u32)0x1<<26)
|
||||
#define NAND_CTRL_W16MHZ ((u32)0x2<<26)
|
||||
|
||||
#define NAND_CTRL_R8MHZ (0)
|
||||
#define NAND_CTRL_R11MHZ ((u32)0x1<<28)
|
||||
|
||||
#define NAND_CTRL_START ((u32)0x1<<31)
|
||||
#define NAND_CTRL_START_MASK ((u32)0x1<<31)
|
||||
|
||||
|
||||
/**/
|
||||
#define NAND_CTRL_SPEED_LO (NAND_CTRL_W8MHZ | NAND_CTRL_R8MHZ)
|
||||
#define NAND_CTRL_SPEED_MIDDLE (NAND_CTRL_W11MHZ | NAND_CTRL_R11MHZ)
|
||||
#define NAND_CTRL_SPEED_HI (NAND_CTRL_W16MHZ | NAND_CTRL_R11MHZ)
|
||||
|
||||
|
||||
/*ステータスレジスタの詳細値*/
|
||||
#define NAND_STAT_FAIL (1) //NAND_STAT_READY状態で有効
|
||||
#define NAND_STAT_READY (1<<6) //60nm品対応
|
||||
#define NAND_STAT_NOPROTECT (1<<7)
|
||||
|
||||
|
||||
/*ID_Hレジスタに入れる値の詳細値*/
|
||||
#define NAND_ID_H_FIFTH_MASK (0x8000)
|
||||
#endif
|
||||
|
||||
#endif /*__NAND_IP_REG_H__*/
|
||||
55
trunk/bootrom/build/libraries/nand/ARM9/Makefile
Normal file
55
trunk/bootrom/build/libraries/nand/ARM9/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: CtrBrom - libraries_sp - mi
|
||||
# File: Makefile
|
||||
#
|
||||
# Copyright 2008-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$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS =
|
||||
#SUBMAKES = Makefile.CALLTRACE \
|
||||
# Makefile.FUNCTIONCOST
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# build ARM & THUMB libraries
|
||||
BROM_CODEGEN_ALL ?= TRUE
|
||||
|
||||
# Codegen for sub processer
|
||||
BROM_PROC = ARM9
|
||||
|
||||
SRCDIR = . ../common
|
||||
|
||||
SRCS = \
|
||||
mi_memory.c \
|
||||
mi_exclusive.c \
|
||||
|
||||
TARGET_LIB = libmi_sp$(BROM_LIBSUFFIX).a
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
INSTALL_TARGETS = $(TARGETS)
|
||||
INSTALL_DIR = $(BROM_INSTALL_LIBDIR)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
do-build: $(TARGETS)
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
34
trunk/bootrom/build/libraries/nand/Makefile
Normal file
34
trunk/bootrom/build/libraries/nand/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#! make -f
|
||||
#----------------------------------------------------------------------------
|
||||
# Project: CtrBrom - libraries - mi
|
||||
# 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$
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/commondefs
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
SUBDIRS = ARM11
|
||||
|
||||
#ifdef CTR_WITH_ARM9
|
||||
SUBDIRS += ARM9
|
||||
#endif
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
include $(CTRBROM_ROOT)/build/buildtools/modulerules
|
||||
|
||||
|
||||
#===== End of Makefile =====
|
||||
BIN
trunk/tools/bootrom/ne1tb/nand_deviceformat.axf
Normal file
BIN
trunk/tools/bootrom/ne1tb/nand_deviceformat.axf
Normal file
Binary file not shown.
@ -10,3 +10,6 @@ NE1
|
||||
|
||||
・"export CTR_PLATFORM=NE1EMU" または "make CTR_PLATFORM=NE1EMU" でビルドして下さい。
|
||||
・"export CTR_DEBUGGER=KMC" または "make CTR_DEBUGGER=KMC" でビルドして下さい。
|
||||
|
||||
・PARTNERを使ってNE1ボードへnand_deviceformat.axfをロードして実行すると、
|
||||
NANDがデバイスレベルでフォーマットされます(ファイルシステムのフォーマットではなく)。
|
||||
|
||||
Loading…
Reference in New Issue
Block a user