📄 amd29lvmtd.c.svn-base
字号:
DEBUG_PRINT(DEBUG_ERASE, ("Erasing sector %d, 0x%02x\n\r",
sectorNum, sectorAddr));
/* Erase the sector */
for(i=0; i<sectorCnt; i++)
{
UINT16 Datum;
if ((pVol->type&0xffff) == 0x22A7 || /* amd29LV320BT */
(pVol->type&0xffff) == 0x22A8 || /* amd29LV320BB */
(pVol->type&0xffff) == 0x22F6 || /* SpansionS29AL032DT */
(pVol->type&0xffff) == 0x22F9 ) /* SpansionS29AL032DB */
{
pFlash = (volatile UINT16*) pVol->map(pVol, offset+i*0x2000, size);
sectorAddr = offset+i*0x2000;
} else
//support mx29lv640cb
if ((pVol->type&0xffff) == 0x227E /* mx29lv640cB */
||(pVol->type&0xffff) == 0x22CB) /* mx29lv640 bb */
{
pFlash = (volatile UINT16*) pVol->map(pVol, offset+i*0x2000, size);
sectorAddr = offset+i*0x2000;
} else
//support mx29lv640cb
#if FLASH_SST_SUPPORT
if ((pVol->type&0xffff) == 0x2780 || /* sst39vf400 */
(pVol->type&0xffff) == 0x2781 || /* sst39vf800 */
(pVol->type&0xffff) == 0x234B || /* sst39vf1601 */
(pVol->type&0xffff) == 0x235B) /* sst39vf3201 */
{
pFlash = (volatile UINT16*) pVol->map(pVol, offset+i*0x1000, size);
sectorAddr = offset+i*0x1000;
} else
#endif
{
pFlash = (volatile UINT16*) pVol->map(pVol, offset+sectorOffset[i], size);
sectorAddr = offset+sectorOffset[i];
};
//printf("\na) %d\n", get_sys_time());
flashReset(pVol);
/* erase sequence */
flashUnlock(pVol);
flashRegWrite16Bits(pVol, 0x5555*2, 0x8080);
flashUnlock(pVol);
/* Hit the locations for the sector */
flashRegWrite16Bits(pVol, sectorAddr, 0x3030);
// printf("\nb) %d\n", get_sys_time());
/* check DQ7 to ensure the device has accepted the command sequence */
#if 1
do {
//CACHE_PIPE_FLUSH();
Datum = flashRegRead16Bits(pVol, sectorAddr);
//CACHE_PIPE_FLUSH();
} while (0==(Datum & (1<<7)));
#endif
#if 0
while((flashRegRead16Bits(pVol, sectorAddr)&(1<<7))==0){
if( errorcounter++ > 0x100000) {
printf("sector erase failed!\n");
return (ERROR);
}
}
/* check DQ3, hit complete, to check erase operation has begun */
errorcounter =0;
while((flashRegRead16Bits(pVol, sectorAddr)&(1<<3))==0){
if( errorcounter++ > 0x100000)
printf("sector erase failed2!\n");
return (ERROR);
}
//printf("\nd) %d\n", get_sys_time());
#endif
#if 0
erased = flashCheck16Bits(pVol, sectorAddr);
if(erased == 1)
{
DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase timeout, %p\n\r", pFlash));
flashReset(pVol);
return(ERROR);
}
else if(erased == 2)
{
DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase error, %p\n\r", pFlash));
flashReset(pVol);
return(ERROR);
}
//printf("\nc) %d\n", get_sys_time());
#endif
}
flashReset(pVol);
return(OK);
}
/******************************************************************************
*
* flashRegWrite16Bits - Write 16 bits to 2 byte aligned address.
*
* RETURNS: N/A
*
*/
LOCAL inline void flashRegWrite16Bits(FLFlash* pVol, UINT32 addr, UINT16 data)
{
UINT32 flashBaseAddr = (pVol->baseAddress << 12);
/* Adjust addr for amd29LV160 */
addr = flashBaseAddr + addr;
DEBUG_PRINT(DEBUG_WRITE, ("Writing 0x%08x to 0x%08x\n\r", data, addr));
/* Write */
*((volatile UINT16*) addr) = data;
CACHE_PIPE_FLUSH();
}
/******************************************************************************
*
* flashRegRead16Bits - Read 16 bits from 2 byte aligned address.
*
* RETURNS: data at specified address
*
*/
LOCAL UINT16 flashRegRead16Bits(FLFlash* pVol, UINT32 addr)
{
UINT16 data;
UINT32 flashBaseAddr = (pVol->baseAddress << 12);
addr = flashBaseAddr + addr;
data = *((volatile UINT16*) addr);
DEBUG_PRINT(DEBUG_READ, ("Read 0x%08x from 0x%08x\n\r", data, addr));
CACHE_PIPE_FLUSH();
return(data);
}
/******************************************************************************
*
* flashRegRead8Bits - Read 8 bits from 2 byte aligned address.
*
* RETURNS: data at specified address
*
*/
LOCAL UINT16 flashRegRead8Bits(FLFlash* pVol, UINT32 addr)
{
UINT16 data;
UINT32 flashBaseAddr = (pVol->baseAddress << 12);
addr = flashBaseAddr + addr;
data = *((volatile UINT16*) addr);
data = data >> 8;
DEBUG_PRINT(DEBUG_READ, ("Read 0x%08x from 0x%08x\n\r", data, addr));
CACHE_PIPE_FLUSH();
return(data);
}
/******************************************************************************
*
* flashIdGet - Get flash man. and device codes.
*
* RETURNS: N/A
*
*/
LOCAL void flashIdGet(FLFlash* pVol, UINT16* manCode, UINT16* devCode)
{
flashUnlock(pVol);
flashRegWrite16Bits(pVol, 0x5555*2, 0x0090);
*manCode = flashRegRead16Bits(pVol, 0x00);
*devCode = flashRegRead16Bits(pVol, 0x01*2);
if(*devCode==0x227E) {
DeviceID_cycle2 = flashRegRead16Bits(pVol, 0x0e*2);
DeviceID_cycle3 = flashRegRead16Bits(pVol, 0x0f*2);// 0x2200 BB 0x2201 BT
/*
DEBUG_PRINT(DEBUG_ALWAYS,
("mx29lv640: 0x%02x 0x%02x\n\r",flashRegRead16Bits(pVol, 0x0e*2),
flashRegRead16Bits(pVol, 0x0f*2)
));
*/
}
flashReset(pVol);
}
/******************************************************************************
*
* flashUnlock - Write unlock sequence to flash section.
*
* RETURNS: N/A
*
*/
LOCAL void flashUnlock(FLFlash* pVol)
{
flashRegWrite16Bits(pVol, 0x5555*2, 0xaaaa);
flashRegWrite16Bits(pVol, 0x2aaa*2, 0x5555);
}
/******************************************************************************
*
* flashReset - Write reset sequence to flash section.
*
* RETURNS: N/A
*
*/
LOCAL void flashReset(FLFlash* pVol)
{
flashRegWrite16Bits(pVol, 0x5555*2, 0xaaaa);
flashRegWrite16Bits(pVol, 0x2aaa*2, 0x5555);
flashRegWrite16Bits(pVol, 0x5555*2, 0xf0f0);
}
/******************************************************************************
*
* amd29lvWrite - Erase and Write Area
*
* RETURNS: N/A
*
*/
extern board_param_t bParam;
STATUS amd29lvWrite(const void * dest, const void * buffer, int length)
{
FLFlash nvVol;
int start, n_blk, status;
//11/09/05' hrchen, disable NIC
Lan_Stop();
nvVol.baseAddress = FLASH_BASE_ADDR >> 12;
nvVol.map = amd29lvMap;
if (amd29lvMTDIdentify(&nvVol) != flOK)
return ERROR;
//if (dest >= nvVol.chipSize)
// return ERROR;
start = ((UINT32)dest-FLASH_BASE_ADDR)/nvVol.erasableBlockSize;
n_blk = (length+nvVol.erasableBlockSize-1)/nvVol.erasableBlockSize;
DEBUGIT("\n1) %d\n", get_sys_time());
if(nvVol.erase(&nvVol, start, n_blk)!=flOK)
return ERROR;
DEBUGIT("\n2) %d\n", get_sys_time());
status = nvVol.write(&nvVol, (UINT32)dest-FLASH_BASE_ADDR, buffer, length, 0);
DEBUGIT("\n3) %d\n", get_sys_time());
//11/09/05' hrchen, enable NIC again
get_param(&bParam);
Lan_Initialize(bParam.mac[0]);
return status;
}
/******************************************************************************
*
* For saving size reason, new NVram area is at 0xbfc0e000 to 0xbfc0ffff
*
* RETURNS: N/A
*
*/
/******************************************************************************
*
* amd29lvEraseNV - Erase reserved area
*
* RETURNS: N/A
*
*/
STATUS amd29lvEraseNV(UINT32 sectorAddr, int length)
{
FLFlash nvVol, *pVol;
volatile UINT16* pFlash;
BOOL erased = FALSE;
int status=OK;
//11/09/05' hrchen, disable NIC
Lan_Stop();
nvVol.baseAddress = FLASH_BASE_ADDR >> 12;
nvVol.map = amd29lvMap;
pVol = &nvVol;
pFlash = (volatile UINT16*) pVol->map(pVol, sectorAddr, length);
flashReset(pVol);
/* erase sequence */
flashUnlock(pVol);
flashRegWrite16Bits(pVol, 0x5555*2, 0x8080);
flashUnlock(pVol);
/* Hit the locations for the sector */
flashRegWrite16Bits(pVol, sectorAddr, 0x3030);
/* check DQ7 to ensure the device has accepted the command sequence */
while((flashRegRead16Bits(pVol, sectorAddr)&(1<<7))==0);
/* check DQ3, hit complete, to check erase operation has begun */
while((flashRegRead16Bits(pVol, sectorAddr)&(1<<3))==0);
erased = flashCheck16Bits(pVol, sectorAddr);
if(erased == 1) {
DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase timeout, %p\n\r", pFlash));
flashReset(pVol);
status = ERROR;
goto return_amd29lvEraseNV;
}
else if(erased == 2) {
DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase error, %p\n\r", pFlash));
flashReset(pVol);
status = ERROR;
goto return_amd29lvEraseNV;
}
flashReset(pVol);
return_amd29lvEraseNV:
//11/09/05' hrchen, enable NIC again
get_param(&bParam);
Lan_Initialize(bParam.mac[0]);
return status;
}
/******************************************************************************
*
* amd29lvWriteNV - Write without erase
*
* RETURNS: N/A
*
*/
STATUS amd29lvWriteNV(const void * dest, const void * buffer, int length)
{
FLFlash nvVol;
int start, n_blk, status;
//11/09/05' hrchen, disable NIC
Lan_Stop();
nvVol.baseAddress = FLASH_BASE_ADDR >> 12;
nvVol.map = amd29lvMap;
if (amd29lvMTDIdentify(&nvVol) != flOK)
return ERROR;
start = ((UINT32)dest-FLASH_BASE_ADDR)/nvVol.erasableBlockSize;
n_blk = (length+nvVol.erasableBlockSize-1)/nvVol.erasableBlockSize;
status = nvVol.write(&nvVol, (UINT32)dest-FLASH_BASE_ADDR, buffer, length, 0);
//11/09/05' hrchen, enable NIC again
get_param(&bParam);
Lan_Initialize(bParam.mac[0]);
return status;
}
/******************************************************************************
*
* amd29lvReadNV - Erase reserved area
*
* RETURNS: N/A
*
*/
STATUS amd29lvReadNV(const void * buffer, const void * src, int length)
{
FLFlash nvVol;
nvVol.baseAddress = FLASH_BASE_ADDR >> 12;
nvVol.map = amd29lvMap;
if (amd29lvMTDIdentify(&nvVol) != flOK)
return ERROR;
memcpy(buffer, nvVol.map(&nvVol, (UINT32)src-FLASH_BASE_ADDR, 0), length);
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -