📄 flash.c
字号:
if (((nPoll ^ *(pWalkSrc)) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else if ((nPoll & FLASH_DQ5_2X16) == FLASH_DQ5_2X16)
{
nPoll = *(pWalk);
if (((nPoll ^ *(pWalkSrc)) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else
{
bFail = TRUE;
bFailTotal = TRUE;
}
}
}
if (bDone == TRUE)
{
nDone += sizeof(*pWalk);
}
nWalk += sizeof(*pWalk);
pWalk++;
pWalkSrc++;
}
// Cancel unlock bypass mode
// ************************************************
*(pBase + 0x000) = 0x00900090;
*(pBase + 0x000) = 0x00000000;
// Reset flash devices
// *******************
*(pBase + 0x000) = 0x00f000f0;
printf("\nFlash Write Complete\n");
// return bFailTotal ? 0 : nDone;
}
// ***************************************************************************
//
// Function: FlashChipErase
//
// This function erases all flash memory sectors
//
//
// Parameters: U32 sAddress start address for erase
//
// Return Value: BOOL chip erase success?
//
//
// ***************************************************************************
BOOL FlashChipErase(U32 sAddress)
{
volatile U32* pBase;
BOOL bDone;
BOOL bFail;
U32 nPoll;
U32 i = 0;
// Check the Flash Starting Address
pBase = (volatile U32*)(sAddress & 0xFE000000);
// Reset flash devices before chip erase
// ***************************************
*(pBase + 0x000) = 0x00f000f0;
// Execute "normal" chip erase algorithm
// ***************************************
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pBase + 0x555) = 0x00800080;
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pBase + 0x555) = 0x00100010;
printf("Chip Erasing...\n");
// Data polling algorithm for erase operation
// ******************************************
bDone = FALSE;
bFail = FALSE;
while ((!bDone) && (!bFail))
{
i++;
if ((i & 0xFFFF) == 0)
{
printf(".");
}
nPoll = *(pBase);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else if ((nPoll & FLASH_DQ5_2X16) == FLASH_DQ5_2X16)
{
nPoll = *(pBase);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else
{
bFail = TRUE;
}
}
}
// Reset flash evices
// *******************
*(pBase + 0x000) = 0x00f000f0;
printf("\nChip Erase Complete\n");
return bFail;
}
/////////////////////////////////////////////////////////////////////////////
//NewFlashSecterErase rewrite for liuhanying..........
//***************************************************************************
//
// Function: FlashSectorErase
//
// This function erases all flash memory sectors overlapping
// the address range specified in the parameters.
//
//
// Parameters: U32 sAddress start address for erase
// U32 nAddress end address for erase
//
// Return Value: U32 number of bytes erased (rounded up to
// next sector limit), or zero on error
//
// ***************************************************************************
U32 NewFlashSectorErase(U32 sAddress,
U32 nAddress)
{
volatile U32* pBase;
volatile U32* pWalk;
BOOL bFailTotal;
BOOL bDone;
BOOL bFail;
U32 nWalk;
U32 nSize;
U32 nPoll;
U32 nDone;
U32 nSec;
U32 SA;
U32 i = 0;
// Check the Flash Starting Address
pBase = (volatile U32*)(sAddress & 0xFE000000);
// Reset flash devices before starting erase sequences
// ***************************************************
*(pBase + 0x000) = 0x00f000f0;
nSec = (U32)pBase;
nDone = 0;
nWalk = sAddress;
printf("Sector Erase at [0x%08X - 0x%08X]...\n",sAddress, nAddress);
//modify it for s29gl256n10 060526
//for (SA = 1; SA <= 512; SA++)
for (SA = 1; SA <= 256; SA++)
//end modify it for s29gl256n10 060526
{
//modify it for s29gl256n10 060526
//nSize = 1024*32*4;
nSize = 1024*64*4;
//end modify it for s29gl256n10 060526
if ((nSec <= nWalk) && (nSec + nSize > nWalk) && (nSec <= nAddress))
{
// This sector overlaps the address range. Erase it
// ************************************************
pWalk = (volatile U32*) nWalk;
// Execute "normal" sector erase algorithm
// ***************************************
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pBase + 0x555) = 0x00800080;
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pWalk) = 0x00300030;
// Data polling algorithm for erase operation
// ******************************************
bDone = FALSE;
bFail = FALSE;
while ((!bDone) && (!bFail))
{
nPoll = *(pWalk);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else if ((nPoll & FLASH_DQ5_2X16) == FLASH_DQ5_2X16)
{
nPoll = *(pWalk);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else
{
bFail = TRUE;
bFailTotal = TRUE;
}
}
if ( (i &= 0xFFFF) ==0)
{
printf(".");
}
i++;
}
nDone += nSize;
nWalk += nSize;
}
nSec += nSize;
}
// Reset flash devices
// *******************
*(pBase + 0x000) = 0x00f000f0;
return bFailTotal ? 0 : nDone;
}
// ***************************************************************************
//
// Function: FlashSectorErase
//
// This function erases all flash memory sectors overlapping
// the address range specified in the parameters.
//
//
// Parameters: U32 sAddress start address for erase
// U32 nAddress end address for erase
//
// Return Value: U32 number of bytes erased (rounded up to
// next sector limit), or zero on error
//
// ***************************************************************************
U32 FlashSectorErase(U32 sAddress,
U32 nAddress)
{
volatile U32* pBase;
volatile U32* pWalk;
BOOL bFailTotal;
BOOL bDone;
BOOL bFail;
U32 nWalk;
U32 nSize;
U32 nPoll;
U32 nDone;
U32 nSec;
U32 SA;
U32 i = 0;
// Check the Flash Starting Address
pBase = (volatile U32*)(sAddress & 0xFE000000);
// Reset flash devices before starting erase sequences
// ***************************************************
*(pBase + 0x000) = 0x00f000f0;
nSec = (U32)pBase;
nDone = 0;
nWalk = sAddress;
printf("Sector Erase at [0x%08X - 0x%08X]...\n",sAddress, nAddress);
for (SA = 1; SA <= 270; SA++)
{
if ((SA >= 1 && SA <= 8) || (SA >= 263 && SA <= 270))
{
nSize = 1024*4*4;
}
else
{
nSize = 1024*32*4;
}
if ((nSec <= nWalk) && (nSec + nSize > nWalk) && (nSec <= nAddress))
{
// This sector overlaps the address range. Erase it
// ************************************************
pWalk = (volatile U32*) nWalk;
// Execute "normal" sector erase algorithm
// ***************************************
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pBase + 0x555) = 0x00800080;
*(pBase + 0x555) = 0x00aa00aa;
*(pBase + 0x2aa) = 0x00550055;
*(pWalk) = 0x00300030;
// Data polling algorithm for erase operation
// ******************************************
bDone = FALSE;
bFail = FALSE;
while ((!bDone) && (!bFail))
{
nPoll = *(pWalk);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else if ((nPoll & FLASH_DQ5_2X16) == FLASH_DQ5_2X16)
{
nPoll = *(pWalk);
if (((~nPoll) & FLASH_DQ7_2X16) == 0)
{
bDone = TRUE;
}
else
{
bFail = TRUE;
bFailTotal = TRUE;
}
}
if ( (i &= 0xFFFF) ==0)
{
printf(".");
}
i++;
}
nDone += nSize;
nWalk += nSize;
}
nSec += nSize;
}
// Reset flash devices
// *******************
*(pBase + 0x000) = 0x00f000f0;
return bFailTotal ? 0 : nDone;
}
// ***************************************************************************
//
// Function: FlashRead
//
//
//
// Parameters: U32 sAddress start address for read
// void* pData data to read
// U32 nData number of bytes to read
//
// Return Value: U32 ?
//
// ***************************************************************************
U32* FlashRead(U32 sAddress, U32* pData, U32 nData)
{
U32 nWalk;
U32 nAddress;
U32* dWalk;
U32* sWalk;
U32 i;
nWalk = sAddress;
nAddress = sAddress + nData;
dWalk = (U32*)sAddress;
sWalk = pData;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -