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

📄 intel28f128_16x2.c

📁 umon bootloader source code, support mips cpu.
💻 C
📖 第 1 页 / 共 2 页
字号:
		src1[0] = src[0];
		src1[1] = src[1];
		src1[2] = src[2];
		src1[3] = src[3];

		/* Flash program setup command */
		Write_40_to(dest);
		
		/* Write the value */
		FWrite(dest,src1);

		/* Wait for write to complete by polling RSR... */
		do {
			Write_70_to_base();
			rsr = Read_0000_from_base();
		} while (! (rsr & WSMS_H && rsr & WSMS_L));

		Write_50_to_base();		/* Clear status register */
		Write_ff_to_base();		/* Go to read-array mode */

		if (Is_Not_Equal(dest, src1)) {
			goto ewrite_again;
		}
		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 */
}

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

/* Intel28f128_16x2_lock():
 */
int
Intel28f128_16x2_lock(struct flashinfo *fdev,int snum,int operation)
{
	volatile int i;
	ulong	add, rsr;
	int		sector;

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

	if (operation == FLASH_LOCKABLE)
		return(1);

	if (operation == FLASH_LOCKQRY) {
		/* TODO: Write this */
		return(0);
	}

	/* Not applicable for this device.
	 */
	if (operation == FLASH_LOCKDWN)
		return(-1);

	/* For this device the unlock is applied to all
	 * sectors, so no need to enter the loop below.
	 */
	if (operation == FLASH_UNLOCK) {
			Write_60_to_base();
			Write_d0_to_base();

			/* Wait for unlock to complete by polling
			 * status register.
			 */
			do {
				for(i=0;i<SR_WAIT*10;i++);
				rsr = *(ulong *)add;
			} while(!(rsr & WSMS));
			for(i=0;i<SR_WAIT;i++);
			Write_ff_to_base();		/* Go to read-array mode */
		return(0);
	}

	/* Lock the requested sector(s):
	 */
	for (sector=0;sector<fdev->sectorcnt;sector++) {
		if ((snum == ALL_SECTORS) || (snum == sector)) {
			/* Issue the setup/lock command sequence
			 */
			Write_60_to(add);	
			Write_01_to(add);

			/* Wait for lock/unlock to complete by polling
			 * status register.
			 */
			do {
				for(i=0;i<SR_WAIT;i++);
				rsr = *(ulong *)add;
			} while(!(rsr & WSMS));
			Write_ff_to_base();		/* Go to read-array mode */
		}
		add += fdev->sectors[sector].size;
	}
	return(0);
}

/* EndIntel28f128_16x2_lock():
 * Function place holder to determine the end of the above function.
 */
void
EndIntel28f128_16x2_lock(void)
{
}
/* Intel28f128_16x2_type():
 * Run the AUTOSELECT algorithm to retrieve the manufacturer and
 * device id of the flash.
 */
int
Intel28f128_16x2_type(struct flashinfo *fdev)
{
	ushort	man, dev;
	ulong	id;

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

	man = (ushort)Read_0000_from_base();	/* manufacturer ID */
	dev = (ushort)Read_0001_from_base();	/* device ID */
	id = man;
	id <<= 16;
	id |= dev;

	fdev->id = id;

	/* Issue the read array command: */
	Write_ff_to_base();
	
	return((int)(fdev->id));
}

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

/**************************************************************************
 **************************************************************************
 *
 * The remainder of the code in this file can be included if the
 * target configuration is such that this 28F128 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.
 */
struct flashdesc FlashNamId[] = {
	{ INTEL28F128J,		"INTEL-28F128J" },
	{ 0, 0 },
};

/* This configuration is 2 side-by-side 28F128J devices.
 * Each device has 128 128Kbyte sectors, so since we have 2
 * in parallel, then each 32-bit sector is 256Kbytes...
 */
int	SectorSizes28F128_32[] = {
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
	0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000, 0x40000,
};


struct sectorinfo sinfo128[sizeof(SectorSizes28F128_32)/sizeof(int)];

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

	/* Based on the flash bank ID returned, load a sector count and a */
	/* sector size-information table... */
	flashtype(fbnk);
	switch(fbnk->id) {
		case INTEL28F128J:
			fbnk->sectorcnt = (sizeof(SectorSizes28F128_32)/sizeof(int));
			sizetable = SectorSizes28F128_32;
			break;
		default:
			printf("Unrecognized flashid: 0x%08lx\n",fbnk->id);
			return(-1);
			break;
	}

	/* 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 for flash sector information\n");
		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 = sizetable[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 += sizetable[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 *)Intel28f128_16x2_lock,
		(ulong *)EndIntel28f128_16x2_lock,
		FlashLockFbuf,sizeof(FlashLockFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f128_16x2_type,
		(ulong *)EndIntel28f128_16x2_type,
		FlashTypeFbuf,sizeof(FlashTypeFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f128_16x2_erase,
		(ulong *)EndIntel28f128_16x2_erase,
		FlashEraseFbuf,sizeof(FlashEraseFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f128_16x2_ewrite,
		(ulong *)EndIntel28f128_16x2_ewrite,
		FlashEwriteFbuf,sizeof(FlashEwriteFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)Intel28f128_16x2_write,
		(ulong *)EndIntel28f128_16x2_write,
		FlashWriteFbuf,sizeof(FlashWriteFbuf)) < 0)
		return(-1);

#endif

	fbnk = &FlashBank[0];
	fbnk->base = (unsigned char *)FLASH_BANK0_BASE_ADDR;
	fbnk->width = FLASH_BANK0_WIDTH;
#ifdef FLASH_COPY_TO_RAM
	fbnk->fltype = (int(*)())FlashTypeFbuf;		/* flashtype(). */
	fbnk->flerase = (int(*)())FlashEraseFbuf;	/* flasherase(). */
	fbnk->flwrite = (int(*)())FlashWriteFbuf;	/* flashwrite(). */
	fbnk->flewrite = (int(*)())FlashEwriteFbuf;	/* flashewrite(). */
	fbnk->fllock = (int(*)())FlashLockFbuf;		/* flashlock(). */
#else
	fbnk->fltype = Intel28f128_16x2_type;
	fbnk->flerase = Intel28f128_16x2_erase;
	fbnk->fllock = Intel28f128_16x2_lock;
	fbnk->flwrite = Intel28f128_16x2_write;
	fbnk->flewrite = Intel28f128_16x2_ewrite;
#endif

	snum += FlashBankInit(fbnk,snum);

	sectorProtect(FLASH_PROTECT_RANGE,1);

#ifdef FLASHRAM_BASE
	FlashRamInit(snum, FLASHRAM_SECTORCOUNT,
		&FlashBank[FLASHRAM_BANKNUM], sinfoRAM, 0);
#endif
	return(0);
}

#endif	/* SINGLE_FLASH_DEVICE */

#endif	/* INCLUDE_FLASH */

⌨️ 快捷键说明

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