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

📄 cmd_doc.c.svn-base

📁 u-boot loader common files, like cpu, clock, environment...etc...
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/* * Driver for Disk-On-Chip 2000 and Millennium * (c) 1999 Machine Vision Holdings, Inc. * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> * * $Id: doc2000.c,v 1.46 2001/10/02 15:05:13 dwmw2 Exp $ */#include <common.h>#include <config.h>#include <command.h>#include <malloc.h>#include <asm/io.h>#ifdef CONFIG_SHOW_BOOT_PROGRESS# include <status_led.h># define SHOW_BOOT_PROGRESS(arg)	show_boot_progress(arg)#else# define SHOW_BOOT_PROGRESS(arg)#endif#if (CONFIG_COMMANDS & CFG_CMD_DOC)#include <linux/mtd/nftl.h>#include <linux/mtd/nand.h>#include <linux/mtd/nand_ids.h>#include <linux/mtd/doc2000.h>#include <linux/mtd/nftl.h>#ifdef CFG_DOC_SUPPORT_2000#define DoC_is_2000(doc) (doc->ChipID == DOC_ChipID_Doc2k)#else#define DoC_is_2000(doc) (0)#endif#ifdef CFG_DOC_SUPPORT_MILLENNIUM#define DoC_is_Millennium(doc) (doc->ChipID == DOC_ChipID_DocMil)#else#define DoC_is_Millennium(doc) (0)#endif/* CFG_DOC_PASSIVE_PROBE:   In order to ensure that the BIOS checksum is correct at boot time, and   hence that the onboard BIOS extension gets executed, the DiskOnChip   goes into reset mode when it is read sequentially: all registers   return 0xff until the chip is woken up again by writing to the   DOCControl register.   Unfortunately, this means that the probe for the DiskOnChip is unsafe,   because one of the first things it does is write to where it thinks   the DOCControl register should be - which may well be shared memory   for another device. I've had machines which lock up when this is   attempted. Hence the possibility to do a passive probe, which will fail   to detect a chip in reset mode, but is at least guaranteed not to lock   the machine.   If you have this problem, uncomment the following line:#define CFG_DOC_PASSIVE_PROBE*/#undef	DOC_DEBUG#undef	ECC_DEBUG#undef	PSYCHO_DEBUG#undef	NFTL_DEBUGstatic struct DiskOnChip doc_dev_desc[CFG_MAX_DOC_DEVICE];/* Current DOC Device	*/static int curr_device = -1;/* ------------------------------------------------------------------------- */int do_doc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){    int rcode = 0;    switch (argc) {    case 0:    case 1:	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;    case 2:	if (strcmp(argv[1],"info") == 0) {		int i;		putc ('\n');		for (i=0; i<CFG_MAX_DOC_DEVICE; ++i) {			if(doc_dev_desc[i].ChipID == DOC_ChipID_UNKNOWN)				continue; /* list only known devices */			printf ("Device %d: ", i);			doc_print(&doc_dev_desc[i]);		}		return 0;	} else if (strcmp(argv[1],"device") == 0) {		if ((curr_device < 0) || (curr_device >= CFG_MAX_DOC_DEVICE)) {			puts ("\nno devices available\n");			return 1;		}		printf ("\nDevice %d: ", curr_device);		doc_print(&doc_dev_desc[curr_device]);		return 0;	}	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;    case 3:	if (strcmp(argv[1],"device") == 0) {		int dev = (int)simple_strtoul(argv[2], NULL, 10);		printf ("\nDevice %d: ", dev);		if (dev >= CFG_MAX_DOC_DEVICE) {			puts ("unknown device\n");			return 1;		}		doc_print(&doc_dev_desc[dev]);		/*doc_print (dev);*/		if (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN) {			return 1;		}		curr_device = dev;		puts ("... is now current device\n");		return 0;	}	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;    default:	/* at least 4 args */	if (strcmp(argv[1],"read") == 0 || strcmp(argv[1],"write") == 0) {		ulong addr = simple_strtoul(argv[2], NULL, 16);		ulong off  = simple_strtoul(argv[3], NULL, 16);		ulong size = simple_strtoul(argv[4], NULL, 16);		int cmd    = (strcmp(argv[1],"read") == 0);		int ret, total;		printf ("\nDOC %s: device %d offset %ld, size %ld ... ",			cmd ? "read" : "write", curr_device, off, size);		ret = doc_rw(doc_dev_desc + curr_device, cmd, off, size,			     &total, (u_char*)addr);		printf ("%d bytes %s: %s\n", total, cmd ? "read" : "write",			ret ? "ERROR" : "OK");		return ret;	} else if (strcmp(argv[1],"erase") == 0) {		ulong off = simple_strtoul(argv[2], NULL, 16);		ulong size = simple_strtoul(argv[3], NULL, 16);		int ret;		printf ("\nDOC erase: device %d offset %ld, size %ld ... ",			curr_device, off, size);		ret = doc_erase (doc_dev_desc + curr_device, off, size);		printf("%s\n", ret ? "ERROR" : "OK");		return ret;	} else {		printf ("Usage:\n%s\n", cmdtp->usage);		rcode = 1;	}	return rcode;    }}U_BOOT_CMD(	doc,	5,	1,	do_doc,	"doc     - Disk-On-Chip sub-system\n",	"info  - show available DOC devices\n"	"doc device [dev] - show or set current device\n"	"doc read  addr off size\n"	"doc write addr off size - read/write `size'"	" bytes starting at offset `off'\n"	"    to/from memory address `addr'\n"	"doc erase off size - erase `size' bytes of DOC from offset `off'\n");int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){	char *boot_device = NULL;	char *ep;	int dev;	ulong cnt;	ulong addr;	ulong offset = 0;	image_header_t *hdr;	int rcode = 0;	switch (argc) {	case 1:		addr = CFG_LOAD_ADDR;		boot_device = getenv ("bootdevice");		break;	case 2:		addr = simple_strtoul(argv[1], NULL, 16);		boot_device = getenv ("bootdevice");		break;	case 3:		addr = simple_strtoul(argv[1], NULL, 16);		boot_device = argv[2];		break;	case 4:		addr = simple_strtoul(argv[1], NULL, 16);		boot_device = argv[2];		offset = simple_strtoul(argv[3], NULL, 16);		break;	default:		printf ("Usage:\n%s\n", cmdtp->usage);		SHOW_BOOT_PROGRESS (-1);		return 1;	}	if (!boot_device) {		puts ("\n** No boot device **\n");		SHOW_BOOT_PROGRESS (-1);		return 1;	}	dev = simple_strtoul(boot_device, &ep, 16);	if ((dev >= CFG_MAX_DOC_DEVICE) ||	    (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN)) {		printf ("\n** Device %d not available\n", dev);		SHOW_BOOT_PROGRESS (-1);		return 1;	}	printf ("\nLoading from device %d: %s at 0x%lX (offset 0x%lX)\n",		dev, doc_dev_desc[dev].name, doc_dev_desc[dev].physadr,		offset);	if (doc_rw (doc_dev_desc + dev, 1, offset,		    SECTORSIZE, NULL, (u_char *)addr)) {		printf ("** Read error on %d\n", dev);		SHOW_BOOT_PROGRESS (-1);		return 1;	}	hdr = (image_header_t *)addr;	if (hdr->ih_magic == IH_MAGIC) {		print_image_hdr (hdr);		cnt = (hdr->ih_size + sizeof(image_header_t));		cnt -= SECTORSIZE;	} else {		puts ("\n** Bad Magic Number **\n");		SHOW_BOOT_PROGRESS (-1);		return 1;	}	if (doc_rw (doc_dev_desc + dev, 1, offset + SECTORSIZE, cnt,		    NULL, (u_char *)(addr+SECTORSIZE))) {		printf ("** Read error on %d\n", dev);		SHOW_BOOT_PROGRESS (-1);		return 1;	}	/* Loading ok, update default load address */	load_addr = addr;	/* Check if we should attempt an auto-start */	if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {		char *local_args[2];		extern int do_bootm (cmd_tbl_t *, int, int, char *[]);		local_args[0] = argv[0];		local_args[1] = NULL;		printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);		do_bootm (cmdtp, 0, 1, local_args);		rcode = 1;	}	return rcode;}U_BOOT_CMD(	docboot,	4,	1,	do_docboot,	"docboot - boot from DOC device\n",	"loadAddr dev\n");int doc_rw (struct DiskOnChip* this, int cmd,	    loff_t from, size_t len,	    size_t * retlen, u_char * buf){	int noecc, ret = 0, n, total = 0;	char eccbuf[6];	while(len) {		/* The ECC will not be calculated correctly if		   less than 512 is written or read */		noecc = (from != (from | 0x1ff) + 1) ||	(len < 0x200);		if (cmd)			ret = doc_read_ecc(this, from, len,					   &n, (u_char*)buf,					   noecc ? NULL : eccbuf);		else			ret = doc_write_ecc(this, from, len,					    &n, (u_char*)buf,					    noecc ? NULL : eccbuf);		if (ret)			break;		from  += n;		buf   += n;		total += n;		len   -= n;	}	if (retlen)		*retlen = total;	return ret;}void doc_print(struct DiskOnChip *this) {	printf("%s at 0x%lX,\n"	       "\t  %d chip%s %s, size %d MB, \n"	       "\t  total size %ld MB, sector size %ld kB\n",	       this->name, this->physadr, this->numchips,	       this->numchips>1 ? "s" : "", this->chips_name,	       1 << (this->chipshift - 20),	       this->totlen >> 20, this->erasesize >> 10);	if (this->nftl_found) {		struct NFTLrecord *nftl = &this->nftl;		unsigned long bin_size, flash_size;		bin_size = nftl->nb_boot_blocks * this->erasesize;		flash_size = (nftl->nb_blocks - nftl->nb_boot_blocks) * this->erasesize;		printf("\t  NFTL boot record:\n"		       "\t    Binary partition: size %ld%s\n"		       "\t    Flash disk partition: size %ld%s, offset 0x%lx\n",		       bin_size > (1 << 20) ? bin_size >> 20 : bin_size >> 10,		       bin_size > (1 << 20) ? "MB" : "kB",		       flash_size > (1 << 20) ? flash_size >> 20 : flash_size >> 10,		       flash_size > (1 << 20) ? "MB" : "kB", bin_size);	} else {		puts ("\t  No NFTL boot record found.\n");	}}/* ------------------------------------------------------------------------- *//* This function is needed to avoid calls of the __ashrdi3 function. */static int shr(int val, int shift) {	return val >> shift;}/* Perform the required delay cycles by reading from the appropriate register */static void DoC_Delay(struct DiskOnChip *doc, unsigned short cycles){	volatile char dummy;	int i;	for (i = 0; i < cycles; i++) {		if (DoC_is_Millennium(doc))			dummy = ReadDOC(doc->virtadr, NOP);		else			dummy = ReadDOC(doc->virtadr, DOCStatus);	}}/* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */static int _DoC_WaitReady(struct DiskOnChip *doc){	unsigned long docptr = doc->virtadr;	unsigned long start = get_timer(0);#ifdef PSYCHO_DEBUG	puts ("_DoC_WaitReady called for out-of-line wait\n");#endif	/* Out-of-line routine to wait for chip response */	while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) {#ifdef CFG_DOC_SHORT_TIMEOUT		/* it seems that after a certain time the DoC deasserts		 * the CDSN_CTRL_FR_B although it is not ready...		 * using a short timout solve this (timer increments every ms) */		if (get_timer(start) > 10) {			return DOC_ETIMEOUT;		}#else		if (get_timer(start) > 10 * 1000) {			puts ("_DoC_WaitReady timed out.\n");			return DOC_ETIMEOUT;		}#endif		udelay(1);	}	return 0;}static int DoC_WaitReady(struct DiskOnChip *doc){	unsigned long docptr = doc->virtadr;	/* This is inline, to optimise the common case, where it's ready instantly */	int ret = 0;	/* 4 read form NOP register should be issued in prior to the read from CDSNControl	   see Software Requirement 11.4 item 2. */	DoC_Delay(doc, 4);	if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B))		/* Call the out-of-line routine to wait */		ret = _DoC_WaitReady(doc);	/* issue 2 read from NOP register after reading from CDSNControl register	   see Software Requirement 11.4 item 2. */	DoC_Delay(doc, 2);	return ret;}/* DoC_Command: Send a flash command to the flash chip through the CDSN Slow IO register to   bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is   required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */static inline int DoC_Command(struct DiskOnChip *doc, unsigned char command,			      unsigned char xtraflags){	unsigned long docptr = doc->virtadr;	if (DoC_is_2000(doc))		xtraflags |= CDSN_CTRL_FLASH_IO;	/* Assert the CLE (Command Latch Enable) line to the flash chip */	WriteDOC(xtraflags | CDSN_CTRL_CLE | CDSN_CTRL_CE, docptr, CDSNControl);	DoC_Delay(doc, 4);	/* Software requirement 11.4.3 for Millennium */	if (DoC_is_Millennium(doc))		WriteDOC(command, docptr, CDSNSlowIO);	/* Send the command */	WriteDOC_(command, docptr, doc->ioreg);	/* Lower the CLE line */	WriteDOC(xtraflags | CDSN_CTRL_CE, docptr, CDSNControl);	DoC_Delay(doc, 4);	/* Software requirement 11.4.3 for Millennium */	/* Wait for the chip to respond - Software requirement 11.4.1 (extended for any command) */	return DoC_WaitReady(doc);}/* DoC_Address: Set the current address for the flash chip through the CDSN Slow IO register to   bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is   required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */static int DoC_Address(struct DiskOnChip *doc, int numbytes, unsigned long ofs,		       unsigned char xtraflags1, unsigned char xtraflags2){	unsigned long docptr;	int i;	docptr = doc->virtadr;	if (DoC_is_2000(doc))		xtraflags1 |= CDSN_CTRL_FLASH_IO;	/* Assert the ALE (Address Latch Enable) line to the flash chip */	WriteDOC(xtraflags1 | CDSN_CTRL_ALE | CDSN_CTRL_CE, docptr, CDSNControl);	DoC_Delay(doc, 4);	/* Software requirement 11.4.3 for Millennium */	/* Send the address */	/* Devices with 256-byte page are addressed as:	   Column (bits 0-7), Page (bits 8-15, 16-23, 24-31)	   * there is no device on the market with page256	   and more than 24 bits.	   Devices with 512-byte page are addressed as:	   Column (bits 0-7), Page (bits 9-16, 17-24, 25-31)	   * 25-31 is sent only if the chip support it.	   * bit 8 changes the read command to be sent	   (NAND_CMD_READ0 or NAND_CMD_READ1).	 */	if (numbytes == ADDR_COLUMN || numbytes == ADDR_COLUMN_PAGE) {		if (DoC_is_Millennium(doc))			WriteDOC(ofs & 0xff, docptr, CDSNSlowIO);		WriteDOC_(ofs & 0xff, docptr, doc->ioreg);	}	if (doc->page256) {		ofs = ofs >> 8;	} else {		ofs = ofs >> 9;	}	if (numbytes == ADDR_PAGE || numbytes == ADDR_COLUMN_PAGE) {		for (i = 0; i < doc->pageadrlen; i++, ofs = ofs >> 8) {			if (DoC_is_Millennium(doc))				WriteDOC(ofs & 0xff, docptr, CDSNSlowIO);			WriteDOC_(ofs & 0xff, docptr, doc->ioreg);		}	}	DoC_Delay(doc, 2);	/* Needed for some slow flash chips. mf. */	/* FIXME: The SlowIO's for millennium could be replaced by	   a single WritePipeTerm here. mf. */	/* Lower the ALE line */	WriteDOC(xtraflags1 | xtraflags2 | CDSN_CTRL_CE, docptr,		 CDSNControl);	DoC_Delay(doc, 4);	/* Software requirement 11.4.3 for Millennium */	/* Wait for the chip to respond - Software requirement 11.4.1 */	return DoC_WaitReady(doc);}/* Read a buffer from DoC, taking care of Millennium oddities */static void DoC_ReadBuf(struct DiskOnChip *doc, u_char * buf, int len){

⌨️ 快捷键说明

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