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

📄 m25p64.c

📁 umon bootloader source code, support mips cpu.
💻 C
📖 第 1 页 / 共 3 页
字号:
 * Erase sector 'snum'.
 * Return 0 if success, else negative.
 */
int
STM25p64_8x1_erase(struct flashinfo *fdev,int snum)
{
	SflashWriteEn();	
    
   	SifModeRegSet(SIF_CBUS_MODE, SIF_CS_n0, SIF_CTL_SEL_8BIT, SIF_ADD_SEL_3BYTE, \
                  	SIF_WRITE, 0 /* sID */, 0 /* blen */);		
   	SifCommandSet(SIF_INSTR_SE);            
    	SifAddrSet(fdev->sectors[snum].begin);                   // Write the start address into the register.
    	//printf("erase sector %d,add 0x%x\n",snum,fdev->sectors[snum].begin);
    	SifStart();     

	return 0;
}

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

int
STM25p64_8x1_write(struct flashinfo *fdev,unsigned char *dest,unsigned char *src,long bytecnt)
{
	int addr;
	//NorFlashProg(addr, data);
	addr = dest;
	SflashProgWord(addr, (int *)src, bytecnt/4+1);
	SflashWaitTillReady();	
}

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

/* STM25p64_8x1_ewrite():
 * Erase all sectors that are part of the address space to be written,
 * then write the data to that address space.  This is basically a
 * concatenation of the above erase & write done in one step.  This is
 * necessary primarily for re-writing the bootcode; because after the boot
 * code is erased, there is nowhere to return so the re-write must be done
 * while executing out of ram also.  It is only needed in systems that are
 * executing the monitor out of the same device that is being updated.
 */
int
STM25p64_8x1_ewrite(struct flashinfo *fdev,uchar *destA,uchar *srcA,
	long bytecnt)
{
	int	    sector, i;
	void	(*reset)();
	uchar   *src, *dest;

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

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

/* STM25p64_8x1_lock():
 */

int
STM25p64_8x1_lock(struct flashinfo *fdev,int snum,int operation)
{
	int sample, bstat;

	return 0;//debug
	
	sample = FLASH_READBASE();

	if (operation == FLASH_LOCKABLE) {
		return(1);
	}
	else if (operation == FLASH_UNLOCK) {
		STRATACMD_LOCKBIT();
		STRATACMD_CONFIRM(fdev->base);
		WAIT_FOR_WSMS_READY();
		STRATACMD_READARRAY();
		WAIT_FOR_DATA(fdev->base,&sample);		
		return(0);
	}
	else if (operation == FLASH_LOCK) {
		STRATACMD_LOCKBIT();
		STRATACMD_SETLOCKCONFIRM(fdev->sectors[snum].begin);
		WAIT_FOR_WSMS_READY();
		STRATACMD_READARRAY();
		WAIT_FOR_DATA(fdev->base,&sample);		
		return(0);
	}
	else if (operation == FLASH_LOCKQRY) {
		STRATACMD_READID();
		if (fdev->id != ST_M58LW064D)
			WAIT_FOR_WSMS_READY();
		bstat = FLASH_READ_BLOCKSTATUS(fdev->sectors[snum].begin);
		STRATACMD_READARRAY();
		FLASHOP_PRINT(("bstat = 0x%lx\n",(long)bstat));
		if ((bstat & 0x0001) == 0x0001)
			return(1);
		else
			return(0);
	}
	else
		return(-1);
}

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

/* STM25p64_8x1_type():
 * Run the AUTOSELECT algorithm to retrieve the manufacturer and
 * device id of the flash.
 */
int
STM25p64_8x1_type(struct flashinfo *fdev)
{
	fdev->id = SflashReadID();
	return((int)(fdev->id));
}

/* EndSTM25p64_8x1_type():
 * Function place holder to determine the end of the above function.
 */
void
EndSTM25p64_8x1_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	FlashLockFbuf[400];
ulong	FlashTypeFbuf[400];
ulong	FlashEraseFbuf[400];
ulong	FlashWriteFbuf[400];
ulong	FlashEwriteFbuf[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[] = {
	{ ST_M25P64,			"ST-M25P64" },
	{ ST_M58LW064D,			"SGS_THOMPSON-M58LW064D" },
	{ INTEL_DT28F640J5,		"INTEL-DT28F640J5" },
	{ INTEL_DT28F128J5,		"INTEL-28F128 (half)" },
	{ 0, 0 },
};

int
FlashBankInit(struct flashinfo *fbnk,int snum)
{
	uchar	*saddr,*tmp;
	int		i, msize;
	struct	sectorinfo *sinfotbl;
	short *data = 0xa0300000;
	
	/* Based on the flash bank ID returned, load a sector count and a
	 * sector size-information table...
	 */
	flashtype(fbnk);
	switch(fbnk->id) {
		case ST_M58LW064D:
		case INTEL_28F640:
		case INTEL_DT28F640J5:
			fbnk->sectorcnt = 64;
			break;
		case INTEL_DT28F128J5:	
		case ST_M25P64:
			fbnk->sectorcnt = 128;
			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, build the sector
	 * information table as part of the flash-bank structure.  For
	 * this set of devices, all sectors are the same size (0x20000).
	 */
	saddr = fbnk->base;
	for(i=0;i<fbnk->sectorcnt;i++) {
		fbnk->sectors[i].snum = snum+i;
		fbnk->sectors[i].size = 0x10000;
		fbnk->sectors[i].begin = saddr;
		fbnk->sectors[i].end =
		    fbnk->sectors[i].begin + fbnk->sectors[i].size - 1;
		fbnk->sectors[i].protected = 0;
		saddr += 0x10000;
	}
	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 *)STM25p64_8x1_lock,
		(ulong *)EndSTM25p64_8x1_lock,
		FlashLockFbuf,sizeof(FlashLockFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)STM25p64_8x1_type,
		(ulong *)EndSTM25p64_8x1_type,
		FlashTypeFbuf,sizeof(FlashTypeFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)STM25p64_8x1_erase,
		(ulong *)EndSTM25p64_8x1_erase,
		FlashEraseFbuf,sizeof(FlashEraseFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)STM25p64_8x1_ewrite,
		(ulong *)EndSTM25p64_8x1_ewrite,
		FlashEwriteFbuf,sizeof(FlashEwriteFbuf)) < 0)
		return(-1);
	if (flashopload((ulong *)STM25p64_8x1_write,
		(ulong *)EndSTM25p64_8x1_write,
		FlashWriteFbuf,sizeof(FlashWriteFbuf)) < 0)
		return(-1);

#endif
	fbnk = &FlashBank[0];
	printf("flash init \n");
	fbnk->device_name = malloc(20);
	strcpy(fbnk->device_name, "m25p64");
	printf("get device name\n");
	//fbnk->device_name = strdup("m25p64");
	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;		/* flashelock(). */
#else
	fbnk->fltype = STM25p64_8x1_type;
	fbnk->flerase = STM25p64_8x1_erase;
	fbnk->flwrite = STM25p64_8x1_write;
	fbnk->flewrite = STM25p64_8x1_ewrite;
	fbnk->fllock = STM25p64_8x1_lock;
#endif

	snum += FlashBankInit(fbnk,snum);

	sectorProtect(FLASH_PROTECT_RANGE,1);

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

#endif	/* SINGLE_FLASH_DEVICE */

#endif
#endif

⌨️ 快捷键说明

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