⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmd_doc.c

📁 F:worksip2440a board可启动u-boot-like.tar.gz F:worksip2440a board可启动u-boot-like.tar.gz
💻 C
📖 第 1 页 / 共 3 页
字号:
			i = ReadDOC(docptr, ECCConf);		} else {			dummy = ReadDOC(docptr, 2k_ECCStatus);			dummy = ReadDOC(docptr, 2k_ECCStatus);			i = ReadDOC(docptr, 2k_ECCStatus);		}		/* Check the ECC Status */		if (i & 0x80) {			int nb_errors;			/* There was an ECC error */#ifdef ECC_DEBUG			printf("DiskOnChip ECC Error: Read at %lx\n", (long)from);#endif			/* Read the ECC syndrom through the DiskOnChip ECC logic.			   These syndrome will be all ZERO when there is no error */			for (i = 0; i < 6; i++) {				syndrome[i] =				    ReadDOC(docptr, ECCSyndrome0 + i);			}			nb_errors = doc_decode_ecc(buf, syndrome);#ifdef ECC_DEBUG			printf("Errors corrected: %x\n", nb_errors);#endif			if (nb_errors < 0) {				/* We return error, but have actually done the read. Not that				   this can be told to user-space, via sys_read(), but at least				   MTD-aware stuff can know about it by checking *retlen */				printf("ECC Errors at %lx\n", (long)from);				ret = DOC_EECC;			}		}#ifdef PSYCHO_DEBUG		printf("ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",			     (long)from, eccbuf[0], eccbuf[1], eccbuf[2],			     eccbuf[3], eccbuf[4], eccbuf[5]);#endif		/* disable the ECC engine */		WriteDOC(DOC_ECC_DIS, docptr , ECCConf);	}	/* according to 11.4.1, we need to wait for the busy line	 * drop if we read to the end of the page.  */	if(0 == ((from + *retlen) & 0x1ff))	{	    DoC_WaitReady(this);	}	return ret;}int doc_write_ecc(struct DiskOnChip* this, loff_t to, size_t len,		  size_t * retlen, const u_char * buf,		  u_char * eccbuf){	int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */	unsigned long docptr;	volatile char dummy;	int len256 = 0;	struct Nand *mychip;	docptr = this->virtadr;	/* Don't allow write past end of device */	if (to >= this->totlen) {		puts ("Out of flash\n");		return DOC_EINVAL;	}	/* Don't allow a single write to cross a 512-byte block boundary */	if (to + len > ((to | 0x1ff) + 1))		len = ((to | 0x1ff) + 1) - to;	/* The ECC will not be calculated correctly if less than 512 is written */	if (len != 0x200 && eccbuf)		printf("ECC needs a full sector write (adr: %lx size %lx)\n",		       (long) to, (long) len);	/* printf("DoC_Write (adr: %lx size %lx)\n", (long) to, (long) len); */	/* Find the chip which is to be used and select it */	mychip = &this->chips[shr(to, this->chipshift)];	if (this->curfloor != mychip->floor) {		DoC_SelectFloor(this, mychip->floor);		DoC_SelectChip(this, mychip->chip);	} else if (this->curchip != mychip->chip) {		DoC_SelectChip(this, mychip->chip);	}	this->curfloor = mychip->floor;	this->curchip = mychip->chip;	/* Set device to main plane of flash */	DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP);	DoC_Command(this,		    (!this->page256		     && (to & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0,		    CDSN_CTRL_WP);	DoC_Command(this, NAND_CMD_SEQIN, 0);	DoC_Address(this, ADDR_COLUMN_PAGE, to, 0, CDSN_CTRL_ECC_IO);	if (eccbuf) {		/* Prime the ECC engine */		WriteDOC(DOC_ECC_RESET, docptr, ECCConf);		WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf);	} else {		/* disable the ECC engine */		WriteDOC(DOC_ECC_RESET, docptr, ECCConf);		WriteDOC(DOC_ECC_DIS, docptr, ECCConf);	}	/* treat crossing 256-byte sector for 2M x 8bits devices */	if (this->page256 && to + len > (to | 0xff) + 1) {		len256 = (to | 0xff) + 1 - to;		DoC_WriteBuf(this, buf, len256);		DoC_Command(this, NAND_CMD_PAGEPROG, 0);		DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);		/* There's an implicit DoC_WaitReady() in DoC_Command */		dummy = ReadDOC(docptr, CDSNSlowIO);		DoC_Delay(this, 2);		if (ReadDOC_(docptr, this->ioreg) & 1) {			puts ("Error programming flash\n");			/* Error in programming */			*retlen = 0;			return DOC_EIO;		}		DoC_Command(this, NAND_CMD_SEQIN, 0);		DoC_Address(this, ADDR_COLUMN_PAGE, to + len256, 0,			    CDSN_CTRL_ECC_IO);	}	DoC_WriteBuf(this, &buf[len256], len - len256);	if (eccbuf) {		WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_CE, docptr,			 CDSNControl);		if (DoC_is_Millennium(this)) {			WriteDOC(0, docptr, NOP);			WriteDOC(0, docptr, NOP);			WriteDOC(0, docptr, NOP);		} else {			WriteDOC_(0, docptr, this->ioreg);			WriteDOC_(0, docptr, this->ioreg);			WriteDOC_(0, docptr, this->ioreg);		}		/* Read the ECC data through the DiskOnChip ECC logic */		for (di = 0; di < 6; di++) {			eccbuf[di] = ReadDOC(docptr, ECCSyndrome0 + di);		}		/* Reset the ECC engine */		WriteDOC(DOC_ECC_DIS, docptr, ECCConf);#ifdef PSYCHO_DEBUG		printf		    ("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",		     (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3],		     eccbuf[4], eccbuf[5]);#endif	}	DoC_Command(this, NAND_CMD_PAGEPROG, 0);	DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);	/* There's an implicit DoC_WaitReady() in DoC_Command */	dummy = ReadDOC(docptr, CDSNSlowIO);	DoC_Delay(this, 2);	if (ReadDOC_(docptr, this->ioreg) & 1) {		puts ("Error programming flash\n");		/* Error in programming */		*retlen = 0;		return DOC_EIO;	}	/* Let the caller know we completed it */	*retlen = len;	if (eccbuf) {		unsigned char x[8];		size_t dummy;		int ret;		/* Write the ECC data to flash */		for (di=0; di<6; di++)			x[di] = eccbuf[di];		x[6]=0x55;		x[7]=0x55;		ret = doc_write_oob(this, to, 8, &dummy, x);		return ret;	}	return 0;}int doc_read_oob(struct DiskOnChip* this, loff_t ofs, size_t len,		 size_t * retlen, u_char * buf){	int len256 = 0, ret;	unsigned long docptr;	struct Nand *mychip;	docptr = this->virtadr;	mychip = &this->chips[shr(ofs, this->chipshift)];	if (this->curfloor != mychip->floor) {		DoC_SelectFloor(this, mychip->floor);		DoC_SelectChip(this, mychip->chip);	} else if (this->curchip != mychip->chip) {		DoC_SelectChip(this, mychip->chip);	}	this->curfloor = mychip->floor;	this->curchip = mychip->chip;	/* update address for 2M x 8bit devices. OOB starts on the second */	/* page to maintain compatibility with doc_read_ecc. */	if (this->page256) {		if (!(ofs & 0x8))			ofs += 0x100;		else			ofs -= 0x8;	}	DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);	DoC_Address(this, ADDR_COLUMN_PAGE, ofs, CDSN_CTRL_WP, 0);	/* treat crossing 8-byte OOB data for 2M x 8bit devices */	/* Note: datasheet says it should automaticaly wrap to the */	/*       next OOB block, but it didn't work here. mf.      */	if (this->page256 && ofs + len > (ofs | 0x7) + 1) {		len256 = (ofs | 0x7) + 1 - ofs;		DoC_ReadBuf(this, buf, len256);		DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);		DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff),			    CDSN_CTRL_WP, 0);	}	DoC_ReadBuf(this, &buf[len256], len - len256);	*retlen = len;	/* Reading the full OOB data drops us off of the end of the page,	 * causing the flash device to go into busy mode, so we need	 * to wait until ready 11.4.1 and Toshiba TC58256FT docs */	ret = DoC_WaitReady(this);	return ret;}int doc_write_oob(struct DiskOnChip* this, loff_t ofs, size_t len,		  size_t * retlen, const u_char * buf){	int len256 = 0;	unsigned long docptr = this->virtadr;	struct Nand *mychip = &this->chips[shr(ofs, this->chipshift)];	volatile int dummy;#ifdef PSYCHO_DEBUG	printf("doc_write_oob(%lx, %d): %2.2X %2.2X %2.2X %2.2X ... %2.2X %2.2X .. %2.2X %2.2X\n",	       (long)ofs, len, buf[0], buf[1], buf[2], buf[3],	       buf[8], buf[9], buf[14],buf[15]);#endif	/* Find the chip which is to be used and select it */	if (this->curfloor != mychip->floor) {		DoC_SelectFloor(this, mychip->floor);		DoC_SelectChip(this, mychip->chip);	} else if (this->curchip != mychip->chip) {		DoC_SelectChip(this, mychip->chip);	}	this->curfloor = mychip->floor;	this->curchip = mychip->chip;	/* disable the ECC engine */	WriteDOC (DOC_ECC_RESET, docptr, ECCConf);	WriteDOC (DOC_ECC_DIS, docptr, ECCConf);	/* Reset the chip, see Software Requirement 11.4 item 1. */	DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP);	/* issue the Read2 command to set the pointer to the Spare Data Area. */	DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP);	/* update address for 2M x 8bit devices. OOB starts on the second */	/* page to maintain compatibility with doc_read_ecc. */	if (this->page256) {		if (!(ofs & 0x8))			ofs += 0x100;		else			ofs -= 0x8;	}	/* issue the Serial Data In command to initial the Page Program process */	DoC_Command(this, NAND_CMD_SEQIN, 0);	DoC_Address(this, ADDR_COLUMN_PAGE, ofs, 0, 0);	/* treat crossing 8-byte OOB data for 2M x 8bit devices */	/* Note: datasheet says it should automaticaly wrap to the */	/*       next OOB block, but it didn't work here. mf.      */	if (this->page256 && ofs + len > (ofs | 0x7) + 1) {		len256 = (ofs | 0x7) + 1 - ofs;		DoC_WriteBuf(this, buf, len256);		DoC_Command(this, NAND_CMD_PAGEPROG, 0);		DoC_Command(this, NAND_CMD_STATUS, 0);		/* DoC_WaitReady() is implicit in DoC_Command */		dummy = ReadDOC(docptr, CDSNSlowIO);		DoC_Delay(this, 2);		if (ReadDOC_(docptr, this->ioreg) & 1) {			puts ("Error programming oob data\n");			/* There was an error */			*retlen = 0;			return DOC_EIO;		}		DoC_Command(this, NAND_CMD_SEQIN, 0);		DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff), 0, 0);	}	DoC_WriteBuf(this, &buf[len256], len - len256);	DoC_Command(this, NAND_CMD_PAGEPROG, 0);	DoC_Command(this, NAND_CMD_STATUS, 0);	/* DoC_WaitReady() is implicit in DoC_Command */	dummy = ReadDOC(docptr, CDSNSlowIO);	DoC_Delay(this, 2);	if (ReadDOC_(docptr, this->ioreg) & 1) {		puts ("Error programming oob data\n");		/* There was an error */		*retlen = 0;		return DOC_EIO;	}	*retlen = len;	return 0;}int doc_erase(struct DiskOnChip* this, loff_t ofs, size_t len){	volatile int dummy;	unsigned long docptr;	struct Nand *mychip;	if (ofs & (this->erasesize-1) || len & (this->erasesize-1)) {		puts ("Offset and size must be sector aligned\n");		return DOC_EINVAL;	}	docptr = this->virtadr;	/* FIXME: Do this in the background. Use timers or schedule_task() */	while(len) {		mychip = &this->chips[shr(ofs, this->chipshift)];		if (this->curfloor != mychip->floor) {			DoC_SelectFloor(this, mychip->floor);			DoC_SelectChip(this, mychip->chip);		} else if (this->curchip != mychip->chip) {			DoC_SelectChip(this, mychip->chip);		}		this->curfloor = mychip->floor;		this->curchip = mychip->chip;		DoC_Command(this, NAND_CMD_ERASE1, 0);		DoC_Address(this, ADDR_PAGE, ofs, 0, 0);		DoC_Command(this, NAND_CMD_ERASE2, 0);		DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP);		dummy = ReadDOC(docptr, CDSNSlowIO);		DoC_Delay(this, 2);		if (ReadDOC_(docptr, this->ioreg) & 1) {			printf("Error erasing at 0x%lx\n", (long)ofs);			/* There was an error */			goto callback;		}		ofs += this->erasesize;		len -= this->erasesize;	} callback:	return 0;}static inline int doccheck(unsigned long potential, unsigned long physadr){	unsigned long window=potential;	unsigned char tmp, ChipID;#ifndef DOC_PASSIVE_PROBE	unsigned char tmp2;#endif	/* Routine copied from the Linux DOC driver */#ifdef CFG_DOCPROBE_55AA	/* Check for 0x55 0xAA signature at beginning of window,	   this is no longer true once we remove the IPL (for Millennium */	if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)		return 0;#endif /* CFG_DOCPROBE_55AA */#ifndef DOC_PASSIVE_PROBE	/* It's not possible to cleanly detect the DiskOnChip - the	 * bootup procedure will put the device into reset mode, and	 * it's not possible to talk to it without actually writing	 * to the DOCControl register. So we store the current contents	 * of the DOCControl register's location, in case we later decide	 * that it's not a DiskOnChip, and want to put it back how we	 * found it.	 */	tmp2 = ReadDOC(window, DOCControl);	/* Reset the DiskOnChip ASIC */	WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,		 window, DOCControl);	WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,		 window, DOCControl);	/* Enable the DiskOnChip ASIC */	WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,		 window, DOCControl);	WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,		 window, DOCControl);#endif /* !DOC_PASSIVE_PROBE */	ChipID = ReadDOC(window, ChipID);	switch (ChipID) {	case DOC_ChipID_Doc2k:		/* Check the TOGGLE bit in the ECC register */		tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;		if ((ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT) != tmp)				return ChipID;		break;	case DOC_ChipID_DocMil:		/* Check the TOGGLE bit in the ECC register */		tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;		if ((ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT) != tmp)				return ChipID;		break;	default:#ifndef CFG_DOCPROBE_55AA/* * if the ID isn't the DoC2000 or DoCMillenium ID, so we can assume * the DOC is missing */# if 0		printf("Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",		       ChipID, physadr);# endif#endif#ifndef DOC_PASSIVE_PROBE		/* Put back the contents of the DOCControl register, in case it's not		 * actually a DiskOnChip.		 */		WriteDOC(tmp2, window, DOCControl);#endif		return 0;	}	puts ("DiskOnChip failed TOGGLE test, dropping.\n");#ifndef DOC_PASSIVE_PROBE	/* Put back the contents of the DOCControl register: it's not a DiskOnChip */	WriteDOC(tmp2, window, DOCControl);#endif	return 0;}void doc_probe(unsigned long physadr){	struct DiskOnChip *this = NULL;	int i=0, ChipID;	if ((ChipID = doccheck(physadr, physadr))) {		for (i=0; i<CFG_MAX_DOC_DEVICE; i++) {			if (doc_dev_desc[i].ChipID == DOC_ChipID_UNKNOWN) {				this = doc_dev_desc + i;				break;			}		}		if (!this) {			puts ("Cannot allocate memory for data structures.\n");			return;		}		if (curr_device == -1)			curr_device = i;		memset((char *)this, 0, sizeof(struct DiskOnChip));		this->virtadr = physadr;		this->physadr = physadr;		this->ChipID = ChipID;		DoC2k_init(this);	} else {		puts ("No DiskOnChip found\n");	}}#endif /* (CONFIG_COMMANDS & CFG_CMD_DOC) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -