亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? nandflash.c

?? NAND Flash Boot Please select function : 0 : USB download file(通過(guò)USB下載文件) 1 : Uart download fi
?? C
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
//#include "../inc/def.h"
//#include "../inc/config.h"
//#include "../inc/utils.h"
//#include "../inc/board.h"
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"

#ifdef	NAND_FLASH_SUPPORT

struct NFChipInfo {
	U32 id;
	U32 size;
}

static NandFlashChip[] = {
	{0xec73, SIZE_16M},
	{0xec75, SIZE_32M},
	{0xec76, SIZE_64M},
	{0xec79, SIZE_128M},
	{0, 0},
};

#define	BLK_IDXL	8
#define	BLK_IDXH	9
#define	FMT_TAG		15

char format_tags[] = "Formatted For NAND FLASH Driver";	//must be less than 32
/***********************************************************/
//nand ecc utils
typedef	unsigned char u_char;
static u_char eccpos[6] = {0, 1, 2, 3, 6, 7};

/*
 * Pre-calculated 256-way 1 byte column parity
 */
static const u_char nand_ecc_precalc_table[] = {
	0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00,
	0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,
	0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,
	0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,
	0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,
	0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,
	0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,
	0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,
	0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a,
	0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f,
	0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c,
	0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69,
	0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03,
	0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66,
	0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65,
	0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00
};


/**
 * nand_trans_result - [GENERIC] create non-inverted ECC
 * @reg2:	line parity reg 2
 * @reg3:	line parity reg 3
 * @ecc_code:	ecc 
 *
 * Creates non-inverted ECC code from line parity
 */
static void nand_trans_result(u_char reg2, u_char reg3,
	u_char *ecc_code)
{
	u_char a, b, i, tmp1, tmp2;
	
	/* Initialize variables */
	a = b = 0x80;
	tmp1 = tmp2 = 0;
	
	/* Calculate first ECC byte */
	for (i = 0; i < 4; i++) {
		if (reg3 & a)		/* LP15,13,11,9 --> ecc_code[0] */
			tmp1 |= b;
		b >>= 1;
		if (reg2 & a)		/* LP14,12,10,8 --> ecc_code[0] */
			tmp1 |= b;
		b >>= 1;
		a >>= 1;
	}
	
	/* Calculate second ECC byte */
	b = 0x80;
	for (i = 0; i < 4; i++) {
		if (reg3 & a)		/* LP7,5,3,1 --> ecc_code[1] */
			tmp2 |= b;
		b >>= 1;
		if (reg2 & a)		/* LP6,4,2,0 --> ecc_code[1] */
			tmp2 |= b;
		b >>= 1;
		a >>= 1;
	}
	
	/* Store two of the ECC bytes */
	ecc_code[0] = tmp1;
	ecc_code[1] = tmp2;
}

/**
 * nand_calculate_ecc - [NAND Interface] Calculate 3 byte ECC code for 256 byte block
 * @dat:	raw data
 * @ecc_code:	buffer for ECC
 */
int nand_calculate_ecc(const u_char *dat, u_char *ecc_code)
{
	u_char idx, reg1, reg2, reg3;
	int j;
	
	/* Initialize variables */
	reg1 = reg2 = reg3 = 0;
	ecc_code[0] = ecc_code[1] = ecc_code[2] = 0;
	
	/* Build up column parity */ 
	for(j = 0; j < 256; j++) {
		
		/* Get CP0 - CP5 from table */
		idx = nand_ecc_precalc_table[dat[j]];
		reg1 ^= (idx & 0x3f);
		
		/* All bit XOR = 1 ? */
		if (idx & 0x40) {
			reg3 ^= (u_char) j;
			reg2 ^= ~((u_char) j);
		}
	}
	
	/* Create non-inverted ECC code from line parity */
	nand_trans_result(reg2, reg3, ecc_code);
	
	/* Calculate final ECC code */
	ecc_code[0] = ~ecc_code[0];
	ecc_code[1] = ~ecc_code[1];
	ecc_code[2] = ((~reg1) << 2) | 0x03;
	return 0;
}

/**
 * nand_correct_data - [NAND Interface] Detect and correct bit error(s)
 * @dat:	raw data read from the chip
 * @read_ecc:	ECC from the chip
 * @calc_ecc:	the ECC calculated from raw data
 *
 * Detect and correct a 1 bit error for 256 byte block
 */
int nand_correct_data(u_char *dat, u_char *read_ecc, u_char *calc_ecc)
{
	u_char a, b, c, d1, d2, d3, add, bit, i;
	
	/* Do error detection */ 
	d1 = calc_ecc[0] ^ read_ecc[0];
	d2 = calc_ecc[1] ^ read_ecc[1];
	d3 = calc_ecc[2] ^ read_ecc[2];
	
	if ((d1 | d2 | d3) == 0) {
		/* No errors */
		return 0;
	}
	else {
		a = (d1 ^ (d1 >> 1)) & 0x55;
		b = (d2 ^ (d2 >> 1)) & 0x55;
		c = (d3 ^ (d3 >> 1)) & 0x54;
		
		/* Found and will correct single bit error in the data */
		if ((a == 0x55) && (b == 0x55) && (c == 0x54)) {
			c = 0x80;
			add = 0;
			a = 0x80;
			for (i=0; i<4; i++) {
				if (d1 & c)
					add |= a;
				c >>= 2;
				a >>= 1;
			}
			c = 0x80;
			for (i=0; i<4; i++) {
				if (d2 & c)
					add |= a;
				c >>= 2;
				a >>= 1;
			}
			bit = 0;
			b = 0x04;
			c = 0x80;
			for (i=0; i<3; i++) {
				if (d3 & c)
					bit |= b;
				c >>= 2;
				b >>= 1;
			}
			b = 0x01;
			a = dat[add];
			a ^= (b << bit);
			dat[add] = a;
			return 1;
		}
		else {
			i = 0;
			while (d1) {
				if (d1 & 0x01)
					++i;
				d1 >>= 1;
			}
			while (d2) {
				if (d2 & 0x01)
					++i;
				d2 >>= 1;
			}
			while (d3) {
				if (d3 & 0x01)
					++i;
				d3 >>= 1;
			}
			if (i == 1) {
				/* ECC Code Error Correction */
				read_ecc[0] = calc_ecc[0];
				read_ecc[1] = calc_ecc[1];
				read_ecc[2] = calc_ecc[2];
				return 2;
			}
			else {
				/* Uncorrectable Error */
				return -1;
			}
		}
	}
	
	/* Should never happen */
	return -1;
}

/**********************************************************/

/*
struct Partition oNandPartition[] = {
	{0x00000000, 0x00030000, "boot"},
	{0x00030000, 0x001d0000, "kernel"},
	{0x00200000, 0x00600000, "rootfs"},
	{0x00800000, 0x00800000, "ext-fs1"},
	{0x01000000, 0x01000000, "ext-fs2"},
	{0x00000000, 0x00000000, 0}
};*/

extern struct Partition *pNandPart;

U32 NandFlashSize;

static U16 NandAddr;
static U16 support;

#define	NAND_DAT	0x02000000
#define	NAND_ALE	0x02000004
#define	NAND_CLE	0x02000002

#define	READCMD0	0
#define	READCMD1	1
#define	READCMD2	0x50
#define	ERASECMD0	0x60
#define	ERASECMD1	0xd0
#define	PROGCMD0	0x80
#define	PROGCMD1	0x10
#define	QUERYCMD	0x70
#define	READIDCMD	0x90

void NFChipSel(U32);
int  NFIsReady(void);
void NFWrCmd(int);
void NFWrAddr(int);
void NFWrDat(int);
U8   NFRdDat(void);

#define	NFChipEn()	NFChipSel(1)
#define	NFChipDs()	NFChipSel(0)
#define	NFIsBusy()	(!NFIsReady())

//#define	NFWrCmd(cmd)	*(volatile U8 *)NAND_CLE = (cmd)
//#define	NFWrAddr(addr)	*(volatile U8 *)NAND_ALE = (addr)
//#define	NFWrDat(dat)	*(volatile U8 *)NAND_DAT = (dat)
//#define	NFRdDat()		*(volatile U8 *)NAND_DAT

//#define	WIAT_BUSY_HARD
//#define	ER_BAD_BLK_TEST
//#define	WR_BAD_BLK_TEST

#ifdef	WIAT_BUSY_HARD
#define	NFWaitBusy()	while(NFIsBusy())
#else
static U32 NFWaitBusy(void)
{
	U8 stat;
	
	NFWrCmd(QUERYCMD);
	do {
		stat = NFRdDat();
		//printf("%x\n", stat);
	}while(!(stat&0x40));
	NFWrCmd(READCMD0);
	return stat&1;
}
#endif

static U32 NFReadID(void)
{
	U32 id, loop = 0;

	NFChipEn();
	NFWrCmd(READIDCMD);
	NFWrAddr(0);
	while(NFIsBusy()&&(loop<10000)) loop++;
	if(loop>=10000)
		return 0;
	id  = NFRdDat()<<8;
	id |= NFRdDat();
	NFChipDs();
	
	return id;
}

static U16 NFReadStat(void)
{
	U16 stat;
	
	NFChipEn();	
	NFWrCmd(QUERYCMD);
	stat = NFRdDat();	
	NFChipDs();
	
	return stat;
}

static U32 NFEraseBlock(U32 addr)
{
	U8 stat;

	addr &= ~0x1f;
		
	NFChipEn();	
	NFWrCmd(ERASECMD0);		
	NFWrAddr(addr);
	NFWrAddr(addr>>8);
	if(NandAddr)
		NFWrAddr(addr>>16);
	NFWrCmd(ERASECMD1);		
	stat = NFWaitBusy();
	NFChipDs();
	
#ifdef	ER_BAD_BLK_TEST
	if(!((addr+0xe0)&0xff)) stat = 1;	//just for test bad block
#endif
	
//	printf("Erase block 0x%08x %s\n", addr, stat?"fail":"ok");
	putch('.');
	
	return stat;
}

//addr = page address
static void NFReadPage(U32 addr, U8 *buf)
{
	U16 i;
	
	NFChipEn();
	NFWrCmd(READCMD0);
	NFWrAddr(0);
	NFWrAddr(addr);
	NFWrAddr(addr>>8);
	if(NandAddr)
		NFWrAddr(addr>>16);
//	InitEcc();
	NFWaitBusy();		
	for(i=0; i<512; i++)
		buf[i] = NFRdDat();		
	NFChipDs();
}

//addr = page address
static U32 NFWritePage(U32 addr, U8 *buf, U16 blk_idx)
{
	U16 i, stat;
//	U8 tmp[3];
	U8 ecc_code[3];
	U8 oob_info[16];
		
	for(i=0; i<sizeof(oob_info); i++)
		oob_info[i] = 0xff;
	
	nand_calculate_ecc(buf, ecc_code);
	oob_info[eccpos[0]] = ecc_code[0];
	oob_info[eccpos[1]] = ecc_code[1];
	oob_info[eccpos[2]] = ecc_code[2];
	nand_calculate_ecc(buf+256, ecc_code);
	oob_info[eccpos[3]] = ecc_code[0];
	oob_info[eccpos[4]] = ecc_code[1];
	oob_info[eccpos[5]] = ecc_code[2];
	oob_info[BLK_IDXL]  = blk_idx;
	oob_info[BLK_IDXH]  = blk_idx>>8;
	oob_info[FMT_TAG]   = format_tags[addr&0x1f];
	
	NFChipEn();
	NFWrCmd(PROGCMD0);
	NFWrAddr(0);
	NFWrAddr(addr);
	NFWrAddr(addr>>8);
	if(NandAddr)
		NFWrAddr(addr>>16);
//	InitEcc();	
	for(i=0; i<512; i++)
		NFWrDat(buf[i]);
		
	if(!addr) {
		NFWrDat('b');
		NFWrDat('o');
		NFWrDat('o');
		NFWrDat('t');		
	} else {		
		for(i=0; i<sizeof(oob_info); i++)
			NFWrDat(oob_info[i]);
	}
		
/*	tmp[0] = rNFECC0;
    tmp[1] = rNFECC1;
    tmp[2] = rNFECC2;
    	
	NFWrDat(tmp[0]);
    NFWrDat(tmp[1]);
    NFWrDat(tmp[2]);*/
    	
	NFWrCmd(PROGCMD1);
	stat = NFWaitBusy();
	NFChipDs();
	
#ifdef	WR_BAD_BLK_TEST
	if((addr&0xff)==0x17) stat = 1;	//just for test bad block
#endif
	
	if(stat)
		printf("Write nand flash 0x%x fail\n", addr);
	else {	
		U8 RdDat[512];
		
		NFReadPage(addr, RdDat);
		for(i=0; i<512; i++)
			if(RdDat[i]!=buf[i]) {
				printf("Check data at page 0x%x, offset 0x%x fail\n", addr, i);
				stat = 1;
				break;
			}
	}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线电影国产精品| 国产一区二区三区免费播放 | 经典三级视频一区| 性做久久久久久| 亚洲五码中文字幕| 亚洲一区二区三区四区中文字幕 | 亚洲制服欧美中文字幕中文字幕| 亚洲欧洲日韩在线| 亚洲精品免费播放| 亚洲高清免费视频| 日本美女一区二区| 久草中文综合在线| 国产不卡在线一区| 色综合天天天天做夜夜夜夜做| www.色综合.com| 欧美视频一区二区三区在线观看 | 欧美日韩一区视频| 91精品国产欧美一区二区成人| 欧美一区二区福利视频| 久久久三级国产网站| 国产精品大尺度| 五月天亚洲精品| 国产精品888| 色综合久久中文字幕| 欧美一区中文字幕| 中文字幕高清一区| 日日夜夜免费精品视频| 国产福利精品导航| 欧美日韩激情一区二区三区| 欧美一区二区三区视频免费播放| 国产午夜精品福利| 亚洲女性喷水在线观看一区| 麻豆国产精品一区二区三区| jizzjizzjizz欧美| 日韩一区二区三区在线| 国产精品美女久久久久av爽李琼| 亚洲主播在线播放| 丁香婷婷综合色啪| 欧美一区二区精品在线| 亚洲免费av高清| 国产在线观看一区二区| 色成年激情久久综合| 久久久久久久精| 午夜久久久影院| 国产成人丝袜美腿| 欧美一区二区三区在线观看| 亚洲人成伊人成综合网小说| 国产乱码精品一区二区三区五月婷| 欧美在线观看视频在线| 国产精品区一区二区三| 国内精品伊人久久久久av影院| 欧美综合在线视频| 1区2区3区精品视频| 国产在线精品一区二区不卡了| 欧美日本不卡视频| 亚洲美女淫视频| 成人毛片老司机大片| 久久久久一区二区三区四区| 日本 国产 欧美色综合| 欧美高清视频不卡网| 一区二区激情视频| 在线视频国产一区| 亚洲日本va在线观看| 成人av电影在线观看| 国产日产欧美一区| 国产精品538一区二区在线| 日韩欧美成人激情| 蜜桃av噜噜一区| 欧美日韩国产综合视频在线观看 | aaa亚洲精品一二三区| 精品奇米国产一区二区三区| 奇米精品一区二区三区在线观看 | 樱桃视频在线观看一区| 97精品久久久午夜一区二区三区| 中文字幕乱码一区二区免费| 风间由美一区二区三区在线观看| 国产日韩精品一区二区三区| 国产成人在线网站| 国产精品情趣视频| 色999日韩国产欧美一区二区| 亚洲欧美国产高清| 欧美日韩一区国产| 五月婷婷另类国产| 精品国产伦一区二区三区观看体验| 日韩和欧美的一区| www亚洲一区| 成人性生交大片免费看中文| 国产精品麻豆久久久| 在线观看国产一区二区| 亚洲不卡在线观看| 精品电影一区二区| 成人免费va视频| 亚洲精品国产一区二区精华液 | 蜜桃一区二区三区四区| 欧美成人vps| 国产不卡视频在线播放| 国产精品护士白丝一区av| 一本到三区不卡视频| 蜜臀av一级做a爰片久久| 国产欧美一区二区三区在线老狼| 色婷婷综合视频在线观看| 五月天久久比比资源色| 欧美一级在线视频| 成人午夜伦理影院| 亚洲乱码国产乱码精品精可以看| 欧美日韩成人综合天天影院| 国产在线国偷精品产拍免费yy| 中文字幕av不卡| 91免费视频网址| 狠狠色丁香婷综合久久| 一区二区三区精品在线观看| 日韩欧美国产1| 色94色欧美sute亚洲线路一久| 久久99久久99精品免视看婷婷| 中文字幕一区二区三区视频| 91精品国产综合久久精品| av电影在线不卡| 激情久久久久久久久久久久久久久久| 成人欧美一区二区三区| 欧美成人性战久久| 欧美性感一类影片在线播放| 国产精品99久| 久久精品国产第一区二区三区| 日韩码欧中文字| 国产日产欧美一区| 精品成人a区在线观看| 欧洲亚洲国产日韩| av一区二区三区在线| 国产精品一级片| 久久成人av少妇免费| 午夜精品爽啪视频| 一区二区三区四区在线| 国产精品灌醉下药二区| 国产亚洲精品中文字幕| 日韩午夜三级在线| 在线91免费看| 欧美精品一级二级| 欧美日韩国产精品成人| 91久久一区二区| 色综合一区二区| 91同城在线观看| 91美女片黄在线| 色噜噜狠狠一区二区三区果冻| 成人一二三区视频| 国产成人av电影在线| 国产一区二区三区最好精华液| 美国三级日本三级久久99| 日本中文在线一区| 日韩二区三区四区| 久久精品国产久精国产| 激情综合一区二区三区| 极品少妇xxxx偷拍精品少妇| 狠狠狠色丁香婷婷综合久久五月| 青青草国产精品亚洲专区无| 日本视频免费一区| 日本欧美在线看| 美洲天堂一区二卡三卡四卡视频| 蜜臀久久99精品久久久画质超高清| 天天av天天翘天天综合网| 人妖欧美一区二区| 国产一区二区在线免费观看| 激情另类小说区图片区视频区| 国产一区二区三区在线观看精品 | 日韩理论片一区二区| 亚洲欧洲国产日韩| 亚洲综合激情小说| 青青草97国产精品免费观看无弹窗版| 无吗不卡中文字幕| 国产毛片精品视频| 99久久er热在这里只有精品66| 欧美优质美女网站| 日韩美女在线视频| 中文字幕制服丝袜一区二区三区 | 欧美成人精精品一区二区频| 亚洲精品一区二区在线观看| 欧美精彩视频一区二区三区| 一区二区三区四区国产精品| 日本在线不卡视频| 成人午夜av影视| 91麻豆精品国产91久久久资源速度| 日韩久久精品一区| 亚洲视频狠狠干| 另类综合日韩欧美亚洲| 成人av资源站| 日韩视频一区在线观看| 中文字幕在线一区二区三区| 肉肉av福利一精品导航| 成人蜜臀av电影| 91精品国产综合久久香蕉的特点| 久久精品免费在线观看| 亚洲午夜久久久| 成人午夜伦理影院| 日韩欧美国产精品一区| 亚洲精品成a人| 国产精品夜夜爽| 日韩一区二区三区视频在线 | 色视频成人在线观看免| 8v天堂国产在线一区二区| 国产精品人妖ts系列视频| 蜜臀av在线播放一区二区三区|