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

📄 intel28f320_8x4.c

📁 umon bootloader source code, support mips cpu.
💻 C
📖 第 1 页 / 共 2 页
字号:
		/* Write the value */
		FLASH_WRITE(dest,src);

		WAIT_FOR_WSMS_READY();

		STRATACMD_READARRAY();

		WAIT_FOR_DATA(dest,src);

		dest += DEV_WIDTH;
		src += DEV_WIDTH;
	}
	
	/* Now that the re-programming of flash is complete, reset: */
	reset = RESETFUNC();
	reset();

	return(0);	/* won't get here */
}

/* EndIntel28f320_8x4_ewrite():
 * Function place holder to determine the end of the above function.
 */
void
EndIntel28f320_8x4_ewrite(void)
{}

/* Intel28f320_8x4_lock():
 */
int
Intel28f320_8x4_lock(struct flashinfo *fdev,int snum,int operation)
{
	vint i;
	int sector;
	vulong	add, bstat;

	add = (ulong)(fdev->base);

	switch(operation) {
		case FLASH_LOCKABLE:
			return(1);

		case FLASH_UNLOCK:
			STRATACMD_LOCKBIT();
			for(i=0;i<SR_WAIT;i++);
			STRATACMD_CONFIRM(add);
			WAIT_FOR_WSMS_READY();
			STRATACMD_READARRAY();
			for(i=0;i<SR_WAIT;i++);
			return(0);

		case FLASH_LOCK:
			for (sector=0;sector<fdev->sectorcnt;sector++) {
				if ((snum == ALL_SECTORS) || (snum == sector)) {
					STRATACMD_LOCKBIT();
					for(i=0;i<SR_WAIT;i++);
					STRATACMD_SETLOCKCONFIRM(add);
					WAIT_FOR_WSMS_READY();
					STRATACMD_READARRAY();
					for(i=0;i<SR_WAIT;i++);
				}
				add += fdev->sectors[sector].size;
			}
			return(0);

		case FLASH_LOCKQRY:
			STRATACMD_READID();
			bstat = FLASH_READ_BLOCKSTATUS(fdev->sectors[snum].begin);
			STRATACMD_READARRAY();
			if ((bstat & 0x01010101) == 0x01010101)
				return(1);
			else
				return(0);

		default:
			return(-1);
	}
}

/* EndIntel28f320_8x4_lock():
 * Function place holder to determine the end of the above function.
 */
void
EndIntel28f320_8x4_lock(void)
{
}
/* Intel28f320_8x4_type():
 * Run the AUTOSELECT algorithm to retrieve the manufacturer and
 * device id of the flash.
 */
int
Intel28f320_8x4_type(struct flashinfo *fdev)
{
	int		i;
	ftype	preval;

	preval = FLASH_READBASE();

	/* Issue the read configuration command: */
	STRATACMD_READID();

	fdev->id = FLASH_READ_DEVICEID();

	/* Issue the read array command: */
	STRATACMD_READARRAY();
	
	/* Wait for the original data to be readable...
	 */
	for(i=0;i<SR_WAIT;i++) {
		if (FLASH_READBASE() == preval)
			break;
	}
	return((int)(fdev->id));
}

/* EndIntel28f320_8x4_type():
 * Function place holder to determine the end of the above function.
 */
void
EndIntel28f320_8x4_type(void)
{}

/**************************************************************************
 **************************************************************************
 *
 * The remainder of the code in this file can be included if the
 * target configuration is such that this 28F640 device is the only
 * real flash device in the system that is to be visible to the monitor.
 *
 **************************************************************************
 **************************************************************************
 */
#ifdef SINGLE_FLASH_DEVICE

/* FlashXXXFbuf[]:
 * If FLASH_COPY_TO_RAM is defined then these arrays will contain the
 * flash operation functions above.  To operate on most flash devices,
 * you cannot be executing out of it (there are exceptions, but
 * in general, we do not assume the flash supports this).  The flash
 * functions are copied here, then executed through the function
 * pointers established in the flashinfo structure below.
 * One obvious requirement...  The size of each array must be at least
 * as large as the function that it will contain.
 */
#ifdef FLASH_COPY_TO_RAM
ulong	FlashTypeFbuf[400];
ulong	FlashEraseFbuf[400];
ulong	FlashWriteFbuf[400];
ulong	FlashEwriteFbuf[400];
ulong	FlashLockFbuf[400];
#endif

/* FlashNamId[]:
 * Used to correlate between the ID and a string representing the name
 * of the flash device.
 * Note that this table (and the case statement in FlashBankInit())
 * allow a 28F128 flash ID to sneak by... This is to allow a 28F128
 * device to be put in the footprint of a 28F640, but with the upper
 * half of the device inaccessible (some CSB360 boards).
 */
struct flashdesc FlashNamId[] = {
	{ DEVICE_28F320J3,	"INTEL-28F320J3" },
	{ DEVICE_28F640J3,	"INTEL-28F640J3" },
	{ DEVICE_28F128J3,	"INTEL-28F128J3" },
	{ 0, 0 },
};

/* Sector size configuration:
 */
int	SectorSizes28f320_8x4[] = {
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
	0x80000, 	0x80000,	0x80000,	0x80000,
};

struct sectorinfo sinfo640[sizeof(SectorSizes28f320_8x4)/sizeof(int)];

int
FlashBankInit(struct flashinfo *fbnk,int snum)
{
	uchar	*saddr;
	int		i, msize;
	struct	sectorinfo *sinfotbl;

	/* Create the per-sector information table.  The size of the table */
	/* depends on the number of sectors in the device...  */
	if (fbnk->sectors)
		free((char *)fbnk->sectors);
	msize = fbnk->sectorcnt * (sizeof(struct sectorinfo));
	sinfotbl = (struct sectorinfo *)malloc(msize);
	if (!sinfotbl) {
		printf("Can't allocate space (%d bytes) for flash sector info\n",msize);
		return(-1);
	}
	fbnk->sectors = sinfotbl;

	/* Using the above-determined sector count and size table, build */
	/* the sector information table as part of the flash-bank structure: */
	saddr = fbnk->base;
	for(i=0;i<fbnk->sectorcnt;i++) {
		fbnk->sectors[i].snum = snum+i;
		fbnk->sectors[i].size = SectorSizes28f320_8x4[i];
		fbnk->sectors[i].begin = saddr;
		fbnk->sectors[i].end =
		    fbnk->sectors[i].begin + fbnk->sectors[i].size - 1;
		fbnk->sectors[i].protected = 0;
		saddr += SectorSizes28f320_8x4[i];
	}
	fbnk->end = saddr-1;
	return(fbnk->sectorcnt);
}

/* FlashInit():
 * Initialize data structures for each bank of flash...
 */
int
FlashInit(void)
{
	int		snum;
	struct	flashinfo *fbnk;

	snum = 0;
	FlashCurrentBank = 0;

#ifdef FLASH_COPY_TO_RAM

	/* Copy functions to ram space... */
	/* Note that this MUST be done when cache is disabled to assure that */
	/* the RAM is occupied by the designated block of code. */

	if (flashopload((ulong *)Intel28f320_8x4_lock,
		(ulong *)EndIntel28f320_8x4_lock,
		FlashLockFbuf,sizeof(FlashLockFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f320_8x4_type,
		(ulong *)EndIntel28f320_8x4_type,
		FlashTypeFbuf,sizeof(FlashTypeFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f320_8x4_erase,
		(ulong *)EndIntel28f320_8x4_erase,
		FlashEraseFbuf,sizeof(FlashEraseFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f320_8x4_ewrite,
		(ulong *)EndIntel28f320_8x4_ewrite,
		FlashEwriteFbuf,sizeof(FlashEwriteFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f320_8x4_write,
		(ulong *)EndIntel28f320_8x4_write,
		FlashWriteFbuf,sizeof(FlashWriteFbuf)) < 0)
		return(-1);

#endif

	fbnk = &FlashBank[0];
	fbnk->base = (unsigned char *)FLASH_BANK0_BASE_ADDR;
	fbnk->id = DEVICE_28F320J3;
	fbnk->width = FLASH_BANK0_WIDTH;
	fbnk->sectorcnt = (sizeof(SectorSizes28f320_8x4)/sizeof(int));
#ifdef FLASH_COPY_TO_RAM
	fbnk->fltype = (int(*)())FlashTypeFbuf;	
	fbnk->flerase = (int(*)())FlashEraseFbuf;
	fbnk->flwrite = (int(*)())FlashWriteFbuf;
	fbnk->flewrite = (int(*)())FlashEwriteFbuf;
	fbnk->fllock = (int(*)())FlashLockFbuf;	
#else
	fbnk->fltype = Intel28f320_8x4_type;
	fbnk->flerase = Intel28f320_8x4_erase;
	fbnk->flwrite = Intel28f320_8x4_write;
	fbnk->flewrite = Intel28f320_8x4_ewrite;
	fbnk->fllock = Intel28f320_8x4_lock;
#endif

	snum += FlashBankInit(fbnk,snum);

	sectorProtect(FLASH_PROTECT_RANGE,1);

	return(0);
}

#endif	/* SINGLE_FLASH_DEVICE */

#endif	/* INCLUDE_FLASH */

⌨️ 快捷键说明

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