/*******************************************************************************
* flashIsSecErased - Check if a given Sector is erased.
*
* DESCRIPTION:
*	Go over the sector and check if its entire data is 0xFF.
* INPUT:
*       secNum	- sector Number.
*	pFlash	- flash information.
*
* OUTPUT:
*	None
*
* RETURN:
*	MV_BAD_PARAM if one of the inputs values is illegal,
*	MV_TRUE if sector is already erased,
*	MV_FALSE otherwise.
*
*******************************************************************************/
MV_BOOL flashIsSecErased(MV_FLASH_INFO *pFlash, MV_U32 secNum)
{
	MV_U32 i;

	DB(mvOsPrintf("Flash: flashIsSecErased. \n"));
	if((NULL == pFlash) || (secNum >= mvFlashNumOfSecsGet(pFlash)) )
		return MV_BAD_PARAM;

	/* reset the flash */
	flashReset(pFlash);

	/* go over the sector */
	for(i = mvFlashSecOffsGet(pFlash,secNum); 
		i < mvFlashSecOffsGet(pFlash,secNum) + mvFlashSecSizeGet(pFlash,secNum);
		i+= 4)
	{
		if(mvFlash32Rd(pFlash,i) != FLASH_WR_ERASED )
		{
			DB(mvOsPrintf("Flash: Not erased addr %x is %x \n",
											i ,mvFlash32Rd(pFlash,i)));
			return MV_FALSE;
		}
	}
	return MV_TRUE;
}
Example #2
0
void reset()
{
	eepromReset(game.getEEPROMSize());
	flashReset(game.getFlashSize());

	rtcReset();
	rtcEnable(game.hasRTC());
}
Example #3
0
STATUS flashLibInit (void)
{
	int i;

	PRINTF ("flashLibInit: devices=%d\n", flashDevCount);

	for (i = 0; i < flashDevCount; i++) {
		flash_dev_t *dev = &flashDev[i];

		/*
		 * For bank 1, probe both without and with byte swappage,
		 * so that this module works on both old and new Mousse boards.
		 */

		flashReset (dev);

		if (flashProbe (dev) != ERROR)
			dev->found = 1;

		flashReset (dev);

		if (flashProbe (dev) != ERROR)
			dev->found = 1;

		dev->swap = 0;

		if (dev->found) {
			PRINTF ("\n  FLASH %s[%d]: iobase=0x%x - %d sectors %d KB",
				flashDev[i].name, i, flashDev[i].base,
				flashDev[i].sectors,
				(flashDev[i].sectors * FLASH_SECTOR_SIZE) / 1024);

		}
	}

	flashLibInited = 1;

	PRINTF ("flashLibInit: done\n");

	return OK;
}
Example #4
0
/*******************************************************************************
* mvFlashInit - Initialize a flash descriptor structure.
*
* DESCRIPTION:
*       This function intialize flash info struct with specified flash 
*       parameters. This structure is used to identify the target flash the 
*       function refers to. This allow the use of the same API for multiple
*       flash devices.
*       
*
* INPUT:
*       pFlash->baseAddr - Flash base address.
*       pFlash->busWidth - Flash bus width (8, 16, 32 bit).
*       pFlash->devWidth - Flash device width (8 or 16 bit).
*
* OUTPUT:
*       pFlash - Flash identifier structure.
*
* RETURN:
*       32bit describing flash size. 
*       In case of any error, it returns 0.
*
*******************************************************************************/
MV_U32 mvFlashInit(MV_FLASH_INFO *pFlash)
{
	MV_U32 manu = 0, id = 0;

	if(NULL == pFlash)
		return 0;
		
	DB(mvOsPrintf("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));

	/* must init first sector base, before calling flashCmdSet */
	pFlash->sector[0].baseOffs = 0;
	/* reset flash 0xf0(AMD) 0xff (Intel) */
	flashCmdSet(pFlash, 0, 0, 0xf0);
	flashCmdSet(pFlash, 0, 0, 0xff);

	/* Write auto select command: read Manufacturer ID 	*/
	/* AMD seq is: 0x555 0xAA -> 0x2AA 0x55 -> 0x555 0x90 	*/
	/* INTEL seq is dc 0x90					*/
	flashCmdSet(pFlash, 0x555, 0, 0xAA);
	flashCmdSet(pFlash, 0x2AA, 0, 0x55);
	flashCmdSet(pFlash, 0x555, 0, 0x90); 

	/* get flash Manufactor and Id */
	manu = flashBusWidthRd(pFlash, mvFlashBaseAddrGet(pFlash));
	id = flashBusWidthRd(pFlash, flashAddrExt(pFlash, 1, 0));

	/* check if this flash is Supported, and Init the pFlash flash feild */	
	if( MV_OK != flashStructGet(pFlash, manu, id ) )
	{
		mvOsPrintf("%s: Flash ISN'T supported: manufactor-0x%x, id-0x%x\n",
                    __FUNCTION__, manu, id);
		return 0;
	}

	/* Init pFlash sectors */	
	if(MV_OK != flashSecsInit(pFlash))
	{
		mvOsPrintf("Flash: ERROR mvFlashInit flashSecsInit failed \n");
		return 0;
	}
	

	/* print all flash information */
	DB(flashPrint(pFlash));

	/* reset the Flash */
	flashReset(pFlash);

	return mvFlashSizeGet(pFlash);
}
/*******************************************************************************
* mvFlashSecErase - Erase a flash sector.
*
* DESCRIPTION:
*       This function checks if the sector isn't protected and if the sector
*		isn't already erased.
*
* INPUT:
*       pFlash    - Flash identifier structure.
*       sectorNum - secrot number to erase.
*
* OUTPUT:
*       None.
*
* RETURN:
*	MV_BAD_PARAM if one of the inputs values is illegal,
*       MV_OK if erased completed successfully,
*	MV_FAIL otherwise (e.g. sector protected).
*
*******************************************************************************/
MV_STATUS mvFlashSecErase(MV_FLASH_INFO *pFlash, MV_U32 sectorNum)
{
	MV_U32 status;
	DB(mvOsPrintf("Flash: mvFlashSecErase \n"));

	/* check parametrs values */
	if((NULL == pFlash) || (sectorNum >= mvFlashNumOfSecsGet(pFlash)) ) {
		return MV_BAD_PARAM;
	}

	/* check if sector is locked */
	if(MV_TRUE == mvFlashSecLockGet(pFlash, sectorNum))
	{
		mvOsPrintf("Flash: ERROR mvFlashSecErase protected sector.\n");
		return MV_FAIL;
	}
	/* check if already erased */
	if(MV_TRUE == flashIsSecErased(pFlash,sectorNum))
	{
		DB(mvOsPrintf("Flash: FlashSecErase sector already erased \n"));
		return MV_OK;
	}

	/* erase sector using the Flash Ven Alg. */
	switch(mvFlashVenIdGet(pFlash))
	{
		case INTEL_MANUF: /* INTEL/MT */
			status = intelFlashSecErase(pFlash,sectorNum);
			break;
		case AMD_MANUF:
		case STM_MANUF:
		case SST_MANUF:			
			status = amdFlashSecErase(pFlash,sectorNum);
			break;
		default:
			mvOsPrintf("Flash: ERROR mvFlashErase. unsupported flash vendor\n");
			return MV_FAIL;
	}	
	/* reset the flash */
	flashReset(pFlash);

	return status;
}
/*******************************************************************************
* mvFlashInit - Initialize a flash descriptor structure.
*
* DESCRIPTION:
*       This function intialize flash info struct with specified flash 
*       parameters. This structure is used to identify the target flash the 
*       function refers to. This allow the use of the same API for multiple
*       flash devices.
*       
*
* INPUT:
*       pFlash->baseAddr - Flash base address.
*       pFlash->busWidth - Flash bus width (8, 16, 32 bit).
*       pFlash->devWidth - Flash device width (8 or 16 bit).
*
* OUTPUT:
*       pFlash - Flash identifier structure.
*
* RETURN:
*       32bit describing flash size. 
*       In case of any error, it returns 0.
*
*******************************************************************************/
MV_U32 mvFlashInit(MV_FLASH_INFO *pFlash)
{
	MV_U32 manu = 0, id = 0;

	if(NULL == pFlash)
		return 0;
		
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));

	/* must init first sector base, before calling flashCmdSet */
	pFlash->sector[0].baseOffs = 0;
	/* reset flash 0xf0(AMD) 0xff (Intel) */
	flashCmdSet(pFlash, 0, 0, 0xf0);
	flashCmdSet(pFlash, 0, 0, 0xff);

	/* Write auto select command: read Manufacturer ID 	*/
	/* AMD seq is: 0x555 0xAA -> 0x2AA 0x55 -> 0x555 0x90 	*/
	/* INTEL seq is dc 0x90					*/
	flashCmdSet(pFlash, 0x555, 0, 0xAA);
	flashCmdSet(pFlash, 0x2AA, 0, 0x55);
	flashCmdSet(pFlash, 0x555, 0, 0x90); 


	/* Write auto select command: read Manufacturer ID 	*/
	/* SST seq is: 0x5555 0xAA -> 0x2AAA 0x55 -> 0x5555 0x90 	*/
	flashCmdSet(pFlash, 0x5555, 0, 0xAA);
	flashCmdSet(pFlash, 0x2AAA, 0, 0x55);
	flashCmdSet(pFlash, 0x5555, 0, 0x90); 

	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	/* get flash Manufactor and Id */
	manu = flashBusWidthRd(pFlash, mvFlashBaseAddrGet(pFlash));
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	/* Some Micron flashes don't use A0 address for Identifier and 
	Lock information, so in order to read Identifier and lock information
	properly we will do the following workarround:
	If our device width is 1 (x8) then if address 0 equal to address 1
	and address 2 equal to address 3 ,then we have this case (A0 is not used)
	and then we will issue the address without A0 to read the Identifier and
	lock information properly*/
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	if ((pFlash->devWidth == 1) && 
		  ((flashBusWidthRd(pFlash, flashAddrExt(pFlash, 0, 0)) == 
			flashBusWidthRd(pFlash, flashAddrExt(pFlash, 1, 0)))&&
		   (flashBusWidthRd(pFlash, flashAddrExt(pFlash, 2, 0)) == 
			flashBusWidthRd(pFlash, flashAddrExt(pFlash, 3, 0)))))
		{
			id = flashBusWidthRd(pFlash, flashAddrExt(pFlash, 2, 0));

		} else id = flashBusWidthRd(pFlash, flashAddrExt(pFlash, 1, 0));


	/* check if this flash is Supported, and Init the pFlash flash feild */	
	if( MV_OK != flashStructGet(pFlash, manu, id ) )
	{
		mvOsPrintf("%s: Flash ISN'T supported: manufactor-0x%x, id-0x%x\n",
                    __FUNCTION__, manu, id);
		return 0;
	}
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	/* Init pFlash sectors */	
	if(MV_OK != flashSecsInit(pFlash))
	{
		mvOsPrintf("Flash: ERROR mvFlashInit flashSecsInit failed \n");
		return 0;
	}
	
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	/* print all flash information */
	DB(flashPrint(pFlash));

	/* reset the Flash */
	flashReset(pFlash);
	DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n",
						pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth));


	return mvFlashSizeGet(pFlash);
}
Example #7
0
PRIVATE int flashWait (flash_dev_t * dev, int addr, int expect, int erase)
{
	int rv = ERROR;
	int i, data;
	int polls;

#if 0
	PRINTF ("flashWait: dev=%d addr=0x%x expect=0x%x erase=%d\n",
		DEV_NO (dev), addr, expect, erase);
#endif

	if (dev->bank != FLASH0_BANK) {
		rv = ERROR;
		goto done;
	}

	if (erase)
		polls = FLASH_ERASE_SECTOR_TIMEOUT;	/* Ticks */
	else
		polls = FLASH_PROGRAM_POLLS;	/* Loops */

	for (i = 0; i < polls; i++) {
		if (erase)
			udelay (SLEEP_DELAY);

		data = FLASH0_READ (dev, addr);

		if (((data ^ expect) & 0x80) == 0) {
			rv = OK;
			goto done;
		}

		if (data & 0x20) {
			/*
			 * If the 0x20 bit has come on, it could actually be because
			 * the operation succeeded, so check the done bit again.
			 */

			data = FLASH0_READ (dev, addr);

			if (((data ^ expect) & 0x80) == 0) {
				rv = OK;
				goto done;
			}

			printf ("flashWait: Program error (dev: %d, addr: 0x%x)\n",
					DEV_NO (dev), addr);

			flashReset (dev);
			rv = ERROR;
			goto done;
		}
	}

	printf ("flashWait: Timeout %s (dev: %d, addr: 0x%x)\n",
		erase ? "erasing sector" : "programming byte",
		DEV_NO (dev), addr);

  done:

#if 0
	PRINTF ("flashWait: rv=%d\n", rv);
#endif

	return rv;
}